Skip to content

Commit 74cfc8d

Browse files
committed
Rename confusing variables
1 parent 7b9ed5d commit 74cfc8d

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

ramanujantools/asymptotics/reducer.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,22 +223,24 @@ def shear(self) -> None:
223223
Used when the leading matrix is nilpotent, this shifts the polynomial degrees
224224
of the variables to expose the hidden sub-exponential growths.
225225
"""
226-
g = self._compute_shear_slope()
226+
slope = self._compute_shear_slope()
227227

228-
if g == sp.S.Zero:
228+
if slope == sp.S.Zero:
229229
self._check_eigenvalue_blindness(self.M.coeffs[0][0, 0])
230230
self._is_reduced = True
231231
return
232232

233-
if not g.is_integer:
234-
g, b = g.as_numer_denom()
235-
self.M, self.S_total = self.M.ramify(b), self.S_total.ramify(b)
236-
self.p *= b
237-
self.precision *= b
233+
shift, ramification = slope.as_numer_denom()
234+
self.M, self.S_total = (
235+
self.M.ramify(ramification),
236+
self.S_total.ramify(ramification),
237+
)
238+
self.p *= ramification
239+
self.precision *= ramification
238240

239-
true_valid_precision, max_shift = self._check_shear_truncation(g)
241+
true_valid_precision, max_shift = self._check_shear_truncation(shift)
240242

241-
logger.debug(f"SHEAR: Computed slope {g=}. Max shift: {max_shift=} terms.")
243+
logger.debug(f"SHEAR: Computed shift {shift=}. Max shift: {max_shift=} terms.")
242244
if max_shift > 0:
243245
padded_coeffs = (
244246
self.S_total.coeffs + [Matrix.zeros(self.dim, self.dim)] * max_shift
@@ -252,12 +254,12 @@ def shear(self) -> None:
252254
f"Remaining buffer: {self.S_total.precision - max_shift}"
253255
)
254256

255-
S_sym = Matrix.diag(*[t ** (i * g) for i in range(self.dim)])
257+
S_sym = Matrix.diag(*[t ** (i * shift) for i in range(self.dim)])
256258
S_series = SeriesMatrix.from_matrix(S_sym, n, self.p, self.S_total.precision)
257259

258260
self.S_total = self.S_total * S_series
259261

260-
self.M, h = self.M.shear_coboundary(g, true_valid_precision)
262+
self.M, h = self.M.shear_coboundary(shift, true_valid_precision)
261263
self.precision = true_valid_precision
262264

263265
if h != 0:
@@ -310,11 +312,11 @@ def _compute_shear_slope(self) -> sp.Rational:
310312

311313
p1, p2 = lower_hull[0], lower_hull[1]
312314
steepest_slope = sp.Rational(p2[1] - p1[1], p2[0] - p1[0])
313-
g = -steepest_slope
315+
slope = -steepest_slope
314316

315317
logger.debug(f"NEWTON: Lower hull points: {lower_hull}")
316-
logger.debug(f"NEWTON: Computed slope {g=}")
317-
return max(sp.S.Zero, g)
318+
logger.debug(f"NEWTON: Computed {slope=}")
319+
return max(sp.S.Zero, slope)
318320

319321
def _check_eigenvalue_blindness(self, exp_base: sp.Expr) -> None:
320322
"""

ramanujantools/asymptotics/series_matrix.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,22 +244,25 @@ def _shear_row_corrections(self, g: int) -> list[list[sp.Expr]]:
244244
return row_corrections
245245

246246
def shear_coboundary(
247-
self, g: sp.Rational | int, target_precision: int | None = None
247+
self, shift: sp.Integer | int, target_precision: int | None = None
248248
) -> tuple[SeriesMatrix, int]:
249249
"""
250250
Applies a shearing transformation S(t) to the series to expose sub-exponential
251-
growth, where $S(t) = diag(1, t^g, t^{2g}, \\dots)$.
251+
growth, where $S(t) = diag(1, t^a, t^{2a}, \\dots)$ and $a$ is the shift parameter.
252252
253253
Args:
254-
g: The shear slope.
254+
shift: Represents a in the above description.
255255
target_precision: If provided, truncates the resulting series to this length,
256256
saving heavy CAS simplification on discarded tail terms.
257257
258258
Returns:
259259
A tuple containing the sheared SeriesMatrix and the integer `h` representing
260260
the overall degree shift (used to adjust the global factorial power).
261261
"""
262-
row_corrections = self._shear_row_corrections(g)
262+
if not shift.is_integer:
263+
raise ValueError(f"{shift=} must be an integer!")
264+
265+
row_corrections = self._shear_row_corrections(shift)
263266
power_dict = {}
264267

265268
for m in range(self.precision):
@@ -269,13 +272,13 @@ def shear_coboundary(
269272
if val_M == sp.S.Zero:
270273
continue
271274

272-
shift = int((j - i) * g)
275+
current = (j - i) * shift
273276
for c in range(self.precision):
274277
val_C = row_corrections[i][c]
275278
if val_C == sp.S.Zero:
276279
continue
277280

278-
power = m + c + shift
281+
power = m + c + current
279282
if power not in power_dict:
280283
power_dict[power] = Matrix.zeros(*self.shape)
281284
power_dict[power][i, j] += val_C * val_M

0 commit comments

Comments
 (0)