MathFlow 2.0.0

dotnet add package MathFlow --version 2.0.0
                    
NuGet\Install-Package MathFlow -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathFlow" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MathFlow" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MathFlow" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MathFlow --version 2.0.0
                    
#r "nuget: MathFlow, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MathFlow@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MathFlow&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MathFlow&version=2.0.0
                    
Install as a Cake Tool

MathFlow

<div align="center">

NuGet License Build Status .NET

C# math expression library with symbolic computation support

Parse • Evaluate • Differentiate • Simplify • Solve

</div>

Installation

Package Manager

dotnet add package MathFlow

Package Reference

<PackageReference Include="MathFlow" Version="2.0.0" />

Package Manager Console

Install-Package MathFlow

Quick Start

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

What's New in v2.0.0

Major Features Added

  • Complex Number Support: Full integration with expression parser
  • Enhanced Polynomial Factoring: Quadratic, cubic, and special forms
  • New ODE Solvers: RungeKutta2 and Adams-Bashforth methods
  • Rational Function Integration: Partial fractions and special forms
  • Symbolic Integration: Extended support for trigonometric and exponential functions

Features

Core Capabilities

  • Parse mathematical expressions from strings
  • Evaluate with variables and custom functions
  • Works with standard math notation
  • Symbolic differentiation and integration
  • Expression simplification and factoring
  • Numerical integration & equation solving
  • ASCII plotting for function visualization
  • Matrix operations & linear algebra
  • Arbitrary precision arithmetic
  • Complex number arithmetic

Supported Operations

Category Functions
Basic + - * / ^ %
Trigonometric sin cos tan asin acos atan
Hyperbolic sinh cosh tanh
Logarithmic ln log10 exp
Other sqrt abs floor ceil round sign min max factorial
Constants pi e tau phi

Advanced Features

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

Function Plotting (ASCII)

Display mathematical functions directly in terminal:

// Simple plot
var plot = engine.Plot("sin(x)", -Math.PI, Math.PI);
Console.WriteLine(plot.ToAsciiChart(60, 20));

// Multiple functions
var multiPlot = engine.CreatePlotter()
    .AddFunction("sin(x)", -Math.PI, Math.PI, label: "sin")
    .AddFunction("cos(x)", -Math.PI, Math.PI, label: "cos");
Console.WriteLine(multiPlot.ToAsciiChart(60, 20));

Output:

    1.0 ┤      ●●●●●                
        │    ●●    ●●              
        │  ●●        ●●            
        │ ●●          ●●           
    0.0 ┤●●────────────●●──────────
        │              ●●         ●
        │               ●●      ●● 
        │                ●●●●●●●   
   -1.0 ┤                          
        └──────────────────────────
         -3.14      0.00      3.14

Working with Expressions

Build expressions programmatically:

var expr1 = engine.Parse("x + 2");
var expr2 = engine.Parse("y - 1");
var combined = expr1 * expr2; // creates (x + 2) * (y - 1)

Variable substitution:

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

Register your own functions:

engine.RegisterFunction("double", args => args[0] * 2);
var result = engine.Calculate("double(5)"); // 10

More Examples

Check the Examples folder for advanced usage:

  • Complex numbers
  • Vector operations
  • Statistical functions
  • Linear regression

API Reference

Core Methods

Method Description
Calculate(expression, variables?) Evaluate expression
Parse(expression) Parse to AST
Simplify(expression) Simplify expression
Differentiate(expression, variable) Take derivative
Integrate(expression, variable, a, b) Numerical integration
FindRoot(expression, guess) Find root using Newton's method
FindRoots(expression, start, end) Find all roots in range
Expand(expression) Expand expression
Factor(expression) Factor expression (limited)
Substitute(expression, var, replacement) Replace variable
ToLatex(expression) Convert to LaTeX
ToMathML(expression) Convert to MathML

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Inspired by various mathematical expression parsers
  • Built with passion for mathematics and clean code

<div align="center"> Made by <a href="https://github.com/Nonanti">Nonanti</a> </div>

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.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.

Version Downloads Last Updated
2.0.0 46 8/27/2025
1.1.0 42 8/26/2025
1.0.0 64 8/26/2025

Initial release with core mathematical functionality