Next: , Previous: , Up: Expressions   [Contents][Index]


4.2.5 Relational expressions

Relational expressions ( <rel_expr>s) compare two arithmetic expressions (see Arithmetic expressions) or test an arithmetic expression for a property. A relational expression can be either TRUE or FALSE.

coNCePTuaL supports a variety of relational expressions. The following is the language’s order of operations from highest to lowest precedence:

unary/
binary/
IS EVEN, IS ODD
=’, ‘<’, ‘>’, ‘<=’, ‘>=’, ‘<>’, DIVIDES, IS IN, IS NOT IN
conjunctive /\
disjunctive \/

In addition, as in most programming languages, parentheses can be used to group subexpressions.

The unary relation IS EVEN is TRUE if a given arithmetic expression represents an even number and the unary relation IS ODD is TRUE if a given arithmetic expression represents an odd number. For example, ‘456 IS EVEN is TRUE and ‘64 MOD 6 IS ODD is FALSE.

The coNCePTuaL operators ‘=’, ‘<’, ‘>’, ‘<=’, ‘>=’, and ‘<>’ represent, respectively, the mathematical relations =, <, >, <=, >=, and <> (i.e., not equal). These are all binary relations that operate on arithmetic expressions (see Arithmetic expressions). For example, ‘2+2 = 4 is TRUE and ‘2**3 > 2**4 is FALSE. The DIVIDES relation is TRUE if the first expression evenly divides the second, i.e., that e2 = 0 (mod e1). Hence, ‘2 DIVIDES 1234’ (equivalent to ‘1234 MOD 2 = 0) is TRUE while ‘2 DIVIDES 4321’ (equivalent to ‘4321 MOD 2 = 0) is FALSE.

The binary relation IS IN has the form

<expr> IS IN <range> [, <range>]*

A <range> represents a range expression. Range expressions are described in Range expressions. In short, a range expression specifies a list of values by explicit enumeration, numeric progression, or predicated combinations of other range expressions. As an example, the relational expression ‘x IS IN {1, ..., 5}’ is TRUE if and only if x is one of 1, 2, 3, 4, or 5. As a more complex example, ‘p*2 IS IN {0}, {1, 2, 4, ..., num_tasks*2}’ is TRUE if and only if twice p is either zero or a power of two less than or equal to twice the number of tasks being used.

The complementary operation to IS IN is the binary relation IS NOT IN. Hence, ‘4 IS NOT IN {3, ..., 5} ’ is FALSE while ‘6 IS NOT IN {3, ..., 5}’ is TRUE.

Conjunction (``and'') and disjunction (``or'') combine multiple relational expressions. <rel_expr> ‘/\ <rel_expr> is TRUE if and only if both <rel_expr>s are TRUE, and <rel_expr> ‘\/ <rel_expr> is TRUE if and only if either <rel_expr> is TRUE. For example, ‘456 IS EVEN \/ 2**3 > 2**4’ is TRUE and ‘456 IS EVEN /\ 2**3 > 2**4’ is FALSE. Conjunction and disjunction are both short-circuiting operations. Evaluation proceeds left-to-right. Expressions such as ‘x<>0 /\ 1/x=1’ will therefore not result in a divide-by-zero error.

coNCePTuaL does not currently have a logical negation operator.


Next: , Previous: , Up: Expressions   [Contents][Index]

Scott Pakin, pakin@lanl.gov