Arithmetic Operators

Arithmetic operators work with numeric operands. LINGO has five binary (two-operand) arithmetic operators, shown here:

Operator

Interpretation

^

Exponentiation

*

Multiplication

/

Division

+

Addition

-

Subtraction

Since these are binary operators, they require two arguments—one immediately to the left of the operator and one immediately to the right.

The only unary (one-operand) arithmetic operator in LINGO is negation (-). In this case, the operator applies to the operand immediately to the right of the negation sign.

These operators should be familiar to all readers. The priority of the operators is given in the following table:

Priority Level

Operator(s)

Highest

- (negation)

 

^

 

* /

Lowest

+ -

Operators with the highest priority are evaluated first, in order from left to right. As an example, consider the expression:

 4 + 6 / 2

The division operator (/) has higher priority than the addition operator (+). Thus, it is evaluated first, leaving: 4 + 3. Evaluating the remaining addition gives a final result of 7.

The order of evaluation of the operators can be controlled with parentheses. LINGO evaluates the equation in the inner-most parentheses first and works out from there. If we recast the expression from above as:

 (4 + 6) / 2

we will now get a final result of 5, instead of 7. The 4 and 6 are added first because they appear in parentheses. The resulting sum of 10 is divided by 2, giving the final result of 5.

Note:LINGO follows the Excel convention of assigning the highest priority to the negation operator.  Given this, LINGO evaluates -3^2 as positive 9.  Some users may prefer to give the unary minus operator a lower priority so that -3^2 evaluates to minus 9.  You can do this by setting the Unary Minus Priority option to Low via the Model Generator tab of the Solver|Options command.  Once you set the unary minus operator’s priority is set to low its priority will be lower than multiplication and division, but higher than addition and subtraction.

 

Note:In the absence of parentheses, all operators of the same priority are processed from left to right.  Thus, 4^3^2 evaluates to 4096.  Be forewarned that for the exponentiation operator, "^", this differs from the convention that some mathematicians follow, namely, to have the exponentiation operator evaluated from right to left, i.e., 4^3^2 would evaluate to 262144. When in doubt, use parentheses to enforce your intentions, e.g., 4^(3^2) unambiguously evaluates to 262144.