[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
3.5 Logical expressions
Logical expression is a rule for computing a single logical value, which can be either true or false.
The primary logical expression may be a numeric expression, relational expression, iterated logical expression, or another logical expression enclosed in parentheses.
Examples
i+1
(numeric expression)
a[i,j] < 1.5
(relational expression)
s[i+1,j-1] <> 'Mar' & year
(relational expression)
(i+1,'Jan') not in I cross J
(relational expression)
S union T within A[i] inter B[j]
(relational expression)
forall{i in I, j in J} a[i,j] < .5 * b
(iterated expression)
(a[i,j] < 1.5 or b[i] >= a[i,j])
(parenthesized expression)
More general logical expressions containing two or more primary logical expressions may be constructed by using certain logical operators.
Examples
not (a[i,j] < 1.5 or b[i] >= a[i,j]) and (i,j) in S (i,j) in S or (i,j) not in T diff U |
Numeric expressions
The resultant value of the primary logical expression, which is a numeric expression, is true, if the resultant value of the numeric expression is non-zero. Otherwise the resultant value of the logical expression is false.
Relational expressions
In MathProg there are the following relational operators, which may be used in logical expressions:
x < y
test on x < y
x <= y
test on x <= y
x = y, x == y
test on x = y
x >= y
test on x >= y
x <> y, x != y
test on x != y
x in Y
test on x in Y
(x1,…,xn) in Y
test on (x1,…,xn) in Y
x not in Y, x !in Y
test on x not in Y
(x1,…,xn) not in Y,
(x1,…,xn) !in Y
test on (x1,…,xn) not in Y
X within Y
test on X within Y
X not within Y, X !within Y
test on X not within Y
where x, x1, …, xn, y are numeric or symbolic expressions, X and Y are set expression.
Note:
- In the operations in, not in, and !in the number of components in the first operands must be the same as the dimension of the second operand.
- In the operations within, not within, and !within both operands must have identical dimension.
All the relational operators listed above have their conventional mathematical meaning. The resultant value is true, if the corresponding relation is satisfied for its operands, otherwise false. (Note that symbolic values are ordered lexicographically, and any numeric value precedes any symbolic value.)
Iterated expressions
Iterated logical expression is a primary logical expression, which has the following syntactic form:
iterated-operator indexing-expression integrand
where iterated-operator is the symbolic name of the iterated operator to be performed (see below), indexing expression is an indexing expression which introduces dummy indices and controls iterating, integrand is a logical expression that participates in the operation.
In MathProg there are two iterated operators, which may be used in logical expressions:
forall
A-quantification
for all (i1,…,in) in D: x(i1,…,in)
exists
E-quantification
exists (i1,…,in) in D: x(i1,…,in)
where i1, …, in are dummy indices introduced in the indexing expression, D is the domain, a set of n-tuples specified by the indexing expression which defines particular values assigned to the dummy indices on performing the iterated operation, x(i1,…,in) is the integrand, a logical expression whose resultant value depends on the dummy indices.
For A-quantification the resultant value of the iterated logical expression is true, if the value of the integrand is true for all n-tuples contained in the domain, otherwise false.
For E-quantification the resultant value of the iterated logical expression is false, if the value of the integrand is false for all n-tuples contained in the domain, otherwise true.
Parenthesized expressions
Any logical expression may be enclosed in parentheses that syntactically makes it primary logical expression.
Parentheses may be used in logical expressions, as in algebra, to specify the desired order in which operations are to be performed. Where parentheses are used, the expression within the parentheses is evaluated before the resultant value is used.
The resultant value of the parenthesized expression is the same as the value of the expression enclosed within parentheses.
Logical operators
In MathProg there are the following logical operators, which may be used in logical expressions:
not x, ! x
negation
x and y, x && y
conjunction (logical “and”)
x or y, x || y
disjunction (logical “or”)
where x and y are logical expressions.
If the expression includes more than one logical operator, all operators are performed from left to right according to the hierarchy of operations (see below).
The resultant value of the expression, which contains logical operators, is the result of applying the operators to their operands.
Hierarchy of operations
The following list shows the hierarchy of operations in logical expressions:
Operation
Hierarchy
Evaluation of numeric operations
1st-7th
Evaluation of symbolic operations
8th-9th
Evaluation of set operations
10th-14th
Relational operations (<, <=, etc.)
15th
Negation (not, !)
16th
Conjunction (and, &&)
17th
A- and E-quantification (forall, exists)
18th
Disjunction (or, ||)
19th
This hierarchy has the same meaning as explained in Section “Numeric expressions”.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |