omnibias.core.verified.asymptotic_jet
Coefficient recurrences, activation contracts, jet algebra, and verified arithmetic shared by the numerical backends.
import omnibias.core.verified.asymptotic_jetModule contract & mathematical conventions
Verified confluent power/root primitives and exact fixed-product calculus.
These are finite analytic calculations on explicit coefficient data.
power_compensator uses the entire beta-moment expansion of
log(x) * integral_0^1 exp((b+t*(a-b))*log(x)) dt. No division by
a-b occurs, including when parameter intervals cross the diagonal.
signed_root_primitive integrates 1/(1+delta*t*t) through delta=0;
negative delta is admitted only before either real pole.
All transcendental calls require the directed backend. Polynomial weighted
derivatives are exact over Q and retain the acceleration of the curved
path (omega*exp(-s), u*exp(s)). No boolean hypothesis can substitute
for either an enclosure calculation or a polynomial identity.
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.
fixed_product_jet
omnibias.core.verified.asymptotic_jet.fixed_product_jetSource ↗fixed_product_jet(polynomial: SparsePolynomial, omega: IntervalLike, u: IntervalLike, *, order: int=2) -> tuple[Interval, ...]Enclose unnormalized derivatives on (omega exp(-s),u exp(s)) at s=0.
The supplied polynomial has exactly two variables ordered (omega,u). Both scales must be positive. Their product is fixed along each path; no independent variation of epsilon is inserted into these derivatives.
Parameters
| Name | Type & default | Contract |
|---|---|---|
polynomialpositional-or-keyword | SparsePolynomialRequired | See the operation contract and implementation below. |
omegapositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
upositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
orderkeyword-only | intDefault: 2 | See the operation contract and implementation below. |
tuple[Interval, ...]Explicit validation & failure cases
- When
polynomial.nvars != 2, raisesValueError('a two-variable polynomial ordered (omega,u) is required'). - When
min(ww.lo, uu.lo) <= 0, raisesValueError('fixed-product scales must be strictly positive').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · fixed product extra axes are fixed and invalid requests fail
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_fixed_product_extra_axes_are_fixed_and_invalid_requests_fail():
p = SparsePolynomial(3, {(2, 1, 3): 2})
assert weighted_scale_derivative(p, order=3, omega_axis=2, u_axis=0).terms == (
((2, 1, 3), Q(-2)),
)
with pytest.raises(ValueError, match="two-variable"):
fixed_product_jet(p, 1, 1)
with pytest.raises(ValueError, match="positive"):
fixed_product_jet(SparsePolynomial.constant(2, 1), 0, 1)
with pytest.raises(ValueError, match="distinct"):
weighted_scale_derivative(p, omega_axis=1, u_axis=1)
with pytest.raises(ValueError):
power_compensator(0, 0, I(0, 1))
with pytest.raises(ValueError):
power_compensator(0, 0, 1, a_order=True)
with pytest.raises(ValueError, match="budget"):
power_compensator(0, 0, 1, a_order=17)
with pytest.raises(NotImplementedError):
signed_root_primitive(0, 1, endpoint_order=2)
with pytest.raises(ValueError):
signed_root_primitive(0, 1, terms=0)python -m pytest "packages/omnibias-core/tests/verified/test_asymptotic_jet.py::test_fixed_product_extra_axes_are_fixed_and_invalid_requests_fail" -qRegression example · fixed product derivatives retain acceleration and reject wrong claim
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_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim():
w, u = SparsePolynomial.variable(2, 0), SparsePolynomial.variable(2, 1)
product = w*u
assert not weighted_scale_derivative(product, order=2).terms
assert not verify_fixed_product_derivative(product, -2*product, order=2)
assert verify_fixed_product_derivative(product, SparsePolynomial.constant(2, 0), order=2)
assert fixed_product_jet(product, I(0.1, 0.2), I(0.4, 0.5), order=4)[1:] == (I.point(0),)*4
polynomial = w**2 + 3*w*u + Q(2, 3)*u**3 - w*u**2
with mp.workdps(100):
for omega, value in ((0.125, 0.25), (0.01, 0.3), (0.4, 0.2)):
jet = fixed_product_jet(polynomial, omega, value, order=6)
def reference(s, w0=omega, u0=value):
a, b = mp.mpf(w0)*mp.exp(-s), mp.mpf(u0)*mp.exp(s)
return a*a + 3*a*b + mp.mpf(2)/3*b**3 - a*b*b
for k, enclosure in enumerate(jet):
contains(enclosure, mp.diff(reference, 0, k))python -m pytest packages/omnibias-core/tests/verified/test_asymptotic_jet.py -k test_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim -qRead the implementation
def fixed_product_jet(
polynomial: SparsePolynomial,
omega: IntervalLike,
u: IntervalLike,
*,
order: int = 2,
) -> tuple[Interval, ...]:
"""Enclose unnormalized derivatives on (omega exp(-s),u exp(s)) at s=0.
The supplied polynomial has exactly two variables ordered (omega,u).
Both scales must be positive. Their product is fixed along each path;
no independent variation of epsilon is inserted into these derivatives.
"""
_order(order, "order")
if polynomial.nvars != 2:
raise ValueError("a two-variable polynomial ordered (omega,u) is required")
ww, uu = _finite(omega, "omega"), _finite(u, "u")
if min(ww.lo, uu.lo) <= 0:
raise ValueError("fixed-product scales must be strictly positive")
result = []
for k in range(order + 1):
derivative = weighted_scale_derivative(polynomial, order=k)
value = _ZERO
for idx, coefficient in derivative.terms:
value = value + coefficient * ww**idx[0] * uu**idx[1]
result.append(_checked(value))
return tuple(result)power_compensator
omnibias.core.verified.asymptotic_jet.power_compensatorSource ↗power_compensator(a: IntervalLike, b: IntervalLike, x: IntervalLike, *, a_order: int=0, b_order: int=0, log_order: int=0, terms: int=20, cells: int=64) -> IntervalEnclose partial_a^p partial_b^q (x partial_x)^k C(a,b;x).
C=(x**a-x**b)/(a-b) off the diagonal and C(a,a;x)=x**a log(x)
on it. x must be strictly positive. Derivatives are unnormalized.
The independent a,b derivatives on the diagonal retain the beta factor;
they are not derivatives along the constraint a=b.
Near confluence an entire series with an explicit tail is evaluated. Elsewhere a partition of the integral gives a sound range enclosure. The returned interval includes every input in the supplied boxes. Total derivative order is limited to 16 as an explicit arithmetic budget. Underflow is enclosed; overflow raises instead of returning a false bound.
Parameters
| Name | Type & default | Contract |
|---|---|---|
apositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
bpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
xpositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
a_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
b_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
log_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
termskeyword-only | intDefault: 20 | See the operation contract and implementation below. |
cellskeyword-only | intDefault: 64 | See the operation contract and implementation below. |
IntervalExplicit validation & failure cases
- When
a_order + b_order + log_order > 16, raisesValueError('total derivative order exceeds the arithmetic budget 16'). - When
xx.lo <= 0, raisesValueError('x must be strictly positive').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · power mixed derivatives include diagonal and tiny opposite splits
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_power_mixed_derivatives_include_diagonal_and_tiny_opposite_splits(a, b, x, orders):
p, q, k = orders
with mp.workdps(110):
box = power_compensator(a, b, x, a_order=p, b_order=q, log_order=k)
contains(box, power_reference(a, b, x, p, q, k))python -m pytest "packages/omnibias-core/tests/verified/test_asymptotic_jet.py::test_power_mixed_derivatives_include_diagonal_and_tiny_opposite_splits[orders0--0.1-0.2-0.7]" -qRegression example · confluent power refuses conditional transcendental backend
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_confluent_power_refuses_conditional_transcendental_backend(monkeypatch):
from omnibias.core.verified import transcend
monkeypatch.setattr(transcend, "_MPMATH", None)
monkeypatch.setattr(transcend, "_MPMATH_RESOLVED", True)
with pytest.raises(RuntimeError, match="rigorous"):
power_compensator(0, 0, 0.5)python -m pytest packages/omnibias-core/tests/verified/test_asymptotic_jet.py -k test_confluent_power_refuses_conditional_transcendental_backend -qRead the implementation
def power_compensator(
a: IntervalLike,
b: IntervalLike,
x: IntervalLike,
*,
a_order: int = 0,
b_order: int = 0,
log_order: int = 0,
terms: int = 20,
cells: int = 64,
) -> Interval:
r"""Enclose ``partial_a^p partial_b^q (x partial_x)^k C(a,b;x)``.
``C=(x**a-x**b)/(a-b)`` off the diagonal and ``C(a,a;x)=x**a log(x)``
on it. x must be strictly positive. Derivatives are unnormalized.
The independent a,b derivatives on the diagonal retain the beta factor;
they are not derivatives along the constraint a=b.
Near confluence an entire series with an explicit tail is evaluated.
Elsewhere a partition of the integral gives a sound range enclosure.
The returned interval includes every input in the supplied boxes. Total
derivative order is limited to 16 as an explicit arithmetic budget.
Underflow is enclosed; overflow raises instead of returning a false bound.
"""
for order, name in ((a_order, "a_order"), (b_order, "b_order"), (log_order, "log_order")):
_order(order, name)
if a_order + b_order + log_order > 16:
raise ValueError("total derivative order exceeds the arithmetic budget 16")
_options(terms, cells)
aa, bb, xx = _finite(a, "a"), _finite(b, "b"), _finite(x, "x")
if xx.lo <= 0:
raise ValueError("x must be strictly positive")
p, q, k = a_order, b_order, log_order
m = p + q + 1
with certificate_mode():
logx = ln_iv(xx)
split = aa - bb
z = _checked(split * logx)
result = _ZERO
diagonal = aa.lo == aa.hi == bb.lo == bb.hi
small = max(abs(z.lo), abs(z.hi)) <= 0.5
for j in range(min(k, m) + 1):
ell = k - j
factor = math.comb(k, j) * math.factorial(m) // math.factorial(m - j)
if diagonal:
moment = _beta(p, q) * aa**ell * exp_iv(_checked(aa * logx))
elif small:
moment = _ZERO
for r in range(ell + 1):
moment = moment + (
math.comb(ell, r) * bb ** (ell - r) * split**r
* _beta_exponential(z, p + r, q, terms)
)
moment = moment * exp_iv(_checked(bb * logx))
else:
moment = _ZERO
for index in range(cells):
t = Interval(
Interval.from_rational(Fraction(index, cells)).lo,
Interval.from_rational(Fraction(index + 1, cells)).hi,
)
exponent = bb + t * split
moment = moment + (
t**p * (_ONE - t)**q * exponent**ell
* exp_iv(_checked(exponent * logx)) / cells
)
result = result + factor * logx ** (m - j) * moment
return _checked(result)signed_root_primitive
omnibias.core.verified.asymptotic_jet.signed_root_primitiveSource ↗signed_root_primitive(delta: IntervalLike, value: IntervalLike, *, delta_order: int=0, endpoint_order: int=0, terms: int=24, cells: int=64) -> IntervalEnclose derivatives of S(delta,v)=integral_0^v dt/(1+delta*t²).
S is atan(sqrt(delta)*v)/sqrt(delta) for positive delta, v at
delta=0, and atanh(sqrt(-delta)*v)/sqrt(-delta) for negative delta
before the pole. The same real integral handles intervals crossing zero.
delta_order=p and endpoint_order=0 or 1 give unnormalized mixed
derivatives. For endpoint order zero the integrand is
(-1)^p p! v^(2p+1) t^(2p)/(1+delta*v²*t²)^(p+1) on [0,1].
Near zero a binomial series has a geometric bound on its omitted tail;
elsewhere interval integration is used. The pole test covers the entire
parameter and endpoint boxes, including negative endpoints.
Parameters
| Name | Type & default | Contract |
|---|---|---|
deltapositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
valuepositional-or-keyword | IntervalLikeRequired | See the operation contract and implementation below. |
delta_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
endpoint_orderkeyword-only | intDefault: 0 | See the operation contract and implementation below. |
termskeyword-only | intDefault: 24 | See the operation contract and implementation below. |
cellskeyword-only | intDefault: 64 | See the operation contract and implementation below. |
IntervalExplicit validation & failure cases
- When
delta_order > 16, raisesValueError('delta_order exceeds the arithmetic budget 16'). - When
endpoint_order > 1, raisesNotImplementedError('endpoint_order above one is not implemented'). - When
(_ONE + Interval(min(0.0, y.lo), max(0.0, y.hi))).lo <= 0, raisesValueError('the integration domain may meet a real pole').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · signed root regimes against atan atanh
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_signed_root_regimes_against_atan_atanh(delta, value, p, endpoint):
with mp.workdps(100):
result = signed_root_primitive(delta, value, delta_order=p, endpoint_order=endpoint)
contains(result, root_reference(delta, value, p, endpoint))python -m pytest "packages/omnibias-core/tests/verified/test_asymptotic_jet.py::test_signed_root_regimes_against_atan_atanh[0-0--0.1--1.0]" -qRegression example · power underflow and explicit series tail
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_power_underflow_and_explicit_series_tail():
with mp.workdps(130):
for a, b in ((2.0, 2.0), (2.0, 2.000001)):
result = power_compensator(a, b, 1e-200)
truth = power_reference(a, b, 1e-200)
contains(result, truth)
assert truth < 0 and all(math.isfinite(v) for v in (result.lo, result.hi))
coarse = power_compensator(0.1, 0, 0.2, terms=1)
fine = power_compensator(0.1, 0, 0.2, terms=20)
truth = power_reference(0.1, 0, 0.2)
contains(coarse, truth)
contains(fine, truth)
assert fine.width < coarse.width / 1000python -m pytest packages/omnibias-core/tests/verified/test_asymptotic_jet.py -k test_power_underflow_and_explicit_series_tail -qRead the implementation
def signed_root_primitive(
delta: IntervalLike,
value: IntervalLike,
*,
delta_order: int = 0,
endpoint_order: int = 0,
terms: int = 24,
cells: int = 64,
) -> Interval:
r"""Enclose derivatives of ``S(delta,v)=integral_0^v dt/(1+delta*t²)``.
S is ``atan(sqrt(delta)*v)/sqrt(delta)`` for positive delta, v at
delta=0, and ``atanh(sqrt(-delta)*v)/sqrt(-delta)`` for negative delta
before the pole. The same real integral handles intervals crossing zero.
``delta_order=p`` and ``endpoint_order=0 or 1`` give unnormalized mixed
derivatives. For endpoint order zero the integrand is
``(-1)^p p! v^(2p+1) t^(2p)/(1+delta*v²*t²)^(p+1)`` on [0,1].
Near zero a binomial series has a geometric bound on its omitted tail;
elsewhere interval integration is used. The pole test covers the entire
parameter and endpoint boxes, including negative endpoints.
"""
_order(delta_order, "delta_order")
_order(endpoint_order, "endpoint_order")
if delta_order > 16:
raise ValueError("delta_order exceeds the arithmetic budget 16")
if endpoint_order > 1:
raise NotImplementedError("endpoint_order above one is not implemented")
_options(terms, cells)
dd, vv = _finite(delta, "delta"), _finite(value, "value")
p = delta_order
y = _checked(dd * vv**2)
if (_ONE + Interval(min(0.0, y.lo), max(0.0, y.hi))).lo <= 0:
raise ValueError("the integration domain may meet a real pole")
factor = (-1) ** p * math.factorial(p)
if endpoint_order:
return _checked(factor * vv ** (2 * p) / (_ONE + y) ** (p + 1))
if dd.lo == dd.hi == 0.0:
return _checked(Fraction(factor, 2 * p + 1) * vv ** (2 * p + 1))
radius = max(abs(y.lo), abs(y.hi))
integral = _ZERO
if radius <= 0.25:
degree = max(terms, p + 1)
power = _ONE
for n in range(degree + 1):
integral = integral + Fraction(math.comb(n + p, p), 2 * n + 2 * p + 1) * power
power = power * (-y)
r = Interval.point(radius)
first = Fraction(math.comb(degree + 1 + p, p), 2 * (degree + 1) + 2 * p + 1) * r ** (degree + 1)
ratio = r * Fraction(degree + p + 2, degree + 2)
tail = first / (_ONE - ratio)
integral = integral + Interval(-tail.hi, tail.hi)
else:
for index in range(cells):
t = Interval(
Interval.from_rational(Fraction(index, cells)).lo,
Interval.from_rational(Fraction(index + 1, cells)).hi,
)
integral = integral + t ** (2 * p) / (_ONE + y * t**2) ** (p + 1) / cells
return _checked(factor * vv ** (2 * p + 1) * integral)verify_fixed_product_derivative
omnibias.core.verified.asymptotic_jet.verify_fixed_product_derivativeSource ↗verify_fixed_product_derivative(source: SparsePolynomial, claimed: SparsePolynomial, *, order: int=1) -> boolReplay the claimed fixed-product derivative as an exact polynomial identity.
This checks supplied operands; it does not accept a caller's proof flag. A straight directional Hessian generally fails the second-order check.
Parameters
| Name | Type & default | Contract |
|---|---|---|
sourcepositional-or-keyword | SparsePolynomialRequired | See the operation contract and implementation below. |
claimedpositional-or-keyword | SparsePolynomialRequired | See the operation contract and implementation below. |
orderkeyword-only | intDefault: 1 | See the operation contract and implementation below. |
boolExecuted regression · fixed product derivatives retain acceleration and reject wrong claim
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_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim():
w, u = SparsePolynomial.variable(2, 0), SparsePolynomial.variable(2, 1)
product = w*u
assert not weighted_scale_derivative(product, order=2).terms
assert not verify_fixed_product_derivative(product, -2*product, order=2)
assert verify_fixed_product_derivative(product, SparsePolynomial.constant(2, 0), order=2)
assert fixed_product_jet(product, I(0.1, 0.2), I(0.4, 0.5), order=4)[1:] == (I.point(0),)*4
polynomial = w**2 + 3*w*u + Q(2, 3)*u**3 - w*u**2
with mp.workdps(100):
for omega, value in ((0.125, 0.25), (0.01, 0.3), (0.4, 0.2)):
jet = fixed_product_jet(polynomial, omega, value, order=6)
def reference(s, w0=omega, u0=value):
a, b = mp.mpf(w0)*mp.exp(-s), mp.mpf(u0)*mp.exp(s)
return a*a + 3*a*b + mp.mpf(2)/3*b**3 - a*b*b
for k, enclosure in enumerate(jet):
contains(enclosure, mp.diff(reference, 0, k))python -m pytest "packages/omnibias-core/tests/verified/test_asymptotic_jet.py::test_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim" -qRead the implementation
def verify_fixed_product_derivative(
source: SparsePolynomial, claimed: SparsePolynomial, *, order: int = 1
) -> bool:
"""Replay the claimed fixed-product derivative as an exact polynomial identity.
This checks supplied operands; it does not accept a caller's proof flag.
A straight directional Hessian generally fails the second-order check.
"""
expected = weighted_scale_derivative(source, order=order)
return claimed.nvars == expected.nvars and claimed.terms == expected.termsweighted_scale_derivative
omnibias.core.verified.asymptotic_jet.weighted_scale_derivativeSource ↗weighted_scale_derivative(polynomial: SparsePolynomial, *, order: int=1, omega_axis: int=0, u_axis: int=1) -> SparsePolynomialExact (u partial_u - omega partial_omega)^order polynomial over Q.
A monomial omega^i u^j has eigenvalue j-i. This includes every path
acceleration term: at second order, omega² f_ww - 2 omega u f_wu
+ u² f_uu + omega f_w + u f_u. Other polynomial axes are fixed.
Parameters
| Name | Type & default | Contract |
|---|---|---|
polynomialpositional-or-keyword | SparsePolynomialRequired | See the operation contract and implementation below. |
orderkeyword-only | intDefault: 1 | See the operation contract and implementation below. |
omega_axiskeyword-only | intDefault: 0 | See the operation contract and implementation below. |
u_axiskeyword-only | intDefault: 1 | See the operation contract and implementation below. |
SparsePolynomialExplicit validation & failure cases
- When
type(omega_axis) is not int or type(u_axis) is not int or omega_axis == u_axis or (not 0 <= min(omega_axis, u_axis)) or (max(omega_axis, u_axis) >= polynomial.nvars), raisesValueError('two distinct polynomial coordinate axes are required').
These are explicit source guards. Backend operations may also raise for invalid shapes, dtypes, or unsupported devices.
Executed regression · fixed product extra axes are fixed and invalid requests fail
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_fixed_product_extra_axes_are_fixed_and_invalid_requests_fail():
p = SparsePolynomial(3, {(2, 1, 3): 2})
assert weighted_scale_derivative(p, order=3, omega_axis=2, u_axis=0).terms == (
((2, 1, 3), Q(-2)),
)
with pytest.raises(ValueError, match="two-variable"):
fixed_product_jet(p, 1, 1)
with pytest.raises(ValueError, match="positive"):
fixed_product_jet(SparsePolynomial.constant(2, 1), 0, 1)
with pytest.raises(ValueError, match="distinct"):
weighted_scale_derivative(p, omega_axis=1, u_axis=1)
with pytest.raises(ValueError):
power_compensator(0, 0, I(0, 1))
with pytest.raises(ValueError):
power_compensator(0, 0, 1, a_order=True)
with pytest.raises(ValueError, match="budget"):
power_compensator(0, 0, 1, a_order=17)
with pytest.raises(NotImplementedError):
signed_root_primitive(0, 1, endpoint_order=2)
with pytest.raises(ValueError):
signed_root_primitive(0, 1, terms=0)python -m pytest "packages/omnibias-core/tests/verified/test_asymptotic_jet.py::test_fixed_product_extra_axes_are_fixed_and_invalid_requests_fail" -qRegression example · fixed product derivatives retain acceleration and reject wrong claim
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_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim():
w, u = SparsePolynomial.variable(2, 0), SparsePolynomial.variable(2, 1)
product = w*u
assert not weighted_scale_derivative(product, order=2).terms
assert not verify_fixed_product_derivative(product, -2*product, order=2)
assert verify_fixed_product_derivative(product, SparsePolynomial.constant(2, 0), order=2)
assert fixed_product_jet(product, I(0.1, 0.2), I(0.4, 0.5), order=4)[1:] == (I.point(0),)*4
polynomial = w**2 + 3*w*u + Q(2, 3)*u**3 - w*u**2
with mp.workdps(100):
for omega, value in ((0.125, 0.25), (0.01, 0.3), (0.4, 0.2)):
jet = fixed_product_jet(polynomial, omega, value, order=6)
def reference(s, w0=omega, u0=value):
a, b = mp.mpf(w0)*mp.exp(-s), mp.mpf(u0)*mp.exp(s)
return a*a + 3*a*b + mp.mpf(2)/3*b**3 - a*b*b
for k, enclosure in enumerate(jet):
contains(enclosure, mp.diff(reference, 0, k))python -m pytest packages/omnibias-core/tests/verified/test_asymptotic_jet.py -k test_fixed_product_derivatives_retain_acceleration_and_reject_wrong_claim -qRead the implementation
def weighted_scale_derivative(
polynomial: SparsePolynomial,
*,
order: int = 1,
omega_axis: int = 0,
u_axis: int = 1,
) -> SparsePolynomial:
r"""Exact ``(u partial_u - omega partial_omega)^order polynomial`` over Q.
A monomial omega^i u^j has eigenvalue j-i. This includes every path
acceleration term: at second order, ``omega² f_ww - 2 omega u f_wu
+ u² f_uu + omega f_w + u f_u``. Other polynomial axes are fixed.
"""
_order(order, "order")
if (type(omega_axis) is not int or type(u_axis) is not int
or omega_axis == u_axis or not 0 <= min(omega_axis, u_axis)
or max(omega_axis, u_axis) >= polynomial.nvars):
raise ValueError("two distinct polynomial coordinate axes are required")
return SparsePolynomial(
polynomial.nvars,
{idx: coefficient * (idx[u_axis] - idx[omega_axis])**order
for idx, coefficient in polynomial.terms},
budget=polynomial.budget,
)