Skip to content
Dmytro Kyshchenko edited this page Sep 28, 2020 · 37 revisions

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.

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();
processor.Parse("2 + 2"); // will return the expression tree

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

Solve:

This method will parse string expression (like Parse method) and then calculate 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("2 + 2").Result; // will return 4.0 (object)
var processor = new Processor();
processor.Solve<NumberResult>("2 + 2"); // will return 4.0 (double)

Note: The Solve method automatically simplify 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.Simplify("arcsin(sin(x))"); // will return simplified expression = "x"

Detailed simplification rules

Differentiate:

var processor = new Processor();
processor.Differentiate("2x"); // will return "2"

You can specified variable (default is "x") of differentiation:

var processor = new Processor();
processor.Differentiate("2y", new Variable("y")); // will return "2"
processor.Differentiate("2x + sin(y)", new Variable("x")); // will return "2"

Performance

Processor

Version Method Mean Allocated
3.7.2 Parse 178.9 μs 62.28 KB
4.0.0 Parse 27.69 μs 4.55 KB
3.7.2 Solve 246.2 μs 94.68 KB
4.0.0 Solve 43.09 μs 10.4 KB

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 Apache 2.0 License.

Thanks

@RonnyCSHARP

Fluent.Ribbon
Azure Pipelines
Coverlet
ReportGenerator
xUnit
Moq

More:

Clone this wiki locally