Boolean expressions return only "true" or "false". Boolean expressions are commonly used in conditional expressions to decide between two or more alternative subexpressions, but a Simile variable can have a boolean value if its whole equation is a boolean expression; indeed, condition and alarm components have to have boolean values.
The expressions "true" and "false" may be used as Boolean constants in expressions. Note that quotation marks must be used around the words. This is because these constants are implemented as built-in enumerated types.
A simple condition consists of a direct comparison between two values, using the relational operators
> |
greater than |
X > Y |
X is greater than Y |
< |
less than |
X < Y |
X is less than Y |
>= |
greater than or equal to |
X >= Y |
X is greater than or equal to Y |
<= |
less than or equal to |
X <= Y |
X is less than or equal to Y |
== |
equal to |
X == Y |
X is equal to Y |
!= |
not equal to |
X != Y |
X is not equal to Y |
Thus, the following are legal examples:
Each of the two terms, on the left and right of the comparison, can themselves be arbitrary mathematical expressions. Thus, the following are also legal:
Four Boolean operators can be used in expressions. There are "and", "or", "xor" and "not". The following table shows the two alternative forms of these operators, which can also written in symbolic form. Note also that a comma "," is accepted as an alternative symbol for "and".
A and B |
A && B |
true if and only if both A and B are true |
A or B |
A ; B |
true if either A is true or B is true |
A xor B |
A != B |
true if either A is true or B is true, but not both |
not A |
! A |
true if and only if A is not true |
The truth tables for the four operators are given here. Note that "and", "or" and "xor" require two operands, whilst "not" requires one operand. The equation parser will signal an error if an incorrect number of operands is used.
Some functions return boolean values, i.e., any(), all(), channel_is(), dies_of(), and first().
In: Contents >> Working with equations >> Components of an equation