High-precision terminal π explorer — Chudnovsky, Ramanujan, Machin, and BBP spigot algorithms.
FoxPi is a pure-Python command-line toolkit for computing, exploring, benchmarking, and validating π using several classical and modern algorithms.
It supports arbitrary-precision decimal computation with Chudnovsky, Ramanujan, and Machin, plus direct hexadecimal digit extraction using the Bailey–Borwein–Plouffe (BBP) formula.
The implementation uses integer-scaled arithmetic and includes an independent test suite that checks computed decimal and hexadecimal digits against reference values rather than merely comparing algorithms against themselves.
- 🧮 Arbitrary-precision decimal computation of π
- ⚡ Chudnovsky computation with binary splitting
- 📜 Ramanujan's rapidly convergent hypergeometric series
- 📐 Classical Machin formula
- 🔢 BBP hexadecimal digit extraction
- 🔬 Term-by-term convergence exploration
- 📊 Built-in algorithm benchmarking
- 🧱 Integer-scaled arithmetic for high-precision calculations
- 🧪 Automated tests against independent reference digits
- 📦 Standard-library implementation with no runtime dependencies
- 🐍 Python package/CLI entry point via
pyproject.toml - 📄 MIT licensed
- Installation
- Quick Start
- CLI Reference
- Algorithms
- Precision and Implementation
- Testing
- Project Structure
- Development
- Performance
- Limitations
- Contributing
- License
FoxPi requires:
- Python 3.8 or newer
pipfor optional editable/package installation
The project declares no runtime third-party dependencies.
git clone https://github.com/foxhackerzdevs/foxpi.git
cd foxpiYou can run FoxPi directly from the repository:
python cli.py digits 100For example:
π (100 digits) using Chudnovsky:
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Time: 0.00xxs
FoxPi defines a foxpi console-script entry point in pyproject.toml.
If a published package is available:
python3 -m pip install foxpiThen run:
foxpi digits 100Clone the repository:
git clone https://github.com/foxhackerzdevs/foxpi.git
cd foxpiInstall it in editable mode:
python -m pip install -e .Then use:
foxpi digits 100The project metadata currently identifies the package as version 0.1.1.
Compute 100 digits of π:
python cli.py digits 100Use Chudnovsky explicitly:
python cli.py digits 1000 --method chudnovskyUse Ramanujan:
python cli.py digits 1000 --method ramanujanUse Machin:
python cli.py digits 1000 --method machinExplore convergence:
python cli.py explore --method chudnovsky --terms 15Benchmark the 1000-digit Chudnovsky and Machin implementations:
python cli.py compareExtract 16 hexadecimal digits beginning at hexadecimal position 100:
python cli.py bbp 100FoxPi exposes four commands:
foxpi
├── digits
├── explore
├── compare
└── bbp
The same commands can be run through python cli.py when working directly from the repository. The CLI requires a subcommand; invoking it without one displays the command-line usage information and exits with an error.
Compute a requested number of decimal digits of π.
python cli.py digits COUNT| Argument | Description |
|---|---|
COUNT |
Number of decimal digits requested |
--method |
chudnovsky, ramanujan, or machin |
The default method is Chudnovsky.
python cli.py digits 50python cli.py digits 1000 --method chudnovskypython cli.py digits 1000 --method ramanujanpython cli.py digits 1000 --method machinFoxPi also raises Python's integer-to-string digit limit when necessary so large requested precisions can be printed on Python versions that impose the default conversion limit.
Negative decimal digit counts are rejected:
Error: digit count must be >= 0
Explore the convergence of the Ramanujan or Chudnovsky series.
python cli.py explore--method ramanujan
--method chudnovsky
--terms NThe default method is Ramanujan and the default number of displayed terms is 30.
python cli.py explorepython cli.py explore --method ramanujan --terms 20python cli.py explore --method chudnovsky --terms 10The command displays intermediate π estimates and finishes with a convergence table containing the iteration, term information, and a π preview.
For visualization purposes, the Chudnovsky convergence generator recomputes binary-splitting results at each step rather than using the optimized one-shot computation. The implementation explicitly treats this as suitable for the small number of terms used by explore.
Benchmark the currently configured algorithm implementations.
python cli.py compareThe current benchmark compares:
- Chudnovsky
- Machin
Both are benchmarked at 1000 decimal digits.
Example:
Benchmarking algorithms...
Algorithm | Precision (Digits) | Time Elapsed (s)
------------------------------------------------------------
Chudnovsky | 1000 | ...
Machin | 1000 | ...
Note: Benchmark times depend on the Python version, processor, operating system, and system load. Treat the output as a local comparison rather than a universal performance ranking.
Extract hexadecimal digits of π using the Bailey–Borwein–Plouffe formula.
python cli.py bbp POSITIONPOSITION=1 refers to the first hexadecimal digit after the hexadecimal point.
python cli.py bbp 1python cli.py bbp 25python cli.py bbp 1000FoxPi returns 16 hexadecimal digits beginning at the requested position.
Example:
Extracting 16 hex digits of π starting at position 1:
243F6A8885A308D3
(BBP Spigot — hexadecimal)
Positions below 1 are rejected by the CLI.
FoxPi currently implements four π-related algorithms.
| Algorithm | Output | Primary purpose |
|---|---|---|
| Chudnovsky | Decimal | High-precision computation |
| Ramanujan | Decimal | Rapid convergence / exploration |
| Machin | Decimal | Classical formula / comparison |
| BBP | Hexadecimal | Direct digit extraction |
The Chudnovsky series is FoxPi's primary high-precision decimal computation method.
The implementation uses binary splitting to evaluate the series efficiently using large integers. It estimates approximately 14 decimal digits of π per iteration and calculates the number of required terms from the requested precision.
The implementation also uses additional guard precision internally before scaling the final result back to the requested number of digits.
- High-precision π computation
- Large decimal digit counts
- The default
digitsmethod
Example:
python cli.py digits 10000 --method chudnovskyFoxPi implements Ramanujan's 1914 hypergeometric series for 1/π:
1/π =
(2√2 / 9801)
×
Σ [
(4k)! × (1103 + 26390k)
/
((k!)⁴ × 396⁴ᵏ)
]
The implementation maintains the calculation using scaled integers and updates the hypergeometric numerator and denominator iteratively.
- Studying rapid series convergence
- Mathematical exploration
- High-precision decimal calculation
Example:
python cli.py digits 1000 --method ramanujanOr explore it interactively:
python cli.py explore --method ramanujan --terms 20FoxPi implements the classical Machin identity:
π = 4 × (4 arccot(5) − arccot(239))
The arccotangent series is evaluated using scaled integer arithmetic.
- A compact classical π formula
- Mathematical education
- Comparing an older approach with Chudnovsky
Example:
python cli.py digits 500 --method machinThe Bailey–Borwein–Plouffe formula provides a particularly useful property: hexadecimal digits of π can be extracted starting at a selected position without first calculating all preceding hexadecimal digits.
FoxPi's implementation uses Python's Decimal arithmetic with additional precision rather than native binary floating point. The implementation generates exactly 16 hexadecimal digits for each request.
Example:
python cli.py bbp 1Expected first 16 hexadecimal fractional digits:
243F6A8885A308D3
FoxPi intentionally avoids relying on a third-party arbitrary-precision mathematics package for its core calculations.
The decimal algorithms use scaled integers. Additional guard digits are calculated internally and removed from the final integer representation before output.
The project also provides its own integer square-root implementation based on Newton-Raphson iteration:
isqrt(n)It:
- Rejects negative inputs with
ValueError - Returns
0for zero - Computes the integer floor square root for positive integers
This helper is covered by the test suite.
FoxPi includes a test suite under tests/.
Run it with Python's standard unittest framework:
python -m unittest discover -s tests -vThe tests cover:
- Integer square roots
- Chudnovsky decimal computation
- Ramanujan decimal computation
- Chudnovsky convergence terms
- Machin decimal computation
- BBP hexadecimal extraction
- Generator termination
- Invalid square-root input
The π tests are deliberately checked against independently generated reference digits rather than simply comparing one FoxPi implementation against another. The repository's tests document reference values generated using mpmath at 250 decimal digits of working precision.
The Chudnovsky implementation is tested at:
1
10
50
100
194
decimal places/digits according to the test suite's precision convention. Ramanujan and Machin are also checked against the reference decimal sequence.
BBP output is independently checked at positions:
1
25
50
100
with 16 hexadecimal digits verified at each position.
The current repository contains:
foxpi/
├── core/
│ ├── algorithms.py
│ └── visualize.py
│
├── tests/
│ └── test_algorithms.py
│
├── .gitignore
├── LICENSE
├── README.md
├── cli.py
└── pyproject.toml
Defines the foxpi command-line interface and dispatches commands to the mathematical and visualization modules.
Contains the mathematical implementations:
get_ramanujan_pi_termsget_chudnovsky_pi_termscompute_chudnovsky_picompute_machin_pigenerate_bbp_spigotisqrt
Provides terminal rendering helpers for convergence and benchmark results.
Contains independent-reference verification tests for the mathematical implementations.
Defines the package metadata and exposes:
foxpi = cli:main
as the installed console command.
Create a development checkout:
git clone https://github.com/foxhackerzdevs/foxpi.git
cd foxpiRun the CLI directly:
python cli.py --helpRun tests:
python -m unittest discover -s tests -vInstall in editable mode:
python -m pip install -e .Then:
foxpi --helpPerformance depends heavily on requested precision.
For general high-precision decimal computation, Chudnovsky is the intended high-performance implementation. Its binary-splitting approach reduces the overhead of evaluating the series term-by-term.
The built-in benchmark provides a convenient way to compare Chudnovsky and Machin on the current machine:
python cli.py compareKeep in mind that:
- Larger precisions require substantially larger integers.
- Memory requirements increase with precision.
- Runtime depends on the Python implementation and CPU.
- Benchmark results are machine-specific.
exploreis intentionally optimized for visualization rather than maximum throughput.
FoxPi is primarily an educational, experimental, and mathematical exploration tool.
Arbitrary precision does not mean unlimited practical precision. Extremely large requests can consume considerable CPU time and memory.
The BBP command currently emits 16 hexadecimal digits per invocation rather than providing a configurable output length.
The compare command currently benchmarks Chudnovsky and Machin at a fixed 1000-digit precision. It is not a general benchmarking framework.
The Chudnovsky convergence generator intentionally recomputes binary-splitting results for each displayed step. This makes it appropriate for exploration but not for replacing the optimized computation routine.
Contributions, improvements, bug reports, and mathematical enhancements are welcome.
Potential areas for development include:
- Additional π algorithms
- More efficient incremental convergence calculations
- Configurable BBP output length
- Expanded benchmark configuration
- More comprehensive CLI tests
- Performance profiling
- Packaging and distribution improvements
- Additional reference-value tests
- Documentation improvements
- Fork the repository.
- Create a feature branch.
- Make your changes.
- Add or update tests where appropriate.
- Run the test suite.
- Open a pull request with a clear description of the change.
Before submitting a mathematical algorithm change, include independent reference validation whenever practical.
FoxPi is released under the MIT License.
Copyright © 2026 Fox Hackerz.
See LICENSE for the complete license text.
GitHub:
https://github.com/foxhackerzdevs/foxpi
Project homepage:
https://foxhackerzdevs.github.io/foxpi/
FoxPi brings several historically important π algorithms together in one small, dependency-free command-line project.
It is designed not only to calculate π, but also to make the underlying computational ideas easy to experiment with:
┌──────────────────────┐
│ FoxPi │
│ π Explorer 🦊 │
└──────────┬───────────┘
│
┌───────────────┼────────────────┐
│ │ │
▼ ▼ ▼
Decimal π Convergence Hexadecimal π
│ │ │
┌────┼────┐ ┌───┴────┐ │
│ │ │ │ │ ▼
▼ ▼ ▼ ▼ ▼ BBP
Chu Ram Mach Ramanujan Chud
dnov anu in
sky jan
Compute it. Explore it. Benchmark it. Verify it. 🦊