Skip to content

Commit c8c4927

Browse files
committed
Trac #21318: fix rmul/lmul issues
1 parent e302a5e commit c8c4927

File tree

1 file changed

+46
-14
lines changed

1 file changed

+46
-14
lines changed

src/sage/combinat/recognizable_series.py

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
from sage.misc.cachefunc import cached_method
8181
from sage.misc.superseded import experimental
82-
from sage.structure.element import Element
82+
from sage.structure.element import ModuleElement
8383
from sage.structure.parent import Parent
8484
from sage.structure.unique_representation import UniqueRepresentation
8585

@@ -368,7 +368,7 @@ def minimized(self, *args, **kwds):
368368
return minimized
369369

370370

371-
class RecognizableSeries(Element):
371+
class RecognizableSeries(ModuleElement):
372372
def __init__(self, parent, mu, left, right):
373373
r"""
374374
A recognizable series.
@@ -1183,19 +1183,39 @@ def _rmul_(self, other):
11831183
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
11841184
sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),
11851185
....: vector([1, 0]), vector([1, 1]))
1186-
sage: M = E * 2 # indirect doctest
1186+
sage: M = 2 * E # indirect doctest
11871187
sage: M
11881188
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
11891189
sage: M.linear_representation()
1190-
((1, 0),
1190+
((2, 0),
11911191
Finite family {0: [0 1]
11921192
[0 1],
11931193
1: [0 0]
11941194
[0 1]},
1195-
(2, 2))
1195+
(1, 1))
1196+
1197+
TESTS:
1198+
1199+
We test that ``_rmul_`` and ``_lmul_`` are actually called::
1200+
1201+
sage: def print_name(f):
1202+
....: def f_with_printed_name(*args, **kwds):
1203+
....: print(f.__name__)
1204+
....: return f(*args, **kwds)
1205+
....: return f_with_printed_name
1206+
1207+
sage: E._rmul_ = print_name(E._rmul_)
1208+
sage: E._lmul_ = print_name(E._lmul_)
1209+
sage: 2 * E
1210+
_rmul_
1211+
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
1212+
sage: E * 2
1213+
_lmul_
1214+
_lmul_
1215+
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
11961216
"""
11971217
P = self.parent()
1198-
return P.element_class(P, self.mu, self.left, self.right*other)
1218+
return P.element_class(P, self.mu, other*self.left, self.right)
11991219

12001220
def _lmul_(self, other):
12011221
r"""
@@ -1210,11 +1230,28 @@ def _lmul_(self, other):
12101230
12111231
A :class:`RecognizableSeries`
12121232
1213-
EXAMPLES:
1233+
EXAMPLES::
1234+
1235+
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
1236+
sage: E = Seq2((Matrix([[0, 1], [0, 1]]), Matrix([[0, 0], [0, 1]])),
1237+
....: vector([1, 0]), vector([1, 1]))
1238+
sage: M = E * 2 # indirect doctest
1239+
sage: M
1240+
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
1241+
sage: M.linear_representation()
1242+
((1, 0),
1243+
Finite family {0: [0 1]
1244+
[0 1],
1245+
1: [0 0]
1246+
[0 1]},
1247+
(2, 2))
1248+
1249+
TESTS:
12141250
12151251
The following is not tested, as `MS^i` for integers `i` does
12161252
not work, thus ``vector([m])`` fails. (See :trac:`21317` for
12171253
details.)
1254+
12181255
::
12191256
12201257
sage: MS = MatrixSpace(ZZ,2,2)
@@ -1225,15 +1262,10 @@ def _lmul_(self, other):
12251262
sage: S # not tested
12261263
sage: M = m * S # not tested indirect doctest
12271264
sage: M # not tested
1228-
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
1229-
sage: M.mu[0], M.mu[1], M.left, M.right # not tested
1230-
(
1231-
[0 1] [0 0]
1232-
[0 1], [0 1], (1, 0), (2, 2)
1233-
)
1265+
sage: M.linear_representation() # not tested
12341266
"""
12351267
P = self.parent()
1236-
return P.element_class(P, self.mu, other*self.left, self.right)
1268+
return P.element_class(P, self.mu, self.left, self.right*other)
12371269

12381270
@minimize_result
12391271
def hadamard_product(self, other):

0 commit comments

Comments
 (0)