Ask Your Question

How to define group actions on sagemath?

asked 2022-02-07 04:56:38 +0200

anonymous user


updated 2022-02-07 07:14:04 +0200

slelievre gravatar image

Hello everyone, I hope you are well.

I have the following problem and I'm having difficulties to make this implementation in sage.


Consider $f \in \mathbb{R}[x,y]$ and $M \in M_{2}(\mathbb{R})$.

How can I implement the $M \cdot f (x,y)=f(M^{-1}(x,y))$ group action in Sage?

I took a look at the link:

but I couldn't understand much.

I thank you for your attention.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2022-02-07 11:07:13 +0200

rburing gravatar image

Here's an Action class:

from sage.categories.action import Action
from sage.groups.matrix_gps.matrix_group import is_MatrixGroup
from sage.rings.polynomial.multi_polynomial_ring import is_MPolynomialRing

class InverseLinearMapSubstitutionAction(Action):
    def __init__(self, G, S):
        if not is_MatrixGroup(G):
            raise TypeError("Not a matrix group: %s" % G)
        if not is_MPolynomialRing(S):
            raise TypeError("Not a multivariate polynomial ring: %s" % S)
        if not == S.ngens():
            raise ValueError("Degree of matrix group (%d) does not match number of generators of polynomial ring (%d)" % (, S.ngens()))
        if not S.base_ring().has_coerce_map_from(G.base_ring()):
            raise ValueError("Base rings not compatible")
        super().__init__(G, S, is_left=True, op=operator.mul)

    def _act_(self, g, f):
        return f(*(g.inverse() * vector(self.domain(), self.domain().gens())))

    def _repr_name_(self):
        return "inverse linear map substitution action"

It works:

sage: R.<x,y> = PolynomialRing(QQ)
sage: G = GL(2, QQ)
sage: a = InverseLinearMapSubstitutionAction(G, R); a
Left inverse linear map substitution action by General Linear Group of degree 2 over Rational Field on Multivariate Polynomial Ring in x, y over Rational Field
sage: M = Matrix(QQ, [[0,-1],[1,0]])
sage: f = x + y
sage: a(M, f)
-x + y

The next step to get the notation M*f working would be to call register_action on R. However M*f is already defined to be a matrix over the polynomial ring, and I don't know how to undo or get around this.

edit flag offensive delete link more


Thank you, this helps a lot.

rafael gravatar imagerafael ( 2022-02-07 16:46:28 +0200 )edit

answered 2022-02-07 07:19:50 +0200

slelievre gravatar image

The link you provide explains how to allow using g * f to let g act on f.

Here is a way to define the action that does not use that.

It requires typing act(g, f) rather than g * f.

Define the action:

def act(g, f):
    Act by this invertible matrix ``g`` on this polynomial ``f``
    by ``g⋅f(x) = f(h(x))`` where ``h`` is the inverse of ``g``.
    M = f.parent()
    return f(*(g.inverse() * vector(M, M.gens())))

Use it:

sage: R.<x, y> = QQ['x, y']
sage: G = GL(2, QQ)
sage: act = GeneralLinearGroupAction(G, R)
sage: f = x + y
sage: g = G([1, 2, 3, 5])
sage: act(g, f)
-2*x + y

Hope someone can say more on registering the group action so that g * f returns the same as act(g, f).

edit flag offensive delete link more


Thank you, this helps a lot.

rafael gravatar imagerafael ( 2022-02-07 16:46:21 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2022-02-07 02:58:51 +0200

Seen: 423 times

Last updated: Feb 07 '22