#12968: round of symbolic expression (precision issue due to RR)
--------------------------------------------------------+-------------------
Reporter: dkrenn | Owner:
burcin
Type: defect | Status:
positive_review
Priority: major | Milestone:
sage-5.1
Component: symbolics | Resolution:
Keywords: round symbolic precision RR beginner | Work issues:
Report Upstream: N/A | Reviewers:
Burcin Erocal
Authors: Mike Hansen | Merged in:
Dependencies: | Stopgaps:
--------------------------------------------------------+-------------------
Changes (by burcin):
* status: needs_review => positive_review
Old description:
> We have
> {{{
> sage: u = sqrt(43203735824841025516773866131535024) #add one digit
> sage: floor(u)
> 207855083711803944
> sage: round(u) # ?? smaller than floor(u)! No warning message...
> 207855083711803936
> sage: r = round(u)
> sage: ceil(u)
> 207855083711803945
> }}}
> Numbers with one digit less work
> {{{
> sage: t=sqrt(4320373582484102551677386613153502)
> sage: floor(t)
> 65729548777426599
> sage: round(t) #everything as expected, floor ≤ round ≤ ceil
> 65729548777426600
> sage: ceil(t)
> 65729548777426600
> }}}
> The docstring/source code of the symbolic round mentions that behavior
> {{{
> Definition: u.round(self)
> Source:
> def round(self):
> """
> Round this expression to the nearest integer.
>
> This method evaluates an expression in ``RR`` first and rounds
> the result. This may lead to misleading results.
>
> EXAMPLES::
>
> sage: t = sqrt(Integer('1'*1000)).round(); t
> 3333333333333333056287287783757109595393...
>
> This is off by a huge margin::
>
> sage: (Integer('1'*1000) - t^2).ndigits()
> 984
> """
> #FIXME: can we do better?
> }}}
>
> This was reported on [https://groups.google.com/d/topic/sage-
> support/s-A22yzFnbY/discussion sage-support] by Lorenzo. I created a
> ticket here, since I didn't find one for that behavior (but maybe I
> missed it...).
New description:
We have
{{{
sage: u = sqrt(43203735824841025516773866131535024) #add one digit
sage: floor(u)
207855083711803944
sage: round(u) # ?? smaller than floor(u)! No warning message...
207855083711803936
sage: r = round(u)
sage: ceil(u)
207855083711803945
}}}
Numbers with one digit less work
{{{
sage: t=sqrt(4320373582484102551677386613153502)
sage: floor(t)
65729548777426599
sage: round(t) #everything as expected, floor ≤ round ≤ ceil
65729548777426600
sage: ceil(t)
65729548777426600
}}}
The docstring/source code of the symbolic round mentions that behavior
{{{
Definition: u.round(self)
Source:
def round(self):
"""
Round this expression to the nearest integer.
This method evaluates an expression in ``RR`` first and rounds
the result. This may lead to misleading results.
EXAMPLES::
sage: t = sqrt(Integer('1'*1000)).round(); t
3333333333333333056287287783757109595393...
This is off by a huge margin::
sage: (Integer('1'*1000) - t^2).ndigits()
984
"""
#FIXME: can we do better?
}}}
This was reported on [https://groups.google.com/d/topic/sage-
support/s-A22yzFnbY/discussion sage-support] by Lorenzo. I created a
ticket here, since I didn't find one for that behavior (but maybe I missed
it...).
Apply attachment:trac_12968.patch.
--
Comment:
Looks good to me.
Patchbot, apply attachment:trac_12968.patch.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/12968#comment:9>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.