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...

>
>  John
>
>
>
>  On 15/02/2008, Jason Grout <[EMAIL PROTECTED]> wrote:
>  >
>  >  David Joyner wrote:
>  >  > Hi:
>  >  > The following function is useful for me and maybe for
>  >  > others. What is amusing is that I wrote it for vectors
>  >  > by it works equally well for matrices (and maybe
>  >  > other structures) unchanged.
>  >  > I'm happy to make a patch for it, if others are interested,
>  >  > but am not sure where it should go. Comments or criticisms?
>  >  >
>  >  > def perm_action_on_matrix(g,v):
>  >  >     """
>  >  >     Returns permutation of rows g*v; also works on vectors
>  >  >     (permuting coordinates).
>  >  >
>  >  >     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_on_vector(g,v)
>  >  >         (1, 2, 0, 0, 1)
>  >  >         sage: MS = MatrixSpace(GF(3),3,7)
>  >  >         sage: G = 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: G; perm_action_on_vector(g,G)
>  >  >         <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 think this is naturally related to #750, which added this functionality:
>  >
>  >
>  >  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: V(g(v.list()))
>  >
>  > (1, 2, 0, 0, 1)
>  >
>  >
>  > (g(list) does what your function does, but just takes and returns a
>  >  list; maybe it would be best to make g(list) really take g(listable) and
>  >  return the same type of object that it received).
>  >
>  >  The corresponding functionality for your matrices is:
>  >
>  >
>  >  sage: MS = MatrixSpace(GF(3),3,7)
>  >  sage: m = MS([[1,0,0,0,1,1,0],[0,1,0,1,0,1,0],[0,0,0,0,0,0,1]])
>  >
>  > sage: G = SymmetricGroup(5)
>  >  sage: G = SymmetricGroup(3)
>  >
>  > sage: g = G([(1,2,3)])
>  >
>  > sage: m; MS(g(m.rows()))
>  >
>  >
>  >  [1 0 0 0 1 1 0]
>  >  [0 1 0 1 0 1 0]
>  >  [0 0 0 0 0 0 1]
>  >
>  >
>  > [0 1 0 1 0 1 0]
>  >  [0 0 0 0 0 0 1]
>  >  [1 0 0 0 1 1 0]
>  >
>  >
>  >
>  > However, if m has more than three rows, we get an error.  In your
>  >  example, you have a permutation living in S5 acting on something with
>  >  only 3 rows by thinking of the permutation as living in S3 (and fixing 4
>  >  and 5).  Should we do that automatic coercion?
>  >
>  >  Thanks,
>  >
>  >
>  >  Jason
>  >
>  >
>  >
>  >
>  >
>  >
>  >  >
>  >
>
>
>  --
>  John Cremona
>
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to