Skip to content

Releases

Pycodemath 0.5.2

Choose a tag to compare

@cybersora9 cybersora9 released this 14 Nov 11:58
c404ee3

Listing in the official MCP Registry.

Added

  • pycodemath mcp starts the MCP server over stdio, so it runs straight from
    PyPI: uvx --with "mcp>=1.0,<2.0" pycodemath mcp. pycodemath-mcp and
    python -m pycodemath.cli.mcp_server still work.
  • server.json for the MCP Registry (io.github.cybersora9/pycodemath) and the
    ownership marker in README.md that the registry checks on PyPI.

Pycodemath 0.5.1

Choose a tag to compare

@cybersora9 cybersora9 released this 04 Nov 01:49
3258a51

Fixes from a hands-on test session against 0.5.0 (49 CLI calls), plus a
first-run intro and commands for finding your way around.

Added

  • sum p(k)*binomial(n,k) for k from a to n with p a polynomial in k: closed
    form via Stirling numbers of the second kind, Σ_k k^m C(n,k) = Σ_j S(m,j) n!/(n-j)! 2^(n-j) (e.g. sum k^3*binomial(n,k) for k from 0 to n =
    2**(n - 3)*n**2*(n + 3)). Proved by that identity; the result is also checked
    against the brute-force sum before it is returned (tests: n = 0..20).
  • Definite integrals of the Bose–Einstein / Fermi–Dirac family on (0, oo):
    ∫ x^(s-1)/(e^(cx) - 1) = Γ(s)ζ(s)/c^s (s > 1) and ∫ x^(s-1)/(e^(cx) + 1) = (1-2^(1-s))Γ(s)ζ(s)/c^s (s > 0), used where SymPy finds no closed form;
    convergence is proved and the value cross-checked against the independent
    quadrature as for every other definite integral (integrate x^3/(exp(x)-1) dx from 0 to oo = pi**4/15, VERIFIED, was a value without a closed form).
  • First run and way-finding. pycodemath intro (also python -m pycodemath intro and intro in the REPL): an 80-column header box with the
    logo (rasterized from assets/pycodemath-sygnet.svg by scripts/gen_logo.py:
    36 columns, stroke 12, transparent half blocks), the name, version, tagline
    "Checks the math in your code.", the number of commands and API functions
    (counted at run time), then one live demo (an off-by-one loop read as a
    formula, REFUTED with the executed call, fixed, VERIFIED; every number comes
    from check_code at run time) and a capability map of eight areas, each with
    a runnable command. Animated only on a TTY, under 6 s; --static,
    PYCODEMATH_NO_ANIM=1 or a pipe print the final frame (30 lines, 80
    columns). Truecolor, a 256-colour fallback mapped to the nearest palette
    entries, monochrome under NO_COLOR or off a TTY. Flags: --static,
    --no-logo, --once.
  • The intro plays by itself once per installed version: on the first run of
    pycodemath / python -m pycodemath with a TTY stdout after installing or
    upgrading, before the command's own output. Never off a TTY, never in the MCP
    server, never with PYCODEMATH_NO_INTRO=1. The shown version is kept in
    intro-shown in the user cache directory. pycodemath intro --once shows it
    only if this version's intro has not been shown yet, else prints nothing and
    exits 0.
  • pycodemath commands (every command by topic), pycodemath help <topic>
    (the REPL help, cut by topic: solve, calculus, verify, code, numbers, money,
    units, geometry, ode, stats, start), pycodemath examples <topic> (3-5
    runnable examples each; a test runs every one) and pycodemath tour (five
    short live demos; Enter = next, q = quit; sequential off a TTY).
  • MCP tool intro: the logo as plain text, the tagline and the capability map
    as text and data (no ANSI, no engine call). The existing tools are unchanged.
  • assets/intro.svg, recorded from the real command by
    scripts/record_intro_svg.py, in a new "First run" section of both READMEs.

