Click or drag to resize
Accord.NET (logo)

PolishExpression Class

Evaluator of expressions written in reverse polish notation.
Inheritance Hierarchy
SystemObject
  AccordPolishExpression

Namespace:  Accord
Assembly:  Accord (in Accord.dll) Version: 3.8.0
Syntax
public static class PolishExpression
Request Example View Source

The PolishExpression type exposes the following members.

Methods
  NameDescription
Public methodStatic memberEvaluate
Evaluates specified expression.
Top
Remarks

The class evaluates expressions writen in reverse postfix polish notation.

The list of supported functuins is:

  • Arithmetic functions: +, -, *, /;
  • sin - sine;
  • cos - cosine;
  • ln - natural logarithm;
  • exp - exponent;
  • sqrt - square root.

Arguments for these functions could be as usual constants, written as numbers, as variables, writen as $<var_number> ($2, for example). The variable number is zero based index of variables array.

Sample usage:

// expression written in polish notation
string expression = "2 $0 / 3 $1 * +";
// variables for the expression
double[] vars = new double[] { 3, 4 };
// expression evaluation
double result = PolishExpression.Evaluate( expression, vars );
See Also