| name | calculator |
| description | Exact symbolic + numeric math with sympy/mpmath — derive formulas, evaluate constants, propagate errors, convert units. Use for ANY multi-step arithmetic or algebra instead of mental math. |
| version | 1.0.0 |
| author | Hermes / AIP |
| license | MIT |
| metadata | {"hermes":{"tags":["math","sympy","mpmath","units","derivation","rigor"],"category":"astronomy","related_skills":["cmd-plotting"]}} |
Calculator — sympy/mpmath for honest math
When to Use
EVERY time a task involves a formula, a derivation, a unit conversion, or any
arithmetic beyond a single trivial operation. The rule from your SOUL: never
hand-evaluate formulas — mental algebra and mental arithmetic both fabricate
precision. Derive symbolically, evaluate numerically, and quote exactly what
the code printed.
sympy (1.14) and mpmath are preinstalled in the analysis environment —
plain python3 imports them directly. astropy.units and
astropy.constants are there too. Never pip install any of these.
Core recipe
import sympy as sp
M, t = sp.symbols("M t", positive=True)
t_ms = 10 * (M) ** sp.Rational(-5, 2)
M_of_t = sp.solve(sp.Eq(t, t_ms), M)[0]
print(t_ms.subs(M, 1.1).evalf())
print(M_of_t.subs(t, 4.0).evalf())
Error propagation (do this instead of hand-waving uncertainties)
import sympy as sp
x, y, sx, sy = sp.symbols("x y sigma_x sigma_y", positive=True)
f = x * y**2
sigma_f = sp.sqrt((sp.diff(f, x) * sx) ** 2 + (sp.diff(f, y) * sy) ** 2)
print(sp.simplify(sigma_f / f))
print(sigma_f.subs({x: 3.2, y: 1.7, sx: 0.1, sy: 0.05}).evalf())
Units & constants — astropy, not memory
from astropy import units as u, constants as c
E = (c.G * u.Msun**2 / u.Rsun).to(u.erg)
v = (500 * u.km / u.s).to(u.pc / u.Myr)
print(E, v)
Never recall constants from memory when astropy.constants has them.
High precision / special functions — mpmath
import mpmath as mp
mp.mp.dps = 50
print(mp.quad(lambda x: mp.exp(-x**2), [0, mp.inf]))
Honesty contract
- The number you report MUST be a number your code printed in this session.
- If symbolic and numeric paths disagree, or a result surprises you, show both
and say so — do not silently pick the one that matches expectations.
- Keep the derivation script in the task's folder (e.g.
analysis/derive_age.py)
so the user can rerun it.