Skip to content

Commit c70f8db

Browse files
committed
Trac #21318: rmul/lmul preserve identity for multiplying by 1
1 parent c8c4927 commit c70f8db

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/sage/combinat/recognizable_series.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,10 @@ def _rmul_(self, other):
11941194
[0 1]},
11951195
(1, 1))
11961196
1197-
TESTS:
1197+
TESTS::
1198+
1199+
sage: 1 * E is E
1200+
True
11981201
11991202
We test that ``_rmul_`` and ``_lmul_`` are actually called::
12001203
@@ -1214,6 +1217,8 @@ def _rmul_(self, other):
12141217
_lmul_
12151218
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
12161219
"""
1220+
if other.is_one():
1221+
return self
12171222
P = self.parent()
12181223
return P.element_class(P, self.mu, other*self.left, self.right)
12191224

@@ -1246,7 +1251,10 @@ def _lmul_(self, other):
12461251
[0 1]},
12471252
(2, 2))
12481253
1249-
TESTS:
1254+
TESTS::
1255+
1256+
sage: E * 1 is E
1257+
True
12501258
12511259
The following is not tested, as `MS^i` for integers `i` does
12521260
not work, thus ``vector([m])`` fails. (See :trac:`21317` for
@@ -1264,6 +1272,8 @@ def _lmul_(self, other):
12641272
sage: M # not tested
12651273
sage: M.linear_representation() # not tested
12661274
"""
1275+
if other.is_one():
1276+
return self
12671277
P = self.parent()
12681278
return P.element_class(P, self.mu, self.left, self.right*other)
12691279

0 commit comments

Comments
 (0)