@@ -1105,6 +1105,11 @@ def minimized(self):
1105
1105
sage: all(c == d and v == w
1106
1106
....: for (c, v), (d, w) in islice(zip(iter(S), iter(M)), 20))
1107
1107
True
1108
+
1109
+ TESTS::
1110
+
1111
+ sage: Rec((Matrix([[0]]), Matrix([[0]])), vector([1]), vector([0])).minimized().linear_representation()
1112
+ ((), Finite family {0: [], 1: []}, ())
1108
1113
"""
1109
1114
return self ._minimized_right_ ()._minimized_left_ ()
1110
1115
@@ -1341,6 +1346,11 @@ def _rmul_(self, other):
1341
1346
sage: 1 * E is E
1342
1347
True
1343
1348
1349
+ ::
1350
+
1351
+ sage: 0 * E is Seq2.zero()
1352
+ True
1353
+
1344
1354
We test that ``_rmul_`` and ``_lmul_`` are actually called::
1345
1355
1346
1356
sage: def print_name(f):
@@ -1359,9 +1369,11 @@ def _rmul_(self, other):
1359
1369
_lmul_
1360
1370
2-regular sequence 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, ...
1361
1371
"""
1372
+ P = self .parent ()
1373
+ if other .is_zero ():
1374
+ return P ._zero_ ()
1362
1375
if other .is_one ():
1363
1376
return self
1364
- P = self .parent ()
1365
1377
return P .element_class (P , self .mu , other * self .left , self .right )
1366
1378
1367
1379
def _lmul_ (self , other ):
@@ -1398,6 +1410,11 @@ def _lmul_(self, other):
1398
1410
sage: E * 1 is E
1399
1411
True
1400
1412
1413
+ ::
1414
+
1415
+ sage: E * 0 is Seq2.zero()
1416
+ True
1417
+
1401
1418
The following is not tested, as `MS^i` for integers `i` does
1402
1419
not work, thus ``vector([m])`` fails. (See :trac:`21317` for
1403
1420
details.)
@@ -1414,9 +1431,11 @@ def _lmul_(self, other):
1414
1431
sage: M # not tested
1415
1432
sage: M.linear_representation() # not tested
1416
1433
"""
1434
+ P = self .parent ()
1435
+ if other .is_zero ():
1436
+ return P ._zero_ ()
1417
1437
if other .is_one ():
1418
1438
return self
1419
- P = self .parent ()
1420
1439
return P .element_class (P , self .mu , self .left , self .right * other )
1421
1440
1422
1441
@minimize_result
@@ -1913,6 +1932,28 @@ def some_elements(self):
1913
1932
break
1914
1933
yield self (mu , * LR )
1915
1934
1935
+ @cached_method
1936
+ def _zero_ (self ):
1937
+ r"""
1938
+ Return the zero element of this :class:`RecognizableSeriesSpace`,
1939
+ i.e. the unique neutral element for `+`.
1940
+
1941
+ TESTS::
1942
+
1943
+ sage: Rec = RecognizableSeriesSpace(ZZ, [0, 1])
1944
+ sage: Z = Rec._zero_(); Z
1945
+ 0
1946
+ sage: Z.linear_representation()
1947
+ ((), Finite family {0: [], 1: []}, ())
1948
+ """
1949
+ from sage .matrix .constructor import Matrix
1950
+ from sage .modules .free_module_element import vector
1951
+ from sage .sets .family import Family
1952
+
1953
+ return self .element_class (
1954
+ self , Family (self .alphabet (), lambda a : Matrix ()),
1955
+ vector ([]), vector ([]))
1956
+
1916
1957
@cached_method
1917
1958
def one_hadamard (self ):
1918
1959
r"""
@@ -1985,13 +2026,7 @@ def _element_constructor_(self, data,
1985
2026
ValueError: left or right vector is None
1986
2027
"""
1987
2028
if isinstance (data , int ) and data == 0 :
1988
- from sage .matrix .constructor import Matrix
1989
- from sage .modules .free_module_element import vector
1990
- from sage .sets .family import Family
1991
-
1992
- return self .element_class (
1993
- self , Family (self .alphabet (), lambda a : Matrix ()),
1994
- vector ([]), vector ([]))
2029
+ return self ._zero_ ()
1995
2030
1996
2031
if type (data ) == self .element_class and data .parent () == self :
1997
2032
element = data
0 commit comments