Skip to main content

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 the project directory:

uv tool install .

Run without installing:

uv run phil '2+2'

60-Second Start

uv tool install .
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:

  1. d(x^3 + 2*x, x)
  2. int(sin(x), x)
  3. solve(x^2 - 4, x)

Usage

One-shot

phil '<expression>'
phil --format pretty '<expression>'
phil --no-simplify '<expression>'
phil --latex '<expression>'
phil --latex-inline '<expression>'
phil --latex-block '<expression>'
phil --wa '<expression>'
phil --wa --copy-wa '<expression>'
phil :examples

Interactive

phil
phil> <expression>

REPL commands:

  • :h / :help show help
  • :examples show sample expressions
  • :v / :version show current version
  • :update / :check compare current vs latest version and print update command
  • :q / :quit / :x exit

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]]).

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 --wa to always print the link.
  • Use --copy-wa to copy the link to your clipboard when shown.
  • Full URLs are usually clickable directly in modern terminals.

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:

  • :version shows your installed version.
  • :update/:check show current version, latest known release, and update command.

For release notifications on GitHub, use "Watch" -> "Custom" -> "Releases only" on the repo page.

Long Expressions (easier input)

phil now uses relaxed parsing by default:

  • 2x works like 2*x
  • {} works like ()
  • ln(t) works like log(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}'

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

GitHub

  • CI: .github/workflows/ci.yml runs 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. 1/3 + 1/6
  2. d(x^3 + 2*x, x)
  3. int(sin(x), x)
  4. solve(x^2 - 4, x)
  5. 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 --strict to require 2*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
  • name = expr assigns in REPL session (ans is 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philcalc-0.1.0.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philcalc-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file philcalc-0.1.0.tar.gz.

File metadata

  • Download URL: philcalc-0.1.0.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for philcalc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 381fa2e0f0e8b12cdb88d716c7f493902576db2453c7d3465b8f79626c62b9ef
MD5 fa262aceb3bbff861e2e2aa0226de447
BLAKE2b-256 440052f6201c9959be58dc2e8c6de87fb1668edd3563850666976a0847b89f1a

See more details on using hashes here.

File details

Details for the file philcalc-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: philcalc-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for philcalc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dde56b8d841fbe109425013075b3e9579311c963bd9e197ba9edae63df4c41ed
MD5 0e05e499f256fcfe26ae63aa0193ce92
BLAKE2b-256 2870723336a0bd5116631179afa05d9c44ed0501e855e446a534ca35c671f2b6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page