Skip to main content

RR-PF

CI Dependency Graph

Exact rational numbers and rational intervals that enclose them, with a Fraction-based test oracle and a Lean 4 model of the interval arithmetic.

Formerly published as mne; renamed because that name is taken on PyPI. The main class is still called MNE for API stability.

Install

pip install rr-pf             # from PyPI
pip install .                 # from a clone
pip install ".[test]"         # from a clone, with pytest

Releases are published to PyPI by .github/workflows/ci.yml when a v* tag is pushed (trusted publishing, no API token). 3.1.0 was uploaded by hand before that workflow existed.

Usage

from fractions import Fraction
from rr_pf import MNE

MNE.parse("0.[3]") * 3          # 1
MNE.parse("0.1[6]")             # 1/6
MNE.parse("0.[142857]")         # 1/7
MNE.parse("-0.25")              # -1/4
MNE(Fraction(4, 9)).sqrt()      # 2/3
MNE.from_float(0.1)             # exact binary value of the float

MNE(0.1) is the decimal 1/10, by documented rule. MNE.from_float(0.1) is the binary value 3602879701896397/36028797018963968.

Division by an interval that contains 0 raises ZeroDivisionError.

Oracle

rr_pf.oracle provides an exact sparse matrix-vector product (ExactCSR, csr_matvec_exact) for use as a slow reference in other projects' tests. It rejects float entries on purpose, so that a binary/decimal ambiguity cannot pass silently.

Lean model

The formal side lives in lean/. It defines bounded numbers (val, bound) and interval operations over ℝ, and proves:

  • add_valid, mul_valid, sub_valid, div_valid: the bounds are sound;
  • add_exact, mul_exact, div_exact, add_mono_bound;
  • RInterval.toBN_add, toBN_sub: the Python-style add and sub correspond exactly;
  • RInterval.mul_hull_sound, div_hull_sound: the Python-style mul and div results lie inside the Lean enclosure;
  • RRPF.Sqrt.pySqrt_enclosure: Python's sqrt on an interval encloses √x for every x in it; RRPF.Literals.periodic_closed: the closed form of a repeating decimal; RRPF.Literals.den_dyadic_pow_two: from_float denominators are powers of two.

lean/RRPF/Cases.lean is generated by tools/export_cases.py and checks 89 Python outputs against the Lean spec. CI fails if the committed file differs from the generator's output.

No sorry. Each theorem depends only on propext, Classical.choice, and Quot.sound.

docs/CORRESPONDENCE.md states, for every claim, whether it is proven in Lean, only tested in Python, or out of scope, and in which direction it holds (equality or containment).

Tests

pip install ".[test]"
pytest -q

The suite has 44 tests. They cover the core arithmetic, the oracle, the Lean-case generator, and a randomized correspondence check between the Python code and the Lean formulas (fixed seed).

The oracle test suite includes a mutant that drops small terms. A float-vs-float comparison misses it for some sizes; the exact oracle catches it.

Lean build

cd lean
lake exe cache get   # fetch the Mathlib cache
lake build           # must end with "Build completed successfully"

Toolchain: leanprover/lean4:v4.14.0, Mathlib v4.14.0.

Continuous integration

.github/workflows/ci.yml runs pytest on Python and lake build on Lean, checks the axiom list of the key theorems, and checks that the generated Lean cases are up to date.

  • The publish job runs only on a v* tag, after the Python and Lean jobs pass. It builds the sdist and wheel and publishes them to PyPI via a trusted publisher (OIDC, GitHub environment release, which requires approval). No API token is stored in this repo.

To release: bump version in pyproject.toml and __version__ in src/rr_pf/__init__.py, merge to main, then tag the merge commit vX.Y.Z and push the tag. The tag must match the package version.

Languages

License

See LICENSE.

Metadata

Release files for rr-pf 3.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rr-pf 3.1.1
File Size Uploaded Provenance Actions
rr_pf-3.1.1.tar.gz 26.1 kB With provenance Details for rr_pf-3.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rr-pf 3.1.1
File Interpreter ABI Platform Actions
rr_pf-3.1.1-py3-none-any.whl Python 3 none any Details for rr_pf-3.1.1-py3-none-any.whl

Total release size: 43.7 kB

Release files / rr_pf-3.1.1.tar.gz

Download URL rr_pf-3.1.1.tar.gz
Size 26.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1e1eaf4ea0e21c80d65141bc75216eaadf687739af7dc4291a7611657fd4c3ab
BLAKE2b-256 checksum
How to use checksums
e6a86fa906dabfdd727a4ba9eb3cca8538d414fabdeab42cfaa6bab1279df5c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Release files / rr_pf-3.1.1-py3-none-any.whl

Download URL rr_pf-3.1.1-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4929696144906e157b0b6624010932bdfd4a280447277cdd4b8b863992267cca
BLAKE2b-256 checksum
How to use checksums
f29660d8cad09ab54f3d2a5942d1d9489e5a71c1897c1de1891ee8573f28c464
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

Security for rr-pf 3.1.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rr_pf-3.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 26, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

3.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page