Previous: Aggregate functions, Up: 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/ ternary |
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 ternary relation IS IN
has the form
‘<expr>
IS IN
[<expr>, <expr>]’. The relational
expression ‘x IS
IN
[a, b]
’ is true
if x lies within the closed interval [a, b] and false otherwise. The interval bounds a and b can be
specified in any order. Hence, ‘x
IS IN
[a, b]’ can be more
precisely described as “(a <= x <= b) or (b <= x
<= a)”. To provide a few examples,
‘4 IS IN [3,5]
’ and ‘4 IS IN [5,3]’ are both
true; ‘5 IS
IN [3,5]’ is true; however, ‘6 IS IN
[3,5]’ is false. The complementary operation to IS IN
is
the ternary 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.
Scott Pakin, pakin@lanl.gov