On Monday, 5 September 2011 18:45:42 UTC+8, Simon King wrote: > Hi Dima, hi Rado, > > On 5 Sep., 11:58, Dima Pasechnik <dim...@gmail.com> wrote: > > I see no reason for int(3)^3 not to return a Sage Integer, and for > int(3)^-3 > > not to return a QQ. > > I see a reason: > > x^n is recursively defined by > x if n==0 > x*x^(n-1) otherwise
x if n==1... To be precise, I can propose that x^0 should be 1, (and not int(1)), then x^n := x*x^{n-1} for n>0, and then multiplication result will a Sage Integer. > > > Hence, if x is a Python int then x^n should be a Python int (namely > the n-fold product of x with itself) even if n is a Sage Integer. > > what about negative n? 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'> Will you tell me that it is OK that int(3)^-3 is not equal to int(3)^QQ(-3) ?! Well, I know that if you compare them then 1/27 gets converted to a float, so == will tell you they are equal, but still... This is very weird, to see this happening. Or, for non-integer n>0? Then it's always a Sage object... So, somehow an integer exponent is an outcast... > Cheers, > Simon > -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org