SympJS: When Your Math Library Has Better Type Safety Than Your Life Choices

SympJS: When Your Math Library Has Better Type Safety Than Your Life Choices

Building Symbolic Mathematics in TypeScript Because Python's Dynamic Typing Gave Me Trust Issues

The Origin Story: Academic Rebellion

It all started when my college professor handed us SymPy like it was holy scripture.
"Here, learn this Python library for symbolic math."

I looked at the Python code:

x = symbols('x')
expr = x**2 + 3*x   # Hope you like runtime errors!

And I thought: What if we could have this... but with actual types?
What if my IDE knew the difference between a symbolic expression and a regular number? What if I didn’t have to run the code to discover I misspelled 'derivative'?

Thus, SympJS was born — not because the world needed another math library, but because my sanity needed type safety.

What Actually Works Right Now

🚀 Core Symbolic Engine:

  • Create variables: const [x, y] = symbols('x', 'y')
  • Build expressions naturally: x.pow(2).add(y.mul(3)) → x² + 3y
  • Automatic simplification: eliminates x * 0, x + 0, and combines like terms
  • Method chaining that would make jQuery jealous

🧠 Automatic Differentiation:

const derivative = diff(x.pow(3), x); // 3x²

It understands calculus rules — power rule, product rule, quotient rule — all without crying over chain rule.

🎨 Beautiful Rendering:

My math expressions don’t look like they’re suffering from depression. They render with proper spacing and elegance:

x² + 3y (not x^2 + 3*y like some barbarian)

🧩 Matrix Operations That Don’t Suck:

const A = new Matrix([[1, 2], [3, 4]]);
const det = A.determinant(); // Actually works!

And yes, it handles MxN matrices, because the real world isn’t always square.

The “Why This Isn’t Completely Pointless” Section

You might ask: “Why build this when SymPy exists?”

  • Type Safety: My IDE knows what I’m doing before I run it
  • Web Native: Runs anywhere JavaScript does
  • No Python Environment Hell: npm install vs virtualenv suffering
  • It's Actually Fun: method chaining > function soup

Current Status: "Surprisingly Usable"

  • 94 real downloads (or bots — but I choose to believe in them)
  • Zero eval() usage because I'm not a monster
  • MIT Licensed
  • No dependencies because I hate node_modules bloat
  • Fast-ish and won’t give you XSS vulnerabilities

The Road to 1.0: Where I'm Headed

  • Symbolic Integration (because differentiation without integration is just one shoe)
  • Equation Solving that doesn’t make you cry
  • LaTeX Export (for professor-impressing rituals)
  • Better Performance (currently “fast enough”)

Try It Yourself

npm install @auriel/sympjs

Then blow your own mind:

import { symbols, diff, Render } from '@auriel/sympjs';

const [x, y] = symbols('x', 'y');
const expr = x.pow(2).add(y.mul(3));
const derivative = diff(expr, x); // 2x

const renderer = new Render();
renderer.renderSymbolic(expr, 'math-container');

Final Thoughts

Building SympJS has been the perfect blend of “this is actually useful” and “I am learning an insane amount about computer algebra systems.”

Is it going to replace Mathematica? Probably not.
Is it going to make your math homework slightly less painful? Absolutely.

And sometimes, that’s enough.

🌙 GitHub: github.com/uriel-flame-of-god/SympJS

📦 NPM: npmjs.com/package/@auriel/sympjs

"Purgatus pulvis, imperfectum perfectum" — because even math libraries need redemption arcs.

Comments