Skip to content

KarpelesLab/mathesis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mathesis

A Mathematica-style computational notebook that runs entirely in your browser.

Mathesis is a free, client-side mathematics workbench: type an expression in Wolfram-style syntax and get an exact answer, computed on your own machine with no server round-trip. The math engine is written in Rust, compiled to WebAssembly, and wrapped in a Vue 3 notebook UI.

Live at https://karpeleslab.github.io/mathesis/ (deployed from master via GitHub Actions).

The interface is available in English, French, and Japanese (switch from the header; it follows your browser by default), and a built-in Docs panel documents every function with syntax and runnable examples in all three languages. Engine error messages are currently English only.

The name

Mathesis (μάθησις) derives from the ancient Greek word for "learning" or "that which is learned". It typically refers to the rigorous, active pursuit of knowledge — particularly mathematical and scientific discipline.

Philosophy

Mathesis is a frontend. It owns the language — a lexer, parser, and evaluator for a Wolfram-style surface syntax — and the presentation (KaTeX rendering, the notebook). It deliberately owns as little mathematics as possible: every real computation is delegated to dependency-free, pure-Rust engines, and anything Mathesis implements itself is a temporary stand-in until an adequate crate exists to hold it.

Engines:

  • puremp — exact arbitrary-precision integers, rationals, and more. Powers today's numeric tower.
  • z3rs — a pure-Rust Z3 port (SMT / logic). To be wired in as the language grows to solving and constraints.

What works today

Exact evaluation of a numeric core:

You type You get
2^128 340282366920938463463374607431768211456
1/3 + 1/3 + 1/3 1
1/2 + 1/3 5/6 (rendered as a fraction)
(1 + 1/2)^10 59049/1024
20! 2432902008176640000
Factor[360] 2³ · 3² · 5
GCD[462, 1071] 21
Fibonacci[100] 354224848179261915075
PrimeQ[2^61 - 1] True
Sqrt[152399025] 12345
Pi π   (≈ 3.141592653589793)
Sqrt[2] √2   (≈ 1.4142135623730951)
N[Pi, 40] 3.1415926535897932384626433832795028841972
Sin[Pi/4] 0.7071067811865476

Exact is preferred, with the decimal shown alongside. Results are kept exact whenever possible, and anything that isn't a plain integer also shows a decimal approximation (≈ …):

  • exact — integers, rationals (in lowest terms), and irrational leaves kept in symbolic form: Pi → π, Sqrt[2] → √2, each with its decimal beneath.
  • real — an arbitrary-precision decimal, used when a result can't be kept exact. It is contagious: 1/3 + 1/3 stays exact 1, but 1/3 + Pi (and Sin[1], 2·Pi, …) becomes a real. Reals show ~16 digits; N[x, d] shows d.

There is no symbolic simplifier yet, so exact irrationals survive only as leaves: Sqrt[2] stays √2, but 2·Pi collapses to a decimal.

Syntax supported: integer & exact-decimal literals, + - * / ^, unary minus, postfix !, parentheses, {lists}, function calls Head[args], and % for the previous result.

