AngouriMath
| Safe to clone right now? | |
| Installation from NuGet | |
| License | |
| Contact us |
What is it about?
AngouriMath is a cross-platform open-source library that enables to work with non-linear multi-variable expressions. Written in C#. Free and distributed under MIT license.
README navigation:
If you are new to AM, we suggest you checking out some samples instead of reading boring documentation. If you prefer full manual to AM, see Wiki. If you want to contribute, we surely appreciate it, but so far do not have documentation for you. It will appear soon!
Installation
The easiest way to install AM is to install it from Nuget.
If you need git commands, that is how you clone the repo
git clone --recurse-submodules https://github.com/asc-community/AngouriMath
Add this repo to your project's dependencies
git submodule add https://github.com/asc-community/AngouriMath
After cloning, you do not need to set up it. It is ready to use, just add the reference to the AngouriMath project from your solution.
Examples
Use as a simple calculator
Entity expr = "1 + 2 * log(3, 9)";
Console.WriteLine(expr.Eval());Console.WriteLine("2 / 3 + sqrt(-16)".Eval());
>>> 2 / 3 + 4iConsole.WriteLine("(-2) ^ 3".Eval());Substitute variables
Entity expr = "2x + sin(x) / sin(2 ^ x)";
var subs = expr.Substitute("x", 0.3m);
Console.WriteLine(subs);Find derivatives
var func = "x2 + ln(cos(x) + 3) + 4x";
var derivative = func.Derive("x");
Console.WriteLine(derivative.Simplify());Simplify
Console.WriteLine("2x + x + 3 + (4 a * a^6) / a^3 / 5".Simplify());var expr = "1/2 + sin(pi / 4) + (sin(3x)2 + cos(3x)2)";
Console.WriteLine(expr.Simplify());Build latex
var expr = "x ^ y + sqrt(x + y / 4)(6 / x)";
Console.WriteLine(expr.Latexise());
>>> {x}^{y}+\sqrt{x+\frac{y}{4}}\times \frac{6}{x}Solve equations analytically
Console.WriteLine("x2 + x + a".SolveEquation("x"));Under developing now and forever (always available)
Entity expr = "(sin(x)2 - sin(x) + a)(b - x)((-3) * x + 2 + 3 * x ^ 2 + (x + (-3)) * x ^ 3)";
Console.WriteLine(expr.SolveEquation("x").Latexise());Solve systems of non-linear equations
Under developing now and forever (always available)
var system = MathS.Equations(
"x2 + y + a",
"y - 0.1x + b"
);
Console.WriteLine(system);
var solutions = system.Solve("x", "y");
Console.WriteLine(solutions);System:
Result:
var system = MathS.Equations(
"cos(x2 + 1)^2 + 3y",
"y * (-1) + 4cos(x2 + 1)"
);
Console.WriteLine(system.Latexise());
var solutions = system.Solve("x", "y");
Console.WriteLine(solutions);Compile functions
Compiled functions work 15x+ faster
var x = MathS.Variable("x");
var expr = MathS.Sin(x) + MathS.Sqrt(x) / (MathS.Sqrt(x) + MathS.Cos(x)) + MathS.Pow(x, 3);
var func = expr.Compile(x);
Console.WriteLine(func.Substitute(3));var expr = "sin(x) + sqrt(x) / (sqrt(x) + cos(x)) + x3";
var compiled = expr.Compile("x");
Console.WriteLine(compiled.Substitute(4));Work with sets
var A = new Set(3, 4, (5, 6)); // {3, 4} | [5; 6]
var B = new Set((x, MathS.Sqrt(x)), 4);
var C = (A | B) & A;Work with numbers
var rat1 = Number.CreateRational(3, 4);
var rat2 = Number.CreateRational(5, 6);
Console.WriteLine((rat1 + rat2).ToString());
>>> 19 / 12Translate number systems
string x = MathS.ToBaseN(-32.25, 4);
Console.WriteLine("-32.25(10) = " + x + "(4)");
double y = MathS.FromBaseN("AB.3", 16);
Console.WriteLine("AB.3(16) = " + y + "(1)");
>>> -32.25(10) = -200.1(4)
>>> AB.3(16) = 171,1875(1)See more on Wiki.
Contribution
We appreciate and welcome any contributors to AngouriMath.
Use pull requests to contribute to it. We also appreciate early pull requests so that we know what you are improving and can help you with something.
Documentation for contributors and developers is here.