xFunc.Maths
4.4.1
dotnet add package xFunc.Maths --version 4.4.1
NuGet\Install-Package xFunc.Maths -Version 4.4.1
<PackageReference Include="xFunc.Maths" Version="4.4.1" />
paket add xFunc.Maths --version 4.4.1
#r "nuget: xFunc.Maths, 4.4.1"
// Install xFunc.Maths as a Cake Addin #addin nuget:?package=xFunc.Maths&version=4.4.1 // Install xFunc.Maths as a Cake Tool #tool nuget:?package=xFunc.Maths&version=4.4.1
Master:
Dev:
xFunc.Maths:
xFunc.Cli:
xFunc
xFunc is a user-friendly C# library for constructing and manipulating mathematical and logical expressions. This lightweight library empowers developers to effortlessly parse strings into expression trees, analyze expressions (including derivatives and simplifications), and perform various mathematical operations.
xFunc is a versatile tool suitable for both educators and students, allowing the creation of complex mathematical expressions.
Note: The WPF application (xFunc UI) was migrated to a separate repository xFunc.UI.
Features:
- Evaluate expressions (see all supported functions and operators):
- basic arithmetic operators:
+
,-
,*
,/
,^
, etc. - trigonometric functions:
sin(x)
,cos(x)
,tan(x)
, etc. - inverse trigonometric functions:
arcsin(x)
,arccos(x)
,arctan(x)
, etc. - hyperbolic functions:
sinh(x)
,cosh(x)
,tanh(x)
, etc. - inverse hyperbolic functions:
arsinh(x)
,arcosh(x)
,artanh(x)
, etc. - complex numbers:
1 + 2i
,im(x)
,re(x)
, etc. - vector/matrix:
{1, 2, 3}
,{{1, 2}, {3, 4}}
, etc. - statistical:
sum(a, b, c)
,avg(a, b, c)
, etc. - bitwise operators:
x or y
,x and y
, etc. - units:
90 'deg'
- angles,10 'm'
- length,10 'min'
- time, etc. - lambdas:
f := (x) => x ^ 2
,((x) => x ^ 2)(3)
,curry(f)
, etc.
- basic arithmetic operators:
- Derivative calculation;
- Simplify expressions (simplification rules);
- Supported Framework: .NET 6+;
Usage
The main class of xFunc library is Processor
. Detailed documentation is located on GitHub Pages.
Processor
It allows you to:
Parse:
var processor = new Processor();
var exp = processor.Parse("2 + x");
// 'exp' will contain the expression tree for later use
// you can calculate it or process it by analyzers (Differentiator, Simplifier, etc.)
// 'exp' has a parameter
// we should provide a value for variable 'x'
var parameters = new ExpressionParameters
{
new Parameter("x", 10)
};
var result = exp.Execute(parameters);
// result will be equal to 12
Note: The Parse
method won't simplify the expression automatically, it will return the complete representation of provided string expression.
Solve:
This method parses string expression (like the Parse
method) and then calculates it (returns object which implements the Result
abstract class).
var processor = new Processor();
var result = processor.Solve("2 + 2");
Console.WriteLine(result); // 4.0
The result
variable will contain 4
(as NumberResult
which is the implementation of the Result
class). It is a hand-made implementation of the discriminated union. The Result
class provides the abstraction (root class) for DU, whereas implementation for each possible return type is dedicated to the appropriate nested result class. Check documentation for more examples: Result, Processor.
If your expression has any parameter, you need to assign a value to it (otherwise xFunc will throw an exception), because Processor
has a build-in collection of parameters and user functions, you don't need to use ExpressionParameters
directly:
processor.Solve("x := 10");
// or explicitly through Parameters property
processor.Parameters.Variables.Add("x", 10);
Simplify:
var processor = new Processor();
processor.Solve("simplify((x) => arcsin(sin(x)))");
// or
processor.Simplify("arcsin(sin(x))");
// will return simplified expression = "x"
Differentiate:
var processor = new Processor();
processor.Solve("deriv((x) => 2x)");
// or
processor.Differentiate("2x");
// will return "2"
You can specify variable (default is "x") of differentiation:
var processor = new Processor();
processor.Differentiate("2y", Variable.Y); // will return "2"
processor.Differentiate("2x + sin(y)", new Variable("x")); // will return "2"
Performance
Processor
Version | Method | Mean | Allocated |
---|---|---|---|
3.7.3 | Parse | 39,567.9 ns | 63736 B |
4.3.0 | Parse | 10,434.04 ns | 4848 B |
3.7.3 | Solve | 55,260.0 ns | 96920 B |
4.3.0 | Solve | 15,683.42 ns | 9552 B |
License
xFunc is released under MIT License.
Thanks
Azure Pipelines
Coverlet
ReportGenerator
NUnit
NSubstitute
docfx
BenchmarkDotNet
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. |
-
net6.0
- System.Collections.Immutable (>= 8.0.0)
-
net8.0
- System.Collections.Immutable (>= 8.0.0)
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 | |
---|---|---|---|
4.4.1 | 5,910 | 12/10/2023 | |
4.4.0 | 978 | 9/13/2023 | |
4.3.0 | 257 | 8/8/2023 | |
4.2.0 | 1,147 | 7/5/2023 | |
4.1.0 | 5,404 | 5/23/2022 | |
4.0.1 | 2,169 | 4/29/2021 | |
4.0.0 | 17,399 | 1/22/2021 | |
3.7.3 | 1,561 | 10/6/2020 | |
3.7.2 | 842 | 9/4/2020 | |
3.7.1 | 3,231 | 7/21/2019 | |
3.7.0 | 958 | 6/30/2019 | |
3.6.0 | 1,363 | 4/13/2019 | |
3.5.0 | 1,478 | 2/19/2018 | |
3.4.0 | 2,494 | 2/26/2017 | |
3.3.0 | 1,515 | 12/18/2016 | |
3.2.1 | 1,561 | 12/4/2016 | |
3.2.0 | 1,527 | 12/3/2016 | |
3.1.0 | 1,572 | 10/14/2016 | |
3.0.0 | 1,813 | 7/10/2016 | |
2.15.16 | 5,471 | 5/5/2015 | |
2.15.15 | 1,775 | 11/18/2014 | |
2.15.12 | 1,529 | 6/19/2014 | |
2.15.10 | 1,458 | 6/13/2014 | |
2.15.8 | 1,408 | 6/11/2014 | |
2.15.7 | 1,456 | 5/29/2014 | |
2.15.6 | 1,462 | 5/26/2014 | |
2.15.5 | 1,448 | 5/17/2014 | |
2.15.4 | 1,462 | 5/14/2014 | |
2.14.1 | 1,482 | 5/6/2014 | |
2.13.3 | 1,579 | 5/3/2014 | |
2.13.2 | 1,497 | 4/29/2014 | |
2.13.0 | 1,423 | 4/28/2014 | |
2.12.3 | 1,464 | 4/24/2014 | |
2.12.1 | 1,481 | 4/22/2014 | |
2.12.0 | 1,625 | 4/20/2014 | |
2.11.4 | 1,564 | 4/6/2014 | |
2.11.3 | 1,534 | 3/22/2014 | |
2.11.2 | 1,544 | 2/22/2014 | |
2.11.1 | 1,520 | 2/21/2014 | |
2.11.0 | 1,539 | 2/18/2014 | |
2.10.2 | 1,513 | 11/12/2013 | |
2.10.1 | 1,489 | 11/6/2013 | |
2.10.0 | 1,465 | 11/4/2013 | |
2.9.0 | 1,500 | 11/2/2013 | |
2.8.3 | 1,493 | 10/25/2013 | |
2.8.2 | 1,447 | 10/21/2013 | |
2.8.1 | 1,453 | 10/20/2013 | |
2.7.1 | 1,490 | 10/6/2013 | |
2.7.0 | 1,503 | 10/5/2013 | |
2.5.11 | 1,459 | 9/25/2013 | |
2.5.9 | 1,508 | 9/23/2013 | |
2.5.8 | 1,437 | 9/22/2013 | |
2.5.5 | 1,465 | 9/15/2013 | |
2.5.3 | 1,497 | 9/13/2013 | |
2.5.2 | 1,484 | 9/11/2013 | |
2.4.1 | 1,541 | 8/17/2013 | |
2.3.2 | 1,778 | 7/12/2013 | |
2.3.0 | 1,744 | 6/26/2013 | |
2.2.2 | 1,589 | 6/18/2013 | |
2.2.1.1 | 1,651 | 6/13/2013 | |
2.2.1 | 1,659 | 6/13/2013 | |
2.2.0 | 1,594 | 6/8/2013 | |
2.1.1.2 | 1,512 | 4/27/2013 | |
2.1.1 | 1,682 | 4/14/2013 | |
2.1.0.4 | 1,559 | 4/3/2013 | |
2.1.0.1 | 1,584 | 3/22/2013 | |
2.0.7 | 1,644 | 3/15/2013 | |
2.0.6 | 1,601 | 3/14/2013 | |
2.0.5 | 1,613 | 3/9/2013 | |
2.0.2.7 | 1,518 | 3/2/2013 | |
2.0.2.6 | 1,528 | 2/28/2013 | |
2.0.2.3 | 1,564 | 2/17/2013 | |
2.0.2 | 1,604 | 2/9/2013 | |
2.0.0.1 | 1,525 | 2/7/2013 | |
2.0.0 | 1,575 | 2/7/2013 |