Skip to content

Commit a57f92d

Browse files
committed
k-regular sequences: fix .one()
1 parent 32e6b77 commit a57f92d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,39 @@ def _n_to_index_(self, n):
918918
except OverflowError:
919919
raise ValueError('value {} of index is negative'.format(n)) from None
920920

921+
@cached_method
922+
def one(self):
923+
r"""
924+
Return the one element of this :class:`kRegularSequenceSpace`,
925+
i.e. the unique neutral element for `*` and also
926+
the embedding of the unique neutral element for `*` in the
927+
coefficient ring.
928+
929+
EXAMPLES::
930+
931+
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
932+
sage: O = Seq2.one(); O
933+
2-regular sequence 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
934+
sage: O.linear_representation()
935+
((1), Finite family {0: [1], 1: [0]}, (1))
936+
937+
TESTS:
938+
939+
sage: Seq2.one() is Seq2.one()
940+
True
941+
"""
942+
from sage.matrix.constructor import Matrix
943+
from sage.modules.free_module_element import vector
944+
945+
R = self.coefficient_ring()
946+
one = R.one()
947+
zero = R.zero()
948+
return self.element_class(self,
949+
[Matrix([[one]])]
950+
+ (self.k-1)*[Matrix([[zero]])],
951+
vector([one]),
952+
vector([one]))
953+
921954
def from_recurrence(self, *args, **kwds):
922955
r"""
923956
Construct the unique `k`-regular sequence which fulfills the given

0 commit comments

Comments
 (0)