#11779: python ints vs sage ints with respect to powers weirdness
-----------------------------+----------------------------------------------
   Reporter:  dimpase        |          Owner:  AlexGhitza       
       Type:  defect         |         Status:  positive_review  
   Priority:  major          |      Milestone:  sage-4.7.2       
  Component:  coercion       |       Keywords:                   
Work_issues:                 |       Upstream:  N/A              
   Reviewer:  William Stein  |         Author:  Dmitrii Pasechnik
     Merged:                 |   Dependencies:                   
-----------------------------+----------------------------------------------
Changes (by leif):

  * reviewer:  => William Stein


Old description:

> {{{
> print type(int(3) + 3)
> print type(int(3) * 3)
> print type(3 ^ int(3))
> print type(int(3) ^ 3)
> }}}
> first three are Sage Integers but last one is just a Python int.
> Worse still:
> {{{
> sage: int(3)^-3
> 0.037037037037037035
> sage: type(int(3)^-3)
> <type 'float'>
> sage: int(3)^QQ(-3)
> 1/27
> sage: type(int(3)^QQ(-3))
> <type 'sage.rings.rational.Rational'>
> }}}
> is very inconsistent, as well as leads to loss of precision, even though
> it can be
> avoided. As well as
> {{{
> sage: p(x)=x^-3
> sage: p(int(3))
> 1/27
> }}}
> is not consistent.
>
> A patch is at
> http://trac.sagemath.org/sage_trac/attachment/ticket/11779/trac_11779.patch
>
> See https://groups.google.com/d/topic/sage-devel/RG-8xcPF53g/discussion

New description:

 {{{
 print type(int(3) + 3)
 print type(int(3) * 3)
 print type(3 ^ int(3))
 print type(int(3) ^ 3)
 }}}
 first three are Sage Integers but last one is just a Python int.
 Worse still:
 {{{
 sage: int(3)^-3
 0.037037037037037035
 sage: type(int(3)^-3)
 <type 'float'>
 sage: int(3)^QQ(-3)
 1/27
 sage: type(int(3)^QQ(-3))
 <type 'sage.rings.rational.Rational'>
 }}}
 is very inconsistent, as well as leads to loss of precision, even though
 it can be
 avoided. As well as
 {{{
 sage: p(x)=x^-3
 sage: p(int(3))
 1/27
 }}}
 is not consistent.

 Apply [attachment:trac_11779.patch] to the Sage library.

 See [https://groups.google.com/d/topic/sage-devel/RG-8xcPF53g/discussion].

--

Comment:

 Please don't put links to the '''HTML version''' of a patch into the
 description.

 Trac wiki mark-up is `[attachment:here_comes_the_filename]`.

 ----

 Wonder whether your undergrads will complain that `[1r][0]` (or
 `(1r,)[0]`) doesn't yield a Sage `Integer`...

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/11779#comment:23>
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.

Reply via email to