[sage-support] Re: Either Sage is doing something wacky or I am.

2016-02-15 Thread Nils Bruin
On Monday, February 15, 2016 at 7:09:19 AM UTC-8, Harald Schilly wrote: > > That's your problem, using "range". > That's *our* problem too (and probably what set Jeremy on investigating this: *we're* executing the matrix construction with a "range". sage: g=lambda i,j: 0 if j==0 else i/j sage: m

[sage-support] Re: Either Sage is doing something wacky or I am.

2016-02-15 Thread Harald Schilly
That's your problem, using "range". On Monday, February 15, 2016 at 4:03:25 PM UTC+1, Jeremy Martin wrote: > > for p in range(3,4): > > That produces python integers while srange produces SageMath Integers. -- h -- You received this message because you are subscribed to the Google Groups

Re: [sage-support] Either Sage is doing something wacky or I am.

2016-02-15 Thread Jeroen Demeyer
On 2016-02-15 15:49, Jeremy Martin wrote: What is going on here? Those -1's are just incorrect. They are because you are dividing ordinary Python ints instead of Sage integers. Solution: ZZ(q)/ZZ(p) instead of q/p. But shouldn't these two pieces of code produce the same output? Yes, they sho

[sage-support] Either Sage is doing something wacky or I am.

2016-02-15 Thread Jeremy Martin
Try running this code in either the cell server or the cloud: f = lambda p,q: matrix(p-1, p-1, lambda i,j: q*(p-1)/p if i==j else -q/p) for p in range(3,4): for q in range(2,3): print f(p,q) print f(3,2) This produces the following output: [4/3 -1] [ -1 4/3] [ 4/3 -2/3] [-2/3 4/3]