-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_action.sage
33 lines (27 loc) · 928 Bytes
/
test_action.sage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from sage.categories.action import Action
from sage.structure.element import ModuleElement
from sage.modules.module import Module
import operator
class TwoVectors(Module):
def __init__(self):
Module.__init__(self, base = QQ)
self.Element = TwoVectorsElement
self.register_action(MatAction(MatrixSpace(QQ,2,2),self))
self._populate_coercion_lists_()
def _element_constructor_(self, x):
return TwoVectorsElement(self, x)
class TwoVectorsElement(ModuleElement):
def __init__(self, parent, x):
ModuleElement.__init__(self, parent)
self.val = (QQ**2)(x)
def __repr__(self):
return str(self.val)
class MatAction(Action):
def __init__(self,G,M):
Action.__init__(self,G,M,is_left = True,op = operator.mul)
def _call_(self,g,v):
return v.parent()(g * v.val)
V = TwoVectors()
v = V((1,2))
g = Matrix(QQ,2,2,[1,2,3,4])
w = g * v