Coverage for src/hypra/hpl/mobius.py: 100.00%
26 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 22:12 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-26 22:12 +0000
1"""Exact real HPL transform t=(1-z)/(1+z), with endpoint-derived constants."""
3from collections import defaultdict
4from functools import lru_cache
6import sympy as s
8from .._typing import IntegerWord, Interval
9from ..errors import UnsupportedExpressionError
10from ..symbolic import HPL
11from .regularization import hpl_endpoint_polynomial
12from .transforms import _validate
14_MAX_MOBIUS_WEIGHT = 8
15_ENDPOINT_LOG = s.Symbol("_mobius_endpoint_log")
16_PULLBACK = {0: ((1, -1), (-1, -1)), 1: ((0, -1), (-1, 1)), -1: ((-1, -1),)}
19@lru_cache(maxsize=512)
20def _mobius_terms(word):
21 if not word:
22 return (((), s.S.One),)
23 # T(M(z)) = -log(z) - log(2) + O(z). At the transformed origin
24 # each nonempty HPL has zero constant term in its power/log expansion.
25 constant = hpl_endpoint_polynomial(word, _ENDPOINT_LOG).subs(_ENDPOINT_LOG, -s.log(2))
26 terms: defaultdict[tuple[int, ...], s.Expr] = defaultdict(lambda: s.S.Zero, {(): constant})
27 for tail, coefficient in _mobius_terms(word[1:]):
28 for letter, sign in _PULLBACK[word[0]]:
29 terms[(letter, *tail)] += sign * coefficient
30 return tuple((word, coefficient) for word, coefficient in terms.items() if coefficient != 0)
33def mobius_hpl(word: IntegerWord, z: s.Symbol, *, domain: Interval | None = None) -> s.Expr:
34 """Return H_word((1-z)/(1+z)) in HPLs at z on the real interval 0<z<1.
36 Every expanded {-1,0,1} word through weight eight is supported.
37 Endpoint constants are preserved
38 as exact alternating multiple-zeta values when not reduced. The transform
39 maps the real interval to itself; no complex continuation is claimed.
41 Args:
42 word: Expanded ternary word of weight at most eight.
43 z: SymPy symbol for the interior coordinate.
44 domain: Declare `"0<z<1"` explicitly.
45 """
46 word = _validate(word, z, domain)
47 if len(word) > _MAX_MOBIUS_WEIGHT:
48 raise UnsupportedExpressionError(
49 f"Mobius transformation supports weight at most {_MAX_MOBIUS_WEIGHT}"
50 )
51 return s.Add(
52 *(
53 coefficient * (HPL(term, z) if term else s.S.One)
54 for term, coefficient in _mobius_terms(word)
55 )
56 )