Skip to content

Commit c3befb5

Browse files
committed
use "positive" partial sums algorithm
1 parent 6ba0eaf commit c3befb5

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

src/sage/combinat/k_regular_sequence.py

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,36 @@ def partial_sums(self, include_n=False):
728728
1: [0 0]
729729
[0 1]},
730730
(1, 1))
731+
731732
sage: P = E.partial_sums(minimize=False)
732733
sage: P.linear_representation()
733-
((1, 0, -1, 0),
734-
Finite family {0: [ 0 1| 0 0]
735-
[ 0 2| 0 -1]
736-
[-----+-----]
737-
[ 0 0| 0 1]
738-
[ 0 0| 0 1],
739-
1: [0 1|0 0]
734+
((1, 0, 0, 0),
735+
Finite family {0: [0 1|0 0]
740736
[0 2|0 0]
741737
[---+---]
738+
[0 0|0 1]
739+
[0 0|0 1],
740+
1: [0 1|0 1]
741+
[0 2|0 1]
742+
[---+---]
742743
[0 0|0 0]
743744
[0 0|0 1]},
744-
(1, 1, 1, 1))
745+
(0, 0, 1, 1))
746+
747+
sage: P = E.partial_sums(include_n=True, minimize=False)
748+
sage: P.linear_representation()
749+
((1, 0, 1, 0),
750+
Finite family {0: [0 1|0 0]
751+
[0 2|0 0]
752+
[---+---]
753+
[0 0|0 1]
754+
[0 0|0 1],
755+
1: [0 1|0 1]
756+
[0 2|0 1]
757+
[---+---]
758+
[0 0|0 0]
759+
[0 0|0 1]},
760+
(0, 0, 1, 1))
745761
"""
746762
from itertools import chain
747763
from sage.matrix.constructor import Matrix
@@ -752,17 +768,21 @@ def partial_sums(self, include_n=False):
752768
A = P.alphabet()
753769
k = P.k
754770
dim = self.dimension()
755-
756-
B = {r: sum(self.mu[a] for a in A[r:]) for r in A}
757771
Z = zero_matrix(dim)
758-
B[k] = Z
772+
773+
z = A[0]
774+
assert z == 0
775+
B = {z: Z}
776+
for r in A:
777+
B[r+1] = B[r] + self.mu[r]
778+
C = B[k]
759779

760780
result = P.element_class(
761781
P,
762-
{r: Matrix.block([[B[0], -B[r + 1]], [Z, self.mu[r]]]) for r in A},
782+
{r: Matrix.block([[C, B[r]], [Z, self.mu[r]]]) for r in A},
763783
vector(chain(self.left,
764-
(dim * (0,) if include_n else -self.left))),
765-
vector(chain(self.right, self.right)))
784+
(dim * (0,) if not include_n else self.left))),
785+
vector(chain(dim * (0,), self.right)))
766786

767787
return result
768788

0 commit comments

Comments
 (0)