sealed class Expression : TreeNode<Expression>
Arithmetic expressions which are used in the Formula.Numeric proposition.
They support standard arithmetic operations (+, -, *, /), floating point literals and variables. Note that any unresolved variables are expected to be resolved "at runtime", meaning they are considered to be a part of the model.
Note that each expressions is either Binary or a constant or a variable.
Add |
data class Add : Expression, Binary<Add, Expression>
Addition: A + B |
Constant |
data class Constant : Expression
A floating point constant. Scientific notation (2.3e10) is not supported. |
Div |
data class Div : Expression, Binary<Div, Expression>
Division: A / B |
Mul |
data class Mul : Expression, Binary<Mul, Expression>
Multiplication: A * B |
Sub |
data class Sub : Expression, Binary<Sub, Expression>
Subtraction: A - B |
Variable |
data class Variable : Expression
A variable name. If there is an existing alias with this name, it will be substituted. Otherwise is considered to be a model variable. |
node |
open val node: Expression
Expression is also the node in the tree, so |
toString |
open fun toString(): String
Return string which uniquely represents this expression and can be parsed to create an equivalent object. |
div |
operator infix fun Expression.div(other: Expression): Div
Create division from two expressions. |
eq |
infix fun Expression.eq(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.EQ. |
fold |
fun <Tree : TreeNode<Tree>, R> TreeNode<Tree>.fold(atom: Tree.() -> R, unary: Unary<*, Tree>.(R) -> R, binary: Binary<*, Tree>.(R, R) -> R): R
Standard tree fold. You can provide transformation operations for atoms, unary and binary nodes. |
ge |
infix fun Expression.ge(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.GE. |
gt |
infix fun Expression.gt(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.GT. |
le |
infix fun Expression.le(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.LE. |
lt |
infix fun Expression.lt(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.LT. |
map |
fun <Tree : TreeNode<Tree>> TreeNode<Tree>.map(atom: Tree.() -> Tree = { this }, unary: Unary<Tree, Tree>.(Tree) -> Tree = { this.copy(inner = it) }, binary: Binary<Tree, Tree>.(Tree, Tree) -> Tree = { left, right -> this.copy(left, right)}): Tree
Change tree structure while preserving tree type. You can provide transformation operations for atoms, unary and binary nodes. The only requirement is that operations don't change the type of the tree. |
minus |
operator infix fun Expression.minus(other: Expression): Sub
Create subtraction from two expressions. |
neq |
infix fun Expression.neq(other: Expression): Numeric
Create Formula.Numeric proposition by comparing two expressions using the CompareOp.NEQ. |
plus |
operator infix fun Expression.plus(other: Expression): Add
Create addition from two expressions. |
times |
operator infix fun Expression.times(other: Expression): Mul
Create multiplication from two expressions. |
Add |
data class Add : Expression, Binary<Add, Expression>
Addition: A + B |
Constant |
data class Constant : Expression
A floating point constant. Scientific notation (2.3e10) is not supported. |
Div |
data class Div : Expression, Binary<Div, Expression>
Division: A / B |
Mul |
data class Mul : Expression, Binary<Mul, Expression>
Multiplication: A * B |
Sub |
data class Sub : Expression, Binary<Sub, Expression>
Subtraction: A - B |
Variable |
data class Variable : Expression
A variable name. If there is an existing alias with this name, it will be substituted. Otherwise is considered to be a model variable. |