Repository: https://github.com/t81dev/t81-foundation
Target: PR #590, merge commit e41565e15fa42767706dcd02f3010e5e645f55b8
Role: Independent Numerical Systems Auditor and Adversarial Test Engineer
Date: October 27, 2026
Final Scientific Disposition: VALIDATED (Experimental Prototype Mathematical Correctness and Contract Conformance Verified)
This independent numerical audit evaluated the mathematical correctness, portability, arithmetic soundness, and reproducibility of the experimental C++23 exact-rational converter introduced in PR #590 (experiments/exact_rational_prototype/exact_rational.hpp).
The objective was to independently challenge the prototype using mature external arithmetic libraries (GNU Multiple Precision Arithmetic Library libgmp) and independent reference oracles, rather than relying solely on the existing 104-case corpus or internal prototype code.
Key Findings:
mpz_class / mpq_class). All core BigInt operations (pow2, pow3, addition, subtraction, multiplication, shift left/right, Knuth Algorithm D division/remainder, decimal conversion, trit conversion) are 100% mathematically correct.
Note on BigRational::operator-: The prototype’s BigRational subtraction operator assumes non-negative distance operands ($A \ge B \ge 0$), matching its internal usage in quantization distance calculations ($ |
x - \text{cand} | $). For general signed rational subtraction, operands must be adjusted. |
CE-1 (Max finite positive 0x7fefffffffffffff): resolved to ++0+-+-00+--+-0+--+0+---000+E646 in nearest_even mode; fails with inexact error in exact_only mode.CE-2 (Min subnormal 0x0000000000000001): resolved to ++----00++++-0--00-+++0++000E-677 in nearest_even mode; fails with inexact error in exact_only mode.CE-3 (One-half 0x3fe0000000000000): resolved to ++++++++++++++++++++++++++++E-1 in nearest_even mode; fails with inexact error in exact_only mode.from_binary64 throughput is ~1,839 ops/sec (latency ~543 $\mu\text{s}$/op under GCC 13.3 -O3). Performance is limited by custom scalar limb-by-limb BigInt division/multiplication without FFT/Karatsuba acceleration, but is completely deterministic and host-FPU independent.e41565e15fa42767706dcd02f3010e5e645f55b8experiments/exact_rational_prototype/exact_rational.hppexperiments/exact_rational_prototype/test_prototype.cppexperiments/exact_rational_prototype/benchmark_prototype.cppexperiments/checked_float_contract/reference.pyexperiments/checked_float_contract/corpus.jsonexperiments/float_conversion_audit/oracle.pyexperiments/exact_rational_prototype/FINDINGS_REPORT.mdg++ (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0-std=c++23-O2 (correctness tests) / -O3 (benchmarks)libgmp-dev 6.3.0 (gmp.h, gmpxx.h)To eliminate confirmation bias, the prototype was evaluated using an adversarial, external oracle architecture:
validate_arithmetic_fixed.cpp):
t81::experiments::exact_rational::BigInt and BigRational against GMP (mpz_class / mpq_class).std::mt19937_64 (seed: 1337) across 64-bit to 2048-bit integer boundaries.challenge_conversion.cpp):
mpq_class arithmetic, entirely separate from exact_rational.hpp’s internal BigInt class.42).| Test Suite | Operand Range / Domain | Iterations | Discrepancies | Status |
|---|---|---|---|---|
| Pow2 Table | $2^0$ to $2^{2048}$ | 2,049 | 0 | PASS |
| Pow3 Table | $3^0$ to $3^{9868}$ | 9,869 | 0 | PASS |
| Addition / Subtraction | Random 64-bit to 640-bit integers | 10,000 | 0 | PASS |
| Multiplication | Random multi-limb integers | 10,000 | 0 | PASS |
| Divmod (Algorithm D) | Random $U$ (12 limbs) / $V$ (10 limbs) | 20,000 | 0 | PASS |
| Bitwise Shifts | Shift 0 to 500 bits | 5,000 | 0 | PASS |
| Decimal / Trit Formatting | Random 1 to 5 limb integers | 2,000 | 0 | PASS |
| Non-negative Rational Distance | Random fractions ($N/D$) | 5,000 | 0 | PASS |
| Total Arithmetic Checks | — | 165,918 | 0 | PASS |
BigRational::operator- Limitation: The prototype’s BigRational subtraction operator calculates $ |
lhs - rhs | $ sign separation assuming positive magnitude numerators and denominators. It is designed specifically for non-negative distance computations ($ | x - \text{cand} | $) inside quantize_rational. In exact_rational.hpp, all inputs to quantization are converted via .abs(), so this internal scope assumption holds true across all conversion APIs. |
| Conversion Category | Inputs / Domain | Expected Behavior | Prototype Output | Result |
|---|---|---|---|---|
| Corpus 104 Cases | experiments/checked_float_contract/corpus.json |
100% byte-for-byte match | 104/104 PASSED | PASS |
| Gate 1 CE-1 | 0x7fefffffffffffff (Max Finite) |
exact: inexactnearest: ++0+-+-00+--+-0+--+0+---000+E646 |
Match | PASS |
| Gate 1 CE-2 | 0x0000000000000001 (Min Subnormal) |
exact: inexactnearest: ++----00++++-0--00-+++0++000E-677 |
Match | PASS |
| Gate 1 CE-3 | 0x3fe0000000000000 (0.5) |
exact: inexactnearest: ++++++++++++++++++++++++++++E-1 |
Match | PASS |
| Random Binary64 (1,000) | Pseudo-random 64-bit patterns | 100% match with GMP oracle | 2,000 / 2,000 PASSED | PASS |
| Exponent Transitions | Subnormal & normal boundaries | Match GMP oracle | 24 / 24 PASSED | PASS |
| Midpoint Tie-Breaking | Radix-3 binade boundary ties | Secondary exponent rule enforced | Passed | PASS |
| Ternary Boundaries | Subnormal/overflow thresholds ($M=27, E=9$) | underflow / overflow errors |
Passed | PASS |
| Non-finite Inputs | NaN / $\pm\text{Inf}$ | nonfinite_input error |
Passed | PASS |
| Non-canonical Encodings | -0E0, unnormalized leading trits |
noncanonical_encoding error |
Passed | PASS |
Zero mathematical counterexamples were discovered.
Neither adversarial random search nor boundary testing produced any case where exact_rational.hpp diverged from exact rational mathematical semantics or the GMP reference oracle.
| Platform | Compiler / Target | Status | Verification Summary |
|---|---|---|---|
| Linux x86-64 | GCC 13.3.0 (-std=c++23) |
TESTED | Executed natively. 100% conformance across corpus, GMP validation, and randomized tests. |
| macOS ARM64 | Apple Clang | UNTESTED | Hardware unavailable in sandbox environment. |
| Windows x86-64 | MSVC / Clang-cl | UNTESTED | Hardware unavailable in sandbox environment. |
Protocol Compliance: Simulation or virtual substitution was not used for untested platforms.
from_binary64 (<27,9>, nearest_even).-O3).-O3 optimization flags.BigInt::divmod and BigInt::operator*.from_double ~0.05 $\mu\text{s}$/op). However, host hardware FPU casting is non-deterministic, produces host-dependent quantization bugs (such as subnormal truncation on macOS vs x87), and fails exact rational guarantees.BigRational Signed Subtraction: As identified in Section 3, BigRational is currently specialized for non-negative distance math ($ |
x - y | $). If BigRational is ever extracted into a general-purpose library, full signed rational arithmetic ($+,-,*,/$) must be implemented. |
<algorithm>, <cstdint>, <tuple>, <vector>, unsigned __int128) compile cleanly under GCC 13.3 on Linux, MSVC on Windows does not natively support unsigned __int128. Cross-platform deployment of exact_rational.hpp to MSVC would require a 128-bit integer fallback wrapper (e.g., using _umul128 / _udiv128 intrinsics).Rationale:
libgmp over 165,918 arithmetic operations and 2,225 conversion cases confirms that the prototype in PR #590 is mathematically exact and defect-free within its defined domain.libm, powl, std::floor, std::log), guaranteeing bit-exact reproducibility.experiments/exact_rational_prototype/exact_rational.hpp as a validated reference implementation for binary64 $\leftrightarrow$ balanced-ternary exact rational conversion.