Skip to content

Commit 26e2d6f

Browse files
committed
Trac #21325 review comment 19: shift_left, shift_right
1 parent 96df7b3 commit 26e2d6f

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,98 @@ def subsequence(self, a, b):
520520

521521
return result
522522

523+
def shift_left(self, b=1, **kwds):
524+
r"""
525+
Return the sequence obtained by shifting
526+
this `k`-regular sequence `b` steps to the left.
527+
528+
INPUT:
529+
530+
- ``b`` -- an integer
531+
532+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
533+
If ``True``, then :meth:`minimized` is called after the operation,
534+
if ``False``, then not. If this argument is ``None``, then
535+
the default specified by the parent's ``minimize_results`` is used.
536+
537+
OUTPUT:
538+
539+
A :class:`kRegularSequence`
540+
541+
.. NOTE::
542+
543+
If `b` is negative (i.e., actually a right-shift), then the
544+
coefficients when accessing negative indices are `0`.
545+
546+
EXAMPLES::
547+
548+
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
549+
sage: C = Seq2((Matrix([[2, 0], [0, 1]]), Matrix([[2, 1], [0, 1]])),
550+
....: vector([1, 0]), vector([0, 1])); C
551+
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
552+
553+
sage: C.shift_left()
554+
2-regular sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
555+
sage: C.shift_left(3)
556+
2-regular sequence 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...
557+
sage: C.shift_left(-2)
558+
2-regular sequence 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, ...
559+
560+
TESTS:
561+
562+
sage: C.shift_left(0) == C # not tested, #21319
563+
sage: C.shift_left(2).shift_right(2)
564+
2-regular sequence 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, ...
565+
"""
566+
return self.subsequence(1, b, **kwds)
567+
568+
def shift_right(self, b=1, **kwds):
569+
r"""
570+
Return the sequence obtained by shifting
571+
this `k`-regular sequence `b` steps to the right.
572+
573+
INPUT:
574+
575+
- ``b`` -- an integer
576+
577+
- ``minimize`` -- (default: ``None``) a boolean or ``None``.
578+
If ``True``, then :meth:`minimized` is called after the operation,
579+
if ``False``, then not. If this argument is ``None``, then
580+
the default specified by the parent's ``minimize_results`` is used.
581+
582+
OUTPUT:
583+
584+
A :class:`kRegularSequence`
585+
586+
.. NOTE::
587+
588+
If `b` is positive (i.e., indeed a right-shift), then the
589+
coefficients when accessing negative indices are `0`.
590+
591+
EXAMPLES::
592+
593+
sage: Seq2 = kRegularSequenceSpace(2, ZZ)
594+
sage: C = Seq2((Matrix([[2, 0], [0, 1]]), Matrix([[2, 1], [0, 1]])),
595+
....: vector([1, 0]), vector([0, 1])); C
596+
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
597+
598+
sage: C.shift_right()
599+
2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ...
600+
sage: C.shift_right(3)
601+
2-regular sequence 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, ...
602+
sage: C.shift_right(-2)
603+
2-regular sequence 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...
604+
605+
TESTS:
606+
607+
sage: C.shift_right(0) == C # not tested, #21319
608+
sage: C.shift_right().shift_left()
609+
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
610+
sage: C.shift_right(2).shift_left(2)
611+
2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ...
612+
"""
613+
return self.subsequence(1, -b, **kwds)
614+
523615
def backward_differences(self, **kwds):
524616
r"""
525617
Return the sequence of backward differences of this

0 commit comments

Comments
 (0)