Previous: , Up: Expressions   [Contents]

### 3.6 Linear expressions

Linear expression is a rule for computing so called linear form or simply formula, which is a linear (or affine) function of elemental variables.

The primary linear expression may be an unsubscripted variable, subscripted variable, iterated linear expression, conditional linear expression, or another linear expression enclosed in parentheses.

It is also allowed to use a numeric expression as the primary linear expression, in which case the resultant value of the numeric expression is automatically converted to the formula that includes the only constant term.

Examples

 z (unsubscripted variable) x[i,j] (subscripted variable) sum{j in J} (a[i] * x[i,j] + 3 * y) (iterated expression) if i in I then x[i,j] else 1.5 * z + 3 (conditional expression) (a[i,j] * x[i,j] + y[i-1] + .1) (parenthesized expression)

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

Examples

2 * x[i-1,j+1] + 3.5 * y[k] + .5 * z
(- x[i,j] + 3.5 * y[k]) / sum{t in T} abs(d[i,j,t])

#### Unsubscripted variables

If the primary linear expression is an unsubscripted variable (which must be 0-dimensional), the resultant formula is that unsubscripted variable.

#### Subscripted variables

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

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

where $name$ is the symbolic name of the variable, $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 variable with which the subscript list is associated.

Actual values of subscript expressions are used to identify a particular member of the model variable that determines the resultant formula, which is an elemental variable associated with the corresponding member.

#### Iterated expressions

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

sum indexing-expression integrand

where indexing-expression is an indexing expression which introduces dummy indices and controls iterating, integrand is a linear expression that participates in the operation.

The iterated linear expression is evaluated exactly in the same way as the iterated numeric expression (see Section “Numeric expressions” above) with the exception that the integrand participated in the summation is a formula, not a numeric value.

#### Conditional expressions

Conditional linear expression is a primary linear expression, which has one of the following two syntactic forms:

if b then f else g

if b then f

where b is an logical expression, f and g are linear expressions.

The conditional linear expression is evaluated exactly in the same way as the conditional numeric expression (see Section “Numeric expressions” above) with the exception that operands participated in the operation are formulae, not numeric values.

#### Parenthesized expressions

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

Parentheses may be used in linear 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 formula is used.

The resultant value of the parenthesized expression is the same as the value of the expression enclosed within parentheses.

#### Arithmetic operators

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

 + f unary plus - f unary minus f + g addition f - g subtraction x * f, f * x multiplication f / x division

where f and g are linear expressions, x is a numeric expression (more precisely, a linear expression containing the constant term only).

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

#### Hierarchy of operations

The hierarchy of arithmetic operations used in linear expressions is the same as for numeric expressions (for details see Section “Numeric expressions” above).

Previous: , Up: Expressions   [Contents]