Builtins (all delegating to puremp):

  • Arithmetic & generalPower, Sqrt, Abs, Sign, N, Floor, Ceiling, Round, IntegerPart, FractionalPart.
  • Number theoryFactor, Divisors, DivisorSigma, EulerPhi, MoebiusMu, Radical, GCD, LCM, PrimeQ, NextPrime, PreviousPrime, Factorial, Binomial, Multinomial, Fibonacci, LucasL, Mod, Quotient, PowerMod, ModularInverse, ExtendedGCD, JacobiSymbol, ChineseRemainder, SqrtMod, DiscreteLog, EvenQ, OddQ, IntegerQ.
  • RationalsNumerator, Denominator, ContinuedFraction, FromContinuedFraction, Rationalize.
  • Constants & transcendentalsPi, E, EulerGamma, Catalan; Exp, Log (Log[x] natural, Log[b, x] base b), Log2, Log10; Sin, Cos, Tan, ArcSin, ArcCos, ArcTan (ArcTan[x, y] = atan2); Sinh, Cosh, Tanh, ArcSinh, ArcCosh, ArcTanh; the special functions Erf, Erfc, and the Riemann zeta Zeta.
  • Complex — the imaginary unit I, plus Re, Im, Conjugate, Abs, Arg. Kept exact (Gaussian-rational) when possible — (1 + I)^22 I, Sqrt[-4]2 I, 1/(1 + I)1/2 - 1/2 I — and an arbitrary-precision inexact complex once an irrational or transcendental enters: Pi*I3.14159… I, Sqrt[-2]1.41421… I, Exp[I*Pi]-1. Sqrt, Exp, Log, Sin, and Cos accept complex arguments.
  • Linear algebra (exact, over rationals) — Det, Inverse, Transpose, Dot, MatrixRank, LinearSolve, IdentityMatrix; LatticeReduce (LLL reduction of an integer basis, optional second argument δ ∈ (1/4, 1]). Rectangular list-of-lists render as bracketed matrices.
  • PlottingPlot[expr, {x, a, b}] draws a 2D curve (a list of expressions plots several at once); Plot3D[expr, {x, a, b}, {y, c, d}] draws a surface you can drag to rotate. The expression is sampled numerically with the plot variable bound; out-of-domain points become gaps.
  • Solving / theorem proving (via z3rs, a pure-Rust Z3 port) —
    • SatisfiableQ[c]True/False. FindInstance[c, vars] finds one satisfying assignment; Solve[c, vars] returns all solutions over the integers (sorted, capped), or one over the reals — each as exact, typeset rules ({x → 6, y → 4}, {} if none, reals as fractions like x → 3/2). An optional third argument picks the domain: Integers (default) or Reals. Constraints use == != < <= > >= && || and the heads And, Or, Not, Implies, Xor. Variables used only in boolean positions are inferred as propositions, so pure logic works too — SatisfiableQ[p || q]True, SatisfiableQ[Implies[p, q] && p && Not[q]]False. Nonlinear constraints can't be solved (z3rs decides only linear arithmetic), but genuinely impossible ones are still refuted: SatisfiableQ[x^2 == -1]False.
    • Maximize[obj, constraints, {vars}] / Minimize[…] do linear optimization, returning {optimum, {x → …}} (unbounded/infeasible objectives error clearly). Only linear arithmetic is decidable; a nonlinear constraint (a product or power of two unknowns) comes back as a clear "unknown" error.
    • SMT["…"] runs a raw SMT-LIB 2 script and shows the solver's verbatim output (decides QF_LIA / QF_LRA / QF_UF / QF_AX / QF_BV). The engine is sound and terminating: a work budget yields unknown, never a hang.
    • The relational/logical operators also work standalone: 2 < 3True.

Sharing

Every computation and the whole notebook are shareable as a self-contained link. The inputs are encoded into the URL hash (#c=… for one computation, #n=… for a notebook) — no server is involved — and opening the link replays them locally. Use the Share button in the header for the whole notebook, or hover a cell for its own share button. On supported devices this opens the native share sheet (navigator.share); otherwise the link is copied to the clipboard.

Long-running computations

The engine runs in a Web Worker, so the UI never freezes — even on an accidental 3000000!. A computation that exceeds a wall-clock budget (a few seconds) is force-stopped by terminating the worker (pure wasm can't be interrupted cooperatively), and there's a Stop button to abort sooner. Results large enough to choke the renderer are shown as truncated text instead of typeset math.

Repository layout

Cargo.toml            # the wasm engine crate (Rust)
src/                  # lexer → parser → evaluator, delegating math to puremp
  lexer.rs  parser.rs  ast.rs  value.rs  eval.rs  lib.rs
frontend/             # Vue 3 + Vite notebook UI
  src/App.vue         # the notebook
  src/components/     # Editor (CodeMirror) + MathOutput (KaTeX)
  src/engine.ts       # loads the wasm module
.github/workflows/    # build wasm + frontend, deploy to Pages

Building

Everything is built in CI (see .github/workflows/pages.yml); no build tooling needs to be installed to hack on the sources. To build locally you need Rust with the wasm32-unknown-unknown target, wasm-pack, and Node:

# 1. Compile the Rust engine to wasm (outputs to frontend/src/pkg/)
wasm-pack build --target web --out-dir frontend/src/pkg --release

# 2. Run the notebook UI
cd frontend
npm install
npm run dev

Rust tests for the engine run without any wasm tooling:

cargo test

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors