























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























Abstract This paper explains indexing notation in mathematics and its implementation in the modeling language LPL. Indexing is one of the most fundamental concept in mathematical notation. It is extremely powerful and allows the modeler to concisely formulate large and complex mathematical model. A certain number of exercises are given and implemented in LPL, so the reader can test the concepts. In my experience, many students fail to create or even read mathematical models, because they didn't learn correctly how to use indexing notation. It is not particularly dicult and it can be learnt easily. Unfortunately, in most mathematical modeling textbook this is badly neglected. Hopefully, this paper can remedy decit.
... etc....
The etc. means that we have to continue writing as many lines as we have prot centers, there may be dozens a rather boring task! There is, however, a much more economical way in mathematics to represent all these expressions in one single statement. It is the indexed notation. To formulate them, we rst introduce a set: the set I of all prot centers:
I = {center 1 , center 2 ,... }
here again the .. . means that we continue writing all centers in a list. Often a short name form is used as follows:
I = { 1... n} where n ∈ IN+
In the previous set denition we just mean that there are n centers, n being a positive number. We are not concerned right now of how many centers there are, we just say n it can be 5 or 1000. Of course, in a concrete context we must specify the number n, but it is part of the data of that specic context. In a second step, we introduce symbols for all prots, revenues and costs. Now, instead of using each time a new symbol, we just attach an subscript to the symbols: zi, xi, yi to express the fact that they mean the prot, the revenue and the cost of the i-th center, together with the notation i ∈ I, which means that i just designates an arbitrary (i-th) element in I. Hence, All data can be written in a concise way as follows:
xi, yi, zi where i ∈ I Mathematically speaking, three vectors are declared to represent all data. The list of expression then can be written in a single statement as follows:
zi = xi − yi with i ∈ I
This notation is in fact nothing else than an economical way of the following n expressions:
z 1 = x 1 − y 1 z 2 = x 2 − y 2
... zn = xn − yn
where n is some positive integer.
In a similar way, we can concisely build an expression that sums all prots, for instance. For this purpose we use the mathematical operator
, the Greek sigma symbol. The total prot p of all prot centers can be formulated as follows:
p =
i∈I
zi
Again, this formmula is nothing else than a shortcut for the long expression: p = z 1 + z 2 + · · · + zn After this introductory example, this paper presents now a more precise way, on how the indexed notation is dened and how it can be used in modeling.
2 Denitions and Notations
Index sets are essential for mastering the complexity of large models. All elements in a model, such as variables, parameters, and constraints as will be shown later on can appear in groups, in the same way they are indexed in mathematical notation. The convention in algebraic notation to denote a set of similar expressions is to use indexes and index sets. For example, a summation of n (numerical) terms
a 1 + a 2 + · · · + an− 1 + an (1) is commonly abbreviated using the notation
∑^ n
i=
ai (2)
The expression (1) is called three-dots notation and expression (2) is called sigma- notation. Both expression are equivalent, but (2) is much shorter and more general. The later was introduced by Joseph Fourier in 1820, according to [1, p. 22]. There exist dierent variants of expression (2) :
∑
1 ≤i≤n
ai ,
∑^ n
i=
ai ,
i∈{ 1 ...n}
ai ,
i∈I
ai with I = { 1... n} (3)
All four expressions in (3) are equivalent and they have all their advantages and disadvantages. The last notation in (3) is more general, because the index set I can be an arbitrary set dened outside the summation expression.
Before we generalize the indexed notation, let us give some examples with the sigma form. A notation
i=1 xi^ means that^ i^ is replaced by whole numbers starting with^1 until the number 5 is reached. Thus
∑^4
i=
xi = x 2 + x 3 + x 4
and
∑^5
i=
xi = x 2 + x 3 + x 4 + x 5
Hence, the notation
∑n i=1 tells us:
For the sigma notation we have three important transformation rules:
Rule 1: if c is a constant, then:
∑^ n
i=
cxi = c
∑^ n
i=
xi
Rule 2: if c is a constant, then:
∑^ n
i=
c = nc
Rule 3: Adding the term can be distributed:
∑^ n
i=
(xi + yi) =
∑^ n
i=
xi +
∑^ n
i=
yi
Proof:
∑^ n
i=
cxi = cx 1 + cx 2 +... + cxn− 1 + cxn
= c · (x 1 + x 2 +... + xn− 1 + xn) = c ·
∑^ n
i=
xi
∑n
i=
c = c︸ + c +︷︷... + c︸ n−times
= n × c = nc
∑^ n
i=
(xi + yi) = (x 1 + y 1 ) +... + (xn + yn)
= (x 1 +... + xn) + (y 1 +... + yn) =
∑^ n
i=
xi +
∑^ n
i=
yi
End of proof
More formally, an expression written in indexed notation can be noted as follows:
⊙
i∈I
Ei (4)
It consists of the following elements:
. This operator can be any associative and commutative operator, such as
(summation), for example.
(1) The index operator: It is clear why the index operator must be commutative and associative: A mathematical set is unordered and its elements can be traversed in any order. As an example, the
does not specify in which order the indexed expressions Ei are added up. Various operators fulll these requirements. Besides the addition, repre- sented by the operator
, the following index operators are commonly used (examples will be given later on):
The product (multiplication)
: The indexed expressions are multiplied.
The Max (Min) operator, written as maxi∈I (mini∈I ): They return the largest (small- est) indexed expression in the list.
In Boolean logical expressions we use the AND- and OR-operators (
): They check whether all indexed expressions are true or at least one is true.
An particular index operator is the list operator
. It is used to list indexed expres- sions (see later on).
(2) The index set: In the simplest case, the elements of the index set are integers, as in :
I = { 1 ,... , n}, where n > 0 However, they can also be identiers (symbolic names), strings or any other items and even sets representing elements of a set. In the following index set I with the four elements are identiers :
J = { spring , summer , autumn , winter }
Ordering: Sets are unordered in mathematics as mentioned above. In modeling environ- ments, however, we often must impose a specic order, for example, if a set consists of a number of time periods or time points. Then the natural order is the sequence of these periods. For example, the weekdays:
K = { Mon, Tue, Wen , Thu, Fri, Sat, Son } Example: Suppose that ai is the quantity of sells in time period i ∈ I. To know the dierence di from one time period to the next, we might use the expression:
di = ai+1 − ai forall k ∈ { 1 ,... , n − 1 }
(Note that the last value dn is not dened!). In modeling, the order of index sets is important in such a context, because we often need to refer to the previous, the next, the last or the rst period in an indexed
in the indexed expression which must have the same spelling as the active index. The term i ∈ I, consisting of the active index and the index set, is called an indexing term. The active index and the passive index are used as place-holders to dene a bijective mapping between the index set and a set of indexed expressions. Each element i in the index set maps to an indexed expression by replacing the passive index with the corre- sponding element i in the index set. This mapping is called the index mechanism. In fact,
it denes the (bijective) function f : i f −→ Ei with i ∈ I. This mapping supposes that the corresponding indexed expressions Ei exist. The domain of this function f contains the elements of the index set { 1 , 2 ,... , n}, and the codomain (or the range) is the set of indexed expressions {E 1 , E 2 ,... , En}.
(4) The index expression: The indexed expression is an arbitrary expression. It is not necessary that it contains a passive index. For example, in the expression:
∑
i∈I
3 with I = { 1 ,... , n}
the indexed expression is just 3. The whole expression then reduces simply to:
n−times
= 3 · n
The indexed expression can also be reduced to a passive index as in:
∑
i∈I
i with I = { 1 ,... , n}
in which case the indexed expression is just i. The whole expression reduces to:
1 + 2 +... + n
The indexed expression can itself contain index operators. For example:
∑
i∈I
j∈J
Fi,j
forall I = { 1 ,... , n}, J = { 1 ,... , m}
In this case, the expression rst expands to:
∑
i∈I
(Fi, 1 + Fi, 2 + · · · + Fi,m) forall I = { 1 ,... , n}
Finally, the outer sum is applied to get the expression
F 1 , 1 + F 1 , 2 + · · · + F 1 ,m + F 2 , 1 + F 2 , 2 +... · · · + Fn,m
Denition: An indexed notation is a formula expressing the fact that the index operator is applied to the set of indexed expressions constructed by the index mechanism., that is, a bijective mapping between the elements of the index set and the indexed expressions.
The general expression of aa indexed notation is given by the following notation as seen before: (^) ⊙
i∈I
Ei
This is really the most general notation, no further concepts are needed to write more complex index notations. This will be shown now by studying several extensions, which all can be reduced to this simple form.
2.3.1 A list of (indexed) expressions
A list of expressions is normally written as follows:
zi = xi − yi forall i ∈ I
This notation is very common. It says that the equations zi = xi − yi has to be repeated as many times as I has elements. However, this notation could be transformed into the general indexed notation by using the list operator as follows:
∧^. i∈I (zi = xi − yi)
The index operator is the
-operator. The meaning of this operator is to list all indexed expressions. In this case, the indexed expression is normally an equation or an assignment, hence the side eect of this operator is to assign a list of values. Of course, in a mathematical text the rst notation is preferred, because it is so common. However, this example shows that it can really be seen as an indexed notation. This fact will be important in the context of modeling languages later on, because we can use the same syntax to specify a list of expressions. To express it, we only need to use the list operator instead of any other index operator, as for instance the sigma operator.
2.3.2 Index Sets as Expressions
In many situations, the index set is not simply an explicit list of elements, as in I = { 1 ,... , n}. Of course, any set expression can be used to construct the index set I. Hence, I could be the union or the intersection of other sets as in the following expression:
I = J ∪ K or I = J ∩ K
This kind of modication does not change anything for the indexed notation. It is imma- terial, how the index set is constructed. Sometimes, however, we construct I as a subset of another set, say J, such that I ⊆ J, and we use the notation:
I = {j ∈ J | P (j)}
where P (j) is a property about j ∈ J that is either true or false. The notation means: for all j ∈ J such that P (j) is true. Clearly, if P (j) is true for all elements in J then the two sets are equal (I = J). However, normally P (j) expresses a property that is true only for a proper subset of J. Using I in an indexed notation, we could write:
In the rst expression k^2 ≤ 100 is only true for 1 ≤ k ≤ 10. In the second expression, only 3 , 4 , 5 are allow for k. In the third, we say to take every k up to 100 , such that k is prime. We saw, to extend the indexing term from i ∈ I to i ∈ I | P (i) does not change the meaning of the indexed notation. The expression i ∈ I | P (i) is still a set albeit a subset of I that has no explicit name. However, no further concept has been added to the indexed notation.
2.3.3 Compound Index Notation
An indexed expression can itself contain an indexed notation, which generates nested indexed notations, as in the following expression:
⊙
i∈I
j∈J
Fi,j
where
and
are two arbitrary index operators. If the two operators are dierent then we need to evaluate the inner expression rst and the outer afterwards. A notable example is a system of m linear equations with n variables that is commonly noted as follows:
∑
j∈{ 1 ...n}
ai,j xj = bi with i ∈ { 1... m}
Using the list operator
, these formula can be noted as a nested indexed notation, that is, a notation where the index expression contains itself an indexed notation, with the
outer index operator
and the inner index operator as
. The nested notation then is noted as follows:
i∈{ 1 ...m}
j∈{ 1 ...n}
ai,j xj = bi
This notation is a very short writing of the following system of equations:
a 1 , 1 x 1 + a 1 , 2 x 2 +... + a 1 ,n− 1 xn− 1 + a 1 ,nxn = b 1 a 2 , 1 x 1 + a 2 , 2 x 2 +... + a 2 ,n− 1 xn− 1 + a 2 ,nxn = b 2
... =... am, 1 x 1 + am, 2 x 2 +... + am,n− 1 xn− 1 + am,nxn = bm
On the other hand, if both index operators in (5) are identical, then the two index operators can be merged in the following way:
⊙
i∈I
j∈J
Fi,j
i∈I, j∈J
Fi,j
It means that we merge the operator and unify also the indexing terms to be written as i ∈ I, j ∈ J. It signies that we build every tuple of the Cartesian Product of the two
sets: (i, j) ∈ I × J. As an example, suppose I = { 1 , 2 } and J = {a, b, c} then the index set is I × J = {(1, a), (1, b), (1, c), ((2, a), (2, b), (2, c)} it consists of 6 tuples. There are two active indexes i and j, or a tuple (i, j) of active indexes. Hence we also may write this expression in the following way:
⊙
(i,j)∈I×J
Fi,j
where the index set is I × J and the active index is replaced by the notation (i, j) which is called an active index tuple. In this case, the names within the active index tuples are called active indices. The active indices are now place-holders for the single components of the tuple. The index set I × J is also a set, the set of all tuples in the Cartesian Product. Hence if we do not need to access the single components within the product, we can replace (i, j) by a single active index, say k, and I × J can be replaced by a set name, say K. Now we see that the previous formula really reduces to our general indexed notation, which is as follows:
⊙
(i,j)∈I×J
Fi,j =
k∈K
Ek
Since indexed notation with multiple indexing terms really is reducible to indexed notation with one indexing term, we only need to extend the denition of index sets:
Denition: A compound index set is any countable (nite or innite) collection of elements, where all elements are either indivisible items called atoms or tuples containing all the same number of components.
Some care has to be taken, if the index-sets are tuple lists.
Sometimes access to the tuple itself and to its components is needed. In such cases, one could use a combined syntax as in: ⊙
k=(i,j)∈I×J
(Ek, Fi,j ) (6)
where (Ek, Fi,j ) is the indexed expression. Tuples list as index-sets are very common. Let the set I be a number of locations of clients in a region. Then J ⊂ I × I is a tuple list and a tuple can be interpreted as direct connection (route) from a location i to a location j, and let Pi,j be true if there is a route from i to j, then the set of all connections is :
J = {(i, j)|Pi,j , i, j ∈ I}
Suppose now, that fi,j is the number of vehicles that are driving from i to j in a hour. Then we can calculate the number of vehicles (xi) arriving at each location i per hour, it is: xi =
j∈I|Pi,j
fi,j forall j ∈ I
How can this be expressed with the tuple list J without using Pi,j? One variant is:
xi =
j∈(i,j)∈J
fi,j forall i ∈ (i, j) ∈ J
Suppose we have a set of 3 products P = { 1 , 2 , 3 } and a set of 4 factory locations F = { 1 , 2 , 3 , 4 }, where these products are manufactured. The products are transported from one factory to another at unit cost ci,j with i, j ∈ F. Furthermore, each product has a price vp with p ∈ P. Suppose also, that we transport xp,i,j unities of product p from factory i to factory j with i, j ∈ F and p ∈ P. The data are as follows (Since x is 3-dimensional,we use the notation xp=1 to slice (or extract) the matrix xi,j where p = 1):
v =
c =
xp=1^ =
xp=2 =
xp=3^ =
Using these data, we now can calculate various data using indexed notation (please verify as an exercise): (1) The total transportation costs T is calculated as follows:
T =
p∈P, i,j∈F
ci,j · xp,i,j = 3180
(2) The total value transported is as follows:
V =
p∈P, i,j∈F
vp · xp,i,j = 5213
(3) The total transportation costs Cp for each product p ∈ P is:
∧^. p∈P
Cp =
i,j∈F
ci,j · xp,i,j
(4) The value Wi,j transported between all factories (i, j) ∈ F × F is:
i,j∈F
Wi,j =
p∈P
vp · xp,i,j
(5) The maximum quantity Mi transported from a factory i ∈ F is:
∧^. i∈F
Mi = max p∈P, j∈F xp,i,j
(6) For each product p ∈ P the sum of the maximum quantity Si transported from a factory i ∈ F is:
∧^. i∈F
Si = max p∈P
j∈F
xp,i,j
2.4.1 Indexed index sets
Index sets occurring in indexing terms can be themselves indexed. (We have already seen an example above in set of sets.) Let us dene an index set I and based on it an indexed index set J = {Ji} where Ji is an index set and i ∈ I. The elements of J are index sets themselves. In this case the index mechanism is not applied to a singleton but to a set. As an example, suppose I = {a, b}, Ja = { 1 , 2 }, and Jb = { 2 , 3 } then J = {{ 1 , 2 }, { 2 , 3 }}. Based on these two sets I and J, one can form the following indexed notation:
⊙
i∈I
j∈Ji
Ei,j
or
i∈I, j∈Ji
Ei,j (7)
It is important to note, however, that the index i in i ∈ I is an active index, whereas the i in Ji is a passive index. Now (7) can be interpreted as follows:
⊙
(i,j)∈K
Ei,j with K ⊆ I × (J 1 ∪ · · · ∪ J|I|) (8)
This means that the concept of indexed index set can be reduced to compound index set and does not add any new features. Nevertheless, a notation like (7) may sometimes be more convenient, because the tuples are presented as a hierarchical structure instead of a at list.
2.4.2 Ordering
We saw that in various context an index set has a natural order. If the set is a sequence of time periods or time points, for instance, then we order the elements within this set according to its natural sequence and we expect that the index mechanism is applied in this order. We take an example: Suppose P is a set of time periods or time points. Furthermore, xp is the production level in period p ∈ P , dp is the demand in period p, and sp is the stock level at the end of period p. Then we can build a balance equation at each period:
production level during p minus demand during p = stock at the end of p minus stock at the beginning of p
Formally this can be written as follows (strictly speaking p has two dierent meaning here: once for a duration and once for a time point (sp), be careful to model this correctly):
xp − dp = sp − sp− 1 with p ∈ P
In this example we make a reference to sp− 1 , that is, to the time period before p. This would have no meaning, if the set P were not ordered. However, if we make reference to a dierent element then we must be careful to check of whether the element exists. In the expression above there is an undened reference: if p = 1 then the expression sp− 1 = s 0 is not dened. Hence strictly speaking, the expression above is only valid for p ∈ P − { 1 }, we must exclude the rst period and the balance equation of the rst period is treated apart, or we must dene s 0 separately.
In LPL there exist a slightly shorter syntax that could also be used for an indexing term. The examples above could be coded as follows:
set i := 1..10; set j := 1..100; parameter n; set k := 1..n;
parameter A := sum {i} 1; parameter B := sum {j} j; parameter C := sum {j|10<=j<=20} j^2;
parameter v{i}; parameter a{i,j}; parameter b{i,j,k};
parameter D := sum {i} v[i]; parameter E := max {i} ( sum {j} a[i,j]); parameter F{k} := sum {i,j} b[i,j,k];
In this code, the active index has the same name as the corresponding index set. Hence, {i in I}, an indexing term, can just be written as {i}. This makes the expressions more readable and in most context much shorter. However, this can lead to diculties as soon as the same index set is used more than once in an indexed expression as in the following simple expression:
i,j∈I
ci,j
In such a case, LPL allows one to dene one or two alias names for the same index set. We then could code this as following:
set i, j := 1..10; parameter c{i,j}; parameter H := sum {i,j} c[i,j];
Of course, one always can use the more traditional notation as follows:
set I := 1..10; parameter c{i in I, j in J} parameter H := sum {i in I,j in I} c[i,j];
The alias names separated by commas are just other names for the index set and can be used as unique active indexes name in indexed notations. LPL allows at most two aliases for each index sets. If we use more than two, then we always need to use the longer syntax as in the following example:
i,j,k,p∈I
di,j,k,p
in which case we need to code this as:
set i, j,k := 1..10; parameter d{i,j,k,p in i}; parameter L := sum {i,j,k,p in i} d[i,j,k,p];
The two versions of the LPL code can be downloaded or executed directly at: exercise0a^2 and exercise0b^3 (^2) https://lpl.matmod.ch/lpl/Solver.jsp?name=/exercise0a (^3) https://lpl.matmod.ch/lpl/Solver.jsp?name=/exercise0b
Let us now code the Exercise 1 given in section 2.4 as an LPL model. First we implement the declarations: The set of products and factories which are P = { 1 , 2 , 3 } and F = { 1 , 2 , 3 , 4 } the cost table ci,j , the value table vp and the quantity table xp,i,j with i, j ∈ F and p ∈ P. In LPL these data tables can be implemented as follows:
set p := 1..3; set i, j := 1..4; parameter c{i,j|i<>j} := [. 1 5 2 , 2. 4 2 , 1 2. 3 , 1 3 1 .]; parameter v{p} := [6 2 3]; parameter x{p,i,j|i<>j} := [
. 48 37 45 36. 43 46 44 36. 33 36 39 34. , . 46 35 39 32. 47 35 45 49. 39 47 46 30. , . 32 32 40 30. 41 30 45 43. 45 44 41 34. ];
In table c and x we use the indexing condition i<>j because there is no cost or quantity dened form a factory to itself. The data itself are listed in a lexico-graphical order. The expressions given in section 2.4 are then formulated as follows in LPL:
parameter T := sum {p,i,j} c[i,j]x[p,i,j]; parameter V := sum {p,i,j} v[p]x[p,i,j]; parameter C{p} := sum {i,j} c[i,j]x[p,i,j]; parameter W{i,j}:= sum {p} v[p]x[p,i,j]; parameter M{i} := max {p,j} x[p,i,j]; parameter S{i} := max {p} ( sum {j} x[p,i,j]);
The complete model can be executed at: exercise1a^4.
Let us now add a requirement that the transportation can only take place between a small subset of all (i, j) links between the factories i, j ∈ F. Hence, we need to introduce a property K(i, j) which is true if the transportation can take place between factory i and factory j. We dene it as:
Ki,j∈F =
The tuple list means that the transportation can only occur from factory 1 to 2 , from 1 to 4 , from 2 to 3 , from 3 to 2 and from 4 to 3. Only 5 transportation links are allowed. The corresponding expressions are then as follows: (1) The total transportation costs T is calculated as follows:
p∈P, i,j∈F |K(i,j)
ci,j · xp,i,j = 1524
(2) The total value transported is as follows:
V =
p∈P, i,j∈F |K(i,j)
vp · xp,i,j = 2148
(3) The total transportation costs Cp for each product p ∈ P is:
Cp∈P =
i,j∈F |K(i,j)
ci,j · xp,i,j =
(^4) https://lpl.matmod.ch/lpl/Solver.jsp?name=/exercise1a