Metadata-Version: 2.4
Name: figurate-numbers
Version: 0.2.0
Summary: Figurate and polygonal numbers in pure Python: generation, membership testing, and inverse lookup for the full k-gonal family.
Project-URL: Homepage, https://github.com/amaar-mc/figurate-numbers
Project-URL: Repository, https://github.com/amaar-mc/figurate-numbers
Project-URL: Issues, https://github.com/amaar-mc/figurate-numbers/issues
Project-URL: Changelog, https://github.com/amaar-mc/figurate-numbers/blob/main/CHANGELOG.md
Author: Amaar Chughtai
License: MIT License
        
        Copyright (c) 2026 Amaar Chughtai
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: combinatorics,figurate-numbers,mathematics,number-theory,oeis,pentagonal-numbers,polygonal-numbers,triangular-numbers
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Education
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: hypothesis>=6; extra == 'dev'
Requires-Dist: mypy>=1.8; extra == 'dev'
Requires-Dist: pytest>=7; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Requires-Dist: twine>=5; extra == 'dev'
Description-Content-Type: text/markdown

# figurate-numbers

<p align="center">
  <img src="assets/logo.png" alt="figurate-numbers logo" width="160">
</p>

Pure-Python library for polygonal and figurate numbers. Zero runtime dependencies.

Provides forward generation, membership testing, and inverse lookup for the full k-gonal family, plus pyramidal numbers, generalized centered polygonal numbers, star, pronic, and Catalan numbers.

## Install

```bash
pip install figurate-numbers
```

## Quick start

```python
from figurate_numbers import (
    triangular, pentagonal, hexagonal, polygonal,
    is_triangular, is_polygonal,
    inverse_triangular, inverse_polygonal,
    tetrahedral, square_pyramidal,
    is_tetrahedral, inverse_tetrahedral,
    centered_polygonal, is_centered_polygonal,
)

triangular(10)          # 55
pentagonal(7)           # 70
hexagonal(5)            # 45
polygonal(10, 3)        # 55  (same as triangular)

is_triangular(28)       # True
is_triangular(50)       # False
is_polygonal(70, 5)     # True  (pentagonal)

inverse_triangular(55)  # 10
inverse_polygonal(45, 6)  # 5

# Pyramidal numbers (3D figurate)
tetrahedral(5)          # 35
square_pyramidal(5)     # 55
is_tetrahedral(20)      # True
inverse_tetrahedral(20) # 4

# Generalized centered polygonal
centered_polygonal(3, 4)  # 19  (centered triangular)
centered_polygonal(6, 3)  # 19  (centered hexagonal, same as centered_hexagonal(3))
is_centered_polygonal(4, 25)  # True  (centered square)
```

## API

### Generators

| Function | Formula | OEIS |
|---|---|---|
| `triangular(n)` | n(n+1)/2 | A000217 |
| `square(n)` | n^2 | A000290 |
| `pentagonal(n)` | n(3n-1)/2 | A000326 |
| `hexagonal(n)` | n(2n-1) | A000384 |
| `heptagonal(n)` | n(5n-3)/2 | A000566 |
| `octagonal(n)` | n(3n-2) | A000567 |
| `polygonal(n, k)` | n((k-2)n-(k-4))/2 | |
| `pronic(n)` | n(n+1) | A002378 |
| `centered_hexagonal(n)` | 3n(n-1)+1 | A003215 |
| `star(n)` | 6n(n-1)+1 | A003154 |
| `catalan(n)` | C(2n,n)/(n+1) | A000108 |
| `tetrahedral(n)` | n(n+1)(n+2)/6 | A000292 |
| `square_pyramidal(n)` | n(n+1)(2n+1)/6 | A000330 |
| `centered_polygonal(sides, n)` | sides*n*(n-1)/2+1 | (sides=3: A005448, sides=4: A001844, sides=6: A003215) |

All generators require `n >= 1`. `polygonal` additionally requires `k >= 3`. `centered_polygonal` additionally requires `sides >= 3`.

### Membership

`is_triangular`, `is_square`, `is_pentagonal`, `is_hexagonal`, `is_heptagonal`, `is_octagonal` - test whether an integer belongs to the sequence.

`is_polygonal(m, k)` - general k-gonal membership test. Requires `k >= 3`.

`is_tetrahedral(m)`, `is_square_pyramidal(m)` - pyramidal membership tests (integer cube-root + exact verification).

`is_centered_polygonal(sides, m)` - centered s-gonal membership test. Requires `sides >= 3`.

All membership functions use integer arithmetic only (no floats in results).

### Inverse lookup

`inverse_triangular(m)` - returns `n` such that `triangular(n) == m`, or `None`.

`inverse_polygonal(m, k)` - returns `n` such that `polygonal(n, k) == m`, or `None`. Requires `k >= 3`.

`inverse_tetrahedral(m)` - returns `n` such that `tetrahedral(n) == m`, or `None`.

`inverse_square_pyramidal(m)` - returns `n` such that `square_pyramidal(n) == m`, or `None`.

## Development

```bash
uv venv .venv
uv pip install -e ".[dev]"
pytest
ruff check .
mypy src
```

## License

MIT