Changed

  • money loan ... for N years is now a duration paid MONTHLY (N×12
    instalments): money loan 300000 PLN at 7.2% for 25 years gives 300
    instalments of 2158.77 PLN. 0.5.0 read years as N annual instalments
    (26208.67 PLN) — what nobody taking a mortgage means. Annual instalments are
    asked for explicitly: ... for 25 years yearly (also annual, annually);
    yearly with a duration in months is refused. The answer now names the
    schedule (300 monthly instalments: payment ...). Same on the CLI/REPL and
    MCP math_eval (whose description says so); the Python API
    (amortization_schedule, annuity_payment) was never ambiguous — it takes
    periods and periods_per_year — and is unchanged.
  • money interest keeps its meaning (the unit is the compounding period:
    for 10 years compounds yearly, for 12 months monthly) and the answer now
    says so (compounded yearly, 10 years).
  • dsolve without a closed form names the CLI command in its hint — solve it numerically instead (ode <expr> for y(t) from <t0> to <t1> at <y0>) — instead
    of the Python function solve_ode_num, as solve already names root.
    route stays "ode".
  • sum(...), Sum(...), summation(...), integrate(...), Integral(...) and
    integral(...) inside an expression (verify sum(k, (k,0,n)) == ..., evalf integrate(x, (x,0,1)) 60) are refused with a pointer to the sum ... for k from .. to .. / integrate ... dx from .. to .. commands instead of "write
    sum*(...) if a product is meant".
  • The interactive REPL greets with a 2-line banner (the text mark ∫>_,
    version, where to start). One-shot commands still print no banner off a TTY
    — pinned by a test.

Fixed

  • sum p(k)*binomial(n,k) answers in about 2 s instead of about 95 s for
    k^5: the proved rule now runs before SymPy, which used to grind until it
    gave up.
  • The time budget no longer fires into cleanup code. When a deadline passed
    while the thread was in a __del__, a gc callback or a weakref.finalize
    finalizer, Python printed Exception ignored in ..., cut the cleanup short
    and dropped the interrupt. The watchdog now waits for the cleanup to finish
    and interrupts 50 ms later. This was also a flaky CI failure.
  • solve and certify solve take an equation: solve x^2 = 4 for x and
    solve x^2-5*x+6 == 0 for x are solved as lhs - rhs. == used to compare
    the two sides as Python objects and printed "(no solutions)". An = anywhere
    else in an expression is now a ParseError that points to solve / verify.
  • Strict mode no longer guesses on 2ab when a and b are also variables of
    the same expression: verify (a+b)^2 == a^2 + 2ab + b^2 came back REFUTED
    (it read ab as one variable). It is now a ParseError asking for a*b or a
    rename. Names like speed, alpha or a lone ab still parse as before.

Pycodemath 0.5.0 — checks the math in your code

Choose a tag to compare

@cybersora9 cybersora9 released this 31 Oct 00:36

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

Pycodemath 0.4.0 — a verifier: VERIFIED, REFUTED or UNDECIDED

Choose a tag to compare

@cybersora9 cybersora9 released this 30 Sep 12:31

verify: VERIFIED, REFUTED with a counterexample, UNDECIDED

benchmarks with their denominators

pip install -U pycodemath · PyPI

Pycodemath now checks math, not just computes it: a verifier that answers
VERIFIED, REFUTED (with a counterexample you can re-check yourself) or
UNDECIDED — and never promotes "agrees numerically" to "proved".

