Skip to content

Commit

Permalink
37282: Fix RegularSequence.subsequence for zero sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
cheuberg committed Feb 10, 2024
1 parent 0c390a0 commit 87218b4
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/sage/combinat/regular_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,12 @@ def subsequence(self, a, b):
sage: S.regenerated().subsequence(1, -4)
2-regular sequence 0, 0, 0, 0, 1, 3, 6, 9, 12, 18, ...
Check that the zero sequence is handeled correctly (issue:`37282`)
::
sage: Seq2.zero().subsequence(1, 1)
2-regular sequence 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...
"""
from itertools import chain
from sage.rings.integer_ring import ZZ
Expand Down Expand Up @@ -835,14 +841,16 @@ def matrix_row(r, c):
d, f = rule[r, c]
return [self.mu[f] if d == j else zero_M for j in kernel]

# We explicitly set the ring when creating vectors in order to avoid
# problems with the zero sequence, see issue:`37282`.
result = P.element_class(
P,
{r: Matrix.block([matrix_row(r, c) for c in kernel])
for r in A},
vector(chain.from_iterable(
vector(P.coefficient_ring(), chain.from_iterable(
b.get(c, 0) * self.left
for c in kernel)),
vector(chain.from_iterable(
vector(P.coefficient_ring(), chain.from_iterable(
(self.coefficient_of_n(c, multiply_left=False) if c >= 0 else zero_R)
for c in kernel)))

Expand Down

0 comments on commit 87218b4

Please sign in to comment.