Skip to content

Commit 1b3ddbd

Browse files
author
Release Manager
committed
gh-36001: regular sequences: use "positive" partial sums algorithm Implement a different algorithm to be used by method `.partial_sums` of a `kRegularSequence`. The new algorithm for partial summation has the advantage that only positive signs are used, which is somehow more "naturally" (compared to the existing algorithm that is kind of subtractive). ### 📝 Checklist - [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. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies None. URL: #36001 Reported by: Daniel Krenn Reviewer(s): cheuberg
2 parents 6617b49 + c3befb5 commit 1b3ddbd

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
@@ -1250,20 +1250,36 @@ def partial_sums(self, include_n=False):
12501250
1: [0 0]
12511251
[0 1]},
12521252
(1, 1))
1253+
12531254
sage: P = E.partial_sums(minimize=False)
12541255
sage: P.linear_representation()
1255-
((1, 0, -1, 0),
1256-
Finite family {0: [ 0 1| 0 0]
1257-
[ 0 2| 0 -1]
1258-
[-----+-----]
1259-
[ 0 0| 0 1]
1260-
[ 0 0| 0 1],
1261-
1: [0 1|0 0]
1256+
((1, 0, 0, 0),
1257+
Finite family {0: [0 1|0 0]
1258+
[0 2|0 0]
1259+
[---+---]
1260+
[0 0|0 1]
1261+
[0 0|0 1],
1262+
1: [0 1|0 1]
1263+
[0 2|0 1]
1264+
[---+---]
1265+
[0 0|0 0]
1266+
[0 0|0 1]},
1267+
(0, 0, 1, 1))
1268+
1269+
sage: P = E.partial_sums(include_n=True, minimize=False)
1270+
sage: P.linear_representation()
1271+
((1, 0, 1, 0),
1272+
Finite family {0: [0 1|0 0]
12621273
[0 2|0 0]
12631274
[---+---]
1275+
[0 0|0 1]
1276+
[0 0|0 1],
1277+
1: [0 1|0 1]
1278+
[0 2|0 1]
1279+
[---+---]
12641280
[0 0|0 0]
12651281
[0 0|0 1]},
1266-
(1, 1, 1, 1))
1282+
(0, 0, 1, 1))
12671283
"""
12681284
from itertools import chain
12691285
from sage.matrix.constructor import Matrix
@@ -1274,17 +1290,21 @@ def partial_sums(self, include_n=False):
12741290
A = P.alphabet()
12751291
k = P.k
12761292
dim = self.dimension()
1277-
1278-
B = {r: sum(self.mu[a] for a in A[r:]) for r in A}
12791293
Z = zero_matrix(dim)
1280-
B[k] = Z
1294+
1295+
z = A[0]
1296+
assert z == 0
1297+
B = {z: Z}
1298+
for r in A:
1299+
B[r+1] = B[r] + self.mu[r]
1300+
C = B[k]
12811301

12821302
result = P.element_class(
12831303
P,
1284-
{r: Matrix.block([[B[0], -B[r + 1]], [Z, self.mu[r]]]) for r in A},
1304+
{r: Matrix.block([[C, B[r]], [Z, self.mu[r]]]) for r in A},
12851305
vector(chain(self.left,
1286-
(dim * (0,) if include_n else -self.left))),
1287-
vector(chain(self.right, self.right)))
1306+
(dim * (0,) if not include_n else self.left))),
1307+
vector(chain(dim * (0,), self.right)))
12881308

12891309
return result
12901310

0 commit comments

Comments
 (0)