#15501: floor(), ceil(), trunc(), round() for AA
-------------------------------------+-------------------------------------
       Reporter:  ppurka             |        Owner:
           Type:  defect             |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.1
      Component:  algebra            |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Marc Mezzarobba    |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/mmezzarobba/ticket/15501-AA_floor_ceil|  
a07f1e7ac809a6377476ff79c35225757eb7ee8d
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Description changed by mmezzarobba:

Old description:

> From google spreadsheet which no one reads `X-(`
>
> It happens that an algebraic number minus itself `(b-b)` is not printed
> as 0, but something like `0.?e-18`. Usually it is not a big problem,
> because `b - b == 0` evaluates to `True`. But interestingly `floor(b-b)`
> is sometimes 0, sometimes a symbolic expression, so weird things can
> happen.
>
> {{{
> sage: a = QQbar((-1)^(1/4)).real()
> sage: floor(a-a) + a
> ---------------------------------------------------------------------------
> TypeError Traceback (most recent call last)
> <ipython-input-337-107a1ad8256f> in <module>()
> ----> 1 floor(a-a) + a
>
> /Applications/sage/local/lib/python2.7/site-
> packages/sage/structure/element.so in
> sage.structure.element.RingElement.__add__
> (sage/structure/element.c:13884)()
>
> /Applications/sage/local/lib/python2.7/site-
> packages/sage/structure/coerce.so in
> sage.structure.coerce.CoercionModel_cache_maps.bin_op
> (sage/structure/coerce.c:8169)()
>
> TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and
> 'Algebraic Real Field'
> }}}

New description:

 Add methods floor(), ceil(), trunc(), and round() to the implementation of
 real algebraic numbers. Also implement trunc() for rational numbers, both
 for consistency and to be able to use it in the code for algebraic
 numbers.

 ORIGINAL BUG DESCRIPTION:

 From google spreadsheet which no one reads `X-(`

 It happens that an algebraic number minus itself `(b-b)` is not printed as
 0, but something like `0.?e-18`. Usually it is not a big problem, because
 `b - b == 0` evaluates to `True`. But interestingly `floor(b-b)` is
 sometimes 0, sometimes a symbolic expression, so weird things can happen.

 {{{
 sage: a = QQbar((-1)^(1/4)).real()
 sage: floor(a-a) + a
 ---------------------------------------------------------------------------
 TypeError Traceback (most recent call last)
 <ipython-input-337-107a1ad8256f> in <module>()
 ----> 1 floor(a-a) + a

 /Applications/sage/local/lib/python2.7/site-
 packages/sage/structure/element.so in
 sage.structure.element.RingElement.__add__
 (sage/structure/element.c:13884)()

 /Applications/sage/local/lib/python2.7/site-
 packages/sage/structure/coerce.so in
 sage.structure.coerce.CoercionModel_cache_maps.bin_op
 (sage/structure/coerce.c:8169)()

 TypeError: unsupported operand parent(s) for '+': 'Symbolic Ring' and
 'Algebraic Real Field'
 }}}

--

--
Ticket URL: <http://trac.sagemath.org/ticket/15501#comment:6>
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/groups/opt_out.

Reply via email to