-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix pi == one(pi)*pi or update docs for one() #37977
Comments
FYI: Returning 1.0 (or 1 or true) isn't strictly wrong. That is the multiplicative identity. The problem comes when you multiply it with pi, or even 2 with pi, you want to get pi or 2pi, but that's only possibly in a CAS (maybe e.g. in http://nemocas.org/ ). It was decided that actualy calculations would convert to floats that make pi rational approximation. |
I think in this case the docs is at fault. It should say that identity only holds for edit: I meant to distinguish where a julia> isconcretetype(typeof(pi))
true
julia> isbits(pi)
true
julia> sizeof(Int)
8
julia> sizeof(Irrational{:π})
0 One way to frame the problem is to say: multiplicative identity of |
|
🤷♂️ Really starting to regret the |
While of course it would be nice, I don't really see why this so badly needs to hold --- many mathematical identities are not true e.g. with floating-point numbers. |
At some point, I think we had the property that |
Perhaps a case where a 0-bit integer is useful! |
Isn't |
First, thank you for the responses. I understand this is a minor issue. I totally agree with @StefanKarpinski that the whole
julia> x = big(1.0)
1.0
julia> cos(-big(π)-x) == cos(π+x)
true
julia> cos(-π-x) ≈ cos(π+x)
false
julia> 2π+x == π+π+x
true
julia> 2π+x ≈ π+(π+x)
false The current documentation contains only the following text, but nothing about AbstractIrrational <: Real
Number type representing an exact irrational value, which is automatically
rounded to the correct precision in arithmetic operations with other numeric
quantities. What I love about julia is that it is easy to use and intuitive. But the behavior in these examples is not intuitive. There is no easy fix. big(1.0) + pi # deprecate this
big(1.0) + big(pi) # in favour of this I belive it would also make user's code less error-prone. |
The latter says a bit more about how cos is implemented on floats (vs big numbers) rather than about pi. It is a bit surprising that it's not even approximately true, with cos symmetric and e.g.:
Note also that despite:
Neither side gives the correct value as both are irrational (and the same), there the approximation of is just the same. You did the right thing with -big(pi), note how careful you would have to be:
|
Clarifying (fixing?) JuliaLang#37977 [skip ci]
The issue came up again in a discussion, with a suggestion by @nsajko to have a function return irrational numbers instead based on an explicitly specified type, eg irrational(:π, Float64) = 3.141592653589793 etc. Yes, this is breaking, but it could be revisited for 2.0. |
A better alternative would perhaps be to remove Edit: That's literally what you wrote just above, derp. Disregard me, I must have brainfarted and couldn't read. |
This comment was marked as resolved.
This comment was marked as resolved.
We could actually have
I guess that the first approach would be both easier to implement and more promising, but the second approach also seems OK. EDIT: actually, the second approach would be more powerful, in that it would prevent any information loss due to negation ( Thoughts? |
I still think that the whole concept of irrationals with precision resolved by context is a design mistake, so I think that fixing that by introducing yet another type is just compounding this. Irrational of a given precision should be requested by the user, |
I mostly agree, I was just thinking about what can be done before Julia 2. |
A new interface In the meantime, |
It seems that So one candidate resolution (which I will dismiss in my next paragraph) is to change The problem is that this would create an inconsistency with inequalities. Because Maybe this is the original sin of the All of this is easily reconciled by the trivial fact that |
I think that the easiest solution at this point (while remaining in Julia 1.x) could be just documenting the intended use and limitations of
Yes, I agree. We should just document that this is not a symbolic algebra system and using it as such will result in problems. |
Based on the discussion in #37931, I have found that
pi == one(pi)*pi
is broken. However, it should hold according to the documentation ofone()
function:Don't know if you prefer fixing the implementation or just updating the documentation to make it consistent. Notice that since
one(pi)
already returnstrue
, it would be possible to maketrue * pi === pi
.The text was updated successfully, but these errors were encountered: