π Calculation Project

This project implements π calculation using three different mathematical algorithms and a unified CLI entry point. It is a simple test of the Pi coding agent used with Meta's Muse Glimmer model run locally on a DGX Spark in vLLM.

Components

  • pi_calc/nilkantha.py Nilakantha series implementation (pi_nilakantha)
  • pi_calc/machin.py Machin arctan formula implementation (pi_machin, arctan_series)
  • pi_calc/gauss_legendre.py Gauss-Legendre AGM algorithm implementation (pi_gauss_legendre)
  • pi.py CLI entry point that dispatches to methods based on user input
  • main.py Minimal placeholder script

Requirements

  • Python >= 3.12
  • uv for dependency management
  • pytest >= 7.0 is in the dev group

Install dev dependencies:

uv sync --group dev

Usage

Compute π to a given number of decimal places:

uv run pi.py <METHOD> <DIGITS>

Methods:

  • nilakantha / pi1
  • machin / pi2
  • gauss / gauss-legendre / legendre / pi3

Examples:

uv run pi.py machin 50
uv run pi.py nilakantha 10
uv run pi.py gauss-legendre 100

Output format is exactly .{digits}f, e.g. 3.1415926535.

Invalid inputs print an error to stderr and exit with code 1.

Running Tests

Tests are written with pytest and cover unit tests for each algorithm, CLI integration tests, and cross-method consistency checks as defined in test-plan.md.

Run all tests:

uv run pytest tests/

Or run a specific test file:

uv run pytest tests/test_nilkantha.py -q
uv run pytest tests/test_cli.py -q

The test suite includes:

  • Unit tests for pi_nilakantha, pi_machin/arctan_series, and pi_gauss_legendre
  • Integration/CLI tests for method alias resolution, argument parsing, error handling
  • Acceptance / accuracy tests against known π values and cross-algorithm consistency

See test-plan.md for the full test strategy and test cases.

S
Description
Demonstration of using the Pi Agent to write a cli tool that calculates pi using Open LLM models.
Readme
65 KiB
Languages
Python 100%