Minimal symbolic CLI calculator powered by SymPy
Project description
phil
A minimal command-line calculator for exact arithmetic, symbolic differentiation, integration, algebraic equation solving, and ordinary differential equations.
Powered by SymPy.
Install
Requires uv.
Install from PyPI (no clone required):
uv tool install philcalc
Then run:
phil
Project links:
- PyPI: https://pypi.org/project/philcalc/
- Source: https://github.com/sacchen/phil
- Tutorial: TUTORIAL.md
Local Development Install
From a local clone:
uv tool install .
60-Second Start
uv tool install philcalc
phil --help
phil '1/3 + 1/6'
phil '(1 - 25e^5)e^{-5t} + (25e^5 - 1)t e^{-5t} + t e^{-5t} ln(t)'
phil
Then in REPL, try:
d(x^3 + 2*x, x)int(sin(x), x)solve(x^2 - 4, x)
Usage
One-shot
phil '<expression>'
phil --format pretty '<expression>'
phil --format json '<expression>'
phil --no-simplify '<expression>'
phil --explain-parse '<expression>'
phil --latex '<expression>'
phil --latex-inline '<expression>'
phil --latex-block '<expression>'
phil --wa '<expression>'
phil --wa --copy-wa '<expression>'
phil --color auto '<expression>'
phil --color always '<expression>'
phil --color never '<expression>'
phil --latex 'dy/dx = y'
phil 'dsolve(Eq(d(y(x), x), y(x)), y(x))'
phil :examples
phil :tutorial
phil :ode
Interactive
phil
phil> <expression>
REPL commands:
:h/:helpshow help:examplesshow sample expressions:tutorial/:tourshow guided first-run tour:odeshow ODE cheat sheet and templates:next/:repeat/:donecontrol interactive tutorial mode:v/:versionshow current version:update/:checkcompare current vs latest version and print update command:q/:quit/:xexit
The REPL starts with a short hint line and prints targeted hint: messages on common errors.
Unknown : commands return a short correction hint.
Evaluation errors also include: hint: try WolframAlpha: <url>.
Complex expressions also print a WolframAlpha equivalent hint after successful evaluation.
REPL sessions also keep ans (last result) and support assignment such as A = Matrix([[1,2],[3,4]]).
REPL also accepts inline CLI options, e.g. --latex d(x^2, x) or phil --latex "d(x^2, x)".
Help
phil --help
Wolfram helper
- By default, complex expressions print a WolframAlpha equivalent link.
- Links are printed as full URLs for terminal auto-linking (including iTerm2).
- Use
--wato always print the link. - Use
--copy-wato copy the link to your clipboard when shown. - Full URLs are usually clickable directly in modern terminals.
Color diagnostics
- Use
--color auto|always|neverto control ANSI color on diagnostic lines (E:andhint:). - Default is
--color auto(enabled only on TTY stderr, disabled for pipes/non-interactive output). NO_COLORdisables auto color.--color alwaysforces color even when output is not a TTY.
Interop Output
--format jsonprints a compact JSON object withinput,parsed, andresult.--format jsonkeeps diagnostics onstderr, sostdoutremains machine-readable.
Clear Input/Output Mode
- Use
--format prettyfor easier-to-scan rendered output. - Use
--explain-parseto printhint: parsed as: ...onstderrbefore evaluation. - Combine with relaxed parsing for shorthand visibility, e.g.
phil --explain-parse 'sinx'. stdoutstays result-only, so pipes/scripts remain predictable.
Updates
From published package (anywhere):
uv tool upgrade philcalc
From a local clone of this repo:
uv tool install --force --reinstall --refresh .
Quick check in CLI:
phil :version
phil :update
phil :check
In REPL:
:versionshows your installed version.:update/:checkshow current version, latest known release, and update command.
For release notifications on GitHub, use "Watch" -> "Custom" -> "Releases only" on the repo page.
Release
Tagged releases are published to PyPI automatically via GitHub Actions trusted publishing.
git pull
git tag -a v0.2.0 -m "Release v0.2.0"
git push origin v0.2.0
# or
scripts/release.sh 0.2.0
Then verify:
- GitHub Actions run: https://github.com/sacchen/phil/actions
- PyPI release page: https://pypi.org/project/philcalc/
Long Expressions (easier input)
phil now uses relaxed parsing by default:
2xworks like2*xsinxworks likesin(x)(with ahint:notice){}works like()ln(t)works likelog(t)
So inputs like these work directly:
phil '(1 - 25e^5)e^{-5t} + (25e^5 - 1)t e^{-5t} + t e^{-5t} ln(t)'
phil '(854/2197)e^{8t}+(1343/2197)e^{-5t}+((9/26)t^2 -(9/169)t)e^{8t}'
phil 'dy/dx = y'
Use strict parsing if needed:
phil --strict '2*x'
Examples
$ phil '1/3 + 1/6'
1/2
$ phil 'd(x^3 + 2*x, x)'
3*x**2 + 2
$ phil 'int(sin(x), x)'
-cos(x)
$ phil 'solve(x^2 - 4, x)'
[-2, 2]
$ phil 'N(pi, 30)'
3.14159265358979323846264338328
$ phil --latex 'd(x^2, x)'
2 x
$ phil --latex-inline 'd(x^2, x)'
$2 x$
$ phil --latex-block 'd(x^2, x)'
$$
2 x
$$
$ phil --format pretty 'Matrix([[1,2],[3,4]])'
[1 2]
[3 4]
Test
uv run --group dev pytest
# full local quality gate
scripts/checks.sh
GitHub
- CI:
.github/workflows/ci.ymlruns tests on pushes and PRs. - License: MIT (
LICENSE). - Ignore rules: Python/venv/cache (
.gitignore). - Contribution guide:
CONTRIBUTOR.md.
Learn by Doing
Try this sequence in REPL mode:
1/3 + 1/6d(x^3 + 2*x, x)int(sin(x), x)solve(x^2 - 4, x)N(pi, 20)
If you get stuck, run :examples or :h.
Reference
Operations
| Operation | Syntax |
|---|---|
| Derivative | d(expr, var) |
| Integral | int(expr, var) |
| Solve equation | solve(expr, var) |
| Solve ODE | dsolve(Eq(...), func) |
| Equation | Eq(lhs, rhs) |
| Numeric eval | N(expr, digits) |
| Matrix determinant | det(Matrix([[...]])) |
| Matrix inverse | inv(Matrix([[...]])) |
| Matrix rank | rank(Matrix([[...]])) |
| Matrix eigenvalues | eigvals(Matrix([[...]])) |
Symbols
x, y, z, t, pi, e, f
Functions
sin, cos, tan, exp, log, sqrt, abs
Matrix helpers
Matrix, eye, zeros, ones, det, inv, rank, eigvals
Syntax notes
^is exponentiation (x^2)!is factorial (5!)- relaxed mode (default) allows implicit multiplication (
2x); use--strictto require2*x d(expr)/int(expr)infer the variable when exactly one symbol is present- Leibniz shorthand is accepted:
d(sin(x))/dx,df(t)/dt - ODE shorthand is accepted:
dy/dx = y,y' = y,y'' + y = 0 - LaTeX-style ODE shorthand is accepted:
\frac{dy}{dx} = y,\frac{d^2y}{dx^2} + y = 0 - Common LaTeX wrappers and commands are normalized:
$...$,\(...\),\sin,\cos,\ln,\sqrt{...},\frac{a}{b} name = exprassigns in REPL session (ansis always last result)- Undefined symbols raise an error
Safety limits
- Expressions longer than 2000 chars are rejected.
- Inputs containing blocked tokens like
__,;, or newlines are rejected.
See DESIGN.md for implementation details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philcalc-0.1.8.tar.gz.
File metadata
- Download URL: philcalc-0.1.8.tar.gz
- Upload date:
- Size: 38.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9e29e0908c9dc445a5ed06f7be49cc7408e03991947d73087de6f5537c80ce6
|
|
| MD5 |
7ae5588b28b6cdfdea4e620c8511f1ae
|
|
| BLAKE2b-256 |
5cbba9ff198fb48bf3d23a3d565ea95bfd36d1f2870929c52fca72da7b3256ae
|
File details
Details for the file philcalc-0.1.8-py3-none-any.whl.
File metadata
- Download URL: philcalc-0.1.8-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71bb3f6c805c5cf668b7cfab5f56609f3ebc2f26764ccbe6eea5c50fd70fee4f
|
|
| MD5 |
30ec63706392647d3f7ca69aacfecd68
|
|
| BLAKE2b-256 |
aa5a2260dd564b6665deb1c0b4affc1345b5938dce47e1b90bbac868d9b3b5a2
|