omnibias.core.verified.hermite_basis
Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.
import omnibias.core.verified.hermite_basisModule contract & mathematical conventions
Verified physicists' Hermite-function basis with an exact Fourier-transform tail.
Convention
This module fixes the **physicists'** Hermite polynomials H_n,
H_0(x) = 1,\quad H_1(x) = 2x,\quad H_{n+1}(x) = 2x\,H_n(x) - 2n\,H_{n-1}(x),
which have exact **integer** coefficients (hermite_poly_coeffs_exact,
generated with the same iterative-recurrence idiom as
omnibias.core.polynomials.hermite_coeffs /
omnibias.core.verified.coeffs.hermite_coeffs_exact for the
*probabilists'* convention used by the Gaussian derivative tower -- this module
does **not** reuse those, because the physicists' and probabilists' Hermite
polynomials are different polynomials (H_n(x) = 2^{n/2} He_n(x\sqrt2)), and
only the physicists' family is the classical Fourier eigenbasis below). The
(unnormalized) **Hermite function** is
\psi_n(x) = H_n(x)\, e^{-x^2/2}
(hermite_function), evaluated rigorously as an interval Horner
evaluation of the exact-integer polynomial (omnibias.core.verified.coeffs.horner_interval)
times a rigorous enclosure of exp(-x^2/2) (gaussian_weight, built on
omnibias.core.verified.transcend.exp_iv).
Exact self-duality under the Fourier transform
Fix the **unitary** Fourier transform convention
\mathcal{F}[f](k) = \frac{1}{\sqrt{2\pi}}\int_{-\infty}^{\infty} f(x)\,e^{-ikx}\,dx.
With *this* normalisation and *this* Gaussian weight (e^{-x^2/2}, not
e^{-x^2}), the Hermite functions are the classical Fourier eigenbasis:
\mathcal{F}[\psi_n] = (-i)^n\,\psi_n \qquad (n = 0, 1, 2, \dots).
The base case is a direct, elementary check that fixes the convention (rather
than merely asserting the general theorem): the Gaussian integral
int e^{-x^2/2} e^{-ikx} dx = sqrt(2 pi) e^{-k^2/2} gives
F[psi_0](k) = e^{-k^2/2} = psi_0(k) = (-i)^0 psi_0(k) -- psi_0 is
self-dual under exactly this transform, which pins down both the 1/sqrt(2
pi) prefactor and the e^{-x^2/2} (not e^{-x^2}) weight as the unique
combination making the n=0 case work; the general n case is the
standard fact that psi_n is built from psi_0 by the raising operator
a^dagger = (x - d/dx)/sqrt2, which anticommutes appropriately with
F (see e.g. Stein & Weiss, *Introduction to Fourier Analysis on Euclidean
Spaces*, or any quantum-mechanical treatment of the harmonic oscillator).
Because the multiplier (-i)^n is *diagonal* in this basis -- exactly the
same shape as the bounded Fourier multipliers riesz/hilbert/leray
in omnibias.core.verified.fourier, which also transform a truncated
expansion by acting coefficient-wise -- HermiteExpansion.fourier_transform_exact
needs no numerical approximation at all: (-i)^n cycles through the four
*exactly representable* values {1, -i, -1, i}, so the transform is applied
by **exact component permutation/sign-flip** (_apply_neg_i_power), not
generic (outward-rounded) complex-interval multiplication -- the result is
bit-for-bit exact, not merely a sound enclosure. And because |(-i)^n| = 1
this diagonal multiplier is an *isometry*, exactly like the Fourier-series
Riesz/Hilbert/Leray multipliers being bounded by 1: it does not change
which coefficient count N is kept, so any tail bound expressed in terms of
N and the coefficient-decay hypothesis (below) applies unchanged to the
transformed expansion.
Why a future Cohn-Elkies sphere-packing bound wants exactly this
The Cohn-Elkies linear-programming bound for sphere packing needs a radial test
function f with f(0) > 0, \hat f(0) > 0, f(x) <= 0 for
|x| >= r, and \hat f >= 0 everywhere -- i.e. *simultaneous* sign
constraints on f **and** its Fourier transform. Candidate functions are
built as finite combinations of Hermite functions precisely because that makes
\hat f computable **exactly** (no numerical FFT, no truncation error in the
transform itself) as the *same* finite coefficient vector up to the diagonal
(-i)^n phases: the sign/positivity LP constraints on f and \hat f
become constraints on one finite-dimensional coefficient vector rather than two
independently-truncated series. This module supplies exactly that primitive
(an exact, rigorous evaluator plus an exact, rigorous transform). The
fixed-dimension Cohn-Elkies LP that consumes this primitive lives in
omnibias.core.verified.cohn_elkies.
Tail-bound contract (read before trusting a truncated evaluation)
HermiteExpansion.tail_bound reuses the geometric-decay contract of
omnibias.core.verified.sequence_space.geometric_tail_bound --
|c_n| <= coeff_bound * ratio^n for n past the truncation, exactly as
that function already assumes -- multiplied by a *caller-supplied* uniform
bound psi_bound on |psi_n(x)| (or |\hat\psi_n(x)|, see below) valid
for every kept-past-truncation n:
\Bigl|\sum_{n>N} c_n\,\psi_n(x)\Bigr| \le \sum_{n>N} |c_n|\,|\psi_n(x)| \le \text{psi\_bound}\sum_{n>N} \text{coeff\_bound}\cdot\text{ratio}^n,
the last sum being exactly geometric_tail_bound with weight nu=1.
This composition is unconditionally sound *given* the two hypotheses; neither
is verified internally (exactly like geometric_tail_bound's own
ratio, or omnibias.core.verified.radii_spectral.SpectralProblem's
tail_inverse_bound / quadratic_norm -- caller-supplied, caller-justified
hypotheses are the norm for this register). tail_bound only checks
psi_bound >= 0 and raises rather than silently under-certifying if it is
negative; it cannot check that psi_bound genuinely bounds |psi_n(x)| for
every n > N, because that is a claim about unboundedly many n.
This matters concretely because the two bases behave very differently as
n -> infinity at a *fixed* x:
- **Unnormalized**
psi_n:H_nhas leading coefficient growing combinatorially, so|psi_n(x)|grows *unboundedly* innfor any fixedx(roughly likesqrt(n!), by the classical Cramer bound below). No finite constantpsi_boundis a valid uniform bound "for alln > N" on this basis -- a constant-psi_boundhypothesis can only be honestly discharged over a *known finite* range ofn(e.g. checked directly againsthermite_functionup to some concrete cutoff), never unboundedly. - **
L^2-normalized**\hat\psi_n(x) = \psi_n(x) / sqrt(2^n n! sqrt(pi))(hermite_function_normalized): the classical **Cramer inequality** (Cramer, 1939; see e.g. Thangavelu, *Lectures on Hermite and Laguerre Expansions*, Lemma 1.5.1) gives the genuinely uniform boundsup_{x in R} |\hat\psi_n(x)| <= pi^{-1/4}for **every**n-- a fixed constant that legitimately discharges the "for alln > N" hypothesis. This module does not re-derive or internally rely on Cramer's inequality (it is cited, not proved, here);CRAMER_UNIFORM_BOUNDis provided purely as a rigorously-outward-rounded value ofpi^{-1/4}(computed fromomnibias.core.verified.transcend.PI_IV) for a caller who chooses to cite Cramer's inequality themselves as theirpsi_boundjustification.
Use the normalized basis (normalized=True) with CRAMER_UNIFORM_BOUND
when an unboundedly-sound tail claim matters; use the unnormalized basis when
only a finite-window comparison against a higher-order truncation is needed
(exactly the containment tests below).
Shared formulas do not imply universal floating-point identity. Verify dtype, shape, derivative-order support, and the stated numerical assumptions for the path you use.
CRAMER_UNIFORM_BOUND
omnibias.core.verified.CRAMER_UNIFORM_BOUNDSource ↗CRAMER_UNIFORM_BOUND: float = PI_IV.sqrt().sqrt().reciprocal().hiRigorously-outward-rounded upper bound on pi**-0.25, the classical
Cramer uniform sup-bound for the L2-normalized physicists' Hermite
functions (see the module docstring). Convenience value only -- never
enforced internally; a caller who wants the unboundedly-sound tail-bound
contract passes this explicitly as psi_bound together with
normalized=True.
Regression example · cramer uniform bound value
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_cramer_uniform_bound_value() -> None:
# pi**-0.25, computed independently of the rigorous PI_IV path.
assert abs(CRAMER_UNIFORM_BOUND - math.pi**-0.25) < 1e-12python -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_cramer_uniform_bound_value -qRegression example · normalized hermite function respects cramer bound
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_normalized_hermite_function_respects_cramer_bound(n: int, x: float) -> None:
val = hermite_function_normalized(n, x)
assert abs(val.mid) <= CRAMER_UNIFORM_BOUND * (1.0 + 1e-9)python -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_normalized_hermite_function_respects_cramer_bound -qRead the implementation
CRAMER_UNIFORM_BOUND: float = PI_IV.sqrt().sqrt().reciprocal().hiOther public import paths
omnibias.core.verified.CRAMER_UNIFORM_BOUNDomnibias.core.verified.hermite_basis.CRAMER_UNIFORM_BOUND
HermiteExpansion
omnibias.core.verified.HermiteExpansionSource ↗class HermiteExpansionDataclass constructor fields; inherited fields, if any, are declared by the base class. A field(...) expression describes a default factory or field options, not a literal argument default.
A finite physicists' Hermite-function expansion f = sum_{n=0}^{N} c_n psi_n.
coeffs are the (generally complex) ~omnibias.core.verified.complex_interval.ComplexInterval
coefficients c_0, ..., c_N; a real-valued target function has every
c_n with an exactly-zero imaginary part. Complex coefficients (rather
than real ~omnibias.core.verified.interval.Interval) are used so
that fourier_transform_exact's (-i)^n phases live in the same
coefficient type without a second class -- exactly the design already used
by omnibias.core.verified.fourier.ValidatedFourierSeries.
This class carries **no stored tail radius**: unlike
~omnibias.core.verified.sequence_space.ValidatedSeries
(whose weighted-norm tail bounds sum_k |a_k| nu^k uniformly, independent
of the evaluation point), a Hermite tail bound is intrinsically a function
of the evaluation point x through |psi_n(x)| -- see
tail_bound, computed on demand from an explicit, caller-supplied
hypothesis rather than stored.
Parameters
| Name | Type & default | Contract |
|---|---|---|
coeffsdataclass field | list[ComplexInterval]Required | See the operation contract and implementation below. |
Executed regression · hermite expansion requires at least one coefficient
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_requires_at_least_one_coefficient() -> None:
with pytest.raises(ValueError):
HermiteExpansion([])python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_requires_at_least_one_coefficient" -qRegression example · hermite expansion repr
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_repr() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0])
text = repr(expansion)
assert "HermiteExpansion" in text
assert "order=1" in textpython -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_hermite_expansion_repr -qFields & methods
coeffsfield
coeffs: list[ComplexInterval]Declared list[ComplexInterval] field on HermiteExpansion. A value must be provided when constructing the configuration, unless an inherited constructor supplies it.
Regression example · fourier transform exact is involution up to period four
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_fourier_transform_exact_is_involution_up_to_period_four() -> None:
# Applying it four times returns exactly the original coefficients: (-i)^4 = 1.
expansion = HermiteExpansion.from_coeffs([1 + 0j, 2 - 1j, -3 + 4j, 0.5j, 7.0])
four_times = expansion
for _ in range(4):
four_times = four_times.fourier_transform_exact()
for orig, back in zip(expansion.coeffs, four_times.coeffs, strict=True):
assert back.re.lo == back.re.hi == orig.re.lo
assert back.im.lo == back.im.hi == orig.im.lopython -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_fourier_transform_exact_is_involution_up_to_period_four -q__post_init__method
__post_init__(self) -> NoneSee the class contract above and the exact method implementation below.
Returns: None
Validation & failure cases
- When
not self.coeffs, raisesValueError('HermiteExpansion needs at least one coefficient (order >= 0)').
Executed regression · hermite expansion requires at least one coefficient
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_requires_at_least_one_coefficient() -> None:
with pytest.raises(ValueError):
HermiteExpansion([])python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_requires_at_least_one_coefficient" -qMethod implementation
def __post_init__(self) -> None:
if not self.coeffs:
raise ValueError("HermiteExpansion needs at least one coefficient (order >= 0)")orderproperty
order(self) -> intThe truncation order N (len(coeffs) - 1).
Returns: int
Executed regression · hermite expansion repr
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_repr() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0])
text = repr(expansion)
assert "HermiteExpansion" in text
assert "order=1" in textpython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_repr" -qMethod implementation
def order(self) -> int:
"""The truncation order ``N`` (``len(coeffs) - 1``)."""
return len(self.coeffs) - 1from_coeffsmethod
from_coeffs(cls, coeffs: Sequence[ComplexLike]) -> HermiteExpansionSee the class contract above and the exact method implementation below.
Parameters
| Name | Type & default | Contract |
|---|---|---|
coeffspositional-or-keyword | Sequence[ComplexLike]Required | See the operation contract and implementation below. |
Returns: HermiteExpansion
Executed regression · hermite expansion repr
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_repr() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0])
text = repr(expansion)
assert "HermiteExpansion" in text
assert "order=1" in textpython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_repr" -qMethod implementation
def from_coeffs(cls, coeffs: Sequence[ComplexLike]) -> HermiteExpansion:
return cls([ComplexInterval.from_value(c) for c in coeffs])getmethod
get(self, n: int) -> ComplexIntervalThe n-th coefficient c_n (0 <= n <= order).
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
Returns: ComplexInterval
Executed regression · hermite expansion order and get
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_order_and_get() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0, 3.0])
assert expansion.order == 2
assert expansion.get(0).re.mid == 1.0
assert expansion.get(2).re.mid == 3.0python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_order_and_get" -qMethod implementation
def get(self, n: int) -> ComplexInterval:
"""The ``n``-th coefficient ``c_n`` (``0 <= n <= order``)."""
return self.coeffs[n]evaluate_keptmethod
evaluate_kept(self, x: IntervalLike, *, normalized: bool=False) -> ComplexIntervalExact enclosure of the retained sum sum_{n=0}^{N} c_n psi_n(x) (no tail).
Uses hermite_function_normalized instead of hermite_function
when normalized=True; the caller must then also use the normalized
basis consistently in tail_bound / evaluate.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
normalizedkeyword-only | boolDefault: False | See the operation contract and implementation below. |
Returns: ComplexInterval
Executed regression · hermite expansion evaluate kept matches manual sum
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_evaluate_kept_matches_manual_sum() -> None:
coeffs = [1.0, 0.5, -0.25]
expansion = HermiteExpansion.from_coeffs(coeffs)
x = 0.8
got = expansion.evaluate_kept(x)
manual = sum(c * hermite_function(n, x).mid for n, c in enumerate(coeffs))
assert got.re.lo <= manual <= got.re.hi
assert got.im.lo <= 0.0 <= got.im.hipython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_evaluate_kept_matches_manual_sum" -qMethod implementation
def evaluate_kept(self, x: IntervalLike, *, normalized: bool = False) -> ComplexInterval:
r"""Exact enclosure of the retained sum ``sum_{n=0}^{N} c_n psi_n(x)`` (no tail).
Uses :func:`hermite_function_normalized` instead of :func:`hermite_function`
when ``normalized=True``; the caller must then also use the normalized
basis consistently in :meth:`tail_bound` / :meth:`evaluate`.
"""
xi = Interval.from_value(x)
basis = hermite_function_normalized if normalized else hermite_function
acc = ComplexInterval.zero()
for n, c in enumerate(self.coeffs):
acc = acc + c * basis(n, xi)
return acctail_boundmethod
tail_bound(self, *, coeff_bound: float, ratio: float, psi_bound: float) -> IntervalRigorous bound on |sum_{n>N} c_n psi_n(x)| under an explicit decay hypothesis.
Requires (both caller-supplied, caller-justified, **not** verified here -- see the module docstring's tail-bound contract):
- a geometric coefficient-decay hypothesis
|c_n| <= coeff_bound * ratio**nfor everyn > order(the exact hypothesisomnibias.core.verified.sequence_space.geometric_tail_boundalready takes, reused here with weightnu=1); - a uniform hypothesis
|psi_n(x)| <= psi_bound(or|\hat\psi_n(x)|if the caller is using the normalized basis) for everyn > order, at whatever evaluation domain the caller intends.
Raises ValueError if psi_bound is negative (an admissibility
check on the parameter, not a proof that it is the true bound) or if
coeff_bound/ratio fail geometric_tail_bound's own checks.
Parameters
| Name | Type & default | Contract |
|---|---|---|
coeff_boundkeyword-only | floatRequired | See the operation contract and implementation below. |
ratiokeyword-only | floatRequired | See the operation contract and implementation below. |
psi_boundkeyword-only | floatRequired | See the operation contract and implementation below. |
Returns: Interval
Validation & failure cases
- When
psi_bound < 0.0, raisesValueError('psi_bound must be non-negative').
Executed regression · tail bound rejects negative psi bound
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_tail_bound_rejects_negative_psi_bound() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0])
with pytest.raises(ValueError):
expansion.tail_bound(coeff_bound=1.0, ratio=0.5, psi_bound=-1.0)python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_tail_bound_rejects_negative_psi_bound" -qMethod implementation
def tail_bound(self, *, coeff_bound: float, ratio: float, psi_bound: float) -> Interval:
r"""Rigorous bound on ``|sum_{n>N} c_n psi_n(x)|`` under an explicit decay hypothesis.
Requires (both caller-supplied, caller-justified, **not** verified here
-- see the module docstring's tail-bound contract):
* a geometric coefficient-decay hypothesis ``|c_n| <= coeff_bound *
ratio**n`` for every ``n > order`` (the exact hypothesis
:func:`omnibias.core.verified.sequence_space.geometric_tail_bound`
already takes, reused here with weight ``nu=1``);
* a uniform hypothesis ``|psi_n(x)| <= psi_bound`` (or ``|\hat\psi_n(x)|``
if the caller is using the normalized basis) for every ``n > order``,
at whatever evaluation domain the caller intends.
Raises :class:`ValueError` if ``psi_bound`` is negative (an admissibility
check on the parameter, not a proof that it is the true bound) or if
``coeff_bound``/``ratio`` fail :func:`geometric_tail_bound`'s own checks.
"""
if psi_bound < 0.0:
raise ValueError("psi_bound must be non-negative")
geo = geometric_tail_bound(coeff_bound, ratio, 1.0, self.order)
return geo * Interval.point(float(psi_bound))evaluatemethod
evaluate(self, x: IntervalLike, *, coeff_bound: float, ratio: float, psi_bound: float, normalized: bool=False) -> ComplexIntervalevaluate_kept(x) symmetrically inflated by tail_bound.
A rigorous enclosure of the full (infinite) sum sum_{n>=0} c_n
psi_n(x) under the same hypothesis tail_bound documents.
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
coeff_boundkeyword-only | floatRequired | See the operation contract and implementation below. |
ratiokeyword-only | floatRequired | See the operation contract and implementation below. |
psi_boundkeyword-only | floatRequired | See the operation contract and implementation below. |
normalizedkeyword-only | boolDefault: False | See the operation contract and implementation below. |
Returns: ComplexInterval
Executed regression · evaluate contains higher truncation proxy
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_evaluate_contains_higher_truncation_proxy(seed: int) -> None:
rng = random.Random(seed)
ratio = 0.5
coeff_bound = 2.0
n_trunc = 4
n_extended = 25
x = rng.uniform(-1.0, 1.0)
coeffs = [coeff_bound * (ratio**n) * rng.uniform(-1, 1) for n in range(n_extended + 1)]
psi_bound = CRAMER_UNIFORM_BOUND
truncated = HermiteExpansion.from_coeffs(coeffs[: n_trunc + 1])
extended = HermiteExpansion.from_coeffs(coeffs)
enclosure = truncated.evaluate(
x, coeff_bound=coeff_bound, ratio=ratio, psi_bound=psi_bound, normalized=True
)
proxy_full = extended.evaluate_kept(x, normalized=True)
assert enclosure.re.lo <= proxy_full.re.mid <= enclosure.re.hipython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_evaluate_contains_higher_truncation_proxy[0]" -qMethod implementation
def evaluate(
self,
x: IntervalLike,
*,
coeff_bound: float,
ratio: float,
psi_bound: float,
normalized: bool = False,
) -> ComplexInterval:
r"""``evaluate_kept(x)`` symmetrically inflated by :meth:`tail_bound`.
A rigorous enclosure of the full (infinite) sum ``sum_{n>=0} c_n
psi_n(x)`` under the same hypothesis :meth:`tail_bound` documents.
"""
kept = self.evaluate_kept(x, normalized=normalized)
b = self.tail_bound(coeff_bound=coeff_bound, ratio=ratio, psi_bound=psi_bound).hi
pad = Interval(-b, b)
return ComplexInterval(kept.re + pad, kept.im + pad)fourier_transform_exactmethod
fourier_transform_exact(self) -> HermiteExpansionExact Fourier transform: c_n -> (-i)^n c_n (bit-for-bit, not rounded).
Because the Hermite functions are exact Fourier eigenfunctions
(F[psi_n] = (-i)^n psi_n, see the module docstring), transforming a
finite expansion is *exactly* this diagonal relabelling of its own
coefficients -- mirroring how omnibias.core.verified.fourier.ValidatedFourierSeries.riesz
/ .hilbert / .leray act coefficient-wise on that series' kept
block. |(-i)^n| = 1 is an isometry, so any tail_bound computed
with the same (coeff_bound, ratio, psi_bound) hypothesis is
identical before and after the transform (the order -- the only
thing tail_bound depends on besides the hypothesis -- is
unchanged).
Returns: HermiteExpansion
Executed regression · fourier transform exact preserves order and tail bound
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_fourier_transform_exact_preserves_order_and_tail_bound() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 0.5, 0.25, 0.125])
transformed = expansion.fourier_transform_exact()
assert transformed.order == expansion.order
before = expansion.tail_bound(coeff_bound=1.0, ratio=0.5, psi_bound=2.0)
after = transformed.tail_bound(coeff_bound=1.0, ratio=0.5, psi_bound=2.0)
assert before.lo == after.lo
assert before.hi == after.hipython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_fourier_transform_exact_preserves_order_and_tail_bound" -qMethod implementation
def fourier_transform_exact(self) -> HermiteExpansion:
r"""Exact Fourier transform: ``c_n -> (-i)^n c_n`` (bit-for-bit, not rounded).
Because the Hermite functions are exact Fourier eigenfunctions
(``F[psi_n] = (-i)^n psi_n``, see the module docstring), transforming a
finite expansion is *exactly* this diagonal relabelling of its own
coefficients -- mirroring how :meth:`omnibias.core.verified.fourier.ValidatedFourierSeries.riesz`
/ ``.hilbert`` / ``.leray`` act coefficient-wise on that series' kept
block. ``|(-i)^n| = 1`` is an isometry, so any :meth:`tail_bound` computed
with the same ``(coeff_bound, ratio, psi_bound)`` hypothesis is
identical before and after the transform (the ``order`` -- the only
thing :meth:`tail_bound` depends on besides the hypothesis -- is
unchanged).
"""
return HermiteExpansion([_apply_neg_i_power(c, n) for n, c in enumerate(self.coeffs)])__repr__method
__repr__(self) -> strSee the class contract above and the exact method implementation below.
Returns: str
Executed regression · hermite expansion repr
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_expansion_repr() -> None:
expansion = HermiteExpansion.from_coeffs([1.0, 2.0])
text = repr(expansion)
assert "HermiteExpansion" in text
assert "order=1" in textpython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_expansion_repr" -qMethod implementation
def __repr__(self) -> str:
return f"HermiteExpansion(order={self.order}, coeffs={self.coeffs!r})"Read the implementation
class HermiteExpansion:
r"""A finite physicists' Hermite-function expansion ``f = sum_{n=0}^{N} c_n psi_n``.
``coeffs`` are the (generally complex) :class:`~omnibias.core.verified.complex_interval.ComplexInterval`
coefficients ``c_0, ..., c_N``; a real-valued target function has every
``c_n`` with an exactly-zero imaginary part. Complex coefficients (rather
than real :class:`~omnibias.core.verified.interval.Interval`) are used so
that :meth:`fourier_transform_exact`'s ``(-i)^n`` phases live in the same
coefficient type without a second class -- exactly the design already used
by :class:`omnibias.core.verified.fourier.ValidatedFourierSeries`.
This class carries **no stored tail radius**: unlike
:class:`~omnibias.core.verified.sequence_space.ValidatedSeries`
(whose weighted-norm tail bounds ``sum_k |a_k| nu^k`` uniformly, independent
of the evaluation point), a Hermite tail bound is intrinsically a function
of the evaluation point ``x`` through ``|psi_n(x)|`` -- see
:meth:`tail_bound`, computed on demand from an explicit, caller-supplied
hypothesis rather than stored.
"""
coeffs: list[ComplexInterval]
def __post_init__(self) -> None:
if not self.coeffs:
raise ValueError("HermiteExpansion needs at least one coefficient (order >= 0)")
@property
def order(self) -> int:
"""The truncation order ``N`` (``len(coeffs) - 1``)."""
return len(self.coeffs) - 1
@classmethod
def from_coeffs(cls, coeffs: Sequence[ComplexLike]) -> HermiteExpansion:
return cls([ComplexInterval.from_value(c) for c in coeffs])
def get(self, n: int) -> ComplexInterval:
"""The ``n``-th coefficient ``c_n`` (``0 <= n <= order``)."""
return self.coeffs[n]
def evaluate_kept(self, x: IntervalLike, *, normalized: bool = False) -> ComplexInterval:
r"""Exact enclosure of the retained sum ``sum_{n=0}^{N} c_n psi_n(x)`` (no tail).
Uses :func:`hermite_function_normalized` instead of :func:`hermite_function`
when ``normalized=True``; the caller must then also use the normalized
basis consistently in :meth:`tail_bound` / :meth:`evaluate`.
"""
xi = Interval.from_value(x)
basis = hermite_function_normalized if normalized else hermite_function
acc = ComplexInterval.zero()
for n, c in enumerate(self.coeffs):
acc = acc + c * basis(n, xi)
return acc
def tail_bound(self, *, coeff_bound: float, ratio: float, psi_bound: float) -> Interval:
r"""Rigorous bound on ``|sum_{n>N} c_n psi_n(x)|`` under an explicit decay hypothesis.
Requires (both caller-supplied, caller-justified, **not** verified here
-- see the module docstring's tail-bound contract):
* a geometric coefficient-decay hypothesis ``|c_n| <= coeff_bound *
ratio**n`` for every ``n > order`` (the exact hypothesis
:func:`omnibias.core.verified.sequence_space.geometric_tail_bound`
already takes, reused here with weight ``nu=1``);
* a uniform hypothesis ``|psi_n(x)| <= psi_bound`` (or ``|\hat\psi_n(x)|``
if the caller is using the normalized basis) for every ``n > order``,
at whatever evaluation domain the caller intends.
Raises :class:`ValueError` if ``psi_bound`` is negative (an admissibility
check on the parameter, not a proof that it is the true bound) or if
``coeff_bound``/``ratio`` fail :func:`geometric_tail_bound`'s own checks.
"""
if psi_bound < 0.0:
raise ValueError("psi_bound must be non-negative")
geo = geometric_tail_bound(coeff_bound, ratio, 1.0, self.order)
return geo * Interval.point(float(psi_bound))
def evaluate(
self,
x: IntervalLike,
*,
coeff_bound: float,
ratio: float,
psi_bound: float,
normalized: bool = False,
) -> ComplexInterval:
r"""``evaluate_kept(x)`` symmetrically inflated by :meth:`tail_bound`.
A rigorous enclosure of the full (infinite) sum ``sum_{n>=0} c_n
psi_n(x)`` under the same hypothesis :meth:`tail_bound` documents.
"""
kept = self.evaluate_kept(x, normalized=normalized)
b = self.tail_bound(coeff_bound=coeff_bound, ratio=ratio, psi_bound=psi_bound).hi
pad = Interval(-b, b)
return ComplexInterval(kept.re + pad, kept.im + pad)
def fourier_transform_exact(self) -> HermiteExpansion:
r"""Exact Fourier transform: ``c_n -> (-i)^n c_n`` (bit-for-bit, not rounded).
Because the Hermite functions are exact Fourier eigenfunctions
(``F[psi_n] = (-i)^n psi_n``, see the module docstring), transforming a
finite expansion is *exactly* this diagonal relabelling of its own
coefficients -- mirroring how :meth:`omnibias.core.verified.fourier.ValidatedFourierSeries.riesz`
/ ``.hilbert`` / ``.leray`` act coefficient-wise on that series' kept
block. ``|(-i)^n| = 1`` is an isometry, so any :meth:`tail_bound` computed
with the same ``(coeff_bound, ratio, psi_bound)`` hypothesis is
identical before and after the transform (the ``order`` -- the only
thing :meth:`tail_bound` depends on besides the hypothesis -- is
unchanged).
"""
return HermiteExpansion([_apply_neg_i_power(c, n) for n, c in enumerate(self.coeffs)])
def __repr__(self) -> str:
return f"HermiteExpansion(order={self.order}, coeffs={self.coeffs!r})"Other public import paths
omnibias.core.verified.HermiteExpansionomnibias.core.verified.hermite_basis.HermiteExpansion
gaussian_weight
omnibias.core.verified.gaussian_weightSource ↗gaussian_weight(x: IntervalLike) -> IntervalRigorous enclosure of the Gaussian weight exp(-x^2/2).
Parameters
| Name | Type & default | Contract |
|---|---|---|
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
IntervalExecuted regression · gaussian weight matches exp
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_gaussian_weight_matches_exp() -> None:
for x in (-1.5, 0.0, 0.7, 3.0):
w = gaussian_weight(x)
ref = math.exp(-0.5 * x * x)
assert w.lo <= ref <= w.hipython -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_gaussian_weight_matches_exp" -qRead the implementation
def gaussian_weight(x: IntervalLike) -> Interval:
r"""Rigorous enclosure of the Gaussian weight ``exp(-x^2/2)``."""
xi = Interval.from_value(x)
return exp_iv(Interval.point(-0.5) * xi.pow_int(2))Other public import paths
omnibias.core.verified.gaussian_weightomnibias.core.verified.hermite_basis.gaussian_weight
hermite_function
omnibias.core.verified.hermite_functionSource ↗hermite_function(n: int, x: IntervalLike) -> IntervalRigorous enclosure of the (unnormalized) Hermite function psi_n(x).
psi_n(x) = H_n(x) * exp(-x^2/2), evaluated exactly via
omnibias.core.verified.coeffs.horner_interval on the exact integer
coefficients of hermite_poly_coeffs_exact, times gaussian_weight.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
IntervalExecuted regression · normalized hermite function respects cramer bound
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_normalized_hermite_function_respects_cramer_bound(n: int, x: float) -> None:
val = hermite_function_normalized(n, x)
assert abs(val.mid) <= CRAMER_UNIFORM_BOUND * (1.0 + 1e-9)python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_normalized_hermite_function_respects_cramer_bound[-1.0-0]" -qRegression example · hermite function contains independent reference
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_function_contains_independent_reference(n: int, x: float) -> None:
ref = _hermite_phys_ref(n, x) * math.exp(-0.5 * x * x)
enclosure = hermite_function(n, x)
assert enclosure.lo <= ref <= enclosure.hi, (n, x, ref, enclosure)python -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_hermite_function_contains_independent_reference -qRead the implementation
def hermite_function(n: int, x: IntervalLike) -> Interval:
r"""Rigorous enclosure of the (unnormalized) Hermite function ``psi_n(x)``.
``psi_n(x) = H_n(x) * exp(-x^2/2)``, evaluated exactly via
:func:`omnibias.core.verified.coeffs.horner_interval` on the exact integer
coefficients of :func:`hermite_poly_coeffs_exact`, times :func:`gaussian_weight`.
"""
xi = Interval.from_value(x)
return horner_interval(hermite_poly_coeffs_exact(n), xi) * gaussian_weight(xi)Other public import paths
omnibias.core.verified.hermite_functionomnibias.core.verified.hermite_basis.hermite_function
hermite_function_normalized
omnibias.core.verified.hermite_function_normalizedSource ↗hermite_function_normalized(n: int, x: IntervalLike) -> IntervalRigorous enclosure of the L^2-normalized Hermite function \hat\psi_n(x).
\hat\psi_n(x) = \psi_n(x) / sqrt(2^n n! sqrt(pi)). Unlike the
unnormalized hermite_function, sup_x |\hat\psi_n(x)| is
uniformly bounded in n (Cramer's inequality; see the module docstring
and CRAMER_UNIFORM_BOUND), which is what makes a constant
psi_bound hypothesis in HermiteExpansion.tail_bound genuinely
discharge-able for unboundedly many n.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
IntervalExecuted regression · normalized hermite function respects cramer bound
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_normalized_hermite_function_respects_cramer_bound(n: int, x: float) -> None:
val = hermite_function_normalized(n, x)
assert abs(val.mid) <= CRAMER_UNIFORM_BOUND * (1.0 + 1e-9)python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_normalized_hermite_function_respects_cramer_bound[-1.0-0]" -qRegression example · normalized consistent with unnormalized
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_normalized_consistent_with_unnormalized() -> None:
for n in (0, 1, 2, 5):
for x in (-1.3, 0.6, 2.1):
raw = hermite_function(n, x)
norm = hermite_function_normalized(n, x)
factor = math.sqrt(2**n * math.factorial(n) * math.sqrt(math.pi))
assert abs(norm.mid * factor - raw.mid) < 1e-9 * max(1.0, abs(raw.mid))python -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_normalized_consistent_with_unnormalized -qRead the implementation
def hermite_function_normalized(n: int, x: IntervalLike) -> Interval:
r"""Rigorous enclosure of the ``L^2``-normalized Hermite function ``\hat\psi_n(x)``.
``\hat\psi_n(x) = \psi_n(x) / sqrt(2^n n! sqrt(pi))``. Unlike the
unnormalized :func:`hermite_function`, ``sup_x |\hat\psi_n(x)|`` is
uniformly bounded in ``n`` (Cramer's inequality; see the module docstring
and :data:`CRAMER_UNIFORM_BOUND`), which is what makes a constant
``psi_bound`` hypothesis in :meth:`HermiteExpansion.tail_bound` genuinely
discharge-able for unboundedly many ``n``.
"""
return hermite_function(n, x) / _normalization_factor(n)Other public import paths
omnibias.core.verified.hermite_function_normalizedomnibias.core.verified.hermite_basis.hermite_function_normalized
hermite_poly_coeffs_exact
omnibias.core.verified.hermite_poly_coeffs_exactSource ↗hermite_poly_coeffs_exact(n: int) -> tuple[int, ...]Exact integer coefficients of the physicists' Hermite polynomial H_n.
Returns (c_0, ..., c_n) with H_n(x) = sum_k c_k * x**k. H_0 = 1,
H_1 = 2x; recurrence H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x). Iterative
(not self-recursive), so a tall tower costs memory but never a
RecursionError.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
tuple[int, ...]Explicit validation & failure cases
- When
n < 0, raisesValueError(f'order n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · hermite poly coeffs rejects negative order
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_poly_coeffs_rejects_negative_order() -> None:
with pytest.raises(ValueError):
hermite_poly_coeffs_exact(-1)python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_hermite_poly_coeffs_rejects_negative_order" -qRegression example · hermite poly coeffs low order hand computed
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_hermite_poly_coeffs_low_order_hand_computed(x: float) -> None:
# H_0 = 1, H_1 = 2x, H_2 = 4x^2 - 2, H_3 = 8x^3 - 12x (hand-derived, not from math).
assert hermite_poly_coeffs_exact(0) == (1,)
assert hermite_poly_coeffs_exact(1) == (0, 2)
assert hermite_poly_coeffs_exact(2) == (-2, 0, 4)
assert hermite_poly_coeffs_exact(3) == (0, -12, 0, 8)python -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_hermite_poly_coeffs_low_order_hand_computed -qRead the implementation
def hermite_poly_coeffs_exact(n: int) -> tuple[int, ...]:
"""Exact integer coefficients of the physicists' Hermite polynomial ``H_n``.
Returns ``(c_0, ..., c_n)`` with ``H_n(x) = sum_k c_k * x**k``. ``H_0 = 1``,
``H_1 = 2x``; recurrence ``H_{n+1}(x) = 2x H_n(x) - 2n H_{n-1}(x)``. Iterative
(not self-recursive), so a tall tower costs memory but never a
``RecursionError``.
"""
if n < 0:
raise ValueError(f"order n must be >= 0, got {n}")
if n == 0:
return (1,)
if n == 1:
return (0, 2)
prev2: tuple[int, ...] = (1,)
prev1: tuple[int, ...] = (0, 2)
for m in range(2, n + 1):
out = [0] * (m + 1)
for k, c in enumerate(prev1):
out[k + 1] += 2 * c
for k, c in enumerate(prev2):
out[k] -= 2 * (m - 1) * c
prev2, prev1 = prev1, tuple(out)
return prev1Other public import paths
omnibias.core.verified.hermite_poly_coeffs_exactomnibias.core.verified.hermite_basis.hermite_poly_coeffs_exact
neg_i_power
omnibias.core.verified.neg_i_powerSource ↗neg_i_power(n: int) -> ComplexIntervalExact enclosure of the Fourier-eigenvalue symbol (-i)^n (period 4).
n=0,1,2,3 -> 1, -i, -1, i, then repeats. Every value is an exact
(degenerate, zero-width) ~omnibias.core.verified.complex_interval.ComplexInterval.
HermiteExpansion.fourier_transform_exact applies this multiplier via
exact component permutation (_apply_neg_i_power), not by generic
complex-interval multiplication with the value returned here, so that the
transform stays bit-for-bit exact rather than merely soundly rounded.
Parameters
| Name | Type & default | Contract |
|---|---|---|
npositional-or-keyword | intRequired | See the operation contract and implementation below. |
ComplexIntervalExplicit validation & failure cases
- When
n < 0, raisesValueError(f'n must be >= 0, got {n}').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · neg i power rejects negative
Recorded coverage confirms this test executed the API body. This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_neg_i_power_rejects_negative() -> None:
with pytest.raises(ValueError):
neg_i_power(-1)python -m pytest "packages/omnibias-core/tests/verified/test_hermite_basis.py::test_neg_i_power_rejects_negative" -qRegression example · neg i power cycle
This example belongs to the pinned upstream test suite. It may use fixtures and imports from its full file. Run it from that checkout with its test dependencies installed.
def test_neg_i_power_cycle() -> None:
expected = [1 + 0j, -1j, -1 + 0j, 1j]
for n in range(9):
z = neg_i_power(n)
want = expected[n % 4]
assert z.re.lo == z.re.hi == want.real
assert z.im.lo == z.im.hi == want.imagpython -m pytest packages/omnibias-core/tests/verified/test_hermite_basis.py -k test_neg_i_power_cycle -qRead the implementation
def neg_i_power(n: int) -> ComplexInterval:
r"""Exact enclosure of the Fourier-eigenvalue symbol ``(-i)^n`` (period 4).
``n=0,1,2,3 -> 1, -i, -1, i``, then repeats. Every value is an exact
(degenerate, zero-width) :class:`~omnibias.core.verified.complex_interval.ComplexInterval`.
:meth:`HermiteExpansion.fourier_transform_exact` applies this multiplier via
exact component permutation (:func:`_apply_neg_i_power`), not by generic
complex-interval multiplication with the value returned here, so that the
transform stays bit-for-bit exact rather than merely soundly rounded.
"""
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
return _NEG_I_POWERS[n % 4]Other public import paths
omnibias.core.verified.neg_i_poweromnibias.core.verified.hermite_basis.neg_i_power