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

### 3.4 Set expressions

Set expression is a rule for computing an elemental set, i.e. a collection of n-tuples, where components of n-tuples are numeric and symbolic quantities.

The primary set expression may be a literal set, unsubscripted set, subscripted set, “arithmetic” set, indexing expression, iterated set expression, conditional set expression, or another set expression enclosed in parentheses.

Examples

 {(123,'aa'), (i,'bb'), (j-1,'cc')} (literal set) I (unsubscripted set) S[i-1,j+1] (subscripted set) 1..t-1 by 2 (“arithmetic” set) {t in 1..T, (t+1,j) in S: (t,j) in F} (indexing expression) setof{i in I, j in J}(i+1,j-1) (iterated expression) if i < j then S[i] else F diff S[j] (conditional expression) (1..10 union 21..30) (parenthesized expression)

More general set expressions containing two or more primary set expressions may be constructed by using certain set operators.

Examples

(A union B) inter (I cross J)
1..10 cross (if i < j then {'a', 'b', 'c'} else {'d', 'e', 'f'})


#### Literal sets

Literal set is a primary set expression, which has the following two syntactic forms:

$\{e_1,e_2,\dots,e_m\}$

$\{(e_{11},\dots,e_{1n}),(e_{21},\dots,e_{2n}),\dots,(e_{m1},\dots, e_{mn})\}$

where $e_1, \dots, e_m, e_{11}, \dots, e_{mn}$ are numeric or symbolic expressions.

If the first form is used, the resultant set consists of 1-tuples (singles) enumerated within the curly braces. It is allowed to specify an empty set, which has no 1-tuples.

If the second form is used, the resultant set consists of n-tuples enumerated within the curly braces, where a particular n-tuple consists of corresponding components enumerated within the parentheses. All n-tuples must have the same number of components.

#### Unsubscripted sets

If the primary set expression is an unsubscripted set (which must be 0-dimensional), the resultant set is an elemental set associated with the corresponding set object.

#### Subscripted sets

The primary set expression, which refers to a subscripted set, has the following syntactic form:

$name[i_1,i_2,\dots,i_n],$

where $name$ is the symbolic name of the set object, $i_1$, $i_2, \dots, i_n$ are subscripts.

Each subscript must be a numeric or symbolic expression. The number of subscripts in the subscript list must be the same as the dimension of the set object with which the subscript list is associated.

Actual values of subscript expressions are used to identify a particular member of the set object that determines the resultant set.

#### “Arithmetic” set

The primary set expression, which is an “arithmetic” set, has the following two syntactic forms:

$t_0$ .. $t_f$ by $\delta t$

$t_0$ .. $t_f$

where $t_0, t_1$, and $\delta t$ are numeric expressions (the value of $\delta t$ must not be zero). The second form is equivalent to the first form, where $\delta t=1$.

If $\delta t>0$, the resultant set is determined as follows:

$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_0\leq t\leq t_f)\}$

Otherwise, if $\delta t<0$, the resultant set is determined as follows:

$\{t:\exists k\in{\cal Z}(t=t_0+k\delta t,\ t_f\leq t\leq t_0)\}$

#### Indexing expressions

If the primary set expression is an indexing expression, the resultant set is determined as described in Section “Indexing expressions and dummy indices” (see above).

#### Iterated expressions

Iterated set expression is a primary set expression, which has the following syntactic form:

setof indexing-expression integrand

where indexing-expression is an indexing expression which introduces dummy indices and controls iterating, integrand is either a single numeric or symbolic expression or a list of numeric and symbolic expressions separated by commae and enclosed in parentheses.

If the integrand is a single numeric or symbolic expression, the resultant set consists of 1-tuples and is determined as follows:

$\{x:(i_1,\dots,i_n)\in\Delta\},$

where $x$ is a value of the integrand, $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.

If the integrand is a list containing m numeric and symbolic expressions, the resultant set consists of m-tuples and is determined as follows:

$\{(x_1,\dots,x_m):(i_1,\dots,i_n)\in\Delta\},$

where $x_1, \dots, x_m$ are values of the expressions in the integrand list, $i_1, \dots, i_n$ and $\Delta$ have the same meaning as above.

#### Conditional expressions

Conditional set expression is a primary set expression that has the following syntactic form:

if b then X else Y

where b is an logical expression, X and Y are set expressions, which must define sets of the same dimension.

The resultant value of the conditional expression depends on the value of the logical expression that follows the keyword if. If it takes on the value true, the resultant set is the value of the expression that follows the keyword then. Otherwise, if the logical expression takes on the value false, the resultant set is the value of the expression that follows the keyword else.

#### Parenthesized expressions

Any set expression may be enclosed in parentheses that syntactically makes it primary set expression.

Parentheses may be used in set 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.

#### Set operators

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

 X union Y union $X\cup Y$ X diff Y difference $X\backslash Y$ X symdiff Y symmetric difference $X\oplus Y$ X inter Y intersection $X\cap Y$ X cross Y cross (Cartesian) product $X\times Y$

where X and Y are set expressions, which must define sets of the identical dimension (except for the Cartesian product).

If the expression includes more than one set 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 set operators, is the result of applying the operators to their operands.

The dimension of the resultant set, i.e. the dimension of n-tuples, of which the resultant set consists of, is the same as the dimension of the operands, except the Cartesian product, where the dimension of the resultant set is the sum of dimensions of the operands.

#### Hierarchy of operations

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

 Operation Hierarchy Evaluation of numeric operations 1st-7th Evaluation of symbolic operations 8th-9th Evaluation of iterated or “arithmetic” set (setof, ..) 10th Cartesian product (cross) 11th Intersection (inter) 12th Union and difference (union, diff, symdiff) 13th Conditional evaluation (if $\dots$ then $\dots$ else) 14th

This hierarchy is used to determine which of two consecutive operations is performed first. If the first operator is higher than or equal to the second, the first operation is performed. If it is not, the second operator is compared to the third, etc. When the end of the expression is reached, all of the remaining operations are performed in the reverse order.

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