Aryabhata
A Python implementation of Aryabhata’s digit‑pair square‑root algorithm — a classical Indian arithmetic method for extracting square roots using only integer operations.
This project provides:
- A mathematically exact square‑root engine
- A modern CLI
- Optional ASCII animation of the digit‑pair extraction
- 100% unit‑test and branch coverage
Features
- Exact integer arithmetic — no floating point drift
- Arbitrary precision via digit‑pair extension
- Decimal output with proper zero‑padding
- Debug mode exposing the invariant:
N = root² + remainder - Optional ASCII animation showing every digit trial
- Pytest test suite with full coverage
Installation
Install with pip:
pip install aryabhata
Local development:
git clone https://github.com/djstompzone/aryabhata
cd aryabhata
pip install -e .[dev]
Usage
Basic
python -m aryabhata 82
Or
aryabhata 82
Output:
9
With decimal precision
aryabhata 82 --digits 3
Output:
9.055
Debug mode
aryabhata 82 --digits 3 --debug
Output:
9.055
[scaled-root] 9055
[remainder] 6975
[identity] 8200000 = 9055^2 + 6975
ASCII animation
aryabhata 82 --digits 3 --animate
This plays a frame‑by‑frame digit‑pair square‑root extraction in your terminal.
Control speed with:
--fps 15
How the algorithm works
Aryabhata’s method operates by grouping digits into base‑100 pairs and extracting square‑root digits one at a time using this rule:
At each step:
Choose max x such that (20R + x)·x ≤ remainder
R := 10R + x
remainder := remainder − (20R + x)·x
Where R is the root built so far.
This is mathematically equivalent to long‑hand square‑root extraction but works entirely in integers.
Library API
from aryabhata.sqrt import sqrt_aryabhata
root, remainder = sqrt_aryabhata(82, digits=3)
Returns:
root = floor( sqrt(n) × 10^digits )
remainder = n × 10^(2·digits) − root²
Testing
Run all tests with coverage:
poetry run coverage run -m pytest
poetry run coverage report -m
All code paths are fully covered.
Why this exists
Most square‑root implementations hide the math behind floating point hardware.
This project exposes the actual arithmetic behind root extraction — the same logic used by scribes, calculators, and engineers long before digital computers existed.
It’s math you can watch happening.
License
MIT License
Metadata
Release files for aryabhata 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aryabhata-1.0.1.tar.gz | 7.1 kB | Without provenance | Details for aryabhata-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aryabhata-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for aryabhata-1.0.1-py3-none-any.whl |
Total release size: 16.1 kB
Release files / aryabhata-1.0.1.tar.gz
| Download URL | aryabhata-1.0.1.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bea0fab1f1378aea7bb223a5b0169af4f55a9bbc1ebf5888005be41cca58f043
|
|
BLAKE2b-256 checksum How to use checksums |
6acaa3e9b17f939a299306d232d749259e9e80763f98073211af91199d865ba7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.9 Linux/6.2.1-PRoot-Distro
|
Release files / aryabhata-1.0.1-py3-none-any.whl
| Download URL | aryabhata-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bb814c7d9b10afcb29401aa5217be4681e11c559b9c5fca90822004aefddb37c
|
|
BLAKE2b-256 checksum How to use checksums |
d904125e8aa8d3a76e0f26548a430ede6132a25441b42f20dd791678290866e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.2.1 CPython/3.13.9 Linux/6.2.1-PRoot-Distro
|
Security for aryabhata 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.