Expressions

Expressions are formed from variables and constants by using operators and functions and by combining expressions together into arrays (array expressions).

The following diagram summarizes all kinds of expressions:

Operator expressions

The CPO file format supports a variety of operators.

The following table summarizes the supported operators. Operator precedence is mostly inspired by the C programming language.

Precedence Associativity Operator Description Argument(s) Result
1 Right-to-left - Unary minus -intExpr intExpr
-floatExpr floatExpr
-cumulExpr cumulExpr
! Logical not !boolExpr boolExpr
2 Left-to-right ^ Power floatExpr ^ floatExpr floatExpr
3 Left-to-right * Multiplication intExpr * intExpr intExpr
floatExpr * floatExpr floatExpr
/ Division floatExpr / floatExpr floatExpr
div Integral division intExpr div intExpr intExpr
% Modulo (remainder) intExpr % intExpr intExpr
4 Left-to-right + Addition intExpr + intExpr intExpr
floatExpr + floatExpr floatExpr
cumulExpr + cumulExpr cumulExpr
- Subtraction intExpr - intExpr intExpr
floatExpr - floatExpr floatExpr
cumulExpr - cumulExpr floatExpr
5 Left-to-right < Less intExpr < intExpr boolExpr
> Greater intExpr > intExpr boolExpr
<= Less or equal intExpr <= intExpr boolExpr
floatExpr <= floatExpr boolExpr
cumulExpr <= uint constraint
uint <= cumulExpr constraint
cumulExpr <= intExpr constraint
intExpr <= cumulExpr constraint
>= Greater or equal intExpr >= intExpr boolExpr
intExpr >= floatExpr boolExpr
uint >= cumulExpr constraint
cumulExpr >= uint constraint
intExpr >= cumulExpr constraint
cumulExpr >= intExpr constraint
6 Left-to-right == Equal to intExpr == intExpr boolExpr
floatExpr == floatExpr boolExpr
!= Not equal to intExpr != intExpr boolExpr
=> Logical implies boolExpr => boolExpr boolExpr
7 Left-to-right && Logical and boolExpr && boolExpr boolExpr
8 Left-to-right || Logical or boolExpr || boolExpr boolExpr

Note the difference between == and = operators: The single equals sign = can be used only in statements identifier = expression;, while a double equal sign == is an operator that returns a Boolean expression.

Example


x = intVar(1..10);
y = intVar(1..10);
z = intVar(1..10);
expr1 = 2*(x + y);
expr2 = y % z;
expr1 + 2 >= expr2;

Function expressions

There are many built-in functions that return expressions, see the list of functions. The syntax to call a function follows a common standard:

There are a few exceptional functions that require extended syntax, for example intVar or intervalVar. In this case, the syntax is described together with the function.

Example


x = intVar(-10..10); // intVar is a function with special syntax
absx = abs(x);       // abs is a function returning absolute value of x