MarcusMedina.Maths.Algebra
0.3.2
dotnet add package MarcusMedina.Maths.Algebra --version 0.3.2
NuGet\Install-Package MarcusMedina.Maths.Algebra -Version 0.3.2
<PackageReference Include="MarcusMedina.Maths.Algebra" Version="0.3.2" />
<PackageVersion Include="MarcusMedina.Maths.Algebra" Version="0.3.2" />
<PackageReference Include="MarcusMedina.Maths.Algebra" />
paket add MarcusMedina.Maths.Algebra --version 0.3.2
#r "nuget: MarcusMedina.Maths.Algebra, 0.3.2"
#:package MarcusMedina.Maths.Algebra@0.3.2
#addin nuget:?package=MarcusMedina.Maths.Algebra&version=0.3.2
#tool nuget:?package=MarcusMedina.Maths.Algebra&version=0.3.2
MarcusMedina.Maths.Algebra
Fluent API for algebraic expressions, symbolic mathematics, and equation manipulation in C#
Build expression trees, evaluate symbolic math, and export to LaTeX - all with a clean, fluent interface designed for both education and production use.
In 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.
๐ Features
- โ Expression Trees - Build complex algebraic expressions programmatically
- โ Symbolic Math - Work with variables and expressions without immediate evaluation
- โ
Fluent API - Chain operations naturally:
Algebra.X.Add(5).Square() - โ Variable Substitution - Replace variables with values or other expressions
- โ Simplification - Automatic constant folding and identity rule application
- โ LaTeX Export - Generate publication-ready mathematical notation
- โ Type-Safe - Full type safety with expression validation
- โ Extensible - Easy to add custom functions and operators
- ๐ Expression Parser - Parse strings like
"3*(x+2)^2"(coming soon) - ๐ Symbolic Differentiation - Automatic derivative calculation (coming soon)
- ๐ Matrix Operations - Fluent matrix algebra (coming soon)
๐ฆ Installation
dotnet add package MarcusMedina.Maths.Algebra
Or via Package Manager Console:
Install-Package MarcusMedina.Maths.Algebra
Requirements:
- .NET 10.0 or later
- C# 14.0 or later
๐ Quick Start
Basic Usage
using MarcusMedina.Maths.Algebra.Builders;
using MarcusMedina.Maths.Algebra.Extensions;
// Create expression: (x + 2)^2 / 3
var expr = Algebra.X
.Add(2)
.Square()
.Divide(3);
// Evaluate with x = 4
double result = expr.Evaluate("x", 4); // (4 + 2)^2 / 3 = 12
// Export to LaTeX
string latex = expr.ToLaTeX(); // \frac{(x + 2)^{2}}{3}
Variable Substitution
// Work with multiple variables
var expr = Algebra.X.Multiply(2).Add(Algebra.Y);
// Substitute and evaluate
var vars = new Dictionary<string, double> { ["x"] = 3, ["y"] = 5 };
double result = expr.Evaluate(vars); // 2*3 + 5 = 11
๐ Documentation
- Getting Started - Installation and setup guide
- Manual - Comprehensive documentation
- Examples - Detailed usage examples
- API Reference - Complete API documentation
๐ง Use Cases
This library solves real-world problems in mathematics and education:
- Equation Solver - Programmatically build and solve algebraic equations
- LaTeX Generator - Convert mathematical expressions to publication-ready notation
- Symbolic Calculator - Interactive symbolic mathematics with variable substitution
Each use case includes a working example and demonstrates how to integrate this library.
๐ก Examples
Creating Complex Expressions
// (2x^2 + 3x + 1) / (x - 1)
var numerator = Algebra.X
.Square()
.Multiply(2)
.Add(Algebra.X.Multiply(3))
.Add(1);
var denominator = Algebra.X.Subtract(1);
var fraction = numerator.Divide(denominator);
var simplified = fraction.Simplify();
Generating Mathematical Notation
var expr = Algebra.X
.Add(5)
.Multiply(Algebra.X.Subtract(3));
var latex = expr.ToLaTeX();
// Output: (x + 5)(x - 3)
var text = expr.ToString();
// Output: (x + 5) * (x - 3)
๐งช Testing
Run the test suite:
cd csharp
dotnet test --configuration Release
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Package Integrity
All releases are signed with cosign (Sigstore keyless signing).
To verify a downloaded package:
cosign verify-blob <package.nupkg> \
--bundle <package.nupkg.sigstore.json> \
--certificate-identity-regexp "https://github.com/MarcusMedinaPro/.*/release.yml" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com
The .sigstore.json bundle is available in each GitHub Release.
๐ค Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Built with Human + AI Collaboration
This library was written by Marcus Medina together with Claude Code (Anthropic) โ not through "vibe coding" where you just describe and accept, but through genuine collaboration: planning together, reviewing each other's decisions, pushing back when something felt wrong, and iterating until the result felt right.
The goal was always to write code worth reading and code worth using โ the kind a student can open, understand, and learn from, and the kind any programmer can drop into real, professional work without wanting to rewrite it from scratch. AI was a partner in that process, not a shortcut around it.
If you're curious about this way of working, the source code and git history are open. Every decision has a reason behind it.
Made for Curious Minds
This library was built with students in mind โ not as a black box to copy and paste, but as a real-world example of how clean, purposeful code is written and shared. At the same time, it's built to be genuinely useful in professional projects too โ for any developer who's tired of writing the same code over and over.
Whether you're discovering C# for the first time, need a reliable helper for your school project, want a dependable building block for production work, or are simply trying to fall in love with writing code โ you're exactly who this was made for.
The source is open. Read it, fork it, break it, improve it. That's the whole point.
๐ Related Projects
- MarcusMedina.Units.Math โ Unit-aware mathematical operations
- MarcusMedina.Units.Distance โ Distance unit conversions
- MarcusMedina.Fluent.Data โ CSV, JSON, XML extensions
- MarcusMedina.Fluent.Data.Sql โ SQL-style pattern matching
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.