From d415cafe1a3cf8381ceff912eed54ace5515e049 Mon Sep 17 00:00:00 2001 From: axiom-marbell Date: Tue, 18 Aug 2026 11:19:32 +0200 Subject: [PATCH] harvest: exact-mass one-loop regulator atoms Advances #76 without promoting scientific claims.\n\nCo-authored-by: prime-agent --- src/substrate_framework/__init__.py | 24 + .../scalar_one_loop_mass.py | 513 ++++++++++++++++++ tests/test_scalar_one_loop_mass.py | 441 +++++++++++++++ 3 files changed, 978 insertions(+) create mode 100644 src/substrate_framework/scalar_one_loop_mass.py create mode 100644 tests/test_scalar_one_loop_mass.py diff --git a/src/substrate_framework/__init__.py b/src/substrate_framework/__init__.py index 12815fdd..db86dc0d 100644 --- a/src/substrate_framework/__init__.py +++ b/src/substrate_framework/__init__.py @@ -749,6 +749,19 @@ leading_scalar_newton_shift_coefficient, scalar_heat_kernel_a2, ) +from .scalar_one_loop_mass import ( + KNOWN_ONE_LOOP_REGULATORS, + SMOOTH_PROPER_TIME_REGULATOR, + ZETA_POWER_SUBTRACTED_REGULATOR, + ExactMassNewtonShift, + ExactMassVacuumShift, + RegulatorSchemeLedger, + curvature_proper_time_integral, + exact_mass_inverse_newton_shift, + exact_mass_vacuum_density_shift, + regulator_scheme_ledger, + vacuum_proper_time_integral, +) from .covariant_sine_gordon_action import ( CovariantSineGordonAction, CovariantSineGordonFluctuation, @@ -2176,6 +2189,17 @@ "metric_ricci_scalar", "metric_ricci_tensor", "worldline_reparametrization_residual", + "KNOWN_ONE_LOOP_REGULATORS", + "SMOOTH_PROPER_TIME_REGULATOR", + "ZETA_POWER_SUBTRACTED_REGULATOR", + "ExactMassNewtonShift", + "ExactMassVacuumShift", + "RegulatorSchemeLedger", + "curvature_proper_time_integral", + "exact_mass_inverse_newton_shift", + "exact_mass_vacuum_density_shift", + "regulator_scheme_ledger", + "vacuum_proper_time_integral", ] __version__ = "0.0.0" diff --git a/src/substrate_framework/scalar_one_loop_mass.py b/src/substrate_framework/scalar_one_loop_mass.py new file mode 100644 index 00000000..dcf08151 --- /dev/null +++ b/src/substrate_framework/scalar_one_loop_mass.py @@ -0,0 +1,513 @@ +"""Exact-mass one-loop proper-time coefficients for preregistered regulators. + +This is the Route 1 (induced / Sakharov gravity) rung that follows +``covariant_sine_gordon_action``. The landed action rung hands the +fluctuation operator + + D_E = -nabla_E**2 + xi*R_E + m**2, m**2 = V''(phi_bg), + +to the determinant. This module evaluates the two leading proper-time +integral classes of ``Gamma_E = (1/2)*ln(det(D_E))`` with the mass retained +exactly --- no expansion of ``exp(-tau*m**2)`` inside the regulated integral +--- for three preregistered regulators: + +``SHARP_PROPER_TIME_REGULATOR`` (reused from ``scalar_induced_newton``) + A sharp lower proper-time cutoff ``tau_0 = Lambda**-2``. Writing + ``z = m**2/Lambda**2``, the curvature class integral is + + I_2 = integral_{tau_0}^{infty} tau**-2 * exp(-m**2*tau) dtau + = Lambda**2 * (exp(-z) - z*E1(z)), + + with ``E1 = expint(1, .)``. The factor ``exp(-z) - z*E1(z)`` is the + load-bearing finite-mass correction named by the PR #13 review + (approximately 0.1485 at z = 1): a leading UV-asymptotic ``Lambda**2`` + term alone does not establish the finite-cutoff result. + +``SMOOTH_PROPER_TIME_REGULATOR`` + A smooth essential-singularity proper-time weight ``exp(-1/(Lambda**2 + * tau))``. All power-divergent classes become convergent single + integrals; the closed forms are modified Bessel functions: + + I_2 = 2*Lambda**2*sqrt(z)*BesselK_1(2*sqrt(z)), + I_3 = 2*Lambda**4*z*BesselK_2(2*sqrt(z)). + +``ZETA_POWER_SUBTRACTED_REGULATOR`` + The Mellin finite-part scheme in which the power divergences are + subtracted; it requires a declared renormalization scale ``mu`` (the + cutoff argument is rejected) and yields the pure logarithmic running + + I_2 = m**2*(ln(m**2/mu**2) + EulerGamma - 1), + I_3 = -(m**4/2)*(ln(m**2/mu**2) + EulerGamma - 3/2). + +Authority note: ``scalar_induced_newton`` and +``covariant_sine_gordon_action`` are landed conditional (unpromoted) +prior-work APIs -- the PR #14 and PR #25 harvests promoted no claims -- and +the accepted ``C-GRV-001`` supplies only the conditional dimensional and +additive-baseline ledger, leaving the coefficient, field content, and +regulator as premises. Every public symbol in this module is likewise +conditional, unpromoted infrastructure linked to open goal #76. + +Composition with that landed conditional scheme factor (one real scalar, +determinant weight 1/2, heat-kernel prefactor ``(4*pi)**-2``, +Einstein-Hilbert matching factor ``16*pi``) gives the exact-mass induced +inverse-Newton shift + + Delta(1/G) = N * coefficient_per_field(xi) * I_2(regulator), + +where ``coefficient_per_field`` is taken from the landed conditional +``scalar_induced_newton.leading_scalar_newton_shift_coefficient`` API, so +the massless sharp limit reproduces that conditional API's +``s*Lambda**2 = N*(1-6*xi)*Lambda**2/(12*pi)`` exactly. The vacuum sector +of the same mass-resummed expansion is + + Delta(rho_Gamma) = -(N/2)*(4*pi)**-2 * I_3(m**2) + +per scheme. The ``-m**2`` entry of the landed conditional +``scalar_heat_kernel_a2`` weights belongs to the *unresummed* organization, +in which the exponential is expanded and the mass survives only as that +coefficient; applying it on top of the resummed ``I_3`` double-counts the +mass. The two organizations agree to first order through the exact +derivative identity ``d I_3/d m**2 = -I_2`` (which holds for all three +schemes and is tested), i.e. ``I_3(m**2) = I_3(0) - m**2*I_2(0) + O(m**4)``. + +Declared derivation oracles (all exact, SymPy): + +* sharp ``I_2``: ``d/dtau_0 I_2(tau_0) = -tau_0**-2*exp(-m**2*tau_0)`` plus + the tail decay, so the closed form is the tail integral by uniqueness; +* sharp ``I_3``: the integration-by-parts identity + ``I_3 = exp(-z)*Lambda**4/2 - (m**2/2)*I_2``; +* smooth closed forms: the exact differential recurrence + ``d/dz J_p = -J_{p-1}`` of the integrals + ``J_p(z) = integral_0^{infty} t**-p exp(-z*t - 1/t) dt`` together with the + boundary limits ``J_2(0+) = 1`` and ``J_3(0+) = 1`` (verified against + SymPy Bessel derivatives), plus independent high-precision quadrature; +* zeta finite parts: the cutoff-subtraction limits + ``lim_{tau_0 -> 0} [I(tau_0) - power terms - log terms]`` evaluated + symbolically. + +This module does NOT identify the cutoff with any substrate scale, choose a +renormalization condition among the three schemes, derive a total Newton +constant (the accepted C-GRV-001 additive baseline remains independent), +evaluate the tau**-1 class (curvature-squared and m**2*R structures), or +confront any empirical comparator. Those are later rungs of issue #76. +Scheme differences are the deliverable: at z = 1 the smooth regulator +induces about 1.88 times the sharp curvature coefficient, and the +power-subtracted scheme changes both the parametric structure and the sign +at small log; any later usable-normalization claim must cite this spread. + +``ExactMassNewtonShift.curvature_weight_sign`` describes only the weight +``1/6 - xi`` and carries no total-shift verdict; ``value_sign`` is the +decidable sign of the full returned value (``None`` when symbolic inputs +leave it undecidable). For the two cutoff schemes ``I_2 > 0`` always, so +the two agree there; for the power-subtracted scheme ``I_2`` itself changes +sign with ``m**2/mu**2`` and the two fields genuinely differ. +""" + +from __future__ import annotations + +from dataclasses import dataclass +from typing import Any + +import sympy as sp + +from .exact_symbolic import exact_real as _exact_real +from .exact_symbolic import positive_exact as _positive_exact +from .scalar_induced_newton import SHARP_PROPER_TIME_REGULATOR +from .scalar_induced_newton import leading_scalar_newton_shift_coefficient # conditional landed API + +SMOOTH_PROPER_TIME_REGULATOR = "proper_time_smooth_essential" +ZETA_POWER_SUBTRACTED_REGULATOR = "zeta_power_subtracted" + +KNOWN_ONE_LOOP_REGULATORS = ( + SHARP_PROPER_TIME_REGULATOR, + SMOOTH_PROPER_TIME_REGULATOR, + ZETA_POWER_SUBTRACTED_REGULATOR, +) + +_FOUR_DIMENSIONAL_HEAT_KERNEL_PREFACTOR = (4 * sp.pi) ** -2 + + +def _nonnegative_exact(value: Any, name: str) -> sp.Expr: + expression = _exact_real(value, name) + if expression.is_nonnegative is not True: + raise ValueError(f"{name} must be provably nonnegative") + return expression + + +def _positive_integer(value: Any, name: str) -> sp.Expr: + expression = _positive_exact(value, name) + if expression.is_integer is not True: + raise ValueError(f"{name} must be a positive integer field count") + return expression + + +def _resolve_regulator( + regulator: Any, + cutoff: Any, + renormalization_scale: Any, +) -> tuple[sp.Expr | None, sp.Expr | None]: + """Validate the scheme contract and return (cutoff, scale) exact values.""" + + if regulator not in KNOWN_ONE_LOOP_REGULATORS: + raise ValueError( + f"unknown regulator {regulator!r}; pass one of " + f"{KNOWN_ONE_LOOP_REGULATORS}" + ) + if regulator == ZETA_POWER_SUBTRACTED_REGULATOR: + if cutoff is not None: + raise ValueError( + "the power-subtracted scheme has no cutoff; pass " + "renormalization_scale only" + ) + if renormalization_scale is None: + raise ValueError( + "the power-subtracted scheme requires an explicit " + "renormalization_scale; it must not default" + ) + return None, _positive_exact(renormalization_scale, "renormalization_scale") + if renormalization_scale is not None: + raise ValueError( + "renormalization_scale belongs to the power-subtracted scheme " + "only; a cutoff scheme must not declare one" + ) + if cutoff is None: + raise ValueError("this regulator requires an explicit positive cutoff") + return _positive_exact(cutoff, "cutoff"), None + + +def _sharp_curvature_integral(cutoff: sp.Expr, mass_squared: sp.Expr) -> sp.Expr: + if mass_squared.is_zero is True: + # Massless limit: the tail integral of tau^-2 is exactly Lambda^2. + return cutoff**2 + z = mass_squared / cutoff**2 + return sp.simplify(cutoff**2 * (sp.exp(-z) - z * sp.expint(1, z))) + + +def _smooth_curvature_integral(cutoff: sp.Expr, mass_squared: sp.Expr) -> sp.Expr: + if mass_squared.is_zero is True: + # Massless limit: 2*sqrt(z)*K_1(2*sqrt(z)) -> 1 as z -> 0+. + return cutoff**2 + z = mass_squared / cutoff**2 + return sp.simplify( + 2 * cutoff**2 * sp.sqrt(z) * sp.besselk(1, 2 * sp.sqrt(z)) + ) + + +def _zeta_curvature_integral( + renormalization_scale: sp.Expr, mass_squared: sp.Expr +) -> sp.Expr: + if mass_squared.is_zero is True: + # Power divergences subtracted: no induced curvature term at m = 0. + return sp.Integer(0) + return sp.simplify( + mass_squared + * (sp.log(mass_squared / renormalization_scale**2) + sp.EulerGamma - 1) + ) + + +def _sharp_vacuum_integral(cutoff: sp.Expr, mass_squared: sp.Expr) -> sp.Expr: + if mass_squared.is_zero is True: + # Massless limit: the tail integral of tau^-3 is Lambda^4/2. + return cutoff**4 / 2 + z = mass_squared / cutoff**2 + return sp.simplify( + sp.exp(-z) * cutoff**4 / 2 + - (mass_squared / 2) * _sharp_curvature_integral(cutoff, mass_squared) + ) + + +def _smooth_vacuum_integral(cutoff: sp.Expr, mass_squared: sp.Expr) -> sp.Expr: + if mass_squared.is_zero is True: + # Massless limit: integral_0^infty t^-3 exp(-1/t) dt = 1, so Lambda^4. + return cutoff**4 + z = mass_squared / cutoff**2 + return sp.simplify(2 * cutoff**4 * z * sp.besselk(2, 2 * sp.sqrt(z))) + + +def _zeta_vacuum_integral( + renormalization_scale: sp.Expr, mass_squared: sp.Expr +) -> sp.Expr: + if mass_squared.is_zero is True: + return sp.Integer(0) + return sp.simplify( + -(mass_squared**2 / 2) + * ( + sp.log(mass_squared / renormalization_scale**2) + + sp.EulerGamma + - sp.Rational(3, 2) + ) + ) + + +def curvature_proper_time_integral( + regulator: Any, + *, + cutoff: Any = None, + mass_squared: Any = 0, + renormalization_scale: Any = None, +) -> sp.Expr: + """Return the exact tau**-2-class proper-time integral for one scheme. + + This is the integral that multiplies the declared heat-kernel weights + ``((1/6 - xi)*R_E - m**2)`` in ``Gamma_E``; with the landed conditional + scheme factor it also multiplies the induced inverse-Newton shift. + """ + + resolved_cutoff, scale = _resolve_regulator(regulator, cutoff, renormalization_scale) + mass = _nonnegative_exact(mass_squared, "mass_squared") + if regulator == SHARP_PROPER_TIME_REGULATOR: + return _sharp_curvature_integral(resolved_cutoff, mass) + if regulator == SMOOTH_PROPER_TIME_REGULATOR: + return _smooth_curvature_integral(resolved_cutoff, mass) + return _zeta_curvature_integral(scale, mass) + + +def vacuum_proper_time_integral( + regulator: Any, + *, + cutoff: Any = None, + mass_squared: Any = 0, + renormalization_scale: Any = None, +) -> sp.Expr: + """Return the exact tau**-3-class proper-time integral for one scheme. + + This is the integral that multiplies the heat-kernel weight ``1`` (the + cosmological/vacuum sector of the one-loop action). + """ + + resolved_cutoff, scale = _resolve_regulator(regulator, cutoff, renormalization_scale) + mass = _nonnegative_exact(mass_squared, "mass_squared") + if regulator == SHARP_PROPER_TIME_REGULATOR: + return _sharp_vacuum_integral(resolved_cutoff, mass) + if regulator == SMOOTH_PROPER_TIME_REGULATOR: + return _smooth_vacuum_integral(resolved_cutoff, mass) + return _zeta_vacuum_integral(scale, mass) + + +@dataclass(frozen=True) +class ExactMassNewtonShift: + """Exact-mass induced inverse-Newton shift data for one scheme.""" + + regulator: str + field_count: sp.Expr + non_minimal_coupling: sp.Expr + mass_squared: sp.Expr + cutoff: sp.Expr | None + renormalization_scale: sp.Expr | None + proper_time_value: sp.Expr + coefficient_per_field: sp.Expr + value: sp.Expr + massless_leading_value: sp.Expr + finite_mass_factor: sp.Expr | None + curvature_weight_sign: int + value_sign: int | None + + +def exact_mass_inverse_newton_shift( + field_count: Any, + non_minimal_coupling: Any, + *, + regulator: Any, + cutoff: Any = None, + mass_squared: Any = 0, + renormalization_scale: Any = None, +) -> ExactMassNewtonShift: + """Return ``Delta(1/G) = N * coefficient_per_field * I_2`` exactly. + + ``coefficient_per_field`` is the per-field scheme factor + ``scheme_factor*(1/6 - xi)`` read from the landed conditional + ``scalar_induced_newton.leading_scalar_newton_shift_coefficient`` API + (its massless sharp regulator tag is used only to read that factor, + which is regulator-independent). The massless sharp limit reproduces + that module's ``N*(1-6*xi)*Lambda**2/(12*pi)`` exactly. + + ``curvature_weight_sign`` is the decidable sign of ``1/6 - xi`` only. + ``value_sign`` is the decidable sign of the full returned value, or + ``None`` when symbolic inputs leave it undecidable; the two coincide + for the cutoff schemes (``I_2 > 0``) but differ for the + power-subtracted scheme whenever ``I_2 < 0``. + """ + + resolved_cutoff, scale = _resolve_regulator(regulator, cutoff, renormalization_scale) + mass = _nonnegative_exact(mass_squared, "mass_squared") + count = _positive_integer(field_count, "field_count") + xi = _exact_real(non_minimal_coupling, "non_minimal_coupling") + + landed = leading_scalar_newton_shift_coefficient( + 1, xi, regulator=SHARP_PROPER_TIME_REGULATOR + ) + coefficient_per_field = landed.coefficient_per_field + + if regulator == SHARP_PROPER_TIME_REGULATOR: + proper_time_value = _sharp_curvature_integral(resolved_cutoff, mass) + massless_leading_value = sp.simplify( + count * coefficient_per_field * resolved_cutoff**2 + ) + finite_mass_factor = sp.simplify(proper_time_value / resolved_cutoff**2) + elif regulator == SMOOTH_PROPER_TIME_REGULATOR: + proper_time_value = _smooth_curvature_integral(resolved_cutoff, mass) + massless_leading_value = sp.simplify( + count * coefficient_per_field * resolved_cutoff**2 + ) + finite_mass_factor = sp.simplify(proper_time_value / resolved_cutoff**2) + else: + proper_time_value = _zeta_curvature_integral(scale, mass) + massless_leading_value = sp.Integer(0) + finite_mass_factor = None + + value = sp.simplify(count * coefficient_per_field * proper_time_value) + curvature_weight = sp.simplify(sp.Rational(1, 6) - xi) + if curvature_weight.is_positive is True: + curvature_weight_sign = 1 + elif curvature_weight.is_zero is True: + curvature_weight_sign = 0 + elif curvature_weight.is_negative is True: + curvature_weight_sign = -1 + else: + raise ValueError( + "non_minimal_coupling must have a decidable relation to the " + "four-dimensional conformal value 1/6" + ) + if value.is_positive is True: + value_sign: int | None = 1 + elif value.is_zero is True: + value_sign = 0 + elif value.is_negative is True: + value_sign = -1 + else: + value_sign = None + + return ExactMassNewtonShift( + regulator=regulator, + field_count=count, + non_minimal_coupling=xi, + mass_squared=mass, + cutoff=resolved_cutoff, + renormalization_scale=scale, + proper_time_value=proper_time_value, + coefficient_per_field=coefficient_per_field, + value=value, + massless_leading_value=massless_leading_value, + finite_mass_factor=finite_mass_factor, + curvature_weight_sign=curvature_weight_sign, + value_sign=value_sign, + ) + + +@dataclass(frozen=True) +class ExactMassVacuumShift: + """Exact-mass one-loop vacuum-sector data for one scheme.""" + + regulator: str + field_count: sp.Expr + mass_squared: sp.Expr + cutoff: sp.Expr | None + renormalization_scale: sp.Expr | None + tau_minus_two_value: sp.Expr + tau_minus_three_value: sp.Expr + value: sp.Expr + # tau_minus_two_value is exposed for reference and for the derivative + # identity d I_3 / d m**2 = -I_2; the returned value composes only the + # mass-resummed tau**-3 class. + + +def exact_mass_vacuum_density_shift( + field_count: Any, + *, + regulator: Any, + cutoff: Any = None, + mass_squared: Any = 0, + renormalization_scale: Any = None, +) -> ExactMassVacuumShift: + """Return ``Delta(rho) = -(N/2)*(4*pi)**-2*I_3(m**2)`` exactly. + + This is the vacuum (cosmological-sector) coefficient of the one-loop + action density in the mass-resummed organization: the trace integrand is + ``exp(-tau*m**2)*[tau**-2 + tau**-1*(1/6-xi)*R_E + ...]``, so the vacuum + sector is the tau**-3 class with the exponential retained. The + ``-m**2`` heat-kernel weight of the landed conditional + ``scalar_heat_kernel_a2`` is the first-order remnant of that same + exponential in the unresummed organization and must not be added again; + the exact bridge is the derivative identity ``d I_3/d m**2 = -I_2``. + The sector is exhibited rather than omitted whenever the curvature-sector + shift is quoted. + """ + + resolved_cutoff, scale = _resolve_regulator(regulator, cutoff, renormalization_scale) + mass = _nonnegative_exact(mass_squared, "mass_squared") + count = _positive_integer(field_count, "field_count") + + tau_minus_two = curvature_proper_time_integral( + regulator, + cutoff=resolved_cutoff, + mass_squared=mass, + renormalization_scale=scale, + ) + tau_minus_three = vacuum_proper_time_integral( + regulator, + cutoff=resolved_cutoff, + mass_squared=mass, + renormalization_scale=scale, + ) + value = sp.simplify( + -count + * sp.Rational(1, 2) + * _FOUR_DIMENSIONAL_HEAT_KERNEL_PREFACTOR + * tau_minus_three + ) + return ExactMassVacuumShift( + regulator=regulator, + field_count=count, + mass_squared=mass, + cutoff=resolved_cutoff, + renormalization_scale=scale, + tau_minus_two_value=tau_minus_two, + tau_minus_three_value=tau_minus_three, + value=value, + ) + + +@dataclass(frozen=True) +class RegulatorSchemeLedger: + """Exact scheme spread of the curvature-class integral at common scales.""" + + cutoff: sp.Expr + mass_squared: sp.Expr + renormalization_scale: sp.Expr + sharp_value: sp.Expr + smooth_value: sp.Expr + zeta_value: sp.Expr + sharp_over_smooth: sp.Expr + sharp_minus_zeta: sp.Expr + + +def regulator_scheme_ledger( + cutoff: Any, + mass_squared: Any, + renormalization_scale: Any, +) -> RegulatorSchemeLedger: + """Return the three curvature-class values and their exact contrasts. + + The sharp and smooth schemes are evaluated at the declared cutoff; the + power-subtracted scheme at the declared renormalization scale. The + contrasts are exact expressions, not numeric fits, so a later + renormalization-condition rung can cite them as reviewable provenance. + """ + + resolved_cutoff = _positive_exact(cutoff, "cutoff") + mass = _nonnegative_exact(mass_squared, "mass_squared") + scale = _positive_exact(renormalization_scale, "renormalization_scale") + + sharp_value = _sharp_curvature_integral(resolved_cutoff, mass) + smooth_value = _smooth_curvature_integral(resolved_cutoff, mass) + zeta_value = _zeta_curvature_integral(scale, mass) + return RegulatorSchemeLedger( + cutoff=resolved_cutoff, + mass_squared=mass, + renormalization_scale=scale, + sharp_value=sharp_value, + smooth_value=smooth_value, + zeta_value=zeta_value, + sharp_over_smooth=sp.simplify(sharp_value / smooth_value), + sharp_minus_zeta=sp.simplify(sharp_value - zeta_value), + ) diff --git a/tests/test_scalar_one_loop_mass.py b/tests/test_scalar_one_loop_mass.py new file mode 100644 index 00000000..69bef40d --- /dev/null +++ b/tests/test_scalar_one_loop_mass.py @@ -0,0 +1,441 @@ +"""Exact-mass one-loop proper-time coefficient tests (P230, advances #76). + +Oracles, per ``.agents/skills/physics-erdos-loop/references/oracles.md``: + +* exact identities are verified symbolically (derivative/tail uniqueness for + the sharp cutoff scheme, the integration-by-parts identity for its vacuum + class, the differential recurrence plus boundary limits for the smooth + Bessel family, and cutoff-subtraction limits for the power-subtracted + scheme); +* the special-function closed forms are independently corroborated by + high-precision mpmath quadrature; +* load-bearing mutations (wrong prefactor, wrong Bessel order, wrong + exponential-integral branch, wrong xi sign, unknown regulator, defaulted + scales) must each break a relevant check. +""" + +import mpmath as mp +import pytest +import sympy as sp + +import substrate_framework as framework +from substrate_framework.scalar_induced_newton import ( + SHARP_PROPER_TIME_REGULATOR, + leading_scalar_newton_shift_coefficient, +) +from substrate_framework.scalar_one_loop_mass import ( + KNOWN_ONE_LOOP_REGULATORS, + SMOOTH_PROPER_TIME_REGULATOR, + ZETA_POWER_SUBTRACTED_REGULATOR, + curvature_proper_time_integral, + exact_mass_inverse_newton_shift, + exact_mass_vacuum_density_shift, + regulator_scheme_ledger, + vacuum_proper_time_integral, +) + +Lam, mu, m2 = sp.symbols("Lambda mu m2", positive=True) +tau0, t = sp.symbols("tau0 t", positive=True) +z = sp.symbols("z", positive=True) + + +def test_one_loop_mass_api_is_exported_from_package() -> None: + assert framework.SMOOTH_PROPER_TIME_REGULATOR == SMOOTH_PROPER_TIME_REGULATOR + assert framework.ZETA_POWER_SUBTRACTED_REGULATOR == ZETA_POWER_SUBTRACTED_REGULATOR + assert framework.curvature_proper_time_integral is curvature_proper_time_integral + assert framework.vacuum_proper_time_integral is vacuum_proper_time_integral + assert framework.exact_mass_inverse_newton_shift is exact_mass_inverse_newton_shift + assert framework.exact_mass_vacuum_density_shift is exact_mass_vacuum_density_shift + assert framework.regulator_scheme_ledger is regulator_scheme_ledger + + +def test_sharp_curvature_closed_form_is_the_tail_integral_exactly() -> None: + # I(tau0) = Lam^2*(exp(-z)-z*E1(z)) with z = m2*tau0, Lam^2 = 1/tau0. + closed = (sp.exp(-m2 * tau0) - m2 * tau0 * sp.expint(1, m2 * tau0)) / tau0 + derivative_residual = sp.simplify( + sp.diff(closed, tau0) + tau0 ** -2 * sp.exp(-m2 * tau0) + ) + assert derivative_residual == 0 + # Tail decay pins the integration constant. E1(x) is by definition the + # tail integral integral_x^infty exp(-u)/u du; for u >= x > 0 the + # integrand is bounded by exp(-u)/x, whose tail integral sympy evaluates + # exactly, so 0 <= E1(x) <= exp(-x)/x -> 0. The explicit exponential + # piece vanishes directly. + assert sp.limit(sp.exp(-m2 * tau0) / tau0, tau0, sp.oo) == 0 + x, u = sp.symbols("x u", positive=True) + assert sp.integrate(sp.exp(-u) / x, (u, x, sp.oo)) == sp.exp(-x) / x + mp.mp.dps = 30 + for xf in (mp.mpf(30), mp.mpf(40)): + assert mp.e1(xf) < mp.e ** (-xf) / xf + assert mp.e1(xf) * xf * mp.e ** xf < 1 + # The module's expression is this closed form. + value = curvature_proper_time_integral( + SHARP_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + assert sp.simplify(value - Lam**2 * (sp.exp(-m2 / Lam**2) - (m2 / Lam**2) * sp.expint(1, m2 / Lam**2))) == 0 + + +def test_sharp_vacuum_closed_form_satisfies_the_by_parts_identity() -> None: + sharp2 = curvature_proper_time_integral( + SHARP_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + sharp3 = vacuum_proper_time_integral( + SHARP_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + expected = sp.exp(-m2 / Lam**2) * Lam**4 / 2 - (m2 / 2) * sharp2 + assert sp.simplify(sharp3 - expected) == 0 + # Independent derivation by parts from the tail-integral form. + by_parts = sp.integrate(sp.exp(-m2 * t) / t**3, (t, tau0, sp.oo)) + target = (sp.exp(-m2 * tau0) / (2 * tau0**2)) - (m2 / 2) * ( + (sp.exp(-m2 * tau0) - m2 * tau0 * sp.expint(1, m2 * tau0)) / tau0 + ) + # sympy may leave Ei-branch structure; compare via the derivative oracle. + residual = sp.diff(by_parts - target, tau0).replace( + sp.exp_polar, lambda arg: sp.exp(arg) + ) + assert sp.simplify(residual) == 0 + + +def test_smooth_closed_forms_satisfy_the_differential_recurrence() -> None: + # J_p(z) = integral_0^infty t^-p exp(-z t - 1/t) dt obeys dJ_p/dz = -J_{p-1}. + J1 = 2 * sp.besselk(0, 2 * sp.sqrt(z)) + J2 = 2 * sp.sqrt(z) * sp.besselk(1, 2 * sp.sqrt(z)) + J3 = 2 * z * sp.besselk(2, 2 * sp.sqrt(z)) + J0 = 2 * z ** sp.Rational(-1, 2) * sp.besselk(1, 2 * sp.sqrt(z)) + assert sp.simplify(sp.diff(J2, z) + J1) == 0 + assert sp.simplify(sp.diff(J3, z) + J2) == 0 + assert sp.simplify(sp.diff(J1, z) + J0) == 0 + # Boundary values pin the solutions of the recurrence. + assert sp.limit(J2, z, 0, "+") == 1 + assert sp.limit(J3, z, 0, "+") == 1 + # The module returns these forms at z = m2/Lam^2. + value2 = curvature_proper_time_integral( + SMOOTH_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + value3 = vacuum_proper_time_integral( + SMOOTH_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + assert sp.simplify(value2 - Lam**2 * J2.subs(z, m2 / Lam**2)) == 0 + assert sp.simplify(value3 - Lam**4 * J3.subs(z, m2 / Lam**2)) == 0 + + +@pytest.mark.parametrize("zf_str", ["0.1", "1.0", "2.5"]) +def test_smooth_closed_forms_match_high_precision_quadrature(zf_str) -> None: + mp.mp.dps = 40 + zf = mp.mpf(zf_str) + num2 = mp.quad(lambda tt: mp.e ** (-zf * tt - 1 / tt) / tt**2, [0, 1, mp.inf]) + closed2 = 2 * mp.sqrt(zf) * mp.besselk(1, 2 * mp.sqrt(zf)) + assert abs(num2 - closed2) < mp.mpf("1e-30") * abs(closed2) + num3 = mp.quad(lambda tt: mp.e ** (-zf * tt - 1 / tt) / tt**3, [0, 1, mp.inf]) + closed3 = 2 * zf * mp.besselk(2, 2 * mp.sqrt(zf)) + assert abs(num3 - closed3) < mp.mpf("1e-30") * abs(closed3) + + +@pytest.mark.parametrize("zf_str", ["0.1", "1.0", "2.5"]) +def test_sharp_closed_form_matches_quadrature(zf_str) -> None: + mp.mp.dps = 40 + zf = mp.mpf(zf_str) + num = mp.quad(lambda tt: mp.e ** (-zf * tt) / tt**2, [1.0, mp.inf]) + closed = mp.e ** (-zf) - zf * mp.e1(zf) + assert abs(num - closed) < mp.mpf("1e-30") * abs(closed) + + +def test_zeta_closed_forms_are_the_power_subtraction_limits() -> None: + sharp2 = (sp.exp(-m2 * tau0) - m2 * tau0 * sp.expint(1, m2 * tau0)) / tau0 + lim2 = sp.limit(sharp2 - 1 / tau0 - m2 * sp.log(tau0), tau0, 0, "+") + zeta2 = curvature_proper_time_integral( + ZETA_POWER_SUBTRACTED_REGULATOR, mass_squared=m2, renormalization_scale=mu + ) + assert sp.simplify(lim2 - m2 * (sp.log(m2) + sp.EulerGamma - 1)) == 0 + assert sp.simplify(zeta2 - m2 * (sp.log(m2 / mu**2) + sp.EulerGamma - 1)) == 0 + + sharp3 = sp.exp(-m2 * tau0) / (2 * tau0**2) - (m2 / 2) * sharp2 + lim3 = sp.limit( + sharp3 - 1 / (2 * tau0**2) + m2 / tau0 + (m2**2 / 2) * sp.log(tau0), + tau0, + 0, + "+", + ) + zeta3 = vacuum_proper_time_integral( + ZETA_POWER_SUBTRACTED_REGULATOR, mass_squared=m2, renormalization_scale=mu + ) + expected3 = -(m2**2 / 2) * (sp.log(m2) + sp.EulerGamma - sp.Rational(3, 2)) + assert sp.simplify(lim3 - expected3) == 0 + assert sp.simplify(zeta3 + (m2**2 / 2) * (sp.log(m2 / mu**2) + sp.EulerGamma - sp.Rational(3, 2))) == 0 + + +def test_massless_sharp_limit_reproduces_the_landed_conditional_shift() -> None: + N, xi = sp.Integer(3), sp.Rational(1, 12) + shift = exact_mass_inverse_newton_shift( + N, + xi, + regulator=SHARP_PROPER_TIME_REGULATOR, + cutoff=Lam, + mass_squared=0, + ) + landed = leading_scalar_newton_shift_coefficient( + N, xi, regulator=SHARP_PROPER_TIME_REGULATOR + ) + assert sp.simplify(shift.value - landed.coefficient * Lam**2) == 0 + assert sp.simplify(shift.finite_mass_factor - 1) == 0 + + smooth = exact_mass_inverse_newton_shift( + N, + xi, + regulator=SMOOTH_PROPER_TIME_REGULATOR, + cutoff=Lam, + mass_squared=0, + ) + # The smooth weight also integrates to exactly Lambda^2 when massless. + assert sp.simplify(smooth.value - landed.coefficient * Lam**2) == 0 + + zeta = exact_mass_inverse_newton_shift( + N, + xi, + regulator=ZETA_POWER_SUBTRACTED_REGULATOR, + mass_squared=0, + renormalization_scale=mu, + ) + # Power divergences subtracted: no induced shift survives at m = 0. + assert sp.simplify(zeta.value) == 0 + + +def test_small_z_series_recovers_the_exact_logarithmic_structure() -> None: + F = sp.exp(-z) - z * sp.expint(1, z) + series = sp.series(F, z, 0, 2).removeO() + assert sp.simplify(series - (1 + z * (sp.log(z) + sp.EulerGamma - 1))) == 0 + + +def test_scheme_ledger_reports_exact_contrasts() -> None: + ledger = regulator_scheme_ledger(Lam, m2, mu) + assert sp.simplify( + ledger.sharp_over_smooth + - ( + (sp.exp(-m2 / Lam**2) - (m2 / Lam**2) * sp.expint(1, m2 / Lam**2)) + / (2 * sp.sqrt(m2 / Lam**2) * sp.besselk(1, 2 * sp.sqrt(m2 / Lam**2))) + ) + ) == 0 + # At z = 1 the smooth scheme induces about 1.88 times the sharp value. + one = regulator_scheme_ledger(1, 1, 1) + ratio = float(sp.N(one.sharp_over_smooth, 12)) + assert abs(ratio - 0.5308496410) < 1e-8 + # The PR #13 review's load-bearing factor is reproduced at z = 1. + factor = sp.N( + sp.exp(-1) - sp.expint(1, 1), + 10, + ) + assert abs(factor - sp.Float("0.1484955068", 10)) < sp.Float("1e-9") + + +def test_exact_mass_shift_composes_the_landed_conditional_scheme_factor() -> None: + N, xi = sp.Integer(2), sp.Rational(1, 12) + shift = exact_mass_inverse_newton_shift( + N, + xi, + regulator=SHARP_PROPER_TIME_REGULATOR, + cutoff=Lam, + mass_squared=m2, + ) + landed = leading_scalar_newton_shift_coefficient( + 1, xi, regulator=SHARP_PROPER_TIME_REGULATOR + ) + assert sp.simplify(shift.coefficient_per_field - landed.coefficient_per_field) == 0 + assert sp.simplify(shift.value - N * landed.coefficient_per_field * shift.proper_time_value) == 0 + + +def test_vacuum_shift_is_the_mass_resummed_determinant_integrand() -> None: + # In the mass-resummed organization the trace integrand is + # exp(-tau*m^2)*[tau^-2 + tau^-1*(1/6-xi)*R + ...], so the vacuum sector + # is the tau^-3 class alone. The value must compose ONLY I_3. + N = sp.Integer(4) + for regulator, kwargs in ( + (SHARP_PROPER_TIME_REGULATOR, {"cutoff": Lam, "mass_squared": m2}), + (SMOOTH_PROPER_TIME_REGULATOR, {"cutoff": Lam, "mass_squared": m2}), + ( + ZETA_POWER_SUBTRACTED_REGULATOR, + {"mass_squared": m2, "renormalization_scale": mu}, + ), + ): + vac = exact_mass_vacuum_density_shift(N, regulator=regulator, **kwargs) + expected = -N * sp.Rational(1, 2) * (4 * sp.pi) ** -2 * vac.tau_minus_three_value + assert sp.simplify(vac.value - expected) == 0 + # Massless sharp vacuum sector: I_3 = Lambda^4/2. + vac0 = exact_mass_vacuum_density_shift( + 1, regulator=SHARP_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=0 + ) + assert sp.simplify(vac0.value + Lam**4 / (4 * (4 * sp.pi) ** 2)) == 0 + + +def test_double_counted_vacuum_composition_is_rejected_by_the_oracle() -> None: + # The reviewed defect: composing the resummed I_3 with the unresummed + # -m^2 weight (i.e. I_3 + m^2*I_2) differs from the exact factored + # determinant by the generally nonzero term -(N/2)*(4*pi)^-2*m^2*I_2. + N = sp.Integer(1) + vac = exact_mass_vacuum_density_shift( + N, regulator=SHARP_PROPER_TIME_REGULATOR, cutoff=Lam, mass_squared=m2 + ) + double_counted = -N * sp.Rational(1, 2) * (4 * sp.pi) ** -2 * ( + vac.tau_minus_three_value + m2 * vac.tau_minus_two_value + ) + assert sp.simplify(double_counted - vac.value - m2 * vac.tau_minus_two_value * (-N * sp.Rational(1, 2) * (4 * sp.pi) ** -2)) == 0 + # ... and the spurious term is nonzero for m^2 > 0 (it vanishes only at + # m = 0, which is why the massless regression could not catch it). + assert sp.simplify(m2 * vac.tau_minus_two_value) != 0 + + +@pytest.mark.parametrize( + "regulator,kwargs", + [ + (SHARP_PROPER_TIME_REGULATOR, {"cutoff": Lam, "mass_squared": m2}), + (SMOOTH_PROPER_TIME_REGULATOR, {"cutoff": Lam, "mass_squared": m2}), + ( + ZETA_POWER_SUBTRACTED_REGULATOR, + {"mass_squared": m2, "renormalization_scale": mu}, + ), + ], +) +def test_derivative_identity_links_the_two_integral_classes(regulator, kwargs) -> None: + # d I_3 / d m^2 = -I_2 holds exactly in every scheme; it is the exact + # bridge showing the -m^2 heat-kernel weight is the first-order remnant + # of the retained exponential, not an additive piece of I_3. + i2 = curvature_proper_time_integral(regulator, **kwargs) + i3 = vacuum_proper_time_integral(regulator, **kwargs) + assert sp.simplify(sp.diff(i3, m2) + i2) == 0 + + +def test_mutations_break_the_oracles() -> None: + # Wrong prefactor: doubling the sharp closed form fails the tail identity. + doubled = 2 * (sp.exp(-m2 * tau0) - m2 * tau0 * sp.expint(1, m2 * tau0)) / tau0 + residual = sp.simplify(sp.diff(doubled, tau0) + tau0 ** -2 * sp.exp(-m2 * tau0)) + assert residual != 0 + # Wrong exponential-integral branch: Ei instead of E1 fails it too. + wrong_branch = (sp.exp(-m2 * tau0) - m2 * tau0 * sp.Ei(m2 * tau0)) / tau0 + residual_branch = sp.simplify( + sp.diff(wrong_branch, tau0) + tau0 ** -2 * sp.exp(-m2 * tau0) + ) + assert residual_branch != 0 + # Wrong Bessel order: K_2 in the curvature class breaks the recurrence. + wrong_order = 2 * sp.sqrt(z) * sp.besselk(2, 2 * sp.sqrt(z)) + J1 = 2 * sp.besselk(0, 2 * sp.sqrt(z)) + assert sp.simplify(sp.diff(wrong_order, z) + J1) != 0 + # Crossing the conformal value 1/6 flips the curvature weight sign: the + # minimal coupling xi = 0 has 1/6 - xi > 0 while xi = 1 flips it. For + # the cutoff schemes I_2 > 0, so the value sign follows. + plus = exact_mass_inverse_newton_shift( + 1, 0, regulator=SHARP_PROPER_TIME_REGULATOR, cutoff=Lam + ) + minus = exact_mass_inverse_newton_shift( + 1, 1, regulator=SHARP_PROPER_TIME_REGULATOR, cutoff=Lam + ) + assert plus.curvature_weight_sign == 1 and minus.curvature_weight_sign == -1 + assert plus.value_sign == 1 and minus.value_sign == -1 + assert sp.simplify(plus.value + minus.value) != 0 + + +def test_zeta_value_sign_disagrees_with_the_curvature_weight_sign() -> None: + # Reviewer counterexample: N=1, xi=0, m^2 = mu^2 = 1 gives a negative + # total shift while the curvature weight is positive. + negative = exact_mass_inverse_newton_shift( + 1, + 0, + regulator=ZETA_POWER_SUBTRACTED_REGULATOR, + mass_squared=1, + renormalization_scale=1, + ) + assert negative.curvature_weight_sign == 1 + assert negative.value.is_negative is True + assert negative.value_sign == -1 + assert sp.simplify(negative.value - (sp.EulerGamma - 1) / (12 * sp.pi)) == 0 + + # Massless power-subtracted branch: value is exactly zero, so the value + # sign is 0 even though the curvature weight stays positive. + zero = exact_mass_inverse_newton_shift( + 1, + 0, + regulator=ZETA_POWER_SUBTRACTED_REGULATOR, + mass_squared=0, + renormalization_scale=1, + ) + assert zero.value == 0 + assert zero.curvature_weight_sign == 1 + assert zero.value_sign == 0 + + # Symbolic scale ratio: the value sign is undecidable, not guessed. + symbolic = exact_mass_inverse_newton_shift( + 1, + 0, + regulator=ZETA_POWER_SUBTRACTED_REGULATOR, + mass_squared=m2, + renormalization_scale=mu, + ) + assert symbolic.value_sign is None + assert symbolic.curvature_weight_sign == 1 + + # Large-mass zeta branch flips the integral itself positive. + positive = exact_mass_inverse_newton_shift( + 1, + 0, + regulator=ZETA_POWER_SUBTRACTED_REGULATOR, + mass_squared=sp.Integer(10), + renormalization_scale=1, + ) + assert positive.value_sign == 1 + + +def test_input_contracts_reject_ambiguous_schemes() -> None: + with pytest.raises(ValueError): + curvature_proper_time_integral("wrong_name", cutoff=Lam) + with pytest.raises(ValueError): + curvature_proper_time_integral(SMOOTH_PROPER_TIME_REGULATOR) + with pytest.raises(ValueError): + curvature_proper_time_integral( + SMOOTH_PROPER_TIME_REGULATOR, + cutoff=Lam, + renormalization_scale=mu, + ) + with pytest.raises(ValueError): + curvature_proper_time_integral(ZETA_POWER_SUBTRACTED_REGULATOR) + with pytest.raises(ValueError): + curvature_proper_time_integral( + ZETA_POWER_SUBTRACTED_REGULATOR, + cutoff=Lam, + renormalization_scale=mu, + ) + with pytest.raises(ValueError): + curvature_proper_time_integral( + SHARP_PROPER_TIME_REGULATOR, + cutoff=Lam, + mass_squared=sp.Symbol("neg", negative=True), + ) + with pytest.raises(ValueError): + exact_mass_inverse_newton_shift( + sp.Rational(3, 2), + 0, + regulator=SHARP_PROPER_TIME_REGULATOR, + cutoff=Lam, + ) + with pytest.raises(ValueError): + exact_mass_inverse_newton_shift( + 1, + sp.Symbol("xi", real=True), + regulator=SHARP_PROPER_TIME_REGULATOR, + cutoff=Lam, + ) + + +def test_module_is_target_blind() -> None: + import inspect + + from substrate_framework import scalar_one_loop_mass + + source = inspect.getsource(scalar_one_loop_mass) + for forbidden in ("6.674", "Planck", "M_pl", "6.708", "observed"): + assert forbidden not in source + + +def test_known_regulators_are_the_three_preregistered_schemes() -> None: + assert set(KNOWN_ONE_LOOP_REGULATORS) == { + SHARP_PROPER_TIME_REGULATOR, + SMOOTH_PROPER_TIME_REGULATOR, + ZETA_POWER_SUBTRACTED_REGULATOR, + }