Added

  • pycodemath.verify.check_equal(a, b) returns a Verdict
    (VERIFIED / REFUTED / UNDECIDED, the method used, a counterexample
    and a one-line reason). Symbolic proof first; then deterministic
    high-precision sampling that avoids singularities. A counterexample is
    re-checked at higher precision before it is reported, so rounding noise is
    never called a refutation. Domain traps are caught: sqrt(x^2) vs x
    is REFUTED at a negative point, not "simplified" into equality.
  • certify(...) — engine results checked by an independent route:
    integrals by differentiating back, roots by substitution plus a
    completeness check, derivatives by finite differences, limits by
    two-sided numeric sequences, ODE solutions by substitution, numeric
    integrals by a second, independent quadrature (certify_integrate,
    certify_diff, certify_solve, certify_limit, certify_dsolve,
    certify_nintegrate). Existing result types are unchanged.
  • check_steps(...) — checks a derivation step by step: per-step
    verdicts, the index of the first wrong step and a counterexample. Equation
    chains are compared as solution sets, with a warning when a step adds roots
    (squaring both sides) or loses them (dividing by an expression that can be
    zero).
  • REPL and MCP surface: verify <a> == <b>, verify steps ... and
    certify <command> in the REPL; a math_verify MCP tool next to
    math_eval, returning structuredContent with the same rules (failure is
    an error field, never an exception).
  • isolated(fn, *args, budget=...) — a hard time limit. The in-process
    time_budget cannot stop one long C call that holds the GIL
    (7**(10**7) under a 2 s budget ran 7.9–8.7 s). isolated runs the call
    in a warm worker process and kills it at budget + 0.5 s (same case: 2.5 s),
    raising the new IsolationError. Opt-in (~0.4 ms per call); the fast path
    of time_budget is unchanged.
  • Benchmarks, with their denominators (python -m pycodemath.bench.verify_bench, python -m pycodemath.bench.real_bench):
    • Synthetic: 210 generated derivations, half with an injected typical
      model error — 105/105 errors caught, 0 false positives. These are
      synthetic, and the verifier was fixed against misses found on this set.
    • Real model errors (PRM800K, MIT-licensed sample): the verifier can
      extract a checkable claim from 9.5% of steps; it pinpoints the labelled
      first wrong step in 24 of 378 flawed solutions (6.3%) and raised 0 false
      alarms on 122 correct ones. Low recall, zero false alarms: when it says
      a step is wrong, it shows why.
  • hypothesis joins the dev extra (property-based tests of the verifier).

Changed

  • A call to an unknown function is now a ParseError ("unknown
    function"), not a product of symbols. Previously zeta(2) parsed as
    2*zeta, which let verify zeta(2) == pi^2/6 "refute" a true identity.
  • A bare function name (sin, log, (sqrt)) and stray brackets (),
    x)) raise ParseError instead of a raw TypeError / IndexError.
  • Expr.to_source() round-trip contract is now stated and tested as
    mathematical equivalence: parse(e.to_source()) is always equivalent to
    e (or the parser refuses), never a different expression; structural
    == is not promised, because SymPy re-distributes constants on parse.

Fixed

  • Expr.evalf() and compiled evaluation no longer leak a bare TypeError;
    nested zoo becomes a DomainError.
  • time_budget: an interrupt could land after the guarded block had
    exited and escape as an internal _Deadline; a nested budget poisoned the
    outer one. Both fixed (Windows reproduced it most).
  • A huge literal such as 2^1e10 no longer hangs before the budget is armed.
  • certify_solve accepts real roots of a cubic in the casus irreducibilis
    (an imaginary part at 1-bit precision is treated as zero only when the
    real part has full precision); quartics take candidates from nroots
    instead of spending the whole budget on Ferrari's formula; decimal
    exponents (5^7.5 vs sqrt(5^15)) no longer yield a false REFUTED.
  • The MCP server imports on Python 3.11 again.
  • Python 3.13: the time-budget interrupt no longer escapes a with time_budget(...) block. CPython 3.13 (only — gh-139622, open) lets an
    asynchronous exception skip every handler of the frame it is raised in, so
    a block around code in the caller's own frame let the raw internal
    interrupt out and kept re-injecting into whatever ran next (measured: 14 of
    18 test runs on Linux 3.13, 5 of 6 on Windows 3.13, 0 on 3.12). On 3.13 the
    watchdog now holds back while the interrupted frame sits inside a handler
    and waits for a frame where nothing would be skipped; engine calls are
    interrupted as before. CI now runs 3.11–3.14.

Known limitations

  • check_equal("cosh(t1 - log(0))", ...) can raise a bare TypeError,
    and trigsimp a bare RecursionError; sqrt(2)^10^20 can still hang in
    the parser.
  • solve can miss periodic solutions; QuadratureResult.error_estimate
    can under-estimate.
  • isolated is not yet wired into the MCP server or the REPL.
  • time_budget on its own stays best-effort (see 0.3.0 below); isolated
    is the hard limit.

Pycodemath 0.3.0 — structured results, typed exceptions, MCP structuredContent

Choose a tag to compare

@cybersora9 cybersora9 released this 19 Aug 22:13

[0.3.0] - 2026-08-19

Every failure and every success now carries evidence an agent can branch on,
instead of a bare value or a string to pattern-match.

