 Corticon Studio: Rule Modeling Guide : Rules containing calculations and equations : Operator precedence and order of evaluation

# Operator precedence and order of evaluation

Operator precedence -- the order in which Corticon Studio evaluates multiple operators in an equation -- is described in the following table (also in the Rule Language Guide. This table specifies for example, that 2*3+4 evaluates to 10 and not 14 because the multiplication operator * has a higher precedence than the addition operator +. It is a good practice, however, to include clarifying parentheses even when Corticon Studio does not require it. This equation would be better expressed as (2*3)+4. Note the addition of parentheses here does not change the result. When expressed as  2*(3+4), however, the result becomes 14.
The precedence of operators affects the grouping and evaluation of expressions. Expressions with higher-precedence operators are evaluated first. Where several operators have equal precedence, they are evaluated from left to right. The following table summarizes Corticon's Rule Operator precedence and their order of evaluation .
 Operator precedence Operator Operator Name Example 1 ( ) Parenthetic expression (5.5 / 10) 2 - Unary negative -10 not Boolean test not 10 3 * Arithmetic: Multiplication 5.5 * 10 / Arithmetic: Division 5.5 / 10 ** Arithmetic: Exponentiation (Powers and Roots) 5 ** 225 ** 0.5125 ** (1.0/3.0) 4 + Arithmetic: Addition 5.5 + 10 - Arithmetic: Subtraction 10.0 – 5.5 5 < Relational: Less Than 5.5 < 10 <= Relational: Less Than Or Equal To 5.5 <= 5.5 > Relational: Greater Than 10 > 5.5 >= Relational: Greater Than Or Equal To 10 >= 10 = Relational: Equal 5.5=5.5 <> Relational: Not Equal 5.5 <> 10 6 (expression, expression) Logical: AND (>5.5,<10) (expression or expression) Logical: OR (<5.5 or >10)
Note: While expressions within parentheses that are separated by logical AND / OR operators are valid, the component expressions are not evaluated individually when testing for completeness, and might cause unintended side effects during rule execution. Best practice within a Corticon Rulesheet is to represent AND conditions as separate condition rows and OR conditions as separate rules -- doing so allows you to get the full benefit of Corticon’s logical analysis.
Note: It is recommended that you place arithmetic exponentiation expressions in parentheses.