From a7421bbb7957f92d360947727b7bb9ff25835376 Mon Sep 17 00:00:00 2001 From: Dylan Roy Date: Thu, 1 Oct 2026 09:40:06 -0500 Subject: [PATCH] Add independent rational certification of the nine c/c2 output enclosures Replay companion to numerical review5380714607 of PR223. Integer/Fraction-only interval oracle with explicit positive-real Stirling remainder independently encloses the supplied closed forms; all nine lie strictly inside the peer's published intervals. Includes exact source bindings, 37 tests in both Python modes, and the corrected reviewer-cache domain regression. No original derivation replay or blanket complex/normal-tail engine acceptance. No source branch, scientific register, formal scope or theorem promotion. Historical source authentication remains the hosted requirement; no self-merge. --- .github/workflows/c2-interval-audit.yml | 41 ++++ .../c2_interval_audit_20261001/MANIFEST.json | 59 ++++++ reviews/c2_interval_audit_20261001/README.md | 31 ++++ .../c2_interval_audit_20261001/RESULTS.json | 110 +++++++++++ reviews/c2_interval_audit_20261001/REVIEW.md | 175 ++++++++++++++++++ .../SOURCE_BINDINGS.json | 31 ++++ .../c2_interval_audit_20261001/VALIDATION.md | 35 ++++ reviews/c2_interval_audit_20261001/oracle.py | 170 +++++++++++++++++ .../test_bindings.py | 55 ++++++ .../c2_interval_audit_20261001/test_oracle.py | 106 +++++++++++ reviews/c2_interval_audit_20261001/verify.py | 83 +++++++++ 11 files changed, 896 insertions(+) create mode 100644 .github/workflows/c2-interval-audit.yml create mode 100644 reviews/c2_interval_audit_20261001/MANIFEST.json create mode 100644 reviews/c2_interval_audit_20261001/README.md create mode 100644 reviews/c2_interval_audit_20261001/RESULTS.json create mode 100644 reviews/c2_interval_audit_20261001/REVIEW.md create mode 100644 reviews/c2_interval_audit_20261001/SOURCE_BINDINGS.json create mode 100644 reviews/c2_interval_audit_20261001/VALIDATION.md create mode 100644 reviews/c2_interval_audit_20261001/oracle.py create mode 100644 reviews/c2_interval_audit_20261001/test_bindings.py create mode 100644 reviews/c2_interval_audit_20261001/test_oracle.py create mode 100644 reviews/c2_interval_audit_20261001/verify.py diff --git a/.github/workflows/c2-interval-audit.yml b/.github/workflows/c2-interval-audit.yml new file mode 100644 index 000000000..b189a1136 --- /dev/null +++ b/.github/workflows/c2-interval-audit.yml @@ -0,0 +1,41 @@ +name: Independent c2 interval audit + +'on': + pull_request: + paths: + - 'reviews/c2_interval_audit_20261001/**' + - '.github/workflows/c2-interval-audit.yml' + workflow_dispatch: + +permissions: + contents: read + +jobs: + rational-and-source: + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 + with: + persist-credentials: false + fetch-depth: 0 + - uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 + with: + python-version: '3.11.16' + - name: Verify the frozen peer source and independent certificate + env: + PYTHONDONTWRITEBYTECODE: '1' + GIT_NO_REPLACE_OBJECTS: '1' + run: | + set -euo pipefail + git fetch --no-tags origin 59a06b65d138994119551059fa336919c07188bf + python -B -S reviews/c2_interval_audit_20261001/verify.py + cd reviews/c2_interval_audit_20261001 + python -B -S -m unittest -v + python -B -O -S -m unittest -v + python -B -S oracle.py > "$RUNNER_TEMP/c2-normal.json" + python -B -O -S oracle.py > "$RUNNER_TEMP/c2-optimized.json" + cmp "$RUNNER_TEMP/c2-normal.json" "$RUNNER_TEMP/c2-optimized.json" + cmp RESULTS.json "$RUNNER_TEMP/c2-normal.json" + python -B -S verify.py + git diff --exit-code diff --git a/reviews/c2_interval_audit_20261001/MANIFEST.json b/reviews/c2_interval_audit_20261001/MANIFEST.json new file mode 100644 index 000000000..91a93fd2d --- /dev/null +++ b/reviews/c2_interval_audit_20261001/MANIFEST.json @@ -0,0 +1,59 @@ +{ + "scientific_effect": "NONE", + "files": [ + { + "path": "README.md", + "bytes": 1519, + "sha256": "f831e1fca62aaf745c1e8e8668679364e1dc1764340c6ee13e15d91e57c78146", + "git_blob": "9826f80b33d4bf605301f1b0a51f85490a62b009" + }, + { + "path": "RESULTS.json", + "bytes": 3044, + "sha256": "27f91293c0ef8cc36975718eecfcd25c554022e2f8e12e41eda60bd77a1b4310", + "git_blob": "ea7cfd2064c72b973683e6a66f9d0a892b31c975" + }, + { + "path": "REVIEW.md", + "bytes": 9655, + "sha256": "c808a02dfd2e8cea53985ceca7de8cb53d07db82b0bfbc368b6e37719239a5cf", + "git_blob": "008b017524e669c1496613c48988db170a3824e5" + }, + { + "path": "SOURCE_BINDINGS.json", + "bytes": 920, + "sha256": "c467e8afa40067094344d017c9d0deff70c4af9c8c4a7b2a43e781d706befcdd", + "git_blob": "02d76b06977a77c509905458d34aeff6104f375e" + }, + { + "path": "VALIDATION.md", + "bytes": 2266, + "sha256": "1f7868d47fdfc883589786c00e3dbc8f8e16b496c64e9f44504a84874ee6bfd6", + "git_blob": "94bca6d5a44a8e1fd74faa34b1fc909eae51e508" + }, + { + "path": "oracle.py", + "bytes": 6375, + "sha256": "b462b1b24613f74abd66042e0f347f69423595e9a1aedf1c6b45197425afe075", + "git_blob": "094bdf84bc8be7aedb4e50e1b1b3732ce0e6f112" + }, + { + "path": "test_bindings.py", + "bytes": 3459, + "sha256": "6fc688dfe38713345f07581dc01488589804946c81c360f33ad45d231a8a5ddd", + "git_blob": "4349b2113e5f8782bd4eacea79d643286c12334b" + }, + { + "path": "test_oracle.py", + "bytes": 6087, + "sha256": "b9c18a8274874e8bba6161c82b35fb75cb03b031d1cfccef1e7de8b38267ff6b", + "git_blob": "f494bea76ece18538a222358067f462cd4dc9206" + }, + { + "path": "verify.py", + "bytes": 4459, + "sha256": "df27846b1c3bf8a97918c543702ddfad1e0d9fdc4e9a63911e5a4d80d665daf8", + "git_blob": "c6fb38bf91bf76f07c171b0120eb86ed18028513" + } + ] +} diff --git a/reviews/c2_interval_audit_20261001/README.md b/reviews/c2_interval_audit_20261001/README.md new file mode 100644 index 000000000..9826f80b3 --- /dev/null +++ b/reviews/c2_interval_audit_20261001/README.md @@ -0,0 +1,31 @@ +# Independent c/c2 numerical enclosure review + +Read REVIEW.md. This is the replay companion to numerical review5380714607 of +Math-#223, not a new persistence theorem or a replacement for its author branch. + +A separate integer/Fraction evaluator certifies the nine supplied reference-kernel +expressions for c, c2 and c2/c in dimensions1,2,3. Each exact rational result is +strictly inside the original published interval. No floating numerical engine, +Gamma library or quadrature is imported. Scientific effect NONE. + +## Replay + + python -B -S -m unittest -v + python -B -O -S -m unittest -v + python -B -S oracle.py + python -B -S verify.py --local-only + +Full historical source authentication, in a checkout containing the pinned commit: + + python -B -S reviews/c2_interval_audit_20261001/verify.py + +The last command verifies six exact source paths/blobs and checks that the copied +published decimal intervals are exactly those in the source RESULTS.json. +Local-only replay explicitly does not authenticate the upstream Git objects. + +The primary mathematical input beyond elementary interval operations and series +is the positive-real log-Gamma Stirling remainder bound in NIST DLMF5.11(ii). +The proof and explicit remainder terms are in REVIEW.md. No full parent theorem, +finite-L c2 transfer, complex quadrature, full libm implementation or unused +special-function branch is accepted by this record. Same-provider/source exposure +and the corrected reviewer-cache test are recorded without rewriting history. diff --git a/reviews/c2_interval_audit_20261001/RESULTS.json b/reviews/c2_interval_audit_20261001/RESULTS.json new file mode 100644 index 000000000..ea7cfd206 --- /dev/null +++ b/reviews/c2_interval_audit_20261001/RESULTS.json @@ -0,0 +1,110 @@ +{ + "Gamma_shift": 40, + "Gamma_terms": 20, + "binary_float_used": false, + "dyadic_bits": 240, + "scientific_effect": "NONE", + "scope": "independent numerical certification of the nine supplied closed forms only", + "source_analytic_derivation_revalidated": false, + "values": { + "1.c": { + "independent_rational_interval": [ + "0.1101103789590514065452039444366610750264", + "0.1101103789590514065452039444366610750265" + ], + "published_interval": [ + "0.1101103789590410", + "0.1101103789590625" + ], + "strictly_inside": true + }, + "1.c2": { + "independent_rational_interval": [ + "0.2300445802661749520884735424539552034425", + "0.2300445802661749520884735424539552034426" + ], + "published_interval": [ + "0.2300445802661503", + "0.2300445802661998" + ], + "strictly_inside": true + }, + "1.ratio": { + "independent_rational_interval": [ + "2.0892179505778060085066669206919920101495", + "2.0892179505778060085066669206919920101496" + ], + "published_interval": [ + "2.089217950577392", + "2.089217950578207" + ], + "strictly_inside": true + }, + "2.c": { + "independent_rational_interval": [ + "0.0734069193060342710301359629577740500176", + "0.0734069193060342710301359629577740500177" + ], + "published_interval": [ + "0.07340691930602738", + "0.07340691930604167" + ], + "strictly_inside": true + }, + "2.c2": { + "independent_rational_interval": [ + "0.2215244106266869909000115594001050107224", + "0.2215244106266869909000115594001050107225" + ], + "published_interval": [ + "0.2215244106266632", + "0.2215244106267110" + ], + "strictly_inside": true + }, + "2.ratio": { + "independent_rational_interval": [ + "3.0177592619457197900651855521106551257715", + "3.0177592619457197900651855521106551257716" + ], + "published_interval": [ + "3.017759261945122", + "3.017759261946299" + ], + "strictly_inside": true + }, + "3.c": { + "independent_rational_interval": [ + "0.0417759318405983433429366654285755564666", + "0.0417759318405983433429366654285755564667" + ], + "published_interval": [ + "0.04177593184059426", + "0.04177593184060272" + ], + "strictly_inside": true + }, + "3.c2": { + "independent_rational_interval": [ + "0.1612340491269627375475895156318002608686", + "0.1612340491269627375475895156318002608687" + ], + "published_interval": [ + "0.1612340491269447", + "0.1612340491269810" + ], + "strictly_inside": true + }, + "3.ratio": { + "independent_rational_interval": [ + "3.8594961745478909155664511588764160940108", + "3.8594961745478909155664511588764160940109" + ], + "published_interval": [ + "3.859496174547095", + "3.859496174548665" + ], + "strictly_inside": true + } + } +} diff --git a/reviews/c2_interval_audit_20261001/REVIEW.md b/reviews/c2_interval_audit_20261001/REVIEW.md new file mode 100644 index 000000000..008b01752 --- /dev/null +++ b/reviews/c2_interval_audit_20261001/REVIEW.md @@ -0,0 +1,175 @@ +# Independent rational certification of the c/c2 output table + +Object OA-C2-NUMERICAL-REVIEW-20261001. Actual performer: OpenAI / GPT-6 Astra Pro. +Requested pickup: Math-#223 comment5933232496. Delivered native review5380714607. +Coordination: main#229. Scientific effect NONE; no self-merge or status transition. + +## 1. Exact target and conclusion + +The inspected target is Math-#223 at59a06b65d138994119551059fa336919c07188bf. +SOURCE_BINDINGS.json gives six immutable file identities. The numerical conclusion +is **ACCEPT of the nine published enclosures of the supplied closed forms**: +leading c, correction c2, and c2/c in dimensions1,2,3 for the reference Gaussian +kernel. The independent evaluator proves strict containment inside all nine +source intervals; the source's broader endpoints need not change. + +This review does not prove that these expressions equal the coefficients of an +actual Gaussian persistence law. The jet/Isserlis derivation, finite part, +typed-versus-fixed-cone comparison, candidate/elder asymptotics and finite-torus +c2 transfer retain their own exact premises and review requirements. In particular, +reference-kernel c2 is not silently a SIDE24 c2 certificate. + +The performer did not author the inspected numerical engine, but is exposed to +upstream Gaussian/persistence sources. There is no organizational or human +independence credit. The new evaluator is reviewer-authored, not an independently +reviewed program in its own right. Its explicit interval proof follows. + +## 2. Independent evaluator and why its intervals enclose the real values + +`oracle.py` imports no source numerical implementation. All numerical quantities +are Python integers or Fractions. There is no floating arithmetic, Gamma library, +quadrature, NumPy, mpmath or interval package in its evaluation path. + +Every arithmetic operation rounds an exact rational lower endpoint DOWN and an +exact rational upper endpoint UP to multiples of2^-240. Products and divisions +use all four endpoint combinations; zero-containing divisors are rejected. +Interval inclusion follows by induction over these arithmetic operations. Final +40-decimal display also uses integer floor/ceiling, not binary-float formatting. + +### Pi, logarithm, exponentials and roots + +Pi uses the Machin identity16 atan(1/5)-4 atan(1/239). For atan(x),0=0, divide t by2 repeatedly until s<=1/2. Its positive Taylor +sum through degree100 has remainder between zero and + + s^101/[101! (1-s/102)]. + +The bound follows because every subsequent term ratio is at most s/102. Repeated +outward interval squaring returns exp(t); negative t uses an outward reciprocal. +This differs from the inspected engine's binary64 range-reduced Horner algorithm. + +The n-th root of a nonnegative rational t is bracketed by adjacent multiples of +2^-240. The integer search chooses k with k^n<=floor(t2^(240n))<(k+1)^n; hence +k/2^240<=t^(1/n)<(k+1)/2^240 unless equality is exact. No library power is trusted. + +### Positive-real Gamma + +For q>0 set y=q+40. Generate the Bernoulli numbers independently by their exact +rational recurrence. Use the log-Gamma Stirling sum through B40: + + S(y)=(y-1/2)log y-y+(1/2)log(2pi) + +sum_(j=1)^20 B_(2j)/[2j(2j-1)y^(2j-1)]. + +For positive real y, the remainder is bounded by the first omitted term, so + + |log Gamma(y)-S(y)| <= |B42|/[42*41*y^41]. + +This is the positive-real bound in NIST DLMF5.11(ii), for expansion5.11.1: +https://dlmf.nist.gov/5.11#ii . The source was inspected at its online statement; +no novel special-function theorem or complex-domain extension is claimed. +Subtract log of the exact rational product prod_(j=0)^39(q+j), then use the +monotone interval exponential. This gives a rigorous enclosure of Gamma(q). +The inspected source engine instead shifts by10 and uses the B22 bound. + +### Closed-form assembly + +Let A=Gamma(1/6)/12^(1/6), B=Gamma(5/6)12^(1/6), s=sqrt6. Then the supplied +expressions are + + c1dim=A/(6pi^(3/2)), c2dim=A/(9pi^(3/2)), + c3dim=(29/72-s/12)A/pi^(5/2), + corr1=(3/4)B/pi^(3/2), corr2=(13/18)B/pi^(3/2), + corr3=(5/48)(33-7s)B/pi^(5/2). + +Here c1dim denotes the leading c in dimension1, NOT the cusp coefficient called +c1 in CU. The program labels outputs `1.c`, `1.c2`, etc to avoid this ambiguity. +All three leading denominators are strictly positive in the computed intervals, +so the three ratios are valid interval divisions. The cone subtraction terms +are retained with their signs, not replaced by half an untruncated moment. + +Each resulting rational interval has width<10^-45. The program verifies strict +containment inside each original published decimal pair using Fractions. This +is a new independent numerical certificate of those displayed expressions, +not a comparison of a few floating digits or an extrapolation from a test grid. + +## 3. The reached code path in the inspected engine + +The basic binary64 arithmetic widens each endpoint by nextafter after arithmetic +or square root, under its stated finite IEEE-754 arithmetic assumptions. This +review concerns the finite arguments used to evaluate these nine outputs. No +general portability proof about every libm routine or unbounded input is claimed. + +The source output path uses Machin pi, positive logarithms, real exponentials, +Gamma at1/6 and5/6, rational powers of12, square roots, and signed sums. Inspection +finds no load-bearing problem with these reached branches: positive divisors and +roots are preserved, the Gamma product/first-omitted remainder is included, and +negative half-integer powers of pi use integer floor division plus a sqrt(pi) +factor correctly. `pub` widens the numerical intervals before directed Decimal +formatting, rather than interpreting rounded decimal centers as exact values. + +Even without treating the source arithmetic library as a universal verified +package, Section2 independently certifies the exact published endpoints. +UNUSED routines are outside this review: normal Phi/Mills tails, trigonometric +and Sinc branches, complex boxes, analytic quadrature/slab selection, and the +million-node reference cusp integration. Exact file equality in another packet +does not widen this review's domain to those routines. + +## 4. Narrow resolution of the prior textual finding + +OA-223-A-01 at review5379979090 objected to calling the actual typed kernel A_r +analytic. The successor NOTE at this review head defines the fixed-cone surrogate +A~_r, states the imported relation A_r=A~_r+O(r^3), and asserts analyticity only +for A~_r. This closes that notation/scope defect at the exact reviewed successor. +It does not independently establish the imported comparison or replace the prior +jet/Isserlis and integration reviews5379979090/5379878251. + +## 5. Actual execution, a reviewer-code correction and limits + +The initial six-test oracle scaffold failed six assertions; the first completed +oracle passed those six. Expanded tests found a genuine defect in THIS NEW +reviewer harness: untyped lru_cache keys equated a cached Fraction(1,2) with0.5, +bypassing the exact-input validator. The isolated reproducer showed a cache hit; +`typed=True` and a dedicated regression fix it. This is not a defect attributed +to the inspected peer's code, and it did not alter the Fraction-only output path. + +Final exact-math tests include recurrence/reflection and integer Gamma identities, +independent coefficient atoms, ratio formulas, radical brackets, all-corner +rational arithmetic, signed outward rounding, and falsifiers for cone omission +and false numerical endpoints. Separate real local Git fixtures check source +identity, unsafe paths, original-versus-worktree reads and replacement refs. +Full ordinary/optimized counts and command outcomes are recorded in VALIDATION.md. + +The original peer exact.py/pseries/certificate.py pipeline was NOT executed by +this reviewer locally. Historical objects were read via the GitHub connector; +local network retrieval failed. `verify.py --local-only` explicitly excludes +historical source authentication. The hosted workflow must fetch the pinned +commit, authenticate all six source paths and confirm the literal source output +intervals match the nine inputs copied in oracle.py. Local fixtures do not stand +in for that check. The new evaluator's output is checked deterministically in +both Python modes. No new analytic/theorem or formal-verification status follows +from a successful job. + +## 6. Reuse and remaining assignments + +This record closes the nine-output numerical certificate question for #223. +The common primitive review may be used elsewhere only for identical inspected +functions under the same preconditions. #219 still requires its Mellin reduction, +complex analytic domain, quadrature error and tail work; this record does not +accept those. The general finite-L c2 problem needs a signed/subtracted-integral +perturbation estimate, not the positive homogeneous c1 sandwich. The concrete +finite-part continuity estimate posted in223/5933574379 defines a bounded route. + +No source math/code was edited. The author's integration lease remains intact. +This new review companion is additive and not self-merged. Institutional human +review and full parent-kernel formalization remain unsupplied validation. diff --git a/reviews/c2_interval_audit_20261001/SOURCE_BINDINGS.json b/reviews/c2_interval_audit_20261001/SOURCE_BINDINGS.json new file mode 100644 index 000000000..02d76b069 --- /dev/null +++ b/reviews/c2_interval_audit_20261001/SOURCE_BINDINGS.json @@ -0,0 +1,31 @@ +{ + "repository": "d6g8k5htny-coder/Math-", + "commit": "59a06b65d138994119551059fa336919c07188bf", + "scientific_effect": "NONE", + "files": [ + { + "path": "frontiers/c2_exact_20261001/ia.py", + "git_blob": "cf4bbfa16f577fe65f4ab5fb3621943fa63cf9fa" + }, + { + "path": "frontiers/c2_exact_20261001/elem.py", + "git_blob": "99ad3332b40daa1eee50106dbaa8b4b726cd5ae6" + }, + { + "path": "frontiers/c2_exact_20261001/gam.py", + "git_blob": "e7707bf14aad66ff8aa40ec5d40bf7ab426d4139" + }, + { + "path": "frontiers/c2_exact_20261001/certificate.py", + "git_blob": "96f1913f909118d921ea16161a1ff0885ba6aaef" + }, + { + "path": "frontiers/c2_exact_20261001/RESULTS.json", + "git_blob": "3077d9b29bc2393fbae1dd2c8420ca1bcc3707dd" + }, + { + "path": "frontiers/c2_exact_20261001/NOTE.md", + "git_blob": "a2798b87674ed5fc0d2144697e77ccb9b185b4ab" + } + ] +} diff --git a/reviews/c2_interval_audit_20261001/VALIDATION.md b/reviews/c2_interval_audit_20261001/VALIDATION.md new file mode 100644 index 000000000..94bca6d5a --- /dev/null +++ b/reviews/c2_interval_audit_20261001/VALIDATION.md @@ -0,0 +1,35 @@ +# Reviewer-side execution record + +Actual performer OpenAI / GPT-6 Astra Pro, numerical reviewer of #223. +This record is not an independent human review and not a source-author replay. + +The initial six mathematical tests failed on the deliberate no-op scaffold, then +passed after implementation. Expanded25-method tests found one failure: an +untyped cache key admitted a float alias after caching a Fraction. The reproducer +showed a cache hit for0.5 after Fraction(1,2). Typed cache keys and a new exact +regression produced26 passing mathematical tests. The source/packet11-method +scaffold separately produced14 failures before implementation, then all11 passed. + +Final suite:37 tests PASS in each normal and optimized Python mode. The serialized +oracle output is identical in both modes and matches RESULTS.json. All9 exact +rational enclosures are strictly inside the original published endpoints; their +internal widths are <10^-45. There is no binary floating arithmetic in evaluation. +The published40-decimal displays use exact outward integer floor/ceiling. + +The cache repair belongs to this new oracle, not the peer library. The exact +Fraction output path was unchanged. Tests of false endpoint shrinkage and omitted +cone terms explicitly reject those assertions; they are not mutations of the +source Gaussian proof. No model-dependent coefficient is numerically integrated. + +This reviewer read ia.py, elem.py, gam.py, certificate.py, NOTE.md and RESULTS.json +through the GitHub connector at exact head59a06b65d138994119551059fa336919c07188bf. +It did not locally replay the original source exact.py/pseries derivation or its +full certificate command. DNS prevented an upstream checkout. Local verification +therefore marks historical_sources_checked=false; the hosted workflow must perform +actual source authentication and literal output-binding comparison. No hosted +outcome is anticipated by this author-time record. The real-Git fixtures test +this behavior on temporary repositories rather than fabricate project inputs. + +No source branch, source proof, scientific register, prize or formal-scope file was +changed. The numerical review accepts exact expression enclosures, not their +identification with a full persistence law or a finite-lifetime error bound. diff --git a/reviews/c2_interval_audit_20261001/oracle.py b/reviews/c2_interval_audit_20261001/oracle.py new file mode 100644 index 000000000..094bdf84b --- /dev/null +++ b/reviews/c2_interval_audit_20261001/oracle.py @@ -0,0 +1,170 @@ +"""Independent rational enclosure of PR223's nine numerical outputs. + +No source numerical engine is imported. Fractions and integers only; all interval +rounding is outward to 2^-240. Log/exp are bounded by explicit power-series tails; +Gamma uses the positive-real Stirling remainder, not float Gamma or quadrature. +This evaluates supplied closed forms, not their Gaussian/persistence derivation. +""" +from fractions import Fraction as F +from functools import lru_cache +from math import comb, factorial, isqrt +import json + +BITS=240 +SCALE=1<b:raise ValueError('reversed interval') + return F(floor(a*SCALE),SCALE),F(ceil(b*SCALE),SCALE) + +def plus(a,b):return enclosure(a[0]+b[0],a[1]+b[1]) +def minus(a,b):return enclosure(a[0]-b[1],a[1]-b[0]) +def times(a,b): + p=[x*y for x in a for y in b];return enclosure(min(p),max(p)) +def over(a,b): + if b[0]<=0<=b[1]:raise ValueError('division by interval containing zero') + p=[x/y for x in a for y in b];return enclosure(min(p),max(p)) +def power(a,n): + if type(n) is not int:raise TypeError('integer power required') + if n<0:return over((F(1),F(1)),power(a,-n)) + out=(F(1),F(1)) + for _ in range(n):out=times(out,a) + return out + +def atan_inv(n,terms=100): + x=F(1,n) + s=sum(((-1)**j*x**(2*j+1)/(2*j+1) for j in range(terms)),F(0)) + tail=x**(2*terms+1)/(2*terms+1) + return enclosure(s-tail,s+tail) + +@lru_cache(None, typed=True) +def pi_bounds():return minus(times((F(16),F(16)),atan_inv(5)),times((F(4),F(4)),atan_inv(239))) + +def _log_small(t,terms=100): + u=(t-1)/(t+1) + if not 1<=t<=2:raise ValueError('reduced logarithm range') + s=2*sum((u**(2*j+1)/(2*j+1) for j in range(terms)),F(0)) + rem=2*u**(2*terms+1)/((2*terms+1)*(1-u*u)) + return enclosure(s,s+rem) + +@lru_cache(None, typed=True) +def log_bounds(t): + t=q(t) + if t<=0:raise ValueError('positive logarithm input') + e=0 + while t<1:t*=2;e-=1 + while t>=2:t/=2;e+=1 + return plus(_log_small(t),times((F(e),F(e)),_log_small(F(2)))) + +def log_iv(a):return log_bounds(a[0])[0],log_bounds(a[1])[1] + +def exp_bounds(t): + t=q(t) + if t<0:return over((F(1),F(1)),exp_bounds(-t)) + n=0 + while t>F(1,2):t/=2;n+=1 + # Positive Taylor series: bound all omitted terms by the first omitted + # term times a geometric series with ratio <= t/(K+2). + K=100 + s=sum((t**j/F(factorial(j)) for j in range(K+1)),F(0)) + tail=t**(K+1)/factorial(K+1)/(1-t/F(K+2)) + ans=enclosure(s,s+tail) + for _ in range(n):ans=times(ans,ans) + return ans + +def exp_iv(a):return exp_bounds(a[0])[0],exp_bounds(a[1])[1] + +def _int_nroot(n,k): + if k==2:return isqrt(n) + lo,hi=0,1<<((n.bit_length()+k-1)//k) + while hi-lo>1: + mid=(lo+hi)//2 + if mid**k<=n:lo=mid + else:hi=mid + return lo + +def root_bounds(t,n): + t=q(t) + if t<0 or type(n) is not int or n<1:raise ValueError('nonnegative input and positive integer root') + k=_int_nroot(floor(t*SCALE**n),n) + lo=F(k,SCALE) + return lo,lo if lo**n==t else F(k+1,SCALE) + +def root_iv(a,n):return root_bounds(a[0],n)[0],root_bounds(a[1],n)[1] + +@lru_cache(None, typed=True) +def bernoulli(n): + B=[F(1)] + for j in range(1,n+1):B.append(-sum((F(comb(j+1,k))*B[k] for k in range(j)),F(0))/F(j+1)) + return B[n] + +@lru_cache(None, typed=True) +def lngamma_bounds(x): + x=q(x) + if x<=0:raise ValueError('positive rational Gamma input') + N,K=40,20;y=x+N + ans=minus(times((y-F(1,2),y-F(1,2)),log_bounds(y)),(y,y)) + ans=plus(ans,times((F(1,2),F(1,2)),log_iv(times((F(2),F(2)),pi_bounds())))) + corr=sum((bernoulli(2*j)/(2*j*(2*j-1)*y**(2*j-1)) for j in range(1,K+1)),F(0)) + rem=abs(bernoulli(2*K+2))/((2*K+2)*(2*K+1)*y**(2*K+1)) + # For positive y, the real log-Gamma Stirling remainder is bounded by + # the first omitted term. See NIST DLMF 5.11(ii). Symmetric use is safe. + ans=plus(ans,enclosure(corr-rem,corr+rem)) + prod=F(1) + for j in range(N):prod*=x+j + return minus(ans,log_bounds(prod)) + +@lru_cache(None, typed=True) +def gamma_bounds(x):return exp_iv(lngamma_bounds(x)) + +@lru_cache(None, typed=True) +def coefficients(): + pi=pi_bounds();p32=times(pi,root_iv(pi,2));p52=times(pi,p32) + sixth=root_bounds(F(12),6) + lead=over(gamma_bounds(F(1,6)),sixth) + corr=times(gamma_bounds(F(5,6)),sixth) + s6=root_bounds(F(6),2) + c3=minus((F(29,72),F(29,72)),times((F(1,12),F(1,12)),s6)) + d3=times((F(5,48),F(5,48)),minus((F(33),F(33)),times((F(7),F(7)),s6))) + out={} + for d,lc,dc,pden in ((1,(F(1,6),)*2,(F(3,4),)*2,p32),(2,(F(1,9),)*2,(F(13,18),)*2,p32),(3,c3,d3,p52)): + c=over(times(lc,lead),pden);c2=over(times(dc,corr),pden) + out[f'{d}.c']=c;out[f'{d}.c2']=c2;out[f'{d}.ratio']=over(c2,c) + return out + +def decimal_pair(iv,places=40): + den=10**places + vals=[floor(iv[0]*den),ceil(iv[1]*den)] + return [('-' if z<0 else '')+str(abs(z)//den)+'.'+f'{abs(z)%den:0{places}d}' for z in vals] + +def results(): + out={} + for key,a in coefficients().items(): + ref=tuple(map(F,PUBLISHED[key])) + if not ref[0]