Added

  • Typed exception hierarchy under PycodemathError: ParseError,
    DomainError, DivergenceError, StagnationError, NonConvergenceError.
    A caller can catch the specific outcome instead of string-matching the
    English message; except PycodemathError still catches everything.
  • Structured solver results: root_find, root_find_nd, minimize and
    minimize_nd take a keyword-only full_result=True and return a
    SolveResult (value / iterations / residual / converged / status).
    integrate_num likewise returns a QuadratureResult (adds an
    error_estimate) and gained an adaptive tol that refines panels until the
    estimate fits inside it, instead of always running a fixed 100-panel grid.
    Default calls are unchanged, bit-identical to 0.2.0.
  • converged is now corroborated, not just "the tolerance test fired": a
    vanishing gradient at a saddle or a maximum, or |f| < tol reached because
    f decayed rather than because x is a root, no longer reports false
    convergence.
  • A symbolic refusal taxonomy: NoClosedFormError (the engine searched
    and found nothing) vs. UnsupportedFormError (no method for this shape at
    all) — so a caller knows whether to stop or re-ask numerically instead of
    parsing English.
  • A time budget for symbolic calls: pycodemath.time_budget(seconds) (a
    context manager) and a budget <s> trailing REPL/MCP option bound how long
    a symbolic call may run and raise TimeBudgetError instead of hanging a
    tool call forever with no result.
  • REPL/MCP grammar reaches solver knobs the Python API already had:
    trailing tol <t> / max_iter <k> options on min / min_nd /
    nintegrate, and budget <s> on the symbolic commands.
  • The MCP surface carries the structured results: math_eval returns
    structuredContent (text / solve / quadrature / error fields) that
    a client validates against the declared schema, not just prose text. A
    raising call now always returns rather than throwing past the tool
    boundary.
  • py.typed + packaging fixes: an external mypy now actually sees the
    package's types (previously silently fell back to Any), and every symbol
    a public function returns (e.g. SolveResult) is importable from the
    top-level package.

Fixed

  • Security: matrix literals (matrix/det/inv/eig/solve_system/
    M/V) parsed user text with bare sp.sympify(), so attribute access
    evaluated (().__class__.__bases__ reaches object). Routed through the
    same whitelist parser scalars already use.
  • Identifiers with a trailing digit (q1, x2, v0, R1 — a common
    physics/engineering subscript convention) crashed the parser with a leaked
    NameError instead of a clean ParseError.
  • Abs / sign / Min / Max did not differentiate on a plain
    (assumption-free) symbol — silently wrong output from diff, and a raw
    SymPy crash instead of a PycodemathError from anything that
    differentiates internally (min, solve_nd, the stiff-ODE Jacobian).
  • A non-finite tol (e.g. tol inf) certified an unmoved starting guess as
    converged; tolerances are now validated finite.
  • mcp dependency pinned to >=1.0,<2.0 — the unbounded constraint let a
    fresh install pick up mcp 2.0.0, which removed an API the MCP test
    helper and integration path both relied on.

Pycodemath 0.2.0 — first public release

Choose a tag to compare

@cybersora9 cybersora9 released this 22 Jul 10:44

Token-efficient exact math for AI agents — one short command in, one exact SymPy/NumPy result out. Built as a disciplined layer over SymPy + NumPy, with an MCP server so any agent (Claude Code included) can plug it in.

Highlights

  • Full ODE suite — symbolic dsolve; fixed-step RK4; adaptive Dormand–Prince 5(4); dense output (callable sol(t)); event detection with terminal events; stiff solvers (BDF2 + Newton) incl. variable-step BDF2; backward integration everywhere. Singularities/divergence raise a readable error — never NaN/garbage.
  • ODE codegen — standalone RK4 / DOPRI5 / dense-output integrators, bit-for-bit identical to the engine.
  • Second-order optimization — min / min_nd with method newton|bfgs + Armijo line search (converges on Rosenbrock where gradient descent stalls).
  • Symbolic extensions — limits (one-sided, at oo), Taylor/Laurent series, finite & symbolic summation (divergent sums refuse cleanly).
  • Hardened parser — whitelist-only function resolution; __import__/eval/open, string literals and attribute access rejected; bounded evaluation cost.

Quality

230 tests passing on Ubuntu + Windows (Python 3.11 / 3.12), mypy clean.

Install

pip install -e .           # core
pip install -e .[mcp]      # + MCP server for AI agents

See the README for the Claude Code skill guide and full command table.