math_expressions library
A math library for parsing and evaluating expressions in real, interval and vector contexts. It also supports simplification and differentiation of expressions.
The libary supports the three basic data types Number, Interval and Vector. It includes the GrammarParser to create Expressions from string inputs.
For backwards-compatibility the legacy ShuntingYardParser is also included. Users are encouraged to switch to GrammarParser as it will not receive new features and bug fixes.
Classes
- Abs
- The absolute value function.
- Acos
- The arcus cosine function.
- AlgorithmicFunction
- Asin
- The arcus sine function.
- Atan
- The arcus tangens function.
- BinaryOperator
- A binary operator takes two expressions and performs an operation on them.
- BoundVariable
- A bound variable is an anonymous variable, e.g. a variable without name, which is bound to an expression.
- Ceil
- The ceil function.
- CompositeFunction
- A composition of two given MathFunctions.
- ContextModel
- The context model keeps track of all known variables and functions.
- Cos
-
The cosine function. Expects input in
radians
. - CustomFunction
- A user-defined MathFunction with an arbitrary expression.
- DefaultFunction
- A default function is predefined in this library. It contains no expression because the appropriate evaluation method usually uses native Dart math code.
- Divide
- The divide operator performs a division.
- Exponential
- The exponential function.
- Expression
- Any Expression supports basic mathematical operations like addition, subtraction, multiplication, division, power and negate.
-
ExpressionEvaluator<
T> - ExpressionParser
- The Parser creates a mathematical Expression from a given input string.
-
ExpressionVisitor<
T> - The visitor interface for the abstract syntax tree (AST) of an Expression.
- Factorial
- simple factorial function might be expanded to the Gamma function to allow negative and complex numbers and deriving
- Floor
- The floor function.
- GrammarParser
- This parser uses a grammar-based approach to parse the input and build the expression.
- Interval
- An Interval is defined by its minimum and maximum values, where min <= max.
- IntervalEvaluator
- IntervalLiteral
- An interval literal.
- Lexer
- The lexer creates tokens (see TokenType and Token) from an input string. The input string is expected to be in infix notation form. The lexer can convert an infix stream into a postfix stream (Reverse Polish Notation) for further processing by a ShuntingYardParser.
- Literal
- A literal can be a number, a constant or a variable.
- Ln
- The natural logarithm (log based e).
- Log
- The logarithm function.
- MathFunction
- A function with an arbitrary number of arguments.
- Minus
- The minus operator performs a subtraction.
- Modulo
- The modulo operator performs a Euclidean modulo operation, as Dart performs it. That is, a % b = a - floor(a / |b|) |b|. For positive integers, this is a remainder.
- NullExpressionVisitor
- Default ("null") implementation of the expression visitor.
- Number
- A number is a constant number literal.
- ParserOptions
- ParserOptions can be used to customise the behaviour of an ExpressionParser.
- Plus
- The plus operator performs an addition.
- Point3
- A point in 3-dimensional space, which is a Vector3. This implementation supplies common mathematical operations on points.
- Power
- The power operator.
- RealEvaluator
- An evaluator for real numbers as per EvaluationType.REAL.
- Root
- The n-th root function. n needs to be a natural number.
- Sgn
- The sign function.
- ShuntingYardParser
- The ShuntingYardParser uses a Lexer to tokenise the input into a RPN token stream, and then builds the expression using the Shunting-yard algorithm.
- Sin
-
The sine function. Expects input in
radians
. - Sqrt
- The square root function. A specialisation of Root.
-
Stack<
E> - Implementation of a stack interface on top of a list.
- Tan
-
The tangens function. Expects input in
radians
. - Times
- The times operator performs a multiplication.
- Token
- A Token consists of text and has a TokenType.
- TokenType
- A token type. Access token types via the static fields.
- UnaryMinus
- The unary minus negates its argument.
- UnaryOperator
- A unary operator takes one argument and performs an operation on it.
- UnaryPlus
- Variable
- A variable is a named literal.
- VariableCollector
- An expression visitor that collects all variables in an expression.
- Vector
- A vector of arbitrary size.
- VectorEvaluator
- The vector evaluator can operate on mixed datatypes, so is typed less strict. The underlying data types could be Vector2, Vector3, Vector4 and double (scalars).
Enums
- EvaluationType
- Mathematical expressions must be evaluated under a certain EvaluationType.
Typedefs
- Parser = ShuntingYardParser
- The default parser. This type alias is deprecated, use GrammarParser or the legacy ShuntingYardParser instead.