# Ticket #4513: trac-4513_matrix_action_on_polynomials.patch

File trac-4513_matrix_action_on_polynomials.patch, 3.0 KB (added by SimonKing, 11 years ago)

Replaces the other patches

• ## sage/groups/matrix_gps/matrix_group_element.py

```# HG changeset patch
# User Simon King <simon.king@nuigalway.ie>
# Date 1279373034 -3600
# Node ID ef2105b3be9a022dfac0dda1f2101175c5bcff27
# Parent  5e9277b8e2ec15c4daae0d1e00c48276dab75540
#4513: Implement proper left and right action of matrix groups on polynomials, rather than doing skalar multiplication

diff -r 5e9277b8e2ec -r ef2105b3be9a sage/groups/matrix_gps/matrix_group_element.py```
 a def _act_on_(self, x, self_on_left): """ EXAMPLES:: EXAMPLES: Left and right action on a vector space:: sage: G = GL(4,7) sage: G.0 * vector([1,2,3,4]) (3, 2, 3, 4) sage: g = G.1 sage: v * g == v * g.matrix()   # indirect doctest True sage: (G.0*G.1)*v == G.0*(G.1*v) True sage: v*(G.0*G.1) == (v*G.0)*G.1 True Left and right action on a polynomial ring:: sage: R. = GF(7)[] sage: G.1 [6 0 0 1] [6 0 0 0] [0 6 0 0] [0 0 6 0] sage: G.1*a -a - b sage: a*G.1 -a + d sage: G.0*(G.1*a) == (G.0*G.1)*a True AUTHOR: - Simon King (2010-07): Action on polynomial rings. """ # if it is a matrix group element or is in the base ring, # then multiplication should be implemented in _mul_ if not is_MatrixGroupElement(x) and x not in self.parent().base_ring(): from sage.rings.polynomial.polynomial_element import is_Polynomial from sage.rings.polynomial.multi_polynomial import is_MPolynomial if is_Polynomial(x) or is_MPolynomial(x): try: R = x.parent() try: D = self.__action_cache_ except AttributeError: try: D = self.__action_cache_ = {} except AttributeError: D = {} f = D.get((R,self,self_on_left)) if f is None: from sage.all import add if self_on_left: f = R.hom([add([a*b for a,b in zip(L,R.gens())]) for L in self.__mat.transpose().rows()]) else: f = R.hom([add([a*b for a,b in zip(L,R.gens())]) for L in self.__mat.rows()]) D[R,self,self_on_left] = f return f(x) except (AttributeError, ValueError, TypeError): pass try: if self_on_left: return self.matrix() * x