# Review: structured fraction limbs for GMP 6.3.0 This proposed enhancement replaces repeated division through zero padding in `mpf_div_ui` with exact reciprocal-prefix growth using multiplication. It also recognizes when the remainder proves that the remaining quotient limbs terminate or repeat, and fills those limbs directly. Every requested limb is still produced. **Review target:** [gmp-6.3.0-structured-fraction-limbs.patch](patches/gmp-6.3.0-structured-fraction-limbs.patch), one consolidated patch against stock GMP 6.3.0. It contains the fraction-generation helper, fixed-remainder handling, regression tests and test registration in `Makefile.am`. Its reviewed source files are byte-identical to the historical component series used for the reference measurements and validation; see the [consolidation check](results/consolidated-patch-check.json). Release tarballs also need the [generated `Makefile.in` companion](../claude/gmp-patch/patches/tarball-only/tests-mpf-Makefile.in.patch) to register the test in their pre-generated build files. The runner handles this automatically. For review as two diffs, apply the [implementation patch](patches/0001-gmp-mpf-div-ui-fraction-generation.patch) and then the [regression tests](patches/0002-gmp-mpf-div-ui-regression-tests.patch). These produce the same files as the combined patch. The same release-tarball companion applies. ## Review order 1. Review [the combined patch](patches/gmp-6.3.0-structured-fraction-limbs.patch) and the arithmetic explanation below. 2. Inspect [the study and limitations](STUDY.md), [all stock-versus-proposed results](results/stock-comparison.txt), and [the independent code audit](REVIEW.md). The audit retains its historical component names; the provenance appendix maps them to the combined change. 3. Run the reproduction command on your machine. Judge the targeted improvements together with generic, below-threshold, full-dividend, exact-division and half-length controls. ## Why the enhancement is exact Let `B` be the limb base. A reciprocal prefix `U` satisfies `B^k = U*v + rho`. That prefix and its one-limb remainder determine the next block by multiplication and a bounded correction. The helper grows the reciprocal prefix in its output workspace, then incorporates the actual numerator remainder. If division of the existing input limbs leaves no remainder, the caller fills the fraction tail with zeros immediately. For a nonzero incoming remainder `0 < rem < v`, the helper's first seed satisfies `B = seed*v + rho`. Two cases admit a direct fill: * `rho == 0`: `rem*B = (rem*seed)*v`. Emit `rem*seed`, then zero limbs. * `rho == 1`: `rem*B = (rem*seed)*v + rem`. The remainder repeats, so every emitted limb is `rem*seed`. The product is less than `B` and fits one limb. It must be saved before the fill overwrites the seed's workspace location. Regression tests use remainders greater than one, both signs, aliased/separate outputs, and actual fraction lengths 23/24/25. Each result is checked against exact limb patterns and GMP's reference division checker. The API still materializes every output limb, and the work remains O(n) in the output length. The proposed fraction-generation path starts at 24 fraction limbs on supported no-nails builds. Threshold tuning and longer-period detection are outside this change. ## Run independently Prerequisites: **Python 3.10+**, a C compiler, `make`, `m4`, `patch`, `tar` with xz support, and `xz`. Downloading also needs `curl` or `wget`; source verification needs `sha256sum`, `shasum`, or `openssl`. The benchmark supports Linux/macOS builds with **64-bit GMP limbs, 64-bit `unsigned long`, no nails, and no LTO**. Unsupported limb configurations are rejected explicitly. No Python packages are required. From the bundle or repository root: ```sh python3 gmp_study/reproduce.py --output /tmp/gmp-fraction-run ``` Use a new output path each time, without whitespace. To use a local source archive and avoid downloading: ```sh python3 gmp_study/reproduce.py --output /tmp/gmp-fraction-run-offline \ --tarball /path/to/gmp-6.3.0.tar.xz --sanitizers ``` The GMP tarball and original contribution archive are checked against pinned SHA-256 values. `--sanitizers` requires a compiler supporting AddressSanitizer and UndefinedBehaviorSanitizer; it instruments the changed C implementations and harness. `--jobs`, `--rounds`, and `--seed` default to 4, 15, and 20261126. `CC`, `CFLAGS` and `GMP_CONFIGURE` may be set for a new build; the runner records them. The portable validation build additionally disables assembly and enables assertions. The runner preserves the historical component application order to reproduce the measured experiment. The [consolidation check](results/consolidated-patch-check.json) verifies that this produces the same final source as applying the combined review patch to stock GMP 6.3.0. The command creates fresh sources, builds all benchmark methods, runs exact checks and both complete GMP suites, then executes candidate run 1, the identical-code A/A control, and candidate run 2 sequentially. It produces: * `run.json`: completion/failure status, commands, timestamps, seeds and input/output hashes. * `gmp_study/results/summary.txt` and `summary.csv`: results from both candidate runs, including every control case. These retain the historical method labels mapped below. * `gmp_study/results/aa-summary.txt`: timing variation when every method label calls the same implementation. * Raw CSVs, stderr logs, build configuration, validation records and full build/test logs. Each timed case uses the same immutable input and output buffer for every method. Exact checks run before and after timing. Shuffled rounds and batches of at least 1 ms reduce order/timer effects. Input generation and validation are outside the timer. Run on an otherwise quiet machine; the runner does not set CPU affinity. The fixture mix measures conditional performance, not workload frequency. ## Evidence and acceptance boundary On the reference ARM64 host, the proposed enhancement is **5.34–39.10 times faster than stock GMP 6.3.0 on targeted short-dividend cases**. Generic short inputs are **1.25–6.89 times faster**. The largest observed slowdowns are **2.43% below the fraction-generation threshold** and **2.73% on full-length dividends**. These ranges cover individual cases in both final runs, not application-wide averages. On x86-64, targeted short inputs were **3.77–12.00 times faster** and generic short inputs were **1.29–7.55 times faster**. The largest observed slowdown was **2.04%** on a full-length dividend that ran faster in the other run. Both validation builds and the sanitizer check passed. [x86-64 comparison](results/x86-64-stock-comparison.txt) · [Raw data and logs](results/x86-64-evidence.tar.gz) Recorded validation: 54,264 exact comparisons; 178 passing tests and one platform-dependent skip in each full GMP build; clean sanitizer checks on the changed C and harness. See [the study](STUDY.md) for configuration, all control families and the identical-code A/A comparison. A successful reproduction establishes correctness and local measurements, not a guarantee of the same speedup elsewhere. The reproduction workflow was also run end to end from a separately extracted bundle. Both suites, sanitizer checks, and all three 6,570-row benchmark runs completed successfully. Its [validation record](results/reproduction-check.json) identifies the tested inputs and verifies every recorded artifact hash. That packaging check leaves the original reference measurements intact; the later consolidated review patch is covered by its separate source-equivalence record. The review question is whether the measured improvements and implementation complexity justify adopting this fraction-generation path. Rational summation and other APIs are separate changes. No application-wide speedup, novelty, universal-optimality or GMP project endorsement is claimed. ## Share the review package ```sh python3 gmp_study/export_review.py /tmp/gmp-fraction-review.tar.gz ``` The deterministic bundle contains the consolidated patch, historical component sources, proof, reproduction tools and final raw evidence. A SHA-256 manifest lists its files. Build trees, compiled binaries and temporary exploration are excluded. The destination must be new. Reference records retain their original machine paths; the fresh runner creates a separate set of paths and provenance for every reproduction. ## Appendix: reproduction labels and provenance This independent study from mikedotexe was developed with Claude and Codex. The reciprocal-prefix implementation originated in the supplied Claude archive; the fixed-state handling and comparative validation were developed during the subsequent collaborative study. The original archive is preserved for attribution and provenance. These stages are presented for review as one combined enhancement against stock GMP. The runner applies the historical series **0001 → release-tarball test registration → 0003**. Component 0001 introduces reciprocal-prefix growth; component 0003 adds the fixed-state branch and focused tests. The [combined patch](patches/gmp-6.3.0-structured-fraction-limbs.patch) includes their final C source changes and `Makefile.am` registration. Applying that patch plus the generated `Makefile.in` companion is the corresponding manual route for a release tarball. | Historical label | Meaning in the experiment | |---|---| | `stock` | Unmodified GMP 6.3.0; the public comparison baseline. | | `claude` | Intermediate reciprocal-prefix implementation from the supplied archive. | | `zero` | Exploratory terminating-state-only variant. | | `repeat` | Exploratory repeating-state-only variant. | | `fixed` | Final proposed enhancement: reciprocal-prefix growth plus the combined fixed-state fill. | | `split` | Exploratory variant with separate zero and repeated-value fills. | These labels and extra comparison columns remain in raw records so earlier work can be audited. In the A/A run, all six labels call the same intermediate function; its `stock` label does **not** execute stock GMP. Public performance claims compare `stock` with `fixed` in the two actual candidate runs, using the `stock_over_fixed` column.