Table of Contents

Class Processor

Namespace
xFunc.Maths
Assembly
xFunc.Maths.dll

The main point of this library. Brings together all features.

public class Processor
Inheritance
Processor
Inherited Members

Examples

To parse the function to expression tree:

var processor = new Processor();
var exp = processor.Parse("2 + x");

To evaluate the function:

var processor = new Processor();
var result = processor.Solve("2 + 2");

To simplify the expression:

var processor = new Processor();
var result = processor.Solve("simplify((x) => arcsin(sin(x)))");

To differentiate the expression:

var processor = new Processor();
var result = processor.Solve("deriv((x) => 2x)");

Constructors

Processor()

Initializes a new instance of the Processor class.

public Processor()

Remarks

Initializes default instance of Processor with default implementation of all dependencies. If you can change them, please, see other overloads of this constructor.

Processor(ISimplifier, IDifferentiator)

Initializes a new instance of the Processor class.

public Processor(ISimplifier simplifier, IDifferentiator differentiator)

Parameters

simplifier ISimplifier

The simplifier.

differentiator IDifferentiator

The differentiator.

See Also

Processor(ISimplifier, IDifferentiator, IConverter, ITypeAnalyzer, ExpressionParameters)

Initializes a new instance of the Processor class.

public Processor(ISimplifier simplifier, IDifferentiator differentiator, IConverter converter, ITypeAnalyzer typeAnalyzer, ExpressionParameters parameters)

Parameters

simplifier ISimplifier

The simplifier.

differentiator IDifferentiator

The differentiator.

converter IConverter

The converter.

typeAnalyzer ITypeAnalyzer

The type analyzer.

parameters ExpressionParameters

The collection of parameters.

Exceptions

ArgumentNullException

Thrown when one of parameters is null.

See Also

Properties

Parameters

Gets expression parameters object.

public ExpressionParameters Parameters { get; }

Property Value

ExpressionParameters

The expression parameters object.

See Also

Methods

Differentiate(string)

Differentiates the specified expression.

public IExpression Differentiate(string function)

Parameters

function string

The function.

Returns

IExpression

Returns the derivative.

Examples

var processor = new Processor();
var result = processor.Differentiate("x ^ 2");

Remarks

This method delegates the actual implementation of differentiation of expression to IDifferentiator.

See Also

Differentiate(IExpression)

Differentiates the specified expression.

public IExpression Differentiate(IExpression expression)

Parameters

expression IExpression

The expression.

Returns

IExpression

Returns the derivative.

Examples

var processor = new Processor();
var exp = processor.Parse("x ^ 2");
var result = processor.Differentiate(exp);

Remarks

This method delegates the actual implementation of differentiation of expression to IDifferentiator.

See Also

Differentiate(IExpression, Variable)

Differentiates the specified expression.

public IExpression Differentiate(IExpression expression, Variable variable)

Parameters

expression IExpression

The expression.

variable Variable

The variable.

Returns

IExpression

Returns the derivative.

Remarks

This method delegates the actual implementation of differentiation of expression to IDifferentiator.

See Also

Parse(string)

Parses the specified function.

public IExpression Parse(string function)

Parameters

function string

The function.

Returns

IExpression

The parsed expression.

Examples

var processor = new Processor();
var exp = processor.Parse("sin(x)");

Exceptions

ArgumentNullException

function is null or empty.

ParseException

Error while parsing.

TokenizeException

Throw when the lexer encounters the unsupported symbol.

See Also

Simplify(string)

Simplifies the function.

public IExpression Simplify(string function)

Parameters

function string

The function.

Returns

IExpression

The simplified expression.

Examples

var processor = new Processor();
var result = processor.Simplify("arcsin(sin(x))");

Remarks

This method delegates the actual implementation of simplification of expression to ISimplifier.

See Also

Simplify(IExpression)

Simplifies the expression.

public IExpression Simplify(IExpression expression)

Parameters

expression IExpression

A expression to simplify.

Returns

IExpression

A simplified expression.

Examples

var processor = new Processor();
var exp = processor.Parse("arcsin(sin(x))");
var result = processor.Simplify(exp);

Remarks

This method delegates the actual implementation of simplification of expression to ISimplifier.

See Also

Solve(string)

Evaluates the specified expression.

public Result Solve(string expression)

Parameters

expression string

The expression.

Returns

Result

The result of evaluation.

Examples

var processor = new Processor();
var result = processor.Solve("2 + 2");

Remarks

If your expression contains any parameter or user-defined function, then they will be resolved from the built-in Parameters collection.

See Also