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


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 < ytest on x < y
x <= ytest on $x\leq y$
x = y, x == ytest on x = y
x >= ytest on $x\geq y$
x <> y, x != ytest on $x\neq y$
x in Ytest on $x\in Y$
$(x_1,\dots,x_n)$ in $Y$test on $(x_1,\dots,x_n)\in Y$
x not in Y, x !in Ytest on $x\not\in Y$
$(x_1,\dots,x_n)$ not in $Y$, $(x_1,\dots,x_n)$ !in $Y$test on $(x_1,\dots,x_n)\not\in Y$
X within Ytest on $X\subseteq Y$
X not within Y, X !within Ytest on $X\not\subseteq Y$

where x, $x_1, \dots, x_n$, y are numeric or symbolic expressions, X and Y are set expression.

Note:

  1. 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.
  2. 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$\forall$-quantification$\forall(i_1,\dots,i_n)_{\in\Delta}[x(i_1,\dots,i_n)]$
exists$\exists$-quantification$\exists(i_1,\dots,i_n)_{\in\Delta}[x(i_1,\dots,i_n)]$

where $i_1, \dots, i_n$ are dummy indices introduced in the indexing expression, $\Delta$ 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(i_1,\dots,i_n)$ is the integrand, a logical expression whose resultant value depends on the dummy indices.

For $\forall$-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 $\exists$-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, ! xnegation
x and y, x && yconjunction (logical “and”)
x or y, x || ydisjunction (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:

OperationHierarchy
Evaluation of numeric operations1st-7th
Evaluation of symbolic operations8th-9th
Evaluation of set operations10th-14th
Relational operations (<, <=, etc.)15th
Negation (not, !)16th
Conjunction (and, &&)17th
$\forall$- and $\exists$-quantification (forall, exists)18th
Disjunction (or, ||)19th

This hierarchy has the same meaning as explained in Section “Numeric expressions”.


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