Python functions (like range) return Python integers, which do C division arithmetic:
sage: int(1)/int(2) 0 sage: type(int(1)) <type 'int'> sage: type(1) <type 'sage.rings.integer.Integer'> Whenever you get an integer out of a Python function you should convert it to a Sage integer with ZZ(): sage: [ i/j for i,j in CartesianProduct(range(1,5),range(1,5)) ] [1, 0, 0, 0, 2, 1, 0, 0, 3, 1, 1, 0, 4, 2, 1, 1] sage: [ ZZ(i)/ZZ(j) for i,j in CartesianProduct(range(1,5),range(1,5)) ] [1, 1/2, 1/3, 1/4, 2, 1, 2/3, 1/2, 3, 3/2, 1, 3/4, 4, 2, 4/3, 1] On Thursday, October 18, 2012 3:01:04 PM UTC+1, Ken Ribet wrote: > > Hi Sage Gurus, > > Am I doing something stupid here: > > sage: print 1/2 < 3/7 > sage: L=[] > sage: for i in range(2,3): > ... for j in range(1,2): > ... L.append([i,j]) > ... > sage: print L > sage: for P in L: > ... print P[1], P[0] > ... P[1]/P[0] < 3/7 > False > [[2, 1]] > 1 2 > True > > ---- > > In plain language: > > I ask sage whether 1/2 is less than 3/7, and sage tells me "false." > > I then create the list L = [[2,1]] and loop through L (which has only one > element). For P=[2,1], I ask sage whether P[1]/P[0] is less than 3/7 and > get "true". The conundrum is that P[1]/P[0] is 1/2, so mathematically I'm > getting the answers "false" and then "true" for the same question. > > So what's going on? I'm sure that there's a simple explanation. > > Thanks, > Ken -- You received this message because you are subscribed to the Google Groups "sage-support" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sage-support?hl=en.
