Home /Modules/pi-generator/PI-20000-DIGIT-FORMULA-AND-NUMERIC-TYPE-STUDY-2026-11-09.md

PI-20000-DIGIT-FORMULA-AND-NUMERIC-TYPE-STUDY-2026-11-09.md

lib/pi-generator/PI-20000-DIGIT-FORMULA-AND-NUMERIC-TYPE-STUDY-2026-11-09.md · 172 line(s) · markdown

SLeeLa / sleelactl — 20,000-Digit π Formula and Numeric-Type Study

Date: 2026-11-09 Status: Prototype study and review plan; SLeeLa timing values are drawn from the repository's existing measurements or clearly marked extrapolations. Target: An iterative 20,000-fractional-digit π calculation through the early sleelactl math-subject interface, framed by the review question stated below.

Descriptive overview

This document describes an early prototype of sleelactl, using its math subject as the proposed control and demonstration surface for a high-precision numerical workload. The question under investigation is: Can the SLeeLa math stack calculate, verify, and report 20,000 fractional digits of π consistently across the available integer, floating-point, and arbitrary-precision representations, while making the time and accuracy trade-offs visible? The existing sleelactl math subject demonstrates scalar mathematical operations; the existing Pi generator supplies the arbitrary-precision algorithms and native big-integer operations needed for this larger task. These are related but distinct layers: a scalar double math function cannot itself retain 20,000 decimal digits.

Important execution qualification: this is a design-and-results review based on checked-in generator documentation and previously recorded SLeeLa timings. No new 20,000-digit run was launched through sleelactl in this session. Accordingly, estimated times are not represented as new measurements, and the document specifies the run and verification needed to turn this prototype study into a measured result.

1. Review summary

QuestionCurrent answerEvidence / qualification
Can binary64 double hold 20,000 digits?NoIEEE-754 binary64 has about 15–17 significant decimal digits
Can float hold 20,000 digits?NoBinary32 has about 6–9 significant decimal digits
Can a fixed-width integer hold π to 20,000 digits?NoFixed-width types can hold limbs, carries, indices, and intermediate products, not the complete scaled value
Can SLeeLa's arbitrary-precision limb representation do it?Yes, in principle and in the existing Pi generatorBase-1e9 limb arrays; existing Chudnovsky implementation uses native big-integer operations
Best current high-precision algorithm in the repositoryChudnovsky with binary splittingNative bigmul, bigadd, bigsub, bigdiv, bigisqrt
Best documented 20k time estimateMachin: about 11 s; Chudnovsky: about 15 sBoth are historical extrapolations, not a fresh 20k measurement; see timing table
Recommended next measured runChudnovsky at 20,000 digits, then Machin and reference cross-checkCapture whole-process and phase timings separately

2. Formula families that can calculate π

The formulas below are not all equally efficient, nor are they all implemented in the current SLeeLa Pi generator. The table distinguishes existing implementations from viable follow-on algorithms.

Formula / methodCore identity or approachConvergence / complexity characteristicsHigh-precision suitabilitySLeeLa status
Chudnovsky(1/\pi = 12\sum_{k\ge0}(-1)^k(6k)!(13591409+545140134k)/((3k)!(k!)^3 640320^{3k+3/2}))About 14.18 decimal digits per term; binary splitting reduces series-combination cost; final square root and division are still important costsExcellent; recommendedImplemented in PiChudnovsky.sleela; native big-integer opcodes
Machin\(\pi=16\arctan(1/5)-4\arctan(1/239)\)Alternating arctangent series; current limb-array accumulation is O(n²)Good for tens of thousands of digits; less attractive at very large scalesImplemented in PiMachin.sleela
Rabinowitz–Wagon spigotEmits decimal digits using a bounded-integer state arrayO(n²) interpreted array sweepsCorrect but slow as digit count growsImplemented in PiGenerator.sleela
Gauss–Legendre / AGM (Brent–Salamin)Arithmetic-geometric mean iteration; quadratic convergencePrecision roughly doubles per iteration; needs high-precision multiplication, division, and square rootExcellent alternative for cross-checking and high precisionNot identified as a current Pi generator implementation
Borwein quadratic / quartic algorithmsIterative algebraic transformations with quadratic or quartic convergenceVery few iterations, but each iteration requires high-precision roots and productsExcellent when arbitrary-precision roots and products are robustCandidate future implementation
Ramanujan seriesRapid hypergeometric series for (1/\pi)Roughly 8 decimal digits per term; binary splitting can accelerate itVery good independent series cross-checkNot identified as current generator implementation
Ramanujan–Sato seriesRelated rapidly convergent series with modular-form constantsCan exceed the classic Ramanujan rate, depending on seriesExcellent, but more complex constants and proof/implementation burdenResearch candidate
BBP formulaExtracts hexadecimal/binary digits of π at selected positionsUseful for digit-position checks; not the most direct route to 20,000 consecutive decimal digitsUseful independent spot-check, not primary decimal generatorNot identified as implemented
Leibniz series\(\pi/4=1-1/3+1/5-1/7+\cdots\)O(n) terms for only slow error reduction; impractical for 20k digitsUnsuitableReference-only teaching formula
Wallis productInfinite product for π/2Very slow convergenceUnsuitableReference-only teaching formula
Euler / Nilakantha seriesAlternating or rapidly decreasing elementary seriesBetter than Leibniz in practice, still far slower than Chudnovsky/AGM for 20k digitsUseful small-scale independent check, not 20k productionReference-only / possible test
Monte CarloEstimate π from random points in a geometric regionStatistical error falls only as (1/\sqrt{N})Fundamentally unsuitable for deterministic 20k-digit outputExcluded from precision result

