-
Notifications
You must be signed in to change notification settings - Fork 196
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
Improve mp_root_n code #532
base: develop
Are you sure you want to change the base?
Conversation
@czurnieden could you maybe have a look if you have the time? You've added parts of the removed code in 984d3ff and I'm not sure whether this should/can really be removed. |
I based it on the development branch. I thought it was more up to date. |
I don't know if it is how readable in this form: Starting with x[i+1] = x[i] - f(x[i])/f'(x[i]), where f(x) = x^b - a So x[i+1] = x[i] - (x[i] ^ b - a) / ( b * x[i] ^ (b-1) ) (this is in the code) When x[i] ^ b > a, x[i+1] will be rounded up. Algebraically: Hence the code removal (unless I'm missing something...). |
It's too warm too sleep, so here we go:
That was three years ago! But I appreciate your optimism regarding my long-term memory ;-) I am sure that I did no proper analysis, so there are some places with…let's call it "belt&girdle" code. The start-value gets calculated based on the equality With addition of unity we get the inequality I'm not sure anymore why I added the loop but I also had some code to find a more exact start-value by doing some rounds of bisection (works well for larger bases and also a little bit for smaller bases but it adds a lot of code and nobody wanted it ;-) ), so it might be a leftover from that experiment. But no matter the exact reason: it is superfluous code in case of One last question: are you, @ssinai1 sure that the main loop cannot oscillate? |
Thanks for the explanation. My reasoning is as follows: This means that not only is As for the second part of the question: |
What is that in lines 110ff? Ouch! How could that have slipped through the tests for over three years? But while we are at it: If we can assume that the error is at most one with a start-value of Is that correct? |
I rewrote it for downward rounding iteration. The mp_div seems to round towards 0, so it needed the remainder... |
No, it is truncating! E.g.: both But I like where it is going to! Thanks for the work! BTW: Libtommath is not as frugal as it looks from the outside, it has some useful macros in
These are a bit cheaper than a full call to If I understood it correctly
That macro is not in |
Anyway, in this case a division rounding to negative infinity would be more practical. |
Do you use this often inside the library or in code using libtommath? IMO it'd be fine to go in either of |
Mainly externally, so |
Sorry @ssinai1 for highjacking your PR for this discussion :) I've created #537 for that purpose now. We should continue with this question #532 (comment) now :) (and by 'we' I mostly mean @ssinai1 and @czurnieden :D thanks) |
October 2022. Oh, my, completely forgotten, sorry! @ssinai1 if you are still out there: could you please rebase this PR to the current develop branch so I can give it my "seal of approval"? Thank you very much! |
@ssinai1 Can you please rebase on top of develop, squash those commits and write a bit of a commit message which summarizes what was done. |
Set a closer initial value for iteration and remove some unnecessary code.
By the way, in the first for loop, one of the err=MP_OKAY branches (never reached) did not set c.