Fk.xFunc.Maths 4.1.0

dotnet add package Fk.xFunc.Maths --version 4.1.0
NuGet\Install-Package Fk.xFunc.Maths -Version 4.1.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="Fk.xFunc.Maths" Version="4.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Fk.xFunc.Maths --version 4.1.0
#r "nuget: Fk.xFunc.Maths, 4.1.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.
// Install Fk.xFunc.Maths as a Cake Addin
#addin nuget:?package=Fk.xFunc.Maths&version=4.1.0

// Install Fk.xFunc.Maths as a Cake Tool
#tool nuget:?package=Fk.xFunc.Maths&version=4.1.0

Master: Build Status codecov
Dev: Build Status codecov
xFunc.Maths: NuGet Downloads
xFunc.DotnetTool: NuGet

xFunc

xFunc is a simple and easy to use application that allows you to build mathematical and logical expressions. It's written on C#. The library includes well-documented code that allows developers to parse strings to expression tree, to analyze (derivate, simplify) expressions by using lexer, parser and etc.

xFunc is a small-sized and portable application that you can use to create complex mathematical expressions which will be automatically computed. It can be used by teachers and students alike.

Note: The WPF application (xFunc UI) was migrated to a separate repository xFunc.UI.

Features:

  • Calculating expressions (supported functions and operations);
  • Supporting measures of angles;
  • Derivative and simplifying expressions;
  • Plotting graphs;
  • Truth tables;
  • Supported Framework: .NET Standard 2.1+;

Usage

The main class of xFunc library is Processor.

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 varible 'x'
var parameters = new ParameterCollection
{
    { "x", 10 }
};
var result = exp.Execute(parameters);

// result will be equal to 12

Note: The Parse method won't simplify expression automatically, it will return the complete representation of provided string expression.

Solve:

This method parses string expression (like Parse method) and then calculates it (returns object which implements IResult interface).

There is two overloads of this method (common and generic). The common returns just IResult (you can access result by Result property). The generic allows to return specific implementation of IResult (eg. NumberResult).

var processor = new Processor();
processor.Solve<NumberResult>("2 + 2"); // will return 4.0 (double)

// or

processor.Solve("2 + 2").Result; // will return 4.0 (object)

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 throught Parameters property

processor.Parameters.Variables.Add("x", 10);

Note: The Solve method automatically simplifies expression, to control this behavior you can use simplify argument. It's useful for differentiation, because it will eliminate unnecessary expression nodes.

Simplify:

var processor = new Processor();

processor.Solve<ExpressionResult>("simplify(arcsin(sin(x)))");
// or
processor.Simplify("arcsin(sin(x))");
// will return simplified expression = "x"

Detailed simplification rules

Differentiate:

var processor = new Processor();

processor.Solve<ExpressionResult>("deriv(2x)");
// or
processor.Differentiate("2x");
// will return "2"

You can specified 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 166,581.4 ns 63770 B
4.0.0 Parse 24,604.93 ns 4760 B
3.7.3 Solve 232,498.0 ns 96952 B
4.0.0 Solve 39,971.82 ns 10673 B

More details

Bug Tracker

Please, if you have a bug or a feature request, create a new issue. Before creating any issue, please search for existing issues.

License

xFunc is released under MIT License.

Thanks

@RonnyCSHARP

Fluent.Ribbon
Azure Pipelines
Coverlet
ReportGenerator
xUnit
Moq

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.1.0 273 10/10/2022