Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
math/big: implement recursive division algorithm #21960
math/big currently only has an implementation of "schoolbook" long division which is O(n^2). An implementation of Burnikel and Ziegler's Fast Recursive Division (1998) would improve division's asymptotic complexity to the multiplication time. The multiplication asymptotic complexity is currently ~n^1.6 for the karatsuba implementation, but could be improved with other algorithms in the future and recursive division would automatically benefit.
Note, The Handbook of Elliptic and Hyperelliptic Cryptography Algorithm 10.35 on page 188 has a more explicit version of the div2NxN algorithm. This algorithm is directly recursive and avoids the mutual recursion of the original paper's calls between div2NxN and div3Nx2N. Algorithm 10.35 along with the Burnikel and Ziegler's handling of unbalanced division in blocks of 2NxN "digits" seems like the best candidate for implementation.
In addition to speeding up division in general, this will improve String output #20906 which relies on repeated large divisions.
Note: Burnikel and Ziegler's Fast Recursive Division is also an ingredient of the Karatsuba Square Root algorithm , which is the method gmp and mpfr use for computing square roots. It should be faster than the Newton approach currently used in
 Paul Zimmermann. Karatsuba Square Root. [Research Report] RR-3805, INRIA. 1999, pp.8.