Skip to main content

High-precision terminal π explorer — Chudnovsky, Ramanujan, Machin, and BBP spigot algorithms.

Project description

🦊 FoxPi

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.


Table of Contents


Features

  • 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.


Project Structure

foxpi/
│
├── cli.py                # Command-line interface
└── core/
    ├── algorithms.py     # Mathematical algorithms
    └── visualize.py      # CLI visualization utilities

Installation

Clone the repository:

git clone <repository-url>
cd foxpi

Python 3.9+ is recommended.

No external packages are required.

Run with a subcommand:

python cli.py digits 100

python 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 cli

Usage

Compute Decimal Digits

Compute π using one of the supported algorithms.

python cli.py digits 1000

Specify the algorithm:

python cli.py digits 5000 --method chudnovsky
python cli.py digits 1000 --method ramanujan
python cli.py digits 1000 --method machin

Explore Convergence

Watch the approximation converge term by term.

python cli.py explore

Choose an algorithm:

python cli.py explore --method ramanujan
python cli.py explore --method chudnovsky

Limit the number of displayed terms:

python cli.py explore --terms 20

Compare Algorithms

Benchmark the available implementations.

python cli.py compare

Current benchmark compares:

  • Chudnovsky
  • Machin

Extract Hexadecimal Digits (BBP)

Retrieve hexadecimal digits beginning at a specified position without computing previous digits.

python cli.py bbp 1

Example:

python cli.py bbp 1000

Outputs the next 16 hexadecimal digits beginning at that position.


Algorithms Implemented

Chudnovsky Algorithm

  • 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.

Ramanujan Series

  • Classic 1914 hypergeometric series.
  • Extremely rapid convergence.
  • Integer-scaled implementation for numerical stability.

Machin Formula

Uses

π = 4 × (4 arccot(5) − arccot(239))

Advantages:

  • Simple
  • Educational
  • Useful for comparison against faster modern methods

Bailey–Borwein–Plouffe (BBP)

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.


Examples

Compute 100 digits:

python cli.py digits 100

Compute 5000 digits using Chudnovsky:

python cli.py digits 5000 --method chudnovsky

Visualize convergence:

python cli.py explore --method chudnovsky --terms 15

Benchmark:

python cli.py compare

Extract hexadecimal digits:

python cli.py bbp 250

Dependencies

Only Python standard library modules are used:

  • argparse
  • decimal
  • pathlib
  • sys
  • time
  • typing

No external dependencies are required.


Configuration

There are currently no configuration files.

Precision and algorithm selection are controlled through command-line arguments.


Troubleshooting

Import errors

Ensure the project directory structure matches the expected layout:

core/
    algorithms.py
    visualize.py

Slow execution

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.

Unexpected precision

Higher requested precision naturally requires more computation time and memory due to large integer arithmetic.


Contributing

Contributions are welcome.

Possible improvements include:

  • Additional π algorithms
  • Parallel binary splitting
  • Progress bars
  • Graphical convergence plots
  • Export benchmark results
  • Automated testing
  • Packaging for PyPI

License

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

foxpi-0.1.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

foxpi-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file foxpi-0.1.0.tar.gz.

File metadata

  • Download URL: foxpi-0.1.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for foxpi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5da40822b3b04ca7ac0232ba1de185ef2d980dfa1b1f3569703ac0879c034301
MD5 67ce53f4d79fb479d1f3a91e5796c5ea
BLAKE2b-256 80398596f09db2a48d0e5097878b19e8ec55ec67ed781825dbfc0200bdbd8993

See more details on using hashes here.

File details

Details for the file foxpi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: foxpi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for foxpi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46336b70c66c1d99a4ed76bc18491acfbb5e381606bf8d9d9d889db24d7e0889
MD5 b414172068d10d265657d6ac08d6777a
BLAKE2b-256 aa516d66fe1a8f1fd24d1c045c411653de686f21e44da5791075eff5e80de06c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page