Recommended primary algorithm: Chudnovsky binary splitting. Recommended independent algorithm: Machin for a second implementation already present in the repository; add Gauss–Legendre or Ramanujan as a future third independent method. A method is not independent merely because it has a different class name: its arithmetic path and implementation should differ enough to catch shared defects.

3. Numeric representation matrix

A 20,000-digit result must be stored as an arbitrary-precision integer or a decimal digit stream. Fixed-width types remain important for limb arithmetic and bookkeeping, but none of them can represent the full result alone.

Numeric type / representationTypical precision or rangeRole in a 20,000-digit π calculationCan it hold all 20,000 digits?Review
int8 / signed 8-bit−128…127Small flags, tiny counters onlyNoNot suitable for limbs
uint8 / unsigned 8-bit0…255Byte output buffers and digit bytesNoUseful for serialization
int16 / signed 16-bit−32,768…32,767Small indices or bounded constantsNoNot suitable for base-1e9 limbs
uint16 / unsigned 16-bit0…65,535Compact digit/metadata storageNoNot suitable for base-1e9 limbs
int32 / intUsually signed 32-bit in C-like ABIs; language-specificBase-1e9 limb storage is valid because each limb is 0…999,999,999; loop counters and small divisorsNoCurrent SLeeLa generator's principal limb type
uint320…4,294,967,295Native kernel limb representation and carry arithmeticNoNative base-1e9 kernel representation
int64 / longUsually signed 64-bit; ABI/language-dependentProducts of two base-1e9 limbs (up to about 10^18), carries, intermediate arithmetic, offsetsNoStrong candidate for native multiplication intermediates
uint64 / unsigned long long0…2^64−1Native limb products and unsigned carry pathsNoCheck overflow bounds and portability explicitly
int128 / __int128128-bit integer where supportedWider products, exact intermediate arithmetic, optimized division helpersNoOptional acceleration; not universally portable
float / binary32About 6–9 significant decimal digitsApproximate seeds, plotting, coarse diagnosticsNoNever use for digit production
double / binary64About 15–17 significant decimal digitsScalar math subject, timing, approximate seed, low-precision sanity checkNoCannot certify or store a 20k-digit result
long doublePlatform-dependent; commonly 64, 80, or 128-bit formatHigher-precision approximate seed/reference on some platformsNoABI and platform differences prevent treating it as a portable 20k-digit type
Fixed-point decimal / scaled integerPrecision chosen by scale and storage widthExact decimal scaling when backed by a large integerOnly if arbitrary-width backing is usedViable as a formatting/representation layer
Decimal floating pointPrecision depends on implementation/contextDecimal reference calculations and independent validationOnly if the implementation supports ≥20,000 digitsGood reference path; not a fixed-width primitive
Base-1e9 arbitrary-precision limb array9 decimal digits per limbStores the scaled integer, partial sums, products, quotient, remainder, and square-root resultYesCurrent SLeeLa Pi architecture
Decimal digit string / streamed fileOne character per decimal digitFinal output, hashing, and external comparisonYes, as textOutput representation only; not arithmetic storage

Limb arithmetic safety notes

4. Existing SLeeLa performance baseline and 20,000-digit review estimate

The figures below are drawn from the repository's Pi generator documentation, especially pi-generator/README.md and pi-generator/NATIVE.ADD.md. They are not new runs performed for this report.

Generator / revisionDigitsWall timeEvidence classNotes
Spigot v2.01,000~2 sRecorded measurementReference match documented
Spigot v2.02,000~4 sRecorded measurementO(n²)
Spigot v2.04,000~9 sRecorded measurementO(n²)
Spigot v2.010,000~48–51 sRecorded measurement across notesO(n²); 51 s appears in the generator comparison
Spigot v2.020,000~192–200 sExtrapolationApproximately 3.2–3.3 minutes
Machin v2.01,000<1 sRecorded measurementNative small-divisor big-integer kernel
Machin v2.010,000~3 sRecorded measurementO(n²) overall
Machin v2.020,000~11 sExtrapolationExisting README estimate; about 18× faster than spigot estimate
Chudnovsky v3.0 before fast-isqrt seed10,000~9 sEarlier recorded measurementBefore R1 improvement
Chudnovsky v3.0 after R1 fast-isqrt seed10,000~4 sRecorded measurementDigit-for-digit reference check documented
Chudnovsky v3.0 after R1 fast-isqrt seed20,000~15 sExtrapolation for this reviewInterpolated from 10k ≈4 s and 50k ≈87 s; not a measured 20k run
Chudnovsky v3.0 after R1 fast-isqrt seed50,000~87 sRecorded measurementDigit-for-digit reference check documented

