Next: Linear expressions, Previous: Set expressions, Up: Expressions [Contents]

*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

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*.

In MathProg there are the following relational operators, which may be used in logical expressions:

x<ytest on x<yx<=ytest on $x\leq y$ x=y,x==ytest on x=yx>=ytest on $x\geq y$ x<>y,x!=ytest on $x\neq y$ xinYtest on $x\in Y$ $(x_1,\dots,x_n)$ in$Y$test on $(x_1,\dots,x_n)\in Y$ xnot inY,x!inYtest 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$ XwithinYtest on $X\subseteq Y$ Xnot withinY,X!withinYtest 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:*

- In the operations
in,not in, and!inthe 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!withinboth 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 logical expression is a primary logical expression, which has the following syntactic form:

iterated-operatorindexing-expressionintegrand

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*.

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.

In MathProg there are the following logical operators, which may be used in logical expressions:

notx,!xnegation xandy,x&&yconjunction (logical “and”) xory,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.

The following list shows the hierarchy of operations in logical expressions:

OperationHierarchyEvaluation 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 $\forall$- and $\exists$-quantification ( forall,exists)18th Disjunction ( or,||)19th

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

Next: Linear expressions, Previous: Set expressions, Up: Expressions [Contents]