-
Notifications
You must be signed in to change notification settings - Fork 188
log compute - taylor series #957
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old PR accidently removed ctx_mp file
Next time please just do "git revert" for bad commit.
I worry, that you are committed fix from a different GH account. Are you code author?
# Taylor series | ||
assert (log(0.99999)).ae(-1.0000050000287824e-5) | ||
assert (log(1.00001)).ae(9.9999500003988414e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see changes.
Did you realize what's doing your code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With default precision of 53, I tested locally for log(0.99999) and log(1.00001) and it ran through to do taylor series compute. The code checks for tfixed (distance from 1) and compares to a threshold scaled to a wp that is 0.001 in floating point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With default precision of 53, I tested locally for log(0.99999) and log(1.00001) and it ran through to do taylor series compute.
Great, you have found values, that trigger you code path.
But results are same wrt the master (or not?). Could you argue why we need this?
The code checks for tfixed (distance from 1) and compares to a threshold scaled to a wp that is 0.001 in floating point?
Did you ask me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Taylor series | |
assert (log(0.99999)).ae(-1.0000050000287824e-5) | |
assert (log(1.00001)).ae(9.9999500003988414e-6) | |
# Taylor series | |
assert log(0.99999).ae(-1.0000050000287824e-5) | |
assert log(1.00001).ae(9.9999500003988414e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may not need it I guess. We wouldn't need to compute as many taylor series terms as the general case of code provided later.
Depending on the threshold, I wasn't sure what was close to 1 enough. I was looking for feedback.
if (tfixed <= threshold): | ||
s = log_taylor(to_fixed(x, wp), wp) | ||
sb = s.bit_length() | ||
rman = s << (sb) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's happens here, for example? Why mantissa corrected this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constructing the mantissa from the fixed point need to be normalize it with MSB. Which is used using bit length and shifted left by this amount to get no leading zeros. Also, then constructing the exponent to input into creating a mpf. rman is constructed using sb, and to get floating point representation, we also need the working precision wp, and by exponent laws of base 2 its wp+sb.
Still learning, this is new :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I still think you shouldn't post code on behalf of some other person.
BTW, please also don't use the master branch of your fork to create pr. Put your code in some branch, else you can't use your fork after merging.
# Taylor series | ||
assert (log(0.99999)).ae(-1.0000050000287824e-5) | ||
assert (log(1.00001)).ae(9.9999500003988414e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With default precision of 53, I tested locally for log(0.99999) and log(1.00001) and it ran through to do taylor series compute.
Great, you have found values, that trigger you code path.
But results are same wrt the master (or not?). Could you argue why we need this?
The code checks for tfixed (distance from 1) and compares to a threshold scaled to a wp that is 0.001 in floating point?
Did you ask me?
# Taylor series | ||
assert (log(0.99999)).ae(-1.0000050000287824e-5) | ||
assert (log(1.00001)).ae(9.9999500003988414e-6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Taylor series | |
assert (log(0.99999)).ae(-1.0000050000287824e-5) | |
assert (log(1.00001)).ae(9.9999500003988414e-6) | |
# Taylor series | |
assert log(0.99999).ae(-1.0000050000287824e-5) | |
assert log(1.00001).ae(9.9999500003988414e-6) |
# if close enough to 1, use Taylor series | ||
# since Taylor series converges rapidly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed AGM mention. Why? Are you know what's it about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's used for high precision due to its convergence properties which contrasts with taylor series depending on x.
Don't know how it would be applied to current code.
else: | ||
tfixed = to_fixed(x, wp) - (MPZ_ONE << wp) | ||
threshold = (1 << wp) // 1000 | ||
if (tfixed <= threshold): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (tfixed <= threshold): | |
if tfixed <= threshold: |
tfixed = (MPZ_ONE << wp) - to_fixed(x,wp) | ||
else: | ||
tfixed = to_fixed(x, 8000 wp) - (MPZ_ONE << wp) | ||
threshold = (1 << wp) // 1000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why such value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure here, looking for feedback.
Hi, it is my code. If your referring to borjha19, thats an old Github account of mine that I don't use and forgot about. Not sure why its showing up here. If your not referring to that, I don't know what you mean. I wrote this code and it wasn't behalf on anyone. |
Comments in libelefun.py, new tests.
-> Old PR accidently removed ctx_mp file, different refactor changes.