How the 20k Chudnovsky estimate was obtained

The measured 10k-to-50k ratio is approximately (87/4=21.75) for a 5× increase in digits. A simple power-law fit gives an effective exponent near 1.92 over that interval. Applying that local fit to 10k→20k gives approximately:

[ t(20{,}000)\approx4\cdot2^{1.92}\approx15\text{ seconds} ]

This is a planning estimate only. It inherits the machine, build, GC, and measurement conditions of the earlier runs and must be replaced by a timed 20k execution. The existing 50k report attributes most of the runtime to the final bigisqrt and schoolbook big division; the binary-splitting recursion itself is already a small fraction of the run.

5. Accuracy and verification plan

A 20,000-digit run should be treated as verified only after all of the following checks pass:

CheckProcedureAcceptance criterion
Output shapeCount digits after the decimal point; validate the leading integer and decimal pointExactly 20,000 fractional digits, one leading 3., no embedded whitespace
Known prefixCompare the first 100 digits with a trusted π referenceExact match
Interior landmarksCheck well-known interior positions, including the Feynman point at fractional positions 762–767Exact match
Full independent referenceCompare all 20,000 digits against an independently generated high-precision referenceByte-for-byte match
Second SLeeLa algorithmRun Machin at 20,000 digits and compare with ChudnovskyExact match
ChecksumSHA-256 the fractional digit streamRecord checksum and byte count
Guard precisionRe-run with a larger guard-digit countThe first 20,000 fractional digits remain identical
RepeatabilityRun the same build and configuration at least twiceSame output hash; timing variance recorded
Numeric edge behaviorExercise carry propagation, borrow propagation, signed intermediate values, division remainder, and square-root floor behaviorAll invariants hold; no overflow or silent truncation
TimingCapture total wall time and per-phase monotonic timingsRecord build, CPU, OS, run count, median, and range

For the reference, the repository already documents independent Python decimal/Chudnovsky comparisons and a 100-million-digit reference file. The strongest comparison for this test is a fresh independent high-precision reference plus the existing checked-in reference prefix; do not rely only on two generators that share the same big-integer kernel.

6. Proposed 20,000-digit execution matrix

RunGeneratorArithmetic pathRequested fractional digitsExpected time (planning only)Purpose
1PiChudnovskyBinary splitting + native big integer20,000~15 s estimatedPrimary result
2PiMachinAlternating arctangent + native small-divisor operations20,000~11 s estimatedIndependent formula cross-check
3PiGeneratorRabinowitz–Wagon spigot20,000~192–200 s estimatedAlgorithmic baseline only; optional if runtime budget is tight
4PiChudnovskySame algorithm, increased guard digits20,000To be measuredGuard-digit stability
5External high-precision referenceIndependent decimal/Chudnovsky implementation20,000Environment-dependentFull output validation

The expected times in this matrix are inherited estimates or extrapolations from existing repository notes. They are not execution results for this 20,000-digit test.

7. Relationship to sleelactl and the scalar math subject

The current math-subject demo and numerical assertion suite exercise scalar operations such as sqrt, pow, exp, log, sin, cos, hypot, and rounding. Those are important for ordinary numerical programs, but a binary64 scalar cannot preserve 20,000 digits. The Pi generator therefore tests a different capability: arbitrary-precision integer arithmetic, signed intermediate values, multiplication algorithms, division, integer square root, memory management, and streamed output.

The proposed early-prototype integration is to make sleelactl expose a coherent high-precision math task (for example, sleelactl run pi --digits 20000 --algorithm chudnovsky) while preserving the existing sleelactl info math and sleelactl run math scalar-subject paths. This is a proposed interface, not a claim that these exact Pi CLI flags already exist.

The result should report at minimum:

8. Source references


Review disposition

Recommended: approve Chudnovsky as the primary 20,000-digit candidate, retain Machin as an independent formula check, and use base-1e9 limb arrays for the actual precision. Treat float, double, long double, and fixed-width integers as helper representations only, never as the 20,000-digit result store.

Not yet claimed: a new SLeeLa 20,000-digit execution, a measured 20k runtime, or a successful sleelactl Pi command. The next implementation/benchmark step is to run the matrix above on the source-built runtime and replace the estimates with measured timings and a full 20,000-digit comparison.