Download verify_disk_bound.py from PureOne/neoryae-aegis: direct link, hf CLI and curl.
- Browser
- Download file 5.14 kB
-
https://huggingface.co/datasets/PureOne/neoryae-aegis/resolve/main/verify_disk_bound.py
- Command line
-
hf download hf://datasets/PureOne/neoryae-aegis/verify_disk_bound.py
-
curl -L -o verify_disk_bound.py https://huggingface.co/datasets/PureOne/neoryae-aegis/resolve/main/verify_disk_bound.py
5.14 kB
| """Independent arithmetic-engine tests and high-precision scalar diagnostics. | |
| The lower-bound proof is analytic. Its strict numeric hypotheses are checked | |
| by certify_disk_bound.py with exact rational interval arithmetic. This file | |
| tests that engine's square-root enclosures directly against exact rational | |
| squares and evaluates the final formulas independently with Decimal at two | |
| precisions. Decimal evaluations are diagnostics, not the proof certificate. | |
| """ | |
| from decimal import Decimal as D, localcontext | |
| from fractions import Fraction | |
| from pathlib import Path | |
| import json | |
| import random | |
| from certify_disk_bound import I | |
| def engine_checks(): | |
| rng = random.Random(319843) | |
| count = 0 | |
| for digits in (20, 80, 120): | |
| for _ in range(100): | |
| q = Fraction(rng.randrange(0, 10**18), rng.randrange(1, 10**12)) | |
| enclosure = I(q).sqrt(digits) | |
| assert enclosure.lo**2 <= q <= enclosure.hi**2 | |
| assert enclosure.hi - enclosure.lo <= Fraction(1, 10**digits) | |
| count += 1 | |
| for q in (Fraction(0), Fraction(1), Fraction(4), Fraction(9, 4), | |
| Fraction(1, 10**100)): | |
| enclosure = I(q).sqrt(120) | |
| assert enclosure.lo**2 <= q <= enclosure.hi**2 | |
| count += 1 | |
| try: | |
| I(-1).sqrt() | |
| except AssertionError: | |
| pass | |
| else: | |
| raise AssertionError("negative radical was accepted") | |
| try: | |
| I(1) / I(-1, 1) | |
| except AssertionError: | |
| pass | |
| else: | |
| raise AssertionError("division through zero was accepted") | |
| return count | |
| def scalar_diagnostics(precision): | |
| with localcontext() as context: | |
| context.prec = precision | |
| r, t, delta = D('.00004057804'), D('.9661517984'), D('2.6864358e-6') | |
| a = 1 + r | |
| sqrt2 = D(2).sqrt() | |
| S, C = (2 - sqrt2).sqrt() / 2, (2 + sqrt2).sqrt() / 2 | |
| w = (a*a - t*t).sqrt() | |
| eta0 = (1 - t) / 2 | |
| omega = ((a**4 - t*t).sqrt() + w) / (a*a - 1) | |
| A, B = 2*(t*S - w*C), 2*(t*C + w*S) | |
| D_neighbor = sqrt2*(t + w) | |
| denominator = A*A + (eta0+B)**2 | |
| q0 = eta0*eta0*A*A / (4*a*denominator) | |
| derivative = A*A*eta0*(A*A+B*B+B*eta0)/(2*a*denominator**2) | |
| def q(value): | |
| return value*value*A*A/(4*a*(A*A+(value+B)**2)) | |
| def qp(value): | |
| return A*A*value*(A*A+B*B+B*value)/(2*a*(A*A+(value+B)**2)**2) | |
| maximum_flow = 2*eta0 | |
| reward = q(4*eta0/3)+q(2*eta0/3) | |
| reward_derivative = 4*qp(4*eta0/3)/3+2*qp(2*eta0/3)/3 | |
| values = { | |
| "packing_reward_contradiction_margin": reward-delta, | |
| "additive_monotonicity_slack": 1-omega*reward_derivative/2, | |
| "final_eta_positive_for_W_at_most_delta": eta0-omega*delta/2, | |
| "eta_positive_at_certified_initial_reward": eta0-omega*reward/2, | |
| "neighbor_branch_dominates_on_whole_eta_interval": | |
| 2*a*(A*A+B*B)-D_neighbor*(A*A+(sqrt2*maximum_flow+B)**2), | |
| "opposed_second_derivative_positive_on_whole_eta_interval": | |
| (A*A+B*B)**2-3*(A*A+B*B)*maximum_flow**2-2*B*maximum_flow**3, | |
| "opposed_localized_projection_slack": 1-t*S-w*C, | |
| "neighbor_localized_projection_slack": 1-t*C-w*S, | |
| "near_coefficient_dominates_far": omega-sqrt2/(1-1/(sqrt2*t)), | |
| } | |
| assert min(values.values()) > 0 | |
| return {"precision": precision, | |
| "positive_values": {key: str(value) for key, value in values.items()}, | |
| "certified_initial_packing_reward": str(reward)} | |
| def main(): | |
| root = Path(__file__).parent | |
| certificate = json.loads((root / 'DISK_BOUND_CERTIFICATE.json').read_text()) | |
| assert certificate['status'] == 'PASS' | |
| count = engine_checks() | |
| records = [scalar_diagnostics(80), scalar_diagnostics(120)] | |
| # Independently evaluate scalar values and compare with the certificate's | |
| # display strings. A tiny display tolerance is intentional: printed | |
| # decimals are rounded, while the certificate's interval signs are exact. | |
| with localcontext() as context: | |
| context.prec = 130 | |
| for record in records: | |
| for key, scalar in record['positive_values'].items(): | |
| lo, hi = map(D, certificate['positive_intervals'][key]) | |
| value = D(scalar) | |
| tolerance = max(D('1e-80'), abs(value)*D('1e-43')) | |
| assert lo-tolerance <= value <= hi+tolerance, key | |
| output = { | |
| "status": "PASS", | |
| "scope": "Arithmetic-engine validation and independent high-precision scalar diagnostics of the complete disk-bound certificate.", | |
| "summary": {"all_assertions_passed": True, "exact_sqrt_enclosure_cases": count, | |
| "decimal_precisions": [80, 120], | |
| "negative_radical_rejected": True, | |
| "division_through_zero_rejected": True, | |
| "all_final_scalar_margins_positive": True}, | |
| "diagnostics": records} | |
| (root / 'DISK_BOUND_VERIFICATION.json').write_text(json.dumps(output, indent=2)+'\n') | |
| print(json.dumps(output['summary'], indent=2)) | |
| if __name__ == '__main__': | |
| main() | |