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 .            # from a clone
pip install ".[test]"    # with pytest

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.

Languages

License

See LICENSE.

Metadata

Release files for rr-pf 3.1.0

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.0
File Size Uploaded Provenance Actions
rr_pf-3.1.0.tar.gz 25.5 kB Without provenance Details for rr_pf-3.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.8 kB

Release files / rr_pf-3.1.0.tar.gz

Download URL rr_pf-3.1.0.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
beaef272e3bf0b4a12738bbb807334c94140148337fed163bf00196ff5ee6266
BLAKE2b-256 checksum
How to use checksums
a38488155e1c94f7b8778f92a27265a5541e0d1c0073bc3001d115c94a1d115f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

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

Download URL rr_pf-3.1.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9f412931ba428332c2689e08c95bc5660f96d19512467b7ea7e62b4bff9c177
BLAKE2b-256 checksum
How to use checksums
e99b1deea93f3dc4545dff26f9188d51033d7b27b46b3a81eef18892d268c046
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for rr-pf 3.1.0

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.

Release history Release notifications | RSS feed

This release

3.1.0 This release

2 release files No 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