Performance and semantic audit

This guide records the audit of the optimizations that form the repository’s performance baseline, release 0.7.1. It lists the optimized paths, the semantic repair found during review, the proofs that each fast path returns exactly what the general path returns, and the evidence boundary of the performance claims. Later work, including the current branch, adds no new performance measurement, so this audit remains the reference for the optimized paths.

Scope

The audit covers commits 69084bc, 7904016, 23005ed and 4fd41ad, which followed release 0.7.0, plus the GDA coefficient helper and the interval regression repair made during the 0.7.1 release review. It treats observed behaviour, normative expectation, implementation choice and acceptance evidence as separate facts.

Issue matrix

RowClassObservedExpectedChangeAcceptance evidence
GDA coefficient kernelsimplementation gapGDA fast paths added small representations, remainder-only division and half-power comparisoncoefficient identities, cohorts, flags, traps and sticky status unchangeduse canonical GdaCoeff operations and keep the shared GDA finalizer93 package tests, 8 frontend tests, 64,986/64,986 official, 16,124/16,124 official0
IEEE decimal pathssemantic-risk optimizationexact and bounded division paths skip repeated generic workexact decimal results, rounding, quantum, flags and exceptional values match IEEE behaviourguard fast paths with finite-domain, factor, bound and finalization predicates; fall back otherwise94 package tests and 15,763/15,763 four-target IEEE cases
Binary IEEE pathssemantic-risk optimizationexact-top ordering, split round/sticky extraction and coefficient dispatch replace wider workcontextual value, rounding, flags, signed zero and interchange bits identicalkeep exact coefficient construction and route every result through contextual rounding68 package tests and 7,464,503/7,464,503 binary cases
Interval endpoint dispatchsemantic deviation, fixedoptimized pown reused endpoint directions across sign regions; negative intervals could give y‾>y‾\underline{y} > \overline{y} or lose one ulpevery returned interval is ordered and contains the exact imageselect endpoints from monotonicity and round each candidate outward; add negative-half-axis tests42 package tests, integer power 174/174, strict ITF1788 4,656/4,656
Release documentationdocumentation gap0.7.0 was still named as the current baselinecurrent references name the new baseline; history stays in the changelogupdate metadata and add this auditpython3 tools/doc_quality.py

Optimization proofs

Exact coefficient paths

For a coefficient a≥0a \ge 0 and a divisor d>0d > 0 the remainder is

r=a−⌊ad⌋d,0≤r<d.r = a - \left\lfloor \frac{a}{d} \right\rfloor d, \qquad 0 \le r < d .

A remainder-only kernel returns the same rr as a quotient-and-remainder kernel, so it preserves every observable remainder and every step of the Euclidean algorithm. The GDA half-power predicate compares aa with 5⋅10 digits⁡(a)−15 \cdot 10^{\,\operatorname{digits}(a) - 1} by its leading decimal digit and whether its tail is non-zero; it is exact, not a floating estimate.

The IEEE decimal exact-division path first divides out g=gcd⁡(cx,cy)g = \gcd(c_x, c_y). A quotient cx/cyc_x / c_y has a finite decimal expansion exactly when the reduced denominator cy/gc_y / g has no prime factor other than 2 and 5:

cxcy=cx/g2i5j=(cx/g)⋅2k−i5k−j10k,k=max⁡(i,j).\frac{c_x}{c_y} = \frac{c_x / g}{2^{i} 5^{j}} = \frac{(c_x / g) \cdot 2^{k-i} 5^{k-j}}{10^{k}}, \qquad k = \max(i, j).

The path is taken only then. It builds the exact coefficient and exponent and calls the existing finalizer; any unmet factor, bound or special-value precondition returns to the generic algorithm. The optimization changes the route to the exact value, not the IEEE rounding or flag rule.

Binary contextual paths

For a finite dyadic value c⋅2ec \cdot 2^{e}, binary_exact_top(c, e) is the exponent of the highest set bit, e+bitlen⁡(c)−1e + \operatorname{bitlen}(c) - 1. Comparing these tops is equivalent to comparing magnitudes before alignment, including coefficients with different trailing powers of two. When a far addend is discarded, the split keeps the first discarded bit (the round bit) and the OR of all later bits (the sticky bit). These are exactly the inputs of the rounding decision: for the truncated magnitude tt and the discarded fraction f∈[0,1)f \in [0, 1) of one ulp,

round bit=[f≥12],sticky bit=[f∉{0,12}],\text{round bit} = [f \ge \tfrac{1}{2}], \qquad \text{sticky bit} = [f \notin \{0, \tfrac{1}{2}\}],

