Skip to content

Napero/calcu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Calcu

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.


Features

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/rect conversion, 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, grab to extract, unlabel to 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).


Quick Start

Requirements

  • Rust 1.70+ (install via rustup)
  • Windows: MSYS2 with GCC, GMP, MPFR (required by Symbolica)

Build & Run

git clone https://github.com/yourusername/calcu.git
cd calcu
cargo build --release
cargo run --release

Graphical Interface (GUI)

Calcu 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 --gui

GUI 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:

  • The GUI uses egui (very lightweight, ~3MB extra)
  • Plots are rendered natively with egui_plot

Windows Setup (MSYS2)

# 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:Path

Usage Examples

RPN 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

Symbolic Math

> '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}

Statistics & Regression

> {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

Science

> 'Fe' element
Z: 26, Symbol: Fe, Name: Iron, Mass: 55.845 u, ...

> 'c' const
299792458 m/s

> 'H2O' molarmass
18.015

Financial

> 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}

Bit Manipulation & Programming

> 0xFF 0x0F band hex
0xF

> 1 10 shl
1024

> 5 ++
6

> 2 3 ***    # Tetration: 2↑↑3 = 2^(2^2) = 16
16

Graph Theory

> [[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)

Automata & Formal Languages

> {'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

Cryptography

> "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}

Sets & Logic

> {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

RPL Programming

Like the HP-48/50g, you can write programs using the Β« Β» delimiters and store them as reusable functions with sto.

Defining Custom Functions

# 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 Syntax

  • Β« ... Β» β€” Program delimiters (use the actual Unicode characters or type them directly)
  • sto β€” Store top of stack into a variable: value 'name' sto
  • rcl β€” Recall a variable: 'name' rcl
  • purge β€” Delete a variable: 'name' purge
  • ifte β€” If-then-else: condition Β« if-true Β» Β« if-false Β» ifte
  • eval β€” Evaluate a program or expression on the stack

Example: Quadratic Formula

# 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

Commands

Command Description
help Show help for a specific operator
list List all available operators
clear Clear the stack
quit Exit the calculator

Project Structure

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

Running Tests

cargo test

Roadmap

This 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, spacecomplexity for algorithm analysis
  • Import/Export β€” Load and save RPL programs from files

What's Already Done βœ…

  • 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

Inspiration

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.


License

MIT


Built with Rust and a love for stack-based computation.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages