-
Notifications
You must be signed in to change notification settings - Fork 211
balancing multiplication #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Rebased and merged to develop |
Well I just found out that your code works only for 64bit architectures resp. I will try to have a look at it, but please do that as well To reproduce on x64:
also tested with |
And TBH, I think you should clarify possible licensing issues with the ruby team! |
Libtommath is not Public Domain anymore but still counts as "Freely Available", I think. For the technical side: I implemented a balancing algorithm myself in a recursive way but on copies to keep it simple (could be done with some pointer juggling, too). I also found out, empirically only, that it makes not much sense if the difference is less than about one percent which is not very much. The second difference is that I did it at limb resolution. The much finer resolution of lomereiter seems to be not only not necessary (see the "one percent" above) but is probably the reason for the test failure, too. CZ |
Okay true - ruby is also public domain... it seems I can't read anymore... Well but regarding the technical side...
Sorry for that question, but what does that mean? |
And the bug also occurs on 64bit architectures resp. |
It also fails on at least one 32-bit machine: mine.
I just tried to be polite and failed English grammar, too, sorry. He tried to save memory, a commendable approach but he implemented it in not exactly the way he intended to do it. I didn't even looked at it but a difference of a mere 75 decimal digits in calculating a 318 decimal digits long result is a strong hint for off-by-one errors and similar. So, please, lomereiter, take a look at your code, it should be easily repaired. It would be sad if you don't, balancing is a good idea! CZ |
I've reverted your commit and created a new branch fix/balance_mul where fixes should be applied to. |
@czurnieden Any comments concerning the status of this PR? Is there hope to get this working and is it worth it? |
There's always hope ;-) But, no, not really. I already have one ready and tested and am just waiting until the new version gets out to start a new one with balanced multiplication, fast division, FFT/NTT and more. |
@czurnieden I guess it is fine to close this one now. Did I understand correctly that you have a patch locally which could be resubmitted at some point? |
Multiplication by Karatsuba or Toom-Cook method is not effective when the two numbers are of different order of magnitude (for example, 167483-digit number times 1263-digit one). It's better to slice the larger number into pieces which size is roughly equal to the smaller number size. This algorithm was implemented in Ruby, and it works much faster.