From b76bf4e6dc30f0363321188835baa2db66a8dc7c Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Wed, 24 Aug 2016 09:21:17 +0200 Subject: [PATCH] factor out subsequence to separat ticket --- src/sage/combinat/k_regular_sequence.py | 162 ------------------------ 1 file changed, 162 deletions(-) diff --git a/src/sage/combinat/k_regular_sequence.py b/src/sage/combinat/k_regular_sequence.py index c079f212135..78f10813798 100644 --- a/src/sage/combinat/k_regular_sequence.py +++ b/src/sage/combinat/k_regular_sequence.py @@ -250,168 +250,6 @@ def __iter__(self): return iter(self[n] for n in count()) - def subsequence(self, a, b, minimize=True): - r""" - Return the subsequence with indices `an+b` of this - `k`-regular sequence. - - INPUT: - - - ``a`` -- a nonnegative integer. - - - ``b`` -- an integer. - - - ``minimize`` -- (default: ``True``) a boolean. If set, then - :meth:`minimized` is called after the addition. - - OUTPUT: - - A :class:`kRegularSequence`. - - EXAMPLES:: - - sage: Seq2 = kRegularSequenceSpace(2, ZZ) - sage: C = Seq2((Matrix([[2, 0], [2, 1]]), Matrix([[0, 1], [-2, 3]])), - ....: vector([1, 0]), vector([0, 1])) - sage: C - 2-regular sequence 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ... - - sage: C.subsequence(2, 0) - 2-regular sequence 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, ... - - sage: S = C.subsequence(3, 1) - sage: S - 2-regular sequence 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, ... - sage: S.mu[0], S.mu[1], S.left, S.right - ( - [ 0 1] [ 6 -2] - [-2 3], [10 -3], (1, 0), (1, 1) - ) - - sage: C.subsequence(3, 2) - 2-regular sequence 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, ... - - :: - - sage: S = C.subsequence(1, -1) - sage: S - 2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ... - sage: S.mu[0], S.mu[1], S.left, S.right - ( - [ 0 1 0] [ -2 2 0] - [-2 3 0] [ 0 0 1] - [-4 4 1], [ 12 -12 5], (1, 0, 0), (0, 0, 1) - ) - - TESTS:: - - sage: C.subsequence(0, 4) - 2-regular sequence 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ... - sage: C.subsequence(1, 0) is C - True - - The following test that the range for `c` in the code - is sufficient:: - - sage: C.subsequence(1, -1, minimize=False) - 2-regular sequence 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, ... - sage: C.subsequence(1, -2, minimize=False) - 2-regular sequence 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, ... - sage: C.subsequence(2, -1, minimize=False) - 2-regular sequence 0, 1, 3, 5, 7, 9, 11, 13, 15, 17, ... - sage: C.subsequence(2, -2, minimize=False) - 2-regular sequence 0, 0, 2, 4, 6, 8, 10, 12, 14, 16, ... - - sage: C.subsequence(2, 21, minimize=False) - 2-regular sequence 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, ... - sage: C.subsequence(2, 20, minimize=False) - 2-regular sequence 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, ... - sage: C.subsequence(2, 19, minimize=False) - 2-regular sequence 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, ... - sage: C.subsequence(2, -9, minimize=False) - 2-regular sequence 0, 0, 0, 0, 0, 1, 3, 5, 7, 9, ... - - sage: C.subsequence(3, 21, minimize=False) - 2-regular sequence 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, ... - sage: C.subsequence(3, 20, minimize=False) - 2-regular sequence 20, 23, 26, 29, 32, 35, 38, 41, 44, 47, ... - sage: C.subsequence(3, 19, minimize=False) - 2-regular sequence 19, 22, 25, 28, 31, 34, 37, 40, 43, 46, ... - sage: C.subsequence(3, 18, minimize=False) - 2-regular sequence 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, ... - - sage: C.subsequence(10, 2, minimize=False) - 2-regular sequence 2, 12, 22, 32, 42, 52, 62, 72, 82, 92, ... - sage: C.subsequence(10, 1, minimize=False) - 2-regular sequence 1, 11, 21, 31, 41, 51, 61, 71, 81, 91, ... - sage: C.subsequence(10, 0, minimize=False) - 2-regular sequence 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, ... - sage: C.subsequence(10, -1, minimize=False) - 2-regular sequence 0, 9, 19, 29, 39, 49, 59, 69, 79, 89, ... - sage: C.subsequence(10, -2, minimize=False) - 2-regular sequence 0, 8, 18, 28, 38, 48, 58, 68, 78, 88, ... - - :: - - sage: C.subsequence(-1, 0) - Traceback (most recent call last): - ... - ValueError: a=-1 is not nonnegative. - """ - from sage.rings.integer_ring import ZZ - a = ZZ(a) - b = ZZ(b) - - if a == 0: - return self[b] * self.parent().one_hadamard() - elif a == 1 and b == 0: - return self - elif a < 0: - raise ValueError('a={} is not nonnegative.'.format(a)) - - from sage.arith.srange import srange - from sage.matrix.constructor import Matrix - from sage.modules.free_module_element import vector - P = self.parent() - - k = self.parent().k - dim = self.dimension() - min_c = min(b, 0) - max_c = max(a, a + (b-1)//k + 1) - range_c = srange(min_c, max_c) - # We use the 'if' below instead of the less efficient - # max_c = max(a, a + b) - # or - # max_c = max(a, a + (b-1)//k + 1, b + 1) - # above. - if b not in range_c: - range_c.append(b) - b = max_c - kernel = tuple((i, c) for c in range_c for i in srange(dim)) - - def pad(T, d): - dd = d - min_c - return dd*dim*(0,) + T + (len(range_c)-1-dd)*dim*(0,) - def mu_line(r, i, c): - d, f = (a*r + c).quo_rem(k) - assert d in range_c - return pad(tuple(self.mu[f].rows()[i]), d) - - result = P.element_class( - P, - dict((r, Matrix(tuple(mu_line(r, i, c) for i, c in kernel))) - for r in srange(k)), - vector(pad(tuple(self.left), b)), - vector(sum((tuple(self.__getitem__(c, multiply_left=False)) - if c >= 0 else dim*(ZZ(0),) - for c in range_c), tuple()))) - - if minimize: - return result.minimized() - else: - return result - - class kRegularSequenceSpace(RecognizableSeriesSpace): r""" The space of `k`-regular Sequences over the given ``coefficients``.