[ < ] | [ > ] | [ << ] | [ 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<ytest on

x<y

x<=ytest on

x<=y

x=y,x==ytest on

x=y

x>=ytest on

x>=y

x<>y,x!=ytest on

x!=y

xinYtest on

xinY(

x1,…,xn)inYtest on (

x1,…,xn) inY

xnot inY,x!inYtest on

xnot inY(

x1,…,xn)not inY,(

x1,…,xn)!inYtest on (

x1,…,xn) not inY

XwithinYtest on

XwithinY

Xnot withinY,X!withinYtest on

Xnot withinY

where *x*,
*x*1, …, *xn*,
*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 expressions

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:

forallA-quantification

for all (

i1,…,in) in D:x(i1,…,in)

existsE-quantification

exists (

i1,…,in) in D:x(i1,…,in)

where
*i*1, …, *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*(*i*1,…,*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:

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.

### Hierarchy of operations

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

Operation

HierarchyEvaluation 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] | [ ? ] |