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

  * component:  basic arithmetic => coercion


Comment:

 Replying to [comment:4 dimpase]:
 > Replying to [comment:3 leif]:
 > > So what do you expect the result types to be?
 > >
 > > IMHO the fact that `3r^3` yields a Python `int` is pretty correct;
 with negative exponents the interpretation is less straightforward.
 >
 > in all other operations (see the ticket description),
 > the Sage type takes the precedence over Python.

 Exponentiation is different, i.e., the ''type'' of the exponent doesn't
 matter at all, only its value.

 [[BR]]

 > I certainly don't mind {{{int(3)^int(3)}}} being int though.

 Why should one?

 [[BR]]

 > in fact, with the patch applied, the behaviour is as follows:
 {{{
 ...
 sage: type(int(3)^3)
 <type 'sage.rings.integer.Integer'>
 ...
 }}}
 which is simply wrong, because `3r^3` is `3r * 3r * 3r`, so the type of
 the result should be the ''base's'' type (unless the result is not an
 integer, in which case Python's rules should apply, leading to a `float`
 result.)

 The following is equally wrong for the same reason. ('''This''' is a bug.)
 >
 {{{
 sage: type(int(3)^-3)
 <type 'sage.rings.rational.Rational'>
 }}}

 > this is the behaviour that is much less confusing.

 Less confusing to whom? Honestly, every school child should know the
 difference.

 Ok, one could argue that `3r * 3` could be interpreted as `3r + 3r + 3r`
 as well (leading to result type `int` rather than `Integer`), but this
 would break commutativity.


 Worth a discussion on sage-devel... (quite curious of the opinions :P )

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