On Feb 15, 2008 9:57 PM, Jason Grout <[EMAIL PROTECTED]> wrote: > > > David Joyner wrote: > > On Fri, Feb 15, 2008 at 12:43 PM, John Cremona <[EMAIL PROTECTED]> wrote: > >> I think both/either of these are useful enough they should be > >> included. In David's code I noticed that he had to shift from > >> permutations starting at 1 to 0 and back, but Jason's code did not do > >> this. What magic is that? Either way, this particular issue needs to > >> be well documented... > > > > Done. The version below has a better docstring. It works not only > > for vectors and matrices but for sequences as well, so I renamed it > > simply perm_action: > > > > def perm_action(g,v): > > """ > > Returns permutation of rows g*v; also works on vectors > > (permuting coordinates). The code requires switching from > > i to i+1 (and back again) since the SymmetricGroup is, > > by convention, the symmetric group on the "letters" > > {1, 2, ..., n} (not {0, 1, ..., n-1}). > > > > EXAMPLES: > > sage: V = VectorSpace(GF(3),5) > > sage: v = V([0,1,2,0,1]) > > sage: G = SymmetricGroup(5) > > sage: g = G([(1,2,3)]) > > sage: perm_action(g,v) > > (1, 2, 0, 0, 1) > > sage: g = G([()]) > > sage: perm_action(g,v) > > (0, 1, 2, 0, 1) > > sage: g = G([(1,2,3,4,5)]) > > sage: perm_action(g,v) > > (1, 2, 0, 1, 0) > > sage: L = Sequence([1,2,3,4,5]) > > sage: perm_action(g,L) > > [2, 3, 1, 4, 5] > > sage: MS = MatrixSpace(GF(3),3,7) > > sage: A = MS([[1,0,0,0,1,1,0],[0,1,0,1,0,1,0],[0,0,0,0,0,0,1]]) > > sage: S5 = SymmetricGroup(5) > > sage: g = S5([(1,2,3)]) > > sage: A; perm_action(g,A) > > <BLANKLINE> > > [1 0 0 0 1 1 0] > > [0 1 0 1 0 1 0] > > [0 0 0 0 0 0 1] > > <BLANKLINE> > > [0 1 0 1 0 1 0] > > [0 0 0 0 0 0 1] > > [1 0 0 0 1 1 0] > > > > AUTHOR: David Joyner, licensed under the GPL v2 or greater. > > """ > > V = v.parent() > > n = len(list(v)) > > gv = [] > > for i in range(n): > > gv.append(v[g(i+1)-1]) > > return V(gv) > > > > I still don't have any idea where it should go... > > > Can we merge it with the code for g(listable)? I'm not sure if I was
I looked at this more carefully. The answer depends on the definition of "we". If "we" means me then maybe not. The _call_ method in PermGpElmt http://www.sagemath.org/hg/sage-main/file/7994ac1af415/sage/groups/perm_gps/permgroup_element.pyx is written in cython, which I'm not familiar with enough. I could probably add it to _r_action though with no problem. Does this sound okay? > clear in my response before: my point was that we have a specific case > already in the code for permutation group elements (the special case of > permuting a list). Your code is more general (it works for any listable > object). Can you patch the current code that was incorporated from the > patch on #750? > > If there is a 0-1 indexing issue, we could make it an option to g(listable). > > In this case, your examples would look like the following (with possibly > a argument added to adjust for 0 or 1 indexing). > > sage: V = VectorSpace(GF(3),5) > sage: v = V([0,1,2,0,1]) > sage: G = SymmetricGroup(5) > sage: g = G([(1,2,3)]) > sage: g(v) > (1, 2, 0, 0, 1) > sage: g = G([()]) > sage: g(v) > (0, 1, 2, 0, 1) > sage: g = G([(1,2,3,4,5)]) > sage: g(v) > (1, 2, 0, 1, 0) > sage: L = Sequence([1,2,3,4,5]) > sage: g(L) > [2, 3, 1, 4, 5] > sage: MS = MatrixSpace(GF(3),3,7) > sage: A = MS([[1,0,0,0,1,1,0],[0,1,0,1,0,1,0],[0,0,0,0,0,0,1]]) > sage: S5 = SymmetricGroup(5) > sage: g = S5([(1,2,3)]) > sage: A; g(A) > <BLANKLINE> > [1 0 0 0 1 1 0] > [0 1 0 1 0 1 0] > [0 0 0 0 0 0 1] > <BLANKLINE> > [0 1 0 1 0 1 0] > [0 0 0 0 0 0 1] > [1 0 0 0 1 1 0] > > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---