Repository navigation
Home
Fluent API for symbolic algebra in C# — build, evaluate, differentiate and parse mathematical expressions.
Think of it as LINQ for mathematics: instead of chaining operations on collections, you chain them on algebraic expressions.
dotnet add package MarcusMedina.Maths.AlgebraIn 2016, working as a study supervisor for upper-secondary (gymnasium) students, I had to explain the thinking behind their algebra assignments — or break the problems down into small enough pieces that they'd click. It was more than a little dismaying how much I'd forgotten since my own gymnasium days, and it got me thinking about how you'd actually explain algebra step by step as code. It took until 2022 for that thought to turn into action: I was hunting through an old gymnasium textbook for simple calculation exercises to use in a first C# course, and that's where the idea of algebra-as-code finally clicked.
In this case, I wanted the code itself to read like the explanation I'd give a student out loud, step by step, not just spit out a final answer.
-
New to algebra-as-code? Chain operations on expressions the same way you'd chain LINQ on a collection — build, differentiate, evaluate, and print
ToLaTeX()step by step, watching each transformation. - Professional? A small symbolic-computation engine for formula/calculator tools, educational software, or domain-specific apps that need expression building and differentiation without a full CAS dependency.
using MarcusMedina.Maths.Algebra.Builders;
using MarcusMedina.Maths.Algebra.Extensions;
using MarcusMedina.Maths.Algebra.Evaluators;
var expr = Algebra.X.Square().Add(Algebra.X.Multiply(3)).Subtract(7);
Console.WriteLine(expr); // (x^2 + 3*x) - 7
Console.WriteLine(expr.Evaluate("x", 2)); // -5
Console.WriteLine(expr.ToLaTeX()); // (x^{2} + 3 \cdot x) - 7