Skip to content

Commit ab87262

Browse files
authored
Merge pull request #125 from RamanujanMachine/refactor/pcf-is-linear-recurrence
refactor/pcf-is-linear-recurrence
2 parents e8150c2 + 1103bcf commit ab87262

15 files changed

Lines changed: 127 additions & 244 deletions

ramanujantools/cmf/cmf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,8 @@ def walk( # noqa: F811
428428
r"""
429429
Returns a list of trajectorial walk multiplication matrices in the desired depths.
430430
431-
The walk operation is defined as $\prod_{i=0}^{n-1}M(s_0 + i \cdot t_0, ..., s_k + i \cdot t_k)$,
432-
where `M=trajectory_matrix(trajectory, start)`, and `n / size(trajectory)` (L1 size - total amount of steps)
431+
The walk operation is defined as $\prod_{i=0}^{n-1}M_{s, t}(n)$,
432+
where M is `trajectory_matrix(trajectory, start)`, s is `start` and t is `trajectory`.
433433
434434
Args:
435435
trajectory: A dict containing the amount of steps in each direction.

ramanujantools/cmf/known_cmfs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_cmf_zeta3():
2929

3030
def test_apery():
3131
cmf = known_cmfs.zeta3()
32-
pcf = cmf.trajectory_matrix({x: 1, y: 1}, {x: 0, y: 0}).as_pcf().pcf
32+
pcf = PCF(cmf.trajectory_matrix({x: 1, y: 1}, {x: 0, y: 0})).deflate_all()
3333
# This is Apery's PCF
3434
assert pcf == PCF(34 * n**3 + 51 * n**2 + 27 * n + 5, -(n**6))
3535

ramanujantools/limit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def walk_to_limit(
148148
initial_values: The initial values matrix, defaults to $e_1$ and $e_2$.
149149
final_projection: The final projection matrix, defaults to $e_{-1}$ and $e_{-1}$.
150150
"""
151-
previous_values = [depth - 1 for depth in iterations]
151+
previous_values = [max(depth - 1, 0) for depth in iterations]
152152
walk_iterations = sorted(list(set(iterations + previous_values)))
153153
walk_matrices = walk_function(walk_iterations)
154154

ramanujantools/linear_recurrence.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,9 @@ def parameters(self) -> set[sp.Symbol]:
143143

144144
def normalize(self) -> LinearRecurrence:
145145
"""
146-
Normalizes the recurrence
146+
Normalizes the recurrence, setting the leading coefficient to 1 by inflating it.
147147
"""
148-
relation = [p * self.denominator_lcm / self.gcd for p in self.relation]
149-
return LinearRecurrence(relation).simplify()
148+
return self.inflate(self.relation[0]).simplify()
150149

151150
def simplify(self) -> LinearRecurrence:
152151
"""
@@ -155,9 +154,10 @@ def simplify(self) -> LinearRecurrence:
155154
relation = [p * self.denominator_lcm / self.gcd for p in self.relation]
156155
return LinearRecurrence([sp.factor(p.simplify()) for p in relation])
157156

157+
@batched("iterations")
158158
def limit(
159-
self, iterations: int | list[int], start=0, initial_values: Matrix = None
160-
) -> Limit:
159+
self, iterations: Batchable[int], start=0, initial_values: Matrix = None
160+
) -> Batchable[Limit]:
161161
r"""
162162
Returns the Limit matrix of the recursion up to a certain depth
163163
"""

ramanujantools/linear_recurrence_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_gamma():
154154
)
155155

156156
unfolded = inflated.unfold_poly(n)
157-
pcf = unfolded.recurrence_matrix.as_pcf().pcf
157+
pcf = PCF(unfolded.recurrence_matrix).deflate_all()
158158
assert PCF(-2 * (n + 2), -((n + 1) ** 2)) == pcf
159159

160160

ramanujantools/matrix.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -343,20 +343,6 @@ def walk_function(iterations):
343343
iterations, walk_function, initial_values, final_projection
344344
)
345345

346-
def as_pcf(self, deflate_all=True):
347-
"""
348-
Converts a `Matrix` to an equivalent `PCF`
349-
350-
Args:
351-
deflate_all: if `True`, the function will also deflate the returned PCF to the fullest.
352-
Returns:
353-
a `PCFFRomMatrix` object, containing a `PCF` whose limit is equal to
354-
a mobius transform of the original `Matrix`.
355-
"""
356-
from ramanujantools.pcf import PCFFromMatrix
357-
358-
return PCFFromMatrix(self.as_polynomial(), deflate_all)
359-
360346
@staticmethod
361347
def poincare_poly(poly: sp.PurePoly) -> sp.PurePoly:
362348
"""

ramanujantools/matrix_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_as_companion_smaller_recursion():
178178
assert companion.is_companion()
179179
assert 2 == companion.rows
180180
# This is Apery's PCF
181-
assert companion.as_pcf().pcf == PCF(34 * n**3 + 51 * n**2 + 27 * n + 5, -(n**6))
181+
assert PCF(34 * n**3 + 51 * n**2 + 27 * n + 5, -(n**6)) == PCF(companion)
182182

183183

184184
def test_companion_coboundary_two_variables():

ramanujantools/pcf/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from .pcf import PCF
2-
from .pcf_from_matrix import PCFFromMatrix
32
from .hypergeometric import (
43
HypergeometricLimit,
54
Hypergeometric1F1Limit,
@@ -8,7 +7,6 @@
87

98
__all__ = [
109
"PCF",
11-
"PCFFromMatrix",
1210
"HypergeometricLimit",
1311
"Hypergeometric1F1Limit",
1412
"Hypergeometric2F1Limit",

ramanujantools/pcf/hypergeometric.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ def HypergeometricLimit(pcf: PCF):
1515
(1, 1): Hypergeometric1F1Limit,
1616
(1, 2): Hypergeometric2F1Limit,
1717
}
18-
if pcf.degree() not in supported_degrees:
18+
if pcf.degrees() not in supported_degrees:
1919
raise ValueError(
2020
(
21-
"Attempted to evaluate hypergeometric limit of {} of degree {}. "
21+
"Attempted to evaluate hypergeometric limit of {} of degrees {}. "
2222
"Supported degrees are {}"
23-
).format(pcf, pcf.degree(), supported_degrees.keys())
23+
).format(pcf, pcf.degrees(), supported_degrees.keys())
2424
)
25-
return supported_degrees[pcf.degree()](pcf)
25+
return supported_degrees[pcf.degrees()](pcf)
2626

2727

2828
class HypLimitInterface:

0 commit comments

Comments
 (0)