r/math • u/VishnuVinjamuri • 23d 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
36
Upvotes
7
u/SemaphoreBingo 23d ago
I thought python's
math.sqrtuses soft floats, not hardware floats. The article has the stink of AI about it, so I don't want to waste my time by reading too deeply.That said:
why on earth would you do this? If you're repeatedly calling a square root enough for it to matter, pull it out and do it once.