Skip to content

Pycodemath 0.5.1

Choose a tag to compare

@cybersora9 cybersora9 released this 04 Nov 01:49
· 5 commits to main since this release
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.