Skip to content

Commit

Permalink
Trac #21319: recognizable series: hash, comparison, TestSuite
Browse files Browse the repository at this point in the history
- Implement hashing and comparison.
- Make TestSuite pass all tests.

See also meta ticket #21202.

URL: https://trac.sagemath.org/21319
Reported by: dkrenn
Ticket author(s): Daniel Krenn
Reviewer(s): Clemens Heuberger
  • Loading branch information
Release Manager committed May 16, 2022
2 parents 52b8e39 + a7ecb88 commit f723fbb
Show file tree
Hide file tree
Showing 2 changed files with 316 additions and 12 deletions.
45 changes: 42 additions & 3 deletions src/sage/combinat/k_regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def __getitem__(self, n, **kwds):
sage: W = Seq2.indices()
sage: M0 = Matrix([[1, 0], [0, 1]])
sage: M1 = Matrix([[0, -1], [1, 2]])
sage: S = Seq2((M0, M1), [0, 1], [1, 1])
sage: S = Seq2((M0, M1), vector([0, 1]), vector([1, 1]))
sage: S._mu_of_word_(W(0.digits(2))) == M0
True
sage: S._mu_of_word_(W(1.digits(2))) == M1
Expand Down Expand Up @@ -540,7 +540,8 @@ def shift_left(self, b=1, **kwds):
TESTS::
sage: C.shift_left(0) == C # not tested, #21319
sage: C.shift_left(0) == C
True
sage: C.shift_left(2).shift_right(2)
2-regular sequence 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, ...
"""
Expand Down Expand Up @@ -585,11 +586,14 @@ def shift_right(self, b=1, **kwds):
TESTS::
sage: C.shift_right(0) == C # not tested, #21319
sage: C.shift_right(0) == C
True
sage: C.shift_right().shift_left()
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
sage: C.shift_right(2).shift_left(2)
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
sage: _ == C
True
"""
return self.subsequence(1, -b, **kwds)

Expand Down Expand Up @@ -765,6 +769,21 @@ def partial_sums(self, include_n=False):
return result


def _pickle_kRegularSequenceSpace(k, coefficients, category):
r"""
Pickle helper.
TESTS::
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
sage: from sage.combinat.k_regular_sequence import _pickle_kRegularSequenceSpace
sage: _pickle_kRegularSequenceSpace(
....: Seq2.k, Seq2.coefficient_ring(), Seq2.category())
Space of 2-regular sequences over Integer Ring
"""
return kRegularSequenceSpace(k, coefficients, category=category)


class kRegularSequenceSpace(RecognizableSeriesSpace):
r"""
The space of `k`-regular Sequences over the given ``coefficient_ring``.
Expand Down Expand Up @@ -831,6 +850,13 @@ def __init__(self, k, *args, **kwds):
sage: kRegularSequenceSpace(3, ZZ)
Space of 3-regular sequences over Integer Ring
::
sage: from itertools import islice
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
sage: TestSuite(Seq2).run( # long time
....: elements=tuple(islice(Seq2.some_elements(), 4)))
.. SEEALSO::
:doc:`k-regular sequence <k_regular_sequence>`,
Expand All @@ -839,6 +865,19 @@ def __init__(self, k, *args, **kwds):
self.k = k
super(kRegularSequenceSpace, self).__init__(*args, **kwds)

def __reduce__(self):
r"""
Pickling support.
TESTS::
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
sage: loads(dumps(Seq2)) # indirect doctest
Space of 2-regular sequences over Integer Ring
"""
return _pickle_kRegularSequenceSpace, \
(self.k, self.coefficient_ring(), self.category())

def _repr_(self):
r"""
Return a representation string of this `k`-regular sequence space.
Expand Down
Loading

0 comments on commit f723fbb

Please sign in to comment.