Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/asc-community/angourimath
New open-source cross-platform symbolic algebra library for C# and F#. Can be used for both production and research purposes.
https://github.com/asc-community/angourimath
algebra arbitrary-precision calculus computer-algebra csharp differentiation equations fsharp inequality integration jupyter latex math nuget parse parsing solver symbolic-manipulation symbolic-math
Last synced: about 23 hours ago
JSON representation
New open-source cross-platform symbolic algebra library for C# and F#. Can be used for both production and research purposes.
- Host: GitHub
- URL: https://github.com/asc-community/angourimath
- Owner: asc-community
- License: mit
- Created: 2019-11-27T17:38:45.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2024-06-11T20:45:01.000Z (8 months ago)
- Last Synced: 2025-01-29T22:12:12.305Z (3 days ago)
- Topics: algebra, arbitrary-precision, calculus, computer-algebra, csharp, differentiation, equations, fsharp, inequality, integration, jupyter, latex, math, nuget, parse, parsing, solver, symbolic-manipulation, symbolic-math
- Language: C#
- Homepage: https://am.angouri.org
- Size: 22.4 MB
- Stars: 792
- Watchers: 29
- Forks: 76
- Open Issues: 132
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
> [!WARNING]
> AngouriMath is deprecated. You can still use it, but it's unlikely it will go forward. Full story at [wbg.gg](https://wbg.gg/blog/angourimath-deprecation)AngouriMath
New open-source cross-platform symbolic algebra library for C# · F# · Jupyter · C++ (WIP)
Get started
·
Examples
·
Contributions
·
What's new
·
Website
Status board
![Solution Build](https://github.com/asc-community/AngouriMath/actions/workflows/EverythingBuild.yml/badge.svg)
#### Builds and tests
| | Kernel/C# | F# | Interactive | C++ |
|-------|-----------|----|-------------|-----|
| Build | ![C#/Kernel Build](https://github.com/asc-community/AngouriMath/actions/workflows/CSharpBuild.yml/badge.svg) | ![F# Build](https://github.com/asc-community/AngouriMath/actions/workflows/FSharpBuild.yml/badge.svg) | ![Interactive Build](https://github.com/asc-community/AngouriMath/actions/workflows/InteractiveBuild.yml/badge.svg) | ![C++ Build](https://github.com/asc-community/AngouriMath/actions/workflows/CPPBuild.yml/badge.svg) |
| Test | ![C# Test](https://github.com/asc-community/AngouriMath/actions/workflows/CSharpTest.yml/badge.svg) | ![F# Test](https://github.com/asc-community/AngouriMath/actions/workflows/FSharpTest.yml/badge.svg) | ![Interactive Test](https://github.com/asc-community/AngouriMath/actions/workflows/InteractiveTest.yml/badge.svg) | ![C++ Test](https://github.com/asc-community/AngouriMath/actions/workflows/CPPTest.yml/badge.svg) |Note, that all tests and builds are tested for the following three operating systems: Windows, Ubuntu, Mac OS.
#### Coverage
| Kernel/C# | F# | C++ |
|-----------|----|-----|
| | ??? | ??? |#### Versions
| | Prerelease | Stable | Downloads |
|:--:|:----------:|:------:|:---------:|
| Kernel/C# | | | |
| F# | | | |
| Interactive | | | |
| Experimental | | | |
| Terminal | | | |
| C++ | | WIP | WIP |There are also latest-master versions (updated on every push to master) on [MyGet](https://www.myget.org/feed/Packages/angourimath):
| MyGet | Downloads |
|-------|-----------|
| [![MyGet (with prereleases)](https://img.shields.io/myget/angourimath/vpre/AngouriMath?label=AngouriMath)](https://www.myget.org/feed/angourimath/package/nuget/AngouriMath) | ![MyGet](https://img.shields.io/myget/angourimath/dt/AngouriMath?label=Downloads) |
| [![MyGet (with prereleases)](https://img.shields.io/myget/angourimath/vpre/AngouriMath.FSharp?label=AngouriMath.FSharp)](https://www.myget.org/feed/angourimath/package/nuget/AngouriMath.FSharp) | ![MyGet](https://img.shields.io/myget/angourimath/dt/AngouriMath.FSharp?label=Downloads) |
| [![MyGet (with prereleases)](https://img.shields.io/myget/angourimath/vpre/AngouriMath.Interactive?label=AngouriMath.Interactive)](https://www.myget.org/feed/angourimath/package/nuget/AngouriMath.Interactive) | ![MyGet](https://img.shields.io/myget/angourimath/dt/AngouriMath.Interactive?label=Downloads) |
| [![MyGet (with prereleases)](https://img.shields.io/myget/angourimath/vpre/AngouriMath.Experimental?label=AngouriMath.Experimental)](https://www.myget.org/feed/angourimath/package/nuget/AngouriMath.Experimental) | ![MyGet](https://img.shields.io/myget/angourimath/dt/AngouriMath.Experimental?label=Downloads) |
Source to install from MyGet:
```
https://www.myget.org/F/angourimath/api/v3/index.json
```
#### Other info
| Website | Stars | License |
|---------|-------|---------|
| | | |If you want, you can add a badge to your repo:
```
[![Powered by AngouriMath](https://img.shields.io/badge/Powered%20by-AngouriMath-purple?style=flat-square&labelColor=646)](https://am.angouri.org)
```
[![Powered by AngouriMath](https://img.shields.io/badge/Powered%20by-AngouriMath-purple?style=flat-square&labelColor=646)](https://am.angouri.org)## What is it about?
AngouriMath is an open source symbolic algebra library.
That is, via AngouriMath, you can
automatically solve
equations, systems of equations,
differentiate,
parse from string,
compile expressions, work
with matrices, find limits,
convert an expression to LaTeX, and many other things.## Where can be used?
The two areas of use:
🧪 Research / Data Science [click 🖱️]
## AngouriMath for researchAs F#, great first-functional language, skyrocketing in the area of data analysis and interactive research, AngouriMath
offers a few ways to conveniently work with symbolic expressions.### Notebooks
![gif](./.github/additional/readme/vscnotebook.gif)
Notebooks provide amazing experience working with function visualization, for functions
over one and two variables. With [dotnet/interactive](https://github.com/dotnet/interactive),
it can be used in Visual Studio Code notebooks as well as Jupyter notebooks. To install
the package, simply run this in the notebook:```
#r "nuget:AngouriMath.Interactive,*-*"
```### Terminal
[![gif](./Sources/Terminal/terminal.gif)](./Sources/Terminal)
As both a demonstration sample and a convenient tool, this repository includes
tool called AngouriMath.Terminal. It is a CLI-based program to interact with
AngouriMath (as opposed to API-based interaction, that is, consuming it as a lib).[**[ Download ]**](https://github.com/asc-community/AngouriMathLab/releases)
Or build from sources:
```
git clone https://github.com/asc-community/AngouriMath
cd AngouriMath/Sources/Terminal/AngouriMath.Terminal
dotnet run -c release
```See the online [Jupyter notebook](https://mybinder.org/v2/gh/asc-community/AngouriMathLab/try?filepath=HelloBook.AngouriMath.Interactive.ipynb) on
how to use the F# API of AngouriMath. Note, that the C# API is still available
via `open AngouriMath` command, then you can call the main library's methods.See its [source folder](./Sources/Terminal).
### More
Read more about using AngouriMath for research on [the website](https://am.angouri.org/research).
💻 Software Development [click 🖱️]
It is installed from [nuget](https://am.angouri.org/quickstart/#dotnet) for both C# and F# and can be used by Web/Desktop/Mobile development.## Installing the library
1. Install AngouriMath from [NuGet](https://www.nuget.org/packages/AngouriMath).
2. Write the following code:
```cs
using AngouriMath; using System;
Entity expr = "x + sin(y)";
Console.WriteLine(expr);
```
3. Run.If you are new to AM, we suggest you checking out some samples instead of reading boring
documentation. If you want to contribute, we would be happy to welcome you in our
community.For any questions, feel free to contact us via Discord.
Official website: [am.angouri.org](https://am.angouri.org/).
## Examples
Expand any section to see. Examples with live shell are on the [website](https://am.angouri.org/).
Computations
Use as a simple calculator:
```cs
Entity expr = "1 + 2 * log(3, 9)";
Console.WriteLine(expr.EvalNumerical());
``````cs
Console.WriteLine("2 / 3 + sqrt(-16)".EvalNumerical());
>>> 2 / 3 + 4i
``````cs
Console.WriteLine("(-2) ^ 3".EvalNumerical());
```Build expressions with variables and substitute them:
```cs
Entity expr = "2x + sin(x) / sin(2 ^ x)";
var subs = expr.Substitute("x", 0.3m);
Console.WriteLine(subs);
```Simplify complicated expressions:
```cs
Console.WriteLine("2x + x + 3 + (4 a * a^6) / a^3 / 5".Simplify());
``````cs
var expr = "1/2 + sin(pi / 4) + (sin(3x)2 + cos(3x)2)";
Console.WriteLine(expr.Simplify());
```Compiled functions work 15x+ faster
```cs
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));
``````cs
var expr = "sin(x) + sqrt(x) / (sqrt(x) + cos(x)) + x3";
var compiled = expr.Compile("x");
Console.WriteLine(compiled.Substitute(4));
```Algebra
Start with boolean algebra:
```cs
Entity expr1 = "a and b or c";// Those are the same
Entity expr3 = "a -> b";
Entity expr3 = "a implies b";
``````cs
Entity expr = "a -> true";
Console.WriteLine(MathS.SolveBooleanTable(expr, "a"));
``````
>>> Matrix[2 x 1]
>>> False
>>> True
```Next, solve some equations:
```cs
Console.WriteLine("x^2 + x + a".SolveEquation("x"));
```Under developing now and forever (always available)
```cs
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());
```Try some inequalities:
```cs
Console.WriteLine("(x - 6)(x + 9) >= 0".Solve("x"));
```Systems of equations:
```cs
var system = MathS.Equations(
"x^2 + y + a",
"y - 0.1x + b"
);
Console.WriteLine(system);
var solutions = system.Solve("x", "y");
Console.WriteLine(solutions);
```
System:Result:
```cs
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);
```
(solution matrix is too complicated to show)Calculus
Find derivatives:
```cs
Entity func = "x^2 + ln(cos(x) + 3) + 4x";
Entity derivative = func.Differentiate("x");
Console.WriteLine(derivative.Simplify());
```Find limits:
```cs
WriteLine("(a x^2 + b x) / (e x - h x^2 - 3)".Limit("x", "+oo").InnerSimplified);
```Find integrals:
```cs
WriteLine("x^2 + a x".Integrate("x").InnerSimplified);
```Sets
There are four types of sets:
```cs
WriteLine("{ 1, 2 }".Latexise());
WriteLine("[3; +oo)".Latexise());
WriteLine("RR".Latexise());
WriteLine("{ x : x^8 + a x < 0 }".Latexise());
```
And there operators:
```cs
WriteLine(@"A \/ B".Latexise());
WriteLine(@"A /\ B".Latexise());
WriteLine(@"A \ B".Latexise());
```
Syntax
You can build LaTeX with AngouriMath:
```cs
var expr = "x ^ y + sqrt(x) + integral(sqrt(x) / a, x, 1) + derive(sqrt(x) / a, x, 1) + limit(sqrt(x) / a, x, +oo)";
Console.WriteLine(expr.Latexise());
>>> {x}^{y}+\sqrt{x}+\int \left[\frac{\sqrt{x}}{a}\right] dx+\frac{d\left[\frac{\sqrt{x}}{a}\right]}{dx}+\lim_{x\to \infty } \left[\frac{\sqrt{x}}{a}\right]
```You can parse `Entity` from string with
```cs
var expr = MathS.FromString("x + 2 + sqrt(x)");
Entity expr = "x + 2 + sqrt(x)";
```A few convenient features: `x2` => `x^2`, `a x` => `a * x`, `(...)2` => `(...)^2`, `2(...)` => `2 * (...)`
Compilation
Now you can compile expressions with pritimives into native lambdas. They will be
at least as fast as if you wrote them in line in code, or faster if you have
same subexpressions in your expression.```cs
Entity expr = "a and x > 3";
var func = expr.Compile("a", "x");
WriteLine(func(true, 6));
WriteLine(func(false, 6));
WriteLine(func(true, 2));
WriteLine(func(false, 2));
```Output:
```
True
False
False
False
```
MultithreadingYou are guaranteed that all functions in AM run in one thread. It is also guaranteed that you can safely run multiple
functions from AM in different threads, that is, all static variables and lazy properties are thread-safe.There is also support of cancellation a task. However, to avoid injecting the cancellation token argument into all methods,
we use `AsyncLocal` instead. That is why instead of passing your token to all methods what you need is to pass it once
to the `MathS.Multithreading.SetLocalCancellationToken(CancellationToken)` method.There is a sample code demonstrating cancellation:
```cs
var cancellationTokenSource = new CancellationTokenSource();// That goes instead of passing your token to methods
MathS.Multithreading.SetLocalCancellationToken(cancellationTokenSource.Token);// Then you normally run your task
var currTask = Task.Run(() => InputText.Text.Solve("x"), cancellationTokenSource.Token);try
{
await currTask;
LabelState.Text = currTask.Result.ToString();
}
catch (OperationCanceledException)
{
LabelState.Text = "Operation canceled";
}
```F#
Not everything is supported directly from F#, so if something missing, you will need
to call the necessary methods from AngouriMath.```fs
open Functions
open Operators
open Shortcutsprintfn "%O" (solutions "x" "x + 2 = 0")
printfn "%O" (simplified (solutions "x" "x^2 + 2 a x + a^2 = 0"))
printfn "%O" (``dy/dx`` "x^2 + a x")
printfn "%O" (integral "x" "x2 + e")
printfn "%O" (``lim x->0`` "sin(a x) / x")
printfn "%O" (latex "x / e + alpha + sqrt(x) + integral(y + 3, y, 1)")
```
C++ (Experimental)
At the moment, AngouriMath.CPP is in the experimental phase. See how to get AngouriMath for C++.
```cpp
#includeint main()
{
AngouriMath::Entity expr = "x y + 2";
std::cout << expr.Differentiate("x");
}
```
AngouriMath is a free open-source project, there is no big company backing us. That is why we warmly welcome any contributors
to the project. Aside from volunteer donations, you can help developing the project: check the [guide for developers](./CONTRIBUTING.md).[![DOI](https://zenodo.org/badge/224485143.svg)](https://zenodo.org/badge/latestdoi/224485143)
The project is open source, but can be used in closed commercial projects. There is no restriction on it
with the only requirement to keep the MIT license with all distributives of AngouriMath.