Skip to content

Pycodemath 0.5.0 — checks the math in your code

Choose a tag to compare

@cybersora9 cybersora9 released this 31 Oct 00:36
· 25 commits to main since this release

Pycodemath now checks the math inside your code. Point it at a function and a formula: you get a proof, or the exact input that breaks it. No guessing, no random samples. 🎯

>>> from pycodemath import check_code
>>> r = check_code(src, "n*(n+1)/2")      # the classic off-by-one
>>> r.verdict, r.counterexample.call
('refuted', 'sum_to(n=1)')

✨ What's new

  • 🔍 Code ↔ formula — check_code proves a function equals its formula, or hands back the call that breaks it, really executed. --emit-test writes the pytest that pins it.
  • 🎯 Float accuracy, with proof — stability / improve: how many bits float64 loses, where, and a rewrite that is proved equal and measured better.
  • 💥 Overflow — ranges / maxsafe: int8…uint64, float16, bfloat16, float32, float64. The 2006 binary-search bug, caught and fixed with a proof.
  • 💰 Money — no lost cents: exact splits, rounding modes, VAT, loans, IRR.
  • 📐 Units, geometry, loops — dimension checks with witnesses, rotation conventions, predicates that never lie, loop counts and recurrences.
  • 🧹 pycodemath-lint — a linter that comes with witnesses (ruff-style exit codes), plus a pytest plugin and pre-commit hook.
  • 🧾 Certificates — every answer ends with a re-runnable certificate:; recheck reproduces it from the file alone.
  • 🔒 Strict parser — xy is one variable, unknown words get a "did you mean…", no more silent product of letters.
  • 🤖 MCP server — 8 tools for AI agents, execute=False by default for foreign code.

✅ By the numbers

  • 2914 tests, Python 3.11 → 3.14, mypy clean
  • verify benchmark: 105 / 105 mistakes caught, 0 false alarms
  • real model solutions: 0 false alarms on 122 correct ones
pip install pycodemath==0.5.0
python -m pycodemath "verify code sums.py:sum_to == n*(n+1)/2 --emit-test"

📦 PyPI: https://pypi.org/project/pycodemath/0.5.0/ · 📝 Full notes: CHANGELOG · 🇵🇱 README.pl