#17984: Dedicated RR.__contains__() and CC.__contains__()
-------------------------+-------------------------------------------------
Reporter: rws | Owner:
Type: | Status: needs_review
enhancement | Milestone: sage-6.6
Priority: major | Resolution:
Component: basic | Merged in:
arithmetic | Reviewers:
Keywords: | Work issues:
Authors: Ralf | Commit:
Stephan | 544450ea18ed2778953141bab8feced61237556e
Report Upstream: N/A | Stopgaps:
Branch: |
u/rws/17984 |
Dependencies: |
-------------------------+-------------------------------------------------
Comment (by pbruin):
I guess the first basic question is how to resolve the following
inconsistency:
{{{
sage: bool(RR(pi) == pi)
True
sage: bool(RR(sqrt(2)) == sqrt(2))
False
}}}
The second basic question is, if we agree on what the correct result is,
is this also the result that `x in RR` should return?
Personally I would answer the second question with "yes", if only for
consistency; there is undoubtedly a lot of code using `x in P` that
expects this behaviour, and it would be very inconvenient to change this
just for `P = RR` and `P = CC` because of what users intuitively expect
when typing `x in RR`.
The first question is harder. One could argue that `bool(RR(pi) == pi)`
should indeed return `True` because the two numbers become equal when
converting to the lowest common precision (just as is done when comparing
elements of two instances of `RealField` with different precision). On
the other hand, this is dangerous due to rounding errors:
{{{
sage: def t(x): return bool(RR(x) == x)
sage: t(sqrt(2))
False
sage: t(sqrt(3))
False
sage: t(sqrt(3) - sqrt(2))
True
}}}
Hence I am tending towards the opinion that if `x` is some exact element,
then `bool(RR(x) == x)` should return `True` if and only if `x` is exactly
representable in `RR`. Unfortunately this moves `RR` a bit further away
from the mathematical field '''R''' than it already is, but I guess that
is better than pretending that `RR` is a general-purpose model for
'''R'''.
--
Ticket URL: <http://trac.sagemath.org/ticket/17984#comment:20>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.