Skip to content

Commit

Permalink
sagemathgh-37283: Fix RegularSequence.subsequence for zero sequence
Browse files Browse the repository at this point in the history
    
<!-- ^^^^^
Please provide a concise, informative and self-explanatory title.
Don't put issue numbers in there, do this in the PR body below.
For example, instead of "Fixes sagemath#1234" use "Introduce new method to
calculate 1+1"
-->
<!-- Describe your changes here in detail -->

<!-- Why is this change required? What problem does it solve? -->
<!-- If this PR resolves an open issue, please link to it here. For
example "Fixes sagemath#12345". -->
<!-- If your change requires a documentation PR, please link it
appropriately. -->
Fixes sagemath#37282

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->
<!-- If your change requires a documentation PR, please link it
appropriately -->
<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
<!-- Feel free to remove irrelevant items. -->

- [x] The title is concise, informative, and self-explanatory.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [ ] I have updated the documentation accordingly.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on
- sagemath#12345: short description why this is a dependency
- sagemath#34567: ...
-->

<!-- If you're unsure about any of these, don't hesitate to ask. We're
here to help! -->
Cc: @dkrenn
    
URL: sagemath#37283
Reported by: cheuberg
Reviewer(s): cheuberg, Sebastian A. Spindler
  • Loading branch information
Release Manager committed Feb 17, 2024
2 parents 8b7b01b + 6b3480e commit ea91293
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 handled 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 ea91293

Please sign in to comment.