A modern RPN/RPL scientific graphing calculator with Computer Algebra System (CAS)
Growing up, I was always fascinated by HP calculators—the HP-48, HP-50g, and their predecessors. There's something deeply satisfying about Reverse Polish Notation: no parentheses, no ambiguity, just pure stack-based computation. The way you build up complex calculations by composing simple operations feels natural once you internalize it.
This project is my attempt to capture that spirit in a modern, extensible command-line tool. It's written in Rust for performance and safety, integrates Symbolica for symbolic math, and aims to be a practical tool for engineers, scientists, and calculator enthusiasts alike.
560+ built-in operators covering:
- Arithmetic & Algebra — Basic ops ( +, -,
*,/,^), roots (sqrt,cbrt,root), powers, logarithms (ln,log,log2,log10) - Programming and Fun Operators —
++,--,<<,>>,**(power),***(tetration),****(pentation—just for fun 🚀) - Trigonometry — Full set:
sin,cos,tan,sec,csc,cot+ inverses + hyperbolics - Complex Numbers — Native support (
3+4i),polar/rectconversion,re,im,arg,conj - Symbolic Math (CAS) — Powered by Symbolica:
deriv,integrate,simplify,expand,factor,collect,subst,solve,solveall - Numerical Calculus — Integration (
ninteg,simpson,romberg,gauss,boole), derivatives (nderiveval),limit, summation (nsum,nprod) - Transforms —
laplace,ilaplace,fourier,ifourier,ztrans,iztrans,fft,ifft - Multivariable Calculus —
grad,hessian,jacobian,laplacian,volrev,surfrev,arclength - ODEs —
ode,odeeval,ode2 - Sequences — Recursive sequences (
recseq,recseqn), special sequences (fib,lucas,catalan,bell,stirling2,triang,pentag,hexag) - Statistics — Descriptive (
mean,median,mode,stddev,variance,skewness,kurtosis,quartiles,percentile,summary) - Regression —
linreg,linregfull,polyreg,expreg,logreg,pwrreg,bestfit(auto-selects best model),multreg,pca,clustering,anova - Hypothesis Tests —
ztest,ttest,ttest2,ttestpaired,ftest,chisqtest,proptest - Confidence Intervals —
zinterval,tinterval,tinterval2,propinterval,varint - Probability Distributions — 15+ distributions with PDF, CDF, and inverse: Normal, t, χ², F, binomial, Poisson, exponential, gamma, beta, Weibull, log-normal, Cauchy, Pareto, Rayleigh, uniform
- Linear Algebra — Matrix ops (
madd,mmul,transpose,det,identity,minv,trace,rank,lu,qr,eigenvalues,eigenvectors), vectors (dot,cross,norm) - Number Theory —
isprime,nextprime,prevprime,nthprime,ifactor,ifactors,divisors,gcd,lcm,euler,factorial,comb,perm,mobius,legendre,jacobi,primroot,dlog - Special Functions —
gamma,erf,erfc - Graph Theory — 80+ operators: BFS/DFS, shortest path (
shortestpath,allpairs), spanning trees (mst,spanningtree), flow (maxflow,mincut), coloring (chromatic,vertexcolor), cliques, components, planar testing, special graphs (completegraph,petersen,randomgraph), visualization (plotgraph,plotdigraph,plotweighted) - Automata & Formal Languages — DFA/NFA (
dfa,nfa,simulate,accepts,minimize,nfatodfa), regex (regex,regexmatch,regextonfa), CFG (cfg,derive,cyk,cnf), PDA (pda,simulatepda), Turing machines (tm,simulatetm) - Sets & Logic — Set ops (
setunion,setintersect,setdiff,powerset,cartesian), relations (isreflexive,issymmetric,istransitive,isequivalence,transitiveclosure), propositional logic (truthtable,satisfiable,tautology,karnaugh) - Cryptography — Classical ciphers (
caesar,rot13,vigenere,atbash,affine), modern crypto (rsa,rsaenc,rsadec,diffiehellman,elgamal), error correction (hamming74,parity), utilities (toascii,fromascii,freqanalysis) - Optimization —
fmin,fmax,fzero,linprog - Financial (TVM) —
tvmpv,tvmfv,tvmpmt,tvmn,tvmi, amortization (amort,amortbal,amortint,amortprin),npv,irr,mirr, bonds (bondpv,bondyld), depreciation (depsl,depdb,depddb,depsoyd) - Date Arithmetic —
dateadd,ddays(days between dates) - Units & Conversions — Physical units (
unit,convert,to,tosi), angle conversions (torad,todeg,tograd,todms,fromdms), user-defined units (defunit) - Bit Manipulation — Bitwise (
band,bor,bxor,bnot,bnand,bnor), shifts (shl,shr,asr,rol,ror), bit ops (setbit,clrbit,tglbit,getbit,bitcount,lsb,msb), fields (getfield,setfield,mask) - Base Conversion —
bin,oct,hex,dec,tobase,frombase - Modular Arithmetic —
addmod,submod,mulmod,powmod - Science — Periodic table (
element), physical constants (const,consts), stoichiometry (molarmass,moles,gmass) - Labeled Values — HP-style labeled data with
:operator,grabto extract,unlabelto unwrap - Plotting — 2D (
plot,plotparam,plotpolar,plotimplicit,plotvector,plotmulti), 3D (plot3d,plotparam3d,plotcyl,plotsph) - Random —
rand,randn,randint,randunif,randnorm,randlist,shuffle,sample,randseed - List Operations —
length,head,tail,append,concat,get,put,sublist,revlist,sort,range,list->
HP-style stack operations: dup, drop, swap, rot, over, pick, roll, nip, tuck, depth, clear, and more.
RPL programs: Write reusable programs using « ... » syntax, with variables (sto, rcl, purge), conditionals (ifte), and logic (and, or, not, xor).
- Rust 1.70+ (install via rustup)
- Windows: MSYS2 with GCC, GMP, MPFR (required by Symbolica)
git clone https://github.com/yourusername/calcu.git
cd calcu
cargo build --release
cargo run --releaseCalcu now includes an optional graphical interface with integrated plotting! To build and run with GUI support:
# Build with GUI feature
cargo build --release --features gui
# Run in GUI mode
cargo run --release --features gui -- --gui
# Or directly:
./target/release/calcu --guiGUI Features:
- 📊 Integrated Plotting — Graphs display directly in the application window (no browser needed)
- 📝 Visual Stack — See your stack in real-time
- ⌨️ Command History — Navigate with arrow keys
- 🎨 Dark Theme — Easy on the eyes
GUI Dependencies:
# Install MSYS2
winget install MSYS2.MSYS2
# Install required libraries
C:\msys64\usr\bin\bash.exe -lc "pacman -Sy --noconfirm mingw-w64-x86_64-gcc mingw-w64-x86_64-gmp mingw-w64-x86_64-mpfr mingw-w64-x86_64-mpc make"
# Add to PATH (for current session)
$env:Path = "C:\msys64\mingw64\bin;C:\msys64\usr\bin;" + $env:PathRPN means you enter values first, then the operator:
> 3 4 +
7
> 45 sin
0.7071067811865476
> 2 3 ^
8
> 100 'km' unit 'mi' convert
62.1371 mi
> 'x^3' 'x' deriv
3*x^2
> 'x^2' 'x' integrate
x^3/3
> '(x+1)^3' expand
x^3+3*x^2+3*x+1
> 'x^2-4' 'x' solveall
{-2, 2}
> {1 2 3 4 5} mean
3
> {1 2 3 4 5} summary
{min: 1, q1: 2, median: 3, q3: 4, max: 5, mean: 3, stddev: 1.58}
> {1 2 3 4 5} {2 4 5 4 5} bestfit
"linear", r²=0.64, y = 0.6x + 1.6
> 'Fe' element
Z: 26, Symbol: Fe, Name: Iron, Mass: 55.845 u, ...
> 'c' const
299792458 m/s
> 'H2O' molarmass
18.015
> 10000 5 12 / 360 tvmpmt # Monthly payment for $10k loan, 5% APR, 30 years
-53.68
> 100000 1000 20 12 amort # Amortization schedule
{payment: 1000, interest: 166.67, principal: 833.33, balance: 99166.67}
> 0xFF 0x0F band hex
0xF
> 1 10 shl
1024
> 5 ++
6
> 2 3 *** # Tetration: 2↑↑3 = 2^(2^2) = 16
16
> [[0 1 1] [1 0 1] [1 1 0]] adjmatrix # Create graph from adjacency matrix
Graph(3 vertices, 3 edges)
> dup bfs # BFS traversal from vertex 0
{0, 1, 2}
> dup shortestpath 0 2 # Shortest path from vertex 0 to 2
{0, 2}
> petersen # Generate the Petersen graph
Graph(10 vertices, 15 edges)
> {'q0 'q1} {'a 'b} 'q0 {'q1} {{'q0 'a 'q1} {'q1 'b 'q1}} dfa
DFA with 2 states
> "ab" simulate # Simulate input "ab"
Accepted
> '(a|b)*abb' regex # Create regex
Regex: (a|b)*abb
> regextonfa # Convert to NFA
NFA with 8 states
> "HELLO" 3 caesar # Caesar cipher with shift 3
"KHOOR"
> "SECRET" "KEY" vigenere # Vigenère cipher
"CIAVIG"
> 61 rsa # Generate RSA keypair with prime p=61
{n: 3233, e: 17, d: 2753, p: 61, q: 53}
> {1 2 3} {2 3 4} setunion # Union of sets
{1, 2, 3, 4}
> {1 2 3} {2 3 4} setintersect # Intersection
{2, 3}
> 'a and (b or c)' truthtable # Truth table for expression
a | b | c | result
0 | 0 | 0 | 0
0 | 0 | 1 | 0
...
> 'a or not a' tautology # Check if tautology
true
Like the HP-48/50g, you can write programs using the « » delimiters and store them as reusable functions with sto.
# Define a function to compute the hypotenuse
> « sq swap sq + sqrt » 'hypot' sto
# Now use it
> 3 4 hypot
5
# Define factorial recursively
> « dup 1 <= « drop 1 » « dup 1 - factorial * » ifte » 'factorial' sto
> 5 factorial
120
« ... »— Program delimiters (use the actual Unicode characters or type them directly)sto— Store top of stack into a variable:value 'name' storcl— Recall a variable:'name' rclpurge— Delete a variable:'name' purgeifte— If-then-else:condition « if-true » « if-false » ifteeval— Evaluate a program or expression on the stack
# Solves ax² + bx + c = 0, returns both roots
# Usage: a b c quadratic
> «
→ a b c
«
b neg b sq 4 a c * * - sqrt + 2 a * /
b neg b sq 4 a c * * - sqrt - 2 a * /
»
» 'quadratic' sto
> 1 -5 6 quadratic
3
2
| Command | Description |
|---|---|
help |
Show help for a specific operator |
list |
List all available operators |
clear |
Clear the stack |
quit |
Exit the calculator |
src/
├── main.rs # REPL entry point
├── stack.rs # RPN stack virtual machine
├── value.rs # Value types (Numeric, Complex, Symbolic, Matrix, List, etc.)
├── operator.rs # Operator trait
├── operators/ # Operator implementations
│ ├── unary.rs # Single-argument functions
│ ├── binary.rs # Two-argument operations
│ ├── cas.rs # Symbolic math (Symbolica integration)
│ ├── calculus.rs # Derivatives, integrals, limits, ODEs
│ ├── statistics.rs # Stats, regression, distributions
│ ├── finance.rs # TVM, amortization, bonds
│ ├── programming.rs # Bitwise, base conversion
│ ├── graph.rs # Graph theory (80+ operators)
│ ├── automata.rs # DFA, NFA, CFG, PDA, Turing machines
│ ├── sets.rs # Set operations, relations, propositional logic
│ ├── crypto.rs # Classical & modern cryptography
│ ├── science.rs # Chemistry, physics constants
│ ├── plotting.rs # 2D and 3D plotting
│ └── ...
├── cas.rs # CAS engine wrapper
├── units.rs # Physical units system
└── rpl.rs # RPL program parser/executor
cargo testThis is an actively developed project. Here's what's coming:
- Persistent Sessions — Save/restore your stack, variables, and custom functions between sessions
- Command History Persistence — Save command history across sessions
- Autocompletion — Tab-completion for operator names
- Non-interactive Mode — Run expressions directly from command line with
-e "expression" - More CAS Features — Improved symbolic integration
- Hash Functions —
md5,sha256(requires external libraries) - Complexity Analysis —
timecomplexity,spacecomplexityfor algorithm analysis - Import/Export — Load and save RPL programs from files
- Graphical User Interface — Full GUI mode with integrated plotting, visual stack, command history (build with
--features gui) - 560+ Operators — Comprehensive coverage from basic math to advanced CAS, graph theory, automata, cryptography
- Native Plotting — 2D and 3D plots rendered directly in the application (GUI) or via browser (CLI)
- RPL Programming — Full HP-style programming with
« »syntax, variables, loops, conditionals
The HP-48 and HP-50g represent, in my opinion, the pinnacle of handheld computing for technical work. Their combination of RPN, a powerful stack, symbolic math, and programmability created tools that were far ahead of their time.
This project doesn't aim to replicate them exactly but it tries to honor their philosophy: give the user powerful primitives, stay out of the way, and let them compose solutions to complex problems.
MIT
Built with Rust and a love for stack-based computation.