MathFlow 1.0.0
See the version list below for details.
dotnet add package MathFlow --version 1.0.0
NuGet\Install-Package MathFlow -Version 1.0.0
<PackageReference Include="MathFlow" Version="1.0.0" />
<PackageVersion Include="MathFlow" Version="1.0.0" />
<PackageReference Include="MathFlow" />
paket add MathFlow --version 1.0.0
#r "nuget: MathFlow, 1.0.0"
#:package MathFlow@1.0.0
#addin nuget:?package=MathFlow&version=1.0.0
#tool nuget:?package=MathFlow&version=1.0.0
MathFlow
C# math expression library with symbolic computation support.
Install
dotnet add package MathFlow
Basic usage
using MathFlow.Core;
var engine = new MathEngine();
// basic stuff
var result = engine.Calculate("2 + 3 * 4"); // returns 14
Console.WriteLine(engine.Calculate("sin(pi/2)")); // 1
// with variables
var vars = new Dictionary<string, double> { ["x"] = 3, ["y"] = 4 };
var answer = engine.Calculate("x^2 + y^2", vars); // 25
Features
Expressions
- Parse mathematical expressions from strings
- Evaluate with variables
- Works with standard math notation
Operations
Basic: +, -, *, /, ^, %
Trig: sin, cos, tan, asin, acos, atan (also sinh, cosh, tanh)
Other: exp, ln, log10, sqrt, abs, floor, ceil, round, sign, min, max, factorial
Constants: pi, e, tau (2*pi), phi (golden ratio)
Advanced stuff
Derivatives
var derivative = engine.Differentiate("x^3 + 2*x^2 - 5*x + 3", "x");
// gives you: 3*x^2 + 4*x - 5
Simplification
var simplified = engine.Simplify("x + 2*x + 3*x");
Console.WriteLine(simplified); // 6*x
Equation solving
// find root near initial guess
double root = engine.FindRoot("x^2 - 4", 3); // returns 2
// find all roots in range
double[] roots = engine.FindRoots("x^3 - 6*x^2 + 11*x - 6", 0, 4);
// gives [1, 2, 3]
Integration (numerical)
double integral = engine.Integrate("x^2", "x", 0, 1);
// returns ~0.333333
Working with expressions
You can also build expressions programmatically:
var expr1 = engine.Parse("x + 2");
var expr2 = engine.Parse("y - 1");
var combined = expr1 * expr2; // creates (x + 2) * (y - 1)
Substitute variables:
var substituted = engine.Substitute("x^2 + y", "x", "sin(t)");
// gives: sin(t)^2 + y
Output formats
LaTeX
string latex = engine.ToLatex("sqrt(x^2 + y^2)");
// \sqrt{x^{2} + y^{2}}
MathML
string mathml = engine.ToMathML("x/2");
// outputs MathML format
Custom functions
You can register your own:
engine.RegisterFunction("double", args => args[0] * 2);
var result = engine.Calculate("double(5)"); // 10
More examples
Check the Examples folder for more usage examples including:
- Complex numbers
- Vector operations
- Statistical functions
- Linear regression
API
Main methods:
Calculate(expression, variables?)
- evaluate expressionParse(expression)
- parse to ASTSimplify(expression)
- simplify expressionDifferentiate(expression, variable)
- take derivativeIntegrate(expression, variable, a, b)
- numerical integrationFindRoot(expression, guess)
- find root using Newton's methodFindRoots(expression, start, end)
- find all roots in rangeExpand(expression)
- expand expressionFactor(expression)
- factor expression (limited support)Substitute(expression, var, replacement)
- replace variableToLatex(expression)
- convert to LaTeXToMathML(expression)
- convert to MathML
Requirements
.NET 8.0 or later
Tests
Run tests with:
dotnet test
Known issues
- Factor() method is not fully implemented
- Some edge cases in complex expressions might not simplify optimally
- Performance could be better for very large expressions
Contributing
PRs welcome. Please add tests for new features.
License
MIT
Credits
Inspired by various math expression parsers and CAS systems.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.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.
Initial release with core mathematical functionality