and every IEEE rounding direction is a function of tt‘s last bit, the sign, and these two bits. The fast path therefore feeds the same rounding inputs while never materializing an enormous aligned coefficient.

Directed interval paths

An interval operation must keep the inclusion invariant f(X)⊆[y‾,y‾]f(X) \subseteq [\underline{y}, \overline{y}] and the storage invariant y‾≤y‾\underline{y} \le \overline{y}. For an exact endpoint candidate yy, RD⁡(y)\operatorname{RD}(y) is a valid lower certificate and RU⁡(y)\operatorname{RU}(y) a valid upper certificate. The pown branches use this monotonicity table for x↦xnx \mapsto x^{n}:

Domainn>0n > 0 oddn>0n > 0 evenn<0n < 0 oddn<0n < 0 even
negative half-axisincreasingdecreasingdecreasingincreasing
positive half-axisincreasingincreasingdecreasingdecreasing
interval containing zeroendpoint order00 up to the outward-rounded maximumpole: split or Entirepole: split or Entire

The implementation selects the mathematical endpoint first and then applies the direction its role requires. For an interval across zero with even n>0n > 0, both finite extremum candidates are rounded upward for the upper bound. quantize_interval then rounds once more outward. The proof is local to the declared operation and precision contract and makes no claim about the unsupported reverse operations.

Performance evidence

AreaMeasurementInterpretation
binary, decimal, GDA and interval kernelsjust bench all --target nativeall four Maremark suites produced valid artifacts
binary square policyjust bench auto-tune --target nativea target-specific policy artifact; raw observations can be non-monotonic and are not a universal threshold
IEEE and GDA fast pathsbenchmark package tests plus the conformance gatesa fast route is admissible only while the semantic oracle stays green
interval endpoint dispatchsrc/bench/ball_float and strict ITF1788lower cost is acceptable only with ordered, outward-rounded enclosures

Generated artifacts live under .tmp/bench/ and are not published as API data. Re-run the commands on the target hardware before promoting a crossover. The workload is evidence about the audited tree; it does not prove a speedup for every release, equivalence across targets, or a latency bound.

Acceptance matrix

CheckResult
sh tools/run_moon_clean_exec.sh test src/decimal_gda --target native --deny-warn --frozen --no-parallelize93/93 passed
sh tools/run_moon_clean_exec.sh test src/decimal --target native --deny-warn --frozen --no-parallelize94/94 passed
sh tools/run_moon_clean_exec.sh test src/bin_float --target native --deny-warn --frozen --no-parallelize68/68 passed
sh tools/run_moon_clean_exec.sh test src/ball_float --target native --deny-warn --frozen --no-parallelize42/42 passed
just gate binary 87,464,503/7,464,503 passed
just gate decimal 815,763/15,763 passed
just gate decimal_gda 864,986/64,986 and 16,124/16,124 passed
just gate interval 84,656/4,656 passed
python3 tools/doc_quality.pypassed

These counts describe the audited tree. The gates have grown since (the binary gate now runs the full IEEE operation matrix); verification lists the current claims.

Reviewer self-review

  • Contribution: pass. The audit records concrete optimization boundaries and a repaired semantic failure instead of an unexplained speedup.
  • Clarity: pass. Each proof separates representation, monotonicity, rounding direction and evidence.
  • Experimental strength: needs replication. The native artifacts are valid, but noisy auto-tune observations should be repeated before a threshold is promoted.
  • Completeness: pass for the declared pinned corpora; it does not cover every standard operation or every real input.
  • Soundness: pass for the covered branches after the negative-half-axis regression fix and the full IEEE 1788 gate.

Claim–evidence map

ClaimEvidenceStatus
fast coefficient routes preserve the declared numerical resultsexact-kernel identities, package tests, IEEE and GDA conformancesupported within the declared APIs and preconditions
interval pown keeps ordered outward enclosuresmonotonicity table, negative-half-axis regression, 4,656 strict ITF1788 casessupported for the declared forward interval operations
the optimized paths are performance-auditednative Maremark all and auto-tune artifactssupported as measurement evidence, not a universal speed claim
every target and operation has equivalent performanceno paired cross-target artifactnot claimed

Limits

The semantic claims are bounded by the pinned corpora, the public operations, target-specific precision rules and the explicit fallback contracts. The 0.6.1 elementary manifest remains the comparison baseline of the elementary performance gate, with 0.7.1 as its candidate. No public API, rounding rule, error signal or enclosure contract is changed merely to improve a benchmark.