High-precision π explorer and mathematical visualization toolkit for the command line.
FoxPi is a Python-based CLI application for computing and exploring the digits of π using several famous algorithms. It provides fast high-precision computation, convergence visualization, benchmarking tools, and hexadecimal digit extraction via the Bailey–Borwein–Plouffe (BBP) formula.
-
- Compute Digits
- Explore Convergence
- Compare Algorithms
- BBP Hexadecimal Digits
-
Compute π to an arbitrary number of decimal digits.
-
Multiple computation algorithms:
- Chudnovsky Algorithm
- Ramanujan Series
- Machin Formula
-
Interactive convergence exploration.
-
Benchmark algorithm performance.
-
Extract hexadecimal digits directly using the BBP formula.
-
Pure Python implementation using integer arithmetic for high precision.
-
No third-party dependencies.
foxpi/
│
├── cli.py # Command-line interface
└── core/
├── algorithms.py # Mathematical algorithms
└── visualize.py # CLI visualization utilities
Clone the repository:
git clone <repository-url>
cd foxpiPython 3.9+ is recommended.
No external packages are required.
Run with a subcommand:
python cli.py digits 100python cli.py alone (with no subcommand) prints usage and exits with an error — a subcommand (digits, explore, compare, or bbp) is required.
or
python -m cliCompute π using one of the supported algorithms.
python cli.py digits 1000Specify the algorithm:
python cli.py digits 5000 --method chudnovskypython cli.py digits 1000 --method ramanujanpython cli.py digits 1000 --method machinWatch the approximation converge term by term.
python cli.py exploreChoose an algorithm:
python cli.py explore --method ramanujanpython cli.py explore --method chudnovskyLimit the number of displayed terms:
python cli.py explore --terms 20Benchmark the available implementations.
python cli.py compareCurrent benchmark compares:
- Chudnovsky
- Machin
Retrieve hexadecimal digits beginning at a specified position without computing previous digits.
python cli.py bbp 1Example:
python cli.py bbp 1000Outputs the next 16 hexadecimal digits beginning at that position.
- Modern state-of-the-art series for computing π.
- Approximately 14 decimal digits per term.
- Uses binary splitting for efficient large integer arithmetic.
- Suitable for very high precision.
- Classic 1914 hypergeometric series.
- Extremely rapid convergence.
- Integer-scaled implementation for numerical stability.
Uses
π = 4 × (4 arccot(5) − arccot(239))
Advantages:
- Simple
- Educational
- Useful for comparison against faster modern methods
Supports direct extraction of hexadecimal digits of π.
Unlike traditional algorithms, BBP allows accessing hexadecimal digits beginning at an arbitrary position without computing all preceding digits.
Compute 100 digits:
python cli.py digits 100Compute 5000 digits using Chudnovsky:
python cli.py digits 5000 --method chudnovskyVisualize convergence:
python cli.py explore --method chudnovsky --terms 15Benchmark:
python cli.py compareExtract hexadecimal digits:
python cli.py bbp 250Only Python standard library modules are used:
- argparse
- decimal
- pathlib
- sys
- time
- typing
No external dependencies are required.
There are currently no configuration files.
Precision and algorithm selection are controlled through command-line arguments.
Ensure the project directory structure matches the expected layout:
core/
algorithms.py
visualize.py
Very large digit counts require significant CPU time.
For best performance:
- Prefer the Chudnovsky algorithm.
- Use Ramanujan for convergence exploration.
- Use Machin primarily for educational purposes and comparisons.
Higher requested precision naturally requires more computation time and memory due to large integer arithmetic.
Contributions are welcome.
Possible improvements include:
- Additional π algorithms
- Parallel binary splitting
- Progress bars
- Graphical convergence plots
- Export benchmark results
- Automated testing
- Packaging for PyPI
No license information was provided in the source files.
Consider adding a LICENSE file (for example MIT, Apache-2.0, or GPL-3.0) before publishing the project.