Thanks Doug. I hadn't realized that the output of mod(m,n) is in the integers mod n.
On Monday, June 11, 2012 8:26:34 AM UTC-6, D. S. McNeil wrote: > > > So is this a bug, or is there some subtle aspect of the set { ... } > > constuction that I'm misusing? > > Oy, that's cute! The second matrix index lives in Zmod(5), and behaves as > such: > > sage: wA = matrix(QuadraticField(2),5,{(j,mod(j+1,5)):1 for j in > range(5)}) > sage: wA.dict() > {(0, 1): 1, (1, 2): 1, (3, 4): 1, (2, 3): 1, (4, 0): 1} > sage: for key in wA.dict(): > ....: print key, map(parent, key) > ....: > (0, 1) [<type 'int'>, Ring of integers modulo 5] > (1, 2) [<type 'int'>, Ring of integers modulo 5] > (3, 4) [<type 'int'>, Ring of integers modulo 5] > (2, 3) [<type 'int'>, Ring of integers modulo 5] > (4, 0) [<type 'int'>, Ring of integers modulo 5] > > and so when _list() goes to build the flattened list, its arithmetic > here doesn't hold: > > v[i*self._ncols + j] = x > > For example (diagnostic print statements mine): > > sage: wA > nrows 5 ncols 5 with parents <type 'int'> <type 'int'> > [((0, 1), 1), ((1, 2), 1), ((3, 4), 1), ((2, 3), 1), ((4, 0), 1)] > i is 0 with parent <type 'int'> > j is 1 with parent Ring of integers modulo 5 > x is 1 with parent Number Field in a with defining polynomial x^2 - 2 > 0 1 1 > v is now [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0] > i is 1 with parent <type 'int'> > j is 2 with parent Ring of integers modulo 5 > x is 1 with parent Number Field in a with defining polynomial x^2 - 2 > 1 2 2 > v is now [0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0] > i is 3 with parent <type 'int'> > j is 4 with parent Ring of integers modulo 5 > x is 1 with parent Number Field in a with defining polynomial x^2 - 2 > 3 4 4 > v is now [0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0] > i is 2 with parent <type 'int'> > j is 3 with parent Ring of integers modulo 5 > x is 1 with parent Number Field in a with defining polynomial x^2 - 2 > 2 3 3 > v is now [0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0] > i is 4 with parent <type 'int'> > j is 0 with parent Ring of integers modulo 5 > x is 1 with parent Number Field in a with defining polynomial x^2 - 2 > 4 0 0 > v is now [1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0] > [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1] > computing rows: nr 5 nc 5 > [1 1 1 1 1] > [0 0 0 0 0] > [0 0 0 0 0] > [0 0 0 0 0] > [0 0 0 0 0] > sage: > > I don't know if there's a use case for generic (i.e. non-int) indices > or not. I've never needed them myself, but maybe there's a reason we > don't __index__/int the inputs? > > In the meantime, > > matrix(QuadraticField(2),5,{(j,int(mod(j+1,5))):1 for j in range(5)}) > > should work. > > > > Doug > -- 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