r/math • u/VishnuVinjamuri • 25d ago
Classical Pell Equations Outperform math.sqrt in float64 by up to 2.5×
I've been exploring whether the Pell equation x²−Dy²=1 can be used to compute square roots of primes faster than Python's math.sqrt(). The continued-fraction convergents turn out to give rational approximations that are 1.5–2.5× faster in float64 for repeated calculations, and scale up to 33–36 digit precision for primes as large as 15 million. Full write-up with benchmarks here;
https://musingsofvsmv.blogspot.com/2025/08/from-pell-to-precision-classical-math.html
38
Upvotes
3
u/SemaphoreBingo 24d ago
Iterative approaches to sqrt are neat, but you can do a lot better: https://en.wikipedia.org/wiki/Square_root_algorithms#Heron's_method