Alg of Inf 1
Alg of Inf 1
Alg of Inf 1
OF INFORMATICS
Volume 1
AnTonCom
Budapest, 2010
This electronic book was prepared in the framework of project Eastern Hungarian
Informatics Books Repository no. TMOP-4.1.2-08/1/A-2009-0046.
This electronic book appeared with the support of European Union and with the
co-financing of European Social Fund.
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
I. AUTOMATA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1. Automata and Formal Languages . . . . . . . . . . . . . . . . . . . . 13
1.1. Languages and grammars . . . . . . . . . . . . . . . . . . . . . . . 13
1.1.1. Operations on languages . . . . . . . . . . . . . . . . . . . . 14
1.1.2. Specifying languages . . . . . . . . . . . . . . . . . . . . . . 14
1.1.3. Chomsky hierarchy of grammars and languages . . . . . . . 18
1.1.4. Extended grammars . . . . . . . . . . . . . . . . . . . . . . 22
1.1.5. Closure properties in the Chomsky-classes . . . . . . . . . . 25
1.2. Finite automata and regular languages . . . . . . . . . . . . . . . . 26
1.2.1. Transforming nondeterministic finite automata . . . . . . . 31
1.2.2. Equivalence of deterministic finite automata . . . . . . . . . 34
1.2.3. Equivalence of finite automata and regular languages. . . . 36
1.2.4. Finite automata with special moves . . . . . . . . . . . . . . 41
1.2.5. Minimization of finite automata . . . . . . . . . . . . . . . . 45
1.2.6. Pumping lemma for regular languages . . . . . . . . . . . . 47
1.2.7. Regular expressions . . . . . . . . . . . . . . . . . . . . . . . 50
1.3. Pushdown automata and context-free languages . . . . . . . . . . . 60
1.3.1. Pushdown automata . . . . . . . . . . . . . . . . . . . . . . 60
1.3.2. Context-free languages . . . . . . . . . . . . . . . . . . . . . 70
1.3.3. Pumping lemma for context-free languages . . . . . . . . . . 71
1.3.4. Normal forms of the context-free languages . . . . . . . . . 73
2. Compilers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
2.1. The structure of compilers . . . . . . . . . . . . . . . . . . . . . . . 81
2.2. Lexical analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
2.2.1. The automaton of the scanner . . . . . . . . . . . . . . . . . 85
2.2.2. Special problems . . . . . . . . . . . . . . . . . . . . . . . . 89
2.3. Syntactic analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
2.3.1. LL(1) parser . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Contents 5
The first volume of the book Informatikai algoritmusok appeared in 2004 in Hungar-
ian [121], and the second volume of the book appeared in 2005 [122]. Two volumes
contained 31 chapters: 23 chapters of the first and second volumes of the present
electronic book, and further chapters on clustering, frequent elements in data bases,
geoinformatics, inner-point methods, number theory, Petri-nets, queuing theory, and
scheduling.
The Hungarian version of the first volume contains those chapters which were
finished until May of 2004, and the second volume contains the chapters finished
until April of 2005.
The printed English version contains the chapters submitted until April of 2007.
Volume 1 [123] contains the chapters belonging to the fundamentals of informatics,
while the second volume [124] contains the chapters having closer connection with
some applications.
The first and second volumes of the given book represent an extended and cor-
rected electronic version of the printed book written is English. The third volume of
the present book contains new chapters.
The chapters of the first volume are divided into three parts. The chapters of Part
1 are connected with automata: Automata and Formal Languages (written by Zoltn
Ksa, Sapientia Hungarian University of Transylvania), Compilers (Zoltn Csrnyei,
Etvs Lornd University), Compression and Decompression (Ulrich Tamm, Chem-
nitz University of Technology Commitment), Reliable Computations (Pter Gcs,
Boston University).
The chapters of Part 2 have algebraic character: here are the chapters Algebra
(written by Gbor Ivanyos and Lajos Rnyai, Budapest University of Technology
and Economics), Computer Algebra (Antal Jrai and Attila Kovcs, Etvs Lornd
University), further Cryptology and Complexity Theory (Jrg Rothe, Heinrich Heine
University).
The chapters of the third part have numeric character: Competitive Analysis
(Csand Imreh, University of Szeged), Game Theory (Ferenc Szidarovszky, The Uni-
versity of Arizona) and Scientific Computations (Aurl Galntai, buda University
and Andrs Jeney, University of Miskolc).
The second volume is also divided into three parts. The chapters of Part 4
are connected with computer networks: Distributed Algorithms (Burkhard Englert,
California State University; Dariusz Kowalski, University of Liverpool; Grzegorz
Malewicz, University of Alabama; Alexander Allister Shvartsman, University of Con-
necticut), Parallel Algorithms (Claudia Fohry, University of Kassel and Antal Ivnyi,
Etvs Lornd University;), Network Simulation (Tibor Gyires, Illinois State Uni-
versity) and Systolic Systems (Eberhard Zehendner, Friedrich Schiller University).
The chapters of Part 5 are Relational Databases and Query in Relational
Databases (Jnos Demetrovics, Etvs Lornd University and Attila Sali, Alfrd
Rnyi Institute of Mathematics), Semistructured Data Bases (Attila Kiss, Etvs
Lornd University) and Memory Management (dm Balog, Antal Ivnyi, Etvs
Lornd University).
The chapters of the third part of the second volume have close connections with
biology: Bioinformatics (Istvn Mikls, Rnyi Institute of Mathematics), Human-
Computer Interactions (Ingo Althfer, Stefan Schwarz, Friedrich Schiller University),
and Computer Graphics (Lszl Szirmay-Kalos, Budapest University of Technology
and Economics).
The chapters are validated by Gbor Ivanyos, Istvn Majzik, Lajos Rnyai,
Andrs Recski, and Tams Szntai (Budapest University of Technology and Eco-
nomics), Andrs benczr, Sndor Fridli, Jnos Gonda, Istvn Tatsnyi, Attila Kiss,
Lszl Varga, Jnos Vida, and Bla Vizvri (Etvs Lornd University), Dezs Sima
(buda University) Pl Dmsi, Jnos Sztrik, and Attila Peth (University of De-
brecen), Zoltn Flp (University of Szeged), Anna Gl (University of Texas), Jnos
Mayer (University of Zrich).
The first and second volumes contain verbal description, pseudocode and anal-
ysis of over 200 algorithms, and over 350 figures and 120 examples illustrating how
the algorithms work. Each section ends with exercises and each chapter ends with
problems. In the two volumes you can find over 330 exercises and 70 problems.
We have supplied an extensive bibliography, in the section Chapter Notes of each
chapter. In the bibliography the names of the authors, journals and publishers are
usually active links to the corresponding web sites (the living elements are underlined
in the printed version and on the screen too).
The LATEX style file was written by Viktor Belnyesi, Zoltn Csrnyei, Lszl
Domoszlai and Antal Ivnyi. The figures was drawn or corrected by Kornl Locher.
Anna Ivnyi transformed the bibliography into hypertext. The DOCBOOK version
was made by Marton 2001. Kft.
Using the data of the colofon page you can contact with any of the creators of the
book. We welcome ideas for new exercises and problems, and also critical remarks
or bug reports.
The publication of the printed book was supported by Department of Mathe-
matics of Hungarian Academy of Science, and the electronic version received support
from European Union and from the European Social Fund.
Automata and formal languages play an important role in projecting and realizing
compilers. In the first section grammars and formal languages are defined. The dif-
ferent grammars and languages are discussed based on Chomsky hierarchy. In the
second section we deal in detail with the finite automata and the languages accepted
by them, while in the third section the pushdown automata and the corresponding
accepted languages are discussed. Finally, references from a rich bibliography are
given.
For the set of nonempty words over the notation + = \ {} will be used. The
set of words of length n over will be denoted by n , and 0 = {}. Then
= 0 1 n and + = 1 2 n .
2) a property, such that all words of the language have this property but other
word have not,
3) a grammar.
From the definition of a reflexive and transitive relation we can deduce the
following: u = v, if there exist the words w0 , w1 , . . . , wn (N T ) , n 0 and
u = w0 , w0 = w1 , w1 = w2 , . . . , wn1 = wn , wn = v. This can be written
shortly u = w0 = w1 = w2 = . . . = wn1 = wn = v. If n = 0 then u = v.
+
The same way we can define the relation u = v except that n 1 always, so at
least one direct derivation will de used.
Definition 1.2 The language generated by grammar G = (N, T, P, S) is the set
L(G) = {u T | S = u} .
So L(G) contains all words over the alphabet T which can be derived from the start
symbol S using the productions from P .
where up to the last but one replacement the first production (S aSb) was used, while
at the last replacement the production S ab. This derivation can be written S = an bn .
G
Therefore an bn can be derived from S for all n and no other words can be derived from S.
Definition 1.3 Two grammars G1 and G2 are equivalent, and this is denoted by
G1
= G2 if L(G1 ) = L(G2 ).
Example 1.2 The following two grammars are equivalent because both of them generate
the language {an bn cn | n 1}.
G1 = (N1 , T, P1 , S1 ), where
N1 = {S1 , X, Y }, T = {a, b, c},
P1 = {S1 abc, S1 aXbc, Xb bX, Xc Y bcc, bY Y b, aY aaX, aY
aa}.
G2 = (N2 , T, P2 , S2 ), where
N2 = {S2 , A, B, C},
P2 = {S2 aS2 BC, S2 aBC, CB BC, aB ab, bB bb, bC bc, cC
cc}.
First let us prove by mathematical induction that for n 2 S1 = an1 Y bn cn . If n = 2
G1
then
S1 = aXbc = abXc = abY bcc = aY b2 c2 .
G1 G1 G1 G1
The inductive hypothesis is S1 = an2 Y bn1 cn1 . We use production aY aaX, then
G1
(n 1) times production Xb bX, and then production Xc Y bcc, afterwards again
(n 1) times production bY Y b. Therefore
S1 = an2 Y bn1 cn1 = an1 Xbn1 cn1 =
G1 G1 G1
an1 bn1 Xcn1 = an1 bn1 Y bcn = an1 Y bn cn .
G1 G1
1.1. Languages and grammars 17
If now we use production aY aa we get S1 = an bn cn for n 2, but S1 = abc
G1 G1
by the production S1 abc, so an bn cn L(G1 ) for any n 1. We have to prove in
addition that using the productions of the grammar we cannot derive only words of the
form an bn cn . It is easy to see that a successful derivation (which ends in a word containing
only terminals) can be obtained only in the presented way.
Similarly for n 2
S2 = aS2 BC = an1 S2 (BC)n1 = an (BC)n = an B n C n
G2 G2 G2 G2
= an bB n1 C n = an bn C n = an bn cC n1 = an bn cn .
G2 G2 G2 G2
Proof We encode grammars for the proof as words on the alphabet {0, 1}. For a
given grammar G = (N, T, P, S) let N = {S1 , S2 , . . . , Sn }, T = {a1 , a2 , . . . , am } and
S = S1 . The encoding is the following:
the code of Si is 10 11 . . 11} 01,
| .{z the code of ai is 100 11 | .{z. . 11} 001 .
i times i times
In the code of the grammar the letters are separated by 000, the code of the arrow
is 0000, and the productions are separated by 00000.
It is enough, of course, to encode the productions only. For example, consider
the grammar
G = ({S}, {a, b}, {S aSb, S ab}, S).
The code of S is 10101, the code of a is 1001001, the code of b is 10011001. The code
of the grammar is
10101
| {z } 0000 1001001
| {z } 000 |10101
{z } 000 |10011001
{z } 00000 |10101
{z } 0000 1001001
| {z } 000
10011001
| {z } .
From this encoding results that the grammars with terminal alphabet T can be
enumerated 1 as G1 , G2 , . . . , Gk , . . . , and the set of these grammars is a denumerable
1 Let us suppose that in the alphabet {0, 1} there is a linear order <, let us say 0 < 1. The words
which are codes of grammars can be enumerated by ordering them first after their lengths, and
inside the equal length words, alphabetically, using the order of their letters. But we can use equally
the lexicographic order, which means that u < v (u is before v) if u is a proper prefix of v or there
exists the decompositions u = xay and v = xby 0 , where x, y, y 0 are subwords, a and b letters with
a < b.
18 1. Automata and Formal Languages
infinite set.
Consider now the set of all languages over T denoted by LT = {L | L T },
that is LT = P(T ). The set T is denumerable because its words can be ordered.
Let this order s0 , s1 , s2 , . . ., where s0 = . We associate to each language L LT an
infinite binary sequence b0 , b1 , b2 , . . . the following way:
1, if si L
bi = i = 0, 1, 2, . . . .
0, if si
6 L
It is easy to see that the set of all such binary sequences is not denumerable, be-
cause each sequence can be considered as a positive number less than 1 using its
binary representation (The decimal point is considered to be before the first digit).
Conversely, to each positive number less than 1 in binary representation a binary
sequence can be associated. So, the cardinality of the set of infinite binary sequences
is equal to cardinality of interval [0, 1], which is of continuum power. Therefore the
set LT is of continuum cardinality. Now to each grammar with terminal alphabet
T associate the corresponding generated language over T . Since the cardinality of
the set of grammars is denumerable, there will exist a language from LT , without
associated grammar, a language which cannot be generated by a grammar.
Definition 1.5 Define for a grammar G = (N, T, P, S) the following four types.
A grammar G is of type 0 (phrase-structure grammar) if there are no re-
strictions on productions.
A grammar G is of type 1 (context-sensitive grammar) if all of its produc-
tions are of the form A , where A N , , (N T ) , (N T )+ .
A production of the form S can also be accepted if the start symbol S does not
occur in the right-hand side of any production.
A grammar G is of type 2 (context-free grammar) if all of its productions are
of the form A , where A N , (N T )+ . A production of the form S
can also be accepted if the start symbol S does not occur in the right-hand side of
any production.
A grammar G is of type 3 (regular grammar) if its productions are of the
form A aB or A a, where a T and A, B N . A production of the form
S can also be accepted if the start symbol S does not occur in the right-hand
side of any production.
If a grammar G is of type i then language L(G) is also of type i.
Example 1.3 We give an example for each type of context-sensitive, context-free and
regular grammars.
Context-sensitive grammar. G1 = (N1 , T1 , P1 , S1 ), where N1 = {S1 , A, B, C}, T1 =
{a, 0, 1}.
Elements of P1 are:
S1 ACA,
AC AACA | ABa | AaB,
B AB | A,
A 0 | 1.
Language L(G1 ) contains words of the form uav with u, v {0, 1} and |u| 6= |v|.
Context-free grammar. G2 = (N2 , T2 , P2 , S), where N2 = {S, A, B}, T2 = {+, , (, ), a}.
Elements of P2 are:
S S + A | A,
A A B | B,
B (S) | a.
Language L(G2 ) contains algebraic expressions which can be correctly built using letter
a, operators + and and brackets.
Regular grammar. G3 = (N3 , T3 , P3 , S3 ), where N3 = {S3 , A, B}, T3 = {a, b}.
Elements of P3 are:
S3 aA
A aB | a
B aB | bB | a | b.
Language L(G3 ) contains words over the alphabet {a, b} with at least two letters a at
the beginning.
It is easy to prove that any finite language is regular. The productions will
be done to generate all words of the language. For example, if u = a1 a2 . . . an
is in the language, then we introduce the productions: S a1 A1 , A1 a2 A2 ,
. . . An2 an1 An1 , An1 an , where S is the start symbol of the language and
A1 , . . . , An1 are distinct nonterminals. We define such productions for all words
of the language using different nonterminals for different words, excepting the start
symbol S. If the empty word is also an element of the language, then the production
S is also considered.
The empty set is also a regular language, because the regular grammar G =
({S}, {a}, {S aS}, S) generates it.
Eliminate-Unit-Productions(G)
1 if the unit productions A B and B C are in P put also
the unit production A C in P while P can be extended,
2 if the unit production A B and the production B ( 6 N ) are in P
put also the production A in P ,
3 let P 0 be the set of productions of P except unit productions
4 return G0
Example 1.4 Use the above algorithm in the case of the grammar G =
{S, A, B, C}, {a, b}, P, S , where P contains
S A, A B, B C, C B, D C,
S B, A D, C Aa,
A aB,
A b.
Using the first step of the algorithm, we get the following new unit productions:
SD (because of S A and A D),
SC (because of S B and B C),
AC (because of A B and B C),
BB (because of B C and C B),
CC (because of C B and B C),
DB (because of D C and C B).
In the second step of the algorithm will be considered only productions with A or C in the
right-hand side, since productions A aB, A b and C Aa can be used (the other
productions are all unit productions). We get the following new productions:
S aB (because of S A and A aB),
Sb (because of S A and A b),
S Aa (because of S C and C Aa),
A Aa (because of A C and C Aa),
B Aa (because of B C and C Aa).
The new grammar G0 = {S, A, B, C}, {a, b}, P 0 , S will have the productions:
S b, A b, B Aa, C Aa,
S aB, A aB,
S Aa A Aa,
Proof Grammars of type 2 and 3 have in left-hand side of any productions only a
nonterminal, so they are in normal form. The proof has to be done for grammars of
type 0 and 1 only.
Let G = (N, T, P, S) be the original grammar and we define the grammar in
normal form as G0 = (N 0 , T, P 0 , S).
Let a1 , a2 , . . . , ak be those terminal symbols which occur in the left-hand side
of productions. We introduce the new nonterminals A1 , A2 , . . . , Ak . The following
notation will be used: T1 = {a1 , a2 , . . . , ak }, T2 = T \ T1 , N1 = {A1 , A2 , . . . , Ak } and
N 0 = N N1 .
Define the isomorphism h : N T N 0 T2 , where
h(ai ) = Ai , if ai T1 ,
h(X) = X, if X N T2 .
Define the set P 0 of production as
n o n o
P 0 = h() h() ( ) P Ai ai i = 1, 2, . . . , k .
In this case = if and only if h() =
0
h(). From this the theorem
G G
immediately results because S = u S = h(S) =
0
h(u) = u.
G G
Example 1.5 Let G = ({S, D, E}, {a, b, c, d, e}, P, S), where P contains
S aebc | aDbc
Db bD
Dc Ebccd
bE Eb
aE aaD | aae.
In the left-hand side of productions the terminals a, b, c occur, therefore consider the
new nonterminals A, B, C, and include in P 0 also the new productions A a, B b and
C c.
Terminals a, b, c will be replaced by nonterminals A, B, C respectively, and we get the
set P 0 as
S AeBC | ADBC
DB BD
DC EBCCd
BE EB
AE AAD | AAe
A a
B b
C c.
Let us see what words can be generated by this grammars. It is easy to see that
aebc L(G0 ), because S = AeBC = aebc.
S = ADBC = ABDC = ABEBCCd = AEBBCCd = AAeBBCCd =
0
aaebbccd, so aaebbccd L(G ).
22 1. Automata and Formal Languages
We prove, using the mathematical induction, that S = An1 EB n C(Cd)n1 for
n 2. For n = 2 this is the case, as we have seen before. Continuing the derivation we
get S = An1 EB n C(Cd)n1 = An2 AADB n C(Cd)n1 = An B n DC(Cd)n1 =
An B n EBCCd(Cd)n1 = An EB n+1 CCd(Cd)n1 = An EB n+1 C(Cd)n , and this is what
we had to prove.
But S = An1 EB n C(Cd)n1 = An2 AAeB n C(Cd)n1 = an ebn c(cd)n1 . So
n n n1 0
a eb c(cd) L(G ), n 1. These words can be generated also in G.
Theorem 1.7 To any extended grammar an equivalent grammar of the same type
can be associated.
Proof Denote by Gext the extended grammar and by G the corresponding equivalent
grammar of the same type.
Type 1. Define the productions of grammar G by rewriting the productions
, where || || of the extended grammar Gext in the form 1 2 1 2
allowed in the case of grammar G by the following way.
Let X1 X2 . . . Xm Y1 Y2 . . . Yn (m n) be a production of Gext , which is not
in the required form. Add to the set of productions of G the following productions,
where A1 , A2 , . . . , Am are new nonterminals:
X1 X2 . . . Xm A1 X2 X3 . . . Xm
A1 X2 . . . Xm A1 A2 X3 . . . Xm
...
A1 A2 . . . Am1 Xm A1 A2 . . . Am1 Am
A1 A2 . . . Am1 Am Y1 A2 . . . Am1 Am
Y1 A2 . . . Am1 Am Y1 Y2 . . . Am1 Am
...
Y1 Y2 . . . Ym2 Am1 Am Y1 Y2 . . . Ym2 Ym1 Am
Y1 Y2 . . . Ym1 Am Y1 Y2 . . . Ym1 Ym Ym+1 . . . Yn .
Furthermore, add to the set of productions of G without any modification the
productions of Gext which are of permitted form, i.e. 1 2 1 2 .
Inclusion L(Gext ) L(G) can be proved because each used production of Gext
in a derivation can be simulated by productions G obtained from it. Furthermore,
since the productions of G can be used only in the prescribed order, we could not
obtain other words, so L(G) L(Gext ) also is true.
Type 2. Let Gext = (N, T, P, S). Productions of form A have to be elimi-
nated, only S can remain, if S doesnt occur in the right-hand side of produc-
1.1. Languages and grammars 23
S aSBC | aBC
CB AB aB ab
AB AD bB bb
AD BD bC bc
BD BC cC cc.
It can be proved that L(Gext ) = L(G) = {an bn cn | n 1}.
Example 1.7 Let Gext = ({S, B, C}, {a, b, c}, P, S) be an extended grammar of type 2,
where P contains:
S aSc | B
B bB | C
C Cc | .
Then U0 = {C}, U1 = {B, C}, U3 = {S, B, C} = U . The productions of the new grammar
are:
S aSc | ac | B
B bB | b | C
C Cc | c.
The original grammar generates also the empty word and because S occurs in the right-
hand side of a production, a new start symbol and two new productions will be defined:
S 0 S, S 0 . The context-free grammar equivalent to the original grammar is G =
({S 0 , S, B, C}, {a, b, c}, P 0 , S 0 ) with the productions:
S0 S |
S aSc | ac | B
B bB | b | C
C Cc | c.
Both of these grammars generate language {am bn cp | p m 0, n 0}.
Example 1.8 Let Gext = ({S, A, B}, {a, b}, P, S) be the extended grammar of type 3 under
examination, where P :
S abA
A bB
B S | .
First, we eliminate production B . Since U0 = U = {B}, the productions will be
S abA
A bB | b
B S.
The latter production (which a unit production) can also be eliminated, by replacing it with
B abA. Productions S abA and B abA have to be transformed. Since, both pro-
ductions have the same right-hand side, it is enough to introduce only one new nonterminal
and to use the productions S aC and C bA instead of S abA. Production B abA
will be replaced by B aC. The new grammar is G = ({S, A, B, C}, {a, b}, P 0 , S), where
P 0:
S aC
A bB | b
B aC
C bA.
Can be proved that L(Gext ) = L(G) = {(abb)n | n 1}.
1.1. Languages and grammars 25
Proof For the proof we will use extended grammars. Consider the extended gram-
mars G1 = (N1 , T1 , P1 , S1 ) and G2 = (N2 , T2 , P2 , S2 ) of type i each. We can suppose
that N1 N2 = .
Union. Let G = (N1 N2 {S}, T1 T2 , P1 P2 {S S1 , S S2 }, S).
We will show that L(G ) = L(G1 )L(G2 ). If i = 0, 2, 3 then from the assumption
that G1 and G2 are of type i follows by definition that G also is of type i. If i = 1
and one of the grammars generates the empty word, then we eliminate from G the
corresponding production (possibly the both) Sk (k = 1, 2) and replace it by
production S .
Product. Let G = (N1 N2 {S}, T1 T2 , P1 P2 {S S1 S2 }, S).
We will show that L(G ) = L(G1 )L(G2 ). By definition, if i = 0, 2 then G will
be of the same type. If i = 1 and there is production S1 in P1 but there is
no production S2 in P2 then production S1 will be replaced by S S2 .
We will proceed the same way in the symmetrical case. If there is in P1 production
S1 and in P2 production S2 then they will be replaced by S .
In the case of regular grammars (i = 3), because S S1 S2 is not a regular
production, we need to use another grammar G = (N1 N2 , T1 T2 , P10 P2 , S1 ),
where the difference between P10 and P1 lies in that instead of productions in the
form A u, u T in P10 will exist production of the form A uS2 .
Iteration. Let G = (N1 {S}, T1 , P, S).
In the case of grammars of type 2 let P = P1 {S S1 S, S }. Then G
also is of type 2.
In the case of grammars of type 3, as in the case of product, we will change the
productions, that is P = P10 {S S1 , S }, where the difference between P10
and P1 lies in that for each A u (u T ) will be replaced by A uS, and the
others will be not changed. Then G also will be of type 3.
The productions given in the case of type 2 are not valid for i = 0, 1, because
when applying production S S1 S we can get the derivations of type S = S1 S1 ,
S1 = 1 1 , S1 = 2 2 , where 1 2 can be a left-hand side of a production. In
this case, replacing 1 2 by its right-hand side in derivation S = 1 1 2 2 , we
can generate a word which is not in the iterated language. To avoid such situations,
first let us assume that the language is in normal form, i.e. the left-hand side of
productions does not contain terminals (see page 20), second we introduce a new
nonterminal S 0 , so the set of nonterminals now is N1 {S, S 0 }, and the productions
are the following:
P = P1 {S , S S1 S 0 } {aS 0 aS | a T1 } .
26 1. Automata and Formal Languages
Now we can avoid situations in which the left-hand side of a production can extend
over the limits of words in a derivation because of the iteration. The above derivations
can be used only by beginning with S = S1 S 0 and getting derivation S = 1 1 S 0 .
Here we can not replace S unless the last symbol in 1 is a terminal symbol, and
0
Exercises
1.1-1 Give a grammar which generates language L = uu1 | u {a, b} and
determine its type.
1.1-2 Let G = (N, T, P, S) be an extended context-free grammar, where
N = {S, A, C, D}, T = {a, b, c, d, e},
P = {S abCADe, C cC, C , D dD, D , A , A
dDcCA}.
Give an equivalent context-free grammar.
1.1-3 Show that and + are regular languages over arbitrary alphabet .
1.1-4 Give a grammar to generate language L = u {0, 1} | n0 (u) = n1 (u) ,
where n0 (u) represents the number of 0s in word u and n1 (u) the number of 1s.
1.1-5 Give a grammar to generate all natural numbers.
1.1-6 Give a grammar to generate the following languages, respectively:
L1 = {an bm cp | n 1, m 1, p 1},
L2 = {a2n | n 1},
L3 = {an bm | n 0, m 0 },
L4 = {an bm | n m 1}.
1.1-7 Let G = (N, T, P, S) be an extended grammar, where N = {S, A, B, C},
T = {a} and P contains the productions:
S BAB, BA BC, CA AAC, CB AAB, A a, B .
Determine the type of this grammar. Give an equivalent, not extended grammar
with the same type. What language it generates?
control unit
- yes/no
An NFA is in fact a directed, labelled graph, whose vertices are the states and
there is a (directed) edge labelled with a from vertex p to vertex q if (p, a, q) E.
Among vertices some are initial and some final states. Initial states are marked by
a small arrow entering the corresponding vertex, while the final states are marked
with double circles. If two vertices are joined by two edges with the same direction
then these can be replaced by only one edge labelled with two letters. This graph
can be called a transition graph.
Example
1.9 Let A = (Q, , E, I, F ), where Q = {q0 , q1 , q2 }, = {0, 1, 2}, E =
(q0 , 0, q0 ), (q0 , 1, q1 ), (q0 , 2, q2 ),
(q1 , 0, q1 ), (q1 , 1, q2 ), (q1 , 2, q0 ),
(q2 , 0, q2 ), (q2 , 1, q0 ), (q2 , 2, q1 )
I = {q0 }, F = {q0 }.
The automaton can be seen in Fig. 1.2.
In the case of an edge (p, a, q) vertex p is the start-vertex, q the end-vertex and
a the label. Now define the notion of the walk as in the case of graphs. A sequence
?
q1
M
2 1
1 2
2
j U
0 - q0 q2 0
i
6 1
- q1 1- q 0,1
2
0,1 0,1
6
0
? ?
- q0 - q0 0 - q 1 - q
1 2
A B
empty productive walk, i.e. there is an initial state which is also a final state.
The set of words accepted by an NFA will be called the language accepted by
this NFA. The language accepted or recognized by NFA A is
n o
w
L(A) = w | p I, q F, p q .
This function associate to a state p and input letter a the set of states in which
the automaton can go if its current state is p and the head is on input letter a.
1.2. Finite automata and regular languages 29
0 1 0 1
q0 {q1 } q0 {q0 , q1 } {q0 }
q1 {q2 } q1 {q2 }
q2 {q2 } {q2 } q2 {q2 } {q2 }
A B
Denote by |H| the cardinal (the number of elements) of H.2 An NFA is a de-
terministic finite automaton (DFA) if
(p, a, q) E, (p, a, r) E = q = r , p, q, r Q, a .
If for a DFA |(q, a)| = 1 for each state q Q and for each letter a then it is
called a complete DFA.
Every DFA can be transformed in a complete DFA by introducing a new state,
which can be called a snare state. Let A = (Q, , E, {q0 }, F ) be a DFA. An equivalent
and complete DFA will be A0 = (Q {s}, , E 0 , {q0 },
F ), where s is the new state
and E = E (p, a, s) | (p, a) = , p Q, a (s, a, s) | a . It is easy to
0
The NFA in Fig. 1.3 are not deterministic: the first (automaton A) has two
initial states, the second (automaton B) has two transitions with 0 from state q0 (to
states q0 and q1 ). The transition table of these two automata are in Fig. 1.4. L(A)
is set of words over = {0, 1} which do not begin with two zeroes (of course is in
language), L(B) is the set of words which contain 01 as a subword.
2 The same notation is used for the cardinal of a set and length of a word, but this is no matter of
confusion because for word we use lowercase letters and for set capital letters. The only exception
is (q, a), but this could not be confused with a word.
30 1. Automata and Formal Languages
Inaccessible-States(A)
1 U0 I
2 i0
3 repeat
4 ii+1
5 for all q Ui1
6 do for all a
7 do Ui Ui1 (q, a)
8 until Ui = Ui1
9 U Q \ Ui
10 return U
Nonproductive-States(A)
1 V0 F
2 i0
3 repeat
4 ii+1
5 for all p Vi1
6 do for all a
7 do Vi Vi1 1 (p, a)
1.2. Finite automata and regular languages 31
8 until Vi = Vi1
9 V Q \ Vi
10 return V
Theorem 1.10 For any NFA one may construct an equivalent DFA.
I = {I},
F = {S Q | S F 6= }.
We prove that L(A) = L(A).
a) First prove that L(A) L(A). Let w = a1 a2 . . . ak L(A). Then there exists
a walk
a1 a2 a3 ak1 ak
q0 q1 q2 qk1 qk , q0 I, qk F .
Using the transition function of NFA A we construct the sets S0 = {q0 }, (S0 , a1 ) =
S1 , . . . (Sk1 , ak ) = Sk . Then q1 S1 , . . . , qk Sk and since qk F we get
Sk F 6= , so Sk F . Thus, there exists a walk
a
1 2 a 3 a ak1
k a
S0 S1 S2 Sk1 Sk , S0 I, Sk F .
There are sets S00 , . . . , Sk0 for which S00 = I, and for i = 0, 1, . . . , k we have Si Si0 ,
and
a1 a2 a3 ak1 0 ak
S00 S10 S20 Sk1 Sk0
R
- S0 0 - 1 - 0, 1
S2 S3
The empty set was excluded from the states, so we used here instead of {}.
Example 1.10 Apply Theorem 1.10 to transform NFA A in Fig. 1.3. Introduce the fol-
lowing notation for the states of the DFA:
S0 := {q0 , q1 }, S1 := {q0 }, S2 := {q1 }, S3 := {q2 },
S4 := {q0 , q2 }, S5 := {q1 , q2 }, S6 := {q0 , q1 , q2 } ,
where S0 is the initial state. Using the transition function we get the transition table:
0 1
S0 {S2 } {S3 }
S1 {S2 }
S2 {S3 }
S3 {S3 } {S3 }
S4 {S5 } {S3 }
S5 {S3 } {S3 }
S6 {S5 } {S3 }
0 1
S0 {S2 } {S3 }
S2 {S3 }
S3 {S3 } {S3 }
NFA-DFA(A)
1 q0 I
2 Q {q 0 }
3 i0 i counts the rows.
4 k0 k counts the states.
34 1. Automata and Formal Languages
5 repeat
6 for j = 1, 2, .[
..,m j counts the columns.
7 do q (p, aj )
pq i
8 if q 6=
9 then if IsIn(q, Q)
10 then M [i, j] {q}
11 else k k + 1
12 qk q
13 M [i, j] {q k }
14 Q Q {q k }
15 else M [i, j]
16 ii+1
17 until i = k + 1
18 return transition table M of A
Since loop repeat is executed as many times as the number of states of new
automaton, in worst case the running time can be exponential, because, if the number
of states in NFA is n, then DFA can have even 2n 1 states. (The number of subsets
of a set of n elements is 2n , including the empty set.)
Theorem 1.10 will have it that to any NFA one may construct an equivalent DFA.
Conversely, any DFA is also an NFA by definition. So, the nondeterministic finite
automata accepts the same class of languages as the deterministic finite automata.
... a ...
... ...
(q, q 0 ) elem (q, a) , elem 0 (q 0 , a)
... ...
1.2. Finite automata and regular languages 35
In the first column of the first row we put (q0 , q00 ) and complete the first row using
the above method. If in the first row in any column there occur a pair of states
from which one is a final state and the other not then the algorithm ends, the two
automata are not equivalent. If there is no such a pair of states, every new pair is
written in the first column. The algorithm continues with the next unfilled row. If
no new pair of states occurs in the table and for each pair both of states are final or
both are not, then the algorithm ends and the two DFA are equivalent.
If |Q| = n, |Q0 | = n0 and || = m then taking into account that in worst
case loop repeat is executed nn0 times, loop for m times, the running time of the
algorithm in worst case will be O(nn0 m), or if n = n0 then O(n2 m).
Our algorithm was described to determine the equivalence of two complete
DFAs. If we have to determine the equivalence of two NFAs, first we transform
them into complete DFAs and after this we can apply the above algorithm.
DFA-Equivalence(A, A0 )
1 write in the first column of the first row the pair (q0 , q00 )
2 i0
3 repeat
4 ii+1
5 let (q, q 0 ) be the pair in the first column of the ith row
6 for all a
7 do write in the column associated to a in the ith row
the pair elem (q, a) , elem 0 (q 0 , a)
8 if one state in elem (q, a) , elem 0 (q 0 , a) is final
and the other not
9 then return no
10 else write pair elem (q, a) , elem 0 (q 0 , a)
in the next empty row of the first column,
if not occurred already in the first column
11 until the first element of (i + 1)th row becomes empty
12 return yes
Example 1.11 Determine if the two DFAs in Fig. 1.6 are equivalent or not. The algorithm
gives the table
a b
(q0 , p0 ) (q2 , p3 ) (q1 , p1 )
(q2 , p3 ) (q1 , p2 ) (q2 , p3 )
(q1 , p1 ) (q2 , p3 ) (q0 , p0 )
(q1 , p2 ) (q2 , p3 ) (q0 , p0 )
The two DFAs are equivalent because all possible pairs of states are considered and
in every pair both states are final or both are not final.
36 1. Automata and Formal Languages
Example 1.12 The table of the two DFAs in Fig. 1.7 is:
a b
(q0 , p0 ) (q1 , p3 ) (q2 , p1 )
(q1 , p3 ) (q2 , p2 ) (q0 , p3 )
(q2 , p1 )
(q2 , p2 )
These two DFAs are not equivalent, because in the last column of the second row in the
pair (q0 , p3 ) the first state is final and the second not.
- q0 - p0 b p2
a
a
b b b b a a
a
~
j R
q1 q2 p1 a - p3
b b
Y a
- q0 - p0 b p2
b a
b a b b a a
a
~
j R
q1 q2 p1 a - p3
b b
Y a
a a
? ?
- q0 b - q1 b - q2
(in the right-hand side of the last production qn does not occur, because qn F ),
so there is the derivation
q0 = a1 q1 = a1 a2 q2 = . . . = a1 a2 . . . an1 qn1 = a1 a2 . . . an .
Therefore, u L(G).
Conversely, let u = a1 a2 . . . an L(G) and u 6= . Then there exists a derivation
q0 = a1 q1 = a1 a2 q2 = . . . = a1 a2 . . . an1 qn1 = a1 a2 . . . an ,
in which productions
Example 1.13 Let A = ({q0 , q1 , q2 }, {a, b}, E, {q0 }, {q2 }) be a DFA, where E = (q0 , a, q0 ),
(q0 , b, q1 ), (q1 , b, q2 ), (q2 , a, q2 ) . The corresponding transition table is
a b
q0 {q0 } {q1 }
q1 {q2 }
q2 {q2 }
38 1. Automata and Formal Languages
The transition graph of A is in Fig. 1.8. By Theorem 1.11 we define regular grammar
G = ({q0 , q1 , q2 }, {a, b}, P, q0 ) with the productions in P
q0 aq0 | bq1 , q1 bq2 | b, q2 aq2 | a .
One may prove that L(A) = {am bban | m 0, n 0}.
The method described in the proof of Theorem 1.11 easily can be given as an
algorithm. The productions of regular grammar G = (Q, , P, q0 ) obtained from the
DFA A = (Q, , E, {q0 }, F ) can be determined by the following algorithm.
Regular-Grammar-from-DFA(A)
1 P
2 for all p Q
3 do for all a
4 do for all q Q
5 do if (p, a, q) E
6 then P P {p aq}
7 if q F
8 then P P {p a}
9 if q0 F
10 then P P {q0 }
11 return G
It is easy to see that the running time of the algorithm is (n2 m), if the number
of states is n and the number of letter in alphabet is m. In lines 24 we can consider
only one loop, if we use the elements of E. Then the worst case running time is
(p), where p is the number of transitions of DFA. This is also O(n2 m), since all
transitions are possible. This algorithm is:
Regular-Grammar-from-Dfa(A)
1 P
2 for all (p, a, q) E
3 do P P {p aq}
4 if q F
5 then P P {p a}
6 if q0 F
7 then P P {q0 }
8 return G
a a
? ?
- S
b - A
b - B
b a
?
~
Z
{Z} if production S does not occur in G,
F =
{Z, S} if production S occurs in G.
Prove that L(G) = L(A).
Let u = a1 a2 . . . an L(G), u 6= . Then there is in G a derivation of word u:
S = a1 A1 = a1 a2 A2 = . . . = a1 a2 . . . an1 An1 = a1 a2 . . . an .
This derivation is based on productions
S a1 A1 , A1 a2 A2 , . . . , An2 an1 An1 , An1 an .
Then, by the definition of the transitions of NFA A there exists a walk
1a 2 a 3 a an1
n a
S A1 A2 An1 Z, Z F .
Thus, u L(A). If L(G), there is production S , but in this case the initial
state is also a final one, so L(A). Therefore, L(G) L(A).
Let now u = a1 a2 . . . an L(A). Then there exists a walk
1a 2 a 3 a an1
n a
S A1 A2 An1 Z, Z F .
If u is the empty word, then instead of Z we have in the above formula S, which
also is a final state. In other cases only Z can be as last symbol. Thus, in G there
exist the productions
S = a1 A1 = a1 a2 A2 = . . . = a1 a2 . . . an1 An1 = a1 a2 . . . an ,
Example 1.14 Let G = ({S, A, B}, {a, b}, {S aS, S bA, A bB, A
b, B aB, B a}, S) be a regular grammar. The NFA associated is A =
({S, A, B, Z}, {a, b}, E, {S}, {Z}), where E = (S, a, S), (S, b, A), (A, b, B), (A, b, Z),
(B, a, B), (B, a, Z) . The corresponding transition table is
40 1. Automata and Formal Languages
a b
S {S} {A}
A {B, Z}
B {B, Z}
E
The transition graph is in Fig. 1.9. This NFA can be simplified, states B and Z can be
contracted in one final state.
NFA-from-Regular-Grammar(A)
1 E
2 Q N {Z}
3 for all A N
4 do for all a T
5 do if (A a) P
6 then E E {(A, a, Z)}
7 for all B N
8 do if (A aB) P
9 then E E {(A, a, B)}
10 if (S ) 6 P
11 then F {Z}
12 else F {Z, S}
13 return A
NFA-from-Regular-Grammar(A)
1 E
2 Q N {Z}
3 for all (A u) P
4 do if u = a
5 then E E {(A, a, Z)}
6 if u = aB
7 then E E {(A, a, B)}
8 if (S ) 6 P
9 then F {Z}
10 else F {Z, S}
11 return A
1.2. Finite automata and regular languages 41
- Nondeterministic
Regular grammars
finite automata
Y
+
Deterministic
finite automata
Figure 1.10 Relations between regular grammars and finite automata. To any regular grammar
one may construct an NFA which accepts the language generated by that grammar. Any NFA can
be transformed in an equivalent DFA. To any DFA one may construct a regular grammar which
generates the language accepted by that DFA.
From Theorems 1.10, 1.11 and 1.12 results that the class of regular languages
coincides with the class of languages accepted by NFAs and also with class of lan-
guages accepted by DFAs. The result of these three theorems is illustrated in Fig.
1.10 and can be summarised also in the following theorem.
Theorem 1.13 The following three class of languages are the same:
the class of regular languages,
the class of languages accepted by DFAs,
the class of languages accepted by NFAs.
Operation on regular languages It is known (see Theorem 1.8) that the set
L3 of regular languages is closed under the regular operations, that is if L1 , L2 are
regular languages, then languages L1 L2 , L1 L2 and L1 are also regular. For regular
languages are true also the following statements.
The complement of a regular language is also regular. This is easy to prove using
automata. Let L be a regular language and let A = (Q, , E, {q0 }, F ) be a DFA
which accepts language L. It is easy to see that the DFA A = (Q, , E, {q0 }, Q \ F )
accepts language L. So, L is also regular.
The intersection of two regular languages is also regular. Since L1 L2 = L1 L2 ,
the intersection is also regular.
The difference of two regular languages is also regular. Since L1 \ L2 = L1 L2 ,
the difference is also regular.
1 0 1
? ? ?
- q0 - q1 - q2
The FA with -moves in Fig. 1.11 accepts words of form uvw, where u
{1} , v {0} and w {1} .
Theorem 1.14 To any FA with -moves one may construct an equivalent NFA
(without -moves).
Let A = (Q, , E, I, F ) be an FA with -moves and we construct an equivalent NFA
A = (Q, , E, I, F ). The following algorithm determines sets F and E.
For a state q denote by (q) the set of states (including even q) in which one
may go from q using -moves only. This may be extended also to sets
[
(S) = (q), S Q .
qS
Clearly, for all q Q and S Q both (q) and (S) may be computed. Suppose in
the sequel that these are given.
The following algorithm determine the transitions using the transition function
, which is defined in line 5.
If |Q| = n and || = m,, then lines 26 show that the running time in worst case
is O(n2 m).
Eliminate-Epsilon-Moves(A)
1 F F {q I | (q) F 6= }
2 for all q Q
3 do for all a [
4 do (p, a)
p(q)
[
5 (q, a) (p)
p
6 E (p, a, q), | p, q Q, a , q (p, a)
7 return A
Example 1.15 Consider the FA with -moves in Fig. 1.11. The corresponding transition
table is:
0 1
q0 {q0 } {q1 }
q1 {q1 } {q2 }
q2 {q2 }
1.2. Finite automata and regular languages 43
1 0 1
? ? ?
- q0 0,1 - q 0,1 - q
1 2
*
0,1
0 1
q0 {q1 , q2 } {q0 , q1 , q2 }
q1 {q1 , q2 } {q2 }
q2 {q2 }
Define regular operations on NFA: union, product and iteration. The result will
be an FA with -moves.
Operation will be given also by diagrams. An NFA is given as in Fig. 1.13(a).
Initial states are represented by a circle with an arrow, final states by a double circle.
Let A1 = (Q1 , 1 , E1 , I1 , F1 ) and A2 = (Q2 , 2 , E2 , I2 , F2 ) be NFA. The result
of any operation is a FA with -moves A = (Q, , E, I, F ). Suppose that Q1 Q2 =
always. If not, we can rename the elements of any set of states.
Union. A = A1 A2 , where
44 1. Automata and Formal Languages
A1 A2
A1
-
- A2
(a) (b)
Figure 1.13 (a) Representation of an NFA. Initial states are represented by a circle with an arrow,
final states by a double circle. (b) Union of two NFAs.
Q = Q1 Q2 {q0 } ,
= 1 2 ,
I = {q0 } ,
F = F1 F2 , [
E = E1 E 2 (q0 , , q) .
qI1 I2
For the result of the union see Fig. 1.13(b). The result is the same if instead of
a single initial state we choose as set of initial states the union I1 I2 . In this case
the result automaton will be without -moves. By the definition it is easy to see that
L(A1 A2 ) = L(A1 ) L(A2 ).
Product. A = A1 A2 , where
Q = Q1 Q2 ,
= 1 2 ,
F = F2 ,
I = I1 , [
E = E1 E 2 (p, , q) .
p F1
q I2
For the result automaton see Fig. 1.14(a). Here also L(A1 A2 ) = L(A1 )L(A2 ).
Iteration. A = A1 , where
Q = Q1 {q0 },
= 1 ,
F = F1 {q0 },
I = {q0 }
1.2. Finite automata and regular languages 45
A1 A2
A1
A1 A2 A1
- R - -
(a) (b)
0
1
?
- q0 0 - q1 1 - q2 q5
6
q4 *
1 0 1
q3 * *
1 q2 * * *
^ ?
q3 j q 0 q5
4
I 1 q1 * * *
6
0
q0 * * * *
0
[ [
E = E1 (q0 , , p) (q, , p) .
pI1 q F1
p I1
The iteration of an FA can be seen in Fig. 1.14(b). For this operation it is also
true that L(A1 ) = L(A1 ) .
The definition of these tree operations proves again that regular languages are
closed under the regular operations.
If two states are not equivalent, then they are distinguishable. In the following
algorithm the distinguishable states will be marked by a star, and equivalent states
will be merged. The algorithm will associate list of pair of states with some pair
of states expecting a later marking by a star, that is if we mark a pair of states
by a star, then all pairs on the associated list will be also marked by a star. The
algorithm is given for DFA without inaccessible states. The used DFA is complete,
so (p, a) contains exact one element, function elem defined on page 34, which gives
the unique element of the set, will be also used here.
Automaton-Minimization(A)
1 mark with a star all pairs of states p, q for which
p F and q 6 F or p 6 F and q F
2 associate an empty list with each unmarked
pair p, q
3 for all unmarked pair of states
p, q and for all symbol a
examine pairs of states elem (p, a) , elem (q, a)
if any of these pairs is marked,
then mark also pair p, q with all the elements on the list before
associated with pair p, q
else if all the above pairs are unmarked
then put pair {p, q} on each list associated
with pairs
elem (p, a) , elem (q, a) , unless (p, a) = (q, a)
4 merge all unmarked (equivalent) pairs
After finishing the algorithm, if a cell of the table does not contain a star,
then the states corresponding to its row and column index, are equivalent and may
be merged. Merging states is continued until it is possible. We can say that the
equivalence relation decomposes the set of states in equivalence classes, and the
states in such a class may be all merged.
Remark. The above algorithm can be used also in the case of an DFA which is
not complete,
that is there are states for which does not exist transition. Then a
pair , {q} may occur, and if q is a final state, consider this pair marked.
Example 1.16 Let be the DFA in Fig. 1.15. We will use a table for marking pairs with
a star. Marking pair {p, q} means putting a star in the cell corresponding to row p and
column q (or row q and column p).
First we mark pairs {q2 , q0 }, {q2 , q1 }, {q2 , q3 }, {q2 , q4 } and {q2 , q5 } (because
q2 is the single final state). Then consider all unmarked pairs and examine them
as the algorithm
requires. Let
us begin with pair {q0 , q1 }.
Associate with it pairs
{elem (q0 , 0) , elem (q1 , 0) }, {elem (q0 , 1) , elem (q1 , 1) }, that is {q1 , q4 }, {q4 , q2 }.
Because pair {q4 , q2 } is already marked, mark also pair {q0 , q1 }.
In the case of pair {q0 , q3 } the new pairs are {q1 , q5 } and {q4 , q4 }. With pair {q1 , q5 }
1.2. Finite automata and regular languages 47
- q0 q3 0 - q1 q5 1 - q2 1
1 0
1 ?
- q4 0
{q1 , q5 } {q0 , q3 } .
Now continuing with {q1 , q5 } one obtain pairs {q4 , q4 } and {q2 , q2 }, with which nothing are
associated by algorithm.
Continue with pair {q0 , q4 }. The associated pairs are {q1 , q4 } and {q4 , q3 }. None of
them are marked, so associate with them on a list pair {q0 , q4 }, that is
Now continuing with {q1 , q4 } we get the pairs {q4 , q4 } and {q2 , q3 }, and because this latter
is marked we mark pair {q1 , q4 } and also pair {q0 , q4 } associated to it on a list. Continuing
we will get the table in Fig. 1.15, that is we get that q0 q3 and q1 q5 . After merging
them we get an equivalent minimum state automaton (see Fig. 1.16).
Theorem 1.15 (pumping lemma). For any regular language L there exists a nat-
ural number n 1 (depending only on L), such that any word u of L with length at
least n may be written as u = xyz such that
(1) |xy| n,
(2) |y| 1,
(3) xy i z L for all i = 0, 1, 2, . . ..
48 1. Automata and Formal Languages
= 6
...
qk1 =
qj+1
ak w >
aj+1
q2 - . . . - qj
q1 3 a3 aj
a2 ak+1
3 qj = qk w
a1 qk+1 - . . . - qm
- q0 am
Figure 1.17 Sketch of DFA used in the proof of the pumping lemma.
Proof If L is a regular language, then there is such an DFA which accepts L (by
Theorems 1.12 and 1.10). Let A = (Q, , E, {q0 }, F ) be this DFA, so L = L(A).
Let n be the number of its states, that is |Q| = n. Let u = a1 a2 . . . am L and
m n. Then, because the automaton accepts word u, there are states q0 , q1 , . . . , qm
and walk
a1 a2 a3 am1 am
q0 q1 q2 qm1 q m , qm F .
Because the number of states is n and m n, by the pigeonhole principle3 states
q0 , q1 , . . . , qm can not all be distinct (see Fig. 1.17), there are at least two of them
which are equal. Let qj = qk , where j < k and k is the least such index. Then
j < k n. Decompose word u as:
x = a1 a2 . . . aj
y = aj+1 aj+2 . . . ak
z = ak+1 ak+2 . . . am .
This decomposition immediately yields to |xy| n and |y| 1. We will prove that
xy i z L for any i.
Because u = xyz L, there exists an walk
x y z
q0 qj qk qm , qm F,
3 Pigeonhole principle: If we have to put more than k objects into k boxes, then at least one box
will contain at least two objects.
1.2. Finite automata and regular languages 49
Example 1.17 We use the pumping lemma to show that L1 = {ak bk | k 1} is not
regular. Assume that L1 is regular, and let n be the corresponding natural number given
by the pumping lemma. Because the length of the word u = an bn is 2n, this word can be
written as in the lemma. We prove that this leads to a contradiction. Let u = xyz be the
decomposition as in the lemma. Then |xy| n, so x and y can contain no other letters
than a, and because we must have |y| 1, word y contains at least one a. Then xy i z for
i 6= 1 will contain a different number of as and bs, therefore xy i z 6 L1 for any i 6= 1. This
is a contradiction with the third assertion of the lemma, this is why that assumption that
L1 is regular, is false. Therefore L1 6 L3 .
Because the context-free grammar G1 = ({S}, {a, b}, {S ab, S aSb}, S) generates
language L1 , we have L1 L2 . From these two follow that L3 L2 .
Example 1.18 We show that L2 = u {0, 1} | n0 (u) = n1 (u) is not regular. (n0 (u) is
the number of 0s in u, while n1 (u) the number of 1s).
We proceed as in the previous example using here word u = 0n 1n , where n is the
natural number associated by lemma to language L2 .
Example 1.19 We prove, using the pumping lemma, that L3 = uu | u {a, b} is not
a regular language. Let w = an ban b = xyz be, where n here is also the natural number
associated to L3 by the pumping lemma. From |xy| n we have that y contains no other
letters than a, but it contains at least one. By lemma we have xz L3 , that is not possible.
Therefore L3 is not regular.
Corollary 1.16 Regular language L is not empty if and only if there exists a word
u L, |u| < n, where n is the natural number associated to L by the pumping lemma.
Proof The assertion in a direction is obvious: if there exists a word shorter than
n in L, then L 6= . Conversely, let L 6= and let u be the shortest word in L.
We show that |u| < n. If |u| n, then we apply the pumping lemma, and give
the decomposition u = xyz, |y| > 1 and xz L. This is a contradiction, because
|xz| < |u| and u is the shortest word in L. Therefore |u| < n.
Corollary 1.17 There exists an algorithm that can decide if a regular language is
or not empty.
Proof Assume that L = L(A), where A = (Q, , E, {q0 }, F ) is a DFA. By Conse-
quence 1.16 and Theorem 1.15 language L is not empty if and only if it contains a
word shorter than n, where n is the number of states of automaton A. By this it is
enough to decide that there is a word shorter than n which is accepted by automaton
A. Because the number of words shorter than n is finite, the problem can be decided.
50 1. Automata and Formal Languages
Now, the question is: how can we apply the pumping lemma for a finite regular
language, since by pumping words we get an infinite number of words? The number
of states of a DFA accepting language L is greater than the length of the longest
word in L. So, in L there is no word with length at least n, when n is the natural
number associated to L by the pumping lemma. Therefore, no word in L can be
decomposed in the form xyz, where |xyz| n, |xy| n, |y| 1, and this is why we
can not obtain an infinite number of words in L.
x+y y+x
(x + y) + z x + (y + z)
(xy)z x(yz)
(x + y)z xz + yz
x(y + z) xy + xz
(x + y) (x + y) (x + y ) (x + y )
(x + y) (x y )
(x ) x
x x xx
xx + x
Some brackets can be omitted in the regular expressions if taking into account the
priority of operations (iteration, product, union) the corresponding languages are
not affected. For example instead of ((x )(x + y)) we can consider x (x + y).
Two regular expressions are equivalent if they represent the same language,
that is x y if X = Y , where X and Y are the languages represented by regular
expressions x and y respectively. Figure 1.18 shows some equivalent expressions.
We show that to any finite language L can be associated a regular expression
x which represent language L. If L = , then x = . If L = {w1 , w2 , . . . , wn },
then x = x1 + x2 + . . . + xn , where for any i = 1, 2, . . . , n expression xi is a regular
expression representing language {wi }. This latter can be done by the following rule.
If wi = , then xi = , else if wi = a1 a2 . . . am , where m 1 depends on i, then
xi = a1 a2 . . . am , where the brackets are omitted.
We prove the theorem of Kleene which refers to the relationship between regular
languages and regular expression.
Theorem 1.20 (Kleenes theorem). Language L is regular if and only if
there exists a regular expression over representing language L.
Proof First we prove that if x is a regular expression, then language L which
represents x is also regular. The proof will be done by induction on the construction
of expression.
If x = , x = , x = a, a , then L = , L = {}, L = {a} respectively. Since
L is finite in all three cases, it is also regular.
If x = (x1 + x2 ), then L = L1 L2 , where L1 and L2 are the languages which
represent the regular expressions x1 and x2 respectively. By the induction hypothesis
languages L1 and L2 are regular, so L is also regular because regular languages are
closed on union. Cases x = (x1 x2 ) and x = (x1 ) can be proved by similar way.
Conversely, we prove that if L is a regular language, then a regular expression x
can be associated to it, which represent exactly the language L. If L is regular, then
there exists a DFA A = (Q, , E, {q0 }, F ) for which L = L(A). Let q0 , q1 , . . . , qn the
52 1. Automata and Formal Languages
1 1 0
? ?
- q0 q1
0 *
Figure 1.19 DFA from Example 1.20, to which regular expression is associated by Method 1.
0
0
R ?
- q0 - q1 - q2 - q3
1 0 1
1
Figure 1.20 DFA in Example 1.21 to which a regular expression is associated by Method 1. The
computation are in Figure 1.21.
0
R10 : 11
Then the regular expression corresponding to L(A) is 1 + 1 0(1 0 + ) 11 1 +
1 0(1 0) 11 .
Example 1.21 Find a regular expression associated to DFA in Fig. 1.20. The computations
3
are in Figure 1.21. The regular expression corresponding to R03 is 11 + (0 + 10)0 1.
Example 1.22 In the case of Fig. 1.19 the result is obtained by steps illustrated in Fig.
1.23. This result is (1 + 00 1) , which represents the same language as obtained by Method
1 (See example 1.20).
Example 1.23 In the case of Fig. 1.20 is not necessary to introduce new initial and
final state. The steps of transformations can be seen in Fig. 1.24. The resulted regular
expression can be written also as (0 + 10)0 1 + 11, which is the same as obtained by the
54 1. Automata and Formal Languages
k
R00
k
R01 1 1 1 1
k
R02 0 0 0 + 10 (0 + 10)0
k
R03 11 11 + (0 + 10)0 1 11 + (0 + 10)0 1
k
R11
k
R12 0 0 0 00
k
R13 1 1 1 1 + 00 1
k
R22 0+ 0+ 0+ 0
k
R23 1 1 1 0 1
k
R33
k .
Figure 1.21 Determining a regular expression associated to DFA in Figure 1.20 using sets Rij
previous method.
Method 3. The third method for writing regular expressions associated to finite
automata uses formal equations. A variable X is associated to each state of the au-
tomaton (to different states different variables). Associate to each state an equation
which left side contains X, its right side contains sum of terms of form Y a or ,
where Y is a variable associated to a state, and a is its corresponding input symbol.
If there is no incoming edge in the state corresponding to X then the right side of
the equation with left side X contains , otherwise is the sum of all terms of the form
Y a for which there is a transition labelled with letter a from state corresponding to
Y to the state corresponding to X. If the state corresponding to X is also an initial
1.2. Finite automata and regular languages 55
x
R x+y
replaced by -
y
xy z
1 2 1 - 2
x y z 3 3
s ? uy z
3 replaced by
3 xy v
u v
s s
4 5 4 - 5
uy v
Figure 1.22 Possible equivalent transformations for finding regular expression associated to an
automaton.
- -
1 0
- ? ? - ?
1 q0 q1 1 q0 00 1 -
0
(1 + 00 1)
? ? ?
and a final state, then on right side of the equation with the left side X will be also
a term equal to . For example in the case of Fig. 1.20 let these variable X, Y, Z, U
corresponding to the states q0 , q1 , q2 , q3 . The corresponding equation are
X=
Y = X1
Z = X0 + Y 0 + Z0
U = Y 1 + Z1.
If an equation is of the form X = X + , where , are arbitrary words not
containing X, then it is easy to see by a simple substitution that X = is a
solution of the equation.
Because these equations are linear, all of them can be written in the form X =
X + or X = X, where do not contain any variable. Substituting this in the
56 1. Automata and Formal Languages
0 0
R ?
- q0 10 - q2 - q3
1
*
11
00 1
j
- q0 100 1
- q3
*
11
- q0 00 1 + 100 1 + 11 - q3
xy x y
- replaced by - -
x
x+y R
- replaced by
y
x
x ?
- replaced by - -
Figure 1.25 Possible transformations to obtain finite automaton associated to a regular expression.
- r -
After this, use the transformations in Fig. 1.25 step by step, until an automaton
with labels equal to letters from or will be obtained.
Example 1.24 Get started from regular expression + (0 + 1) 1. The steps of transfor-
mations are in Fig. 1.26(a)-(e). The last finite automaton (see Fig. 1.26(e)) can be done
in a simpler form as can be seen in Fig. 1.26(f). After eliminating the -moves and trans-
forming in a deterministic finite automaton the DFA in Fig. 1.27 will be obtained, which
is equivalent to DFA in Fig. 1.19.
Exercises
1.2-1 Give a DFA which accepts natural numbers divisible by 9.
1.2-2 Give a DFA which accepts the language containing all words formed by
a. an even number of 0s and an even number of 1s,
b. an even number of 0s and an odd number of 1s,
c. an odd number of 0s and an even number of 1s,
d. an odd number of 0s and an odd number of 1s.
1.2-3 Give a DFA to accept respectively the following languages:
L1 = {an bm | n 1, m 0}, L2 = {an bm | n 1, m 1},
L3 = {a b | n 0, m 0},
n m
L4 = {an bm | n 0, m 1}.
1.2-4 Give an NFA which accepts words containing at least two 0s and any number
of 1s. Give an equivalent DFA.
1.2-5 Minimize the DFAs in Fig. 1.28.
1.2-6 Show that the DFA in 1.29.(a) is a minimum state automaton.
1.2-7 Transform NFA in Fig. 1.29.(b) in a DFA, and after this minimize it.
58 1. Automata and Formal Languages
+ (0 + 1) 1 j
- - -
*
(0 + 1) 1
(a) (b)
R R
- - - - - - -
(0 + 1) 1 1
6
0+1
(c) (d)
1
1
? R ?
- - - - - - -
1 1
6 6
0
0
(e) (f)
Figure 1.26 Associating finite automaton to regular expression + (0 + 1) 1.
0 R
- - -
0 1
6 6
0 1
a a
p - q a - 1 - 2 a
K 6 K 6
b a b a b a b a
U + j U +
b b
r s 3 - 4 b
Y
b
? 1 0 1
q0
? ? ?
66 - p 0,1 - q 0,1 -
r
a b
a b *
? ? 0,1
b j
q1 q2
Y a
(b)
(a)
Figure 1.29 Finite automata for Exercises 1.2-6 and 1.2-7.
1.2-8 Define finite automaton A1 which accepts all words of the form 0(10)n (n 0),
and finite automaton A2 which accepts all words of the form 1(01)n (n 0). Define
the union automaton A1 A2 , and then eliminate the -moves.
1.2-9 Associate to DFA in Fig. 1.30 a regular expression.
1.2-10 Associate to regular expression ab ba + b + ba a a DFA.
1.2-11 Prove, using the pumping lemma, that none of the following languages are
regular:
L1 = an cbn | n 0 , L2 = an bn an | n 0 , L3 = ap | p prm .
1.2-12 Prove that if L is a regular language, then {u1 | u L} is also regular.
1.2-13 Prove that if L is a regular language, then the following languages are
0,1 0,1
? ?
- q0 1 - q1 0 - q2 1 - q3
input
a1 a2 ... an stack
tape
- zk
6
...
z0
also regular.
pre(L) = {w | u , wu L}, suf(L) = {w | u , uw L}.
(or empty word) and stack top symbol and replace the top symbol in the stack with
a (possibly empty) word.
There are two type of acceptances. The pushdown automaton accepts a word by
final state when after reading it the automaton enter a final state. The pushdown
automaton accepts a word by empty stack when after reading it the automaton
empties its stack. We show that these two acceptances are equivalent.
: Q ( {}) W P(W Q) ,
which associate to current state, input letter and top letter in stack pairs of the form
(w, q), where w W is the word written in stack and q Q the new state.
Because the pushdown automaton is nondeterministic, we will have for the tran-
sition function
(q, a, z) = {(w1 , p1 ), . . . , (wk , pk )} (if the pushdown automaton reads an input
letter and moves to right), or
(q, , z) = {(w1 , p1 ), . . . , (wk , pk )} (without move on the input tape).
A pushdown automaton is deterministic, if for any q Q and z W we have
|(q, a, z)| 1, a {} and
if (q, , z) 6= , then (q, a, z) = , a .
We can associate to any pushdown automaton a transition table, exactly as in
the case of finite automata. The rows of this table are indexed by elements of Q, the
columns by elements from {} and W (to each a {} and z W will cor-
respond a column). At intersection of row corresponding to state q Q and column
corresponding to a {} and z W we will have pairs (w1 , p1 ), . . . , (wk , pk ) if
(q, a, z) = {(w1 , p1 ), . . . , (wk , pk )}.
The transition graph, in which the label of edge (p, q) will be (a, z/w) corre-
sponding to transition p, (a, z/w), q , can be also defined.
62 1. Automata and Formal Languages
(a, z0 /z0 z1 ): q1 (a, z1 /z1 z1 )
- q0 (b, z1 /)
Y
?
(, z0 /) q2
(b, z1 /)
Example 1.25 V1 = ({q0 , q1 , q2 }, {a, b}, {z0 , z1 }, E, q0 , z0 , {q0 }). Elements of E are:
q0 , (a, z0 /z0 z1 ), q1
q1 , (a, z1 /z1 z1 ), q1 q1 , (b, z1 /), q2
q2 , (b, z1 /), q2 q2 , (, z0 /), q0 .
(q0 , a, z0 ) = {(z0 z1 , q1 )}
(q1 , a, z1 ) = {(z1 z1 , q1 )} (q1 , b, z1 ) = {(, q2 )}
(q2 , b, z1 ) = {(, q2 )} (q2 , , z0 ) = {(, q0 )} .
{} a b
W z0 z1 z1 z0
q0 (z0 z1 , q1 )
q1 (z1 z1 , q1 ) (, q2 )
q2 (, q2 ) (, q0 )
Because for the transition function every set which is not empty contains only one element
(e.g. (q0 , a, z0 ) = {(z0 z1 , q1 )}), in the above table each cell contains only one element,
And the set notation is not used. Generally, if a set has more than one element, then its
elements are written one under other. The transition graph of this pushdown automaton is
in Fig. 1.32.
The current state, the unread part of the input word and the content of stack
1.3. Pushdown automata and context-free languages 63
Example 1.26 Pushdown automaton V1 of Example 1.25 accepts the language {an bn | n
0} by final state. Consider the derivation for words aaabbb and abab.
Word a3 b3 is accepted by the considered pushdown automaton because
(q0 , aaabbb, z0 ) = (q1 , aabbb, z0 z1 ) = (q1 , abbb, z0 z1 z1 ) = (q1 , bbb, z0 z1 z1 z1 )
= (q2 , bb, z0 z1 z1 ) = (q2 , b, z0 z1 ) = (q2 , , z0 ) = (q0 , , ) and because q0 is a final
state the pushdown automaton accepts this word. But the stack being empty, it accepts
this word also by empty stack.
64 1. Automata and Formal Languages
(0, z2 /z2 z1 )
(0, z1 /z1 z1 )
(0, z1 /)
(0, z0 /z0 z1 )
? ?
- q0 - q1
(0, z1 /)
6 (1, z2 /) 6
(, z0 /)
Because the initial state is also a final state, the empty word is accepted by final state,
but not by empty stack.
To show that word abab is not accepted, we need to study all possibilities. It is easy to
see that in our case there is only a single possibility:
(q0 , abab, z0 ) = (q1 , bab, z0 z1 ) = (q2 , ab, z0 ) = (q0 , ab, ), but there is no further
going, so word abab is not accepted.
{} 0 1
W z0 z1 z2 z0 z1 z2 z0
q1 (, q1 ) (, q1 ) (, q1 )
(q0 , 1001, z0 )
(q0 , 01, z0 z2 z1 )
(q0 , 1, z0 z2 z1 z1 ) (q1 , 1, z0 z2 )
(q0 , , z0 z2 z1 z1 z2 ) (q1 , , z0 )
(q1 , , )
Figure 1.34 Computation tree to show acceptance of the word 1001 (see Example 1.27).
(q0 , 101, z0 )
(q0 , 1, z0 z2 z1 )
(q0 , , z0 z2 z1 z2 )
Figure 1.35 Computation tree to show that the pushdown automaton in Example 1.27 does not
accept word 101.
The next two theorems prove that the class of languages accepted by nondeter-
ministic pushdown automata is just the set of context-free languages.
From-Cfg-to-Pushdown-Automaton(G)
1 for all production A
do put in E the transition q, (, A/1 ), q
2 for all terminal a T
do put in E the transition q, (a, a/), q
3 return V
If G has n productions and m terminals, then the number of step of the algorithm
is (n + m).
Example 1.28 Let G = ({S, A}, {a, b}, {S , S ab, S aAb, A aAb, A
ab}, S). Then V = ({q}, {a, b}, {a, b, A, S}, E, q, S, ), with the following transition table.
{} a b
W a b S A
(, q) (, q) (, q) (bAa, q)
q (ba, q) (ba, q)
(bAa, q)
Let us see how pushdown automaton V accepts word aabb, which in grammar G can
be derived in the following way:
S = aAb = aabb ,
where productions S aAb and A ab were used. Word is accepted by empty stack (see
Fig. 1.36).
(q, aabb, S)
(q, b, b)
(q, bb, bbbAa) (q, bb, bbba)
(q, , )
From-Pushdown-Automaton-to-Cf-Grammar(V, G)
1 for all q Q
2 do put in P production S Sq0 ,z0 ,q
3 for all q, (a, z/zk . . . z2 z1 ), p E q Q, z, z1 , z2 , . . . zk W
(k 1), a {}
4 do for all states p1 , p2 , . . . , pk
5 do put in P productions Sq,z,pk aSp,z1 ,p1 Sp1 ,z2 ,p2 . . . Spk1 ,zk ,pk
6 for All q(a, z/), p E p, q Q, z W , a {}
7 do put in P production Sq,z,p a
If the automaton has n states and m productions, then the above algorithm
executes at most n + mn + m steps, so in worst case the number of steps is O(nm).
Finally, without proof, we mention that the class of languages accepted by de-
terministic pushdown automata is a proper subset of the class of languages accepted
by nondeterministic pushdown automata. This points to the fact that pushdown
automata behave differently as finite automata.
Example 1.29 As an example, consider pushdown automaton V from the Example 1.28:
V = ({q}, {a, b}, {a, b, A, S}, E, q, S, ). Grammar G is:
G = ({S, Sa , Sb , SS , SA , }, {a, b}, P, S) ,
where for all z {a, b, S, A} instead of Sq,z,q we shortly used Sz . The transitions:
q, (a, a/), q , q, (b, b/), q ,
q, (, S/), q , q, (, S/ba), q , q, (, S/bAa), q ,
q, (, A/ba), q , q, (, A/bAa), q .
a A
a A
a A b
a b
Consider grammar:
G = ({S, A}, {a, b, c}, {S bA, S bAS, S a, A cS, A a}, S).
In this grammar word bcbaa has two different leftmost derivations:
S = bA = bcS = bcbAS = bcbaS = bcbaa,
1.3. Pushdown automata and context-free languages 71
The above grammar G is ambiguous, because word bcbaa has two different left-
most derivations. A language can be generated by more than one grammar, and
between them can exist ambiguous and unambiguous too. A context-free language
is inherently ambiguous, if there is no unambiguous grammar which generates it.
Theorem 1.29 (pumping lemma). For any context-free language L there exists a
natural number n (which depends only on L), such that every word z of the language
longer than n can be written in the form uvwxy and the following are true:
(1) |w| 1,
(2) |vx| 1,
(3) |vwx| n,
(4) uv i wxi y is also in L for all i 0.
S T
A T 00
A T0
u v w x y
Corollary 1.30 L2 L1 .
Proof This consequence states that there exists a context-sensitive language which
is not context-free. To prove this it is sufficient to find a context-sensitive language
1.3. Pushdown automata and context-free languages 73
for which the lemma is not true. Let this language be L = {am bm cm | m 1}.
To show that this language is context-sensitive it is enough to give a convenient
grammar. In Example 1.2 both grammars are extended context-sensitive, and we
know that to each extended grammar of type i an equivalent grammar of the same
type can be associated.
Let n be the natural number associated to L by lemma, and consider the word
z = an bn cn . Because of |z| = 3n > n, if L is context-free z can be decomposed in
z = uvwxy such that conditions (1)(4) are true. We show that this leads us to a
contradiction.
Firstly, we will show that word v and x can contain only one type of letters.
Indeed if either v or x contain more than one type of letters, then in word uvvwxxy
the order of the letters will be not the order a, b, c, so uvvwxxy 6 L(G), which
contradicts condition (4) of lemma.
If both v and x contain at most one type of letters, then in word uwy the
number of different letters will be not the same, so uwy 6 L(G). This also contradicts
condition (4) in lemma. Therefore L is not context-free.
Corollary 1.31 The class of context-free languages is not closed under the inter-
section.
Proof We give two context-free languages which intersection is not context-free. Let
N = {S, A, B}, T = {a, b, c} and
G1 = (N, T, P1 , S) where P1 :
S AB,
A aAb | ab,
B cB | c,
and G2 = (N, T, P2 , S), where P2 :
S AB,
A Aa | a,
B bBc | bc.
Languages L(G1 ) = {an bn cm | n 1, m 1} and L(G2 ) = {an bm cm | n 1, m
1} are context-free. But
Example 1.31 Grammar G = ({S, A, B, C}, {a, b}, {S AB, S CB, C AS, A
a, B b}, S) is in Chomsky normal form and L(G) = {an bn | n 1}.
Example 1.32 Let G = ({S, D}, {a, b, c}, {S aSc, S D, D bD, D b}, S). It is
easy to see that L(G) = {an bm cn | n 0, m 1}. Steps of transformation to Chomsky
normal form are the following:
Step 1: N 0 = {S, D}
Step 2: After eliminating the unit production S D the productions are:
S aSc | bD | b,
D bD | b.
Step 3: We introduce three new nonterminals because of the three terminals in productions.
Let these be A, B, C. Then the production are:
S ASC | BD | b,
D BD | b,
A a,
B b,
C c.
Step 4: Only one new nonterminal (let this E) must be introduced because of a single
production with three letters in the right-hand side. Therefore N 0 = {S, A, B, C, D, E},
1.3. Pushdown automata and context-free languages 75
Example 1.33 Grammar G = ({S, B}, {a, b}, {S aB, S aSB, B b}, S) is in
Greibach normal form and L(G) = {an bn | n 1}.
Greibach-Normal-Form(G)
1 N0 N
2 P0 P
3 for i 2 to n Case Ai Aj x, j < i
4 do for j 1 to i 1
5 do for all productions Ai Aj x and Aj (where has no Aj
as first letter) in P 0 productions Ai x,
delete from P 0 productions Ai Aj x
6 if there is a production Ai Ai x Case Ai Ai x
7 then put in N 0 the new nonterminal Bi ,
for all productions Ai Ai x put in P 0 productions Bi xBi
and Bi x,delete from P 0 production Ai Ai x,
for all production Ai (where Ai is not the first letter of )
put in P 0 production Ai Bi
8 for i n 1 downto 1 Case Ai Aj x, j > i
9 do for j i + 1 to n
10 do for all productions Ai Aj x and Aj
put in P 0 production Ai x and
delete from P 0 productions Ai Aj x,
76 1. Automata and Formal Languages
11 for i 1 to n Case Bi Aj x
12 do for j 1 to n
13 do for all productions Bi Aj x and Aj
put in P 0 production Bi x and
delete from P 0 productions Bi Aj x
14 return G 0
Exercises
1.3-1 Give
pushdown automata
to accept the following languages:
L1 = an cbn | n 0 ,
L2 = an b2n | n 1 ,
L3 = a2n bn | n 0 an b2n | n 0 ,
1.3-2 Give a context-free grammar to generate language L = {an bn cm | n 1, m
1}, and transform it in Chomsky and Greibach normal forms. Give a pushdown
automaton which accepts L.
Problems
Chapter Notes
In the definition of finite automata instead of transition function we have used the
transition graph, which in many cases help us to give simpler proofs.
There exist a lot of classical books on automata and formal languages. We men-
tion from these the following: two books of Aho and Ullman [6, 7] in 1972 and 1973,
book of Gcseg and Pek [83] in 1972, two books of Salomaa [215, 216] in 1969 and
1973, a book of Hopcroft and Ullman [112] in 1979, a book of Harrison [104] in 1978,
a book of Manna [168], which in 1981 was published also in Hungarian. We notice
also a book of Sipser [236] in 1997 and a monograph of Rozenberg and Salomaa
[214]. In a book of Lothaire (common name of French authors) [160] on combina-
torics of words we can read on other types of automata. Paper of Giammarresi and
Montalbano [88] generalise the notion of finite automata. A new monograph is of
Hopcroft, Motwani and Ullman [111]. In German we recommend the textbook of
Asteroth and Baier [14]. The concise description of the transformation in Greibach
normal form is based on this book.
A practical introduction to formal languages is written by Webber [?].
Other books in English: [31, 39, 67, 138, 145, 153, 158, 159, 171, 179, 233, 234,
245, 246].
At the end of the next chapter on compilers another books on the subject are
mentioned.
2. Compilers
When a programmer writes down a solution of her problems, she writes a program
on a special programming language. These programming languages are very different
from the proper languages of computers, from the machine languages. Therefore
we have to produce the executable forms of programs created by the programmer. We
need a software or hardware tool, that translates the source language program
written on a high level programming language to the target language program,
a lower level programming language, mostly to a machine code program.
There are two fundamental methods to execute a program written on higher
level language. The first is using an interpreter. In this case, the generated machine
code is not saved but executed immediately. The interpreter is considered as a special
computer, whose machine code is the high level language. Essentially, when we use an
interpreter, then we create a two-level machine; its lower level is the real computer, on
which the higher level, the interpreter, is built. The higher level is usually realized
by a computer program, but, for some programming languages, there are special
hardware interpreter machines.
The second method is using a compiler program. The difference of this method
from the first is that here the result of translation is not executed, but it is saved in
an intermediate file called target program.
The target program may be executed later, and the result of the program is
received only then. In this case, in contrast with interpreters, the times of translation
and execution are distinguishable.
In the respect of translation, the two translational methods are identical, since
the interpreter and the compiler both generate target programs. For this reason
we speak about compilers only. We will deal the these translator programs, called
compilers (Figure 2.1).
Our task is to study the algorithms of compilers. This chapter will care for
the translators of high level imperative programming languages; the translational
methods of logical or functional languages will not be investigated.
First the structure of compilers will be given. Then we will deal with scanners,
that is, lexical analysers. In the topic of parsers syntactic analysers , the two most
successful methods will be studied: the LL(1) and the LALR(1) parsing methods.
The advanced methods of semantic analysis use O-ATG grammars, and the task of
code generation is also written by this type of grammars. In this book these topics
are not considered, nor we will study such important and interesting problems as
symbol table handling, error repairing or code optimising. The reader can find very
new, modern and efficient methods for these methods in the bibliography.
source
program
source code
handler ?compiler?
handler
target
list program
ANALYSIS SYNTHESIS
scanner
parser code
generator
semantic code
analyzer optimizer
The third program of the analysis is the semantic analyser. Its task is to check
the static semantics. For example, when the semantic analyser checks declarations
and the types of variables in the expression a + b, it verifies whether the variables
a and b are declared, do they are of the same type, do they have values? The errors
detected by this program are the semantic errors.
The output of the semantic analyser is the input of the programs of synthesis.
The first step of the synthesis is the code generation, that is made by the code
generator:
The target code usually depends on the computer and the operating system. It is
usually an assembly language program or machine code. The next step of synthesis
is the code optimisation:
The code optimiser transforms the target code on such a way that the new code is
better in many respect, for example running time or size.
As it follows from the considerations above, a compiler consists of the next
components (the structure of the ?compiler? program is in the Figure 2.3):
semantic errors),
code generator (analysed program)(target code),
code optimiser (target code)(target code),
code handler(target code)(target program).
The algorithm of the part of the compiler, that performs analysis and synthesis,
is the next:
?Compiler?
1 determine the symbolic items in the text of source program
2 check the syntactic correctness of the series of symbols
3 check the semantic correctness of the series of symbols
4 generate the target code
5 optimise the target code
The objects written in the first two points will be analysed in the next sections.
Exercises
2.1-1 Using the above notations, give the structure of interpreters.
2.1-2 Take a programming language, and write program details in which there are
lexical, syntactic and semantic errors.gyakindexerror!lexical
2.1-3 Give respects in which the code optimiser can create better target code than
the original.
codes and the attributes of a symbols are written in this series, immediately after
the code of the symbol concerned.
The output information of the lexical analyser is not readable: it is usually
a series of binary codes. We note that, in the viewpoint of the compiler, from this
step of the compilation it is no matter from which characters were made the symbol,
i.e. the code of the if symbol was made form English if or Hungarian ha or German
wenn characters. Therefore, for a program language using English keywords, it is
easy to construct another program language using keywords of another language. In
the compiler of this new program language the lexical analysis would be modified
only, the other parts of the compiler are unchanged.
1. describe symbolic units in the language of regular expressions, and from this
information construct the deterministic finite automaton which is equivalent to
these regular expressions,
2. implement this deterministic finite automaton.
We note that, in writing of symbols regular expressions are used, because they are
more comfortable and readable then regular grammars. There are standard programs
as the lex of UNIX systems, that generate a complete syntactical analyser from
regular expressions. Moreover, there are generator programs that give the automaton
of scanner, too.
A very trivial implementation of the deterministic finite automaton uses mul-
tidirectional case instructions. The conditions of the branches are the characters
of state transitions, and the instructions of a branch represent the new state the
automaton reaches when it carries out the given state transition.
The main principle of the lexical analyser is building a symbol from the longest
series of symbols. For example the string ABC is a three-letters symbol, rather than
three one-letter symbols. This means that the alternative instructions of the case
branch read characters as long as they are parts of a constructed symbol.
Functions can belong to the final states of the automaton. For example, the
function converts constant symbols into an inner binary forms of constants, or the
function writes identifiers to the symbol table.
The input stream of the lexical analyser contains tabulators and space characters,
since the source-handler expunges the carriage return and line feed characters only.
86 2. Compilers
D
D
D
(space | tab) ,
where space and the tab tabulator are the characters which build the white space
symbols and | is the symbol for the or function. No actions have to make with
this white space symbols, the scanner does not pass these symbols to the syntactic
analyser.
Some examples for regular expression:
Example 2.1 Introduce the following notations: Let D be an arbitrary digit, and let L be
an arbitrary letter,
the not-visible characters are denoted by their short names, and let be the name of the
empty character stream. Not(a) denotes a character distinct from a. The regular expressions
are:
1. real number: (+ | | )D+ .D+ (e(+ | | )D+ | ),
2. positive integer and real number: (D+ ( | .)) | (D .D+ ),
3. identifier: (L | _ )(L | D | _ ) ,
4. comment: - -(Not(eol)) eol,
5. comment terminated by ## : ##((# | )Not(#)) ##,
6. string of characters: (Not() | ) .
Deterministic finite automata constructed from regular expressions 2 and 3 are in
Figures 2.4 and 2.5.
The task of lexical analyser is to determine the text of symbols, but not all the
characters of a regular expression belong to the symbol. As is in the 6th example, the
first and the last " characters do not belong to the symbol. To unravel this problem,
a buffer is created for the scanner. After recognising of a symbol, the characters
2.2. Lexical analysis 87
L|_
L|D|_
_ _ eol
Not(eol)
T (Not())
T ()
of these symbols will be in the buffer. Now the deterministic finite automaton is
supplemented by a T transfer function, where T (a) means that the character a is
inserted into the buffer.
Example 2.2 The 4th and 6th regular expressions of the example 2.1 are supplemented by
the T function, automata for these expressions are in Figures 2.6 and 2.7. The automaton
of the 4th regular expression has none T function, since it recognises comments. The au-
tomaton of the 6th regular expression recognises This is a "string" from the character
string "This is a ""string""".
Now we write the algorithm of the lexical analyser given by deterministic finite
automaton. (The state of the set of one element will be denoted by the only element
of the set).
Let A = (Q, , , q0 , F ) be the deterministic finite automaton, which is the scan-
ner. We augment the alphabet with a new notion: let others be all the characters
not in . Accordingly, we modify the transition function :
0 (q, a), if a 6= others ,
(q, a) =
, otherwise .
Lex-analyse(x#, A0 )
1 q q0 , a first character of x
2 s0 analyzing
3 while a 6= # and s0 = analyzing
4 do if 0 (q, a) 6=
5 then q 0 (q, a)
6 a next character of x
7 else s0 error
8 if s0 = analyzing and q F
9 then s0 O.K.
10 else s0 ERROR
11 return s0 , a
The algorithm has two parameters: the first one is the input character string
terminated by #, the second one is the automaton of the scanner. In the line 1
the state of the scanner is set to q0 , to the start state of the automaton, and the
first character of the input string is determined. The variable s0 indicates that the
algorithm is analysing the input string, the text analysing is set in this variable in
the line 2. In the line 5 a state-transition is executed. It can be seen that the above
augmentation is needed to terminate in case of unexpected, invalid character. In line
810 the O.K. means that the analysed character string is correct, and the ERROR
signs that a lexical error was detected. In the case of successful termination the
variable a contains the # character, at erroneous termination it contains the invalid
character.
We note that the algorithm Lex-Analyse recognise one symbol only, and then
it is terminated. The program written in a programming language consists of a lot
of symbols, hence after recognising a symbol, the algorithm have to be continued by
detecting the next symbol. The work of the analyser is restarted at the state of the
automaton. We propose the full algorithm of the lexical analyser as an exercise (see
Exercise 2-1).
Example 2.3 The automaton of the identifier in the point 3 of example 2.1 is in Figure
2.5. The start state is 0, and the final state is 1. The transition function of the automaton
follows:
L _ D
0 1 1
1 1 1 1
0 L _ D others
0 1 1
1 1 1 1
2.2. Lexical analysis 89
The algorithm Lex-Analyse gives the series of states 0111111 and sign O.K. to the
input string abc123#, it gives sign ERROR to the input sting 9abc#, and the series 0111
and sign ERROR to the input string abc123.
Look ahead. Since the lexical analyser creates a symbol from the longest char-
acter stream, the lexical analyser has to look ahead one or more characters for the
allocation of the right-end of a symbol There is a classical example for this problem,
the next two FORTRAN statements:
DO 10 I = 1.1000
DO 10 I = 1,1000
In the FORTRAN programming language space-characters are not important char-
acters, they do not play an important part, hence the character between 1 and 1000
decides that the statement is a DO cycle statement or it is an assignment statement
for the DO10I identifier.
To sign the right end of the symbol, we introduce the symbol / into the descrip-
tion of regular expressions. Its name is lookahead operator. Using this symbol the
description of the above DO keyword is the next:
DO / (letter | digit) = (letter | digit) ,
This definition means that the lexical analyser says that the first two D and O letters
are the DO keyword, if looking ahead, after the O letter, there are letters or digits,
then there is an equal sign, and after this sign there are letters or digits again,
and finally, there is a , character. The lookahead operator implies that the
lexical analyser has to look ahead after the DO characters. We remark that using this
lookahead method the lexical analyser recognises the DO keyword even if there is an
error in the character stream, such as in the DO2A=3B, character stream, but in a
correct assignment statement it does not detect the DO keyword.
In the next example we concern for positive integers. The definition of integer
numbers is a prefix of the definition of the real numbers, and the definition of real
numbers is a prefix of the definition of real numbers containing explicit power-part.
positive integer : D+
positive real : D+ .D+
s D+ .D+ e(+ | | )D+
The automaton for all of these three expressions is the automaton of the longest
character stream, the real number containing explicit power-part.
The problem of the lookahead symbols is resolved using the following algorithm.
Put the character into a buffer, and put an auxiliary information aside this character.
This information is it is invalid. if the character string, using this red character,
is not correct; otherwise we put the type of the symbol into here. If the automaton
is in a final-state, then the automaton recognises a real number with explicit power-
part. If the automaton is in an internal state, and there is no possibility to read a
2.2. Lexical analysis 91
next character, then the longest character stream which has valid information is the
recognised symbol.
Example 2.4 Consider the 12.3e+f# character stream, where the character # is the endsign
of the analysed text. If in this character stream there was a positive integer number in the
place of character f, then this character stream should be a real number. The content of
the puffer of lexical analyser:
1 integer number
12 integer number
12. invalid
12.3 real number
12.3e invalid
12.3e+ invalid
12.3e+f invalid
12.3e+f#
The recognised symbol is the 12.3 real number. The lexical analysing is continued at the
text e+f.
The symbol table. There are programming languages, for example C, in which
small letters and capital letters are different. In this case the lexical analyser uses
characters of all symbols without modification. Otherwise the lexical analyser con-
verts all characters to their small letter form or all characters to capital letter form.
It is proposed to execute this transformation in the source handler program.
At the case of simpler programming languages the lexical analyser writes the
characters of the detected symbol into the symbol table, if this symbol is not there.
After writing up, or if this symbol has been in the symbol table already, the lexical
analyser returns the table address of this symbol, and writes this information into
its output. These data will be important at semantic analysis and code generation.
directives.
Exercises
2.2-1 Give a regular expression to the comments of a programming language. In
this language the delimiters of comments are / and /, and inside of a comment
may occurs / and characters, but / is forbidden.
2.2-2 Modify the result of the previous question if it is supposed that the program-
ming language has possibility to write nested comments.
2.2-3 Give a regular expression for positive integer numbers, if the pre- and post-
zero characters are prohibited. Give a deterministic finite automaton for this regular
expression.
2.2-4 Write a program, which re-creates the original source program from the out-
put of lexical analyser. Pay attention for nice an correct positions of the re-created
character streams.
LL(k) grammars Our methods build the syntax tree top-down and read symbols
of the program left to right. For this end we try to create terminals on the left side
of sentential forms.
xA = x .
lef tmost
Definition 2.5 If all of direct derivations in S = x (x T ) are leftmost, then
this derivation is said to be leftmost derivation, and
S = x.
lef tmost
In a leftmost derivation terminal symbols appear at the left side of the sentential
forms. Therefore we use leftmost derivations in all of top-down parsing methods.
Hence if we deal with top-down methods, we do not write the text leftmost at the
arrows.
One might as well say that we create all possible syntax trees. Reading leaves
from left to right, we take sentences of the language. Then we compare these sen-
tences with the parseable text and if a sentence is same as the parseable text, then we
can read the steps of parsing from the syntax tree which is belongs to this sentence.
But this method is not practical; generally it is even impossible to apply.
A good idea is the following. We start at the start symbol of the grammar, and
using leftmost derivations we try to create the text of the program. If we use a not
suitable derivation at one of steps of parsing, then we find that, at the next step,
we can not apply a proper derivation. At this case such terminal symbols are at the
left side of the sentential form, that are not same as in our parseable text.
For the leftmost terminal symbols we state the theorem as follows.
Theorem 2.6 If S = x = yz ( (N T ) , x, y, z T ) s |x| = |y|, then
x=y .
The proof of this theorem is trivial. It is not possible to change the leftmost ter-
minal symbols x of sentential forms using derivation rules of a context free grammar.
This theorem is used during the building of syntax tree, to check that the leftmost
terminals of the tree are same as the leftmost symbols of the parseable text. If they
are different then we created wrong directions with this syntax tree. At this case we
have to make a backtrack, and we have to apply an other derivation rule. If it is
2.3. Syntactic analysis 95
impossible (since for example there are no more derivation rules) then we have to
apply a backtrack once again.
General top-down methods are realized by using backtrack algorithms, but these
backtrack steps make the parser very slow. Therefore we will deal only with gram-
mars such that have parsing methods without backtracks.
The main properties of LL(k) grammars are the following. If, by creating the
leftmost derivation S = wx (w, x T ), we obtain the sentential form S = wA
(A N, (N T ) ) at some step of this derivation, and our goal is to achieve
A = x, then the next step of the derivation for nonterminal A is determinable
unambiguously from the first k symbols of x.
To look ahead k symbols we define the function First k .
Firstk () =
{x | = x and |x| = k} and |x| = k} {x | = x and |x| < k}
(x T , (N T ) ) .
The set Firstk (x) consists of the first k symbols of x; for |x| < k, it consists the
full x. If = , then Firstk ().
(A N, x, y, w T , 1 , 2 , (N T ) ) the equality
implies
1 = 2 .
Using this definition, if a grammar is a LL(k) grammar then the k symbol after
the parsed x determine the next derivation rule unambiguously (Figure 2.8).
One can see from this definition that if a grammar is an LL(k0 ) grammar then
for all k > k0 it is also an LL(k) grammar. If we speak about LL(k) grammar then
we also mean that k is the least number such that the properties of the definition
are true.
Example 2.5 The next grammar is a LL(1) grammar. Let G = ({A, S}, {a, b}, P, S) be a
grammar whose derivation rules are:
S AS |
A aA | b
We have to use the derivation S AS for the start symbol S if the next symbol of the
parseable text is a or b. We use the derivation S if the next symbol is the mark #.
96 2. Compilers
w A
w x
7k
Figure 2.8 LL(k) grammar.
Example 2.6 The next grammar is a LL(2) grammar. Let G = ({A, S}, {a, b}, P, S) be a
grammar whose the derivation rules are:
S abA |
A Saa | b
One can see that at the last step of derivations
SabA
S = abA = abSaa = ababAaa
and
S
S = abA = abSaa = abaa
if we look ahead one symbol, then in both derivations we obtain the symbol a. The proper
rule for symbol S is determined to look ahead two symbols (ab or aa).
There are context free grammars such that are not LL(k) grammars. For example
the next grammar is not LL(k) grammar for any k.
Example 2.7 Let G = ({A, B, S}, {a, b, c}, P, S) be a grammar whose the derivation rules
are:
SA|B
A aAb | ab
B aBc | ac
L(G) consists of sentences ai bi s ai ci (i 1). If we analyse the sentence ak+1 bk+1 , then
at the first step we can not decide by looking ahead k symbols whether we have to use the
derivation S A or S B, since for all k Firstk (ak bk ) = Firstk (ak ck ) = ak .
By the definition of the LL(k) grammar, if we get the sentential form wA using
leftmost derivations, then the next k symbol determines the next rule for symbol A.
This is stated in the next theorem.
implies
Firstk () Firstk () = .
2.3. Syntactic analysis 97
If there is a A rule in the grammar, then the set Firstk consists the k
length prefixes of terminal series generated from . It implies that, for deciding the
property LL(k), we have to check not only the derivation rules, but also the infinite
derivations.
We can give good methods, that are used in the practice, for LL(1) grammars
only. We define the follower-series, which follow a symbol or series of symbols.
Definition 2.10 Followk () = {x | S = and x Firstk ()}, and if
Followk (), then Followk () = Followk () \ {} {#} (, , (N T ) , x T )
.
The second part of the definition is necessary because if there are no symbols
after the in the derivation , that is = , then the next symbol after is the
mark # only.
Follow 1 (A) (A N ) consists of terminal symbols that can be immediately after
the symbol A in the derivation
S = A = Aw (, (N T ) , w T ).
Theorem 2.11 The grammar G is a LL(1) grammar iff, for all nonterminal A and
for all derivation rules A | ,
In this theorem the expression First1 (Follow1 (A)) means that we have to con-
catenate to the elements of set Follow1 (A) separately, and for all elements of this
new set we have to apply the function First1 .
It is evident that Theorem 2.11 is suitable to decide whether a grammar is LL(1)
or it is not.
Hence forward we deal with LL(1) languages determined by LL(1) grammars,
and we investigate the parsing methods of LL(1) languages. For the sake of simplicity,
we omit indexes from the names of functions First1 s Follow1 .
The elements of the set First() are determined using the next algorithm.
First()
1 if =
2 then F {}
3 if = a, where a T
4 then F {a}
98 2. Compilers
5 if = A, where A N
6 then if A P
7 then F {}
8 else F
9 for all A Y1 Y2 . . . Ym P (m 1)
10 do F F (First(Y1 ) \ {})
11 for k 1 to m 1
12 do if Y1 Y2 . . . Yk =
13 then F F (First(Yk+1 ) \ {})
14 if Y1 Y2 . . . Ym =
15 then F F {}
16 if = Y1 Y2 . . . Ym (m 2)
17 then F (First(Y1 ) \ {})
18 for k 1 to m 1
19 do if Y1 Y2 . . . Yk =
20 then F F (First(Yk+1 ) \ {})
21 if Y1 Y2 . . . Ym =
22 then F F {}
23 return F
In lines 14 the set is given for and a terminal symbol a. In lines 515 we
construct the elements of this set for a nonterminal A. If is derivated from A then
we put symbol into the set in lines 67 and 1415. If the argument is a symbol
stream then the elements of the set are constructed in lines 1622. We notice that
we can terminate the for cycle in lines 11 and 18 if Yk T , since in this case it is
not possible to derive symbol from Y1 Y2 . . . Yk .
In Theorem 2.11 and hereafter, it is necessary to know the elements of the set
Follow(A). The next algorithm constructs this set.
Follow(A)
1 if A = S
2 then F {#}
3 else F
4 for all rules B A P
5 do if || > 0
6 then F F (First() \ {})
7 if =
8 then F F Follow(B)
9 else F F Follow(B)
10 return F
The elements of the Follow(A) set get into the set F . In lines 49 we check that,
if the argumentum is at the right side of a derivation rule, what symbols may stand
immediately after him. It is obvious that no is in this set, and the symbol # is in
2.3. Syntactic analysis 99
S S
x B x b
x ay x ay
the set only if the argumentum is the rightmost symbol of a sentential form.
Parsing with table Suppose that we analyse a series of terminal symbols xay
and the part x has already been analysed without errors. We analyse the text with a
top-down method, so we use leftmost derivations. Suppose that our sentential form
is xY , that is, it has form xB or xb (Y (N T ), B N, a, b T, x, y
T , (N T ) ) (Figure 2.9).
In the first case the next step is the substitution of symbol B. We know the next
element of the input series, this is the terminal a, therefore we can determine the
correct substitution of symbol B. This substitution is the rule B for which
a First(Follow(B)). If there is such a rule then, according to the definition of
LL(1) grammar, there is exactly one. If there is not such a rule, then a syntactic
error was found.
In the second case the next symbol of the sentential form is the terminal symbol
b, thus we look out for the symbol b as the next symbol of the analysed text. If this
comes true, that is, a = b, then the symbol a is a correct symbol and we can go
further. We put the symbol a into the already analysed text. If a 6= b, then here is a
syntactic error. We can see that the position of the error is known, and the erroneous
symbol is the terminal symbol a.
The action of the parser is the following. Let # be the sign of the right end of
the analysed text, that is, the mark # is the last symbol of the text. We use a stack
through the analysing, the bottom of the stack is signed by mark #, too. We give
serial numbers to derivation rules and through the analysing we write the number
of the applied rule into a list. At the end of parsing we can write the syntax tree
from this list (Figure 2.10).
We sign the state of the parser using triples (ay#, X#, v). The symbol ay# is
the text not analysed yet. X# is the part of the sentential form corresponding to
the not analysed text; this information is in the stack, the symbol X is at the top
of the stack. v is the list of the serial numbers of production rules.
If we analyse the text then we observe the symbol X at the top of the stack,
and the symbol a that is the first symbol of the not analysed text. The name of
the symbol a is actual symbol. There are pointers to the top of the stack and to the
actual symbol.
We use a top down parser, therefore the initial content of the stack is S#. If the
initial analysed text is xay, then the initial state of the parsing process is the triple
100 2. Compilers
x a y #
6
X parser
?
v
#
LL(1)-Table-Fill-in(G)
1 for all A N
2 do if A P the i-th rule
3 then for all a First()- ra
4 do T [A, a] (, i)
5 if First()
6 then for all a Follow(A)
7 do T [A, a] (, i)
8 for all a T
9 do T [a, a] pop
10 T [#, #] accept
11 for all X (N T {#}) and all a (T {#})
12 do if T [X, a] = empty
13 then T [X, a] error
14 return T
At the line 10 we write the text accept into the right lower corner of the table. At
2.3. Syntactic analysis 101
the lines 89 we write the text pop into the main diagonal of the square labelled by
terminal symbols. The program in lines 17 writes a tuple in which the first element
is the right part of a derivation rule and the second element is the serial number of
this rule. In lines 1213 we write error texts into the empty positions.
The actions of the parser are written by state-transitions. The initial state is
(x#, S#, ), where the initial text is x, and the parsing process will be finished if
the parser goes into the state (#, #, w), this state is the final state. If the text is ay#
in an intermediate step, and the symbol X is at the top of stack, then the possible
state-transitions are as follows.
(ay#, #, vi), ha T [X, a] = (, i) ,
(y#, #, v), ha T [X, a] = pop ,
(ay#, X#, v)
O.K., ha T [X, a] = accept ,
ERROR, ha T [X, a] = error .
The letters O.K. mean that the analysed text is syntactically correct; the text ER-
ROR means that a syntactic error is detected.
The actions of this parser are written by the next algorithm.
LL(1)-Parser(xay#, T )
1 s (xay#, S#, ), s0 analyze
2 repeat
3 if s = (ay#, A#, v) s T [A, a] = (, i)
4 then s (ay#, #, vi)
5 else if s = (ay#, a#, v)
6 then s (y#, #, v) Then T [a, a] = pop.
7 else if s = (#, #, v)
8 then s0 O.K. Then T [#, #] = accept.
9 else s0 ERROR Then T [A, a] = error.
10 until s0 = O.K. or s0 = ERROR
11 return s0 , s
The input parameters of this algorithm are the text xay and the parsing table
T . The variable s0 describes the state of the parser: its value is analyse, during the
analysis, and it is either O.K. or ERROR. at the end. The parser determines his
action by the actual symbol a and by the symbol at the top of the stack, using the
parsing table T . In the line 34 the parser builds the syntax tree using the derivation
rule A . In lines 56 the parser executes a shift action, since there is a symbol
a at the top of the stack. At lines 89 the algorithm finishes his work if the stack is
empty and it is at the end of the text, otherwise a syntactic error was detected. At
the end of this work the result is O.K. or ERROR in the variable s0 , and, as a result,
there is the triple s at the output of this algorithm. If the text was correct, then we
can create the syntax tree of the analysed text from the third element of the triple.
If there was an error, then the first element of the triple points to the position of
the erroneous symbol.
Example 2.8 Let G be a grammar G = ({E, E 0 , T, T 0 , F }, {+, , (, ), i}, P, E), where the
102 2. Compilers
+ * ( ) i #
E (T E 0 , 1) (T E 0 , 1)
E0 (+T E 0 , 2) (, 3) (, 3)
T (F T 0 , 4) (F T 0 , 4)
T0 (, 6) (F T 0 , 5) (, 6) (, 6)
F ((E), 7) (i, 8)
+ pop
* pop
( pop
) pop
i pop
# accept
2.3. Syntactic analysis 103
T E0
F T0 + T E0
i F T0
i F T0
Example 2.9 Using the parsing table of the previous example, analyse the text i + i i.
(T E 0 ,1)
(i + i i#, S#, ) ( i + i i#, T E 0 #, 1 )
0
(F T ,4)
( i + i i#, F T 0 E 0 #, 14 )
(i,8)
( i + i i#, iT 0 E 0 #, 148 )
pop
( +i i#, T 0 E 0 #, 148 )
(,6)
( +i i#, E 0 #, 1486 )
(+T E 0 ,2)
( +i i#, +T E 0 #, 14862 )
pop
( i i#, T E 0 #, 14862 )
(F T 0 ,4)
( i i#, F T 0 E 0 #, 148624 )
(i,8)
( i i#, iT 0 E 0 #, 1486248 )
pop
( i#, T 0 E 0 #, 1486248 )
(F T 0 ,5)
( i#, F T 0 E 0 #, 14862485 )
pop
( i#, F T 0 E 0 #, 14862485 )
(i,8)
( i#, iT 0 E 0 #, 148624858 )
pop
( #, T 0 E 0 #, 148624858 )
(,6)
( #, E 0 #, 1486248586 )
(,3)
( #, #, 14862485863 )
accept
O.K.
procedure Check(a);
begin
if actual_symbol = a
then Next_symbol
else Error_report
end;
The procedure Next_symbol reads the next symbol, it is a call for the lexical
analyser. This procedure determines the next symbol and put this symbol into the
actual_symbol variable. The procedure Error_report creates an error report and
then finishes the parsing.
We create procedures to symbols of the grammar as follows. The procedure of
the nonterminal symbol A is the next.
procedure A;
begin
T(A)
end;
where T(A) is determined by symbols of the right part of derivation rule having
symbol A in its left part.
The grammars which are used for syntactic analysis are reduced grammars. It
means that no unnecessary symbols in the grammar, and all of symbols occur at the
left side at least one reduction rule. Therefore, if we consider the symbol A, there is
at least one A production rule.
1. If there is only one production rule for the symbol A,
T(X_n)
end;
2. If there are more rules for the symbol A:
case actual_symbol of
First(alpha_1) : T(alpha_1);
First(alpha_2) : T(alpha_2);
...
First(alpha_n) : T(alpha_n)
end;
We note that this is the first point of the method of recursive-descent parser
where we use the fact that the grammar is an LL(1) grammar.
case actual_symbol of
First(alpha_1) : T(alpha_1);
First(alpha_2) : T(alpha_2);
...
First(alpha_(n-1)) : T(alpha_(n-1));
Follow(A) : skip
end;
Create-Rec-Desc(G)
1 P
2 Write-Program(
3 procedure Check(a);
4 begin
5 if actual_symbol = a
6 then Next_symbol
7 else Error_report
8 end;
9 )
10 for all symbol A N of the grammar G
11 do if A = S
12 then Write-Program(
13 program S;
14 begin
15 Rec-Desc-Stat(S, P )
16 end;
17 )
18 else Write-Program(
19 procedure A;
20 begin
21 Rec-Desc-Stat(A, P )
22 end;
23 )
24 return P
The algorithm creates the Check procedure in lines 29/ Then, for all nontermi-
nals of grammar G, it determines their procedures using the algorithm Rec-Desc-
Stat. In the lines 1117, we can see that for the start symbol S we create the main
program. The output of the algorithm is the parsing program.
Rec-Desc-Stat(A, P )
1 if there is only one rule A
2 then Rec-Desc-Stat1(, P ) A .
3 else Rec-Desc-Stat2(A, (1 , . . . , n ), P ) A 1 | | n .
4 return P
The form of the statements of the parsing program depends on the derivation
rules of the symbol A. Therefore the algorithm Rec-Desc-Stat divides the next
tasks into two parts. The algorithm Rec-Desc-Stat1 deals with the case when
there is only one derivation rule, and the algorithm Rec-Desc-Stat2 creates the
program for the alternatives.
2.3. Syntactic analysis 107
Rec-Desc-Stat1(, P )
1 if = a
2 then Write-Program(
3 Check(a)
4 )
5 if = B
6 then Write-Program(
7 B
8 )
9 if = X1 X2 . . . Xn (n 2)
10 then Write-Program(
11 begin
12 Rec-Desc-Stat1(X1 , P ) ;
13 Rec-Desc-Stat1(X2 , P ) ;
14 ...
15 Rec-Desc-Stat1(Xn , P )
16 end;
17 return P
Rec-Desc-Stat2(A, (1 , . . . , n ), P )
1 if the rules 1 , . . . , n are - free
2 then Write-Program(
3 case actual_symbol of
4 First(alpha_1) : Rec-Desc-Stat1 (1 , P ) ;
5 ...
6 First(alpha_n) : Rec-Desc-Stat1 (n , P )
7 end;
8 )
9 if there is a -rule, i = (1 i n)
10 then Write-Program(
11 case actual_symbol of
12 First(alpha_1) : Rec-Desc-Stat1 (1 , P ) ;
13 ...
14 First(alpha_(i-1)) : Rec-Desc-Stat1 (i1 , P ) ;
15 Follow(A) : skip;
16 First(alpha_(i+1)) : Rec-Desc-Stat1 (i+1 , P ) ;
17 ...
18 First(alpha_n) : Rec-Desc-Stat1 (1 , P )
19 end;
20 )
21 return P
mark #. If the start symbol of the grammar is S, then we create the new rule
S 0 S#, where the new symbol S 0 is the start symbol of our new grammar. The
mark # is considered as terminal symbol. Then we generate the parsing program
for this new grammar.
Example 2.10 We augment the grammar of the Example 2.8 in the above manner. The
production rules are as follows.
S 0 E#
E T E0
E 0 +T E 0 |
T FT0
T 0 F T 0 |
F (E) | i
In the example 2.8 we give the necessary First and Follow sets. We use the next sets:
First(+T E 0 ) = {+},
First(F T 0 ) = {},
First((E)) = {(},
First(i) = {i},
Follow(E 0 ) = {), #},
Follow(T 0 ) = {+, ), #}.
In the comments of the program lines we give the using of these sets. The first characters
of the comment are the character pair --.
The program of the recursive-descent parser is the following.
program S;
begin
E;
Check(#)
end.
procedure E;
begin
T;
E
end;
procedure E;
begin
case actual_symbol of
+ : begin -- First(+TE)
Check(+);
T;
E
end;
),# : skip -- Follow(E)
end
end;
procedure T;
begin
F;
T
end;
2.3. Syntactic analysis 109
procedure T;
begin
case actual_symbol of
* : begin -- First(*FT)
Check(*);
F;
T
end;
+,),# : skip -- Follow(T)
end
end;
procedure F;
begin
case actual_symbol of
( : begin -- First((E))
Check(();
E;
Check())
end;
i : Check(i) -- First(i)
end
end;
We can see that the main program of this parser belongs to the symbol S 0 .
Ax = x .
rightmost
Definition 2.13 If the derivation S = x (x T ) all of the substitutions were
rightmost substitution, then this derivation is a rightmost derivation,
S = x.
rightmost
110 2. Compilers
In a rightmost derivation, terminal symbols are at the right side of the sentential
form. By the connection of the notion of the handle and the rightmost derivation, if
we apply the steps of a rightmost derivation backwards, then we obtain the steps of a
bottom-up parsing. Hence the bottom-up parsing is equivalent with the inverse
of a rightmost derivation. Therefore, if we deal with bottom-up methods, we will not
write the text "rightmost" at the arrows.
General bottom-up parsing methods are realized by using backtrack algorithms.
They are similar to the top-down parsing methods. But the backtrack steps make
the parser very slow. Therefore we only deal with grammars such that have parsing
methods without backtracks.
Hence forward we produce a very efficient algorithm for a large class of context-
free grammars. This class contains the grammars for the programming languages.
The parsing is called LR(k) parsing; the grammar is called LR(k) grammar. LR
means the "Left to Right" method, and k means that if we look ahead k symbols then
we can determine the handles of the sentential forms. The LR(k) parsing method is
a shift-reduce method.
We deal with LR(1) parsing only, since for all LR(k) (k > 1) grammar there is
an equivalent LR(1) grammar. This fact is very important for us since, using this
type of grammars, it is enough to look ahead one symbol in all cases.
Creating LR(k) parsers is not an easy task. However, there are such standard
programs (for example the yacc in UNIX systems), that create the complete parsing
program from the derivation rules of a grammar. Using these programs the task of
writing parsers is not too hard.
After studying the LR(k) grammars we will deal with the LALR(1) parsing
method. This method is used in the compilers of modern programming languages.
G0 = (N {S 0 }, T, P {S 0 S}, S 0 ) .
Assign serial numbers to the derivation rules of grammar, and let S 0 S be the
0th rule. Using this numbering, if we apply the 0th rule, it means that the parsing
process is concluded and the text is correct.
We notice that if the original start symbol S does not happen on the right side
of any rules, then there is no need for this augmentation. However, for the sake of
generality, we deal with augmented grammars only.
S0 S0
A w B x
w x
7k y
7k
Figure 2.12 The LR(k) grammar.
implies
= , A = B s x = y .
Example 2.11 Let G0 = ({S 0 , S}, {a}, P 0 , S 0 ) be a grammar and let the derivation rules
be as follows.
S0 S
S Sa | a
This grammar is not an LR(0) grammar, since using notations of the definition, in the
derivations
S 0 = S 0 = S ,
A w w
S 0 = S 0 = Sa = S a,
B x x y
Example 2.12
The next grammar is a LR(1) grammar. G = ({S 0 , S}, {a, b}, P 0 , S 0 ), the derivation
rules are:
S0 S
112 2. Compilers
S SaSb | .
In the next example we show that there is a context-free grammar, such that is
not LR(k) grammar for any k (k 0).
Example 2.13 Let G0 = ({S 0 , S}, {a}, P 0 , S 0 ) be a grammar and let the derivation rules
be
S0 S
S aSa | a
Now for all k (k 0)
S 0 = ak Sak = ak aak = a2k+1 ,
S 0 = ak+1 Sak+1 = ak+1 aak+1 = a2k+3 ,
and
Firstk (ak ) = Firstk (aak+1 ) = ak ,
but
ak+1 Sak+1 6= ak Sak+2 .
It is not sure that, for a LL(k) (k > 1) grammar, we can find an equivalent
LL(1) grammar. However, LR(k) grammars have this nice property.
Theorem 2.16 For all LR(k) (k > 1) grammar there is an equivalent LR(1) gram-
mar.
The great significance of this theorem is that it makes sufficient to study the
LR(1) grammars instead of LR(k) (k > 1) grammars.
LR(1) canonical sets Now we define a very important notion of the LR parsings.
Example 2.14 Let G0 = ({E, T, S 0 }, {i, +, (, )}, P 0 , S 0 ) be a grammar and the derivation
rule as follows.
(0) S 0 E
(1) E T
(2) E E + T
(3) T i
(4) T (E)
E + (i + i) is a sentential form, and the first i is the handle. The viable prefixes of this
sentential form are E, E+, E + (, E + (i.
By the above definition, symbols after the handle are not parts of any viable
prefix. Hence the task of finding the handle is the task of finding the longest viable
prefix.
For a given grammar, the set of viable prefixes is determined, but it is obvious
that the size of this set is not always finite.
2.3. Syntactic analysis 113
. a
The significance of viable prefixes are the following. We can assign states of a
deterministic finite automaton to viable prefixes, and we can assign state transitions
to the symbols of the grammar. From the initial state we go to a state along the
symbols of a viable prefix. Using this property, we will give a method to create an
automaton that executes the task of parsing.
[A ., a] , (a T {#}) ,
Example 2.15 Let G0 = ({S 0 , S, A}, {a, b}, P 0 , S 0 ) a grammar and the derivation rules as
follows.
(0) S 0 S
(1) S AA
(2) A aA
(3) A b
Using these rules, we can derive S 0 = aaAab = aaaAab. Here aaa is a viable prefix,
and [A a.A, a] is valid for this viable prefix. Similarly, S 0 = AaA = AaaA, and
LR(1)-item [A a.A, #] is valid for viable prefix Aaa.
Definition 2.20 Let the set H be a set of LR(1)-items for a given grammar. The
set closure(H) consists of the next LR(1)-items:
1. every element of the set H is an element of the set closure(H),
114 2. Compilers
S0
A a x
. B a x
. a x
Closure-Set-of-Items(H)
1 K
2 for all E H LR(1)-item
3 do K K Closure-Item(E)
4 return K
Closure-Item(E)
1 KE {E}
2 if the LR(1)-item E has form [A .B, a]
3 then I
4 J KE
2.3. Syntactic analysis 115
5 repeat
6 for for all LR(1)-items J which have form [C .D, b]
7 do for for all rules D P
8 do for for all symbols c First(b)
9 do I I [D ., c]
10 J I
11 if I 6=
12 then KE KE I
13 I
14 until J 6=
15 return KE
Definition 2.21 Let H be a set of LR(1)-items for the grammar G. Then the set
read(H, X) (X (N T )) consists of the following LR(1)-items.
1. if [A .X, a] H, then all items of the set closure([A X., a]) are in
read(H, X),
2. the set read(H, X) is extended using step 1 until no more items can be added to
it.
The function read(H, X) "reads symbol X" in items of H, and after this operation
the sign "point" in the items gets to the right side of X. If the set H contains the
valid LR(1)-items for the viable prefix then the set read(H, X) contains the valid
LR(1)-items for the viable prefix X.
The algorithm Read-set-of-items executes the function read. The result is the
set K.
Read-Set(H, Y )
1 K
2 for all E H
3 do K K Read-item(E, Y )
4 return K
116 2. Compilers
Read-Item(E, Y )
1 if E = [A .X, a] and X = Y
2 then KE,Y Closure-Item([A X., a])
3 else KE,Y
4 return KE,Y
Using these algorithms we can create all of items which writes the state after
reading of symbol Y .
Now we introduce the following notation for LR(1)-items, to give shorter de-
scriptions. Let
[A .X, a/b]
be a notation for items
Example 2.16 The LR(1)-item [S 0 .S, #] is an item of the grammar in the example
2.15. For this item
closure( S 0 .S, # ) = { S 0 .S, # , [S .AA, #] , [A .aA, a/b] , [A .b, a/b]} .
The number of elements of LR(1)-items for a grammar is finite, hence the above
method is terminated in finite time.
The next algorithm creates canonical sets of the grammar G.
2.3. Syntactic analysis 117
Create-Canonical-Sets(G)
1 i0
2 Hi Closure-Item([S 0 .S, #])
3 I {Hi }, K {Hi }
4 repeat
5 LK
6 for all M I-re
7 do I I \ M
8 for all X T N -re
9 do J Closure-Set-of-Items(Read-Set(M, X))
10 if J 6= and J 6 K
11 then i i + 1
12 Hi J
13 K K {Hi }
14 I I {Hi }
15 until K = L
16 return K
The result of the algorithm is K. The first canonical set is the set H0 in the line
2. Further canonical sets are created by functions Closure-Set-of-Items(Read-
Set) in the line 9. The program in the line 10 checks that the new set differs from
previous sets, and if the answer is true then this set will be a new set in lines 1112.
The for cycle in lines 614 guarantees that these operations are executed for all sets
previously generated. In lines 314 the repeat cycle generate new canonical sets as
long as it is possible.
Example 2.17 The canonical sets of LR(1)-items for the Example 2.15 are as follows.
1 5
S A a
A a A
0 2 6 9
b
b
a
7
a
b
A
3 8
H0 , H1 , . . . , Hm
were created, then assign the state k of an automaton to the set Hk . Relation between
the states of the automaton and the canonical sets of LR(1)-items is stated by the
next theorem. This theorem is the great theorem of the LR(1)-parsing.
Theorem 2.23 The set of the LR(1)-items being valid for a viable prefix can be
assigned to the automaton-state k such that there is path from the initial state to
state k labeled by gamma.
This theorem states that we can create the automaton of the parser using canon-
ical sets. Now we give a method to create this LR(1) parser from canonical sets of
LR(1)-items.
The deterministic finite automaton can be described with a table, that is called
LR(1) parsing table. The rows of the table are assigned to the states of the automa-
ton.
2.3. Syntactic analysis 119
The parsing table has two parts. The first is the action table. Since the operations
of parser are determined by the symbols of analysed text, the action table is divided
into columns labeled by the terminal symbols. The action table contains information
about the action performing at the given state and at the given symbol. These actions
can be shifts or reductions. The sign of a shift operation is sj, where j is the next
state. The sign of the reduction is ri, where i is the serial number of the applied rule.
The reduction by the rule having the serial number zero means the termination of
the parsing and that the parsed text is syntactically correct; for this reason we call
this operation accept.
The second part of the parsing table is the goto table. In this table are infor-
mations about shifts caused by nonterminals. (Shifts belong to terminals are in the
action table.)
Let {0, 1, . . . , m} be the set of states of the automata. The i-th row of the table
is filled in from the LR(1)-items of canonical set Hi .
The i-th row of the action table:
if [A .a, b] Hi and read(Hi , a) = Hj then action[i, a] = sj,
In both table we have to write the text error into the empty positions.
These action and goto tables are called canonical parsing tables.
Theorem 2.24 The augmented grammar G0 is LR(1) grammar iff we can fill in
the parsing tables created for this grammar without conflicts.
x a y #
6
X k parser
# 0
Fill-in-LR(1)-Table(G)
1 for all LR(1) canonical sets Hi
2 do for all LR(1)-items
3 if [A .a, b] Hi and read(Hi , a) = Hj
4 then action[i, a] = sj
5 if [A ., a] Hi and A 6= S 0 and A the l-th rule
6 then action[i, a] = rl
7 if [S 0 S., #] Hi
8 then action[i, #] = accept
9 if read(Hi , A) = Hj
10 then goto[i, A] = j
11 for all a (T {#})
12 do if action[i, a] = empty
13 then action[i, a] error
14 for all X N
15 do if goto[i, X] = empty
16 then goto[i, X] error
17 return action, goto
We fill in the tables its line-by-line. In lines 26 of the algorithm we fill in the
action table, in lines 910 we fill in the goto table. In lines 1113 we write the error
into the positions which remained empty.
Now we deal with the steps of the LR(1) parsing. (Figure 2.16).
The state of the parsing is written by configurations. A configuration of the LR(1)
parser consists of two parts, the first is the stack and the second is the unexpended
input text.
The stack of the parsing is a double stack, we write or read two data with the
operations push or pop. The stack consists of pairs of symbols, the first element of
pairs there is a terminal or nonterminal symbol, and the second element is the serial
number of the state of automaton. The content of the start state is #0.
The start configuration is (#0, z#), where z means the unexpected text.
The parsing is successful if the parser moves to final state. In the final state the
content of the stack is #0, and the parser is at the end of the text.
2.3. Syntactic analysis 121
Suppose that the parser is in the configuration (#0 . . . Yk ik , ay#). The next move
of the parser is determined by action[ik , a].
State transitions are the following.
If action[ik , a] = sl, i.e. the parser executes a shift, then the actual symbol a and
the new state l are written into the stack. That is, the new configuration is
(#0 . . . Ykr ikr Ykr+1 ikr+1 . . . Yk ik , y#) (#0 . . . Ykr ikr Ail , y#) ,
where || = r.
If action[ik , a] = accept, then the parsing is completed, and the analysed text
was correct.
If action[ik , a] = error, then the parsing terminates, and a syntactic error was
discovered at the symbol a.
The LR(1) parser is often named canonical LR(1) parser.
Denote the action and goto tables together by T . We can give the following
algorithm for the steps of parser.
LR(1)-Parser(xay#, T )
1 s (#0, xay#), s0 parsing
2 repeat
3 s = (#0 . . . Ykr ikr Ykr+1 ikr+1 . . . Yk ik , ay#)
4 if action[ik , a] = sl
5 then s (#0 . . . Yk ik ail , y#)
6 else if action[ik , a] = rl and A is the l-th rule and
7 || = r and goto[ikr , A] = il
8 then s (#0 . . . Ykr ikr Ail , ay#)
9 else if action[ik , a] = accept
10 then s0 O.K.
11 else s0 ERROR
12 until s = O.K. or s = ERROR
0 0
13 return s0 , s
The input parameters of the algorithm are the text xay and table T . The vari-
able s0 indicates the action of the parser. It has value parsing in the intermediate
states, and its value is O.K. or ERROR at the final states. In line 3 we detail the
configuration of the parser, that is necessary at lines 68. Using the action table,
the parser determines its move from the symbol xk at the top of the stack and from
the actual symbol a. In lines 45 we execute a shift step, in lines 68 a reduction.
The algorithm is completed in lines 911. At this moment, if the parser is at the end
122 2. Compilers
of text and the state 0 is at the top of stack, then the text is correct, otherwise a
syntax error was detected. According to this, the output of the algorithm is O.K. or
ERROR, and the final configuration is at the output, too. In the case of error, the
first symbol of the second element of the configuration is the erroneous symbol.
Example 2.18The action and goto tables of the LR(1) parser for the grammar of Example
2.15 are as follows. The empty positions denote errors.
Example 2.19 Using the tables of the previous example, analyse the text abb#.
rule
s3
(#0, aab#) (#0a3, bb#)
s4
(#0a3b4, b#)
r3
(#0a3A8, b#) Ab
r2
(#0A2, b#) A aA
s7
(#0A2b7, #)
r3
(#0A2A5, #) Ab
r1
(#0S1, #) S AA
elfogad
O.K.
The syntax tree of the sentence is in Figure 2.17.
LALR(1) parser Our goal is to decrease the number of states of the parser,
since not only the size but the speed of the compiler is dependent on the number of
states. At the same time, we wish not to cut radically the set of LR(1) grammars
and languages, by using our new method.
There are a lot of LR(1)-items in the canonical sets, such that are very similar:
their core are the same, only their lookahead symbols are different. If there are two
or more canonical sets in which there are similar items only, then we merge these
sets.
If the canonical sets Hi s a Hj are mergeable, then let K[i,j] = Hi Hj .
Execute all of possible merging of LR(1) canonical sets. After renumbering the
2.3. Syntactic analysis 123
S0
A A
a A b
b
Figure 2.17 The syntax tree of the sentence aab.
indexes we obtain sets K0 , K1 , . . . , Kn ; these are the merged LR(1) canonical sets or
LALR(1) canonical sets.
We create the LALR(1) parser from these united canonical sets.
Example 2.20 Using the LR(1) canonical sets of the example 2.17, we can merge the next
canonical sets:
H3 and H6 ,
H4 and H7 ,
H8 and H9 .
In the Figure 2.15 it can be seen that mergeable sets are in equivalent or similar
positions in the automaton.
There is no difficulty with the function read if we use merged canonical sets. If
K = H1 H2 . . . Hk ,
0 0 0
read(H1 , X) = H1 , read(H2 , X) = H2 , . . . , read(Hk , X) = Hk ,
and 0 0 0
K0 = H1 H2 . . . Hk ,
then
read(K, X) = K0 .
We can prove this on the following way. By the definition of function read, the
set read(H, X) depends on the core of LR(1)-items in H only, and it is independent
of the lookahead symbols. Since the cores of LR(1)-items in the sets H1 , H2 , . . . , Hk
are the same, the cores of LR(1)-items of
are also the same. It follows that these sets are mergeable into a set K0 , thus
read(K, X) = K0 .
124 2. Compilers
However, after merging canonical sets of LR(1)-items, elements of this set can
raise difficulties. Suppose that
K[i,j] = Hi Hj .
After merging there are not shift-shift conflicts. If
[A .a, b] Hi
and
[B .a, c] Hj
then there is a shift for the symbol a and we saw that the function read does
not cause problem, i.e. the set read(K[i,j] , a) is equal to the set read(Hi , a)
read(Hj , a).
If there is an item
[A .a, b]
in the canonical set Hi and there is an item
[B ., a]
in the set a Hj , then the merged set is an inadequate set with the symbol a, i.e.
there is a shift-reduce conflict in the merged set.
But this case never happens. Both items are elements of the set Hi and of
the set Hj . These sets are mergeable sets, thus they are different in lookahead
symbols only. It follows that there is an item [A .a, c] in the set Hj . Using
the Theorem 2.24 we get that the grammar is not a LR(1) grammar; we get
shift-reduce conflict from the set Hj for the LR(1) parser, too.
However, after merging reduce-reduce conflict may arise. The properties of LR(1)
grammar do not exclude this case. In the next example we show such a case.
Example 2.21 Let G0 = ({S 0 , S, A, B}, {a, b, c, d, e}, P 0 , S 0 ) be a grammar, and the deriva-
tion rules are as follows.
S0 S
S aAd | bBd | aBe | bAe
Ac
Bc
This grammar is a LR(1) grammar. For the viable prefix ac the LR(1)-items
Now we give the method for creating a LALR(1) parsing table. First we give the
canonical sets of LR(1)-items
H1 , H2 , . . . , Hm
, then we merge canonical sets in which the sets constructed from the core of the
items are identical ones. Let
K1 , K2 , . . . , Kn (n m)
Definition 2.25 If the filling in the LALR(1) parsing tables do not produce con-
flicts then the grammar is said to be an LALR(1) grammar.
Example 2.22 Denote the result of merging canonical sets Hi and Hj by K[i,j] . Let [i, j]
be the state which belonging to this set.
The LR(1) canonical sets of the grammar of Example 2.15 were given in the Example
2.17 and the mergeable sets were seen in the example 2.20. For this grammar we can create
the next LALR(1) parsing tables.
The filling in the LALR(1) tables are conflict free, therefore the grammar is an LALR(1)
grammar. The automaton of this parser is in Figure 2.18.
Example 2.23 Analyse the text abb# using the parsing table of the previous example.
126 2. Compilers
1 5
S A a
A a A
0 2 3,6 8,9
b
a
b
4,7
b
rule
s[3,6]
(#0, aab#) (#0a [3, 6] , bb#)
s[4,7]
(#0a [3, 6] b [4, 7] , b#)
r3
(#0a [3, 6] A[8, 9], b#) Ab
r2
(#0A2, b#) A aA
s[4,7]
(#0A2b [4, 7] , #)
r3
(#0A2A5, #) Ab
r1
(#0S1, #) S AA
elfogad
O.K.
The syntax tree of the parsed text is in the Figure 2.17.
As it can be seen from the previous example, the LALR(1) grammars are LR(1)
grammars. The converse assertion is not true. In Example 2.21 there is a grammar
which is LR(1), but it is not LALR(1) grammar.
Programming languages can be written by LALR(1) grammars. The most fre-
quently used methods in compilers of programming languages is the LALR(1)
method. The advantage of the LALR(1) parser is that the sizes of parsing tables
are smaller than the size of LR(1) parsing tables.
For example, the LALR(1) parsing tables for the Pascal language have a few
hundreds of lines, whilst the LR(1) parsers for this language have a few thousands
of lines.
Exercises
2.3-1 Find the LL(1) grammars among the following grammars (we give their
derivation rules only).
1. S ABc
A a|
B b|
2. S Ab
A a|B|
B b|
2.3. Syntactic analysis 127
3. S ABBA
A a|
B b|
4. S aSe | A
A bAe | B
B cBe | d
2.3-2 Prove that the next grammars are LL(1) grammars (we give their derivation
rules only).
1. S Bb | Cd
B aB |
C cC |
2. S aSA |
A c | bS
3. S AB
A a|
B b|
2.3-3 Prove that the next grammars are not LL(1) grammars (we give their deriva-
tion rules only).
1. S aAa | Cd
A abS | c
2. S aAaa | bAba
A b|
3. S abA |
A Saa | b
2.3-6 Prove that the next grammars are LR(1) grammars. (we give their derivation
rules only).
1. S0 S
S aSS | b
2. S0 S
S SSa | b
128 2. Compilers
2.3-7 Prove that the next grammars are not LR(k) grammars for any k (we give
their derivation rules only).
1. S0 S
S aSa | bSb | a | b
2. S0 S
S aSa | bSa | ab | ba
2.3-8 Prove that the next grammars are LR(1) but are not LALR(1) grammars (we
give their derivation rules only).
1. S0 S
S Aa | bAc | Bc | bBa
A d
B d
2. S0 S
S aAcA | A | B
A b | Ce
B dD
C b
D CcS | CcD
Problems
of a variable is the character string of its name, or the attribute of a number is its
value and type. It is practical to write pointers to the symbols in places of data.
2-3 LALR(1) parser from LR(0) canonical sets
If we omit lookahead symbols from the LR(1)-items then we get LR(0)-items.
We can define functions closure and read for LR(0)-items too, doing not care for
lookahead symbols. Using a method similar to the method of LR(1), we can construct
LR(0) canonical sets
I0 , I1 , . . . , In .
One can observe that the number of merged canonical sets is equal to the number of
LR(0) canonical sets, since the cores of LR(1)-items of the merged canonical sets are
the same as the items of the LR(0) canonical sets. Therefore the number of states
of LALR(1) parser is equal to the number of states of its LR(0) parser.
Using this property, we can construct LALR(1) canonical sets from LR(0) canon-
ical sets, by completing the items of the LR(0) canonical sets with lookahead sym-
bols. The result of this procedure is the set of LALR(1) canonical sets.
It is obvious that the right part of an LR(1)-item begins with symbol point only
if this item was constructed by the function closure. (We notice that there is one
exception, the [S 0 .S] item of the canonical set H0 .) Therefore it is no need for
all items of LR(1) canonical sets. Let the kernel of the canonical set H0 be the
LR(1)-item [S 0 .S, #], and let the kernel of any other canonical set be the set of
the LR(1)-items such that there is no point at the first position on the right side
of the item. We give an LR(1) canonical set by its kernel, since all of items can be
construct from the kernel using the function closure.
If we complete the items of the kernel of LR(0) canonical sets then we get the
kernel of the merged LR(1) canonical sets. That is, if the kernel of an LR(0) canonical
set is Ij , then from it with completions we get the kernel of the LR(1) canonical set,
Kj .
If we know Ij then we can construct read(Ij , X) easily. If [B .C] Ij , C
A and A X, then [A X.] read(Ij , X). For LR(1)-items, if [B .C, b]
Kj , C A and A X then we have to determine also the lookahead symbols,
i.e. the symbols a such that [A X., a] read(Kj , X).
If 6= and a First(b) then it is sure that [A X., a] read(Kj , X).
In this case, we say that the lookahead symbol was spontaneously generated for
this item of canonical set read(Kj , X). The symbol b do not play important role in
the construction of the lookahead symbol.
If = then [A X., b] is an element of the set read(Kj , X), and the looka-
head symbol is b. In this case we say that the lookahead symbol is propagated from
Kj into the item of the set read(Kj , X).
If the kernel Ij of an LR(0) canonical set is given then we construct the propa-
gated and spontaneously generated lookahead symbols for items of read(Kj , X) by
the following algorithm.
For all items [B .] Ij we construct the set Kj = closure([B ., @]),
where @ is a dummy symbol,
if [A .X, a] Kj and a 6= @ then [A X., a] read(Kj , X) and the
symbol a is spontaneously generated into the item of the set read(Kj , X),
130 2. Compilers
Chapter Notes
The theory and practice of compilers, computers and program languages are of the
same age. The construction of first compilers date back to the 1950s. The task of
writing compilers was a very hard task at that time, the first Fortran compiler took
18 man-years to implement [7]. From that time more and more precise definitions
and solutions have been given to the problems of compilation, and better and better
methods and utilities have been used in the construction of translators.
The development of formal languages and automata was a great leap forward,
and we can say that this development was urged by the demand of writing of com-
pilers. In our days this task is a simple routine project. New results, new discoveries
are expected in the field of code optimisation only.
One of the earliest nondeterministic and backtrack algorithms appeared in the
1960s. The first two dynamic programming algorithms were the CYK (Cocke-
Younger-Kasami) algorithm from 196567 and the Earley-algorithm from 1965. The
idea of precedence parsers is from the end of 1970s and from the beginning of 1980s.
The LR(k) grammars was defined by Knuth in 1965; the definition of LL(k) gram-
mars is dated from the beginning of 1970s. LALR(1) grammars were studied by De
Remer in 1971, the elaborating of LALR(1) parsing methods were finished in the
beginning of 1980s [5, 6, 7].
To the middle of 1980s it became obvious that the LR parsing methods are the
real efficient methods and since than the LALR(1) methods are used in compilers
[5].
A lot of very excellent books deal with the theory and practice of compiles.
Perhaps the most successful of them was the book of Gries [95]; in this book there
are interesting results for precedence grammars. The first successful book which
wrote about the new LR algorithms was of Aho and Ullman [6], we can find here
also the CYK and the Early algorithms. It was followed by the "dragon book" of
Aho and Ullman[7]; the extended and corrected issue of it was published in 1986 by
authors Aho, Ullman and Sethi [5].
Without completeness we notice the books of Fischer and LeBlanc [73], Tremblay
and Sorenson [252], Waite and Goos [?], Hunter [115], Pittman [200] and Mak [165].
Advanced achievements are in recently published books, among others in the book
of Muchnick [183], Grune, Bal, Jacobs and Langendoen [97], in the book of Cooper
and Torczon [51] and in a chapter of the book by Louden [161].
3. Compression and Decompression
Algorithms for data compression usually proceed as follows. They encode a text over
some finite alphabet into a sequence of bits, hereby exploiting the fact that the letters
of this alphabet occur with different frequencies. For instance, an e occurs more
frequently than a q and will therefore be assigned a shorter codeword. The quality
of the compression procedure is then measured in terms of the average codeword
length.
So the underlying model is probabilistic, namely we consider a finite alphabet and a
probability distribution on this alphabet, where the probability distribution reflects
the (relative) frequencies of the letters. Such a pairan alphabet with a probability
distributionis called a source. We shall first introduce some basic facts from Infor-
mation Theory. Most important is the notion of entropy, since the source entropy
characterises the achievable lower bounds for compressibility.
The source model to be best understood, is the discrete memoryless source. Here
the letters occur independently of each other in the text. The use of prefix codes,
in which no codeword is the beginning of another one, allows to compress the text
down to the entropy of the source. We shall study this in detail. The lower bound
is obtained via Krafts inequality, the achievability is demonstrated by the use of
Huffman codes, which can be shown to be optimal.
There are some assumptions on the discrete memoryless source, which are not
fulfilled in most practical situations. Firstly, usually this source model is not realistic,
since the letters do not occur independently in the text. Secondly, the probability
distribution is not known in advance. So the coding algorithms should be universal
for a whole class of probability distributions on the alphabet. The analysis of such
universal coding techniques is much more involved than the analysis of the discrete
memoryless source, such that we shall only present the algorithms and do not prove
the quality of their performance. Universal coding techniques mainly fall into two
classes.
Statistical coding techniques estimate the probability of the next letters as ac-
curately as possible. This process is called modelling of the source. Having enough
information about the probabilities, the text is encoded, where usually arithmetic
coding is applied. Here the probability is represented by an interval and this interval
will be encoded.
132 3. Compression and Decompression
A 64 H 42 N 56 U 31
B 14 I 63 O 56 V 10
C 27 J 3 P 17 W 10
D 35 K 6 Q 4 X 3
E 100 L 35 R 49 Y 18
F 20 M 20 S 56 Z 2
G 14 T 71
where the logarithm is to the base 2. We shall also use the notation H(X)
according to the interpretation of the source as a random variable.
c1 (x), c2 (x), . . . , cL(x) (x) 6= c1 (y), c2 (y), . . . , cL(x) (y) . So in at least one of the
first L(x) components c(x) and c(y) differ.
Messages encoded using a prefix code are uniquely decipherable. The decoder
proceeds by reading the next letter until a codeword c(x) is formed. Since c(x) cannot
be the beginning of another codeword, it must correspond to the letter x X .
Now the decoder continues until another codeword is formed. The process may be
repeated until the end of the message. So after having found the codeword c(x) the
decoder instantaneously knows that x X is the next letter of the message. Because
of this property a prefix code is also denoted as instantaneous code.
The criterion for data compression is to minimise the average length of the
codewords. So if we are given a source (X , P ), where X = {1, . . . , m} and P =
P (1), P (2), . . . , P (m) is a probability distribution on X , the average length L(c)
is defined by
X
L(c) = P (x) L(x) .
xX
The following prefix code c for English texts has average length L(c) = 30.266+
4 0.415 + 5 0.190 + 6 0.101 + 7 0.016 + 8 0.012 = 4.222.
We can still do better, if we do not encode single letters, but blocks of n letters
for some n N . In this case we replace the source (X , P ) by (X n , P n ) for some
n N . Remember that P n (x1 x2 . . . xn ) = P (x1 ) P (x2 ) P (xn ) for a word
(x1 x2 . . . xn ) X n , since the source is memoryless. If e.g. we are given an alphabet
with two letters, X = {a, b} and P (a) = 0.9, P (b) = 0.1, then the code c defined
by c(a) = 0, c(b) = 1 has average length L(c) = 0.9 1 + 0.1 1 = 1. Obviously we
cannot find a better code. The combinations of two letters now have the following
probabilities:
1 000
00
* q 001
0
1 010
j 01
q 011
1 100
* 10 q 101
R1
1 110
j 11
q 111
of
1 X
L(n, P ) = min P n (x1 . . . xn )L(x1 . . . xn ) .
cU DC n
(x1 ...xn )X n
It follows from the Noiseless Coding Theorem, which is stated in the next section,
that limn L(n, P ) = H(P ) the entropy of the source (X , P ).
In our example for the English language we have H(P ) 4.19. So the code
presented above, where only single letters are encoded, is already nearly optimal in
respect of L(n, P ). Further compression is possible, if we consider the dependencies
between the letters.
Proof The central idea is to interpret the codewords as nodes of a rooted binary
tree with depth T = maxxX {L(x)}. The tree is required to be complete (every path
from the root to a leaf has length T ) and regular (every inner node has outdegree
2). The example in Figure 3.2 for T = 3 may serve as an illustration.
So the nodes with distance n from the root are labeled with the words xn
{0, 1}n . The upper successor of x1 x2 . . . xn is labeled x1 x2 . . . xn 0, its lower successor
136 3. Compression and Decompression
is labeled x1 x2 . . . xn 1.
The shadow of a node labeled by x1 x2 . . . xn is the set of all the leaves which
are labeled by a word (of length T ) beginning with x1 x2 . . . xn . In other words, the
shadow of x1 . . . xn consists of the leaves labeled by a sequence with prefix x1 . . . xn .
In our example {000, 001, 010, 011} is the shadow of the node labeled by 0.
Now suppose we are given positive integers L(1), . . . , L(m). We further assume
that L(1) L(2) L(m). As first codeword c(1) = |00 {z . . . 0} is chosen. Since
L(1)
P
2T L(x) 2T , we have 2T L(1) < 2T (otherwise only one letter has to be
xX
encoded). Hence there are left some nodes on the T -th level, which are not in the
shadow of c(1). We pick the first of these remaining nodes and go back T L(2) steps
in direction to the root. Since L(2) L(1) we shall find a node labeled by a sequence
of L(2) bits, which is not a prefix of c(1). So we can choose this sequence as c(2). Now
again, either m = 2, and we are ready, or by the hypothesis 2T L(1) + 2T L(2) < 2T
and we can find a node on the T -th level, which is not contained in the shadows
of c(1) and c(2). We find the next codeword as shown above. The process can be
continued until all codewords are assigned.
P L(x) P
T
Conversely, observe that 2 = wj 2j , where wj is the number of
xX j=1
codewords with length j in the uniquely decipherable prefix code and T again denotes
the maximal word length.
The s-th power of this term can be expanded as
s
XT T s
X
wj 2j = Nk 2k .
j=1 k=s
P
Here Nk = wi1 . . . wis is the total number of messages whose coded
i1 ++is =k
representation is of length k.
Since the code is uniquely decipherable, to every sequence of k letters corresponds
P
T s TPs
at most one possible message. Hence Nk 2k and Nk 2k 1 = T ss+1
k=s k=s
P
T 1
T s. Taking sth root this yields wj 2j (T s) s .
j=1
1
Since this inequality holds for any s and lim (T s) s = 1, we have the desired
s
result
T
X X
wj 2j = 2L(x) 1 .
j=1 xX
3.1. Facts from information theory 137
Proof Let L(1), . . . , L(m) denote the codeword lengths of an optimal uniquely de-
2L(x)
cipherable code. Now we define a probability distribution Q by Q(x) = r for
P
m
x = 1, . . . , m, where r = 2L(x) . By Krafts inequality r 1.
x=1
For two probability distributions P and Q on X the I-divergence D(P ||Q) is
defined by
X P (x)
D(P ||Q) = P (x) lg .
Q(x)
xX
P P
= P (x) L(x) P (x) lg r 1 = Lmin (P ) + lg r.
xX xX
3.1.4. Shannon-Fano-Elias-codes
In the proof of the Noiseless Coding Theorem it was explicitly shown how to con-
struct a prefix code c to a given probability distribution P = (P (1), . . . , P (a)). The
138 3. Compression and Decompression
1
x P (x) Q(x) Q(x) dlg P (x)
e cS (x) cSF E (x)
1 0.25 0 0.125 2 00 001
2 0.2 0.25 0.35 3 010 0101
3 0.11 0.45 0.505 4 0111 10001
4 0.11 0.56 0.615 4 1000 10100
5 0.11 0.67 0.725 4 1010 10111
6 0.11 0.78 0.835 4 1100 11010
7 0.11 0.89 0.945 4 1110 11110
L 3.3 4.3
assigned to each message contained in one subset and a 1 to each of the remaining
messages. The same procedure is repeated for subsets of X0 and X1 ; that is, X0 will
be partitioned into two subsets X00 and X01 . Now the code word corresponding to a
message contained in X00 will start with 00 and that corresponding to a message in
X01 will begin with 01. This procedure is continued until each subset contains only
one message.
However, this algorithm neither yields an optimal code in general, since the prefix
code 1 01, 2 000, 3 001, 4 110, 5 111, 6 100, 7 101 has
average length 2.75.
length.
Theorem 3.3 We are given a source (X , P ), where X = {1, . . . , m} and the prob-
abilities are ordered nonincreasingly P (1) P (2) P (m). A new probability
distribution is defined by
P 0 = P (1), . . . , P (m 2), P (m 1) + P (m) .
Let c0 = c0 (1), c0 (2), . . . , c0 (m 1) be an optimal prefix code for P 0 . Now we
define a code c for the distribution P by
c(m 1) = c0 (m 1)0 ,
c(m) = c0 (m 1)1 .
ii) Assume we are given a code with L(1) L(m 1) < L(m). Because of
the prefix property we may drop the last L(m) L(m 1) bits and thus obtain
a new code with L(m) = L(m 1).
iii) If no two codewords of maximal length agree in all places but the last, then we
may drop the last digit of all such codewords to obtain a better code.
Now we are ready to prove the statement from the theorem. From the definition
of c and c0 we have
Now let d be an optimal prefix code with the properties ii) and iii) from the
preceding lemma. We define a prefix code d0 for
3.2. Arithmetic coding and modelling 141
Lopt (P 0 ) + P (m 1) + P (m)
Analysis. If m denotes the size of the source alphabet, the Huffman coding
algorithm needs m 1 additions and m 1 code modifications (appending 0 or 1).
Further we need m 1 insertions, such that the total complexity can be roughly esti-
mated to be O(m lg m). However, observe that with the Noiseless Coding Theorem,
the quality of the compression rate can only be improved by jointly encoding blocks
of, say, k letters, which would result in a Huffman code for the source X k of size
mk . So, the price for better compression is a rather drastic increase in complexity.
Further, the codewords for all mk letters have to be stored. Encoding a sequence of
n letters can since be done in O( nk (mk lg mk )) steps.
Exercises
. . 01} is
3.1-1 Show that the code c : {a, b} {0, 1} with c(a) = 0 and c(b) = |0 . {z
n
uniquely decipherable but not instantaneous for any n > 0.
3.1-2 Compute the entropy of the source (X , P ), with X = {1, 2} and P =
(0.8, 0, 2).
3.1-3 Find the Huffman-codes and the Shannon-Fano-codes for the sources
(X n , P n ) with (X , P ) as in the previous exercise for n = 1, 2, 3 and calculate their
average codeword lengths.
3.1-4 Show that always 0 H(P ) lg |X |.
3.1-5 Show that the redundancy (c) = L(c) H(P ) of a prefix code c for a source
with probability distribution P can be expressed as a special Idivergence.
3.1-6 Show that the I-divergence D(P ||Q) 0 for all probability distributions P
and Q over some alphabet X with equality exactly if P = Q but that the I-divergence
is not a metric.
other hand, for long blocks of source symbols, Huffman-coding is a rather complex
procedure, since it requires the calculation of the probabilities of all sequences of the
given block length and the construction of the corresponding complete code.
For compression techniques based on statistical methods often arithmetic cod-
ing is preferred. Arithmetic coding is a straightforward extension of the Shannon-
Fano-Elias-code. The idea is to represent a probability by an interval. In order to do
so, the probabilities have to be calculated very accurately. This process is denoted as
modelling of the source . So statistical compression techniques consist of two stages:
modelling and coding. As just mentioned, coding is usually done by arithmetic cod-
ing. The different algorithms like, for instance, DCM (Discrete Markov Coding) and
PPM (Prediction by Partial Matching) vary in the way of modelling the source. We
are going to present the context-tree weighting method, a transparent algorithm for
the estimation of block probabilities due to Willems, Shtarkov, and Tjalkens, which
also allows a straightforward analysis of the efficiency.
which means that we do not have to store the code as in the case of Huffman coding.
Further, the relevant source models allow to easily compute P n (x1 x2 . . . xn1 xn ) and
Qn (x1 x2 . . . xn1 xn ) from P n1 (x1 x2 . . . xn1 ), usually by multiplication by P (xn ).
This means that the sequence to be encoded can be parsed sequentially bit by bit,
unlike in Huffman coding, where we would have to encode blockwise.
Arithmetic-Encoder(x)
1 B0
2 A1
3 for i 1 to n
4 do B B + A Qi (x[i])
5 A A Pi (x[i])
1
6 L dlg A e+1
7 c dB 2L e
8 return c
We shall illustrate the encoding procedure by the following example from the
literature. Let the discrete, memoryless source (X , P ) be given with ternary alphabet
X = {1, 2, 3} and P (1) = 0.4, P (2) = 0.5, P (3) = 0.1. The sequence x4 = (2, 2, 2, 3)
has to be encoded. Observe that Pi = P and Qi = Q for all i = 1, 2, 3, 4. Further
Q(1) = 0, Q(2) = P (1) = 0.4, and Q(3) = P (1) + P (2) = 0.9.
The above algorithm yields
i Bi Ai
0 0 1
1 B0 + A0 Q(2) = 0.4 A0 P (2) = 0.5
2 B1 + A1 Q(2) = 0.6 A1 P (2) = 0.25
3 B2 + A2 Q(2) = 0.7 A2 P (2) = 0.125
4 B3 + A3 Q(3) = 0.8125 A3 P (3) = 0.0125 .
Hence Q(2, 2, 2, 3) = B4 = 0.8125 and P (2, 2, 2, 3) = A4 = 0.0125. From this can
1
be calculated that L = dlg A e + 1 = 8 and finally dB 2L e = d0.8125 256e = 208
144 3. Compression and Decompression
Arithmetic-Decoder(c)
1 for i 1 to n
2 do j 1
3 while (c < Qi (j))
4 do j j + 1
5 x[i] j 1
6 c (c Qi (x[i]))/Pi (x[i])
7 return x
Observe that when the decoder only receives codeword c he does not know when
the decoding procedure terminates. For instance c = 0 can be the codeword for
x1 = (1), x2 = (1, 1), x3 = (1, 1, 1), etc. In the above pseudocode it is implicit that
the number n of symbols has also been transmitted to the decoder, in which case
it is clear what the last letter to be encoded was. Another possibility would be to
provide a special end-of-file (EOF)-symbol with a small probability, which is known
to both the encoder and the decoder. When the decoder sees this symbol, he stops
decoding. In this case line 1 would be replaced by
1 while (x[i] 6= EOF)
(and i would have to be increased). In our above example, the decoder would
receive the codeword 11010000, the binary expansion of 0.8125 up to L = 8 bits.
This number falls in the interval [0.4, 0.9) which belongs to the letter 2, hence the
1
first letter x1 = 2. Then he calculates (0.8075 Q(2)) P (2) = (0.815 0.4) 2 = 0.83.
Again this number is in the interval [0.4, 0.9) and the second letter is x2 = 2. In order
1
to determine x3 the calculation (0.83 Q(2)) P (2) = (0.83 0.4) 2 = 0.86 must be
1
performed. Again 0.86 [0.4, 0.9) such that also x3 = 2. Finally (0.86 Q(2)) P (2) =
(0.86 0.4) 2 = 0.92. Since 0.92 [0.9, 1), the last letter of the sequence must be
x4 = 3.
2. It can also be shown that the additional transmission of block length n or the
introduction of the EOF symbol only results in a negligible loss of compression.
However, the basic algorithms we presented are not useful in order to compress
longer files, since with increasing block length n the intervals are getting smaller and
smaller, such that rounding errors will be unavoidable. We shall present a technique
to overcome this problem in the following.
Analysis. The basic algorithm for arithmetic coding is linear in the length n
of the sequence to be encoded. Usually, arithmetic coding is compared to Huffman
coding. In contrast to Huffman coding, we do not have to store the whole code, but
can obtain the codeword directly from the corresponding interval. However, for a
discrete memoryless source, where the probability distribution Pi = P is the same
for all letters, this is not such a big advantage, since the Huffman code will be the
same for all letters (or blocks of k letters) and hence has to be computed only once.
Huffman coding, on the other hand, does not use any multiplications which slow
down arithmetic coding.
For the adaptive case, in which the Pi s may change for different letters xi to be
encoded, a new Huffman code would have to be calculated for each new letter. In
this case, usually arithmetic coding is preferred. We shall investigate such situations
in the section on modelling.
For implementations in practice floating point arithmetic is avoided. Instead, the
subdivision of the interval [0, 1) is represented by a subdivision of the integer range
0, . . . , M , say, with proportions according to the source probabilities. Now integer
arithmetic can be applied, which is faster and more precise.
Precision problem. In the basic algorithms for arithmetic encoding and de-
coding the shrinking of the current interval would require the use of high precision
arithmetic for longer sequences. Further, no bit of the codeword is produced until
the complete sequence xn has been read in. This can be overcome by coding each bit
as soon as it is known and then double the length of the current interval [LO, HI),
say, so that this expansion represents only the unknown part of the interval. This is
the case when the leading bits of the lower and upper bound are the same, i. e. the
interval is completely contained either in [0, 21 ) or in [ 12 , 1). The following expansion
rules guarantee that the current interval does not become too small.
Case 1 ([LO, HI) [0, 21 )): LO 2 Lo, HI 2 HI .
Case 2 ([LO, HI) [ 12 , 1)): LO 2 LO 1, HI 2 HI 1 .
Case 3 ( 14 LO < 1
2 HI < 34 ): LO 2 LO 21 , HI 2 HI 1
2 .
The last case called underflow (or follow) prevents the interval from shrinking
too much when the bounds are close to 12 . Observe that if the current interval is
contained in [ 14 , 43 ) with LO < 21 HI, we do not know the next output bit, but we
do know that whatever it is, the following bit will have the opposite value. However,
in contrast to the other cases we cannot continue encoding here, but have to wait
(remain in the underflow state and adjust a counter underf lowcount to the number
of subsequent underflows, i. e. underf lowcount underf lowcount + 1) until the
current interval falls into either [0, 21 ) or [ 12 , 1). In this case we encode the leading
146 3. Compression and Decompression
bit of this interval 0 for [0, 12 ) and 1 for [ 12 , 1) followed by underf lowcount many
inverse bits and then set underf lowcount = 0. The procedure stops, when all letters
are read in and the current interval does not allow any further expansion.
Arithmetic-Precision-Encoder(x)
1 LO 0
2 HI 1
3 A1
4 underflowcount 0
5 for i 1 to n
6 do LO LO + Qi (x[i]) A
7 A Pi (x[i])
8 HI LO + A
9 while HI LO < 21 AND NOT (LO < 41 AND HI 12 )
10 do if HI < 12
11 then c c||0, underflowcount many 1s
12 underflowcount 0
13 LO 2 LO
14 HI 2 HI
15 else if LO 12
16 then c c||1, underflowcount many 0s
17 underflowcount 0
18 LO 2 LO 1
19 HI 2 HI 1
20 else if LO 14 AND HI < 34
21 then underflowcount underflowcount +1
22 LO 2 LO 12
23 HI 2 HI 21
24 if underflowcount > 0
25 then c c||0, underflowcount many 1s)
26 return c
We shall illustrate the encoding algorithm in Figure 3.6 by our example the
encoding of the message (2, 2, 2, 3) with alphabet X = {1, 2, 3} and probability
distribution P = (0.4, 0.5, 0.1). An underflow occurs in the sixth row: we keep track
of the underflow state and later encode the inverse of the next bit, here this inverse
bit is the 0 in the ninth row. The encoded string is 1101000.
Precision-decoding involves the consideration of a third variable besides the in-
terval bounds LO and HI.
3.2.2. Modelling
Modelling of memoryless sources. In this section we shall only consider
binary sequences xn {0, 1}n to be compressed by an arithmetic coder. Further,
we shortly write P (xn ) instead of P n (xn ) in order to allow further subscripts and
superscripts for the description of the special situation. Pe will denote estimated
3.2. Arithmetic coding and modelling 147
Current Subintervals
Interval Action 1 2 3 Input
[0.00, 1.00) subdivide [0.00, 0.40) [0.40, 0.90) [0.90, 1.00) 2
[0.40, 0.90) subdivide [0.40, 0.60) [0.60, 0.85) [0.85, 0.90) 2
[0.60, 0.85) encode 1
expand [ 21 , 1)
[0.20, 0.70) subdivide [0.20, 0.40) [0.40, 0.65) [0.65, 0.70) 2
[0.40, 0.65) underflow
expand [ 41 , 34 )
[0.30, 0.80) subdivide [0.30, 0.50) [0.50, 0.75) [0.75, 0.80) 3
[0.75, 0.80) encode 10
expand [ 21 , 1)
[0.50, 0.60) encode 1
expand [ 21 , 1)
[0.00, 0.20) encode 0
expand [0, 12 )
[0.00, 0.40) encode 0
expand [0, 12 )
[0.00, 0.80) encode 0
b + 21
P (Xn = 1|xn1 ) = ,
a+b+1
where a and b denote the number of 0s and 1s, respectively, in the sequence
xn1 = (x1 x2 . . . xn1 ). So given the sequence xn1 with a many 0s and b many
b+ 21
1s, the probability that the next letter xn will be a 1 is estimated as a+b+1 . The
estimated block probability of a sequence containing a zeros and b ones then is
1
2 (a 21 ) 12 (b 21 )
Pe (a, b) =
1 2 (a + b)
with initial values a = 0 and b = 0 as in Figure 3.7, where the values of the
Krichevsky-Trofimov-estimator Pe (a, b) for small (a, b) are listed.
1
Note that the summand 2 in the nominator guarantees that the probability for
148 3. Compression and Decompression
a b 0 1 2 3 4 5
0 1 1/2 3/8 5/16 35/128 63/256
1 1/2 1/8 1/16 5/128 7/256 21/1024
2 3/8 1/16 3/128 3/256 7/1024 9/2048
3 5/16 5/128 3/256 5/1024 5/2048 45/32768
1
10
00
???????
0 1 0 0 1 0 0 1 1 1
the next letter to be a 1 is positive even when the symbol 1 did not occur in the
sequence so far. In order to avoid infinite codeword length, this phenomenon has to
be carefully taken into account when estimating the probability of the next letter in
all approaches to estimate the parameters, when arithmetic coding is applied.
Modells with known context tree. In most situations the source is not
memoryless, i. e., the dependencies between the letters have to be considered. A
suitable way to represent such dependencies is the use of a suffix tree, which we
denote as context tree. The context of symbol xt is suffix s preceding xt . To each
context (or leaf in the suffix tree) s there corresponds a parameter s = P (Xt = 1|s),
which is the probability of the occurrence of a 1 when the last sequence of past source
symbols is equal to context s (and hence 1s is the probability for a 0 in this case).
We are distinguishing here between the model (the suffix tree) and the parameters
(s ).
The actual probability of the sequence 0100111 given the past . . . 010 is
P s (0100111| . . . 010) = (110 )00 (11 )(110 )00 1 1 = 23 12 54 23 21 51 15 = 1075
4
,
since the first letter 0 is preceded by suffix 10, the second letter 1 is preceded by
suffix 00, etc.
Suppose the model S is known, but not the parameters s . The problem now is
to find a good coding distribution for this case. The tree structure allows to easily
3.2. Arithmetic coding and modelling 149
determine which context precedes a particular symbol. All symbols having the same
context (or suffix) s S form a memoryless source subsequence whose probability
is determined by the unknown parameter s . In our example these subsequences are
11 for 00 , 00 for 10 and 011 for 1 . One uses the Krichevsky-Trofimov-estimator
for this case. To each node s in the suffix tree, we count the numbers as of zeros and
bs of ones preceded by suffix s. For the children 0s and 1s of parent node s obviously
a0s + a1s = as and b0s + b1s = bs must be satisfied.
In our example (a , b ) = (3, 4) for the root , (a1 , b1 ) = (1, 2), (a0 , b0 ) =
(2, 2) and (a10 , b10 ) = (2, 0), (a00 , b00 ) = (0, 2). Further (a11 , b11 ) = (0, 1),
(a01 , b01 ) = (1, 1), (a111 , b111 ) = (0, 0), (a011 , b011 ) = (0, 1), (a101 , b101 ) =
(0, 0),(a001 , b001 ) = (1, 1), (a110 , b110 ) = (0, 0), (a010 , b010 ) = (2, 0), (a100 , b100 ) =
(0, 2), and (a000 , b000 ) = (0, 0). These last numbers are not relevant for our special
source S but will be important later on, when the source model or the corresponding
suffix tree, respectively, is not known in advance.
Example 3.2 Let S = {00, 10, 1} as in the previous example. Encoding a subsequence is
done by successively updating the corresponding counters for as and bs . For example, when
we encode the sequence 0100111 given the past . . . 010 using the above suffix tree and
Krichevsky-Trofimovestimator we obtain
1 1 1 3 3 1 1 3 3 1 9
Pes (0100111| . . . 010) = = = ,
2 2 2 4 4 4 2 8 8 16 1024
where 83 , 38 and 16
1
are the probabilities of the subsequences 11, 00 and 011 in the
context of the leaves. These subsequences are assumed to be memoryless.
Example 3.3 After encoding the sequence 0100111 given the past . . . 010 we obtain the
150 3. Compression and Decompression
(0,0)
11
Pw = 1/2
(0,1)
6
(0,1) 1
011 Pw = 1/16
Pw = 1/2 (1,2)
(0,0) 1
(1,1)
01
Pw = 1/8
(1,1)
001 Pw = 35/4096
Pw = 1/8 (3,4)
(0,0)
10
Pw = 3/8
(2,0)
(2,0)
010
Pw = 3/8 (2,2) 0
0
(0,2) Pw = 21/256
100
Pw = 3/8
(0,2)
00
?
Pw = 3/8
(0,0)
Figure 3.9 Weighted context tree for source sequence 0100111 with past . . . 010. The pair (as , bs )
denotes as zeros and bs ones preceded by the corresponding context s. For the contexts s =
s = P (0, 0) = 1.
111, 101, 110, 000 it is Pw e
Recall that for the application in arithmetic coding it is important that prob-
abilities P (x1 . . . xn1 0) and P (x1 . . . xn1 1) can be efficiently calculated from
P (x1 . . . xn ). This is possible with the context-tree weighting method, since the
weighted probabilities Pws only have to be updated, when s is changing. This just
occurs for the contexts along the path from the root to the leaf in the context
tree preceding the new symbol xn namely the D + 1 contexts xn1 , . . . , xni for
i = 1, . . . , D 1 and the root . Along this path, as = as + 1 has to be performed,
when xn = 0, and bs = bs + 1 has to be performed, when xn = 1, and the corre-
sponding probabilities Pe (as , bs ) and Pws have to be updated.
This suggests the following algorithm for updating the context tree
CT (x1 , . . . , xn1 |xD+1 , . . . x0 ) when reading the next letter xn . Recall that to each
node of the tree we store the parameters (as , bs ), Pe (as , bs ) and Pws . These parame-
ters have to be updated in order to obtain CT (x1 , . . . , xn |xD+1 , . . . x0 ). We assume
the convention that the ordered pair (xn1 , xn ) denotes the root .
3.2. Arithmetic coding and modelling 151
The probability Pw assigned to the root in the context tree will be used for
the successive subdivisions in arithmetic coding. Initially, before reading x1 , the
parameters in the context tree are (as , bs ) = (0, 0), Pe (as , bs ) = 1, and Pws = 1 for
all contexts s in the tree. In our example the updates given the past (x2 , x1 , x0 ) =
(0, 1, 0) would yield the successive probabilities Pw : 21 for x1 = 0, 32 9
for (x1 x2 ) =
5 13 27
(01), 64 for (x1 x2 x3 ) = (010), 256 for (x1 x2 x3 x4 ) = (0100), 1024 for (x1 x2 x3 x4 ) =
13 13
(01001), 1024 for (x1 x2 x3 x4 x5 ) = (010011), 1024 for (x1 x2 x3 x4 x5 x6 ) = (010011),
35
and finally 4096 for (x1 x2 x3 x4 x5 x6 x7 ) = (0100111).
Correctness Recall that the quality of a code concerning its compression capabil-
ity is measured with respect to the average codeword length. The average codeword
length of the best code comes as close as possible to the entropy of the source. The
difference between the average codeword length and the entropy is denoted as the
redundancy (c) of code c, hence
|S| n
(xn |S) lg + |S| + 2 .
2 |S|
S) is bounded by
|S| n
(xn |S) < 2|S| 1 + lg + |S| + 2 .
2 |S|
Comparing these two formulae, we see that the difference of the individual re-
dundancies is 2|S| 1 bits. This can be considered as the cost of not knowing the
model, i.e. the model redundancy. So, the redundancy splits into the parameter re-
dundancy, i. e. the cost of not knowing the parameter, and the model redundancy. It
can be shown that the expected redundancy behaviour of the context-tree weighting
method achieves the asymptotic lower bound due to Rissanen who could demonstrate
that about 21 lg n bits per parameter is the minimum possible expected redundancy
for n .
Exercises
3.2-1 Compute the arithmetic codes for the sources (X n , P n ), n = 1, 2, 3 with
X = {1, 2} and P = (0.8, 0.2) and compare these codes with the corresponding
Huffman-codes derived previously.
3.2-2 For the codes derived in the previous exercise compute the individual redun-
dancies of each codeword and the redundancies of the codes.
3.2-3 Compute the estimated probabilities Pe (a, b) for the sequence 0100110 and
all its subsequences using the Krichevsky-Trofimov-estimator.
3.2-4 Compute all parameters (as , bs ) and the estimated probability Pes for the se-
quence 0100110 given the past 110, when the context tree S = {00, 10, 1} is known.
What will be the codeword of an arithmetic code in this case?
3.2-5 Compute all parameters (as , bs ) and the estimated probability P for the
sequence 0100110 given the past 110, when the context tree is not known, using the
3.3. Ziv-Lempel-coding 153
3.3. Ziv-Lempel-coding
In 19761978 Jacob Ziv and Abraham Lempel introduced two universal coding algo-
rithms, which in contrast to statistical coding techniques, considered so far, do not
make explicit use of the underlying probability distribution. The basic idea here is to
replace a previously seen string with a pointer into a history buffer (LZ77) or with
the index of a dictionary (LZ78). LZ algorithms are widely usedzip and its vari-
ations use the LZ77 algorithm. So, in contrast to the presentation by several authors,
Ziv-Lempel-coding is not a single algorithm. Originally, Lempel and Ziv introduced
a method to measure the complexity of a stringlike in Kolmogorov complexity.
This led to two different algorithms, LZ77 and LZ78. Many modifications and vari-
ations have been developed since. However, we shall present the original algorithms
and refer to the literature for further information.
3.3.1. LZ77
The idea of LZ77 is to pass a sliding window over the text to be compressed. One
looks for the longest substring in this window representing the next letters of the
text. The window consists of two parts: a history window of length lh , say, in which
the last lh bits of the text considered so far are stored, and a lookahead window
of length lf containing the next lf bits of the text. In the simplest case lh and lf
are fixed. Usually, lh is much bigger than lf . Then one encodes the triple (offset,
length, letter). Here the offset is the number of letters one has to go back in the
text to find the matching substring, the length is just the length of this matching
substring, and the letter to be stored is the letter following the matching substring.
Let us illustrate this procedure with an example. Assume the text to be compressed
is ...abaabbaabbaaabbbaaaabbabbbabbb..., the window is of size 15 with lh = 10 letters
history and lf = 5 letters lookahead buffer. Assume, the sliding window now arrived
at
...aba||abbaabbaaa|bbbaa|| ,
i. e., the history window contains the 10 letters abbaabbaaa and the lookahead win-
dow contains the five letters bbbaa. The longest substring matching the first letters
of the lookahead window is bb of length 2, which is found nine letters back from the
right end of the history window. So we encode (9, 2, b), since b is the next letter (the
string bb is also found five letters back, in the original LZ77 algorithm one would
select the largest offset). The window then is moved 3 letters forward
...abaabb||aabbaaabbb|aaaab|| .
154 3. Compression and Decompression
The next codeword is (6, 3, a), since the longest matching substring is aaa of
length 3 found 6 letters backwards and a is the letter following this substring in the
lookahead window. We proceed with
...abaabbaabb||aaabbbaaaa|bbabb|| ,
...abaabbaabbaaab||bbaaaabbab|babbb|| .
Here we encode (3, 4, b). Observe that the match can extend into the lookahead
window.
There are many subtleties to be taken into account. If a symbol did not appear
yet in the text, offset and length are set to 0. If there are two matching strings of
the same length, one has to choose between the first and the second offset. Both
variations have advantages. Initially one might start with an empty history window
and the first letters of the text to be compressed in the lookahead window - there
are also further variations.
A common modification of the original scheme is to output only the pair (offset,
length) and not the following letter of the text. Using this coding procedure one has
to take into consideration the case in which the next letter does not occur in the
history window. In this case, usually the letter itself is stored, such that the decoder
has to distinguish between pairs of numbers and single letters. Further variations do
not necessarily encode the longest matching substring.
3.3.2. LZ78
LZ78 does not use a sliding window but a dictionary which is represented here as
a table with an index and an entry. LZ78 parses the text to be compressed into a
collection of strings, where each string is the longest matching string seen so far
plus the symbol s following in the text to be compressed. The new string s is
added into the dictionary. The new entry is coded as (i, s), where i is the index of
the existing table entry and s is the appended symbol.
As an example, consider the string abaabbaabbaaabbbaaaabba. It is divided by
LZ78 into strings as shown below. String 0 is here the empty string.
Since we are not using a sliding window, there is no limit for how far back strings
can reach. However, in practice the dictionary cannot continue to grow infinitely.
There are several ways to manage this problem. For instance, after having reached
the maximum number of entries in the dictionary, no further entries can be added
to the table and coding becomes static. Another variation would be to replace older
entries. The decoder knows how many bits must be reserved for the index of the
string in the dictionary, and hence decompression is straightforward.
3.4. The Burrows-Wheeler-transform 155
Analysis. If we fix the size of the sliding window or the dictionary, the running
time of encoding a sequence of n letters will be linear in n. However, as usually
in data compression, there is a tradeoff between compression rate and speed. A
better compression is only possible with larger memory. Increasing the size of the
dictionary or the window will, however, result in a slower performance, since the
most time consuming task is the search for the matching substring or the position
in the dictionary.
Decoding in both LZ77 and LZ78 is straightforward. Observe that with LZ77
decoding is usually much faster than encoding, since the decoder already obtains the
information at which position in the history he can read out the next letters of the
text to be recovered, whereas the encoder has to find the longest matching substring
in the history window. So algorithms based on LZ77 are useful for files which are
compressed once and decompressed more frequently.
Further, the encoded text is not necessarily shorter than the original text. Es-
pecially in the beginning of the encoding the coded version may expand a lot. This
expansion has to be taken into consideration.
For implementation it is not optimal to represent the text as an array. A suitable
data structure will be a circular queue for the lookahead window and a binary search
tree for the history window in LZ77, while for LZ78 a dictionary tree should be used.
Exercises
3.3-1 Apply the algorithms LZ77 and LZ78 to the string abracadabra.
3.3-2 Which type of files will be well compressed with LZ77 and LZ78, respectively?
For which type of files are LZ77 and LZ78 not so advantageous?
3.3-3 Discuss the advantages of encoding the first or the last offset, when several
matching substrings are found in LZ77.
~ In
1) We form a matrix M consisting of all cyclic shifts of the original text X.
our example
W H E E L E R
H E E L E R W
E E L E R W H
M =
E L E R W H E .
L E R W H E E
E R W H E E L
R W H E E L E
E E L E R W H
E L E R W H E
E R W H E E L
M0 =
H E E L E R W .
L E R W H E E
R W H E E L E
W H E E L E R
3) The transformed string L~ then is just the last column of the matrix M 0 and
the index I is the number of the row of M 0 , in which the original text is contained.
In our example L ~ = HELWEER and I = 6 we start counting the the rows with
row no. 0.
This gives rise to the following pseudocode. We write here X instead of X~ and
~
L instead of L, since the purpose of the vector notation is only to distinguish the
vectors from the letters in the text.
3.4. The Burrows-Wheeler-transform 157
BWT-Encoder(X)
1 for j 0 to n 1
2 do M [0, j] X[j]
3 for i 0 to n 1
4 do for j 0 to n 1
5 do M [i, j] M [i 1, j + 1 mod n]
6 for i 0 to n 1
7 do row i of M 0 row i of M in lexicographic order
8 for i 0 to n 1
9 do L[i] M 0 [i, n 1]
10 i=0
11 while (row i of M 0 6= row i of M )
12 do i i + 1
13 Ii
14 return L and I
~ = H
L E L W E E R00
~ = E
E E E H L R W 00 .
~
Now obviously the first letter X(0) ~ is the letter in position
of our original text X
~ ~ ~
I of the sorted string E, so here X(0) = E(6) = W . Then we look at the position of
~ here there is only one W, which is letter
the letter just considered in the string L
~ This position gives us the location of the next letter of the original text,
no. 3 in L.
~
namely X(1) ~
= E(3) ~ hence X(2)
= H. H is found in position no. 0 in L, ~ ~
= E(0) = E.
~
Now there are three Es in the string L and we take the first one not used so far, here
~
the one in position no. 1, and hence X(3) ~
= E(1) = E. We iterate this procedure
~ ~ ~ ~
and find X(4) = E(4) = L, X(5) = E(2) = E, X(6) ~ ~
= E(5) = R.
This suggests the following pseudocode.
158 3. Compression and Decompression
BWT-Decoder(L, I)
1 E[0 . . n 1] sort L[0 . . n 1]
2 pi[1] I
3 for i 0 to n 1
4 do j = 0
5 while (L[j]) 6= E[pi[i 1]] OR j is a component of pi)
6 do j j + 1
7 pi[i] j
8 X[i] L[j]
9 return X
This algorithm implies a more formal description. Since the decoder only knows
~ he has to sort this string to find out E.
L, ~ To each letter L(j)
~ from the transformed
~ ~
string L record the position (j) in E from which it was jumped to by the process
described above. So the vector pi in our pseudocode yields a permutation such
~
that for each j = 0, . . . , n1 row j it is L(j) ~
= E((j)) in matrix M . In our example
= (3, 0, 1, 4, 2, 5, 6). This permutation can be used to reconstruct the original text
X~ of length n via X(n ~ 1 j) = L(
~ j (I)), where 0 (x) = x and j (x) = ( j1 (x))
for j = 1, . . . , n 1.
Observe that so far the original data have only been transformed and are not
compressed, since string L ~ has exactly the same length as the original string L.~ So
what is the advantage of the Burrows-Wheeler transformation? The idea is that the
transformed string can be much more efficiently encoded than the original string.
The dependencies among the letters have the effect that in the transformed string
~ there appear long blocks consisting of the same letter.
L
In order to exploit such frequent blocks of the same letter, Burrows and Wheeler
suggested the following move-to-front-code, which we shall illustrate again with
our example above.
We write down a list containing the letters used in our text in alphabetic order
indexed by their position in this list.
E H L R W
0 1 2 3 4
Then we parse through the transformed string L ~ letter by letter, note the index
of the next letter and move this letter to the front of the list. So in the first step we
note 1the index of the H, move H to the front and obtain the list
H E L R W
0 1 2 3 4
Then we note 1 and move E to the front,
E H L R W
0 1 2 3 4
note 2 and move L to the front,
3.4. The Burrows-Wheeler-transform 159
L E H R W
0 1 2 3 4
note 4 and move W to the front,
W L E H R
0 1 2 3 4
note 2 and move E to the front,
E W L H R
0 1 2 3 4
note 0 and leave E at the front,
E W L H R
0 1 2 3 4
note 4 and move R to the front,
R E W L H
0 1 2 3 4
So we obtain the sequence (1, 1, 2, 4, 2, 0, 4) as our move-to-front-code. The pseu-
docode may look as follows, where Q is a list of the letters occuring in the string
~
L.
Move-To-Front(L)
1 Q[0 . . n 1] list of m letters occuring in L ordered alphabetically
2 for i 0 to n 1
3 do j = 0
4 while (j 6= L[i])
5 j j+1
6 c[i] j
7 for l 0 to j
8 do Q[l] Q[l 1 mod j + 1]
9 return c
run-length codes.
The algorithm performed very well in practice regarding the compression rate
as well as the speed. The asymptotic optimality of compression has been proven for
a wide class of sources.
Exercises
3.4-1 Apply the Burrows-Wheeler-transform and the move-to-front code to the text
abracadabra.
3.4-2 Verify that the transformed string L ~ and the index i of the position in the
~
sorted text E (containing the first letter of the original text to be compressed) indeed
yield enough information to reconstruct the original text.
3.4-3 Show how in our example the decoder would obtain the string
~ =HELWEER from the move-to-front code (1, 1, 2, 4, 2, 0, 4) and the letters
L
E,H,L,W,R occuring in the text. Describe the general procedure for decoding move-
to-front codes.
3.4-4 We followed here the encoding procedure presented by Burrows and Wheeler.
Can the encoder obtain the transformed string L ~ even without constructing the two
matrices M and M ? 0
X7 X 7
1 (2i + 1)u (2j + 1)v
F (u, v) = cu cv f (i, j) cos cos .
4 i=0 j=0
16 16
162 3. Compression and Decompression
The cosine transform is applied after shifting the unsigned integers to signed
integers by subtraction of 2k1 .
DCT(f )
1 for u 0 to 7
2 do for v 0 to 7
3 do F (u, v) DCT - coefficient of matrix f
4 return F
The coefficients need not be calculated according to the formula above. They
can also be obtained via a related Fourier transform (see Exercises) such that a Fast
Fourier Transform may be applied. JPEG also supports wavelet transforms, which
may replace the discrete cosine transform here.
The discrete cosine transform can be inverted via
7 7
!
1 XX (2i + 1)u (2j + 1)v
f (i, j) = cu cv F (u, v) cos cos ,
4 u=0 v=0 16 16
1 1
for u = 0 for v = 0
where cu = 2 and cv = 2 are normalisation
1 for u 6= 0 1 for v 6= 0
constants.
In our example, the transformed block F is
235.6 1.0 12.1 5.2 2.1 1.7 2.7 1.3
22.6 17.5 6.2 3.2 2.9 0.1 0.4 1.2
10.9 9.3 1.6 1.5 0.2 0.9 0.6 0.1
7.1 1.9 0.2 1.5 0.9 0.1 0.0 0.3
F =
0.6 0.8 1.5 1.6 0.1 0.7 0.6 1.3
1.8 0.2 1.6 0.3 0.8 1.5 1.0 1.0
1.3 0.4 0.3 1.5 0.5 1.7 1.1 0.8
2.6 1.6 3.8 1.8 1.9 1.2 0.6 0.4
3.5.3. Quantisation
The discrete cosine transform maps integers to real numbers, which in each case
have to be rounded to be representable. Of course, this rounding already results in
a loss of information. However, the transformed block F will now be much easier to
manipulate. A quantisation takes place, which maps the entries of F to integers
3.5. Image compression 163
Quantisation(F )
1 for i 0 to 7
2 do for j 0 to 7
F (i,j)
3 do T (i, j) { Q(i,j) }
4 return T
F (i,j)
This quantisation transforms block F to a new block T with T (i, j) = { Q(i,j) },
where {x} is the closest integer to x. This block will finally be encoded. Observe that
in the transformed block F besides the entry F (0, 0) all other entries are relatively
small numbers, which has the effect that T mainly consists of 0s .
15 0 1 0 0 0 0 0
2 1 0 0 0 0 0 0
1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0
T = .
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
Coefficient T (0, 0), in this case 15, deserves special consideration. It is called DC
term (direct current), while the other entries are denoted AC coefficients (alternate
current).
3.5.4. Coding
Matrix T will finally be encoded by a Huffman code. We shall only sketch the
procedure. First the DC term will be encoded by the difference to the DC term of
164 3. Compression and Decompression
the previously encoded block. For instance, if the previous DC term was 12, then
T (0, 0) will be encoded as 3.
After that the AC coefficients are encoded according to the zig-zag order T (0, 1),
T (1, 0), T (2, 0), T (1, 1), T (0, 2), T (0, 3), T (1, 2), etc.. In our example, this yields the
sequence 0, 2, 1, 1, 1, 0, 0, 1 followed by 55 zeros. This zigzag order exploits
the fact that there are long runs of successive zeros. These runs will be even more
efficiently represented by application of run-length coding, i. e., we encode the
number of zeros before the next nonzero element in the sequence followed by this
element.
Integers are written in such a way that small numbers have shorter representa-
tions. This is achieved by splitting their representation into size (number of bits to
be reserved) and amplitude (the actual value). So, 0 has size 0, 1 and 1 have size
1. 3, 2, 2, and 3 have size 2, etc.
In our example this yields the sequence (2)(3) for the DC term followed by
(1, 2)(2), (0, 1)(1), (0, 1)(1), (0, 1)(1), (2, 1)(1), and a final (0, 0) as an end-
of-block symbol indicating that only zeros follow from now on. (1, 2)(2), for in-
stance, means that there is 1 zero followed by an element of size 2 and amplitude
2.
These pairs are then assigned codewords from a Huffman code. There are differ-
ent Huffman codes for the pairs (run, size) and for the amplitudes. These Huffman
codes have to be specified and hence be included into the code of the image.
In the following pseudocode for the encoding of a single 8 8-block T we shall
denote the different Huffman codes by encode-1, encode-2, encode-3.
Run-Length-Code(T )
1 c encode-1(size(DC T [0, 0]))
2 c c|| encode-3(amplitude(DC T [00]))
3 DC T [0, 0]
4 for l 1 to 14
5 do for i 0 to l
6 do if l = 1 mod 2
7 then u i
8 else u l i
9 if T [u, l u] = 0
10 then run run + 1
11 else c c|| encode -2(run, size(T [u, l u]))
12 c c|| encode-3(amplitude(T [u, l u])
13 run 0
14 if run > 0
15 then encode-2(0,0)
16 return c
240 0 10 0 0 0 0 0
24 12 0 0 0 0 0 0
14 13 0 0 0 0 0 0
0 0 0 0 0 0 0 0
F =
.
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
To F the inverse cosine transform is applied. This allows to decode the original
8 8block f of the original image in our example as
144 146 149 152 154 156 156 156
148 150 152 154 156 156 156 156
155 156 157 158 158 157 156 155
160 161 161 162 161 159 157 155
f =
.
163 163 164 163 162 160 158 156
163 164 164 164 162 160 158 157
160 161 162 162 162 161 159 158
158 159 161 161 162 161 159 158
Exercises
3.5-1 Find size and amplitude for the representation of the integers 5, -19, and 32.
3.5-2 Write the entries of the following matrix in zig zag order.
5 0 2 0 0 0 0 0
3 1 0 1 0 0 0 0
0 1 0 0 0 0 0 0
2 1 0 0 0 0 0 0
.
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
How would this matrix be encoded if the difference of the DC term to the previous
one was 2?
3.5-3 In our example after quantising the sequence (2)(3), (1, 2)(2), (0, 1)(1),
(0, 1)(1), (0, 1)(1), (2, 1)(1), (0, 0) has to be encoded. Assume the Huffman
codebooks would yield 011 to encode the difference 2 from the preceding blocks
DC, 0, 01, and 11 for the amplitudes 1, 2, and 3, respectively, and 1010, 00,
11011, and 11100 for the pairs (0, 0), (0, 1), (1, 2), and (2, 1), respectively. What
would be the bitstream to be encoded for the 8 8 block in our example? How many
bits would hence be necessary to compress this block?
166 3. Compression and Decompression
for quantising after the cosine transform in the block of our example?
3.5-5 What would be the zig-zag-code in this case (assuming again that the DC
term would have difference 3 from the previous DC term)?
3.5-6 For any sequence (f (n))n=0,...,m1 define a new sequence (f(n))n=0,...,2m1
by
f (n) for n = 0, . . . , m 1,
f(n) =
f (2m 1 n) for n = m, . . . , 2m 1 .
This sequence can be expanded to a Fourier-series via
2m1
X 2m1
1 1 X
f(n) =
2 2
g(u)ei 2m nu with g(u) = f (u)ei 2m nu , i= 1 .
2m n=0
2m n=0
Problems
related to special search problems. Show that in this case a prefix code with lengths
L(1) L(a) exists if and only if
X 1
2L(x) .
2
xX
Chapter Notes
The frequency table of the letters in English texts is taken from [?]. The Huffman
coding algorithm was introduced by Huffman in [113]. A pseudocode can be found in
[53], where the Huffman coding algorithm is presented as a special Greedy algorithm.
There are also adaptive or dynamic variants of Huffman-coding, which adapt the
Huffman-code if it is no longer optimal for the actual frequency table, for the case
that the probability distribution of the source is not known in advance. The 3/4-
conjecture on Krafts inequality for fix-free-codes is due to Ahlswede, Balkenhol,
and Khachatrian [4].
Arithmetic coding has been introduced by Rissanen [206] and Pasco [193]. For
a discussion of implementation questions see [152, 152, 263]. In the section on mod-
elling we are following the presentation of Willems, Shtarkov and Tjalkens in [262].
The exact calculations can be found in their original paper [261] which received the
Best Paper Award of the IEEE Information Theory Society in 1996. The Krichevsky-
Trofimov-estimator had been introduced in [146].
We presented the two original algorithms LZ77 and LZ78 [266, 267] due to
Lempel and Ziv. Many variants, modifications and extensions have been developed
since that concerning the handling of the dictionary, the pointers, the behaviour
after the dictionary is complete, etc. For a description, see, for instance, [24] or
[25]. Most of the prominent tools for data compression are variations of Ziv-Lempel-
coding. For example zip and gzip are based on LZ77 and a variant of LZ78 is
used by the program compress.
The Burrows-Wheeler transform was introduced in the technical report [35]. It
168 3. Compression and Decompression
became popular in the sequel, especially because of the Unix compression tool bzip
based on the Burrows-Wheeler-transform, which outperformed most dictionary
based tools on several benchmark files. Also it avoids arithmetic coding, for which
patent rights have to be taken into consideration. Further investigations on the
Burrows-Wheeler-transform have been carried out, for instance in [21, 68, 149].
We only sketched the basics behind lossy image compression, especially the
preparation of the data for application of techniques as Huffman coding. For a
detailed discussion we refer to [250], where also the new JPEG2000 standard is
described. Our example is taken from [258].
JPEGshort for Joint Photographic Experts Groupis very flexible. For in-
stance, it also supports lossless data compression. All the topics presented in the
section on image compression are not unique. There are models involving more basic
colours and further transforms besides the Y Cb Cr -transform (for which even differ-
ent scaling factors for the chrominance channels were used, the formula presented
here is from [250]). The cosine transform may be replaced by another operation like
a wavelet transform. Further, there is freedom to choose the quantisation matrix,
responsible for the quality of the compressed image, and the Huffman code. On the
other hand, this has the effect that these parameters have to be explicitly specified
and hence are part of the coded image.
The ideas behind procedures for video and sound compression are rather similar
to those for image compression. In principal, they follow the same steps. The amount
of data in these cases, however, is much bigger. Again information is lost by remov-
ing irrelevant information not realizable by the human eye or ear (for instance by
psychoacoustic models) and by quantising, where the quality should not be reduced
significantly. More refined quantising methods are applied in these cases.
Most information on data compression algorithms can be found in literature
on Information Theory, for instance [54, 101], since the analysis of the achievable
compression rates requires knowledge of source coding theory. Recently, there have
appeared several books on data compression, for instance [25, 102, 185, 218, 219], to
which we refer to further reading. The benchmark files of the Calgary Corpus and
the Canterbury Corpus are available under [36] or [37].
The book of I. Csiszr and J. Krner [57] analyses different aspects of information
theory including the problems of data compression too.
4. Reliable Computation
4.1.1. Terminology
A probability space is a triple (, A, P) where is the set of elementary events,
A is a set of subsets of called the set of events and P : A [0, 1] is a function.
4.1. Probability theory 171
For E A, the value P(E) is called the probability of event E. It is required that
A and that E A implies r E A. Further, if a (possibly infinite) sequence
of sets is in A then so is their union. Also, it is assumed that P() = 1 and that if
E1 , E2 , . . . A are disjoint then
[ X
P Ei = P(Ei ) .
i i
Example 4.1 Let = {1, . . . , n} where A is the set of all subsets of and P(E) = |E|/n .
This is an example of a discrete probability space: one that has a countable number of
elements.
More generally, a discrete probability space is P given by a countable set =
{1 , 2 , . . . }, and a sequence p1 , p2 , . . . with pi 0, p = 1. ThePset A of events is
i i
the set of all subsets of , and for an event E we define P(E) = E pi .
i
EX = p1 x1 + p2 x2 + .
It is easy to see that the expected value is a linear function of the random variable:
E(X + Y ) = EX + EY ,
even if X, Y are not independent. On the other hand, if variables X, Y are indepen-
dent then the expected values can also be multiplied:
EXY = EX EY . (4.1)
172 4. Reliable Computation
There is an important simple inequality called the Markov inequality, which says
that for an arbitrary nonnegative random variable X and any value > 0 we have
P[ X ] EX/ . (4.2)
where the inequality (useful for small f and ep < f ) comes via 1 > 1 p > 1 f
f
and ln(1 f ) 1f from (4.3). Using the concavity of logarithm, it can be shown
that D(f, p) is always nonnegative, and is 0 only if f = p (see Exercise 4.1-1).
P[ Sn f n ] enD(f,p) .
Proof For a certain real number > 1 (to be chosen later), let Yn be the random
variable that is if Xn = 1 and 1 if Xn = 0, and let Pn = Y1 Yn = Sn : then
P[ Sn f n ] = P[ Pn f n ] .
Applying the Markov inequality (4.2) and (4.1), we get
P[ Pn f n ] EPn /f n = (EY1 /f )n ,
f (1p)
where EY1 = p + (1 p). Let us choose = p(1f ) , this is > 1 if p < f . Then we
1p
get EY1 = 1f , and hence
pf (1 p)1f
EY1 /f = = eD(f,p) .
f f (1 f )1f
This theorem also yields some convenient estimates for binomial coefficients. Let
h(f ) = f ln f (1 f ) ln(1 f ) .
This is sometimes called the entropy of the probability distribution (f, 1 f ) (mea-
sured in logarithms over base e instead of base 2). From inequality (4.3) we obtain
the estimate
e
f ln f h(f ) f ln (4.7)
f
which is useful for small f .
Corollary 4.2 We have, for f 1/2:
Xn f n
n nh(f ) e
e . (4.8)
i f
if n
n
n
Substituting g = 1 f , and noting the symmetries f = g , h(f ) = h(g) and (4.7)
gives (4.8).
174 4. Reliable Computation
Exercises
4.1-1 Prove that the statement made in the main text that D(f, p) is always non-
negative, and is 0 only if f = p.
4.1-2 For f = p + , derive from Theorem 4.1 the useful bound
2
P[ Sn f n ] e2 n
.
Hint. Let F (x) = D(x, p), and use the Taylor formula: F (p + ) = F (p) + F 0 (p) +
F 00 (p + 0 ) 2 /2, where 0 0 .
4.1-3 Prove that in Theorem 4.1, the assumption that Xi are independent and
identically distributed can be weakened: replaced by the single inequality
P[ Xi = 1 | X1 , . . . , Xi1 ] p .
Example 4.2 Given an undirected graph G with N nodes, suppose we want to study the
question whether it has a Hamiltonian cycle (a sequence (u1 , . . . , un ) listing all vertices of
G such that (ui , ui+1 ) is an edge for each i < n and also (un , u1 ) is an edge). This question
is described by a Boolean function f as follows. The graph can be described with N2
Boolean variables xij (1 i < j N ): xij is 1 if and only if there is an edge between nodes
i and j. We define f (x12 , x13 , . . . , xN 1,N ) = 1 if there is a Hamiltonian cycle in G and 0
otherwise.
Example 4.3[Boolean vector function] Let n = m = 2k, let the input be two integers
u, v, written as k-bit strings: x = (u1 , . . . , uk , v1 , . . . , vk ). The output of the function is
their product y = u v (written in binary): if u = 5 = (101)2 , v = 6 = (110)2 then
y = u v = 30 = (11110)2 .
There are only four one-variable Boolean functions: the identically 0, identically
1, the identity and the negation: x x = 1 x. We mention only the following
two-variable Boolean functions: the operation of conjunction (logical AND):
(
1 if x = y = 1 ,
xy =
0 otherwise ,
A finite number of Boolean functions is sufficent to express all others: thus, arbi-
trarily complex Boolean functions can be computed by elementary operations.
In some sense, this is what happens inside computers.
Claim 4.6 The set {, , } forms a complete basis; in other words, every Boolean
function can be represented by a Boolean expression using only these connectives.
4.2.2. Circuits
A Boolean expression is sometimes large since when writing it, there is no possibility
for reusing partial results. (For example, in the expression
((x y z) u) ((x y z) v) ,
the part x y z occurs twice.) This deficiency is corrected by the following more
general formalism.
A Boolean circuit is essentially an acyclic directed graph, each of whose nodes
computes a Boolean function (from some complete basis) of the bits coming into it
on its input edges, and sends out the result on its output edges (see Figure 4.2). Let
us give a formal definition.
For every node v there is a natural number kv showing its number of inputs. The
sources, nodes v with kv = 0, are called input nodes: we will denote them, in
increasing order, as
inpi (i = 1, . . . , n) .
To each non-input node v a Boolean function
bv (y1 , . . . , ykv )
4.2. Logic circuits 177
0 1 1
1 0
1 1
Figure 4.2 The assignment (values on nodes, configuration) gets propagated through all the gates.
This is the computation.
from the complete basis Q is assigned: it is called the gate of node v. It has as many
arguments as the number of entering edges. The sinks of the graph, nodes without
outgoing edges, will be called output nodes: they can be denoted by
outi (i = 1, . . . , m) .
(Our Boolean circuits will mostly have just a single output node.) To every non-input
node v and every j = 1, . . . , kv belongs a node argj (v) V (the node sending the
value of input variable yj of the gate of v). The circuit defines a graph G = (V, E)
whose set of edges is
E = { (argj (v), v) : v V, j = 1, . . . , kv } .
We require argj (v) < v for each j, v (we identified the with the natural numbers
1, . . . , N ): this implies that the graph G is acyclic. The size
|N |
of the circuit N is the number of nodes. The depth of a node v is the maximal
length of directed paths leading from an input node to v. The depth of a circuit is
the maximum depth of its output nodes.
Definition 4.8 An input assignment, or input configuration to our circuit N
is a vector x = (x1 , . . . , xn ) with xi {0, 1} giving value xi to node inpi :
valx (v) = yv (x) = xi
for v = inpi , i = 1, . . . , n. The function yv (x) can be extended to a unique con-
figuration v 7 yv (x) on all other nodes of the circuit as follows. If gate bv has k
178 4. Reliable Computation
x1 x2 x3 x4 x5 x6 x7 x8
y2,1 y2,2
y3,1
arguments then
yv = bv (yarg1 (v) , . . . , yargk (v) ) . (4.11)
For example, if bv (x, y) = x y, and uj = argj (v) (j = 1, 2) are the input nodes
to v then yv = yu1 yu2 . The process of extending the configuration by the above
equation is also called the computation of the circuit. The vector of the values
youti (x) for i = 1, . . . , m is the result of the computation. We say that the Boolean
circuit computes the vector function
x 7 (yout1 (x), . . . , youtm (x)) .
The assignment procedure can be performed in stages: in stage t, all nodes of depth
t receive their values.
We assign values to the edges as well: the value assigned to an edge is the one
assigned to its start node.
Theorem 4.10
(a) Over the complete basis consisting of the set of all 3-argument Boolean functions,
for each n there is a Boolean circuit of input size n and depth 3 log(n + 1)
whose output vector represents the sum of the input bits as a binary number.
b Over this same complete basis, for each n there is a Boolean circuit of input size
n and depth 2 log(n + 1) computing a near-majority.
when performed in the naive way, will typically take more than a constant number
of steps: the numbers yi,j have length up to i + 1 and therefore the addition may
add i to the depth, bringing the total depth to 1 + 2 + + k = (k 2 ).
The following observation helps to decrease
Pk the depth. Let a, b, c be three num-
bers in binary notation: for example, a = i=0 ai 2i . There are simple parallel for-
mulas to represent the sum of these three numbers as the sum of two others, that is
to compute a + b + c = d + e where d, e are numbers also in binary notation:
di = ai + bi + ci mod 2 ,
(4.12)
ei+1 = b(ai + bi + ci )/2c .
Since both formulas are computed by a single 3-argument gate, 3 numbers can be
reduced to 2 (while preserving the sum) in a single parallel computation step. Two
such steps reduce 4 numbers to 2. In 2(k 1) steps therefore they reduce a sum of 2k
terms to a sum of 2 numbers of length k. Adding these two numbers in the regular
way increases the depth by k: we found that 2k bits can be be added in 3k 2 steps.
To prove (4.10), construct the circuit as in the proof of (4.10), but without the
last addition: the output is two k-bit numbers whose sum we are interested in. The
highest-order nonzero bit of these numbers is at some position < k. If the sum is
more than 2k1 then one these numbers has a nonzero bit at position (k 1) or
(k 2). We can determine this in two applications of 3-input gates.
Exercises
4.2-1 Show that {1, , } is a complete basis.
4.2-2 Show that the function x NOR y = (x y) forms a complete basis by itself.
180 4. Reliable Computation
0 1
4.2-3 Let us fix the complete basis {, }. Prove Proposition 4.6 (or look up its
proof in a textbook). Use it to give an upper bound for an arbitrary Boolean function
f of n variables, on:
(a) the smallest size of a Boolean expression for f ;
(b) the smallest size of a Boolean circuit for f ;
(c) the smallest depth of a Boolean circuit for f ;
4.2-4 Show that for every n there is a Boolean function f of n variables such that
every Boolean circuit in the complete basis {, } computing f contains (2n /n)
nodes. Hint. For a constant c > 0, upperbound the number of Boolean circuits with
at most c2n /n nodes and compare it with the number of Boolean functions over n
variables.]
4.2-5 Consider a circuit Mr3 with 3r inputs, whose single output bit is computed
from the inputs by r levels of 3-input majority gates. Show that there is an input
vector x which is 1 in only n1/ log 3 positions but with which Mr3 outputs 1. Thus
a small minority of the inputs, when cleverly arranged, can command the result of
this circuit.
Let us impose conditions on the kind of noise that will be allowed. Each fault
should occur only with probability at most , two specific faults should only occur
with probability at most 2 , and so on.
Definition 4.12 For an > 0, let us say that the random configuration (Yv : v
V ) is -admissible if
(a) Yinp(i) = xi for i = 1, . . . , n.
(b) For every set C of non-input nodes, we have
Definition 4.13 We say that the circuit N with output node w is (, )-resilient
if for all inputs x, all -admissible configurations Y, we have P[ Yw 6= valx (w) ] .
Let us explore this concept. There is no (, )-resilient circuit with < , since
even the last gate can fail with probability . So, let us, a little more generously,
allow > 2. Clearly, for each circuit N and for each > 0 we can choose small
enough so that N is (, )-resilient. But this is not what we are after: hopefully, one
does not need more reliable gates every time one builds a larger circuit. So, we hope
to find a function
F (N, )
and an 0 > 0 with the property that for all < 0 , 2, every Boolean circuit N
of size N there is some (, )-resilient circuit N 0 of size F (N, ) computing the same
function as N . If we achieve this then we can say that we prevented the accumulation
of errors. Of course, we want to make F (N, ) relatively small, and 0 large (allowing
more noise). The function F (N, )/N can be called the redundancy: the factor by
which we need to increase the size of the circuit to make it resilient. Note that the
problem is nontrivial even with, say, = 1/3. Unless the accumulation of errors is
prevented we will lose gradually all information about the desired output, and no
< 1/2 could be guaranteed.
How can we correct errors? A simple idea is this: do everything 3 times and
then continue with the result obtained by majority vote.
Definition 4.14 For odd natural number d, a d-input majority gate is a Boolean
function that outputs the value equal to the majority of its inputs.
182 4. Reliable Computation
Note that a d-input majority can be computed using O(d) gates of type AND
and NOT.
Why should majority voting help? The following informal discussion helps un-
derstanding the benefits and pitfalls. Suppose for a moment that the output is a
single bit. If the probability of each of the three independently computed results
failing is then the probability that at least 2 of them fails is bounded by 3 2 .
Since the majority vote itself can fail with some probability the total probability
of failure is bounded by 3 2 + . We decrease the probability of failure, provided
the condition 3 2 + < holds.
We found that if is small, then repetition and majority vote can make it
smaller. Of course, in order to keep the error probability from accumulating, we
would have to perform this majority operation repeatedly. Suppose, for example,
that our computation has t stages. Our bound on the probability of faulty output
after stage i is i . We plan to perform the majority operation after each stage i. Let
us perform stage i three times. The probability of failure is now bounded by
i+1 = i + 3 2 + . (4.15)
Here, the error probabilities of the different stages accumulate, and even if 3 2 + <
we only get a bound t < (t 1). So, this strategy will not work for arbitrarily large
computations.
Here is a somewhat mad idea to avoid accumulation: repeat everything before
the end of stage i three times, not only stage i itself. In this case, the growing
bound (4.15) would be replaced with
i+1 = 3(i + )2 + .
Now if i < and 12 2 + < then also i+1 < , so errors do not accumulate. But
we paid an enormous price: the fault-tolerant version of the computation reaching
stage (i + 1) is 3 times larger than the one reaching stage i. To make t stages fault-
tolerant this way will cost a factor of 3t in size. This way, the function F (N, )
introduced above may become exponential in N .
The theorem below formalizes the above discussion.
Theorem 4.15 Let R be a finite and complete basis for Boolean functions. If
2 0.01 then every function can be computed by an (, )-resilient circuit over
R.
Proof. For simplicity, we will prove the result for a complete basis that contains the
three-argument majority function and contains not functions with more than three
arguments. We also assume that faults occur independently.
Let N be a noise-free circuit of depth t computing function f . We will prove
that there is an (, )-resilient circuit N 0 of depth 2t computing f . The proof is by
induction on t. The sufficient conditions on and will emerge from the proof.
The statement is certainly true for t = 1, so suppose t > 1. Let g be the
output gate of the circuit N , then f (x) = g(f1 (x), f2 (x), f3 (x)). The subcircuits
Ni computing the functions fi have depth t 1. By the inductive assumption,
there exist (, )-resilient circuits Ni0 of depth 2t 2 that compute fi . Let M be a
4.3. Expensive fault-tolerance in Boolean circuits 183
new circuit containing copies of the circuits Ni0 (with the corresponding input nodes
merged), with a new node in which f (x) is computed as g is applied to the outputs
of Ni0 . Then the probability of error of M is at most 3 + < 4 if < since
each circuit Ni0 can err with probability and the node with gate g can fail with
probability .
Let us now form N 0 by taking three copies of M (with the inputs merged) and
adding a new node computing the majority of the outputs of these three copies. The
error probability of N 0 is at most 3(4)2 + = 48 2 + . Indeed, error will be due to
either a fault at the majority gate or an error in at least two of the three independent
copies of M. So under condition
48 2 + , (4.16)
the circuit N 0 is (, )-resilient. This condition will be satisfied by 2 0.01.
The circuit N 0 constructed in the proof above is at least 3t times larger than N .
So, the redundancy is enormous. Fortunately, we will see a much more economical
solution. But there are interesting circuits with small depth, for which the 3t factor
is not extravagant.
Theorem 4.16 Over the complete basis consisting of all 3-argument Boolean func-
tions, for all sufficiently small > 0, if 2 0.01 then for each n there is an
(, )-resilient Boolean circuit of input size n, depth 4 log(n + 1) and size (n + 1)7
outputting a near-majority (as given in Definition 4.9).
Proof. Apply Theorem 4.15 to the circuit from part (4.10) of Theorem 4.10: it gives
a new, 4 log(n + 1)-deep (, )-resilient circuit computing a near-majority. The size
of any such circuit with 3-input gates is at most 34 log(n+1) = (n + 1)4 log 3 < (n + 1)7 .
Exercises
4.3-1 Exercise 4.2-5 suggests that the iterated majority vote Mr3 is not safe against
manipulation. However, it works very well under some circumstances. Let the input
to Mr3 be a vector X = (X1 , . . . , Xn ) of independent Boolean random variables
with P[ Xi = 1 ] = p < 1/6. Denote the (random) output bit of the circuit by Z.
Assuming that our majority gates can fail with probability p/2 independently,
prove
k
P[ Z = 1 ] max{10, 0.3(p/0.3)2 } .
Hint. Define g(p) = + 3p2 , g0 (p) = p, gi+1 (p) = g(gi (p)), and prove P[ Z = 1 ]
gr (p). ]
4.3-2 We say that a circuit N computes the function f (x1 , . . . , xn ) in an (, )-
input-robust way, if the following holds: For any input vector x = (x1 , . . . , xn ), for
any vector X = (X1 , . . . , Xn ) of independent Boolean random variables perturbing
it in the sense P[ Xi 6= xi ] , for the output Y of circuit N on input X we have
P[ Y = f (x) ] 1 . Show that if the function x1 xn is computable on an
(, 1/4)-input-robust circuit then 1/n.
184 4. Reliable Computation
F (n, ) = N log(n/) ,
for all < 0 , 3, for every deterministic computation of size N there is an
(, )-resilient computation of size R0 F (N, ) with the same result.
Let us introduce a concept that will simplify the error analysis of our circuits,
making it independent of the input vector x.
Clearly, if for all -admissible random configurations the output is tainted with
probability then the circuit is (, )-resilient.
4.4.1. Cables
So far, we have only made use of redundancy idea (4) of the introduction to the
present chapter: repeating computation steps. Let us now try to use idea (4) (keeping
information in redundant form) in Boolean circuits. To protect information traveling
from gate to gate, we replace each wire of the noiseless circuit by a cable of k wires
(where k will be chosen appropriately). Each wire within the cable is supposed to
carry the same bit of information, and we hope that a majority will carry this bit
even if some of the wires fail.
1 0 0 0 0 0 0 1 0 0
1 0 1 0 0
minority
restoring organ
smaller minority
4.4.2. Compressors
How to build a restoring organ? Keeping in mind that this organ itself must also
work in noise, one solution is to build (for an approriate 0 ) a special (, 0 )-resilient
circuit that computes the near-majority of its k inputs in k independent copies.
Theorem 4.16 provides a circuit of size k(k + 1)7 to do this.
It turns out that, at least asymptotically, there is a better solution. We will look
for a very simple restoring organ: one whose own noise we can analyse easily. What
could be simpler than a circuit having only one level of gates? We fix an odd positive
integer constant d (for example, d = 3). Each gate of our organ will be a d-input
majority gate.
Definition 4.20 A multigraph is a graph in which between any two vertices there
may be several edges, not just 0 or 1. Let us call a bipartite multigraph with k inputs
and k outputs, d-half-regular. if each output node has degree d. Such a graph is a
(d, , , k)-compressor if it has the following property: for every set E of at most
k inputs, the number of those output points connected to at least d/2 elements
of E (with multiplicity) is at most k.
there is an such that for all integer k > 0 there is a (d, , , k)-compressor.
Note that for d = 3, the theorem does not guarantee a compressor with < 1.
Proof We will not give an explicit construction for the multigraph, we will just show
that it exists. We will select a d-half-regular multigraph randomly (each such multi-
graph with the same probability), and show that it will be a (d, , , k)-compressor
with positive probability. This proof method is called the probabilistic method.
Let
s = bd/2c .
Our construction will be somewhat more general, allowing k 0 6= k outputs. Let us
generate a random bipartite d-half-regular multigraph with k inputs and k 0 outputs
in the following way. To each output, we draw edges from d random input nodes
chosen independently and with uniform distribution over all inputs. Let A be an
input set of size k, let v be an output node and let Ev be the event that v has s + 1
or more edges from A. Then we have
d s+1 d s+1
P(Ev ) = =: p .
s+1 s
4.4. Safeguarding intermediate results 187
On the average (in expected value), the event Ev will occur for pk 0 different output
nodes v. For an input set A, let FA be the event that the set of nodes v for which
Ev holds has size > k 0 . By inequality (4.6) we have
k0
ep
P(FA ) .
The number M of sets A of inputs with k elements is, using inequality (4.7),
X k e k
M .
i
ik
The probability that our random graph is not a compressor is at most as large as
the probability that there is at least one input set A for which event FA holds. This
can be bounded by 0
M P(FA ) eDk
where
D = (s k/k 0 ) ln ln (ds) ln + 1 k/k 0 .
As we decrease the first term of this expression dominates. Its coefficient is positive
according to the assumption (4.17). We will have D > 0 if
!
ln (ds) ln + 1 + k/k 0
< exp .
s k/k 0
pR
be the probability of this event. Assuming that the gates of R fail independently
with probability , inequality (4.6) gives
k
e
pR . (4.18)
Example 4.5 Choose = 0.4, d = 7, = 107 as in Example 4.4, further = 0.14 (this
188 4. Reliable Computation
m m
2m + 0.14m = 2.14m
restoring organ
8
will satisfy the inequality (4.19) needed later). With = 109 , we get pR e10 k .
The attractively small degree d = 7 led to an extremely unattractive probability bound
on the failure of the whole compressor. This bound does decrease exponentially with cable
width k, but only an extremely large k would make it small.
Example 4.6 Choosing again = 0.4, but d = 41 (voting in each gate of the compressor
over 41 wires instead of 7), leads to somewhat more realistic results. This choice allows
= 0.15. With = 0.14, = 109 again, we get pR e0.32k .
These numbers look less frightening, but we will still need many scores of wires in the
cable to drive down the probability of compression failure. And although in practice our
computing components fail with frequency much less than 109 , we may want to look at
the largest that still can be tolerated.
Definition 4.22 Given a Boolean circuit N with a single bit of output (for sim-
plicity), a cable width k and a Boolean circuit R with k inputs and k outputs, let
N 0 = Cab(N , R)
be the Boolean circuit that we obtain as follows. The input nodes of N 0 are the same
as those of N . We replace each wire of N with a cable of width k, and each gate of
4.4. Safeguarding intermediate results 189
N with an executive organ followed by a restoring organ that is a copy of the circuit
R. The new circuit has k outputs: the outputs of the restoring organ of N 0 belonging
to the last gate of N .
Lemma 4.23 There are constants d, 0 , , > 0 and for every cable width k a
circuit R of size 2k and gate size d with the following property. For every Boolean
circuit N of gate size 2 and number of nodes N , for every < 0 , for every -
admissible configuration of N 0 = Cab(N , R), the probability that not every cable of
e k
N 0 is -safe is < 2N ( ) .
Proof We know that there are d, and < 1/2 with the property that for all k a
(d, , , k)-compressor exists. Let be chosen to satisfy
(2 + ) + 1 , (4.19)
and define
= /(2 + ) . (4.20)
Let R be a restoring organ built from a (d, , , k)-compressor. Consider a gate v
of circuit N , and the corresponding executive organ and restoring organ in N 0 . Let
us estimate the probability of the event Ev that the input cables of this combined
organ are -safe but its output cable is not. Assume that the two incoming cables
are safe: then at most 2k of the outputs of the executive organ are tainted due
to the incoming cables: new taint can still occur due to failures. Let Ev1 be the
event that the executive organ taints at least k more of these outputs. Then
e k
P(Ev1 ) ( ) , using the estimate (4.18). The outputs of the executive organ
are the inputs of the restoring organ. If no more than (2 + )k = k of these are
tainted then, in case the organ operates perfectly, it would decrease the number of
tainted wires to (2 + )k. Let Ev2 be the event that the restoring organ taints
e k
an additional k of these wires. Then again, P(Ev2 ) ( ) . If neither Ev1 nor
Ev2 occur then at most (2 + )k + k k (see (4.19)) tainted wires emerge
from the restoring organ, so the outgoing cable is safe. Therefore Ev Ev1 Ev2
e k
and hence P(Ev ) 2( ) .
Let V = {1, . . . , N } be the nodes of the circuit N . Since the incoming cables of
the whole circuit N 0 are safe, the event that there is some cable that is not safe is
e k
contained in E1 E2 EN ; hence the probability is bounded by 2N ( ) .
4.4.4. Endgame
Proof Proof of Theorem 4.17 We will prove the theorem only for the case when
our computation is a Boolean circuit with a single bit of output. The generalization
with more bits of output is straightforward. The proof of Lemma 4.23 gives us a
e k
circuit N 0 whose output cable is safe except for an event of probability < 2N ( ) .
190 4. Reliable Computation
N log( N/)
size N each gate fails
noiseless
with prob. e
log(6N/)
k
. (4.21)
log e 0
It remains to add a little circuit to this output cable to extract from it the majority
reliably. This can be done using Theorem 4.16, adding a small extra circuit of size
(k + 1)7 that can be called the coda to N 0 . Let us call the resulting circuit N 00 .
The probability that the output cable is unsafe is < /3. The probability that the
output cable is safe but the coda circuit fails is bounded by 2. So, the probability
that N 00 fails is 2 + /3 , by the assumption 3.
Let us estimate the size of N 00 . By (4.21), we can choose cable width k =
O(log(N/)). We have |N 0 | 2kN , hence
|N 00 | 2kN + (k + 1)7 = O(N log(N/)).
Example 4.7 Take the constants of Example 4.6, with defined in equation (4.20): then
0 = 109 , d = 41, = 0.4, = 0.14, = 0.15, = 0.07, giving
1
6.75 ,
ln e0
4.4. Safeguarding intermediate results 191
so making k as small as possible (ignoring that it must be integer), we get k 6.75 ln(N/).
With = 108 , N = 1012 this allows k = 323. In addition to this truly unpleasant cable
size, the size of the coda circuit is (k + 1)7 4 1017 , which dominates the size of the
rest of N 00 (though as N it becomes asymptotically negligible).
As Example 4.7 shows, the actual price in redundancy computable from the
proof is unacceptable in practice. The redundancy O(lg(N/)) sounds good, since it
is only logarithmic in the size of the computation, and by choosing a rather large
majority gate (41 inputs), the factor 6.75 in the O() here also does not look bad;
still, we do not expect the final price of reliability to be this high. How much can
this redundancy improved by optimization or other methods? Problem 4-6 shows
that in a slightly more restricted error model (all faults are independent and have
the same probability), with more randomization, better constants can be achieved.
Exercises 4.4-1, 4.4-2 and 4.4-5 are concerned with an improved construction for the
coda circuit. Exercise 4.5-2 shows that the coda circuit can be omitted completely.
But none of these improvements bring redundancy to acceptable level. Even aside
from the discomfort caused by their random choice (this can be helped), concentra-
tors themselves are rather large and unwieldy. The problem is probably with using
circuits as a model for computation. There is no natural way to break up a general
circuit into subunits of non-constant size in order to deal with the reliability problem
in modular style.
their compressor property as for their expander property (see the section on reliable
storage).
For vectors v, w, let (v, w) denote their inner product. A d-half-regular bipartite
multigraph with 2k nodes can be defined by an incidence matrix M = (mij ),
where mij is the number of edges connecting input j to output i. Let e be the vector
(1, 1, . . . , 1)T . Then M e = de, so e is an eigenvector of M with eigenvalue
P d.
Moreover, d is the largest eigenvalue of M . Indeed, denoting by |x|1 = i |xi | for
any row vector x = (x1 , . . . , xk ), we have |xM |1 |x|1 .
Theorem 4.24 Let G be a multigraph defined by the matrix M . For all > 0, and
< d /2, (4.22)
there is an > 0 such that if the second largest eigenvalue of the matrix M T M is
2 then G is a (d, , , k)-compressor.
i>1
2 2 2
= d (f , e) /k + (f , f ) .
Suppose that there are ck nodes i with di > d/2, then this says
c 4(/d)2 + 42 .
Since (4.22) implies 4(/d)2 < , it follows that M is a (d, , , k, k)-compressor for
small enough .
4.4. Safeguarding intermediate results 193
It is actually sufficient to look for graphs with large k and /d < c < 1 where
d, c are constants. To see this, let us define the product of two bipartite multigraphs
with 2k vertices by the multigraph belonging to the product of the corresponding
matrices.
Suppose that M is symmetric: then its second largest eigenvalue is and the
ratio of the two largest eigenvalues of M r is (/d)r . Therefore using M r for a
sufficiently large r as our matrix, the condition (4.22) can be satisfied. Unfortunately,
taking the power will increase the degree d, taking us probably even farther away
from practical realizability.
We found that there is a construction of a compressor with the desired param-
eters as soon as we find multigraphs with arbitrarily large sizes 2k, with symmetric
matrices M k and with a ratio of the two largest eigenvalues of M k bounded by
a constant c < 1 independent of k. There are various constructions of such multi-
graphs (see the references in the historical overview). The estimation of the desired
eigenvalue quotient is never very simple.
Exercises
4.4-1 The proof of Theorem 4.17 uses a coda circuit of size (k + 1)7 . Once we
proved this theorem we could, of course, apply it to the computation of the final
majority itself: this would reduce the size of the coda circuit to O(k log k). Try out
this approach on the numerical examples considered above to see whether it results
in a significant improvement.
4.4-2 The proof of Theorem 4.21 provided also bipartite graphs with the compres-
sor property, with k inputs and k 0 < 0.8k outputs. An idea to build a smaller coda
circuit in the proof of Theorem 4.17 is to concatenate several such compressors,
decreasing the number of cables in a geometric series. Explore this idea, keeping
in mind, however, that as k decreases, the exponential error estimate in inequal-
ity (4.18) becomes weaker.
4.4-3 In a noisy Boolean circuit, let Fv = 1 if the gate at vertex v fails and 0
otherwise. Further, let Tv = 1 if v is tainted, and 0 otherwise. Suppose that the dis-
tribution of the random variables Fv does not depend on the Boolean input vector.
Show that then the joint distribution of the random variables Tv is also independent
of the input vector.
4.4-4 This exercise extends the result of Exercise 4.3-1 to random input vectors:
it shows that if a random input vector has only a small number of errors, then the
iterated majority vote Mr3 of Exercise 4.2-5 may still work for it, if we rearrange the
input wires randomly. Let k = 3r , and let j = (j1 , . . . , jk ) be a vector of integers
ji {1, . . . , k}. We define a Boolean circuit C(j) as follows. This circuit takes input
vector x = (x1 , . . . , xk ), computes the vector y = (y1 , . . . , yk ) where yi = xji (in
other words, just leads a wire from input node ji to an intermediate node i) and
then inputs y into the circuit Mr3 .
Denote the (possibly random) output bit of C(j) by Z. For any fixed input
vector x, assuming that our majority gates can fail with probability /2
independently, denote q(j, x) := P[ Z = 1 ]. Assume that the input is a vector
X = (X1 , . . . , Xk ) of (not necessarily independent) Boolean random variables, with
194 4. Reliable Computation
P
p(x) := P[ X = x ]. Denoting |X| = i Xi , assume P[ |X| > k ] < 1. Prove
that there is a choice of the vector j for which
X k
p(x)q(j, x) + max{10, 0.3(/0.3)2 } .
x
The choice may depend on the distribution of the random vector X. Hint. Choose the
vector j (and hence the circuit C(j)) randomly, as a random vector J = (J1 , . . . , Jk )
where the variables Ji are independent and uniformly distributed over {1, . . . , k},
and denote s(j) := P[ J = j ]. Then prove
X X k
s(j) p(x)q(j, x) + max{10, 0.3(/0.3)2 }.
j x
P
For this, interchange the averaging over x and j. Then note that j s(j)q(j, x)
is the probability of Z = 1 when the wires Ji are chosen randomly on the fly
during the computation of the circuit. ]
4.4-5 Taking the notation of Exercise 4.4-3 suppose, like there, that the random
variables Fv are independent of each other, and their distribution does not depend
on the Boolean input vector. Take the Boolean circuit Cab(N , R) introduced in
Definition 4.22, and define the random Boolean vector T = (T1 , . . . , Tk ) where Ti = 1
if and only if the ith output node is tainted. Apply Exercise 4.4-4 to show that there
is a circuit C(j) that can be attached to the output nodes to play the role of the
coda circuit in the proof of Theorem 4.17. The size of C(j) is only linear in k, not
(k + 1)7 as for the coda circuit in the proof there. But, we assumed a little more
about the fault distribution, and also the choice of the wiring j depends on the
circuit Cab(N , R).
trigger s
x t #
Q
s
Q
- XOR -
t 3 "!
y
@
R#
@
Q
s
Q
- carry t - Maj
"!
Figure 4.10 Part of a circuit which computes the sum of two binary numbers x, y. We feed the
digits of x and y beginning with the lowest-order ones, at the input nodes. The digits of the sum
come out on the output edge. A shift register holds the carry.
logic circuit
clock
Figure 4.11 A computer consists of some memory (shift registers) and a Boolean circuit oper-
ating on it. We can define the size of computation as the size of the computer times the number
of steps.
going from the inputs and the shift registers to the outputs and the shift registers
defines two Boolean vector functions : {0, 1}k {0, 1}n {0, 1}m and : {0, 1}k
{0, 1}n {0, 1}k . The operation of the clocked circuit is described by the following
equations (see Figure 4.11, which does not show any inputs and outputs).
Frequently, we have no inputs or outputs during the work of the circuit, so the
equations (4.23) can be simplified to
How to use a clocked circuit described by this equation for computation? We write
some initial values into the shift registers, and propagate the assignment using the
gates, for the given clock cycle. Now we send a clock pulse to the register, causing
it to write new values to their output edges (which are identical to the input edges
of the circuit). After this, the new assignment is computed, and so on.
How to compute a function f (x) with the help of such a circuit? Here is a possible
convention. We enter the input x (only in the first step), and then run the circuit,
until it signals at an extra output edge when desired result f (x) can be received
from the other output nodes.
Example 4.8 This example uses a convention different from the above described one: new
input bits are supplied in every step, and the output is also delivered continuously. For the
4.5. The reliable storage problem 197
binary adder of Figure 4.10, let ut and v t be the two input bits in cycle t, let ct be the
content of the carry, and wt be the output in the same cycle. Then the equations (4.23)
now have the form
wt = ut v t ct , ct+1 = Maj(ut , v t , ct ) ,
where Maj is the majority operation.
4.5.2. Storage
A clocked circuit is an interesting parallel computer but let us pose now a task for it
that is trivial in the absence of failures: information storage. We would like to store
a certain amount of information in such a way that it can be recovered after some
time, despite failures in the circuit. For this, the transition function introduced
in (4.24) cannot be just the identity: it will have to perform some error-correcting
operations. The restoring organs discussed earlier are natural candidates. Indeed,
suppose that we use k memory cells to store a bit of information. We can call the
content of this k-tuple safe when the number of memory cells that dissent from the
correct value is under some treshold k. Let the rest of the circuit be a restoring
organ built on a (d, , , k)-compressor with = 0.9. Suppose that the input cable
is safe. Then the probability that after the transition, the new output cable (and
therefore the new state) is not safe is O(eck ) for some constant c. Suppose we keep
the circuit running for t steps. Then the probability that the state is not safe in
some of these steps is O(teck ) which is small as long as t is significantly smaller
than eck . When storing m bits of information, the probability that any of the bits
loses its safety in some step is O(mtecm ).
To make this discussion rigorous, an error model must be introduced for clocked
circuits. Since we will only consider simple transition functions like the majority
vote above, with a single computation step between times t and t + 1, we will make
the model also very simple.
Thus, Zi,t = 1 says that a failure occurs at the space-time point (i, t). The sequence
{Y t } will be called -admissible if (4.14) holds for every set C of space-time points
with t > 0.
x7 = x1 x6 .
x8 = x1 x3 x5 ,
x9 = x1 x2 x5 x6 .
y1 y7 = 0 ,
y1 y3 y5 y8 = 0 ,
y1 y2 y5 y6 y9 = 0 ,
Note h1 = h5 . The matrix H is called the error check matrix, or parity check
matrix.
Another way to write the error check relations is
y1 h1 y5 h5 y9 h9 = 0.
4.5. The reliable storage problem 199
In general, if we have s error check bits then our code can have size 2s 1, hence the
number of bits left to store information, the information bits is k = 2s s 1.
So, to protect m bits of information from a single error, the Hamming code adds
log m error check bits. This is much better than repeating every bit 3 times.
Definition 4.27 The pair of functions : {0, 1}m {0, 1}n and : {0, 1}n
{0, 1}m is called a code if ( (x)) = x holds for all x {0, 1}m . The strings
x {0, 1}m are called messages, words of the form y = (x) {0, 1}n are called
codewords. (Sometimes the set of all codewords by itself is also called a code.) For
every message x, the set of words Cx = { y : (y) = x } is called the decoding set
of x. (Of course, different decoding sets are disjoint.) The number
R = m/n
If the rate is R then the n-bit codewords carry Rn bits of useful information. In
terms of decoding sets, a code corrects t errors if each decoding set Cx contains all
words that differ from (x) in at most t symbols (the set of these words is a kind
of ball of radius t).
The Hamming code corrects a single error, and its rate is close to 1. One of the
important questions connected with error-correcting codes is how much do we have
to lower the rate in order to correct more errors.
Having a notion of codes, we can formulate the main result of this section about
information storage.
This theorem shows that it is possible to store m bits information for time t, in
a clocked circuit of size
O(max(log t, m)) .
As long as the storage time t is below the exponential bound ecm for a certain
constant c, this circuit size is only a constant times larger than the amount m of
information it stores. (In contrast, in (4.26) we needed an extra factor log m when
we used a separate restoring organ for each bit.)
The theorem says nothing about how difficult it is to compute the codeword
(x) at the beginning and how difficult it is to carry out the decoding (Y t ) at
the end. Moreover, it is desireable to perform these two operations also in a noise-
tolerant fashion. We will return to the problem of decoding later.
Linear algebra. Since we will be dealing more with bit matrices, it is convenient
to introduce the algebraic structure
F2 = ({0, 1}, +, ) ,
Ir
(x) = Gx ,
with an m n matrix G called the generator matrix of the code. The number m
is called the the number of information bits in the code, the number
k =nm
This shows that the bits y1 , . . . , y4 can be taken to be the message bits, or information
bits, of the code, making the Hamming code a linear code with the generator matrix
(I 4 , K)T . (Of course, K = K over the field F2 .)
The following statement is proved using standard linear algebra, and it gener-
alizes the relation between error check matrix and generator matrix seen in Exam-
ple 4.9.
{ Gx : x Fm n
2 } = { y F2 : Hy = 0 }. (4.28)
Definition 4.31 For a vector x, let |x| denote the number of its nonzero elements:
we will also call it the weight of x.
R = 1 k/n.
We can fix any subset S of k linearly independent columns, and call the indices i S
error check bits and the indices i 6 S the information bits. (In Example 4.9,
we chose S = {5, 6, 7}.) Important operations can performed over a code, however,
without fixing any separation into error-check bits and information bits.
4.5.4. Refreshers
Correcting a single error was not too difficult; finding a similar scheme to correct 2
errors is much harder. However, in storing n bits, typically n (much more than 2)
of those bits will be corrupted in every step. There are ingenious and quite efficient
codes of positive rate (independent of n) correcting even this many errors. When
applied to information storage, however, the error-correction mechanism itself must
also work in noise, so we are looking for a particularly simple one. It works in our
favor, however, that not all errors need to be corrected: it is sufficient to cut down
their number, similarly to the restoring organ in reliable Boolean circuits above.
For simplicity, as gates of our circuit we will allow certain Boolean functions with
a large, but constant, number of arguments. On the other hand, our Boolean circuit
will have just depth 1, similarly to a restoring organ of Section 4.4. The output of
each gate is the input of a memory cell (shift register). For simplicity, we identify
the gate and the memory cell and call it a cell. At each clock tick, a cell reads its
inputs from other cells, computes a Boolean function on them, and stores the result
(till the next clock tick). But now, instead of majority vote among the input values
cells, the Boolean function computed by each cell will be slightly more complicated.
Our particular restoring operations will be defined, with the help of a certain
k n parity check matrix H = (hij ). Let x = (x1 , . . . , xn )T be a vector of bits. For
some j = 1, . . . , n, let Vj (from vertical) be the set of those indices i with hij = 1.
For integer i = 1, . . . , k, let Hi (from horizontal) be the set of those indices j with
hij = 1. ThenP the condition Hx = 0 can also be expressed by saying that for all
i, we have jHi xj 0 (mod 2). The sets Hi are called the parity check sets
belonging to the matrix H. From now on, the indices i will be called checks, and
the indices j locations.
4.5. The reliable storage problem 203
In our constructions, we will keep the bounds K, N constant while the length n
of codewords grows. Consider a situation when x is a codeword corrupted by some
errors. To check whether bit xj is incorrect we may check all the sums
X
si = xj
jHi
for all i Vj . If all these sums are 0 then we would not suspect xj to be in error. If
only one of these is nonzero, we will know that x has some errors but we may still
think that the error is not in bit xj . But if a significant number of these sums is
nonzero then we may suspect that xj is a culprit and may want to change it. This
idea suggests the following definition.
Definition 4.33 For a low-density parity-check code H with bounds K, N , the re-
freshing operation associated with the code is the following, to be performed si-
multaneously for all locations j:
Find out whether more than bK/2c of the sums si are nonzero among
the ones for i Vj . If this is the case, flip xj .
Let xH denote the vector obtained from x by this operation. For parameters 0 <
, < 1, let us call H a (, , K, N, k, n)-refresher if for each vector x of length n
with weight |x| n the weight of the resulting vector decreases thus: |xH | n.
Theorem 4.35 There is a parameter > 0 and integers K > N > 0 such that
for all sufficiently large codelength n and k = N n/K there is a (, 1/2, K, N, k, n)-
refresher with at least n k = 1 N/K information bits.
In particular, we can choose N = 100, K = 120, = 1.31 104 .
204 4. Reliable Computation
n corrupted symbols
KN -input gate
clock
n + n n
Example 4.10 Let = 109 . Using the sample values in Theorem 4.35 we can take
N = 100, K = 120, so the information rate is 1 N/K = 1/6. With the corresponding
values of , and = = 1/2, we have = 6.57 105 . The probability that there are
more than n failures is bounded by
5 4
(e/)n = (104 e/6.57)6.5710 n
e6.6310 n
.
This is exponentially decreasing with n, albeit initially very slowly: it is not really small
4.5. The reliable storage problem 205
Remark 4.37 What we are bounding is only the probability of a corrupt symbol in
the particular position j. Some of the symbols will certainly be corrupt, but any one
symbol one points to will be corrupt only with probability c.
The upper bound on required in the condition of the theorem is very severe,
underscoring the theoretical character of this result.
The first members of the sequence bu are 1,2,3,4,6,8,11,15,18,24,32, and for cu they
are 1,1,1,2,2,3,4,5,6,8,11.
Lemma 4.38 Suppose that Yt (j0 ) 6= 0. Then either there is a time t0 < t at which
(1/2)n circuit elements failed, or there is a sequence of sets Bu Dtu for
0 u < v and C Etv with the following properties.
206 4. Reliable Computation
(a) For u > 0, every element of Bu shares some error-check with some element of
Bu1 . Also every element of C shares some error-check with some element of
Bv1 .
(b) We have |Etu Bu | < |Bu |/3 for u < v, on the other hand C Etv .
(c) We have B0 = {j0 }, |Bu | = bu , for all u < v, and |C| = cv .
Proof We will define the sequence Bu recursively, and will say when to stop. If
j0 Et then we set v = 0, C = {0}, and stop. Suppose that Bu is already defined.
Let us define Bu+1 (or C if v = u + 1). Let Bu+1 0
be the set of those j which
share some error-check with an element of Bu , and let Bu+1
00
= Bu+1
0
Dtu1 . The
refresher property implies that either |Bu+1 | > n or
00
00
|Bu r Etu | (1/2)|Bu+1 |.
In the former case, there must have been some time t0 < t u with |Et0 | > (1/2)n,
otherwise Dtu1 could never become larger than n. In the latter case, the property
|Etu Bu | < (1/3)|Bu | implies
00
(2/3)|Bu | < |Bu r Etu | (1/2)|Bu+1 |,
00
(4/3)bu < |Bu+1 |.
where we used (4.9). Similarly, the number of different choices for C is bounded by
KN bv1
cv with = 2.1KN .
cv
It follows that the number of choices for the whole sequence B1 , . . . , Bv1 , C is
bounded by
b1 ++bv1 +cv .
On the other hand, the probability for a fixed C to have C Ev is cv . This way,
we can bound the probability that the sequence ends exactly at v by
p0 , p1 , p2 3 , p3 2 6 , p4 2 10 , p5 3 16 .
4.5. The reliable storage problem 207
E E0
degree N degree K
Therefore
X 5
X
X 3 16
pv pv + (10 )cv (1 + + 3 ) + 2 (6 + 10 ) + ,
v=0 v=0 v=6
1 10
where we used 10 < 1 and the property cv+1 > cv for v 5. We can bound the
last expression by c with an appropriate constantb c.
We found that the event Yt (j) 6= Y0 (j) happens either if there is a time t0 < t at
which (1/2)n circuit elements failed (this has probability bound t(2e/)(1/2)n )
or an event of probability c occurs.
Definition 4.39 Here, we will distinguish the two parts of the bipartite (multi)
graphs not as inputs and outputs but as left nodes and right nodes. A bipartite
multigraph B is (N, K)-regular if the points of the left set have degree N and the
points in the right set have degree K. Consider such a graph, with the left set having
n nodes (then the right set has nN/K nodes). For a subset E of the left set of B, let
Nb(E) consist of the points connected by some edge to some element of E. We say
that the graph B expands E by a factor if we have |Nb(E)| |E|. For , > 0,
our graph B is an (N, K, , , n)-expander if B expands every subset E of size n
of the left set by a factor .
208 4. Reliable Computation
Definition 4.40 Given an (N, K)-regular bipartite multigraph B, with left set
{u1 , . . . , un } and right set {v1 , . . . , vk }, we assign to it a parity-check code H(B)
as follows: hij = 1 if vi is connected to uj , and 0 otherwise.
Now for every possible error set E, the set Nb(E) describes the set of parity
checks that the elements of E participate in. Under some conditions, the lower
bound on the size of Nb(E) guarantees that a sufficient number of errors will be
corrected.
Proof More generally, for any > 0, let B be an (N, K, , (3/4 + )N, n)-expander
with integer n. We will prove that H(B) is a ((1 + 4)/2, (1 4), K, N, k, n)-
refresher. For an n-dimensional bit vector x with A = { j : xj = 1 }, a = |A| = |x|,
assume
a n(1 + 4)/2 . (4.30)
Our goal is to show |xH | a(1 4): in other words, that in the corrected vector
the number of errors decreases at least by a factor of (1 4).
Let F be the set of bits in A that the error correction operation fails to flip,
with f = |F |, and G the set of of bits that were 0 but the operation turns them
to 1, with g = |G|. Our goal is to bound |F G| = f + g. The key observation is
that each element of G shares at least half of its neighbors with elements of A, and
similarly, each element of F shares at least half of its neighbors with other elements
of A. Therefore both F and G contribute relatively weakly to the expansion of AG.
Since this expansion is assumed strong, the size of |F G| must be limited.
Let
= |Nb(A)|/(N a) .
By expansion, 3/4 + .
First we show |A G| n. Assume namely that, on the contrary, |A G| > n,
and let G0 be a subset of G such that |A G0 | = n =: p (an integer, according to
the assumptions of the theorem). By expansion,
Each bit in G has at most N/2 neighbors that are not neighbors of A; so,
|Nb(A G0 )| N a + N (p a)/2 .
Combining these:
Each j F must share at least half of its neighbors with others in A. Therefore j
contributes at most N/2 neighbors on its own; the contribution of the other N/2
must be divided by 2, so the the total contribution of j to the neighbors of A is at
most (3/4)N :
Random expanders. Are there expanders good enough for Theorem 4.41?
The maximum expansion factor is the degree N and we require a factor of (7/8)N.
It turns out that random choice works here, too, similarly to the one used in the
construction of compressors.
The choice has to be done in a way that the result is an (N, K)-regular bipartite
multigraph of left size n. We will start with N n left nodes u1 , . . . , uN n and N n
right nodes v1 , . . . , vN n . Now we choose a random matching, that is a set of N n
edges with the property that every left node is connected by an edge to exactly
one right node. Let us call the resulting graph M . We obtain B now as follows: we
collapse each group of N left nodes into a single node: u1 , . . . , uN into one node,
uN +1 , . . . , u2N into another node, and so on. Similarly, we collapse each group of K
right nodes into a single node: v1 , . . . , vK into one node, vK+1 , . . . , v2K into another
node, and so on. The edges between any pair of nodes in B are inherited from the
ancestors of these nodes in M . This results in a graph B with n left nodes of degree
N and nN/K right nodes of degree K. The process may give multiple edges between
nodes of B, this is why B is a multigraph. Two nodes of M will be called cluster
neighbors if they are collapsed to the same node of B.
Then the above random choice gives an (N, K, , (7/8)N, n)-expander with positive
probability.
210 4. Reliable Computation
Example 4.11 If N = 48, K = 60 then the inequality in the condition of the theorem
becomes
1/6785 .
Proof Let E be a set of size n in the left set of B. We will estimate the probability
that E has too few neighbors. In the above choice of the graph B we might as well
start with assigning edges to the nodes of E, in some fixed order of the N |E| nodes
of the preimage of E in M . There are N |E| edges to assign. Let us call a node of the
right set of M occupied if it has a cluster neighbor already reached by an earlier
edge. Let Xi be a random variable that is 1 if the ith edge goes to an occupied node
and 0 otherwise. There are
N n i + 1 N n N n = N n(1 )
choices for the ith edge and at most KN |E| of these are occupied. Therefore
KN |E| K
P[ Xi = 1 | X1 , . . . , Xi1 ] = =: p .
N n(1 ) 1
Using the large deviations theorem in the generalization given in Exercise 4.1-3, we
have, for f > 0:
N
X n f N n
ep
P[ Xi f N n ] eN nD(f,p) .
i=1
f
P
Now, the number of different neighbors of E is N n i Xi , hence
f N n f N n
ep eK
P[ N (E) N n(1 f ) ] = .
f f (1 )
of sets E of size n:
e n eK f N n f N !n f N !n
f N 1 eK eK
= e f N 1 e ,
f (1 ) f (1 ) 0.99f
Proof Proof of Theorem 4.35 Theorem 4.41 shows how to get a refresher from an
expander, and Theorem 4.42 shows the existence of expanders for certain parameters.
Example 4.11 shows that the parameters can be chosen as needed for the refreshers.
Exercises
4.5-1 Prove Proposition 4.30.
4.5-2 Apply the ideas of the proof of Theorem 4.36 to the proof of Theorem 4.17,
showing that the coda circuit is not needed: each wire of the output cable carries
the correct value with high probability.
Problems
Chapter Notes
The large deviation theorem (Theorem 4.1), or theorems similar to it, are sometimes
attributed to Chernoff or Bernstein. One of its frequently used variants is given in
Exercise 4.1-2.
The problem of reliable computation with unreliable components was addressed
by John von Neumann in [187] on the model of logic circuits. A complete proof of
the result of that paper (with a different restoring organ) appeare first in the paper
[62] of R. L. Dobrushin and S. I. Ortyukov. Our presentation relied on parts of the
paper [199] of N. Pippenger.
The lower-bound result of Dobrushin and Ortyukov in the paper [61] (corrected
in [197], [205] and [85]), shows that reduncancy of log n is unavoidable for a general
reliable computation whose complexity is n. However, this lower bound only shows
the necessity of putting the input into a redundantly encoded form (otherwise critical
information may be lost in the first step). As shown in [199], for many important
function classes, linear redundancy is achievable.
It seems natural to separate the cost of the initial encoding: it might be possible
to perform the rest of the computation with much less redundancy. An important
step in this direction has been made by D. Spielman in the paper [242] in (essen-
tially) the clocked-circuit model. Spielman takes a parallel computation with time t
running on w elementary components and makes it reliable using only (log w)c times
more processors and running it (log w)c times longer. The failure probability will be
texp(w1/4 ). This is small as long as t is not much larger than exp(w1/4 ). So, the
redundancy is bounded by some power of the logarithm of the space requirement; the
time requirement does not enter explictly. In Boolean circuits no time- and space-
complexity is defined separately. The size of the circuit is analogous to the quantity
obtained in other models by taking the product of space and time complexity.
Questions more complex than Problem 4-1 have been studied in [198]. The
method of Problem 4-2, for generating random d-regular multigraphs is analyzed
for example in [26]. It is much harder to generate simple regular graphs (not multi-
graphs) uniformly. See for example [139].
The result of Exercise 4.2-4 is due to C. Shannon, see [229]. The asymptotically
best circuit size for the worst functions was found by Lupanov in [164]. Exercise 4.3-1
is based on [62], and Exercise 4.3-2 is based on [61] (and its corrections).
Problem 4-7 is based on the starting idea of the lg n depth sorting networks
in [9].
For storage in Boolean circuits we partly relied on A. V. Kuznietsovs paper [150]
(the main theorem, on the existence of refreshers is from M. Pinsker). Low density
parity check codes were introduced by R. G. Gallager in the book [79], and their
use in reliable storage was first suggested by M. G. Taylor in the paper [251]. New,
constructive versions of these codes were developed by M. Sipser and D. Spielman
in the paper [241], with superfast coding and decoding.
Expanders, invented by Pinsker in [196] have been used extensively in theoretical
computer science: see for example [182] for some more detail. This book also gives
references on the construction of graphs with large eigenvalue-gap. Exercise 4.4-4
and Problem 4-6 are based on [62].
214 4. Reliable Computation
The use of expanders in the role of refreshers was suggested by Pippenger (pri-
vate communication): our exposition follows Sipser and Spielman in [237]. Random
expanders were found for example by Pinsker. The needed expansion rate (> 3/4
times the left degree) is larger than what can be implied from the size of the eigen-
value gap. As shown in [196] (see the proof in Theorem 4.42) random expanders
have the needed expansion rate. Lately, constructive expanders with nearly maxi-
mal expansion rate were announced by Capalbo, Reingold, Vadhan and Wigderson
in [38].
Reliable computation is also possible in a model of parallel computation that
is much more regular than logic circuits: in cellular automata. We cannot present
those results here: see for example the papers [84, 86].
II. COMPUTER ALGEBRA
5. Algebra
First, in this chapter, we will discuss some of the basic concepts of algebra, such as
fields, vector spaces and polynomials (Section 5.1). Our main focus will be the study
of polynomial rings in one variable. These polynomial rings play a very important
role in constructive applications. After this, we will outline the theory of finite fields,
putting a strong emphasis on the problem of constructing them (Section 5.2) and
on the problem of factoring polynomials over such fields (Section 5.3). Then we
will study lattices and discuss the Lenstra-Lenstra-Lovsz algorithm which can be
used to find short lattice vectors (Section 5.4). We will present a polynomial time
algorithm for the factorisation of polynomials with rational coefficients; this was the
first notable application of the Lenstra-Lenstra-Lovsz algorithm (Section 5.5).
a (b + c) = a b + a c and
(b + c) a = b a + c a .
Being an Abelian group with respect to the addition means that the operation
5.1. Fields, vector spaces, and polynomials 217
a(bu) = (ab)u, 1u = u .
Here a, b are arbitrary elements of F, the elements u, v are arbitrary in V , and the
element 1 is the multiplicative identity of F.
The space of (m n)-matrices over F is an important example of vector spaces.
Their properties are studied in Chapter 31.
A vector space V over a field F is said to be finite-dimensional if there is a
collection {v1 , . . . , vn } of finitely many elements in V such that each of the elements
v V can be written as a linear combination v = a1 v1 + + an vn for some
5.1. Fields, vector spaces, and polynomials 219
Proof As
(u) (v) = (u v) and a(u) = (au),
we obtain that U is a subspace. Further, it is clear that the images of the elements
of a generating set of V1 form a generating set for U . Let us now suppose that is
one-to-one. In this case, the image of a linearly independent subset of V1 is linearly
independent in V2 . It easily follows from these observations that the image of a
basis of V1 is a basis of U , and so dimF U = dimF V1 . If we assume, in addition,
that dimF V2 = dimF V1 , then a basis of U is also a basis of V2 , as it is a linearly
independent set, and so it can be extended to a basis of V2 . Thus U = V2 and the
mapping must be a one-to-one correspondence. It is easy to see, and is left to the
reader, that 1 is a linear mapping.
The direct sum of vector spaces can be defined similarly to the direct sum of
rings. The direct sum of the vector spaces V1 and V2 is denoted by V1 V2 . The
underlying set of the direct sum is V1 V2 , and the addition and the action of the
field F are defined componentwise. It is easy to see that
Here the summation index d runs through all positive divisors of n. In order to verify
this identity, consider all the rational numbers i/n with 1 i n. The number of
these is exactly n. After simplifying these fractions, they will be of the form j/d
where d is a positive divisor of n. A fixed denominator d will occur exactly (d)
times.
Theorem 5.2 Suppose that F is a field and let G be a finite multiplicative subgroup
of F. Then there exists an element a G such that G = hai.
Proof Suppose that |G| = n. Lagranges theorem (Theorem 33.15) implies that the
order of an element b G is a divisor of n. We claim, for an arbitrary d, that there
are at most (d) elements in F with order d. The elements with order d are roots
of the polynomial xd 1. If F has an element b with order d, then, by Lemma 5.5,
xd 1 = (x b)(x b2 ) (x bd ) (the lemma will be verified later). Therefore
all the elements of F with order d are contained in the group hbi, which, in turn,
contains exactly (d) elements of order d.
If G had no element of order n, then the order of each of the elements of G
would be a proper divisor of n. In this case, however, using the identity above and
the fact that (n) > 0, we obtain
X
n = |G| (d) < n ,
d|n, d<n
which is a contradiction.
5.1.2. Polynomials
Suppose that F is a field and that a0 , . . . , an are elements of F. Recall that an
expression of the form
f = f (x) = a0 + a1 x + a2 x2 + + an xn ,
5.1. Fields, vector spaces, and polynomials 221
f = f (x) = a0 + a1 x + a2 x2 + + an xn
and
g = g(x) = b0 + b1 x + b2 x2 + + bn xn
are polynomials with degree not larger than n, then their sum is defined as the
polynomial
h = h(x) = f + g = c0 + c1 x + c2 x2 + + cn xn
whose coefficients are ci = ai + bi .
The product f g of the polynomials f and g is defined as the polynomial
f g = d0 + d1 x + d2 x2 + + d2n x2n
Division with remainder and divisibility. The ring F[x] of polynomials over
F is quite similar, in many ways, to the ring Z of integers. One of their similar
features is that the procedure of division with remainder can be performed in both
rings.
Lemma 5.3 Let f (x), g(x) F[x] be polynomials such that g(x) 6= 0. Then there
there exist polynomials q(x) and r(x) such that
and either r(x) = 0 or deg r(x) < deg g(x). Moreover, the polynomials q and r are
uniquely determined by these conditions.
Proof We verify the claim about the existence of the polynomials q and r by induc-
tion on the degree of f . If f = 0 or deg f < deg g, then the assertion clearly holds.
Let us suppose, therefore, that deg f deg g. Then subtracting a suitable multiple
q (x)g(x) of g from f , we obtain that the degree of f1 (x) = f (x) q (x)g(x) is
smaller than deg f (x). Then, by the induction hypothesis, there exist polynomials
q1 and r1 such that
f1 (x) = q1 (x)g(x) + r1 (x)
and either r1 = 0 or deg r1 < deg g. It is easy to see that, in this case, the polynomials
q(x) = q1 (x) + q (x) and r(x) = r1 (x) are as required.
222 5. Algebra
It remains to show that the polynomials q and r are unique. Let Q and R be
polynomials, possibly different from q and r, satisfying the assertions of the lemma.
That is, f (x) = Q(x)g(x) + R(x), and so (q(x) Q(x))g(x) = R(x) r(x). If the
polynomial on the left-hand side is non-zero, then its degree is at least deg g, while
the degree of the polynomial on the right-hand side is smaller than deg g. This,
however, is not possible.
is another such decomposition, then r = s, and, after possibly reordering the factors
Qi , the polynomials qi and Qi are associates, and moreover di = ei for all 1 i r.
Two polynomials are said to be relatively prime, if they have no common irre-
ducible divisors.
A scalar a F is a root of a polynomial f F[x], if f (a) = 0. Here the value
f (a) is obtained by substituting a into the place of x in f (x).
Lemma 5.5 Suppose that a F is a root of a polynomial f (x) F[x]. Then there
exists a polynomial g(x) F[x] such that f (x) = (x a)g(x). Hence the polynomial
f may have at most deg f roots.
5.1. Fields, vector spaces, and polynomials 223
Proof By Lemma 5.3, there exists g(x) F[x] and r F such that f (x) = (x
a)g(x)+r. Substituting a for x, we find that r = 0. The second assertion now follows
by induction on deg f from the fact that the roots of g are also roots of f .
The cost of the operations with polynomials. Suppose that f (x), g(x)
F[x] are polynomials of degree at most n. Then the polynomials f (x) g(x) can
obviously be computed using O(n) field operations. The product f (x)g(x) can be
obtained, using its definition, by O(n2 ) field operations. If the Fast Fourier Trans-
form can be performed over F, then the multiplication can be computed using only
O(n lg n) field operations (see Theorem 32.2). For general fields, the cost of the
fastest known multiplication algorithms for polynomials (for instance the Schn-
e
hageStrassen-method) is O(n lg n lg lg n), that is, O(n) field operations.
The division with remainder, that is, determining the polynomials q(x) and r(x)
for which f (x) = q(x)g(x) + r(x) and either r(x) = 0 or deg r(x) < deg g(x), can
be performed using O(n2 ) field operations following the straightforward method
outlined in the proof of Lemma 5.3. There is, however, an algorithm (the Sieveking
Kung algorithm) for the same problem using only O(n) e steps. The details of this
algorithm are, however, not discussed here.
Congruence, residue class ring. Let f (x) F[x] with deg f = n > 0, and let
g, h F[x]. We say that g is congruent to h modulo f , or simply g h (mod f ),
if f divides the polynomial g h. This concept of congruence is similar to the
corresponding concept introduced in the ring of integers (see 33.3.2). It is easy to
see from the definition that the relation is an equivalence relation on the set F[x].
Let [g]f (or simply [g] if f is clear from the context) denote the equivalence class
containing g. From Lemma 5.3 we obtain immediately, for each g, that there is a
unique r F[x] such that [g] = [r], and either r = 0 (if f divides g) or deg r < n. This
polynomial r is called the representative of the class [g]. The set of equivalence
classes is traditionally denoted by F[x]/(f ).
Lemma 5.6 Let f, f1 , f2 , g1 , g2 F[x] and let a F. Suppose that f1
f2 (mod f ) and g1 g2 (mod f ). Then
f1 + g1 f2 + g2 (mod f ) ,
f1 g1 f2 g2 (mod f ) ,
and
af1 af2 (mod f ) .
Proof The first congruence is valid, as
(f1 + g1 ) (f2 + g2 ) = (f1 f2 ) + (g1 g2 ) ,
and the right-hand side of this is clearly divisible by f . The second and the third
congruences follow similarly from the identities
f1 g1 f2 g2 = (f1 f2 )g1 + (g1 g2 )f2
224 5. Algebra
and
af1 af2 = a(f1 f2 ) ,
respectively.
The previous lemma makes it possible to define the sum and the product of two
congruence classes [g]f and [h]f as [g]f + [h]f := [g + h]f and [g]f [h]f := [gh]f ,
respectively. The lemma claims that the sum and the product are independent of
the choice of the congruence class representatives. The same way, we may define the
action of F on the set of congruence classes: we set a[g]f := [ag]f .
Theorem 5.7 Suppose that f (x) F[x] and that deg f = n > 0.
(i) The set of residue classes F[x]/(f ) is a commutative ring with an identity under
the operations + and defined above.
(ii) The ring F[x]/(f ) contains the field F as a subring, and it is an n-dimensional
vector space over F. Further, the residue classes [1], [x], . . . , [xn1 ] form a basis of
F[x]/(f ).
(iii) If f is an irreducible polynomial in F[x], then F[x]/(f ) is a field.
Proof (i) The fact that F[x]/(f ) is a ring follows easily from the fact that F[x] is a
ring. Let us, for instance, verify the distributive property:
[g]([h1 ]+[h2 ]) = [g][h1 +h2 ] = [g(h1 +h2 )] = [gh1 +gh2 ] = [gh1 ]+[gh2 ] = [g][h1 ]+[g][h2 ] .
The zero element of F[x]/(f ) is the class [0], the additive inverse of the class [g] is
the class [g], while the multiplicative identity element is the class [1]. The details
are left to the reader.
(ii) The set {[a] | a F} is a subring isomorphic to F. The correspondence is
obvious: a [a]. By part (i), F[x]/(f ) is an additive Abelian group, and the action
of F satisfies the vector space axioms. This follows from the fact that the polyno-
mial ring is itself a vector space over F. Let us, for example, verify the distributive
property:
a([h1 ]+[h2 ]) = a[h1 +h2 ] = [a(h1 +h2 )] = [ah1 +ah2 ] = [ah1 ]+[ah2 ] = a[h1 ]+a[h2 ] .
the classes [g][1], [g][x], . . . , [g][xn1 ] are linearly independent. Indeed, an equation
[0] = a0 [g][1]+ +an1 [g][xn1 ] implies [0] = [g][a0 + +an1 xn1 ], and, in turn, it
also yields that a0 = = an1 = 0. Therefore the classes [g][1], [g][x], . . . , [g][xn1 ]
form a basis of F[x]/(f ). Hence there exist coefficients bi F for which
Thus we find that the class [0] 6= [g] has a multiplicative inverse, and so F[x]/(f ) is
a field, as required.
We note that the converse of part (iii) of the previous theorem is also true, and
its proof is left to the reader (Exercise 5.1-1).
Example 5.2 We usually represent the elements of the residue class ring F[x]/(f ) by their
representatives, which are polynomials with degree less than deg f .
1. Suppose that F = F2 is the field of two elements, and let f (x) = x3 + x + 1. Then
the ring F[x]/(f ) has 8 elements, namely
[0], [1], [x], [x + 1], [x2 ], [x2 + 1], [x2 + x], [x2 + x + 1].
Practically speaking, the addition between the classes is the is addition of polynomials. For
instance
[x2 + 1] + [x2 + x] = [x + 1] .
When computing the product, we compute the product of the representatives, and substi-
tute it (or reduce it) with its remainder after dividing by f . For instance,
The polynomial f is irreducible over F2 , since it has degree 3, and has no roots. Hence the
residue class ring F[x]/(f ) is a field.
2. Let F = R and let f (x) = x2 1. The elements of the residue class ring are the
classes of the form [ax + b] where a, b R. The ring F[x]/(f ) is not a field, since f is not
irreducible. For instance, [x + 1][x 1] = [0].
Proof (i) For a sufficiently large n, the elements 1, , . . . , n are linearly dependent
over F. A linear dependence gives a polynomial 0 6= f F[x] such that f () = 0.
(ii) If g = g1 g2 , then, as 0 = g() = g1 ()g2 (), the element is a root of either
g1 or g2 . As g was chosen to have minimal degree, one of the polynomials g1 , g2 is a
unit, and so g is irreducible. Finally, let h F[x] such that h() = 0. Let q, r F[x]
be the polynomials as in Lemma 5.3 for which h(x) = q(x)g(x) + r(x). Substituting
for x into the last equation, we obtain r() = 0, which is only possible if r = 0.
226 5. Algebra
Definition 5.9 The polynomial g F[x] in the last lemma is said to be a minimal
polynomial of .
It follows from the previous lemma that the minimal polynomial is unique up to
a scalar multiple. It will often be helpful to assume that the leading coefficient (the
coefficient of the term with the highest degree) of the minimal polynomial g is 1.
Corollary 5.10 Let L be a field containing F, and let L. Suppose that f F[x]
is irreducible and that f () = 0. Then f is a minimal polynomial of .
Let L be a field containing F and let L. Let F() denote the smallest subfield
of L that contains F and .
Theorem 5.11 Let L be a field containing F and let L. Suppose that f F[x]
is a minimal polynomial of . Then the field F() is isomorphic to the field F[x]/(f ).
More precisely, there exists an isomorphism : F[x]/(f ) F() such that (a) = a,
for all a F, and ([x]f ) = . The map is also an isomorphism of vector spaces
over F, and so dimF F() = deg f .
Proof Let us consider the map : F[x] L, which maps a polynomial g F[x]
into g(). This is clearly a ring homomorphism, and (F[x]) F(). We claim
that (g) = (h) if and only if [g]f = [h]f . Indeed, (g) = (h) holds if and only
if (g h) = 0, that is, if g() h() = 0, which, by Lemma 5.8, is equivalent
to f | g h, and this amounts to saying that [g]f = [h]f . Suppose that is the
map F[x]/(f ) F() induced by , that is, ([g]f ) := (g). By the argument
above, the map is one-to-one. Routine computation shows that is a ring, and
also a vector space, homomorphism. As F[x]/(f ) is a field, its homomorphic image
(F[x]/(f )) is also a field. The field (F[x]/(f )) contains F and , and so necessarily
(F[x]/(f )) = F().
Euclidean algorithm and the greatest common divisor. Let f (x), g(x)
F[x] be polynomials such that g(x) 6= 0. Set f0 = f , f1 = g and define the polyno-
mials qi and fi using division with reminder as follows:
Note that if 1 < i < k then deg fi+1 is smaller than deg fi . We form this sequence
of polynomials until we obtain that fk+1 = 0. By Lemma 5.3, this defines a finite
process. Let n be the maximum of deg f and deg g. As, in each step, we decrease
the degree of the polynomials, we have k n + 1. The computation outlined above
is usually referred to as the Euclidean algorithm. A version of this algorithm for
the ring of integers is described in Section 33.2.
We say that the polynomial h(x) is the greatest common divisor of the
polynomials f (x) and g(x), if h(x) | f (x), h(x) | g(x), and, if a polynomial h1 (x) is a
divisor of f and g, then h1 (x) is a divisor of h(x). The usual notation for the greatest
common divisor of f (x) and g(x) is gcd(f (x), g(x)). It follows from Theorem 5.4 that
gcd(f (x), g(x)) exists and it is unique up to a scalar multiple.
Theorem 5.12 Suppose that f (x), g(x) F[x] are polynomials, that g(x) 6= 0,
and let n be the maximum of deg f and deg g. Assume, further, that the number k
and the polynomial fk are defined by the procedure above. Then
(i) gcd(f (x), g(x)) = fk (x).
(ii) There are polynomials F (x), G(x) with degree at most n such that
(iii) With a given input f, g, the polynomials F (x), G(x), fk (x) can be computed
using O(n3 ) field operations in F.
Proof (i) Going backwards in the Euclidean algorithm, it is easy to see that the
polynomial fk divides each of the fi , and so it divides both f and g. The same way,
if a polynomial h(x) divides f and g, then it divides fi , for all i, and, in particular,
it divides fk . Thus gcd(f (x), g(x)) = fk (x).
(ii) The claim is obvious if f = 0, and so we may assume without loss of generality
that f 6= 0. Starting at the beginning of the Euclidean sequence, it is easy to see
that there are polynomials Fi (x), Gi (x) F[x] such that
We observe that (5.2) also holds if we substitute Fi (x) by its remainder Fi (x) after
dividing by g and substitute Gi (x) by its remainder Gi (x) after dividing by f . In
order to see this, we compute
and notice that the degree of the polynomials on both sides of this congruence is
smaller than (deg f )(deg g). This gives
f (x) = a0 + a1 x + a2 x2 + + an xn F[x]
is the polynomial
f 0 (x) = a1 + 2a2 x + + nan xn1 .
It follows immediately from the definition that the map f (x) 7 f 0 (x) is an F-linear
mapping F[x] F[x]. Further, for f (x), g(x) F[x] and a F, the equations
(f (x) + g(x))0 = f 0 (x) + g 0 (x) and (af (x))0 = af 0 (x) hold. The derivative of a
product can be computed using the Leibniz rule: for all f (x), g (x) F[x] we
have (f (x)g(x))0 = f 0 (x)g(x) + f (x)g 0 (x). As the derivation is a linear map, in order
to show that the Leibniz rule is valid, it is enough to verify it for polynomials of
the form f (x) = xi and g(x) = xj . It is easy to see that, for such polynomials, the
Leibniz rule is valid.
The derivative f 0 (x) is sensitive to multiple factors in the irreducible factorisation
of f (x).
Lemma 5.13 Let F be an arbitrary field, and assume that f (x) F[x] and f (x) =
uk (x)v(x) where u(x), v(x) F[x]. Then uk1 (x) divides the derivative f 0 (x) of the
polynomial f (x).
Proof Using induction on k and the Leibniz rule, we find (uk (x))0 = kuk1 (x)u0 (x).
Thus, applying the Leibniz rule again, f 0 (x) = uk1 (x)(ku0 (x)v(x) + uk (x)v 0 (x)).
Hence uk1 (x) | f 0 (x).
Lemma 5.14 Let F be an arbitrary field, and assume that f (x) F[x] and f (x) =
u(x)v(x) where the polynomials u(x) and v(x) are relatively prime. Suppose further
that u0 (x) 6= 0 (for instance F has characteristic 0 and u(x) is non-constant). Then
the derivative f 0 (x) is not divisible by u(x).
Proof By the Leibniz rule, f 0 (x) = u(x)v 0 (x) + u0 (x)v(x) u0 (x)v(x) (mod u(x)).
Since deg u0 (x) is smaller than deg u(x), we obtain that u0 (x) is not divisible by u(x),
and neither is the product u0 (x)v(x), as u(x) and v(x) are relatively prime.
5.1. Fields, vector spaces, and polynomials 229
Exercises
5.1-1 Let f F[x] be polynomial. Show that the residue class ring F[x]/(f ) has no
zero divisors if and only if f is irreducible.
5.1-2 Let R be a commutative ring with an identity. A subset I R is said to be
an ideal, if I is an additive subgroup, and a I, b R imply ab I. Show that R
is a field if and only if its ideals are exactly {0} and R.
5.1-3 Let a1 , . . . , ak R. Let (a1 , . . . , ak ) denote the smallest ideal in R that
contains the elements ai . Show that (a1 , . . . , ak ) always exists, and it consists of the
elements of the form b1 a1 + b2 a2 + + bk ak where b1 , . . . , bk R.
5.1-4 A commutative ring R with an identity and without zero divisors is said to
be a principal ideal domain if, for each ideal I of R, there is an element a I
such that (using the notation of the previous exercise) I = (a). Show that Z and
F[x] where F is a field, are principal ideal domains.
5.1-5 Suppose that S is a commutative ring with an identity, that I an ideal in S,
and that a, b S. Define a relation on S as follows: a b (mod I) if and only if
a b I. Verify the following:
a.) The relation is an equivalence relation on S.
b.) Let [a]I denote the equivalence class containing an element a, and let S/I denote
the set of equivalence classes. Set [a]I + [b]I := [a + b]I , and [a]I [b]I := [ab]I . Show
that, with respect to these operations, S/I is a commutative ring with an identity.
Hint. Follow the argument in the proof of Theorem 5.7.
5.1-6 Let F be a field and let f (x), g(x) F[x] such that gcd(f (x), g(x)) = 1. Show
that there exists a polynomial h(x) F[x] such that h(x)g(x) 1 (mod f (x)). Hint.
Use the Euclidean algorithm.
230 5. Algebra
Proof By Theorem 5.19 and Lemma 5.5, the product on the right-hand side is a
divisor of the polynomial xq x F[x]. Now the assertion follows, as the degrees
and the leading coefficients of the two polynomials in the equation coincide.
Corollary 5.21 Arbitrary two finite fields with the same number of elements are
isomorphic.
Proof Suppose that q = pd , and that both K and L are fields with q elements.
Let be a primitive element in L. Then Corollary 5.18 implies that a minimal
polynomial g(x) Fp [x] of over Fp is irreducible (in Fp [x]) with degree d. Further,
L = Fp [x]/(g(x)). By Lemma 5.8 and Theorem 5.19, the minimal polynomial g is
a divisor of the polynomial xq x. Applying Theorem 5.20 to K, we find that the
polynomial xq x, and also its divisor g(x), can be factored as a product of linear
terms in K[x], and so g(x) has at least one root in K. As g(x) is irreducible in
Fp [x], it must be a minimal polynomial of (see Corollary 5.10), and so Fp () is
isomorphic to the field Fp [x]/(g(x)). Comparing the number of elements in Fp ()
and in K, we find that Fp () = K, and further, that K and L are isomorphic.
In the sequel, we let Fq denote the field with q elements, provided it exists. In
order to prove the existence of such a field for each prime-power q, the following two
facts will be useful.
Lemma 5.22 If p is a prime number and j is an integer such that 0 < j < p, then
p | pj .
p
p
Proof On the one hand, the number j is an integer. On the other hand, j =
p(p 1) (p j + 1)/j! is a fraction such that, for 0 < j < p, its numerator is
divisible by p, but its denominator is not.
Lemma 5.23 Let R be a commutative ring and let p be a prime such that pr = 0
for all r R. Then the map p : R R mapping r 7 rp is a ring homomorphism.
Theorem 5.24 Assume that the polynomial g(x) Fq [x] is irreducible, and, for a
d
positive integer d, it is a divisor of the polynomial xq x. Then the degree of g(x)
divides d.
N
X N
X N
X
d d d d
u(x)q = uqi xiq = ui (xq )i ui xi = u(x) (mod g(x)) .
i=0 i=0 i=0
Note that we applied Lemma 5.23 to the ring R = Fq [x]/(g(x)), and Theorem 5.19
to Fq . The residue class ring Fq [x]/(g(x)) is isomorphic to the field Fqn , which
has q n elements. Let u(x) Fq [x] be a polynomial for which u(x) (mod g(x))
n
is a primitive element in the field Fqn . That is, u(x)q 1 1 (mod g(x)), but
u(x)j 6 1 (mod g(x)) for j = 1, . . . , q n 2. Therefore,
d tn+s nt s s
u(x) u(x)q = u(x)q = (u(x)q )q u(x)q (mod g(x)) ,
s
and so u(x)(u(x)q 1 1) 0 (mod g(x)). Since the residue class ring Fq [x]/(g(x))
s
is a field, u(x) 6 0 (mod g(x)), but we must have u(x)q 1 1 (mod g(x)). As
0 q s 1 < q n 1, this contradicts to the primitivity of u(x) (mod g(x)).
Theorem 5.25 For an arbitrary prime p and positive integer d, there exists a field
with pd elements.
Proof We use induction on d. The claim clearly holds if d = 1. Now let d > 1 and let
r be a prime divisor of d. By the induction hypothesis, there is a field with q = p(d/r)
elements. By Theorem 5.24, each of the irreducible factors, in Fq [x], of the the
r r
polynomial f (x) = xq x has degree either 1 or r. Further, f 0 (x) = (xq x)0 = 1,
and so, by Lemma 5.13, f (x) is square-free. Over Fq , the number of linear factors of
f (x) is at most q, and so is the degree of their product. Hence there exist at least
(q r q)/r 1 polynomials with degree r that are irreducible in Fq [x]. Let g(x) be
such a polynomial. Then the field Fq [x]/(g(x)) is isomorphic to the field with q r = pd
elements.
A little bit later, in Theorem 5.31, we will prove a stronger statement: a random
polynomial in Fp [x] with degree d is irreducible with high probability.
Theorem 5.28 Assume that Fq F are finite fields, and let F. Let f Fq [x]
be the minimal polynomial of over Fq with leading coefficient 1, and suppose that
deg f = d. Then
d1
f (x) = (x )(x q ) (x q ) .
d1
Moreover, the elements , q , . . . , q are pairwise distinct.
Proof Let f (x) = a0 +a1 x+ +xd . If F with f () = 0, then, using Lemma 5.23
and Theorem 5.19, we obtain
This theorem shows that a polynomial f which is irreducible over a finite field
cannot have multiple roots. Further, all the roots of f can be obtained from a single
root taking q-th powers repeatedly.
where the summation runs for the distinct prime divisors r of k. Indeed, if does
not generate, over Fq , the field Fqk , then it is contained in a maximal subfield of
Fqk , and these maximal subfields are, by Theorem 5.27, exactly the fields of the form
Fqk/r . The number of distinct prime divisors of k are at most lg k, and so the number
of such elements is at least q k (lg k)q k/2 . The minimal polynomials with leading
coefficients 1 over Fq of such elements have degree k and they are irreducible.
Such a polynomial is a minimal polynomial of exactly k elements (Theorem 5.28).
Hence the number of distinct irreducible polynomials with degree k and leading
coefficient 1 in Fq [x] is at least
If, having Fq , we would like to construct one of its extensions Fqk , then it is
worth selecting a random polynomial
In certain cases, we can use the previous lemma to boost the probability of
finding an irreducible polynomial.
Claim 5.33 Let r be a prime such that r | q 1. Then, for a random element
b Fq , the polynomial xr b is irreducible in Fq [x] with probability at least 1 1/r.
Proof Under the conditions, the r-th powers in Fq constitute the cyclic subgroup
with order (q 1)/r. Thus a random element b Fq is an r-th power with probability
1/r, and hence the assertion follows from Lemma 5.32.
Remark. Assume that r | (q 1), and, if r = 2, then assume also that 4 | (q 1).
In this case there is an element b in Fq that is not an r-th power. We claim that
that the residue class [x] is not an r-th power in Fq [x]/(xr b)
= Frq . Indeed, by the
argument in the proof of Lemma 5.32, it suffices to show that r2 - (q r 1)/(q 1).
By our assumptions, this is clear if r = 2. Now assume that r > 2, and write
q 1 + rt (mod r2 ). Then, for all integers i 0, we have q i 1 + irt (mod r2 ),
and so, by the assumptions,
qr 1 r(r 1)
= 1 + q + + q r1 r + rt r (mod r2 ) .
q1 2
Exercises
5.2-1 Show that the polynomial xq+1 1 can be factored as a product of linear
factors over the field Fq2 .
5.2-2 Show that the polynomial f (x) = x4 + x + 1 is irreducible over F2 , that is,
F2 [x]/(f )
= F16 . What is the order of the element [x]f in the residue class ring? Is
it true that the element [x]f is primitive in F16 ?
5.2-3 Determine the irreducible factors of x31 1 over the field F2 .
5.2-4 Determine the subfields of F36 .
5.2-5 Let a and b be positive integers. Show that there exists a finite field K con-
taining Fq such that Fqa K and Fqb K. What can we say about the number of
elements in K?
5.2-6 Show that the number of irreducible polynomials with degree k and leading
coefficient 1 over Fq is at most q k /k.
5.2-7 (a) Let F be a field, let V be an n-dimensional vector space over F, and let
A : V V be a linear transformation whose minimal polynomial coincides with
its characteristic polynomial. Show that there exists a vector v V such that the
images v, Av, . . . , An1 v are linearly independent.
d1
(b) A set S = {, q , . . . , q } is said to be a normal basis of Fqd over Fq , if
Fqd and S is a linearly independent set over Fq . Show that Fqd has a normal basis
over Fq . Hint. Show that a minimal polynomial of the Fq -linear map : Fqd Fqd
is xd 1, and use part (a).
5.3. Factoring polynomials over finite fields 237
None of the factors x2 x + 10, x2 + 5x + 1, x2 7x + 7 has a root in F23 , and so they are
necessarily irreducible in F23 [x].
Lemma 5.34 Let f (x) Fq [x] be a polynomial. If f 0 (x) = 0, then there exists a
polynomial g(x) Fq [x] such that f (x) = g(x)p .
Pn Pn
Proof Suppose that f (x) = i=0 ai xi . Then f 0 (x) = i=1 ai ixi1 . If the coefficient
ai i is zero in Fq then either ai = 0 or p | i. Hence, if f 0 (x) = 0 then f (x) can be
238 5. Algebra
Pk d1
written as f (x) = j=0 bj x .
pj
Let q = pd ; then choosing cj = bjp , we have
d Pk
cpj = bpj = bj , and so f (x) = ( j=0 cj xj )p .
Square-Free-Factorisation(f )
1 gf
2 S
3 m1
4 i1
5 while deg g 6= 0
6 do if g 0 = 0
7 then g p g
8 iip
9 else h g/gcd(g, g 0 )
10 g g/h
11 if deg h 6= 0
12 then S S (h, m)
13 mm+i
14 return S
The degree of the polynomial g decreases after each execution of the main loop,
and the subroutines used in this algorithm run in polynomial time. Thus the method
5.3. Factoring polynomials over finite fields 239
The theorem offers an efficient method for computing the polynomials hi (x).
First we separate h1 from f , and then, step by step, we separate the product of the
factors with higher degrees.
Distinct-Degree-Factorisation(f )
1 F f
2 for i 1 to deg f
i
3 do hi gcd(F, xq x)
4 F F/hi
5 return h1 , . . . , hdeg f
If, in this algorithm, the polynomial F (x) is constant, then we may stop, as the
i
further steps will not give new factors. As the polynomial xq x may have large
i
degree, computing gcd(F (x), xq x) must be performed with particular care. The
i
important idea here is that the residue xq (mod F (x)) can be computed using fast
exponentiation.
The algorithm outlined above is suitable for testing whether a polynomial is
irreducible, which is one of the important problems that we encounter when con-
structing finite fields. The algorithm presented here for distinct degree factorisation
can solve this problem efficiently. For, it is obvious that a polynomial f with degree
k is irreducible, if, in the factorisation (5.4), we have hk (x) = f (x).
240 5. Algebra
Irreducibility-Test(f )
1 n deg f
n
2 if xp 6 x (mod f )
3 then return "no"
4 for the prime divisors r of n
n/r
5 do if xp x (mod f )
6 then return "no"
7 return "yes"
In lines 2 and 5, we check whether n is the smallest among the positive integers k
k
for which f divides xq x. By Theorem 5.35, this is equivalent to the irreducibility
of f . If f survives the test in line 2, then, by Theorem 5.35, we know that f is
square-free and k must divide n. Using at most lg n + 1 fast exponentiations modulo
f , we can thus decide if f is irreducible.
Theorem 5.36 If the field Fq is given and k > 1 is an integer, then the field
Fqk can be constructed using a randomised Las Vegas algorithm which runs in time
polynomial in lg q and k.
Proof The algorithm is the following.
Finite-Field-Construction(q k )
1 for i 0 to k 1
2 do ai a random element (uniformly distributed) of Fq
Pk1
3 f xk + i=0 ai xi
4 if Irreducibility-Test(f ) = "yes"
5 then return Fq [x]/(f )
6 else return "fail"
special case is that a square-free distinct degree factorisation reduces the general fac-
torisation problem to such a simpler problem. If q is even, then Berlekamps method,
presented in Subsection 5.3.4, gives a deterministic polynomial time solution. There
is a variation of the method discussed in the present section that works also for even
q; see Problem 5-2
Lemma 5.37 Suppose that q is odd. Then there are (q 2 1)/2 pairs (c1 , c2 )
(q1)/2 (q1)/2
Fq Fq such that exactly one of c1 and c2 is equal to 1.
Proof Suppose that a is a primitive element in Fq ; that is, aq1 = 1, but ak 6= 1 for
2
0 < k < q 1. Then Fq \ {0} = {as |s = 0, . . . , q 2}, and further, as a(q1)/2 = 1,
but a(q1)/2 6= 1, we obtain that a(q1)/2 = 1. Therefore as(q1)/2 = (1)s , and
so half of the element c Fq \ {0} give c(q1)/2 = 1, while the other half give
c(q1)/2 = 1. If c = 0 then clearly c(q1)/2 = 0. Thus there are ((q 1)/2)((q +1)/2)
(q1)/2 (q1)/2
pairs (c1 , c2 ) such that c1 = 1, but c2 6= 1, and, obviously, we have the
same number of pairs for which the converse is valid. Thus the number of pairs that
satisfy the condition is (q 1)(q + 1)/2 = (q 2 1)/2.
Theorem 5.38 Suppose that q is odd and the polynomial f (x) Fq [x] is of
the form (5.5) and has degree n. Choose a uniformly distributed random poly-
nomial u(x) Fq [x] with degree less than n. (That is, choose pairwise inde-
pendent, Puniformly distributed scalars u0 , . . . , un1 , and consider the polynomial
n1
u(x) = i=0 ui x .) Then, with probability at least (q
i 2d
1)/(2q 2d ) 4/9, the
greatest common divisor
q d 1
gcd(u(x) 2 1, f (x))
is a proper divisor of f (x).
Proof The element u(x) (mod fi (x)) corresponds to an element of the residue
class field F[x]/(fi (x))
= Fqd . By the Chinese remainder theorem (Theorem 5.15),
choosing the polynomial u(x) uniformly implies that the residues of u(x) modulo
the factors fi (x) are independent and uniformly distributed random polynomials.
By Lemma 5.37, the probability that exactly one of the residues of the polynomial
d
u(x)(q 1)/2 1 modulo f1 (x) and f2 (x) is zero is precisely (q 2d 1)/(2q 2d ). In this
case the greatest common divisor in the theorem is indeed a divisor of f . For, if
d
u(x)(q 1)/2
1 0 (mod f1 (x)), but this congruence is not valid modulo f2 (x),
d
then the polynomial u(x)(q 1)/2 1 is divisible by the factor f1 (x), but not divisible
by f2 (x), and so its greatest common divisor with f (x) is a proper divisor of f (x).
The function
q 2d 1 1 1
= 2d
2q 2d 2 2q
is strictly increasing in q d , and it takes its smallest possible value if q d is the smallest
odd prime-power, namely 3. The minimum is, thus, 1/2 1/18 = 4/9.
242 5. Algebra
The previous theorem suggests the following randomised Las Vegas polynomial
time algorithm for factoring a polynomial of the form (5.5) to a product of two
factors.
Cantor-Zassenhaus-Odd(f, d)
1 n deg f
2 for i 0 to n 1
3 do ui a random element (uniformly distributed) of Fq
Pn1
4 u i=0 ui xi
d
5 g gcd(u(q 1)/2 1, f )
6 if 0 < deg g < deg f
7 then return(g, f /g)
8 else return "fail"
It is easy to see that Af Bf . The term subalgebra is used here, because both
types of Berlekamp subalgebras are subrings in the residue class ring Fq [x]/(f (x))
(that is they are closed under addition and multiplication modulo f (x)), and, in
addition, Bf is also linear subspace over Fq , that is, it is closed under multiplication
by the elements of Fq . The absolute Berlekamp subalgebra Af is only closed under
multiplication by the elements of the prime field Fp .
The Berlekamp subalgebra Bf is a subspace, as the map u 7 uq u (mod f (x))
is an Fq -linear map of Fq [x]/g(x) into itself, by Lemma 5.23 and Theorem 5.19.
Hence a basis of Bf can be computed as a solution of a homogeneous system of
linear equations over Fq , as follows.
For all i {0, . . . , n1}, compute the polynomial hi (x) with degree at most n1
that satisfies xiq xi hi (x) (mod f (x)). For each i, such a polynomial hi can be
determined by fast exponentiation usingPO(lg q) multiplications of polynomials and
n
divisions with remainder. Set hi (x) = j=0 hij xj . The class [u]f of a polynomial
Pn1
u(x) = i=0 ui xi with degree less than n lies in the Berlekamp subalgebra if and
only if
n1
X
ui hi (x) = 0 ,
i=0
where uij Fp . Let, for all i {0, . . . , n 1} and for all j {0, . . . , d 1}, hij (x)
Fq [x] be the unique polynomial with degree at most (n 1) for which hij (x)
244 5. Algebra
Pn1 Pd1
(y j xi )p y j xi (mod f (x)). The polynomial hij (x) is of the form k=0 l=0 hkl
ij y x .
l k
The criterion for being a member of the absolute Berlekamp subalgebra of [u] with
Pn1 Pd1
u[x] = i=0 j=0 uij y j xi is
n1
XX d1
uij hij (x) = 0 ,
i=0 j=0
This is indeed a homogeneous system of linear equations in the variables uij . Systems
of linear equations over fields can be solved in polynomial time (see Section 31.4),
the operations in the ring Fq [x]/(f (x)) can be performed in polynomial time, and
the fast exponentiation also runs in polynomial time. Thus the following theorem is
valid.
Theorem 5.39 Let f Fq [x]. Then it is possible to compute the Berlekamp subal-
gebras Bf Fq [x]/(f (x)) and Af Fq [x]/(f (x)), in the sense that an Fq -basis of Bf
and Fp -basis of Af can be obtained, using polynomial time deterministic algorithms.
and
The following theorem shows that the elements of the Berlekamp subalgebra can
be characterised by their Chinese remainders.
Theorem 5.40
and
Proof Using the Chinese remainder theorem, and equations (5.8), (5.9), we are only
required to prove that
and
Hence, if uq (x) u(x) (mod g e (x)), then u(x) is of the form u(x) = c + h(x)g(x)
where h(x) Fq [x]. Let N be an arbitrary positive integer. Then
N N N N N
u(x) uq (x) uq (x) (c + h(x)g(x))q c + h(x)q g(x)q c (mod g q (x)) .
Proof Let i and j be integers such that ci 6= cj Fq , u(x) ci (mod fiei (x)),
e
and u(x) cj (mod fj j (x)). Then, choosing c = ci , the polynomial u(x) c is
e
divisible by fiei (x), but not divisible by fj j (x). If, in addition, u(x) Af , then also
c = ci Fp .
Assume that we have a basis of Af at hand. At most one of the basis elements
can be trivial, as a trivial element is a scalar multiple of 1. If f (x) is not a power of an
irreducible polynomial, then there will surely be a non-trivial basis element [u(x)]f ,
and so, using the idea in the previous lemma, f (x) can be factored two factors.
Proof It suffices to show that f can be factored to two factors within the given time
bound. The method can then be repeated.
Berlekamp-Deterministic(f )
1 S a basis of Af
2 if |S| > 1
3 then u a non-trivial element of S
4 for c Fp
5 do g gcd(u c, f )
6 if 0 < deg g < deg f
7 then return (g, f /g)
8 else return "a power of an irreducible"
The time bound in the previous theorem is not polynomial in the input size, as
it contains p instead of lg p. However, if p is small compared to the other parameters
(for instance in coding theory we often have p = 2), then the running time of the
algorithm will be polynomial in the input size.
Corollary 5.43 Suppose that p can be bounded by a polynomial function of deg f
and lg q. Then the irreducible factorisation of f can be obtained in polynomial time.
The previous two results are due to E. R. Berlekamp. The most important open
problem in the area discussed here is the existence of a deterministic polynomial
time method for factoring polynomials. The question is mostly of theoretical interest,
since the randomised polynomial time methods, such as the a Cantor -Zassenhaus
algorithm, are very efficient in practice.
Fq . Then there are at least (q 1)/2 elements b Fq such that exactly one of the
elements (a1 + b)(q1)/2 and (a2 + b)(q1)/2 is 1.
Proof Using the argument at the beginning of the proof of Lemma 5.37, one can
easily see that there are (q 1)/2 elements in the set Fq \ {1} whose (q 1)/2-th
power is 1. It is also quite easy to check, for a given element c Fq \ {1}, that
there is a unique b 6= a2 such that c = (a1 + b)/(a2 + b). Indeed, the required b is
the solution of a linear equation.
By the above, there are (q 1)/2 elements b Fq \ {a2 } such that
(q1)/2
a1 + b
= 1 .
a2 + b
For such a b, one of the elements (a1 + b)(q1)/2 and (a2 + b)(q1)/2 is equal to 1 and
the other is equal to 1.
Theorem 5.45 Suppose that q is odd and the polynomial f (x) Fq [x] has at least
two irreducible factors in Fq [x]. Let u(x) be a non-trivial element in the Berlekamp
subalgebra Bf . If we choose a uniformly distributed random element b Fq , then,
with probability at least (q 1)/(2q) 1/3, the greatest common divisor gcd((u(x) +
b)(q1)/2 1, f (x)) is a proper divisor of the polynomial f (x).
Qs
Proof Let f (x) = i=1 fiei (x), where the factors fi (x) are pairwise distinct irre-
ducible polynomials. The element [u(x)]f is a non-trivial element of the Berlekamp
subalgebra, and so there are indices 0 < i, j s and elements ci 6= cj Fq such
e
that u(x) ci (mod fiei (x)) and u(x) cj (mod fj j (x)). Using Lemma 5.44 with
a1 = ci and a2 = cj , we find, for a random element b Fq , that the probability that
exactly one of the elements (ci + b)(q1)/2 1 and (cj + b)(q1)/2 1 is zero is at least
(q 1)/(2q). If, for instance, (ci + b)(q1)/2 1 = 0, but (cj + b)(q1)/2 1 6= 0, then
e
(u(x) + b)(q1)/2 1 0 (mod fiei (x)) but (u(x) + b)(q1)/2 1 6= 0 (mod fj j (x)),
that is, the polynomial (u(x) + b)(q1)/2 1 is divisible by fiei (x), but not divisible
e
by fj j (x). Thus the greatest common divisor gcd(f (x), (u(x) + b)(q1)/2 1) is a
proper divisor of f .
The quantity (q 1)/(2q) = 1/2 1/(2q) is a strictly increasing function in q,
and so it takes its smallest value for the smallest odd prime-power, namely 3. The
minimum is 1/3.
The previous theorem gives the following algorithm for factoring a polynomial
to two factors.
248 5. Algebra
Berlekamp-Randomised(f )
1 S a basis of Bf
2 if |S| > 1
3 then u a non-trivial elements of S
4 c a random element (uniformly distributed) of Fq
5 g gcd((u c)(q1)/2 1, f )
6 if 0 < deg g < deg f
7 then return (g, f /g)
8 else return "fail"
9 else return "a power of an irreducible"
Exercises
5.3-1 Let f (x) Fp [x] be an irreducible polynomial, and let be an element of the
field Fp [x]/(f (x)). Give a polynomial time algorithm for computing 1 . Hint. Use
the result of Exercise 5.1-6
5.3-2 Let f (x) = x7 + x6 + x5 + x4 + x3 + x2 + x + 1 F2 [x]. Using the Distinct-
Degree-Factorisation algorithm, determine the factorisation (5.4) of f .
5.3-3 Follow the steps of the Cantor-Zassenhaus algorithm to factor the polynomial
x2 + 2x + 9 F11 [x].
5.3-4 Let f (x) = x2 3x + 2 F5 [x]. Show that F5 [x]/(f (x)) coincides with the
absolute Berlekamp subalgebra of f , that is, Af = F5 [x]/(f (x)).
5.3-5 Let f (x) = x3 x2 +x1 F7 [x]. Using Berlekamps algorithm, determine the
irreducible factors of f : first find a non-trivial element in the Berlekamp subalgebra
Af , then use it to factor f .
5.4.1. Lattices
First, we recall a couple of concepts related to real vector spaces. Let Rn denote
the collection of real vectors of length n. It is routine to check that Rn is a vector
space over the field R. The scalar product of two vectors u = (u1 , . . . , un ) and
v = (v1 , . . . , vn ) in R
p is defined as the number (u, v) = u1 v1 + u2 v2 + + un vn .
n
The quantity |u| = (u, u) is called the length of the vector u. The vectors u and
v are said to be orthogonal if (u, v) = 0. A basis b1 , . . . , bn of the space Rn is said
to be orthonormal, if, for all i, (bi , bi ) = 1 and, for all i and j such that i 6= j, we
have (bi , bj ) = 0.
The rank and the determinant of a real matrix, and definite matrices are dis-
cussed in Section 31.1.
Definition 5.46 A set L Rn is said to be a lattice, if L is a subgroup with
respect to addition, and L is discrete, in the sense that each bounded region of Rn
contains only finitely many points of L. The rank of the lattice L is the dimension
of the subspace generated by L. Clearly, the rank of L coincides with the cardinality
of a maximal linearly independent subset of L. If L has rank n, then L is said to be
a full lattice. The elements of L are called lattice vectors or lattice points.
In this case, as the vectors b1 , . . . , br are linearly independent, all vectors of Rn can
uniquely be written as real linear combinations of b1 , . . . , br .
By the following theorem, the lattices are precisely those additive subgroups of
Rn that have bases.
Proof Obviously, L is a subgroup, that is, it is closed under addition and subtraction.
In order to show that it is discrete, let us assume that n = r. This assumption means
no loss of generality, as the subspace spanned by b1 , . . . , br is isomorphic to Rr . In
this case, : (1 , . . . , n ) 7 1 b1 + . . . + n bn is an invertible linear map of Rn onto
itself. Consequently, both and 1 are continuous. Hence the image of a discrete
set under is also discrete. As L = (Zn ), it suffices to show that Zn is discrete in
Rn . This, however, is obvious: if K is a bounded region in Rn , then there is a positive
integer , such that the absolute value of each of the coordinates of the elements of
K is at most . Thus Zn has at most (2bc + 1)n elements in K.
The second assertion is proved by induction on n. If L = {0}, then we have
nothing to prove. Otherwise, by discreteness, there is a shortest non-zero vector, b1
say, in L. We claim that the vectors of L that lie on the line {b1 | R} are
exactly the integer multiples of b1 . Indeed, suppose that is a real number and
consider the vector b1 L. As usual, {} denotes the fractional part of . Then
250 5. Algebra
0 6= |{}b1 | < |b1 |, yet {}b1 = b1 []b1 , that is {}b1 is the difference of two
vectors of L, and so is itself in L. This, however, contradicts to the fact that b1 was
a shortest non-zero vector in L. Thus our claim holds.
The claim verified in the previous paragraph shows that the theorem is valid
when n = 1. Let us, hence, assume that n > 1. We may write an element of Rn as
the sum of two vectors, one of them is parallel to b1 and the other one is orthogonal
to b1 :
(v, b1 )
v = v + b1 .
(b1 , b1 )
Simple computation shows that (v , b1 ) = 0, and the map v 7 v is linear. Let
L = {v |v L}. We show that L is a lattice in the subspace, or hyperplane,
H = Rn1 formed by the vectors orthogonal to b1 . The map v 7 v is linear, and
so L is closed under addition and subtraction. In order to show that it is discrete,
let K be a bounded region in H. We are required to show that only finitely many
points of L are in K. Let v L be a vector such that v K. Let be the integer
that is closest to the number (v, b1 )/(b1 , b1 ) and let v 0 = v b1 . Clearly, v 0 L and
v 0 = v . Further, we also have that |(v 0 , b1 )/(b1 , b1 )| = |(v b1 , b1 )/(b1 , b1 )| 1/2,
and so the vector v 0 lies in the bounded region K {b1 : 1/2 1/2}.
However, there are only finitely many vectors v 0 L in this latter region, and so K
also has only finitely many lattice vectors v = v 0 L .
We have, thus, shown that L is a lattice in H, and, by the induction hypothesis,
it has a basis. Let b2 , . . . , br L be lattice vectors such that the vectors b2 , . . . , br
form a basis of the lattice L . P Then, for an arbitrary lattice vector v L, the vector
r
v can be P written in the form i=2 i bi where the coefficients i are integers. Then
r
v = v i=2 i bi L and, as the map v 7 v is linear, we have v 0 = 0. This,
0
Proof Straightforward.
5.4. Lattice reduction 251
we have W = ABAT , and so det W = det B(det A)2 . The number det W/ det B =
(det A)2 is a non-negative integer, since the entries of A are integers. Swapping the
two bases, the same argument shows that det B/ det W is also a non-negative integer.
This can only happen if det B = det W .
Kx = (1/2)K (x + P ) = (1/2)K {x + z : z P } .
(1/2)K P = {u v : u (1/2) K, v P } .
Proof
Let K be the following centrally symmetric cube with side length s =
2 n det L:
We remark that, for n > 1, we can find an even shorter lattice vector, if we
replace the cube in the proof of the previous assertion by a suitable ball.
5.4. Lattice reduction 253
Gauss(b1 , b2 )
1 (a, b) (b1 , b2 )
2 forever
3 do b the shortest lattice vector on the line b a
4 if |b| < |a|
5 then b a
6 else return (a, b)
Lemma 5.55 Suppose that a and b are two linearly independent vectors in the
plane R2 , and let L be the lattice generated by them. The vector b is a shortest
non-zero vector of L on the line b a if and only if
This quantity takes its smallest value for the integer that is the closest to the
number (b, a)/(a, a). Hence = 0 gives the minimal value if and only if (5.10) holds.
Lemma 5.56 Suppose that the linearly independent vectors a and b form a basis
for a lattice L R2 and that inequality (5.10) holds. Assume, further, that
Write b, as in (5.11), as the sum of the vector ((b, a)/(a, a))a, which is parallel to a,
and the vector b = b ((b, a)/(a, a))a, which is orthogonal to a. Then
|b |2 (1/2)|a|2 . (5.13)
4 2 4 4 2 4
|a|2 |b| = |b |2 + ((b, a)/(a, a)) |a|2 |b |2 + (1/3)|a|2 .
3 3 3 3
which implies |v| > |a| whenever || 2. If = 0 and 6= 0, then |v| = |||a| |a|.
Similarly, = 0 and 6= 0 gives |v| = || |b| |b|. It remains to consider the case
when 6= 0 and = 1. As | v| = |v|, we may assume that = 1. In this case,
however, v is of the form v = b a ( = ), and, by Lemma 5.55, the vector b is
a shortest lattice vector on this line.
Theorem 5.57 Let v be a shortest non-zero lattice vector in L. Then Gauss algo-
rithm terminates after O(1 + lg(|b1 |/|v|)) iterations, and the resulting vector a is a
shortest non-zero vector in L.
Proof First we verify that, during the course of the algorithm, the vectors a and b
will always form a basis for the lattice L. If, in line 3, we replace b by a vector of
the form b0 = b a, then, as b = b0 + a, the pair a, b0 remains a basis of L. The
swap in line 5 only concerns the order of the basis vectors. Thus a and b is always a
basis of L, as we claimed.
By Lemma 5.55, inequality (5.10) holds after the first step (line 3) in the loop,
and so we may apply Lemma 5.56 to the scenario before lines 45. This shows that
if none of a and b is shortest, then |b|2 (3/4)|a|2 . Thus, except perhaps for the last
execution of the loop,
p after each swap in line 5, the length of a is decreased by a
factor of at least 3/4. Thus we obtain the bound for the number of executions of
the loop. Lemma 5.56 implies also that the vector a at the end is a shortest non-zero
vector in L.
and so det L = |a||b |. The number |b | can now be bounded by the previous in-
equality.
where
(bi , bj ) = 0 for j = 1, . . . , i 1 .
Clearly b1 = b1 . The vectors b1 , . . . , bi1 span the same subspace as the vectors
b1 , . . . , bi1 , and so, with suitable coefficients ij , we may write
i1
X
bi = bi + ij bj , (5.14)
j=1
and
(bi , bj ) = 0, if j 6= i .
By the latter equations, the vectors b1 , . . . , bi1 , bi form an orthogonal system, and
so
(bi , bj )
ij = (j = 1, . . . , i 1) . (5.15)
(bj , bj )
The set of the vectors b1 , . . . , bn is said to be the Gram-Schmidt orthogonal-
isation of the vectors b1 , . . . , bn .
Lemma 5.59 Let L Rn be a lattice with basis b1 , . . . , bn . Then
n
Y
det L = |bi | .
i=1
Pn
Proof Set ii = 1 and ij = 0, if j > i. Then bi = k=1 ik bk , and so
n
X n
X
(bi , bj ) = ik (bk , bl )jl ,
k=1 l=1
that is, B = M BM T where B and B are the Gram matrices of the collections
256 5. Algebra
Qn
Corollary 5.60 (Hadamard inequality). i=1 |bi | det L.
Proof The vector bi can be written as the sum of the vector bi and a vector orthog-
onal to bi , and hence |bi | |bi |.
1
|ij | for 1j<in.
2
Lemma 5.62 The basis given by the procedure Weak-Reduction is weakly re-
duced.
Proof By the remark preceding the algorithm, we obtain that the vectors b1 , . . . , bn
never change. Indeed, we only subtract linear combinations of vectors with index less
than i from bi . Hence the inner instruction does not change the value of (bk , bl ) with
k 6= i. The values of the (bi , bl ) do not change for l > j either. On the other hand,
the instruction achieves, with the new bi , that the inequality |ij | 1/2 holds:
1
|(bi bj , bj )| = |(bi , bj ) (bj , bj )| = |(bi , bj ) (bj , bj )| (b , b ) .
2 j j
By the observations above, this inequality remains valid during the execution of the
procedure.
5.4. Lattice reduction 257
5.4.5. Lovsz-reduction
First we define, in an arbitrary dimension, a property of the bases that usually
turns out to be useful. The definition will be of a technical nature. Later we will see
that these bases are interesting, in the sense that they consist of short vectors. This
property will make them widely applicable.
Let us observe the analogy of the conditions above to the inequalities that we
have seen when investigating Gauss algorithm. For i = 1, a = b1 and b = b2 , being
weakly reduced ensures that b is a shortest vector on the line b a. The second
condition is equivalent to the inequality |b|2 (3/4)|a|2 , but here it is expressed in
terms of the Gram-Schmidt basis. For a general index i, the same is true, if a plays
the rle of the vector bi , and b plays the rle of the component of the vector bi+1
that is orthogonal to the subspace spanned by b1 , . . . , bi1 .
Lovsz-Reduction(b1 , . . . , bn )
1 forever
2 do (b1 , . . . , bn ) Weak-Reduction(b1 , . . . , bn )
3 find an index i for which the second condition of being reduced is violated
4 if there is such an i
5 then bi bi+1
6 else return (b1 , . . . , bn )
Theorem 5.64 Suppose that in the lattice L Rn each of the pairs of the lattice
vectors has an integer scalar product. Then the swap in the 5th line of the Lovsz-
Reduction occurs at most lg4/3 (B1 Bn1 ) times where Bi is the upper left (ii)-
subdeterminant of the Gram matrix of the initial basis b1 , . . . , bn .
be at most 3/4 times the old one. Then the assertion follows from the fact that the
quantity B remains a positive integer.
Corollary 5.65 Under the conditions of the previous theorem, the cost of the
procedure Lovsz-Reduction is at most O(n5 lg nC) arithmetic operations with
rational numbers where C is the maximum of 2 and the quantities |(bi , bj )| with
i, j = 1, . . . , n.
Proof It follows from the Hadamard inequality that
i q
Y
Bi (b1 , bj )2 + . . . + (bi , bj )2 ( iC)i ( nC)n .
j=1
Hence B1 Bn1 ( nC)n(n1) and lg4/3 (B1 . . . Bn1 ) = O(n2 lg nC). By the
previous theorem, this is the number of iterations in the algorithm. The cost of the
Gram-Schmidt orthogonalisation is O(n3 ) operations, and the cost of weak reduc-
tion is O(n2 ) scalar product computations, each of which can be performed using
O(n) operations (provided the vectors are represented by their coordinates in an
orthogonal basis).
One can show that the length of the integers that occur during the run of the
algorithm (including the numerators and the denominators of the fractions in the
Gram-Schmidt orthogonalisation) will be below a polynomial bound.
Theorem 5.67 Assume that the vectors b1 , . . . , bn form a reduced basis of a lattice
L. Then
(i) |b1 | 2(n1)/4 (det L)(1/n) .
(ii) |b1 | 2(n1)/2 |b| for all lattice vectors 0 6= b L. In particular, the length of b1
is not greater than 2(n1)/2 times the length of a shortest non-zero lattice vector.
(iii) |b1 | |bn | 2(n(n1))/4 det L.
i
!2
X (bi , bj )
(bi , bi ) = (bj , bj )
j=1
(bj , bj )
i1 i1
1X 1 X ij
(bi , bi ) + (bj , bj ) (bi , bi ) + 2 (bi , bi )
4 j=1 4 j=1
Exercises
5.4-1 The triangular lattice is optimal. Show that the bound in Corollary 5.58 is
sharp. More precisely, let L R2 be a full latticeand let 0 6= a L be a shortest
vector in L. Verify that the inequality |a|2 = (2/ 3) det L holds if and only if L is
similar to the triangular lattice.
5.4-2 The denominators of the Gram-Schmidt numbers. Let us assume that the
Gram matrix of a basis b1 , . . . , bn has only integer entries. Show that the numbers
Qj1
ij in (5.15) can be written in the form ij = ij / k=1 Bk where the ij are integers
and Bk is the determinant of the Gram matrix of the vectors b1 , . . . , bk .
5.4-3 The length of the vectors in a reduced basis. Let b1 , . . . , bn be a reduced basis
of a lattice L and let us assume that the numbers (bi , bi ) are integers. Give an upper
bound depending only on n and det L for the length of the vectors bi . More precisely,
prove that
n(n1)
|bi | 2 4 det L .
It follows from the assumption that each of the components of v (in the orthogonal
basis) is at most as long as b1 = b1 :
n
X |b1 |
zj +
ij i
z
.
i=j+1 |bj |
5.5.1. Preparations
First we reduce the problem (5.18) to another problem that can be handled more
easily.
Lemma 5.68 We may assume that the polynomial f (x) has integer coefficients
and it has leading coefficient 1.
Proof Multiplying by the common denominator of the coefficients, we may assume
that f (x) = a0 + a1 x + + an xn Z[x]. Performing the substitution y = an x, we
obtain the polynomial
n1
X
n1 y
g(y) = an f = yn + ani1
n ai y i ,
an i=0
which has integer coefficients and its leading coefficient is 1. Using a factorisation of
g(y), a factorisation of f (x) can be obtained efficiently.
Lemma 5.70 (Gauss Lemma). If u(x), v(x) Z[x] are primitive polynomials,
then so is the product u(x)v(x).
Proof We argue by contradiction and Passume that p is aPprime number that divides
n m
all the coefficients of uv. Set u(x) = i=0 ui xi , v(x) = j=0 vj xj and let i0 and j0
be the smallest indices such that p - ui0 and p - vj0 . Let k0 = i0 + j0 and consider
the coefficient of xk0 in the product u(x)v(x). This coefficient is
X 0 1
iX 0 1
jX
ui vj = ui0 vj0 + ui vk0 i + uk0 j vj .
i+j=k0 i=0 j=0
Both of the sums on the right-hand side of this equation are divisible by p, while
ui0 vj0 is not, and hence the coefficient of xk0 in u(x)v(x) cannot be divisible by p
after all. This, however, is a contradiction.
Claim 5.71 Let us assume that g(x), h(x) Q[x] are polynomials with ratio-
nal coefficients and leading coefficient 1 such that the product g(x)h(x) has integer
coefficients. Then the polynomials g(x) and h(x) have integer coefficients.
262 5. Algebra
Proof Let us multiply g(x) and h(x) by the least common multiple cg and ch ,
respectively, of the denominators of their coefficients. Then the polynomials cg g(x)
and ch h(x) are primitive polynomials with integer coefficients. Hence, by Gauss
Lemma, so is the product cg ch g(x)h(x) = (cg g(x))(ch h(x)). As the coefficients of
g(x)h(x) are integers, each of its coefficients is divisible by the integer cg ch . Hence
cg ch = 1, and so cg = ch = 1. Therefore g(x) and h(x) are indeed polynomials with
integer coefficients.
One can show similarly, for a polynomial f (x) Z[x], that factoring f (x) in Z[x]
is equivalent to factoring the primitive part of f (x) in Q[x] and factoring an integer,
namely the greatest common divisor of the coefficients
The inequality maxni=0 |ai | kf (x)k implies that a polynomial f (x) with integer
coefficients can be described using O(n lg kf (x)k) bits.
Lemma 5.73 Let f (x) C[x] be a polynomial with complex coefficients. Then,
for all c C, we have
n+1
X
(x c)f (x) = (ai1 cai )xi ,
i=0
and hence
n+1
X n+1
X
k(x c)f (x)k2 = |ai1 cai |2 = (|ai1 |2 + |cai |2 ai1 cai ai1 cai )
i=0 i=0
n+1
X
= kf (x)k2 + |c|2 kf (x)k2 (ai1 cai + ai1 cai ) .
i=0
Performing similar computations with the right-hand side of the equation in the
lemma, we obtain that
n+1
X
(cx 1)f (x) = (cai1 ai )xi ,
i=0
5.5. Factoring polynomials in Q[x] 263
and so
n+1
X n+1
X
k(cx 1)f (x)k2 = |cai1 ai |2 = (|cai1 |2 + |ai |2 cai1 ai cai1 ai )
i=0 i=0
n+1
X
= kf (x)k2 + |c|2 kf (x)k2 (ai1 cai + ai1 cai ) .
i=0
Theorem 5.74 (Mignotte). Let us assume that the polynomials f (x), g(x) C[x]
have complex coefficients and leading coefficient 1 and that g(x)|f (x). If deg(g(x)) =
m, then kg(x)k 2m kf (x)k.
Qn
Proof By the fundamental theorem of algebra, f (x) = i=1 (x i ) where
1 , . . . , n are the complex roots of the polynomial
Q f (x) (with multiplicity). Then
there is a subset I {1, . . . , n} such that g(x) = iI (x i ). First we claim, for
an arbitrary set J {1, . . . , n}, that
Y
|i | kf (x)k . (5.19)
iJ
If J contains an integer i with i = 0, then this inequality will trivially hold. Let
Q hence assume that i 6= 0 for every i J. Set J = {1, . . . , n} \ J and h(x) =
us
iJ (x i ). Applying Lemma 5.73 several times, we obtain that
Y Y Y
kf (x)k = k (x i )h(x)k = k (i x 1)h(x)k = | i | ku(x)k ,
iJ iJ iJ
Q
where u(x) = iJ (x1/i )h(x). As the leading coefficient of u(x) is 1, ku(x)k 1,
and so
Y Y
| i | = | i | = kf (x)k/ku(x)k kf (x)k .
iJ iJ
Corollary 5.75 The bit size of the irreducible factors in Q[x] of an f (x) Z[x]
with leading coefficient 1 is polynomial in the bit size of f (x).
The matrix above is usually referred to as the Sylvester matrix. The blank spaces
in the Sylvester matrix represent zero entries.
The resultant provides information about the common factors of f and g. One
can use it to express, particularly elegantly, the fact that two polynomials are rela-
tively prime:
gcd(f (x), g(x)) = 1 Res(f, g) 6= 0 . (5.21)
Proof The entries of the Sylvester matrix corresponding to f (x) and f 0 (x) are
integers, and so is its determinant. The polynomial f has no multiple roots over
5.5. Factoring polynomials in Q[x] 265
Q, and so, by Exercise 5.5-1, gcd(f (x), f 0 (x)) = 1, which gives, using (5.21), that
Res(f (x), f 0 (x)) 6= 0. Let F (x) denote the polynomial f reduced modulo p. Then
it follows from our assumptions that Res(F (x), F 0 (x)) is precisely the residue of
Res(f (x), f 0 (x)) modulo p. By Exercise 5.5-1, the polynomial F (x) is square-free
precisely when gcd(F (x), F 0 (x)) = 1, which is equivalent to Res(F (x), F 0 (x)) 6= 0.
This amounts to saying that p does not divide the integer Res(f (x), f 0 (x)).
Corollary 5.77 If f (x) Z[x] is a square-free polynomial with degree n, then there
is a prime p = O((n lg n + 2n lg kf k)2 ) (that is, the absolute value of p is polynomial
in the bit size of f ) such that the polynomial f (x) (mod p) is square-free in Fp [x].
Proof By the Prime Number Theorem (Theorem 33.37), for large enough K, the
product of the primes in the interval [1, K] is at least 2(0.9K/ ln K) .
2
Set K = ((n + 1) lg n + 2n lg kf k) . If K is large enough, then
p1 pl 2(0.9K/ ln K) > 2 K
nn+1 kf k2n nn+1 kf k2n1 |an | (5.22)
where p1 , . . . , pl are primes not larger than K, and an is the leading coefficient of f .
Let us suppose, for the primes p1 , . . . , pl , that f (x) (mod pi ) is not square-free
in Fpi [x]. Then the product p1 pl divides Res(f (x), f 0 (x)) nan , and so
(In the last two inequalities, we used the Hadamard inequality, and the fact that
kf 0 (x)k nkf (x)k.) This contradicts to inequality (5.22), which must be valid be-
cause of the choice of K.
We note that using the Prime Number Theorem more carefully, one can obtain
a stronger bound for p.
Hensel lifting. We present a general procedure that can be used to obtain, given
a factorisation modulo a prime p, a factorisation modulo pN of a polynomial with
integer coefficients.
Theorem 5.78 (Hensels lemma). Suppose that f (x), g(x), h(x) Z[x] are poly-
nomials with leading coefficient 1 such that f (x) g(x)h(x) (mod p), and, in ad-
dition, g(x) (mod p) and h(x) (mod p) are relatively prime in Fp [x]. Then, for an
arbitrary positive integer t, there are polynomials gt (x), ht (x) Z[x] such that
both of the leading coefficients of gt (x) and ht (x) are equal to 1,
gt (x) g(x) (mod p) and ht (x) h(x) (mod p),
f (x) gt (x)ht (x) (mod pt ).
Moreover, the polynomials gt (x) and ht (x) satisfying the conditions above are unique
modulo pt .
Proof From the conditions concerning the leading coefficients, we obtain that
deg f (x) = deg g(x) + deg h(x), and, further, that deg gt (x) = deg g(x) and
266 5. Algebra
deg ht (x) = deg h(x), provided the suitable polynomials gt (x) and ht (x) indeed
exist. The existence is proved by induction on t. In the initial step, t = 1 and the
choice g1 (x) = g(x) and h1 (x) = h(x) is as required.
The induction step t t+1: let us assume that there exist polynomials gt (x) and
ht (x) that are well-defined modulo pt and satisfy the conditions. If the polynomials
gt+1 (x) and ht+1 (x) exist, then they must satisfy the conditions imposed on gt (x)
and ht (x). As gt (x) and ht (x) are unique modulo pt , we may write gt+1 (x) = gt (x) +
pt g (x) and ht+1 (x) = ht (x) + pt h (x) where g (x) and h (x) are polynomials with
integer coefficients. The condition concerning the leading coefficients guarantees that
deg g (x) < deg g(x) and that deg h (x) < deg h(x).
By the induction hypothesis, f (x) = gt (x)ht (x) + pt (x) where (x) Z[x]. The
observations about the degrees of the polynomials gt (x) and ht (x) imply that the
degree of (x) is smaller than deg f (x). Now we may compute that
As 2t > t + 1, the congruence above holds modulo pt+1 . Thus gt+1 (x) and ht+1 (x)
satisfy the conditions if and only if
This, however, amounts to saying, after cancelling pt from both sides, that
Using the congruences gt (x) g(x) (mod p) and ht (x) h(x) (mod p) we obtain
that this is equivalent to the congruence
Considering the inequalities deg g (x) < deg gt (x) and deg h (x) < deg ht (x) and
the fact that in Fp [x] the polynomials g(x) (mod p) and h(x) (mod p) are relatively
prime, we find that equation (5.23) can be solved uniquely in Fp [x]. For, if u(x) and
v(x) form a solution to u(x)g(x) + v(x)h(x) 1 (mod p), then, by Theorem 5.12,
the polynomials
and
form a solution of (5.23). The uniqueness of the solution follows from the bounds
on the degrees, and from the fact that g(x) (mod p) and h(x) (mod p) relatively
prime. The details of this are left to the reader.
5.5. Factoring polynomials in Q[x] 267
Corollary 5.79 Assume that p, and the polynomials f (x), g(x), h(x) Z[x] sat-
isfy the conditions of Hensels lemma. Set deg f = n and let N be a positive integer.
Then the polynomials gN (x) and hN (x) can be obtained using O(N n2 ) arithmetic
operations modulo pN .
Hensel-Lifting(f, g, h, p, N )
1 (u(x), v(x)) is a solution, in Fp [x], of u(x)g(x) + v(x)h(x) 1 (mod p)
2 (G(x), H(x)) (g(x), h(x))
3 for t 1 to N 1
4 do (x) (f (x) G(x) H(x))/pt
5 g (x) v(x)(x) reduced modulo g(x) (in Fp [x])
6 h (x) u(x)(x) reduced modulo h(x) (in Fp [x])
7 (G(x), H(x)) (G(x) + pt g (x), H(x) + pt h (x)) (in (Z/(pt+1 ))[x])
8 return (G(x), H(x))
we want to factor is square-free, its coefficients are integers, and its leading coefficient
is 1.
The fundamental idea of the Berlekamp-Zassenhaus algorithm is that we com-
pute the irreducible factors of f (x) modulo pN where p is a suitably chosen prime
268 5. Algebra
and N is large enough. If, for instance, pN > 2 2n1 kf k, and we have already com-
puted the coefficients of a factor modulo pN , then, by Mignottes theorem, we can
obtain the coefficients of a factor in Q[x].
From now on, we will also assume that p is a prime such that the polynomial
f (x) (mod p) is square-free in Fp [x]. Using linear search such a prime p can be found
in polynomial time (Corollary 5.77). One can even assume that p is polynomial in
the bit size of f (x).
The irreducible factors in Fp [x] of the polynomial f (x) (mod p) can be found
using Berlekamps deterministic method (Theorem 5.42). Let g1 (x), . . . , gr (x) Z[x]
be polynomials, all with leading coefficient 1, such that the gi (x) (mod p) are the
irreducible factors of the polynomial f (x) (mod p) in Fp [x].
Using the technique of Hensels lemma (Theorem 5.78) and Corollary 5.79, the
system g1 (x), . . . , gr (x) can be lifted modulo pN . To simplify the notation, we assume
now that g1 (x), . . . , gr (x) Z[x] are polynomials with leading coefficients 1 such that
and the gi (x) (mod p) are the irreducible factors of the polynomial f (x) (mod p) in
Fp [x].
Let h(x) Z[x] be an irreducible factor with leading coefficient 1 of the poly-
nomial f (x) in Q[x]. Then there is a uniquely determined set I {1, . . . , r} for
which
Y
h(x) gi (x) (mod pN ) .
iI
Let N be the smallestQ integer such that pN 22n1 kf (x)k. Mignottes bound shows
that the polynomial iI gi (x) (mod pN ) on the right-hand side, if its coefficients
are represented by the residues with the smallest absolute values, coincides with h.
We found that determining the irreducible factors of f (x) is equivalent to finding
minimal subsets I {1, . . . , r} for which
Q there is a polynomial h(x) Z[x] with
leading coefficient 1 such that h(x) iI gi (x) (mod pN ), the absolute values of
the coefficients of h(x) are at most 2n1 kf (x)k, and, moreover, h(x) divides f (x).
This can be checked by examining at most 2r1 sets I. The cost of examining a
single I is polynomial in the size of f .
To summarise, we obtained the following method to factor, in Q[x], a square-free
polynomial f (x) with integer coefficients and leading coefficient 1.
Berlekamp-Zassenhaus(f )
1 p a prime p such that f (x) (mod p) is square-free in Fp [x]
and p = O((n lg n + 2n lg kf k)2 )
2 {g1 , . . . , gr } the irreducible factors of f (x) (mod p) in Fp [x]
(using Berlekamps deterministic method)
3 N blogp (2deg f kf k)c + 1
5.5. Factoring polynomials in Q[x] 269
Pn1
Theorem 5.80 Let f (x) = xn + i=0 ai xi Z[x] be a square-free polynomial with
integer coefficients and leading coefficient 1, and let p be a prime number such that
the polynomial f (x) (mod p) is square-free in Fp [x] and p = O((n lg n + 2n lg kf k)2 ).
Then the irreducible factors of the polynomial f in Q[x] can be obtained by the
Berlekamp-Zassenhaus algorithm. The cost of this algorithm is polynomial in n,
lg kf (x)k and 2r where r is the number of irreducible factors of the polynomial
f (x) (mod p) in Fp [x].
where 2, 3, . . . , pl are the first l prime numbers, and the product is taken over all possible
2l combinations of the signs + and . The degree of f (x) is n = 2l , and one can show that
it is irreducible in Q[x]. On the other hand, for all primes p, the polynomial f (x) (mod p)
is the product of factors with degree at most 2. Therefore these polynomials represent hard
cases for the Berlekamp-Zassenhaus algorithm, as we need to examine about 2n/21 sets I
to find out that f is irreducible.
Suppose that u(x) = 0 +1 x+. . .+m1 xm1 and v(x) = 0 +1 x+. . .+n1 xn1 .
(We know that d = 1. If i > d, then i = 0, and similarly, if j > deg u(x), then
j = 0.) Rewriting the congruence, we obtain
X X
xd g(x) + j xj g(x) i xi f (x) 0 (mod pN ) .
j6=d i
Considering the coefficient vectors of the polynomials xj g(x) and xi f (x), this con-
gruence amounts to saying that adding to the (m + d)-th row of the Sylvester matrix
(5.20) a suitable linear combination of the other rows results in a row in which all the
elements are divisible by pN . Consequently, det M 0 (mod pN ). The Hadamard
inequality (Corollary 5.60) yields that | det M | kf km kgkn < pN , but this can
only happen if det M = 0. However, det M = Res(f (x), g(x)), and so, by (5.21),
gcd(f (x), g(x)) 6= 1.
Further, we let g0 (x) Z[x] be a polynomial with leading coefficient 1 such that
g0 (x) (mod pN ) is an irreducible factor of f (x) (mod pN ). Set d = deg g0 (x) < n.
Define the set L as follows:
Theorem 5.82 Let g1 (x) Z[x] be a polynomial with degree less than n such that
the coefficient vector of g1 (x) is the first element in a Lovsz-reduced basis of L.
Then f (x) is irreducible in Q[x] if and only if gcd(f (x), g1 (x)) = 1.
Proof As g1 (x) 6= 0, it is clear that gcd(f (x), g1 (x)) = 1 whenever f (x) is irre-
ducible. In order to show the implication in the other direction, let us assume that
f (x) is reducible and let g(x) be a proper divisor of f (x) such that g(x) (mod p)
is divisible by g0 (x) (mod p) in Fp [x]. Using Hensels lemma (Theorem 5.78), we
conclude that g(x) (mod pN ) is divisible by g0 (x) (mod pN ), that is, g(x) L.
Mignottes theorem (Theorem 5.74) shows that
Now, if we use the properties of reduced bases (second assertion of Theorem 5.67),
then we obtain
and so
2
kg1 (x)kn kf (x)kdeg g1 kg1 (x)kn kf (x)kn < 22n kf (x)k2n pN .
We can hence apply Lemma 5.81, which gives gcd(g1 (x), f (x)) 6= 1.
Based on the previous theorem, the LLL algorithm can be outlined as follows
(we only give a version for factoring to two factors). The input is a square-free
polynomial f (x) Z[x] with integer coefficients and leading coefficient 1 such that
deg f = n > 1.
LLL-Polynomial-Factorisation(f )
1 p a prime p such that f (x) (mod p) is square-free in Fp [x]
and p = O((n lg n + 2n lg kf k)2 )
2 w(x) an irreducible factor f (x) (mod p) in Fp [x]
(using Berlekamps deterministic method)
3 if deg w = n
4 then return "irreducible"
2
5 else N dlogp ((22n kf (x)k2n )e = O(n2 + n lg(kf (x)k)
6 (g0 , h0 ) Hensel-Lifting(f, w, f /w (mod p), p, N )
7 (b1 , . . . , bn ) a basis of the lattice L Rn in (5.24)
8 (g1 , . . . , gn ) Lovsz-Reduction(b1 , . . . , bn )
9 f gcd(f, g1 )
10 if deg f > 0
11 then return (f , f /f )
12 else return "irreducible"
Theorem 5.83 Using the LLL algorithm, the irreducible factors in Q[x] of a poly-
nomial f Q[x] can be obtained deterministically in polynomial time.
Proof The general factorisation problem, using the method introduced at the dis-
cussion of the Berlekamp-Zassenhaus procedure, can be reduced to the case in which
the polynomial f (x) Z[x] is square-free and has leading coefficient 1. By the obser-
vations made there, the steps in lines 17 can be performed in polynomial time. In
line 8, the Lovsz reduction can be carried out efficiently (Corollary 5.65). In line 9,
we may use a modular version of the Euclidean algorithm to avoid intermediate
expression swell (see Chapter 6).
The correctness of the method is asserted by Theorem 5.82. The LLL algorithm
can be applied repeatedly to factor the polynomials in the output, in case they are
not already irreducible.
272 5. Algebra
One can show that the Hensel lifting costs O(N n2 ) = O(n4 + n3 lg kf k) op-
erations with moderately sized integers. The total cost of the version of the LLL
algorithm above is O(n5 lg(pN )) = O(n7 + n6 lg kf k).
Exercises
5.5-1 Let F be a field and let 0 6= f (x) F[x]. The polynomial f (x) has no
irreducible factors with multiplicity greater than one if and only if gcd(f (x), f 0 (x)) =
1. Hint. In one direction, one can use Lemma 5.13, and use Lemma 5.14 in the other.
5.5-2 Show that the polynomials
form a basis of the lattice in (5.24). Hint. It suffices to show that the polynomials
pN xj (d j < n) can be expressed with the given polynomials. To show this, divide
pN xj by g0 (x) and compute the remainder.
Problems
a. Show that the map tr is Fq -linear and its image is precisely Fq . Hint. Use the
fact that tr is defined using a polynomial with degree q k1 to show that tr is
not identically zero.
b. Let (, ) be a uniformly distributed random pair of elements from Fqk Fqk .
Then the probability that tr() 6= tr() is 1 1/q.
5-2 The Cantor-Zassenhaus algorithm for fields of characteristic 2
Let F = F2m and let f (x) F[x] be a polynomial of the form
f = f1 f2 fs , (5.25)
where the fi are pairwise relatively prime and irreducible polynomials with degree
d in F[x]. Also assume that s 2.
a. Let u(x) F[x] be a uniformly distributed random polynomial with degree less
than deg f . Then the greatest common divisor
md1
gcd(u(x) + u2 (x) + + u2 (x), f (x))
b. Using part (a), give a randomised polynomial time method for factoring a poly-
nomial of the form (5.25) over F.
5-3 Divisors and zero divisors
Let F be a field. The ring R is said to be an F-algebra (in case F is clear from
the context, R is simply called an algebra), if R is a vector space over F, and
(ar)s = a(rs) = r(as) holds for all r, s S and a F. It is easy to see that the rings
F[x] and F[x]/(f ) are F-algebras.
Let R be a finite-dimensional F-algebra. For an arbitrary r R, we may consider
the map Lr : R R defined as Lr (s) = rs for s R. The map Lr is F-linear, and
so we may speak about its minimal polynomial mr (x) F[x], its characteristic
polynomial kr (x) F[x], and its trace T r(r) = T r(Lr ). In fact, if U is an ideal in
R, then U is an invariant subspace of Lr , and so we can restrict Lr to U , and we
may consider the minimal polynomial, the characteristic polynomial, and the trace
of the restriction.
a. Let f (x), g(x) F[x] with deg f > 0. Show that the residue class [g(x)]
is a zero divisor in the ring F[x]/(f ) if and only if f does not divide g and
gcd(f (x), g(x)) 6= 1.
b. Let R be an algebra over F, and let r R be an element with minimal polynomial
f (x). Show that if f is not irreducible over F, then R contains a zero divisor.
To be precise, if f (x) = g(x)h(x) is a non-trivial factorisation (g, h F[x]), then
g(r) and h(r) form a pair of zero divisors, that is, both of them are non-zero,
but their product is zero.
5-4 Factoring polynomials over algebraic number fields
a. Let F be a field with characteristic zero and let R be a finite-dimensional F-
algebra with an identity element. Let us assume that R = S1 S2 where S1
and S2 are non-zero F-algebras. Let r1 , . . . , rk be a basis of R over F. Show that
there is a j such that mrj (x) is not irreducible in F[x].
Hint. This exercise is for readers who are familiar with the elements of linear
algebra. Let us assume that the minimal polynomial of rj is the irreducible poly-
nomial m(x) = xd a1 xd1 + + ad . Let ki (x) be the characteristic polynomial
of Lrj on the invariant subspace Ui (for i {1, 2}). Here U1 and U2 are the sets
of elements of the form (s1 , 0) and (0, s2 ), respectively where si Si . Because of
our conditions, we can find suitable exponents di such that ki (x) = m(x)di . This
implies that the trace Ti (rj ) of the map Lrj on the subspace Ui is Ti (rj ) = di a1 .
Set ei = dimF Ui . Obviously, ei = di d, which gives T1 (rj )/e1 = T2 (rj )/e2 . If the
assertion of the exercise is false, then the latter equation holds for all j, and so,
as the trace is linear, it holds for all r R. This, however, leads to a contradic-
tion: if r = (1, 0) S1 S2 (1 denotes the unity in S1 ), then clearly T1 (r) = e1
and T2 (r) = 0.
274 5. Algebra
b. Let F be an algebraic number field, that is, a field of the form Q() where
C, and there is an irreducible polynomial g(x) Z[x] such that g() = 0. Let
f (x) F[x] be a square-free polynomial and set R = F[x]/(f ). Show that R is
a finite-dimensional algebra over Q. More precisely, if deg g = m and deg f = n,
then the elements of the form i [x]j (0 i < m, 0 j < n) form a basis over
Q.
c. Show that if f is reducible over F, then there are Q-algebras S1 , S2 such that
R= S1 S2 .
Hint. Use the Chinese remainder theorem .
d. Consider the polynomial g above and suppose that a field F and a polynomial
f F[x] are given. Assume, further, that f is square-free and is not irreducible
over F. The polynomial f can be factored to the product of two non-constant
polynomials in polynomial time.
Hint. By the previous remarks, the minimal polynomial m(y) over Q of at least
one of the elements i [x]j (0 i m, 0 j n) is not irreducible in Q[y]. Using
the LLL algorithm, m(y) can be factored efficiently in Q[y]. From a factorisation
of m(y), a zero divisor of R can be obtained, and this can be used to find a
proper divisor of f in F[x].
Chapter Notes
The abstract algebraic concepts discussed in this chapter can be found in many
textbooks; see, for instance, Hungerfords book [114].
The theory of finite fields and the related algorithms are the theme of the excel-
lent books by Lidl and Niederreiter [157] and Shparlinski [232].
Our main algorithmic topics, namely the factorisation of polynomials and lattice
reduction are thoroughly treated in the book by von zur Gathen and Gerhard [81].
We recommend the same book to the readers who are interested in the efficient meth-
ods to solve the basic problems concerning polynomials. Theorem 8.23 of that book
estimates the cost of multiplying polynomials by the Schnhage-Strassen method,
while Corollary 11.6 is concerned with the cost of the asymptotically fast implemen-
tation of the Euclidean algorithm. Ajtais result about shortest lattice vectors was
published in [8].
The method by Kaltofen and Shoup is a randomised algorithm for factoring
polynomials over finite fields, and currently it has one of the best time bounds among
the known algorithms. The expected number of Fq -operations in this algorithm is
O(n1.815 lg q) where n = deg f . Further competitive methods were suggested by von
zur Gathen and Shoup, and also by Huang and Pan. The number of operations
required by the latter is O(n1.80535 lg q), if lg q < n0.00173 . Among the deterministic
methods, the one by von zur Gathen and Shoup is the current champion. Its cost is
e 2 + n3/2 s + n3/2 s1/2 p1/2 ) operations in Fq where q = ps . An important related
O(n
problem is constructing the field Fqn . The fastest randomised method is by Shoup. Its
cost is O(n2 +n lg q). For finding a square-free factorisation, Yun gave an algorithm
Notes for Chapter 5 275
e
that requires O(n) + O(n lg(q/p)) field operations in Fq .
The best methods to solve the problem of lattice reduction and that of factoring
polynomials over the rationals use modular and numerical techniques. After slightly
modifying the definition of reduced bases, an algorithm using O(n e 3.381 lg2 C) bit
operations for the former problem was presented by Storjohann. (We use the orig-
inal definition introduced in the paper by Lenstra, Lenstra and Lovsz [155].) We
also mention Schnhages method using O(n e 6 + n4 lg2 l) bit operations for factoring
polynomials with integer coefficients (l is the length of the coefficients).
Besides factoring polynomials with rational coefficients, lattice reduction can
also be used to solve lots of other problems: to break knapsack cryptosystems and
random number generators based on linear congruences, simultaneous Diophantine
approximation, to find integer linear dependencies among real numbers (this problem
plays an important rle in experiments that attempt to find mathematical identities).
These and other related problems are discussed in the book [81].
A further exciting application area is the numerical solution of Diophantine
equations. One can read about these developments in in the books by Smart [239]
and Gal [78]. The difficulty of finding a shortest lattice vector was verified in Ajtais
paper [8].
Finally we remark that the practical implementations of the polynomial meth-
ods involving lattice reduction are not competitive with the implementations of the
Berlekamp-Zassenhaus algorithm, which, in the worst case, has exponential com-
plexity. Nevertheless, the basis reduction performs very well in practice: in fact it is
usually much faster than its theoretically proven speed. For some of the problems in
the application areas listed above, we do not have another useful method.
The work of the authors was supported in part by grants NK72845 and T77476
of the Hungarian Scientific Research Fund.
6. Computer Algebra
dynamic (i.e. chosen approximately for the particular integer being represented)
or static (i.e. pre-specified fixed length), depending on whether the linear list
is implemented using linked list allocation or using array (sequential) notation.
The sign of n is stored within the list, possibly as the sign of d0 or one or more
of the other entries.
Modular notation, in which n is represented by its value modulo a sufficient
number of large (but representable in one computer word) primes. From the
images one can reconstruct n using the Chinese remainder algorithm.
The modular form is fast for addition, subtraction and multiplication but is
much slower for divisibility tasks. Hence, the choice of representation influences
the algorithms that will be chosen. Indeed, not only the choice of representation
influences the algorithms to be used but also the algorithms influence the choice of
representation.
Example 6.1 For the sake of simplicity, in the next example we work only with natural
numbers. Suppose that we have a computer architecture with machine word 32 bits in
length, i.e. our computer is able to perform integer arithmetic with the integers in range
I1 = [0, 232 1] = [0, 4 294 967 295]. Using this arithmetic, we carry out a new arithmetic
by which we are able to perform integer arithmetic with the integers in range I2 = [0, 1050 ].
Using radix representation let B = 104 , and let
n1 = 123456789098765432101234567890 ,
n2 = 2110 .
Then,
n1 = [7890, 3456, 1012, 5432, 9876, 7890, 3456, 12] ,
n2 = [2110] ,
n1 + n2 = [0, 3457, 1012, 5432, 9876, 7890, 3456, 12] ,
n1 n2 = [7900, 3824, 6049, 1733, 9506, 9983, 3824, 6049, 2] ,
where the sum and the product were computed using radix notation.
Switching to modular representation we have to choose pairwise relatively prime inte-
gers from the interval I1 such that their product is greater than 1050 . Let, for example, the
primes be
m1 = 4294967291, m2 = 4294967279, m3 = 4294967231 ,
m4 = 4294967197, m5 = 4294967189, m6 = 4294967161 ,
Q6
where i=1
mi > 1050 . Then, an integer from the interval I2 can be represented by a
6-tuple from the interval I1 . Therefore,
n1 2009436698 (mod m1 ), n1 961831343 (mod m2 ) ,
n1 4253639097 (mod m3 ), n1 1549708 (mod m4 ) ,
n1 2459482973 (mod m5 ), n1 3373507250 (mod m6 ) ,
furthermore, n2 2110 (mod mi ), (1 i 6). Hence
n1 + n2 = [2009438808, 961833453, 4253641207, 1551818, 2459485083, 3373509360] ,
n1 n2 = [778716563, 2239578042, 2991949111, 3269883880, 1188708718, 1339711723] ,
6.1. Data representation 279
where addition and multiplication were carried out using modular arithmetic.
In order to represent objects in a computer algebra system, one has to make choices
on both the form and the data structure level. Clearly, various representations are
possible for many objects. The problem of how to represent an object becomes
even more difficult when one takes into consideration other criteria, such as memory
space, computation time, or readability. Let us see an example. For the polynomial
the product form is more comprehensive, but the second one is more suitable to
know the coefficient of, say, x5 . Two other illustrative examples are
x1000 1 and (x 1)(x999 + x998 + + x + 1) ,
(x + 1)1000 and x1000 + 1000x999 + + 1000x + 1 .
It is very hard to find any good strategy to represent mathematical objects satisfying
several criteria. In practice, one object may have several different representations.
This, however, gives rise to the problem of detecting equality when different repre-
sentations of the same object are encountered. In addition, one has to be able to
convert a given representation to others and simplify the representations.
Consider the integers. In the form level, one can represent the integers using
base B representation, while at the data structure level they can be represented by
a linked list or as an array.
Rational numbers can be represented by two integers, a numerator and a denom-
inator. Considering memory constraints, one needs to ensure that rational numbers
are in lowest terms and also that the denominator is positive (although other choices,
such as positive numerator, are also possible). This implies that a greatest common
divisor computation has to be performed. Since the ring of integers is a Euclidean
280 6. Computer Algebra
domain, this can be easily computed using the Euclidean algorithm. The uniqueness
of the representation follows from the choice of the denominators sign.
Multivariate polynomials (elements of R[x1 , x2 , . . . , xn ], where R is an integral
domain) can be represented in the form a1 xe1 +a2 xe2 + +an xen , where ai R\{0}
e e e
and for ei = (ei1 , . . . , ein ), one can write xei for x1i1 x2i2 xnin . In the form level,
one can consider the following levels of abstraction:
1. Expanded or factored representation, where the products are multiplied out or
the expression is in product form. Compare
x2 y x2 + y 1 , and
x2 + 1 (y 1) .
2. Recursive or distributive representation (only for multivariate polynomials). In
the bivariate case, the polynomial f (x, y) can be viewed as an element of the
domain R[x, y], (R[x])[y] or (R[y])[x]. Compare
x2 y 2 + x2 + xy 2 1 ,
(x2 + x)y 2 + x2 1 , and
(y 2 + 1)x2 + y 2 x 1 .
At the data structure level, there can be dense or sparse representation. Either
all terms are considered, or only those having non-zero coefficients. Compare x4 +
0x3 + 0x2 + 0x 1 and x4 1. In practice, multivariate polynomials are represented
mainly in the sparse way. P
The traditional approach of representing power series of the form i=0 ai xi is to
truncate at some specified point, and then to regard them as univariate polynomials.
However, this is not a real representation, since many power series can have the
same representation. To overcome this disadvantage, there exists a technique of
representing power series by a procedure generating all coefficients (rather than by
any finite list of coefficients). The generating function is a computable function f
such that f (i) = ai . To perform an operation with power series, it is enough to know
how to compute the coefficients of the resulting series from the coefficients of the
operands. For example, the P coefficients hi of the product of the power series f and
i
g can be computed as hi = k=0 fk gik . In that way, the coefficients are computed
when they are needed. This technique is called lazy evaluation.
Since computer algebra programs compute in a symbolic way with arbitrary
accuracy, in addition to examining time complexity of the algorithms it is also im-
portant to examine their space complexity.1 Consider the simple problem of solving
a linear system having n equations an n unknowns with integer coefficients which
require computer word of storage. Using Gaussian elimination, it is easy to see
that each coefficient of the reduced linear system may need 2n1 computer words
of storage. In other words, Gaussian elimination suffers from exponential growth
in the size of the coefficients. Note that if we applied the same method to linear
systems having polynomial coefficients, we would have exponential growth both in
1 We consider the running time as the number of operations executed, according to the RAM-
model. Considering the Turing-machine model, and using machine words with constant length, we
do not have this problem, since in this case space is always bounded by the time.
6.1. Data representation 281
the size of the numerical coefficients of the polynomials and in the degrees of the
polynomials themselves. In spite of the observed exponential growth, the final result
of the Gaussian elimination will always be of reasonable size because by Cramers
rule we know that each component of the solution to such a linear system is a ratio
of two determinants, each of which requires approximately n computer words. The
phenomenon described above is called intermediate expression swell. This often
appears in computer algebra algorithms.
Example 6.2 Using only integer arithmetic we solve the following system of linear equa-
tions:
First, we eliminate variable x from the second equation. We multiply the first row by 31,
the second by 37 and take their sum. If we apply this strategy for the third equation to
eliminate variable x, we get the following system.
Now, we eliminate variable y multiplying the second equation by 723, the third one by
1200, then taking their sum. The result is
1874311479932400x = 5622934439797200 ,
246553200y = 2712085200 ,
205461z = 1232766 .
In order to avoid the intermediate expression swell phenomenon, one uses mod-
ular techniques. Instead of performing the operations in the base structure R (e.g.
Euclidean ring), they are performed in some factor structure, and then, the result is
transformed back to R (Figure 6.1). In general, modular computations can be per-
formed efficiently, and the reconstruction steps can be made with some interpolation
strategy. Note that modular algorithms are very common in computer algebra, but
it is not a universal technique.
282 6. Computer Algebra
modular
problem in R - problem in R/hmi
reduction
direct
computations
modular
computations
? ?
solution solution in
in R reconstruction R/hmi
Classical-Euclidean(a, b)
1 c normal(a)
2 d normal(b)
3 while d 6= 0
4 do r c rem d
5 cd
6 dr
7 return normal(c)
Extended-Euclidean(a, b)
1 (r0 , u0 , v0 ) (normal(a), 1, 0)
2 (r1 , u1 , v1 ) (normal(b), 0, 1)
3 while r1 6= 0
4 do q r0 quo r1
5 r r0 qr1
6 u (u0 qu1 )
7 v (v0 qv1 )
8 (r0 , u0 , v0 ) (r1 , u1 , v1 )
9 (r1 , u1 , v1 ) (r, u, v)
10 return (normal(r0 ), u0 /(unit(a) unit(r0 )), v0 /(unit(b) unit(r0 )))
iteration r c d
18 30
1 18 30 18
2 12 18 12
3 6 12 6
4 0 6 0
Figure 6.2 Illustration of the operation of the Classical-Euclidean algorithm in Z and Q[x]. In
case (a), the input is a = 18, b = 30, a, b Z. The first two lines of the pseudocode compute
the absolute values of the input numbers. The loop between lines 3 and 6 is executed four times,
values r, c and d in these iterations are shown in the table. The Classical-Euclidean(18,30)
algorithm outputs 6 as result. In case (b), the input parameters are a = 12x4 68x3 + 52x2
92x + 56, b = 12x3 + 80x2 84x + 24 Q[x]. The first two lines compute the normal form of
the polynomials, and the while loop is executed three times. The output of the algorithm is the
polynomial normal(c) = x 2/3.
Lines 89 perform the following operations: u0 , v0 take the values of u1 and v1 , then
u1 , v1 take the values of u and v, while r0 , r1 takes the value of r1 and r. Thus,
the equalities in (6.3) are also fulfilled after the iteration of the while loop. Since
(r1 ) < (r0 ) in each iteration of the loop, the series {(ri )} obtained in lines 89
is a strictly decreasing series of natural numbers, so sooner or later the control steps
6.2. Common roots of polynomials 285
out of the while loop. The greatest common divisor is the last non-zero remainder
in the series of Euclidean divisions, that is, r0 in lines 89.
Example 6.3 Let us examine the series of remainders in the case of polynomials
19 4 59 3 5 2 8
r0 = x5 + x x + x ,
21 63 7 63
6 54 2 5 9
r1 = x4 x3 x + x ,
7 77 77 7
6185 3 1016 2 1894 943
r2 = x + x + x+ ,
4851 539 1617 441
gcd(a, b) = 1,
2580775248128 3 3823697946464 2
u = x x
467729710968369 779549518280615
27102209423483 7615669511954
x+ ,
2338648554841845 779549518280615
703847794944 4 3072083769824 3
v = x + x
155909903656123 779549518280615
25249752472633 2 301255883677 25468935587159
x x+ .
2338648554841845 779549518280615 2338648554841845
We can see that the size of the coefficients show a drastic growth. One might ask
why we do not normalise in every iteration of the while loop? This idea leads to
the normalised version of the Euclidean algorithm for polynomials.
286 6. Computer Algebra
Extended-Euclidean-Normalised(a, b)
1 e0 unit(a)
2 (r0 , u0 , v0 ) (normal(a), e1 0 , 0)
3 e1 unit(b)
4 (r1 , u1 , v1 ) (normal(b), 0, e1 1 )
5 while r1 6= 0
6 do q r0 quo r1
7 s r0 rem r1
8 e unit(s)
9 r normal(s)
10 u (u0 qu1 )/e
11 v (v0 qv1 )/e
12 (r0 , u0 , v0 ) (r1 , u1 , v1 )
13 (r1 , u1 , v1) (r, u, v)
14 return r0 , u0 , v0
Example 6.4 Let us look at the series of remainders and series e obtained in the
Extended-Euclidean-Normalised algorithm in case of the polynomials (6.4) and (6.5)
19 4 59 3 5 2 8
r0 = x5 + x x + x , e0 =63 ,
21 63 7 63
6 54 2 5 9
r1 = x4 x3 x + x , e1 = 77 ,
7 77 77 7
9144 2 5682 10373 6185
r2 = x3 + x + x+ , e2 = ,
6185 6185 6185 4851
2338183 369080899 771300096
r3 = x2 + x+ , e3 = ,
8034376 257100032 420796475
166651173 222685475860375
r4 = x+ , e4 = ,
5236962760 258204790837504
156579848512133360531
r5 = 1, e5 = .
109703115798507270400
Before the execution of line 14 of the pseudocode, the values of the variables gcd(a, b) =
r0 , u = u0 , v = v0 are
gcd(a, b) = 1,
2580775248128 3 3823697946464 2
u = x x
467729710968369 779549518280615
27102209423483 7615669511954
x+ ,
2338648554841845 779549518280615
703847794944 4 3072083769824 3
v = x + x
155909903656123 779549518280615
25249752472633 2 301255883677 25468935587159
x x+ .
2338648554841845 779549518280615 2338648554841845
Looking at the size of the coefficients in Q[x], the advantage of the normalised version
is obvious, but we could still not avoid the growth. To get a machine architecture-
dependent description and analysis of the Extended-Euclidean-Normalised al-
6.2. Common roots of polynomials 287
coefficients may only grow by a factor of around three in each Euclidean division.
This estimate seems accurate for pseudorandom polynomials, the interested reader
should look at Problem 6-1 The worst case estimate suggests that
iteration r c d
3x4 17x3 + 13x2 23x + 14 3x3 + 20x2 21x + 6
1 108x2 342x + 108 3x3 + 20x2 21x + 6 6x2 19x + 10
2 621x 414 6x2 19x + 10 3x 2
3 0 3x 2 0
Figure 6.3 The illustration of the operation of the Primitive-Euclidean algorithm with input
a(x) = 12x4 68x3 + 52x2 92x + 56, b(x) = 12x3 + 80x2 84x + 24 Z[x]. The first two lines
of the program compute the primitive parts of the polynomials. The loop between lines 3 and 6 is
executed three times, the table shows the values of r, c and d in the iterations. In line 7, variable
equals gcd(4, 4) = 4. The Primitive-Euclidean(a, b) algorithm returns 4 (3x 2) as result.
On the other hand, each polynomial f (x) R[x] can be written in a unique form
up to a unit factor, where cont(f ) R and pp(f ) R[x] are primitive polynomials.
In this case, cont(f ) is called the content, pp(f ) is called the primitive part of
f (x). The uniqueness of the form can be achieved by the normalisation of units.
For example, in the case of integers, we always choose the positive ones from the
equivalence classes of Z.
The following algorithm performs a series of pseudo-divisions. The algorithm
uses the function prem(), which computes the pseudo-remainder, and it assumes
that we can calculate greatest common divisors in R, contents and primitive parts
in R[x]. The input is a, b R[x], where R is a UFD. The output is the polynomial
gcd(a, b) R[x].
Primitive-Euclidean(a, b)
1 c pp(f )
2 d pp(g)
3 while d 6= 0
4 do r prem(c, d)
5 cd
6 d pp(r)
7 gcd(cont(a), cont(b))
8 c
9 return
The operation of the algorithm is illustrated by Figure 6.3. The running time of the
Primitive-Euclidean algorithm is the same as the running time of the previous
versions of the Euclidean algorithm.
The Primitive-Euclidean algorithm is very important because the ring
R[x1 , x2 , . . . , xt ] of multivariate polynomials is a UFD, so we apply the algorithm re-
cursively, e.g. in R[x2 , . . . , xt ][x1 ], using computations in the UFDs R[x2 , . . . , xt ], . . . ,
290 6. Computer Algebra
R[xt ]. In other words, the recursive view of multivariate polynomial rings leads to the
recursive application of the Primitive-Euclidean algorithm in a straightforward
way.
We may note that, like above, the algorithm shows a growth in the coefficients.
Let us take a detailed look at the UFD Z[x]. The bound on the size of the
coefficients of the greatest common divisor is given by the following theorem, which
we state without proof.
Pm Pn
Theorem 6.3 (Landau-Mignotte). Let a(x) = i=0 ai x , b(x) =
i i
i=0 bi x
Z[x], am 6= 0 6= bn and b(x) | a(x). Then
v
n u m
X bn u
X
|bi | 2n t a2i .
am
i=1 i=0
Corollary 6.4 With the notations of the previous theorem, the absolute value of
any coefficient of the polynomial gcd(a, b) Z[x] is smaller than
v v
um u n
1 uX 1 uX
2min{m,n}
gcd(am , bn ) min t 2
ai , t b2i .
|am | i=1 |bn | i=1
Proof The greatest common divisor of a and b obviously divides both a and b, and its
degree is at most the minimum of their degrees. Furthermore, the leading coefficient
of the greatest common divisor divides am and bn , so it also divides gcd(am , bn ).
It is obvious that res(f, g) equals to 0 if and only if i = j for some i and j, that
is, f and g have a common root. The product res(f, g) is called the resultant of the
polynomials f and g. Note that the value of the resultant depends on the order of f
and g, but the resultants obtained in the two ways can only differ in sign.
n Y
Y m
res(g, f ) = gnm fm
n
(j i )
j=1 i=1
m Y
Y n
= (1)mn fm
n m
gn (i j ) = (1)mn res(f, g) .
i=1 j=1
Evidently, this form of the resultant cannot be applied in practice, since it presumes
that the roots are known. Let us examine the different forms of the resultant. Since
hence,
g(i ) = gn (i 1 )(i 2 ) (i n )
n
Y
= gn (i j ) .
j=1
Thus,
m
Y n
Y
n
res(f, g) = fm gn (i j )
i=1 j=1
Ym n
Y
n
= fm g(i ) = (1)mn gnm f (j ) .
i=1 j=1
Although it looks a lot more friendly, this form still requires the roots of at least one
polynomial. Next we examine how the resultant may be expressed only in terms of
the coefficients of the polynomials. This leads to the Sylvester form of the resultant.
Let us presume that polynomial f in (6.1) and polynomial g in (6.2) have a
common root. This means that there exists a number K such that
f () = fm m + fm1 m1 + + f1 + f0 = 0 ,
g() = gn n + gn1 n1 + + g1 + g0 = 0 .
non-trivial solutions if and only if its determinant is zero. We get that f and g can
only have common roots if the determinant
fm f0
.. ..
. . n
fm f0
D = gn g0 (6.9)
.. ..
. . m
.. ..
. .
gn g0
equals to 0 (there are 0s everywhere outside the dotted areas). Thus, a necessary
condition for the existence of common roots is that the determinant D of order
(m + n) is 0. Below we prove that D equals to the resultant of f and g, hence, D = 0
is also a sufficient condition for common roots. The determinant (6.9) is called the
Sylvester form of the resultant.
f (x) = fm (x 1 ) (x m1 ) = fm1
xm1 + fm2 xm2 + + f1 x + f0
fm1 f0
.. ..
. .
fm1 f0 m1
Y
D = gn g0 m
= fm1 g(i ) .
.. ..
. . i=1
.. ..
. .
gn g0
Thus,
fm1 fm2 fm1 m f0 m
.. ..
. .
fm1 f0 m
D= gn g0 .
.. ..
. .
.. ..
. .
gn g0
We transform the determinant in the following way: add m times the first column to
the second column, then add m times the new second column to the third column,
etc. This way the m -s disappear from the first n lines, so the first n lines of D and
the transformed D are identical. In the last m rows, subtract m times the second
one from the first one, and similarly, always subtract m times a row from the row
right above it. In the end, D becomes
fm1 f0
.. ..
. .
fm1 f0
gn g0
D= .. .. .
. .
.. ..
. .
gn g0
gn gn m + gn1 g(m )
Using
Qmthe last row for expansion, we get D = D g(m ), which implies D =
We get that D = res(f, g), that is, polynomials f and g have a common root in
K if and only if determinant D vanishes.
>From an algorithmic point of view, the computation of the resultant in
Sylvester form for higher degree polynomials means the computation of a large
determinant. The following theorem implies that pseudo-division may simplify the
computation.
Theorem 6.6 For the polynomials f of (6.1) and g of (6.2), in case of m n > 0
res(f, g) = 0, if prem(f, g) = 0 ,
(mn)(n1)+d
gn res(f, g) = (1)mn res(g, r), if r = prem(f, g) 6= 0 and d = deg(r) .
Proof Multiply the first line of the determinant (6.9) by gnmn+1 . Let q =
294 6. Computer Algebra
0 0 rd r0
fm f0
.. ..
. .
fm f0
gn g0
gnmn+1 res(f, g) = .. ..
. . .
.. ..
. .
.. ..
. .
.. ..
. .
gn g0
Here rd is in the (m d + 1)th column of the first row, and r0 is in the (m + 1)th
column of the first row.
Similarly, multiply the second row by gnmn+1 , then multiply rows (n+2), (n+3),
. . . by qmn , qmn1 etc., and subtract them from the second row. Continue the same
6.2. Common roots of polynomials 295
rd r0
.. ..
. .
.. ..
. .
rd r0
gn g0
n(mn+1)
gn res(f, g) = ..
.
..
.
.
.. ..
. .
.. ..
. .
.. ..
. .
gn g0
Note that
gn g0
.. ..
. .
gn g0
rd r0
= res(g, r) ,
.. ..
. .
.. ..
. .
rd r0
296 6. Computer Algebra
thus,
gnn(mn+1) res(f, g) = (1)mn gnmd res(g, r) ,
and therefore
gn(mn)(n1)+d res(f, g) = (1)mn res(g, r) . (6.10)
Corollary 6.7 There exist polynomials u, v R[x] such that res(f, g) = f u + gv,
with deg u < deg g, deg v < deg f .
Proof Multiply the ith column of the determinant form of the resultant by xm+ni
and add it to the last column for i = 1, . . . , (m + n 1). Then
fm f0 xn1 f
.. .. ..
. . .
fm f
res(f, g) = .
gn g0 xm1 g
.. .. ..
. . .
gn g
Using the last column for expansion and factoring f and g, we get the statement
with the restrictions on the degrees.
The most important benefit of the resultant method, compared to the previously
discussed methods, is that the input polynomials may contain symbolic coefficients
as well.
Then the existence of common rational roots of f and g cannot be decided by variants of
the Euclidean algorithm, but we can decide it with the resultant method. Such a root exists
if and only if
2 1 3
2 1 3
2
res(f, g) = 1 5 6 = 36 429 + 1260 = 3(4 21)(3 20) = 0 ,
1 5 6
1 5 6
6.2. Common roots of polynomials 297
The significance of the resultant is not only that we can decide the existence of
common roots of polynomials, but also that using it we can reduce the solution of
algebraic equation systems to solving univariate equations.
Consider polynomials f and g as elements of (Z[x])[y]. They have a common root if and
only if
x+1 x2 + 2x 1 0
3 2
resy (f, g) = 0 x+1 x2 + 2x 1 = x 2x + 3x = 0 .
1 2 x2 + 3x 1
Common roots in Z can exist for x {3, 0, 1}. For each x, we substitute into
equations (6.11) and (6.12) (already in Z[y]) and get that the integer solutions are
(3, 1), (0, 1), (1, 1).
We note that the resultant method can also be applied to solve polynomial
equations in several variables, but it is not really effective. One problem is that
computational space explosion occurs in the computation of the determinant. Note
that computing the resultant of two univariate polynomials in determinant form
using the usual Gauss-elimination requires O((m+n)3 ) operations, while the variants
of the Euclidean algorithm are quadratic. The other problem is that computational
complexity depends strongly on the order of the indeterminates. Eliminating all
variables together in a polynomial equation system is much more effective. This
leads to the introduction of multivariate resultants.
We get that polynomials a and b are relatively prime in Zp [x]. The following theorem
describes the connection between greatest common divisors in Z[x] and Zp [x].
Theorem 6.8 Let a, b Z[x], a, b 6= 0. Let p be a prime such that p 6 | lc(a) and
p 6 | lc(b). Let furthermore c = gcd(a, b) Z[x], ap = a remp, bp = b remp and
cp = c remp. Then
(1) deg gcd(ap , bp ) deg gcd(a, b) ,
(2) if p 6 | res(a/c, b/c), then gcd(ap , bp ) = cp .
Proof (1): Since cp | ap and cp | bp , thus cp | gcd(ap , bp ). So
deg gcd(ap , bp ) deg gcd(a, b) mod p .
By the hypothesis p 6 | lc gcd(a, b) , which implies
deg gcd(a, b) mod p = deg gcd(a, b) .
Modular-Gcd-Bigprime(a, b)
1 M the Landau-Mignotte constant (from Corollary 6.4)
2 H {}
3 while true
4 do p a prime with p 2M , p 6 H, p 6 | lc(a) and p 6 | lc(b)
5 cp gcd(ap , bp )
6 if cp | a and cp | b
7 then return cp
8 else H H {p}
The first line of the algorithm requires the calculation of the Landau-Mignotte
bound. The fourth line requires a sufficiently large prime p which does not divide
the leading coefficient of a and b. The fifth line computes the greatest common divi-
sor of polynomials a and b modulo p (for example with the Classical-Euclidean
algorithm in Zp [x]). We store the coefficients of the resulting polynomials with sym-
metrical representation. The sixth line examines whether cp | a and cp | b are fulfilled,
6.2. Common roots of polynomials 299
in which case cp is the required greatest common divisor. If this is not the case, then
p is an unlucky prime, so we choose another prime. Since, by Theorem 6.8, there
are only finitely many unlucky primes, the algorithm eventually terminates. If the
primes are chosen according to a given strategy, set H is not needed.
The disadvantage of the Modular-gcd-bigprime algorithm is that the
Landau-Mignotte constant grows exponentially in terms of the degree of the in-
put polynomials, so we have to work with large primes. The question is how we
could modify the algorithm so that we can work with many small primes. Since
the greatest common divisor in Zp [x] is only unique up to a constant factor, we
have to be careful with the coefficients of the polynomials in the new algorithm. So,
before applying the Chinese remainder theorem for the coefficients of the modular
greatest common divisors taken modulo different primes, we have to normalise the
leading coefficient of gcd(ap , bp ). If am and bn are the leading coefficients of a and
b, then the leading coefficient of gcd(a, b) divides gcd(am , bn ). Therefore, we nor-
malise the leading coefficient of gcd(ap , bp ) to gcd(am , bn ) mod p in case of primitive
polynomials a and b; and finally take the primitive part of the resulting polynomial.
Just like in the Modular-gcd-bigprime algorithm, modular values are stored with
symmetrical representation. These observations lead to the following modular gcd
algorithm using small primes.
Modular-Gcd-Smallprimes(a, b)
1 d gcd( lc(a), lc(b))
2 p a prime such that p 6 | d
3 H {p}
4 P p
5 cp gcd(ap , bp )
6 gp (d mod p) cp
7 (n, i, j) (3, 1, 1)
8 while true
9 do if j = 1
10 then if deg gp = 0
11 then return 1
12 (g, j, P ) (gp , 0, p)
13 if n i
14 then g pp(g)
15 if g | a and g | b
16 then return g
17 p a prime such that p 6 | d and p 6 H
18 H H {p}
19 cp gcd(ap , bp )
20 gp (d mod p) cp
21 if deg gp < deg g
22 then (i, j) (1, 1)
300 6. Computer Algebra
23 if j = 0
24 then if deg gp = deg g
25 then g1 = Coeff-build(g, gp , P, p)
26 if g1 = g
27 then i i + 1
28 else i 1
29 P P p
30 g g1
Coeff-Build(a, b, m1 , m2 )
1 p0
2 c 1/m1 mod m2
3 for i deg a downto 0
4 do r ai mod m1
5 s (bi r) mod m2
6 p p + (r + s m1 )xi
7 return p
After the execution of the first six lines of the algorithm with p = 5, we have d = 7, cp =
x2 + 3x + 2 and gp = 2x2 + x 1. Since j = 1 due to line 7, lines 1012 are executed.
Polynomial gp is not zero, so g = 2x2 + x 1, j = 0, and P = 5 will be the values after
the execution. The condition in line 13 is not fulfilled, so we choose another prime, p = 7
is a bad choice, but p = 11 is allowed. According to lines 1920, cp = 1, gp = 4. Since
deg gp < deg g, we have j = 1 and lines 2530 are not executed. Polynomial gp is constant,
6.2. Common roots of polynomials 301
so the return value in line 11 is 1, which means that polynomials a and b are relatively
prime.
Example 6.10 In our second example, consider the already discussed polynomials
Let again p = 5. After the first six lines of the polynomials d = 12, cp = x + 1, gp = 2x + 2.
After the execution of lines 1012, we have P = 5, g = 2x + 2. Let the next prime be p = 7.
So the new values are cp = x + 4, gp = 2x 1. Since deg gp = deg g, P = 35 and the new
value of g is 12x 8 after lines 2530. The value of the variable i is still 1. Let the next
prime be 11. Then cp = gp = x + 3. Polynomials gp and g have the same degree, so we
modify the coefficients of g. Then g1 = 12x 8 and since g = g1 , we get i = 2 and P = 385.
Let the new prime be 13. Then cp = x + 8, gp = x + 5. The degrees of gp and g are still
equal, thus lines 2530 are executed and the variables become g = 12x 8, P = 4654, i = 3.
After the execution of lines 1718, it turns out that g | a and g | b, so g = 12x 8 is
the greatest common divisor.
Exercises Pm
PnLet R ibe a commutative ring with identity element, a = i=0 ai x R[x],
i
6.2-1
b = i=0 bi x R[x], furthermore, bn a unit, m n 0. The following algorithm
performs Euclidean division for a and b and outputs polynomials q, r R[x] for
which a = qb + r and deg r < n or r = 0 holds.
Euclidean-Division-Univariate-Polynomials(a, b)
1 ra
2 for i m n downto 0
3 do if deg r = n + i
4 then qi lc(r)/bn
5 r r qi xi b
6 else qi 0
Pmn
7 q i=0 qi xi and r
8 return q
operations in R.
6.2-2 What is the difference between the algorithms Extended-Euclidean and
302 6. Computer Algebra
Extended-Euclidean-Normalised in Z[x]?
6.2-3 Prove that res(f g, h) = res(f, h) res(g, h).
6.2-4 The discriminant of polynomial f (x) R[x] (deg f = m, lc(f ) = fm ) is
the element m(m1)
(1) 2
discrf = res(f, f 0 ) R ,
fm
where f 0 denotes the derivative of f with respect to x. Polynomial f has a multiple
root if and only if its discriminant is 0. Compute discrf for general polynomials of
second and third degree.
The knowledge of the variety V (I) means that we also know the common roots of
f1 , . . . , fs . The most important questions about the variety and ideal I are as follows.
V (I) 6= ?
I=R?
Fortunately, in a special basis of ideal I, in the so-called Grbner basis, these ques-
tions are easy to answer. First let us study the case n = 1. Since F [x] is a Euclidean
ring,
hf1 , . . . , fs i = h gcd(f1 , . . . , fs ) i . (6.14)
We may assume that s = 2. Let f, g F [x] and divide f by g with remainder. Then
there exist unique polynomials q, r F [x] with f = gq + r and deg r < deg g. Hence,
f hgi r = 0 .
6.3. Grbner basis 303
The elements of T are called monomials. Observe that T is closed under multi-
plication in F [x1 , . . . , xn ], constituting a commutative monoid. The map Nn T ,
(i1 , . . . , in ) 7 xi11 xinn is an isomorphism, therefore, for an allowable total order
on T , we have that
(i) 1 t for all t T ,
(ii) t1 , t2 , t T t1 t2 t1 t t2 t.
The allowable orders on T are called monomial orders. If n = 1, the natural order
is a monomial order, and the corresponding univariate monomials are ordered by
their degree. Let us see some standard examples of higher degree monomial orders.
Let
= xi11 xinn , = xj11 xjnn T ,
Example 6.11
304 6. Computer Algebra
1 z z 2 y yz yz 2
y 2 y 2 z y 2 z 2 x xz xz 2
xy xy 2 x2 .
1 zyx
z 2 yz xz y 2 xy x2
z 3 yz 2 xz 2 y 2 z xyz
x2 z y 3 xy 2 x2 y x3 .
Example 6.12 Consider the polynomial f (x, y, z) = 2xyz 2 3x3 +4y 4 5xy 2 z Q[x, y, z].
Let =plex and z y x. Then
Multivariate-Division-with-Remainder(f, f1 , . . . , fs )
1 r0
2 pf
3 for i 1 to s
4 do qi 0
5 while p 6= 0
6 do if lt(fi ) divides lt(p) for some i {1, . . . , s}
7 then choose such an i and qi qi + lt(p)/lt (fi )
8 p p lt(p)/lt(fi ) fi
9 else r r + lt(p)
10 p p lt(p)
11 return q1 , . . . , qs and r
The correctness of the algorithm follows from the fact that in every iteration of the
while cycle of lines 510, the following invariants hold
(i) mdeg(p) mdeg(f ) and f = p + q1 f1 + + qs fs + r,
(ii) qi 6= 0 mdeg(qi fi ) mdeg(f ) for all 1 i s,
(iii) no monomial in r is divisible by any lt(fi ).
The algorithm has a weakness, namely, the multivariate division with remainder is
not deterministic. In line 7, we can choose arbitrarily from the appropriate values of
i.
As we have seen in the previous example, we can make the algorithm deter-
ministic by always choosing the smallest possible i in line 7. In this case, the
quotients q1 , . . . , qs and the remainder r are unique, which we can express as
r = f rem (f1 , . . . , fs ).
Observe that if s = 1, then the algorithm gives the answer to the ideal member-
ship problem: f hf1 i if and only if the remainder is zero. Unfortunately, if s 2,
then this is not true anymore. For example, with the monomial order plex
xy 2 x rem (xy + 1, y 2 1) = x y ,
The most important consequence of the lemma is that two monomial ideals are
identical if and only if they contain the same monomials.
Lemma 6.12 (Dicksons lemma). Every monomial ideal is finitely generated,
namely, for every A Nn , there exists a finite subset B A such that hxA i = hxB i.
Together with Dicksons lemma applied to hlt(I)i, and the fact that the zero
polynomial generates the zero ideal, we obtain the following famous result.
It is easy to show that the remainder on division by the Grbner basis G does
not depend on the order of the elements of G. Therefore, we can use the notation
f rem G = r R. Using the Grbner basis, we can easily answer the ideal member-
ship problem.
Proof We prove that there exists a unique r R such that (1) f r I, (2) no term
of r is divisible by any monomial of lt(G). The existence of such an r comes from
division with remainder. For the uniqueness, let f = h1 + r1 = h2 + r2 for arbitrary
h1 , h2 I and suppose that no term of r1 or r2 is divisible by any monomial of
lt(G). Then r1 r2 = h2 h1 I, and by Lemma 6.11, lt(r1 r2 ) is divisible by
lt(g) for some g G. This means that r1 r2 = 0.
It is easy to see that S(g, h) = S(h, g), moreover, since x /lt(g), x /lt(h) R,
therefore S(g, h) hg, hi.
The following theorem yields an easy method to test whether a given set G is a
Grbner basis of the ideal hGi.
Theorem 6.18 The set G = {g1 , . . . , gs } R is the Grbner basis of the ideal
hGi if and only if
Grbner-basis(f1 , . . . , fs )
1 G {f1 , . . . , fs }
2 P {(fi , fj ) | fi , fj G, i < j, fi 6= fj }
3 while P 6=
4 do (f, g) an arbitrary pair from P
5 P P \ (f, g)
6 r S(f, g) rem G
7 if r 6= 0
8 then G G {r}
9 P P {(f, r) | f G}
10 return G
First we show the correctness of the Grbner-basis algorithm assuming that the
procedure terminates. At any stage of the algorithm, set G is a basis of ideal I, since
initially it is, and at any other step only those elements are added to G that are
remainders of the S-polynomials on division by G. If the algorithm terminates, the
remainders of all S-polynomials on division by G are zero, and by Theorem (6.18),
G is a Grbner basis.
Next we show that the algorithm terminates. Let G and G be the sets corre-
sponding to successive iterations of the while cycle (lines 3 9). Clearly, G G
and hlt(G)i hlc(G )i. Hence, ideals hlt(G)i in successive iteration steps form an
ascending chain, which stabilises by Corollary (6.15). Thus, after a finite number of
steps, we have hlt(G)i = hlc(G )i. We state that G = G in this case. Let f, g G
and r = S(f, g) rem G. Then r G and either r = 0 or lt(r) hlt(G )i = hlt(G)i,
and using the definition of the remainder, we conclude that r = 0.
Example 6.15 In Example 6.14 not only G but also G0 = {xy z, 2y z +z 2 , 1/2z 4
1/2z 2 + 1} is a Grbner basis. It is not hard to show that Gr = {x 1/2z 2 1/2z, y
1/2z 2 1/2z, z 4 + z 2 z} is a reduced Grbner basis.
f = f1 g1 + + fs gs
a + b + c = 3, a2 + b2 + c2 = 9, a3 + b3 + c3 = 24 .
G = {a + b + c 3, b2 + c2 3b 3c + bc, 1 3c2 + c3 } .
Exercises
6.3-1 Prove that the orders plex , grlex and tdeg are monomial orders.
6.3-2 Let be a monomial order on R, f, g R \ {0}. Prove the following:
a. mdeg(f g) = mdeg(f ) + mdeg(g),
b. if f + g 6= 0, then mdeg(f + g) max{mdeg(f ), mdeg(g)}, where equality
holds if mdeg(f ) 6= mdeg(g).
6.3-3 Let f = 2x4 y 2 z 3x4 yz 2 + 4xy 4 z 2 5xy 2 z 4 + 6x2 y 4 z 7x2 yz 4 Q[x, y, z].
a. Determine the order of the monomials in f for the monomial orders plex ,
grlex and tdeg with z y x in all cases.
b. For each of the three monomial orders from (a.), determine mdeg(f ), lc(f ),
6.4. Symbolic integration 311
Example 6.17 (1) With the notations of the previous definition, the mapping f 7 0 on
K is the trivial derivation, for this we have C = K.
(2) Let K = Q(x). There exists a single differential operator on Q(x) with x0 = 1, it is
the usual differentiation. For this the constants are the elements of Q. Indeed, n0 = 0 for
n N by induction, so the elements of Z and Q are also constants. We have by induction
that the derivative of power functions is the usual one, thus, by linearity, this is true for
polynomials, and by the differentiation rule of quotients, we get the statement. It is not
difficult to calculate that for the usual differentiation, the constants are the elements of Q.
(3) If K = C(x), where C is an arbitrary field of characteristic 0, then there exists
a single differential operator on K with constant subfield C and x0 = 1: it is the usual
differentiation. This statement is obtained similarly to the previous one.
or an element of
Q(i) x, log(x), log(x i), log(x + i)
as well. Obviously, it is more reasonable to choose the first possibility, because in this case
there is no need to extend the base field.
Since gcd(gm , g gm
0
) = 1, there exist polynomials s, t K[x] such that
sgm + tg gm
0
=h.
Hermite-Reduction(f, g)
1 p quo(f, g)
2 h rem(f, g)
3 (g[1], . . . , g[m]) Square-Free(g)
4 construct the partial fraction decomposition of (h/g), compute numerators
h[i, j] belonging to g[i]j
5 rac 0
6 int 0
7 for i 1 to m
8 do int int + h[i, 1]/g[i]
9 for j 2 to i
10 do n j
11 while n > 1
12 do determine s and t from the equation s g[i] + t g[i]0 = h[i, j]
13 nn1
14 rac rac (t/n)/g[i]n
15 h[i, n] s + t0 /n
16 int R int +
R h[i, 1]/g[i]
17 red rac + p + int
18 return red
R
If for some field K of characteristic 0, we want to compute the integral a/b,
where a, b K[x] are non-zero relatively prime polynomials with deg a < deg b,
b square-free Q
and monic, we can proceed by decomposing polynomial b into linear
n
factors, b = k=1 (x ak ), inPits splitting field L, then constructing the partial
n
fraction decomposition, a/b = k=1 ck /(x ak ), over L, finally integrating we get
Z n
a X
= ck log(x ak ) L x, log(x a1 ), . . . , log(x an ) .
b
k=1
The disadvantage of this method, as we have seen in the example of the function
1/(x3 + x), is that the degree of the extension field L can be too large. An extension
degree as large as n! can occur, which leads to totally unmanageable cases. On the
other hand, it is not clear either if a field extension is needed at all: for example, in
case of the function 1/(x2 2), can we not compute the integral without extending
the base field? The following theorem enables us to choose the degree of the field
extension as small as possible.
(2) The polynomial r = resx (b, a yb0 ) K[y] can be decomposed into linear factors
over L, c1 , . . . , ck are exactly the distinct roots of r, and vi = gcd(b, a ci b0 ) if
i = 1, . . . , k. Here, resx is the resultant taken in the indeterminate x.
R
Example 6.19 Let us consider again the problem of computing the integral 1/(x3 +x) dx.
In this case,
r = resx x3 + x, 1 y(3x2 + 1) = 4z 3 + 3y + 1 = (2y + 1)2 (y 1) ,
v1 = gcd x3 + x, 1 (3x2 + 1) = x ,
1
v2 = gcd x3 + x, 1 + (3x2 + 1) = x2 + 1 .
2
The algorithm, which can be easily given based on the previous theorem, can be
slightly improved: instead of computing vi = gcd(b, a ci b0 ) (by calculations over
the field L), vi can also be computed over K, applying the Extended-Euclidean-
Normalised algorithm. This was discovered by Trager, , and independently by
Lazard and Rioboo. It is not difficult to show that the running
time of the complete
integration algorithm obtained this way is O nM (n) lg n if deg f, deg g < n.
(1) deg vi = e;
Integrate-Logarithmic-Part(a, b, x)
1 Let r(y) resx (b, a yb0 ) by the subresultant algorithm, furthermore
2 let we (x, y) be the remainder of degree e during the computation
3 (r1 (y), . . . , rk (y)) Square-free(r(y))
4 int 0
5 for i 1 to k
6 do if ri (y) 6= 1
7 then w(y) the gcd of the coefficients of wi (x, y)
8 (l(y), s(y), t(y))
Extended-Euclidean-Normalised(w(y), ri (y))
9 wi (x, y) Primitive-Part(rem(s(y) wi (x, y), ri (y)))
10 (ri,1 , . . . , ri,k ) Factors(ri )
11 for j 1 to k
12 do d deg(ri,j )
13 c Solve(ri,j (y) = 0, y)
14 if d = 1
15 then int int + c log(wi (x, c))
16 else for n 1 to d
17 do int int + c[n] log(wi (x, c[n]))
18 return int
R
Example 6.20 Let us consider again the problem of computing the integral 1/(x2 2) dx.
In this case,
r = resx (x2 2, 1 y 2x) = 8y 2 + 1 .
The polynomial is irreducible in Q[x], thus, we cannot avoid the extension of Q. The
roots of r are 1/ 8. From the Extended-Euclidean-Normalised-algorithm over Q(y),
w1 (x, y) = x 1/(2y), thus, the integral is
Z
1 1 1
dx = log(x 2) log(x + 2) .
x2 2 8 8
Kj1 = K(1 , . . . , j1 )
Example 6.21 The function f = exp(x) + exp(2x) + exp(x/2) can be written in the form
f = 1 + 2 + 3 Q(x, 1 , 2 , 3 ), where 1 = exp(x), 2 = exp(2x), 3 = exp(x/2).
Trivially, 1 is exponential over Q(x), 2 is exponential over Q(x, 1 ) and 3 is exponential
over Q(x, 1 , 2 ). Since 2 = 12 and Q(x, 1 , 2 ) = Q(1 ), f can be written in the simpler
form f = 1 + 12 + 3 . The function 3 is not only exponential but also algebraic over
6.4. Symbolic integration 319
f = 32 + 34 + 3 Q(x, 3 ) .
Example 6.23 The function f = exp log(x)/2 can be written in the form f = 2
Q(x, 1 , 2 ), where 1 = log(x) and 2 = exp(1 /2), so 1 is logarithmic over Q(x), and 2
is exponential over Q(x, 1 ). But 22 x = 0, so 2 is algebraic over Q(x), and f (x) = x1/2 .
The most important classic result of the entire theory is the following theorem.
Theorem 6.25 (Liouvilles Principle). Let K be a differential field with constant
field C. Let L be a differential extension field of K with the same constant field. Let
us assume that g 0 = f K. Then there exist constants c1 , . . . , cm C and elements
v0 , v1 , . . . , vm K such that
m
X vj0
f = v00 + cj ,
j=1
vj
that is,
Z m
X
g= f = v0 + cj log(vj ) .
j=1
zero, and differentiating this equation, we get the derivative of the extending element
as a rational function of the element. Finally, we have to examine extensions by
transcendental logarithmic elements. We show that such an extending element can
be eliminated by differentiation if and only if it appears in a linear polynomial with
constant leading coefficient. This is due to the fact that differentiating a polynomial
of such an extending element, we get a polynomial the degree of which is either
the same or is reduced by one, the latter case only being possible when the leading
coefficient is constant.
Unlike the integration of rational functions, here the integration of the polynomial
part is more difficult. Therefore, we begin with the integration of the rational part.
Z Z
t() t()0 s()
= + +
(j 1)gi ()j1
Z (j 1)gi ()0
j1 gi ()j1
t() s() + t() /(j 1)
= + .
(j 1)gi ()j1 gi ()j1
Continuing this procedure while j > 1, we get
Z Z
h() c() a()
= + ,
g() d() b()
where a(), b(), c(), d() Kn1 [], deg a() < deg b() and b() is a square-free
and monic polynomial.
It can beR shown that the Rothstein-Trager method can be applied to compute
the integral a()/b(). Let us calculate the resultant
r(y) = res b(), a() y b()0 .
It can be shown that the integral is elementary if and only if r(y) is of the form
r(y) = r(y)s, where r(y) K[y] and s Kn1 . If we compute the primitive part
of r(y), choose it as r(y) and any coefficient of r(y) is not a constant, then there
is no elementary integral. Otherwise, let c1 , . . . , ck be the distinct roots of r(y) in
its factor field and let
vi () = gcd b(), a() ci b()0 Kn1 (c1 , . . . , ck )[]
R
Example 6.25 The integrand of the integral 1/ x log(x) is 1/(x) Q(x, ), where
= log(x). Here,
which has primitive part 1 y. Every coefficient of this is constant, so the integral is
elementary, c1 = 1, v1 () = gcd(, 1/x 1/x) = , so
Z
1
= c1 log v1 () = log log(x) .
x log(x)
6.4. Symbolic integration 323
k
X vj ()0
p() = v0 ()0 + cj ,
j=1
vj ()
We also get, by the reasoning used in the proof of Liouvilles Principle, that the
degree of v0 () is at most k + 1. So if v0 () = qk+1 k+1 + qk k + + q0 , then
m
X vj0
pk k + pk1 k1 + + p0 = (qk+1 k+1 + qk k + + q0 )0 + cj .
j=1
vj
rearranging, we get
pk1 kdk 0 = kbk 0 + qk1
0
,
so we have Z
u0
pk1 kdk = kbk + qk1
u
after integration. The integrand on the right hand side is in Kn1 , so we can call
the integration procedure in a recursive way. Just like above, the equation can only
be solved when the integral is elementary, it uses at most one logarithmic extension
and it is exactly = log(u). Let us assume that this is the case and
Z
u0
pk1 kdk = ck1 + dk1 ,
u
where ck1 K and dk1 Kn1 . Then the solution is bk = ck1 /k K and
qk1 = dk1 + bk1 , where bk1 is an arbitrary integration constant. Continuing
the procedure, the solution of the penultimate equation is b2 = c1 /2 K and
q1 = d1 +b1 with an integration constant b1 . Substituting for q1 into the last equation,
after rearrangement and integration, we get
Z
u0
p0 d 1 = b1 + q0 .
u
This time the only condition is that the integral should be an elementary function.
If it is elementary, say
Z
u0
p0 d 1 = d0 Kn1 ,
u
and 0 = b02R, 1 = 2b2 0 + q10 , 0 = q1 0R+ q00 . With the unknown constant b2 from the second
equation, 1 = 2b2 + q1 . Since 1 = x + b1 , we get b2 = 0, q1R = x + b1 . From the
third
R equation x0 = b1 0 + q00 . Since 0 = R1/x, after integration 1 = b1 + q0 and
1 = x, we get b1 = 0, q0 = x, hence, log(x) = x log(x) x.
R
Example 6.27 The integrand of the integral log log(x) is 2 Q(x, 1 , 2 ), where
6.4. Symbolic integration 325
and 0 = b02R, 1 = 2b2 20 + q10 , 0 = q1R20 + q00 . With the unknown constant b2 from the second
equation, 1 = 2b2 + q1 . Since 1 = x + b1 , we get b2 = 0, q1 = x + b1 . From the third
equation x20 = b1 20 + q00 . Since 20 = 10 /1 = 1/ x log(x) , the equation
Z
1
= b1 2 + q0
log(x)
must hold but we know from Example 6.24 that the integral on the left hand side is not
elementary.
It can be shown, however, that this unpleasant phenomenon does not appear if
6 | gj (), in which case gcd gj (), gj ()0 = 1. Thus, it will be sufficient to eliminate
from the denominator. Let g() = ` g(), where 6 | g(), and let us look for
polynomials h(), s() Kn1 [] with h()` + t()g() = h(), deg h() <
deg g() and deg s() < `. Dividing both sides by g(), we get
f () t() h()
= q() + l + .
g() g()
Using the notation p() = q()+t()/l , p() is a finite Laurent-series the integration
of which will be no harder than the integration of a polynomial. This is not surprising
if we note 1 = exp(u). Even so, the integration of the polynomial part is more
difficult here, too. We start with the other one.
where a(), b(), c(), d() Kn1 [], deg a() < deg b() and b() is a square-free
and monic polynomial, 6 | b().
It can beR shown that the Rothstein-Trager method can be applied to compute
the integral a()/b(). Let us calculate the resultant
r(y) = res b(), a() y b()0 .
It can be shown that the integral is elementary if and only if r(y) is of form r(y) =
r(y)s, where r(y) K[y] and s Kn1 . If we compute the primitive part of
r(y), choose it as r(y) and any coefficient of r(y) is not a constant, then there is
no elementary integral. Otherwise, let c1 , . . . , ck be the distinct roots of r(y) in its
factor field and let
vi () = gcd b(), a() ci b()0 Kn1 (c1 , . . . , ck )[]
R
Example 6.29 The integrand of the integral x/ 1+exp(x) is x/(1+) Q(x, ), where
= exp(x). Since
r(y) = res( + 1, x y) = x y Q(x)[y]
is a primitive polynomial that has a non-constant coefficient, the integral is not elementary.
6.4. Symbolic integration 327
where qj , vj Kn1 and cj K. The summation should be taken over the same
range as in p() since
(qj j )0 = (qj0 + ju0 gj )j .
Comparing the coefficients, we get the system
pj = qj0 + ju0 qj , ha ` j k, j 6= 0 ,
p0 = q00 ,
Pm
where q0 = q0 + j=1 cj log(vj ). The solution of the equation p0 = q00 is simply
R R
q0 = p0 ; if this integral is not elementary, then p() cannot be elementary
either, but if it is, then we have determined q0 . In the case j 6= 0, we have to solve
a differential equation called Risch differential equation to determine qj . The
differential equation is of the form y 0 + f y = g, where the given functions f and g
are elements of Kn1 , and we are looking for solutions in Kn1 . At first sight it
looks as if we had replaced the problem of integration with a more difficult problem,
but the linearity of the equations and that the solution has to be in Kn1 means
a great facility. If any Risch differential equation fails to have a solution in Kn1 ,
328 6. Computer Algebra
R
then p() is not elementary, otherwise
Z X
p() = qj j + q0 .
j6=0
The Risch differential equation can be solved algorithmically, but we will not go into
details.
Let us consider a few examples.
R
Example 6.30 The integrand of the integral R exp(x2 ) is Q(x, ), where =
2
exp(x ). If the integral is elementary, then = q1 , where q1 C(x).
R It is 2not dif-
ficult to show that the differential equation has no rational solutions, so exp(x ) is not
elementary.
R
Example 6.31 The integrand of the integral xx is exp (x log(x) = 2 Q(x, 1 , 2 ),
R
where 1 = log(x) and 2 = exp(x1 ). If the integral is elementary, then 2 = q1 2 , where
q1 C(x, 1 ). Differentiating both sides, 2 = q10 2 + q1 (1 + 1)2 , thus, 1 = q10 + (1 + 1)q1 .
Since 1 is transcendental over C(x), R by comparing the coefficients 1 = q10 + q1 and 0 = q1 ,
x
which has no solutions. Therefore, x is not elementary.
4x2 + 4x 1
q20 + 4xq2 = ,
(x + 1)2
2
4x + 4x 1
q00 = .
(x + 1)2
The second equation can be integrated and q0 is elementary. The solution of the first
equation is q2 = 1/(1 + x). Hence,
Z
1 (2x + 1)2
f () = exp2 (x2 ) + 4 log(x + 1) .
x+1 x+1
Exercises
6.4-1 Apply Hermite-reduction to the following function f (x) Q(x) :
R
6.4-2 Compute the integral f , where
36x6 + 126x5 + 183x4 + 13807/6x3 407x2 3242/5x + 3044/15
f (x) = Q(x) .
(x2 + 7/6x + 1/3)2 (x 2/5)3
6.4-3 Apply the Risch integration algorithm to compute the following integral:
Z 2 2
x(x + 1){(x2 e2x log(x + 1)2 ) + 2xe3x (x (2x3 + 2x2 + x + 1) log(x + 1))}
dx .
((x + 1) log2 (x + 1) (x3 + x2 )e2x2 )2
Hensels lemma for the arithmetic of p-adic numbers to extend factorisation. Hensel-
lifting as his procedure is now called is a general approach for the reconstruction
of factors from their modular images. Unlike interpolation, which needs multiple
points from the image, Hensel-lifting only needs one point from the image. The
BerlekampZassenhaus-algorithm for the factorisation of polynomials with integer
coefficients is of fundamental importance but it has two hidden pitfalls. First, for
a certain type of polynomial the running time is exponential. Unfortunately, many
bad polynomials appear in the case of factorisation over algebraic number fields.
Second, a representation problem appears for multivariable polynomials, similar to
what we have encountered at the Gauss-elimination of sparse matrices. The first
problem was solved by a Diophantine optimisation based on the geometry of num-
bers, a so-called lattice reduction algorithm by Lenstra-Lenstra-Lovsz [155]; it is
used together with Berlekamps method. This polynomial algorithm is completed by
a procedure which ensures that the Hensel-lifting will start from a good modular
image and that it will end in time. Solutions have been found for the mentioned
representation problem of the factorisation of multivariable polynomials as well. This
is the second area where randomisation plays a crucial role in the design of effective
algorithms. We note that in practice, the Berlekamp-Zassenhaus-Hensel-algorithm
proves more effective than the Lenstra-Lenstra-Lovsz-procedure. As a contrast, the
problem of polynomial factorisation can be solved in polynomial time, while the best
proved algorithmic bound for the factorisation of the integer N is O(N e 1/4 ) (Pollard
and Strassen) in the deterministic case and L(N ) 1+o(1)
(Lenstra and Pomerance) in
the probabilistic case, where L(N ) = e ln N ln ln N .
In fact, a new theory of heuristic or probabilistic methods in computer algebra
is being born to avoid computational or memory explosion and to make algorithms
with deterministically large running times more effective. In the case of probabilistic
algorithms, the probability of inappropriate operations can be positive, which may
result in an incorrect answer (Monte Carlo algorithms) oralthough we always get
the correct answer (Las Vegas algorithms)we may not get anything in polyno-
mial time. Beside the above examples, nice results have been achieved in testing
polynomial identity, irreducibility of polynomials, determining matrix normal forms
(Frobenius, Hilbert, Smith), etc. Their role is likely to increase in the future.
So far in the chapter we gave an overview of the most important symbolic algo-
rithms. We mentioned in the introduction that most computer algebra systems are
also able to perform numeric computations: unlike traditional systems, the precision
can be set by the user. In many cases, it is useful to combine the symbolic and nu-
meric computations. Let us consider for example the symbolically computed power
series solution of a differential equation. After truncation, evaluating the power se-
ries with the usual floating point arithmetics in certain points, we get a numerical
approximation of the solution. When the problem is an approximation of a physical
problem, the attractivity of the symbolic computation is often lost, simply because
they are too complicated or too slow and they are not necessary or useful, since we
are looking for a numerical solution. In other cases, when the problem cannot be
dealt with using symbolic computation, the only way is the numerical approxima-
tion. This may be the case when the existing symbolic algorithm does not find a
closed solution (e.g. the integral of non-elementary functions, etc.), or when a sym-
6.5. Theory and practice 331
bolic algorithm for the specified problem does not exist. Although more and more
numerical algorithms have symbolic equivalents, numerical procedures play an im-
portant role in computer algebra. Let us think of differentiation and integration:
sometimes traditional algorithmsintegral transformation, power series approxima-
tion, perturbation methodscan be the most effective.
In the design of computer algebra algorithms, parallel architectures will play
an increasing role in the future. Although many existing algorithms can be paral-
lelised easily, it is not obvious that good sequential algorithms will perform optimally
on parallel architectures as well: the optimal performance might be achieved by a
completely different method.
Problems
2 Declarative programming languages specify the desired result unlike imperative languages, which
describe how to get the result.
Notes for Chapter 6 333
Chapter Notes
The algorithms Classical-Euclidean and Extended-Euclidean for non-
negative integers are described in [53]. A natural continuation of the theory of resul-
tants leads to subresultants, which can help in reducing the growth of the coefficients
in the Extended-Euclidean algorithm (see e.g. [82, 87]).
Grbner bases were introduced by B. Buchberger in 1965 [34]. Several authors
examined polynomial ideals before this. The most well-known is perhaps Hironaka,
who used bases of ideals of power series to resolve singularities over C. He was
rewarded a Fields-medal for his work. His method was not constructive, however.
Grbner bases have been generalised for many algebraic structures in the last two
decades.
The bases of differential algebra have been layed by J. F. Ritt in 1948 [207].
The square-free factorisation algorithm used in symbolic integration can be found
for example in the books [82, 87]. The importance of choosing the smallest possible
extension degree in Hermite-reduction is illustrated by Example 11.11 in [87], where
the splitting field has very large degree but the integral can be expressed in an
extension of degree 2. The proof of the Rothstein-Trager integration algorithm can be
found in [82] (Theorem 22.8). We note that the algorithm was found independently
by Rothstein and Trager. The proof of the correctness of the Lazard-Rioboo-Trager
formula, the analysis of the running time of the Integrate-Logarithmic-Part
algorithm, an overview of the procedures that deal with the difficulties of algebraic
extension steps, the determination of the hyperexponential integral (if exists) of a
hyperexponential element over C(x), the proof of Liouvilles principle and the proofs
of the statements connected to the Risch algorithm can be found in the book [82].
There are many books and publications available on computer algebra and re-
lated topics. The interested reader will find mathematical description in the following
general works: Caviness [41], Davenport et al. [59], von zur Gathen et al. [82], Geddes
et al. [87], Knuth [140, 141, 142], Mignotte [175], Mishra [178], Pavelle et al. [195],
Winkler [?].
The computer-oriented reader will find further information on computer algebra
in Christensen [43], Gonnet and Gruntz [?], Harper et al. [103] and on the world
wide web.
A wide range of books and articles deal with applications, e.g. Akritas [10],
Cohen et al. (eds.) [48, 49], Grossman (ed.) [96], Hearn (ed.) [105], Kovcs [144] and
Odlyzko [189].
334 6. Computer Algebra
For the role of computer algebra systems in education see for example the works
of Karian [132] and Uhl [254].
Conference proceedings: Aaecc, Disco, Eurocal, Eurosam, Issac and Sym-
sac.
Computer algebra journals: Journal of Symbolic ComputationAcademic Press,
Applicable Algebra in Engineering, Communication and ComputingSpringer-
Verlag, Sigsam BulletinACM Press.
The Department of Computer Algebra of the Etvs Lornd University, Bu-
dapest takes works [82, 87, 175, ?] as a base in education.
7. Cryptology
Erich
7.1. Foundations
Cryptography is the art and science of designing secure cryptosystems, which are
used to encrypt texts and messages so that they be kept secret and unauthorised de-
cryption is prevented, whereas the authorised receiver is able to efficiently decrypt
the ciphertext received. This section presents two classical symmetric cryptosys-
tems. In subsequent sections, some important asymmetric cryptosystems and cryp-
tographic protocols are introduced. A protocol is dialog between two (or more)
parties, where a party may be either a human being or a computing machine.
Cryptographic protocols can have various cryptographic purposes. They consist of
algorithms that are jointly executed by more than one party.
Cryptanalysis is the art and science of (unauthorised) decryption of cipher-
texts and of breaking existing cryptosystems. Cryptology captures both these fields,
cryptography and cryptanalysis. In this chapter, we focus on cryptographic algo-
rithms. Algorithms of cryptanalysis, which are used to break cryptographic proto-
cols and systems, will be mentioned as well but will not be investigated in detail.
7.1. Foundations 337
7.1.1. Cryptography
Figure 7.1 shows a typical scenario in cryptography: Alice and Bob communicate
over an insecure channel that is eavesdropped by Erich, and thus they encrypt their
messages using a cryptosystem.
Definition 7.1 (Cryptosystem). A cryptosystem is a quintuple (P, C, K, E, D)
with the following properties:
1. P, C, and K are finite sets, where P is the plaintext space, C is the ciphertext
space, and K is the key space. The elements of P are called the plaintexts,
and the elements of C are called the ciphertexts. A message is a string of
plaintext symbols.
2. E = {Ek | k K} is a family of functions Ek : P C, which are used for
encryption. D = {Dk | k K} is a family of functions Dk : C P, which are
used for decryption.
3. For each key e K, there exists some key d K such that for each plaintext
p P,
Dd (Ee (p)) = p . (7.1)
Example 7.1 (Shift Cipher) The first example is a monoalphabetic symmetric cryptosys-
tem. Let K = P = C = Z26 . The shift cipher encrypts messages by shifting every plaintext
symbol by the same number k of letters in the alphabet modulo 26. Shifting each letter in
the ciphertext back using the same key k, the original plaintext is recovered. For each key
k Z26 , the encryption function Ek and the decryption function Dk are defined by:
Ek (m) = (m + k) mod 26
Dk (c) = (c k) mod 26 ,
where addition and subtraction by k modulo 26 are carried out characterwise.
338 7. Cryptology
m S H I FT EACH L ETTE R TO TH E L E FT
c RGHE S D Z BG KD S S DQ S N S GD KDE S
Figure 7.2 shows an encryption of the message m by the shift cipher with key k = 25.
The resulting ciphertext is c. Note that the particular shift cipher with key k = 3 is also
known as the Caesar cipher, since the Roman Emperor allegedly used this cipher during
his wars to keep messages secret.1 This cipher is a very simple substitution cipher in which
each letter is substituted by a certain letter of the alphabet.
Since the key space is very small, the shift cipher can easily be broken. It is
already vulnerable by attacks in which the attacker knows the ciphertext only, simply
by checking which of the 26 possible keys reveals a meaningful plaintext, provided
that the ciphertext is long enough to allow unique decryption.
The shift cipher is a monoalphabetic cryptosystem, since every plaintext letter is
replaced by one and the same letter in the ciphertext. In contrast, a polyalphabetic
cryptosystem can encrypt the same plaintext symbols by different ciphertext sym-
bols, depending on their position in the text. Such a polyalphabetic cryptosystem
that is based on the shift cipher, yet much harder to break, was proposed by the
French diplomat Blaise de Vigenre (1523 until 1596). His system builds on previous
work by the Italian mathematician Leon Battista Alberti (born in 1404), the German
abbot Johannes Trithemius (born in 1492), and the Italian scientist Giovanni Porta
(born in 1675). It works like the shift cipher, except that the letter that encrypts
some plaintext letter varies with its position in the text.
Ek (b) = (b + k) mod 26
Dk (c) = (c k) mod 26,
where addition and subtraction by k modulo 26 are again carried out characterwise. That
is, the key k Zn n
26 is written letter by letter above the symbols of the block b Z26 to be
encrypted. If the last plaintext block has less than n symbols, one uses less key symbols
1 Historic remark: Gaius Julius Caesar reports in his book De Bello Gallico that he sent an
encrypted message to Q. Tullius Cicero (the brother of the famous speaker) during the Gallic Wars
(58 until 50 B.C.). The system used was monoalphabetic and replaced Latin letters by Greek letters;
however, it is not explicitly mentioned there if the cipher used indeed was the shift cipher with key
k = 3. This information was given later by Suetonius.
7.1. Foundations 339
0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
1 B C D E F G H I J K L M N O P Q R S T U V W X Y Z A
2 C D E F G H I J K L M N O P Q R S T U V W X Y Z A B
3 D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
4 E F G H I J K L M N O P Q R S T U V W X Y Z A B C D
5 F G H I J K L M N O P Q R S T U V W X Y Z A B C D E
6 G H I J K L M N O P Q R S T U V W X Y Z A B C D E F
7 H I J K L M N O P Q R S T U V W X Y Z A B C D E F G
8 I J K L M N O P Q R S T U V W X Y Z A B C D E F G H
9 J K L M N O P Q R S T U V W X Y Z A B C D E F G H I
10 K L M N O P Q R S T U V W X Y Z A B C D E F G H I J
11 L M N O P Q R S T U V W X Y Z A B C D E F G H I J K
12 M N O P Q R S T U V W X Y Z A B C D E F G H I J K L
13 N O P Q R S T U V W X Y Z A B C D E F G H I J K L M
14 O P Q R S T U V W X Y Z A B C D E F G H I J K L M N
15 P Q R S T U V W X Y Z A B C D E F G H I J K L M N O
16 Q R S T U V W X Y Z A B C D E F G H I J K L M N O P
17 R S T U V W X Y Z A B C D E F G H I J K L M N O P Q
18 S T U V W X Y Z A B C D E F G H I J K L M N O P Q R
19 T U V W X Y Z A B C D E F G H I J K L M N O P Q R S
20 U V W X Y Z A B C D E F G H I J K L M N O P Q R S T
21 V W X Y Z A B C D E F G H I J K L M N O P Q R S T U
22 W X Y Z A B C D E F G H I J K L M N O P Q R S T U V
23 X Y Z A B C D E F G H I J K L M N O P Q R S T U V W
24 Y Z A B C D E F G H I J K L M N O P Q R S T U V W X
25 Z A B C D E F G H I J K L M N O P Q R S T U V W X Y
accordingly. In order to encrypt the ith plaintext symbol bi , which has the key symbol ki
sitting on top, use the ith row of the Vigenre square as in the shift cipher.
For example, choose the block length n = 4 and the key k = TONY. Figure 7.4 shows
the encryption of the message m, which consists of seven blocks, into the ciphertext c by
the Vigenre cipher using key k.
To the first plaintext letter, H, the key symbol T is assigned. The intersection of
the H column with the T row of the Vigenre square yields A as the first letter of
the ciphertext, see Figure 7.3.
340 7. Cryptology
There are many other classical cryptosystems, which will not be described in de-
tail here. There are various ways to classify cryptosystems according to their proper-
ties or to the specific way they are designed. In Definition 7.1, the distinction between
symmetric and asymmetric cryptosystems was explained. The two examples above
(the shift cipher and the Vigenre cipher) demonstrated the distinction between
monoalphabetic and polyalphabetic systems. Both are substitution ciphers, which
may be contrasted with permutation ciphers (a.k.a. transposition ciphers) in
which the plaintext letters are not substituted by certain ciphertext letters but go
to another position in the text remaining otherwise unchanged.
Moreover, block ciphers such as the Vigenre system can be contrasted with
stream ciphers, which produce a continuous stream of key symbols depending on
the plaintext context to be encrypted. One can also distinguish between different
types of block ciphers. An important type are the affine linear block ciphers,
which are defined by affine linear encryption functions E(A,~b) and decryption func-
tions D(A1 ,~b) , both mapping from Znm to Znm . That is, they are of the following
form:
Here, (A, ~b) and (A1 , ~b) are the keys used for encryption and decryption, respec-
tively; A is a (n n) matrix with entries from Zm ; A1 is the inverse matrix for A;
~x, ~y , and ~b are vectors in Znm , and all arithmetics is carried out modulo m. Some
mathematical explanations are in order (see also Definition 7.2 in Subsection 7.1.3):
An (n n) matrix A over the ring Zm has a multiplicative inverse if and only
if gcd(det A, m) = 1. The inverse matrix for A is defined by A1 = (det A)1 Aadj ,
where det A is the determinant of A, and Aadj = ((1)i+j det Aj,i ) is the adjunct ma-
trix for A. The determinant det A of A is recursively defined: PFor n = 1 and A = (a),
n
det A = a; for n > 1 and each i {1, 2, . . . , n}, det A = j=1 (1)i+j ai,j det Ai,j ,
where ai,j denotes the (i, j) entry of A and the (n 1) (n 1) matrix Ai,j results
from A by cancelling the ith row and the jth column. The determinant of a matrix
and thus its inverse (if it exists) can be computed efficiently, see Problem 7-3.
For example, the Vigenre cipher is an affine linear cipher whose key contains
the unity matrix as its first component. If ~b in (7.2) is the zero vector, then it is
a linear block cipher. A classical example is the Hill cipher, invented by Lester
Hill in 1929. Here, the key space is the set of all (n n) matrices A with entries
in Zm such that gcd(det A, m) = 1. This condition guarantees the invertibility of
those matrices that are allowed as keys, since the inverse matrix A1 is used for
decryption of the messages encrypted by key A. For each key A, the Hill cipher is
defined by the encryption function EA (~x) = A~x mod m and the decryption function
DA1 (~y ) = A1 ~y mod m. Thus, it is the most general linear cipher. The permutation
cipher also is linear, and hence is a special case of the Hill cipher.
7.1. Foundations 341
7.1.2. Cryptanalysis
Cryptanalysis aims at breaking existing cryptosystems and, in particular, at deter-
mining the decryption keys. In order to characterise the security or vulnerability of
the cryptosystem considered, one distinguishes different types of attacks according
to the information available for the attacker. For the shift cipher, ciphertext-only
attacks were already mentioned. They are the weakest type of attack, and a cryp-
tosystem that does not resist such attacks is not of much value.
Affine linear block ciphers such as the Vigenre and the Hill cipher are vulner-
able to attacks in which the attacker knows the plaintext corresponding to some
ciphertext obtained and is able to conclude the keys used. These attacks are called
known-plaintext attacks. Affine linear block ciphers are even more vulnerable to
chosen-plaintext attacks, in which the attacker can choose some plaintext and is
then able to see which ciphertext corresponds to the plaintext chosen. Another type
of attack is in particular relevant for asymmetric cryptosystems: In an encryption-
key attack, the attacker merely knows the public key but does not know any ci-
phertext yet, and seeks to determine the private key from this information. The
difference is that the attacker now has plenty of time to perform computations,
whereas in the other types of attacks the ciphertext was already sent and much less
time is available to decrypt it. That is why keys of much larger size are required in
public-key cryptography to guarantee the security of the system used. Hence, asym-
metric cryptosystems are much less efficient than symmetric cryptosystems in many
practical applications.
For the attacks mentioned above, the method of frequency counts is often useful.
This method exploits the redundancy of the natural language used. For example,
in many natural languages, the letter E occurs statistically significant most fre-
quently. On average, the E occurs in long, typical texts with a percentage of
12.31% in English, of 15.87% in French, and even of 18.46% in German. In other
languages, different letters may occur most frequently. For example, the A is the
most frequent letter in long, typical Finnish texts, with a percentage of 12.06%.
That the method of frequency counts is useful for attacks on monoalphabetic
cryptosystems is obvious. For example, if in a ciphertext encrypting a long German
text by the shift cipher, the letter occurring most frequently is Y, which is rather
rare in German (as well as in many other languages), then it is most likely that
Y encrypts E. Thus, the key used for encryption is U (k = 20). In addition to
counting the frequency of single letters, one can also count the frequency with which
certain pairs of letters (so-called digrams) and triples of letters (so-called trigrams)
occur, and so on. This kind of attack also works for polyalphabetic systems, provided
the period (i.e., the block length) is known.
Polyalphabetic cryptosystems with an unknown period, however, provide more
security. For example, the Vigenre cipher resisted each attempt of breaking it for a
long time. No earlier than in 1863, about 300 years after its discovery, the German
cryptanalyst Friedrich Wilhelm Kasiski found a method of breaking the Vigenre
cipher. He showed how to determine the period, which initially is unknown, from
repetitions of the same substring in the ciphertext. Subsequently, the ciphertext can
be decrypted by means of frequency counts. Singh writes that the British eccentric
342 7. Cryptology
Charles Babbage, who was considered a genius of his time by many, presumably had
discovered Kasiskis method even earlier, around 1854, although he didnt publish
his work.
The pathbreaking work of Claude Shannon (1916 until 2001), the father of mod-
ern coding and information theory, is now considered a milestone in the history
of cryptography. Shannon proved that there exist cryptosystems that guarantee
perfect secrecy in a mathematically rigorous sense. More precisely, a cryptosystem
(P, C, K, E, D) guarantees perfect secrecy if and only if |P| = |C| = |K|, the keys
in K are uniformly distributed, and for each plaintext p P and for each cipher-
text c C there exists exactly one key k K with Ek (p) = c. That means that
such a cryptosystem often is not useful for practical applications, since in order to
guarantee perfect secrecy, every key must be at least as long as the message to be
encrypted and can be used only once.
The element e is called the neutral element of the group G. The element x1
is called the inverse element forx. G is said to be a monoid if G satisfies
associativity and closure under , even if G has no neutral element or if not every
element in G has an inverse. A group G = (S, ) (respectively, a monoid G =
(S, )) is said to be commutative (or abelian) if and only if x y = y x for all
x, y S. The number of elements of a finite group G is said to be the order G
and is denoted by |G|.
H = (T, ) is said to be a subgroup of a group G = (S, ) (denoted by H G)
if and only if T S and H satisfies the group axioms.
A ring is a triple R = (S, +, ) such that (S, +) is an abelian group and (S, ) is
a monoid and the distributive laws are satisfied:
(x S) (y S) (z S) :
7.1. Foundations 343
Claim 7.3 If n = p q for prime numbers p and q, then (n) = (p 1)(q 1).
Eulers Theorem below is a special case (namely, for the group Zn ) of Lagranges
Theorem, which says that for each group element a of a finite multiplicative group
G of order |G| and with neutral element e, a|G| = e. The special case of Eulers
theorem, where n is a prime number not dividing a, is known as Fermats Little
Theorem.
In Section 8.4, algorithms for the graph isomorphism problem will be presented.
This problem, which also is related to the zero-knowledge protocols to be introduced
344 7. Cryptology
The notion of pointwise stabilisers is especially important for the design of al-
gorithms solving problems on permutation groups. The crucial structure exploited
there is the so-called tower of stabilisers of a permutation group G:
id = G(n) G(n1) G(1) G(0) = G .
For each i with
Sn11 i n, let Ti be the complete right transversal of G in G
(i) (i1)
.
Then, T = i=1 Ti is said to be a strong generator of G, and we have G = hTi.
Every G then has a unique factorisation = 1 2 n with i Ti . The
following basic algorithmic results about permutation groups will be useful later in
Section 8.4.
7.1. Foundations 345
The notions introduced in Definition 7.6 for permutation groups are now ex-
plained for concrete examples from graph theory. In particular, we consider the
automorphism group and the set of isomorphisms between graphs. We start by in-
troducing some useful graph-theoretical concepts.
Definition 7.8 (Graph isomorphism and graph automorphism). A graph G con-
sists of a finite set of vertices, V (G), and a finite set of edges, E(G), that connect
certain vertices with each other. We assume that no multiple edges and no loops
occur. In this chapter, we consider only undirected graphs, i.e., the edges are not
oriented and can be seen as unordered vertex pairs. The disjoint union G H of two
graphs G and H is defined as the graph with vertex set V (G) V (H) and edge set
E(G) E(H), where we assume that that the vertex sets V (G) and V (H) are made
disjoint (by renaming if necessary).
Let G and H be two graphs with the same number of vertices. An isomorphism
between G and H is an edge-preserving bijection of the vertex set of G onto that
of H. Under the convention that V (G) = {1, 2, . . . , n} = V (H), G and H are iso-
morphic (G = H, for short) if and only if there exists a permutation Sn such
that for all vertices i, j V (G),
{i, j} E(G) {(i), (j)} E(H) . (7.4)
For algorithmic purposes, graphs are represented either by their vertex and edge
lists or by an adjacency matrix, which has the entry 1 at position (i, j) if {i, j} is
an edge, and the entry 0 otherwise. This graph representation is suitably encoded
over the alphabet = {0, 1}. In order to represent pairs of graphs, we use a stan-
dard bijective pairing function (, ) from onto that is polynomial-time
computable and has polynomial-time computable inverses.
Example 7.4[Graph isomorphism and graph automorphism] The graphs G and H shown
in Figure 7.5 are isomorphic.
346 7. Cryptology
F 2 1
4 5
G 5 H 2 1
3 4
3
1 2 4 5
Figure 7.5 Three graphs: G is isomorphic to H, but not to F .
Iso(G, H) and Aut(G) have the same number of elements if and only if G and
H are isomorphic. To wit, if G and H are isomorphic, then |Iso(G, H)| = |Aut(G)|
follows from Aut(G) = Iso(G, G). Otherwise, if G 6 H, then Iso(G, H) is empty but
=
Aut(G) contains always the trivial automorphism id. This implies (7.5) in Lemma 7.9
below, which we will need later in Section 8.4. For proving (7.6), suppose that G
and H are connected; otherwise, we simply consider instead of G and H the co-
graphs G and H, see Exercise 7.1-5. An automorphism of G H that switches the
vertices of G and H, consists of an isomorphism in Iso(G, H) and an isomorphism
in Iso(H, G). Thus, |Aut(G H)| = |Aut(G)| |Aut(H)| + |Iso(G, H)|2 , which implies
(7.6) via (7.5).
7.1. Foundations 347
Corollary 7.10 If G is a graph with n vertices, then there are exactly n!/|Aut(G)|
graphs isomorphic to G.
For the graph G in Figure 7.5 from Example 7.4, there thus exist exactly 5!/4 =
30 isomorphic graphs. The following lemma will be used later in Section 8.4.
Lemma 7.11 Let G and H be two graphs with n vertices. Define the set
Then, we have
n! if G
=H
|A(G, H)| =
2n! if G
6= H .
n!
|{(F, ) | F
= G and Aut(F )}| = |Aut(F )| = n! .
|Aut(F )|
Figure 7.6 Two ciphertexts encrypting the same plaintext, see Exercise 7.1-1.
It follows that |A(G, H)| = n!. If G and H are nonisomorphic, then {(F, ) | F
=G
and Aut(F )} and {(F, ) | F = H and Aut(F )} are disjoint sets. Thus,
|A(G, H)| = 2n!.
Exercises
7.1-1 Figure 7.6 shows two ciphertexts, c1 and c2 . It is known that both encrypt
the same plaintext m and that one was obtained using the shift cipher, the other one
using the Vigenre cipher. Decrypt both ciphertexts. Hint. After decryption you will
notice that the plaintext obtained is a true statement for one of the two ciphertexts,
whereas it is a false statement for the other ciphertext. Is perhaps the method of
frequency counts useful here?
7.1-2 Prove that Z is a ring with respect to ordinary addition and multiplication.
Is it also a field? What can be said about the properties of the algebraic structures
(N, +), (N, ), and (N, +, )?
7.1-3 Prove the properties stated for Eulers function:
a. (m n) = (m) (n) for all m, n N with gcd(m, n) = 1.
b. (p) = p 1 for all prime numbers p.
Using these properties, prove Proposition 7.3.
7.1-4 Consider the graphs F , G, and H from Figure 7.5 in Example 7.4.
a. Determine all isomorphisms between G and H.
b. Determine all automorphisms of F , G, and H.
c. For which isomorphisms between G and H is Iso(G, H) a right coset of Aut(G)
in S5 , i.e., for which Iso(G, H) is Iso(G, H) = Aut(G) ? Determine the complete
right transversals of Aut(F ), Aut(G), and Aut(H) in S5 .
d. Determine the orbit of all vertices of F in Aut(F ) and the orbit of all vertices
of H in Aut(H).
e. Determine the tower of stabilisers of the subgroups Aut(F ) S5 and
Aut(H) S5 .
f. How many graphs with 5 vertices are isomorphic to F ?
7.1-5 The co-graph G of a graph G is defined by the vertex set V (G) = V (G) and
the edge set E(G) = {{i, j} | i, j V (G) and {i, j} 6 E(G)}. Prove the following
claims: a. Aut(G) = Aut(G).
b. Iso(G, H) = Iso(G, H).
c. G is connected if G is not connected.
7.2. Diffie and Hellmans secret-key agreement protocol 349
Example 7.5 Consider Z5 = {1, 2, 3, 4}. Since Z4 = {1, 3}, we have (4) = 2, and the two
primitive roots of 5 are 2 and 3. Both 2 and 3 generate all of Z5 , since:
20 = 1; 21 = 2; 22 = 4; 23 3 mod 5 ;
30 = 1; 31 = 3; 32 4 mod 5; 33 2 mod 5 .
Not every number has a primitive root; 8 is the smallest such example. It is
known that a number n has a primitive root if and only if n either is from {1, 2, 4},
or has the form n = q k or n = 2q k for some odd prime number q.
The protocol given in Figure 7.7 works, since (in the arithmetics modulo p)
kA = a = rba = rab = b = kB ,
so Alice indeed computes the same key as Bob. Computing this key is not hard, since
350 7. Cryptology
Square-and-Multiply(a, b, m)
1 m is the modulus, b < m is the base, and a is the exponent
Pk
2 determine the binary expansion of the exponent a = i=0 ai 2i , where ai {0, 1}
i i+1
i 2
3 compute successively b2 , where 0 i k, using that b2 = b2
Qk i
4 compute ba = i = 0 b2 in the arithmetics modulo m
ai =1
i i+1
5 as soon as a factor b2 in the product and b2 are determined,
2i
b can be deleted and need not be stored
6 return ba
Why can the modular exponential function expr,p (a) = ra mod p be computed
efficiently? Naively performed, this computation may require many multiplications,
depending on the size of the exponent a. However, using algorithm Square-and-
Multiply there is no need to perform a1 multiplications as in the naive approach;
no more than 2 log a multiplications suffice. The square-and-multiply algorithm thus
speeds modular exponentiation up by an exponential factor.
Note that in the arithmetics modulo m, we have
Pk k
Y ai k
Y
ai 2i i i
ba = b i=0 = b2 = b2 .
i=0 i=0
ai =1
Example 7.6[ Square-and-Multiply in the Diffie-Hellman Protocol] Alice and Bob have
chosen the prime number p = 5 and the primitive root r = 3 of 5. Alice picks the secret
number a = 17. In order to send her public number to Bob, Alice wishes to compute
= 317 = 129140163 3 mod 5. The binary expansion of the exponent is 17 = 1 + 16 =
20 + 24 . Alice successively computes the values:
0 1 2 3 4
32 = 3; 32 = 32 4 mod 5; 32 42 1 mod 5; 32 12 1 mod 5; 32 12 1 mod 5 .
0 4
Then, she computes 317 32 32 3 1 3 mod 5. Note that Alice does not have to
multiply 16 times but merely performs four squarings and one multiplication to determine
= 3 mod 5.
Suppose that Bob has chosen the secret exponent b = 23. By the same method, he
can compute his part of the key, = 323 = 94143178827 2 mod 5. Now, Alice and Bob
7.2. Diffie and Hellmans secret-key agreement protocol 351
determine their joint secret key according to the Diffie-Hellman protocol from Figure 7.7;
see Exercise 7.2-2.
Note that the protocol is far from being secure in this case, since the prime number
p = 5 and the secret exponents a = 17 and b = 23 are much too small. This toy example
was chosen just to explain how the protocol works. In practice, a and b should have at least
160 bits each.
If Erich was listening very careful, he knows the values p, r, , and after Alice
and Bob have executed the protocol. His aim is to determine their joint secret key
kA = kB . This problem is known as the Diffie-Hellman problem. If Erich were able to
determine a = logr mod p and b = logr mod p efficiently, he could compute the
key kA = a mod p = b mod p = kB just like Alice and Bob and thus would have
solved the Diffie-Hellman problem. Thus, this problem is no harder than the problem
of computing discrete logarithms. The converse question of whether or not the Diffie-
Hellman problem is at least as hard as solving the discrete logarithm (i.e., whether
or not the two problems are equally hard) is still just an unproven conjecture. As
many other cryptographic protocols, the Diffie-Hellman protocol currently has no
proof of security.
However, since up to date neither the discrete logarithm nor the Diffie-Hellman
problem can be solved efficiently, this direct attack is not a practical threat. On the
other hand, there do exist other, indirect attacks in which the key is determined not
immediately from the values and communicated in the Diffie-Hellman protocol.
For example, Diffie-Hellman is vulnerable by the man-in-the-middle attack. Unlike
the passive attack described above, this attack is active, since the attacker Erich aims
at actively altering the protocol to his own advantage. He is the man in the middle
between Alice and Bob, and he intercepts Alices message = ra mod p to Bob and
Bobs message = rb mod p to Alice. Instead of and , he forwards his own values
E = rc mod p to Bob and E = rd mod p to Alice, where the private numbers c and
d were chosen by Erich. Now, if Alice computes her key kA = (E )a mod p, which
she falsely presumes to share with Bob, kA in fact is a key for future communications
with Erich, who determines the same key by computing (in the arithmetics modulo p)
kE = d = rad = rda = (E )a = kA .
Similarly, Erich can share a key with Bob, who has not the slightest idea that he in
fact communicates with Erich. This raised the issue of authentication, which we will
deal with in more detail later in Section 7.5 about zero-knowledge protocols.
Exercises
7.2-1 a. How many primitive roots do Z13 and Z14 have?
b. Determine all primitive roots of Z13 and Z14 , and prove that they indeed are
primitive roots.
c. Show that every primitive root of 13 and of 14, respectively, generates all of
Z13 and Z14 .
7.2-2 a. Determine Bobs number = 323 = 94143178827 2 mod 5 from Example
7.6 using the algorithm Square-and-Multiply.
b. For and from Example 7.6, determine the joint secret key of Alice and
Bob according to the Diffie-Hellman protocol from Figure 7.7.
352 7. Cryptology
and computes the inverse of e mod (n), i.e., the unique number d such that
The pair (n, e) is Bobs public key, and d is Bobs private key.
2. Encryption: As in Section 7.1, messages are strings over an alphabet . Any
message is subdivided into blocks of a fixed length, which are encoded as positive
integers in ||-adic representation. These integers are then encrypted. Let m < n
be the number encoding some block of the message Alice wishes to send to Bob.
Alice knows Bobs public key (n, e) and encrypts m as the number c = E(n,e) (m),
where the encryption function is defined by
3. Decryption: Let c with 0 c < n be the number encoding one block of the
ciphertext, which is received by Bob and also by the eavesdropper Erich. Bob
decrypts c by using his private key d and the following decryption function
Dd (c) = cd mod n .
7.3. RSA and factoring 353
Theorem 7.13 states that the RSA protocol described above indeed is a cryp-
tosystems in the sense of Definition 7.1. The proof of Theorem 7.13 is left to the
reader as Exercise 7.3-1.
Theorem 7.13 Let (n, e) be the public key and d be the private key in the RSA
protocol. Then, for each message m with 0 m < n,
d
m = (me ) mod n .
2 The complexity classes P and NP will be defined in Section 8.1 and the notion of NP-completeness
will be defined in Section 8.2.
354 7. Cryptology
Miller-Rabin(n)
1 determine the representation n 1 = 2k m, where m and n are odd
2 choose a number z {1, 2, . . . , n 1} at random under the uniform distribution
3 compute x = z m mod n
4 if (x 1 mod n)
5 then return n is a prime number
6 else for j 0 to k 1
7 do if (x 1 mod n)
8 then return n is a prime number
9 else x x2 mod n
10 return n is not a prime number
One of the most popular randomised primality tests is the algorithm Miller-
Rabin developed by Rabin [203], which is based on the ideas underlying the deter-
ministic algorithm of Miller [176]. The Miller-Rabin test is a so-called Monte Carlo
algorithm, since the no answers of the algorithm are always reliable, whereas its
yes answers have a certain error probability. An alternative to the Miller-Rabin
test is the primality test of Solovay and Strassen [240]. Both primality tests run in
time O(n3 ). However, the Solovay-Strassen test is less popular because it is not as
efficient in practice and also less accurate than the Miller-Rabin test.
The class of problems solvable via Monte Carlo algorithms with always reliable
yes answers is named RP, which stands for Randomised Polynomial Time. The
complementary class, coRP = {L | L RP}, contains all those problems solvable
via Monte Carlo algorithms with always reliable no answers. Formally, RP is de-
fined via nondeterministic polynomial-time Turing machines (NPTMs, for short; see
Section 8.1 and in particular Definitions 8.1, 8.2, and 8.3) whose computations are
viewed as random processes: For each nondeterministic guess, the machine flips an
unbiased coin and follows each of the resulting two next configurations with probabil-
ity 1/2 until a final configuration is reached. Depending on the number of accepting
computation paths of the given NPTM, one obtains a certain acceptance probability
for each input. Errors may occur. The definition of RP requires that the error prob-
ability must be below the threshold of 1/2 for an input to be accepted, and there
must occur no error at all for an input to be rejected.
Theorem 7.15 follows from the fact that, for example, the Miller-Rabin test is a
Monte Carlo algorithm for the primality problem. We present a proof sketch only. We
show that the Miller-Rabin test accepts PRIMES with one-sided error probability as in
Definition 7.14: If the given number n (represented in binary) is a prime number then
the algorithm cannot answer erroneously that n is not prime. For a contradiction,
7.3. RSA and factoring 355
suppose n is prime but the Miller-Rabin test halts with the output: n is not a prime
number. Hence, z m 6 1 mod n. Since x is squared in each iteration of the for loop,
we sequentially test the values
k1
z m , z 2m , . . . , z 2 m
modulo n. By assumption, for none of these values the algorithm says n were prime.
It follows that for each j with 0 j k 1,
j
z2 m
6 1 mod n .
k
Since n 1 = 2k m, Fermats Little Theorem (see Corollary 7.5) implies z 2 m
k1
1 mod n. Thus, z 2 m is a square roots of 1 modulo n. Since n is prime, there are
only two square roots of 1 modulo n, namely 1 mod n, see Exercise 7.3-1. Since
k1 k1 k2
z 2 m 6 1 mod n, we must have z 2 m 1 mod n. But then, z 2 m again is a
k2
square root of 1 modulo n. By the same argument, z 2 m 1 mod n. Repeating
this argument again and again, we eventually obtain z m 1 mod n, a contradiction.
It follows that the Miller-Rabin test works correctly for each prime number. On the
other hand, if n is not a prime number, it can be shown that the error probability of
the Miller-Rabin tests does not exceed the threshold of 1/4. Repeating the number
of independent trials, the error probability can be made arbitrarily close to zero, at
the cost of increasing the running time of course, which still will be polynomially in
log n, where log n is the size of the input n represented in binary.
Example 7.7[ RSA] Suppose Bob chooses the prime numbers p = 67 and q = 11. Thus,
n = 67 11 = 737, so we have (n) = (p 1)(q 1) = 66 10 = 660. If Bob now chooses the
smallest exponent possible for (n) = 660, namely e = 7, then (n, e) = (737, 7) is his public
key. Using the extended Euclidean algorithm, Bob determines his private key d = 283, and
we have e d = 7 283 = 1981 1 mod 660; see Exercise 7.3-2. As in Section 7.1, we identify
the alphabet = {A, B, . . . , Z} with the set Z26 = {0, 1, . . . , 25}. Messages are strings over
and are encoded in blocks of fixed length as natural numbers in 26-adic representation.
In our example, the block length is ` = blog26 nc = blog26 737c = 2.
More concretely, any block b = b1 b2 b` of length ` with bi Z26 is represented by
the number
X
mb = bi 26`i .
i=1
Since ` = blog26 nc, we have
X
0 mb 25 26`i = 26` 1 < n .
i=1
The RSA encryption function encrypts the block b (i.e., the corresponding number mb ) as
cb = (mb )e mod n. The ciphertext for block b then is cb = c0 c1 c` with ci Z26 . Thus,
RSA maps blocks of length ` injectively to blocks of length ` + 1. Figure 7.9 shows how to
subdivide a message of length 34 into 17 blocks of length 2 and how to encrypt the single
blocks, which are represented by numbers. For example, the first block, RS, is turned
into a number as follows: R corresponds to 17 and S to 18, and we have
17 261 + 18 260 = 442 + 18 = 460 .
356 7. Cryptology
M RS AI ST HE KE YT OP UB L I CK EY CR YP TO GR AP HY
mb 460 8 487 186 264 643 379 521 294 62 128 69 639 508 173 15 206
cb 697 387 229 340 165 223 586 5 189 600 325 262 100 689 354 665 673
The resultingP number cb is written again in 26-adic representation and can have the
`
length ` + 1: cb = i=0 ci 26`i , where ci Z26 , see also Exercise 7.3-2. So, the first block,
697 = 676 + 21 = 1 262 + 0 261 + 21 260 , is encrypted to yield the ciphertext BAV.
Decryption is also done blockwise. In order to decrypt the first block with the private
key d = 283, compute 697283 mod 737, again using fast exponentiation with Square-
and-Multiply. To prevent the numbers from becoming too large, it is recommendable to
reduce modulo n = 737 after each multiplication. The binary expansion of the exponent is
283 = 20 + 21 + 23 + 24 + 28 , and we obtain
0 1 3 4 8
697283 6972 6972 6972 6972 6972 697 126 9 81 15 460 mod 737
as desired.
either. And even if one could prove this hypothesis, this would not imply a proof
of security of RSA. Breaking RSA is at most as hard as the factoring problem;
however, the converse is not known to hold. That is, it is not known whether these
two problems are equally hard. It may be possible to break RSA without factoring n.
We omit listing potential attacks on the RSA system here. Rather, the interested
reader is pointed to the comprehensive literature on this subject; note also Problem
7-4 at the end of this chapter. We merely mention that for each of the currently
known attacks on RSA, there are suitable countermeasures, rules of thumb that ei-
ther completely prevent a certain attack or make its probability of success negligibly
small. In particular, it is important to take much care when choosing the prime
numbers p and q, the modulus n = pq, the public exponent e, and the private key d.
Finally, since the factoring attacks on RSA play a particularly central role,
we briefly sketch two such attacks. The first one is based on Pollards (p 1)
method [201]. This method is effective for composite numbers n having a prime
factor p such that the prime factors of p 1 each are small. Under this assumption,
a multiple of p 1 can be determined without knowing p. By Fermats Little
Theorem (see Corollary 7.5), it follows that a 1 mod p for all integers a coprime
with p. Hence, p divides a 1. If n does not divide a 1, then gcd(a 1, n) is a
nontrivial divisor of n. Thus, the number n can be factored.
How can the multiple of p 1 be determined? Pollards (p 1) method uses
as candidates for the products of prime powers below a suitably chosen bound S:
Y
= qk .
q is prime, q k S
If all prime powers dividing p 1 are less than S, then is a multiple of p 1. The
algorithm determines gcd(a 1, n) for a suitably chosen base a. If no nontrivial
divisor of n is found, the algorithm is restarted with a new bound S 0 > S.
Other factoring methods, such as the quadratic sieve, are described, e.g., in [213,
243]. They use the following simple idea. Suppose n is the number to be factored.
Using the sieve, determine numbers a and b such that:
Exercises
d d
7.3-1 a. Prove Theorem 7.13. Hint. Show (me ) m mod p and (me ) m mod q
using Corollary 7.5, Fermats Little Theorem. Since p and q are prime numbers
d
with p 6= q and n = pq, the claim (me ) m mod n now follows from the Chinese
remainder theorem.
b. The proof sketch of Theorem 7.15 uses the fact that any prime number n can
358 7. Cryptology
have only two square roots of 1 modulo n, namely 1 mod n. Prove this fact. Hint.
It may be helpful to note that r is a square root of 1 modulo n if and only if n
divides (r 1)(r + 1).
7.3-2 a. Let (n) = 660 and e = 7 be the values from Example 7.7. Show that the
extended Euclidean algorithm indeed provides the private key d = 283, the inverse
of 7 mod 660.
b. Consider the plaintext in Figure 7.9 from Example 7.7 and its RSA en-
cryption. Determine the encoding of this ciphertext by letters of the alphabet
= {A, B, . . . , Z} for each of the 17 blocks.
c. Decrypt each of the 17 ciphertext blocks in Figure 7.9 and show that the
original message is obtained indeed.
d. Prove that the RSA digital signature protocol from Figure 7.10 works.
infix notation xy instead of the prefix notation (x, y). This property implies that
the above protocol works:
kA = x(yz) = (xy)z = kB ,
so Alice and Bob indeed compute the same secret key.
The notion of strong noninvertibility is not to be defined formally here. Infor-
mally put, is said to be strongly noninvertible if is not only a one-way function,
but even if in addition to the function value one of the corresponding arguments
is given, it is not possible to compute the other argument efficiently. This property
implies that the attacker Erich, knowing y and xy and yz, is not able to compute
the secret numbers x and z, from which he could easily determine the secret key
kA = kB .
Exercises
7.4-1 Modify the Rivest-Sherman protocol for secret-key agreement from Fig-
ure 7.11 to a protocol for digital signatures.
7.4-2 (a. Try to give a formal definition of the notion of strong noninvertibility
that is defined only informally above. Use the worst-case complexity model.
b. Suppose is a partial function from N N to N, i.e., may be undefined for
some pairs in N N. Give a formal definition of associativity for partial functions.
What is wrong with the following (flawed) attempt of a definition: A partial function
: N N N is said to be associative if and only if x(yz) = (xy)z holds for
all x, y, z N for which each of the four pairs (x, y), (y, z), (x, yz), and (xy, z) is
in the domain of . Hint. A comprehensive discussion of these notions can be found
in [?, 107, 108].
3 Here, an individual or a party is not necessarily a human being; it may also be a computer
program that automatically executes a protocol with another computer program.
360 7. Cryptology
But then, it no longer is a secret! Bob, knowing her secret, might pretend to be Alice
in another protocol he executes with Chris, a third party. So the question is how to
prove knowledge of a secret without giving it away. This is what zero-knowledge is all
about. Zero-knowledge protocols are special interactive proof systems, which were
introduced by Goldwasser, Micali, and Rackoff and, independently, by Babai and
Moran. Babai and Morans notion (which is essentially equivalent to the interactive
proof systems proposed by Goldwasser et al.) is known as Arthur-Merlin games,
which we will now describe informally.
Merlin and Arthur wish to jointly solve a problem L, i.e., they wish to jointly
decide whether or not a given input x belongs to L. The mighty wizard Merlin is
represented by an NP machine M , and the impatient King Arthur is represented by
a randomised polynomial-time Turing machine A. To make their decision, they play
the following game, where they are taking turns to make alternating moves. Merlins
intention is always to convince Arthur that x belongs to L (no matter whether or
not that indeed is the case). Thus, each of Merlins moves consists in presenting a
proof for x L, which he obtains by simulating M (x, y), where x is the input
and y describes all previous moves in this game. That is, the string y encodes all
previous nondeterministic choices of M and all previous random choices of A.
King Arthur, however, does not trust Merlin. Of course, he cannot check the
mighty wizards proofs all alone; this task simply exceeds his computational power.
But he knows Merlin well enough to express some doubts. So, he replies with a nifty
challenge to Merlin by picking some details of his proofs at random and requiring
certificates for them that he can verify. In order to satisfy Arthur, Merlin must
convince him with overwhelming probability. Thus, each of Arthurs moves consists
in the simulation of A(x, y), where x again is the input and y describes the previous
history of the game.
The idea of Arthur-Merlin games can be captured via alternating existential
and probabilistic quantifiers, where the former formalise Merlins NP computation
and the latter formalise Arthurs randomised polynomial-time computation.4 In this
way, a hierarchy of complexity classes can be defined, the so-called Arthur-Merlin
hierarchy. We here present only the class MA from this hierarchy, which corresponds
to an Arthur-Merlin game with two moves, with Merlin moving first.
Definition 7.16 (MA in the Arthur-Merlin hierarchy). The class MA contains
exactly those problems L for which there exists an NP machine M and a randomised
polynomial-time Turing machine A such that for each input x:
If x L then there exists a path y of M (x) such that A(x, y) accepts with
probability at least 3/4 (i.e., Arthur cannot refute Merlins proof y for x L,
and Merlin thus wins).
If x 6 L then for each path y of M (x), A(x, y) rejects with probability at least
3/4 (i.e., Arthur is not taken in by Merlins wrong proofs for x L and thus
wins).
Analogously, the classes AM, MAM, AMA, . . . can be defined, see Exercise 7.5-1.
4 This is similar to the well-known characterisation of the levels of the polynomial hierarchy via
alternating and quantifiers, see Section 8.4 and in particular item 3 Theorem 8.11.
7.5. Interactive proof systems and zero-knowledge 361
NP MA AM = AMA = MAM = .
property that it does not leak any information whatsoever about Merlins secret. If
there is nothing to put in, there can be nothing to take out.
Definition 7.17 (Zero-knowledge protocol). Let L be any set in IP, and let (M, A)
be an interactive proof system for L, where M is an NPTM and A is a randomised
polynomial-time Turing machine. The IP protocol (M, A) is a zero-knowledge pro-
tocol for L if and only if there exists a randomised polynomial-time Turing machine
such that (M c, A) simulates the original protocol (M, A) and, for each x L, the
tuples (m1 , m2 , . . . , mk ) and (m
b 1, m b k ) representing the information commu-
b 2, . . . , m
nicated in (M, A) and in (M c, A), respectively, are identically distributed over the
random choices in (M, A) and in (M c, A), respectively.
Figure 7.12 Goldreich, Micali, and Wigdersons zero-knowledge protocol for GI.
It remains to show that the protocol from Figure 7.12 is a zero-knowledge proto-
col. Figure 7.13 shows a simulated protocol with Marvin who does not know Merlins
secret but pretends to know it. The information communicated in one round of
the protocol has the form of a triple: (H, b, ). If Marvin is lucky enough to choose
a random bit a with a = b, he can simply send = and wins: Arthur (or any
third party watching the communication) will not notice the fraud. On the other
hand, if a 6= b then Marvins attempt to betray will be uncovered. However, that is
no problem for the malicious wizard: He simply deletes this round from the protocol
and repeats. Thus, he can produce a sequence of triples of the form (H, b, ) that
is indistinguishable from the corresponding sequence of triples in the original proto-
col between Merlin and Arthur. It follows that Goldreich, Micali, and Wigdersons
protocol for GI is a zero-knowledge protocol.
Exercises
7.5-1 Arthur-Merlin hierarchy:
a. Analogously to MA from Definition 7.16, define the other classes AM, MAM,
AMA, . . . of the Arthur-Merlin hierarchy.
b. What is the inclusion structure between the classes MA, coMA, AM, coAM,
and the classes of the polynomial hierarchy defined in Definition 8.10 of Subsection
8.4.1.
7.5-2 Zero-knowledge protocol for graph isomorphism:
a. Consider the graphs G and H from Example 7.4 in Section 7.1.3. Execute
the zero-knowledge protocol from Figure 7.12 with the graphs G0 = G and G1 = H
and the isomorphism = (13 24 31 45 52). Use an isomorphism of your choice, and try all
possibilities for the random bits a and b. Repeat this Arthur-Merlin game with an
unknown isomorphism chosen by somebody else.
b. Modify the protocol from Figure 7.12 such that, with only one round of the
protocol, Marvins success probability is less than 225 .
Problems
that k messages ci = (ai m + bi )e mod ni are sent and are intercepted by Erich.
2
Further, suppose that k > e(e + 1)/2 and min(ni ) > 2e . How can attacker Erich
now determine the original message m?
Hint. Apply so-called lattice reduction techniques (see, e.g., Micciancio and Gold-
wasser [173]). The attack mentioned here is due to Hstad [98] and has been
strengthened later by Coppersmith [52].
c. How can the attacks described above be prevented?
Chapter Notes
Singhs book [235] gives a nice introduction to the history of cryptology, from its
ancient roots to modern cryptosystems. For example, you can find out there about
recent discoveries related to the development of RSA and Diffie-Hellman in the
nonpublic sector. Ellis, Cocks, and Williamson from the Communications Electronics
Security Group (CESG) of the British Government Communications Head Quarters
(GCHQ) proposed the RSA system from Figure 7.8 and the Diffie-Hellman protocol
from Figure 7.7 even earlier than Rivest, Shamir, and Adleman and at about the
same time as but independent of Diffie and Hellman, respectively. RSA and Diffie-
Hellman are described in probably every book about cryptography written since
their invention. A more comprehensive list of attacks against RSA than that of
Section 7.3 can be found in, e.g., [28, 130, 181, 211, 213, 228].
Primality tests such as the Miller-Rabin test and factoring algorithms are also
described in many books, e.g., in [90, 213, 217, 243].
The notion of strongly noninvertible associative one-way functions, on which
the secret-key agreement protocol from Figure 7.11 is based, is due to Rivest and
Sherman. The modification of this protocol to a digital signature scheme is due
to Rabi and Sherman. In their paper [202], they also proved that commutative,
associative one-way function exist if and only if P 6= NP. However, the one-way
functions they construct are neither total nor strongly noninvertible, even if P 6= NP
is assumed. Hemaspaandra and Rothe [108] proved that total, strongly noninvertible,
commutative, associative one-way functions exist if and only if P 6= NP. Further
investigations on this topic can be found in [27, ?, 107, 110].
The notion of interactive proof systems and zero-knowledge protocols is due
to Goldwasser, Micali, and Rackoff [91]. One of the best and most comprehensive
sources on this field is Chapter 4 in Goldreichs book [90]; see also the books [137, 192,
213] and the surveys [?, ?, 211]. Arthur-Merlin games were introduced by Babai and
Moran [19, 18] and have been investigated in many subsequent papers. Variants of
the notion of zero-knowledge, which differ from the notion in Definition 7.17 in their
technical details, are extensively discussed in, e.g., [90] and also in, e.g., [?, ?, 211].
8. Complexity Theory
In Chapter 7, efficient algorithms were introduced that are important for cryp-
tographic protocols. Designing efficient algorithms of course is a central task in all
areas of computer science. Unfortunately, many important problems have resisted
all attempts in the past to devise efficient algorithms solving them. Well-known ex-
amples of such problems are the satisfiability problem for boolean formulas and the
graph isomorphism problem.
One of the most important tasks in complexity theory is to classify such problems
according to their computational complexity. Complexity theory and algorithmics
are the two sides of the same medal; they complement each other in the following
sense. While in algorithmics one seeks to find the best upper bound for some problem,
an important goal of complexity theory is to obtain the best possible lower bound
for the same problem. If the upper and the lower bound coincide, the problem has
been classified.
The proof that some problem cannot be solved efficiently often appears to be
negative and not desirable. After all, we wish to solve our problems and we wish
to solve them fast. However, there is also some positive aspect of proving lower
bounds that, in particular, is relevant in cryptography (see Chapter 7). Here, we are
interested in the applications of inefficiency: A proof that certain problems (such
as the factoring problem or the discrete logarithm) cannot be solved efficiently can
support the security of some cryptosystems that are important in practical applica-
tions.
In Section 8.1, we provide the foundations of complexity theory. In particular,
the central complexity classes P and NP are defined. The question of whether or
not these two classes are equal is still open after more than three decades of intense
research. Up to now, neither a proof of the inequality P 6= NP (which is widely
believed) could be achieved, nor were we able to prove the equality of P and NP.
This question led to the development of the beautiful and useful theory of NP-
completeness.
One of the best understood NP-complete problems is SAT, the satisfiability prob-
lem of propositional logic: Given a boolean formula , does there exist a satisfying
assignment for , i.e., does there exist an assignment of truth values to s variables
that makes true? Due to its NP-completeness, it is very unlikely that there exist
efficient deterministic algorithms for SAT. In Section 8.3, we present a deterministic
368 8. Complexity Theory
and a randomised algorithm for SAT that both run in exponential time. Even though
these algorithms are asymptotically inefficient (which is to say that they are useless
in practice for large inputs), they are useful for sufficiently small inputs of sizes still
relevant in practice. That is, they outperform the naive deterministic exponential-
time algorithm for SAT in that they considerably increase the input size for which
the algorithms running time still is tolerable.
In Section 8.4, we come back to the graph isomorphism problem, which was
introduced in Section 7.1.3 (see Definition 7.8) and which was useful in Section 7.5.2
with regard to the zero-knowledge protocols. This problem is one of the few natural
problems in NP, which (under the plausible assumption that P 6= NP) may be
neither efficiently solvable nor be NP-complete. In this regard, this problem is special
among the problems in NP. Evidence for the hypothesis that the graph isomorphism
problem may be neither in P nor NP-complete comes from the theory of lowness,
which is introduced in Section 8.4. In particular, we present Schnings result that
GI is contained in the low hierarchy within NP. This result provides strong evidence
that GI is not NP-complete. We also show that GI is contained in the complexity
class SPP and thus is low for certain probabilistic complexity classes. Informally put,
a set is low for a complexity class C if it does not provide any useful information
when used as an oracle in C computations. For proving the lowness of GI, certain
group-theoretic algorithms are useful.
8.1. Foundations
As mentioned above, complexity theory is concerned with proving lower bounds.
The difficulty in such proofs is that it is not enough to analyse the runtime of just
one concrete algorithm for the problem considered. Rather, one needs to show that
every algorithm solving the problem has a runtime no better than the lower bound
to be proven. This includes also algorithms that have not been found as yet. Hence,
it is necessary to give a formal and mathematically precise definition of the notion
of algorithm.
Since the 1930s, a large variety of formal algorithm models has been proposed.
All these models are equivalent in the sense that each such model can be trans-
formed (via an algorithmic procedure) into any other such model. Loosely speaking,
one might consider this transformation as some sort of compilation between dis-
tinct programming languages. The equivalence of all these algorithm models justifies
Churchs thesis, which says that each such model captures precisely the somewhat
vague notion of intuitive computability. The algorithm model that is most common
in complexity theory is the Turing machine, which was introduced in 1936 by Alan
Turing (1912 until 1954) in his pathbreaking work [253]. The Turing machine is a
very simple abstract model of a computer. In what follows, we describe this model
by defining its syntax and its semantics, and introduce at the same time two basic
computation paradigms: determinism and nondeterminism. It makes sense to first
define the more general model of nondeterministic Turing machines. Deterministic
Turing machines then are easily seen to be a special case.
First, we give some technical details and describe how Turing machines work. A
8.1. Foundations 369
finite
control
input tape head
22222222 I N PU T2222222222 22
work tape head
2 S H H H ! 2 WO R K 2 I N 2 P R O G R E S S ! 2
Figure 8.1 A Turing machine with one input and two work tapes.
Turing machine has k infinite work tapes that are subdivided into cells. Every cell
may contain one letter of the work alphabet. If a cell does not contain a letter, we
indicate this by a special blank symbol, denoted by 2. The computation is done on
the work tapes. Initially, a designated input tape contains the input string, and all
other cells contain the blank. If a computation halts, its result is the string contained
in the designated output tape.1 To each tape belongs a head that accesses exactly
one cell of this tape. In each step of the computation, the head can change the
symbol currently read and then moves to the left or to the right or does not move at
all. At the same time, the current state of the machine, which is stored in its finite
control can change. Figure 8.1 displays a Turing machine with one input and two
work tapes.
Definition 8.1 (Syntax of Turing machines). A nondeterministic Turing ma-
chine with k tapes (a k-tape NTM, for short) is a 7-tuple M =
(, , Z, , z0 , 2, F ), where is the input alphabet, is the work alphabet, Z is
a finite set of states disjoint with , : Z k P(Z k {L, R, N }k ) is the
transition function, z0 Z is the initial state, 2 is the blank symbol, and
F Z is the set of final states. Here, P(S) denotes the power set of set S, i.e., the
set of all subsets of S.
For readability, we write (z, a) 7 (z 0 , b, x) instead of (z 0 , b, x) (z, a) with
z, z Z, x {L, R, N } and a, b . This transition has the following meaning. If
0
the current state is z and the head currently reads a symbol a, then:
a is replaced by b,
z 0 is the new state, and
the head moves according to x {L, R, N }, i.e., the head either moves one cell
to the left (if x = L), or one cell to the right (if x = R), or it does not move at
all (if x = N ).
The special case of a deterministic Turing machine with k tapes (k-tape DTM,
for short) is obtained by requiring that the transition function maps from Z k
to Z k {L, R, N }k .
For k = 1, we obtain the one-tape Turing machine, abbreviated simply by NTM
1 One can require, for example, that the input tape is a read-only and the output tape is a write-
only tape. Similarly, one can specify a variety of further variations of the technical details, but we
do not pursue this any further here.
370 8. Complexity Theory
and DTM, respectively. Every k-tape NTM or k-tape DTM can be simulated by
a Turing machine with only one tape, where the runtime at most doubles. Tur-
ing machines can be considered both as acceptors (which accept languages) and as
transducers (which compute functions).
KM such that
k = k0 `M k1 `M `M kt = k 0 ,
where possibly k = k0 = kt = k 0 . If k0 = z0 x is the initial configuration of M on
input x, then this sequence of configurations is a finite computation of M (x), and
we say M halts on input x. The language accepted by M is defined by
For NTMs, any configuration may be followed by more than one configuration.
Thus, they have a computation tree, whose root is labelled by the initial configuration
and whose leaves are labelled by the final configurations. Note that trees are special
graphs (recall Definition 7.8 in Section 7.1.3 and Problem 7-2), so they have vertices
and edges. The vertices of a computation tree M (x) are the configurations of M on
input x. For any two configurations k and k 0 from KM , there is exactly one directed
edge from k to k 0 if and only if k `M k 0 . A path in the computation tree of M (x) is a
sequence of configurations k0 `M k1 `M `M kt `M . The computation tree of
an NTM can have infinite paths on which never a halting configuration is reached.
For DTMs, each non-halting configuration has a unique successor configuration.
Thus, the computation tree of a DTM degenerates to a linear chain.
8.1. Foundations 371
(s0 , a)
7 (s1 , $, R) (s2 , $) 7 (s2 , $, R) (s5 , c)
7 (s5 , c, L)
(s1 , a) 7 (s1 , a, R) (s3 , c) 7 (s3 , c, R) (s5 , $) 7 (s5 , $, L)
(s1 , b) 7 (s2 , $, R) (s3 , 2) 7 (s4 , 2, L) (s5 , b)
7 (s5 , b, L)
(s1 $) 7 (s1 , $, R) (s4 , $) 7 (s4 , $, L) (s5 , a) 7 (s5 , a, L)
(s2 , b) 7 (s2 , b, R) (s4 , 2) 7 (s6 , 2, R) (s5 , 2) 7 (s0 , 2, R)
(s2 , c) 7 (s3 , $, R) (s4 , c) 7 (s5 , c, L) (s0 , $) 7 (s0 , $, R)
Z Meaning Intention
s0 initial state start next cycle
s1 one a stored look for next b
s2 one a and one b stored look for next c
s3 one a, one b, and one c deleted look for right boundary
s4 right boundary reached move back and test if all a, b, and c are deleted
s5 test not successful move back and start next cycle
s6 test successful accept
Example 8.1 Consider the language L = {an bn cn | n 1}. A Turing machine accepting
L is given by
where the transitions of are stated in Figure 8.2. Figure 8.3 provides the meaning of the
single states of M and the intention corresponding to the each state. See also Exercise
8.1-2.
Let M be an NTM with L(M ) and let x be an input. Define the time
function of M (x), which maps from to N, as follows:
min{TimeM (x, ) | M (x) accepts on path } if x L(M )
NTimeM (x) =
undefined otherwise .
Let IPol be the set of all polynomials. Define the complexity classes P and NP as
follows:
[ [
P= DTIME(t) and NP = NTIME(t) .
tIPol tIPol
t(n) n = 10 n = 20 n = 30 n = 40 n = 50 n = 60
n .00001 sec .00002 sec .00003 sec .00004 sec .00005 sec .00006 sec
n2 .0001 sec .0004 sec .0009 sec .0016 sec .0025 sec .0036 sec
n3 .001 sec .008 sec .027 sec .064 sec .125 sec .256 sec
n5 .1 sec 3.2 sec 24.3 sec 1.7 min 5.2 min 13.0 min
2n .001 sec 1.0 sec 17.9 min 12.7 days 35.7 years 366 cent.
3n .059 sec 58 min 6.5 years 3855 cent. 2 108 cent. 1.3 1013 cent.
are? For functions ti (n), 1 i 6, let Ni be the maximum size of inputs that can
be solved by a ti (n) time-bounded algorithm within one hour. Figure 8.5 also taken
from [80]) shows that a computer 1000 times faster than todays computers increases
N5 for t5 (n) = 2n by only an additive value close to 10. In contrast, using computers
with the same increase in speed, an n5 time-bounded algorithm can handle problem
instances about four times as large as before.
Intuitively, the complexity class P contains the efficiently solvable problems.
The complexity class NP contains many problems important in practice but cur-
rently not efficiently solvable. Examples are the satisfiability problem and the graph
isomorphism problem that will be dealt with in more detail later in this chapter.
The question of whether or not the classes P and NP are equal is still open. This
famous P-versus-NP question gave rise to the theory of NP-completeness, which is
briefly introduced in Section 8.2.
Exercises
8.1-1 Can Churchs thesis ever be proven formally?
8.1-2 Consider the Turing machine M in Example 8.1.
a. What are the sequences of configurations of M for inputs x = a3 b3 c2 and
y = a3 b3 c3 , respectively?
b. Prove that M is correct, i.e., show that L(M ) = {an bn cn | n 1}.
c. Estimate the running time of M .
d. Show that the graph isomorphism problem and the graph automorphism
problem introduced in Definition 7.8 are both in NP.
374 8. Complexity Theory
8.2. NP-completeness
The theory of NP-completeness provides methods to prove lower bounds for problems
in NP. An NP problem is said to be complete in NP if it belongs to the hardest
problems in this class, i.e., if it is at least as hard as any NP problem. The complexity
of two given problems can be compared by polynomial-time reductions. Among the
different types of reduction one can consider, we focus on the polynomial-time many-
one reducibility in this section. In Section 8.4, more general reducibilities will be
introduced, such as the polynomial-time Turing reducibility and the polynomial-time
(strong) nondeterministic Turing reducibility.
Reductions are efficient algorithms that can be used to show that problems are
not efficiently solvable. That is, if one can efficiently transform a hard problem into
another problem via a reduction, the hardness of the former problem is inherited
by the latter problem. At first glance, it might seem that infinitely many efficient
algorithms are required to prove some problem X NP-hard, namely one reduction
from each of the infinitely many NP problems to X. However, an elementary result
says that it is enough to find just one such reduction, from some NP-complete
problem V . Since the pm -reducibility is transitive (see Exercise 8.2-2), the NP-
hardness of V implies the NP-hardness of X via the reduction A pm V pm X for
each NP problem A.
In 1971, Stephen Cook found a first such NP-complete problem: the satisfiability
problem of propositional logic, SAT for short. For many NP-completeness result, it
is useful to start from the special problem 3-SAT, the restriction of the satisfiability
problem in which each given Boolean formula is in conjunctive normal form and
each clause contains exactly three literals. 3-SAT is also NP-complete.
Definition 8.5 (Satisfiability problem). The Boolean constants false and true are
represented by 0 and 1. Let x1 , x2 , . . . , xm be Boolean variables, i.e., xi {0, 1}
for each i. Variables and their negations are called literals. A Boolean formula is
satisfiable if and only if there is an assignment to the variables in that makes the
formula true. A Boolean formula is in conjunctive normal form (CNF, for short)
Vn Wki
if and only if is of the form (x1 , x2 , . . . , xm ) = i=1 j=1 `i,j , where the `i,j
W ki
are literals over {x1 , x2 , . . . , xm }. The disjunctions j=1 `i,j of literals are called the
clauses of . A Boolean formula is in k-CNF if and only if is in CNF and each
clause of contains exactly k literals. Define the following two problems:
Example 8.2[Boolean formulas] Consider the following two satisfiable Boolean formulas
(see also Exercise 8.2-1):
(w, x, y, z) = (x y z) (x y z) (w y z) (w x z);
(w, x, y, z) = (w x y z) (x y z) (w y z) (w x z) .
Here, is in 3-CNF, so is in 3-SAT. However, is not in 3-CNF, since the first clause
contains four literals. Thus, is in SAT but not in 3-SAT.
Theorem 8.6 (Cook). The problems SAT and 3-SAT are NP-complete.
The proof that SAT is NP-complete is omitted. The idea is to encode the com-
putation of an arbitrary NP machine M running on input x into a Boolean formula
M,x such that M,x is satisfiable if and only if M accepts x.
SAT is a good starting point for many other NP-completeness results. In fact, in
many cases it is very useful to start with its restriction 3-SAT. To give an idea of
how such proofs work, we now show that SAT pm 3-SAT, which implies that 3-SAT is
NP-complete. To this end, we need to find a reduction r that transforms any given
Boolean formula in CNF into another Boolean formula b in 3-CNF (i.e., with
exactly three literals per clause) such that
is satisfiable b is satisfiable .
(8.1)
bj = (z1 z2 y j ) (z1 z2 y j ).
If k = 2, define C 1 1
b
If k = 3, define Cj = Cj = (z1 z2 z3 ), i.e., the jth clause remains unchanged.
If k 4, define
bj
C = (z1 z2 y1j ) (y1j z3 y2j ) (y2j z4 y3j )
j j j
(yk4 zk2 yk3 ) (yk3 zk1 zk ) .
Exercises
8.2-1 Find a satisfying assignment each for the Boolean formulas and from
Example 8.2.
8.2-2 Show that the pm -reducibility is transitive: (A pm B B pm C) =
A pm C.
8.2-3 Prove that SAT is in NP.
8.2-4 Consider the reduction SAT pm 3-SAT. Prove the following:
a. the reduction r is polynomial-time computable, and
b. the equivalence (8.1) holds.
2 The result presented here is not the best result known, but see Figure 8.7 on page 395 for further
improvements.
8.3. Algorithms for the satisfiability problem 377
Backtracking-SAT(, )
1 if ( assigns truth values to all variables of )
2 then return ()
3 else if ( makes one of the clauses of false)
4 then return 0
5 dead branch
6 else if Backtracking-SAT(, 0))
7 then return 1
8 else return Backtracking-SAT(, 1))
3 The inner vertices of the recursion tree represent the recursive calls of the algorithm, its root is
the first call, and the algorithm terminates at the leaves without any further recursive call.
378 8. Complexity Theory
the worst case, we do not consider these additional dead subtrees. It follows that
n n
O 23 1 3 = O( 7 ) O(1.9129n )
3
is an upper bound for Backtracking-SAT in the worst case. This bound slightly
improves upon the trivial O(2n ) upper bound of the naive algorithm for 3-SAT.
As mentioned above, the deterministic time complexity of 3-SAT can be improved
even further. For example, Monien and Speckenmeyer [180] proposed a divide-and-
conquer algorithm with runtime O(1.618n ). Dantsin et al. [58] designed a determin-
istic local search with restart algorithm whose runtime is O(1.481n ), which was
further improved by Brueggemann and Kern [33] in 2004 to a O(1.4726n ) bound.
There are also randomised algorithms that have an even better runtime. One
will be presented now, a random-walk algorithm that is due to Schning [222].
Random-SAT()
n
1 for i 1 to d(4/3) e)
n is the number of variables in
2 do randomly choose an assignment {0, 1}n
under the uniform distribution
8.3. Algorithms for the satisfiability problem 379
s
1 6 15 20 15 6 1
64 64 64 64 64 64 64
2 2 2 2 2
3 3 3 3 3
2
1 0 1
1 2 3 4 5 6 3
3 1 1 1 1 1
3 3 3 3 3
Figure 8.6 Transition graph of a stochastic automaton for describing Random-SAT.
3 for j 1 to n
4 if (() = 1)
5 then return the satisfying assignment to
6 else choose a clause C = (x y z) with C() = 0
7 randomly choose a literal ` {x, y, z}
under the uniform distribution
8 determine the bit ` {0, 1} in assigning `
9 swap ` to 1 ` in
10 return is not satisfiable
Now, let qi be the probability for the event that Random-SAT() reaches some
state i n/3 with the initial step. Clearly, we have
n
qi = 2n . (8.3)
i
8.4. Graph isomorphism and lowness 381
Finally, let p be the probability for the event that Random-SAT() reaches the
final state 0 within the inner for loop. Of course, this event can occur also when
starting from a state j > n/3. Thus,
n/3
X
p pi q i .
i=0
Approximating this sum by the entropy function and estimating the binomial
coefficients from (8.2) and (8.3) in the single terms by Stirlings formula, we obtain
n
the lower bound ((3/4) ) for p.
To reduce the error probability, Random-SAT performs a total of t independent
trials, each starting with a new initial assignment . For each trial, the probability of
success (i.e., the probability of finding a satisfying assignment of , if one exists) is at
n n
least (3/4) , so the error is bounded by 1 (3/4) . Since the trials are independent,
n t
these error probabilities multiply, which gives an error of (1 (3/4) ) e1 . Thus,
the total probabilitiy of success of Random-SAT() is at least 1 1/e 0.632 if
is satisfiable. On the other hand, Random-SAT() does not make any error at all
if is unsatisfiable; in this case, the output is : is not satisfiable.
The particular choice of this value of t can be explained as follows. The runtime
of a randomised algorithm, which performs independent trials such as Random-
n
SAT(), is roughly reciprocal to the success probability of one trial, p (3/4) .
In particular, the error probability (i.e., the probability that that in none of the
t trials a satisfying assignment of is found even though is satisfiable) can be
estimated by (1 p)t etp . If a fixed error of is to be not exceeded, it is enough
to choose t such that etp ; equivalently, such that t ln(1/)/p. Up to constant
n
factors, this can be accomplished by choosing t = d(4/3) e. Hence, the runtime of
the algorithm is in O ((4/3)n ).
Exercises
8.3-1 Start the algorithm Backtracking-SAT for the Boolean formula = (x
y z) (x y z) (u y z) (u y z) and construct step by step a
satisfying assignment of . How does the resulting recursion tree look like?
Theorem 8.7 (Ladner). If P 6= NP then there exist sets in NP that are neither in
P nor NP-complete.
The problems constructed in the proof of Theorem 8.7 are not overly natural
problems. However, there are also good candidates of natural problems that are
neither in P nor NP-complete. One such candidate is the graph isomorphism prob-
lem. To provide some evidence for this claim, we now define two hierarchies of com-
plexity classes, the low hierarchy and the high hierarchy, both introduced by Schn-
ing [220]. First, we need to define the polynomial hierarchy, which builds upon NP.
And to this end, we need a more flexible reducibility than the (polynomial-time)
many-one reducibility pm from Definition 8.4, namely the Turing reducibility pT .
We will also define the (polynomial-time) nondeterministic Turing reducibility, NP
T ,
and the (polynomial-time) strong nondeterministic Turing reducibility, NP sT . These
two reducibilities are important for the polynomial hierarchy and for the high hi-
erarchy, respectively. Turing reducibilities are based on the notion of oracle Turing
machines, which we now define.
For the empty oracle set , we obtain the unrelativized classes NP = NP and P =
P , and we then write NPTM instead of NPOTM and DPTM instead of DPOTM.
In particular, oracle Turing machines can be used for prefix search. Let us con-
sider an example.
Note that, for n 1, the empty string does not encode a permutation in Sn . Furthermore,
Iso(G, H) = if and only if (G, H, ) 6 Pre-Iso, which in turn is true if and only if
(G, H) 6 GI.
Starting from the empty string, we will construct, bit by bit, the smallest isomorphism
between the two given graphs (if there exists any). We below present an DPOTM N that,
using the NP set Pre-Iso as its oracle, computes the function f by prefix search; see also
Exercise 8.4-2. Denoting the class of functions computable in polynomial time by FP, we
thus have shown that f is in FPPre-Iso . Since Pre-Iso is in NP (see Exercise 8.4-2), it follows
that f is in FPNP .
384 8. Complexity Theory
N-Pre-Iso(G, H)
1 if ((G, H, ) 6 Pre-Iso)
2 then return
3 else
4 j0
5 while j < n G and H have n vertices each.
6 do i 1
7 while (G, H, i) 6 Pre-Iso
8 do i i + 1
9 i
10 j j+1
11 return
Example 8.3 shows that also Turing machines computing functions can be
equipped with an oracle, and that also function classes such as FP can be rela-
tivizable. We now return to oracle machines accepting languages and use them to
define several reducibilities. All reducibilities considered here are polynomial-time
computable.
Definition 8.9 (Turing reducibilities). Let = {0, 1} be a binary alphabet, let
A and B be sets of strings over , and let C be any complexity class. The set of
complements of sets in C is defined by coC = {L | L C}.
Define the following reducibilities:
Turing reducibility: A pT B A = L(M B ) for some DPOTM M.
Nondeterministic Turing reducibility: A NP T B A = L(M ) for
B
some NPOTM M.
B
Strong nondeterministic Turing reducibility: A NP sT B A NP
B
coNP .
Let r be one of the reducibilities defined above. We call a set B r -hard for C
if and only if A r B for each set A C. A set B is said to be r -complete in
C if and only if B is r -hard for C and B C.
PC = {A | (B C) [A pT B]} is the closure of C under the pT -reducibility.
NPC = {A | (B C) [A NP NP
T B]} is the closure of C under the T -
reducibility.
Definition 8.12 (Low hierarchy and high hierarchy within NP). For k 0, de-
fine the kth level of the
S
low hierarchy LH = k0 Lowk in NP by Lowk = {L NP | p,L k pk };
S
high hierarchy HH = k0 Highk in NP by Highk = {H NP | pk+1 p,H k }.
Definition 8.14 (Hashing). Let = {0, 1}, and let m and t be positive integers
with t > m. A hash function h : t m is a linear mapping determined by a
Boolean tm matrix Bh = (bi,j )i,j , where bi,j {0, 1}. For x t and 1 j m,
8.4. Graph isomorphism and lowness 387
b | (v V ) (h H)
C(V ) = {H b (x V ) [v 6= x h(v) = h(x)]}
In Section 7.5, the Arthur-Merlin hierarchy has been defined, and it was men-
tioned that this hierarchy collapses to its second level. Here, we are interested in the
class coAM, cf. Definition 7.16 in Subsection 7.5.1.
Proof By Theorem 8.13, every NP coAM set is in Low2 . Thus, to prove that GI
in Low2 , it is enough to show that GI is in coAM. Let G and H be two graphs with
n vertices each. We wish to apply Lemma 8.15. A first idea is to use
as the set V from that lemma. By Lemma 7.11, we have |A(G, H)| = n! if G
= H,
and |A(G, H)| = 2n! if G =
6 H.
The coAM machine we wish to construct for GI is polynomial-time bounded.
388 8. Complexity Theory
Thus, the parameters t and m from the hashing lemma must be polynomial in n.
So, to apply Lemma 8.15, we would have to choose a polynomial m = m(n) such
that
n! 2m1 < (m + 1)2m < 2n! . (8.4)
This would guarantee that the set V = A(G, H) would be large enough to tell
two isomorphic graphs G and H apart from two nonisomorphic graphs G and H.
Unfortunately, it is not possible to find a polynomial m that satisfies (8.4). Thus, we
define a different set V , which yields a gap large enough to distinguish isomorphic
graphs from nonisomorphic graphs.
Define V = A(G, H)n = A(G, H) A(G, H) A(G, H). Now, (8.4)
| {z }
n times
changes to
(n!)n 2m1 < (m + 1)2m < (2n!)n , (8.5)
and this inequality can be satisfied by choosing m = m(n) = 1 + dn log n!e, which is
polynomially in n as desired.
Construct a coAM machine M for GI as follows. Given the graphs G and H
each having n vertices, M first computes the parameter m. The set V = A(G, H)n
contains n-tuples of pairs each having the form (F, ), where F is a graph with n
vertices, and where is a permutation in the automorphism group Aut(F ). The
elements of V can be suitably encoded as strings over the alphabet = {0, 1}, for a
suitable polynomial t = t(n). All computations performed so far are deterministic.
Then, M performs Arthurs probabilistic move by randomly choosing a family
Hb = (h1 , h2 , . . . , hm+1 ) of hash functions from Ht,m under the uniform distribution.
Each hash function hi H b is represented by a Boolean tm matrix. Thus, the m+1
b
hash functions hi in H can be represented as a string zH b of length p(n) for a
suitable polynomial p. Modify the collision predicate C(V ) defined in the hashing
lemma as follows:
B = {(G, H, zH
b ) | (v V ) (i : 1 i m + 1) (x V ) [v 6= x hi (v) = hi (x)]} .
Note that the quantifier in B ranges over only polynomially many i and can thus
be evaluated in deterministic polynomial time. It follows that the two quantifiers
in B can be merged into a single polynomially length-bounded quantifier. By
Theorem 8.11, B is a set in p1 = NP. Let N be an NPTM for B. For the string zH b
that encodes m+1 randomly picked hash functions from Ht,m , M now simulates the
computation of N (G, H, zHb ). This corresponds to Merlins move. Finally, M accepts
its input (G, H) if and only if N (G, H, zH
b ) accepts.
We now estimate the probability (taken over the random choice of the hash
functions in zHb that M accepts its input (G, H). If G and H isomorphic, then
|A(G, H)| = n! by Lemma 7.11. Inequality (8.5) implies |V | = (n!)n 2m1 . By
Lemma 8.15, the probability that (G, H, zH b ) is in B (and that M (G, H) thus ac-
cepts) is at most 1/4. However, if G and H are nonisomorphic, Lemma 7.11 implies
that |A(G, H)| = 2n!. Inequality (8.5) now gives |V | = (2n!)n > (m + 1)2m . By
Lemma 8.15, the probability that (G, H, zHb ) is in B and M (G, H) thus accepts is 1.
It follows that GI is in coAM as desired.
8.4. Graph isomorphism and lowness 389
Proof We now state our algorithm LERC for computing the lexicographically small-
est permutation in the right coset G of G in Sn , where the permutation group G
is given by a generator G, see Definition 7.6 in Subsection 7.1.3.
LERC(G, )
1 compute the tower G(n) G(n1) G(1) G(0) of stabilisers in G
2 0
3 for i 0 to n 1
4 do x i + 1
5 compute the element y in the orbit G(i) (x) for which i (y)
is minimum
6 compute a permutation i in G(i) such that i (x) = y
7 i+1 i i
8 return n
Theorem 8.19 can easily be extended to Corollary 8.20, see Exercise 8-3.
Corollary 8.20 Let G Sn be a permutation group with G = hGi, and let and
be two given permutations in Sn . There exists a polynomial-time algorithm that,
given (G, , ), computes the lexicographically smallest permutation of G.
Proof Define the (functional) problem AUTO as follows: Given a graph G, compute
a strong generator of the automorphism group Aut(G); see Definition 7.6 and the
subsequent paragraph and Definition 7.8 for these notions. By Mathons [170] result,
the problems AUTO and GI are Turing-equivalent (see also [136]), i.e., AUTO is in FPGI
and GI is in PAUTO . Thus, it is enough to show that AUTO is in FPSPP because the self-
lowness of SPP stated in Theorem 8.18 implies that GI is in PAUTO SPPSPP SPP,
which will complete the proof.
So, our goal is to find an FPSPP algorithm for AUTO. Given a graph G, this
Sn1
algorithm has to compute a strong generator S = i=1 Ti for Aut(G), where
N(G, S, i, j, )
1 verify that S Aut(G)(i)
2 nondeterministically guess a permutation Sn ; // G has n vertices
3 if Aut(G)(i1) and (i) = j and extends and = LERC(S, )
4 then accept and halt
5 else reject and halt
Thus, A is in NP. Note that if (i) = j then (i) = j, for each permutation in
the right coset hSi .
We now show that if hSi = Aut(G)(i) then the number of accepting computation
paths of N on input (G, S, i, j, ) is either 0 or 1. In general, accN (G, S, i, j, )
0, |Aut(G)(i) |/|hSi| .
Suppose (G, S, i, j, ) is in A and hSi = Aut(G)(i) . If (i) = j for some
Aut(G)(i1) and j > i, then the right coset hSi contains exactly those permu-
tations in Aut(G)(i1) that map i to j. Thus, the only accepting computation path
of N (G, S, i, j, ) corresponds to the unique lexicographically smallest permutation
= LERC(S, ). If, on the other hand, hSi is a strict subgroup of Aut(G)(i) , then
Aut(G)(i) can be written as the disjoint union of k = |Aut(G)(i) |/|hSi| right cosets
of hSi. In general, N (G, S, i, j, ) thus possesses k accepting computation paths if
(G, S, i, j, ) is in A, and otherwise it has no accepting computation path.
M-A(G)
1 set Ti := {id} for each i, 0 i n 2; // G has n vertices
Ti will be a complete right transversal of Aut(G)(i+1) in Aut(G)(i) .
3 set Si := for each i, 0 i n 2
4 set Sn1 := {id}
Si will be a strong generator for Aut(G)(i) .
5 for i n 1 downto 1
Si is already found at the start
of the ith iteration, and Si1 will now be computed.
6 do let : [i 1] [n] be the partial permutation
with (a) = a for each a [i 1]
7 For i = 1, is the nowhere defined partial permutation.
8 for j i + 1 to n
9 do := j, i.e., extends by the pair (i, j) with (i) = j
10 if ((G, Si , i, j, ) A) {
11 then Construct the smallest permutation
in Aut(G)(i1) mapping i to j by prefix search.
12 for k i + 1 to n
13 do find the element ` not in the image
of with (G, Si , i, j, `) A
14 := `
15 Now, is a total permutation in Sn
8.4. Graph isomorphism and lowness 393
The above algorithm is an FPA algorithm M A for AUTO. The DPOTM M makes
only queries q = (G, Si , i, j, ) to its oracle A for which hSi i = Aut(G)(i) . Thus,
accN (q) 1 for each query q actually asked. By item 4 of Theorem 8.18, it follows
that AUTO is in FPSPP .
The claim that the output S0 of M A (G) indeed is a strong generator for
Aut(G) = Aut(G)(0) can be shown by induction on n. The induction base is n 1,
and Sn1 = {id} of course generates Aut(G)(n1) = id.
For the induction step, assume that prior to the ith iteration a strong generator
Si for Aut(G)(i) has already been found. We now show that after the ith iteration
the set Si1 = Si Ti1 is a strong generator for Aut(G)(i1) . For each j with i+1
j n, the oracle query (G, Si , i, j, ) A? checks whether there is a permutation
in Aut(G)(i1) mapping i to j. By prefix search, which is performed by making
suitable oracle queries to A again, the lexicographically smallest permutation in
Aut(G)(i1) with (i) = j is constructed. Note that, as claimed above, only queries
q satisfying accN (q) 1 are made to A, since Si is a strong generator for Aut(G)(i) ,
so hSi i = Aut(G)(i) . By construction, after the ith iteration, Ti1 is a complete right
transversal of Aut(G)(i) in Aut(G)(i1) . It follows that Si1 = Si Ti1 is a strong
generator for Aut(G)(i1) . Eventually, after n iterations, a strong generator S0 for
Aut(G) = Aut(G)(0) is found.
From Theorem 8.21 and the first two items of Theorem 8.18, we obtain Corol-
lary 8.22.
Corollary 8.22 GI is low for both SPP and PP, i.e., SPPGI = SPP and PPGI =
PP.
Exercises
8.4-1 By Definition 8.9, A pT B if and only if A PB . Show that A pT B if and
only if PA PB .
8.4-2 Show that the set Pre-Iso defined in Example 8.3 is in NP. Moreover, prove
that the machine N defined in Example 8.3 runs in polynomial time, i.e., show that
N is a DPOTM.
394 8. Complexity Theory
Problems
Chapter Notes
Parts of the Chapters 7 and 8 are based on the book [213] that provides the proofs
omitted here, such as those of Theorems 8.11, 8.13, and 8.18 and of Lemma 8.15,
and many more details.
More background on complexity theory can be found in the books [106, 192, ?, ?].
A valuable source on the theory of NP-completeness is still the classic [80] by
Garey and Johnson. The pT -reducibility was introduced by Cook [50], and the
pm -reducibility by Karp [134]. A deep and profound study of polynomial-time re-
ducibilities is due to Ladner, Lynch, and Selman [151].
Exercise 8-1 and Problem 8-1 are due to Selman [225].
Dantsin et al. [58] obtained an upper bound of O(1.481n ) for the determin-
istic time complexity of 3-SAT, which was further improved by Brueggemann and
Kern [33] to O(1.4726n ). The randomised algorithm presented in Subsection 8.3.2 is
due to Schning [222]; it is based on a limited local search with restart. For k-SAT
with k 4, the algorithm by Paturi et al. [194] is slightly better than Schnings
algorithm. Iwama and Tamaki [125] combined the ideas of Schning [222] and Paturi
et al. [194] to obtain a bound of O(1.324n ) for k-SAT with k {3, 4}. For k-SAT with
k 5, their algorithm is not better than that by Paturi et al. [194].
Figure 8.7 gives an overview over some algorithms for the satisfiability problem.
For a thorough, comprehensive treatment of the graph isomorphism problem
the reader is referred to the book by Kbler, Schning, and Torn [137], particu-
larly under complexity-theoretic aspects. Hoffman [109] investigates group-theoretic
algorithms for the graph isomorphism problem and related problems.
Algorithm Type 3-SAT 4-SAT 5-SAT 6-SAT
Backtracking det. O(1.913n ) O(1.968n ) O(1.987n ) O(1.995n )
Monien and det. O(1.618n ) O(1.839n ) O(1.928n ) O(1.966n )
Speckenmeyer [180]
Dantsin et al. [58] det. O(1.481n ) O(1.6n ) O(1.667n ) O(1.75n )
Brueggemann and Kern [33] det. O(1.4726n )
Paturi et al. [194] prob. O(1.362n ) O(1.476n ) O(1.569n ) O(1.637n )
Schning [222] prob. O(1.334n ) O(1.5n ) O(1.6n ) O(1.667n )
Iwama and Tamaki [125] prob. O(1.324n ) O(1.474n )
The polynomial hierarchy was introduced by Meyer and Stockmeyer [172, 244].
In particular, Theorem 8.11 is due to them. Schning [220] introduced the low hier-
archy and the high hierarchy within NP. The results stated in Theorem 8.13 are due
to him [220]. He also proved that GI is in Low2 , see [221]. Kbler et al. [135, 136]
obtained the first lowness results of GI for probabilistic classes such as PP. These
results were improved by Arvind and Kurur [12] who proved that GI is even in SPP.
The class SPP generalises Valiants class UP, see [255]. So-called promise classes
such as UP and SPP have been thoroughly studied in a number of papers; see, e.g.,
[12, 29, 70, 135, 136, 204, 212]. Lemma 8.15 is due to Carter and Wegman [40].
The author is grateful to Uwe Schning for his helpful comments on an earlier
version of this chapter and for sending the slides of one of this talks that helped sim-
plifying the probability analysis for the algorithm Random-SAT sketched in Sub-
section 8.3; a more comprehensive analysis can be found in Schnings book [223].
Thanks are also due to Dietrich Stoyan, Robert Stoyan, Sigurd Assing, Gbor Erd-
lyi and Holger Spakowski for proofreading previous versions of Chapters 7 and 8.
This work was supported in part by the Deutsche Forschungsgemeinschaft (DFG)
under grants RO 1202/9-1 and RO 1202/9-3 and by the Alexander von Humboldt
Foundation in the TransCoop program.
III. NUMERICAL METHODS
9. Competitive Analysis
In on-line computation an algorithm must make its decisions based only on past
events without secure information on future. Such methods are called on-line al-
gorithms. On-line algorithms have many applications in different areas such as
computer science, economics and operations research.
The first results in this area appeared around 1970, and later since 1990 more
and more researchers have started to work on problems related to on-line algorithms.
Many subfields have been developed and investigated. Nowadays new results of the
area have been presented on the most important conferences about algorithms. This
chapter does not give a detailed overview about the results, because it is not possible
in this framework. The goal of the chapter is to show some of the main methods of
analysing and developing on-line algorithms by presenting some subareas in more
details.
In the next section we define the basic notions used in the analysis of on-line
algorithms. After giving the most important definitions we present one of the best-
known on-line problemsthe on-line k-server problemand some of the related
results. Then we deal with a new area by presenting on-line problems belonging
to computer networks. In the next section the on-line bin packing problem and its
multidimensional generalisations are presented. Finally in the last section of this
chapter we show some basic results concerning the area of on-line scheduling.
objective function value achieved by the algorithm is a random variable, and the
expected value of this variable is used in the definition of the competitive ratio.
Since we consider only deterministic on-line algorithms in this chapter, we do not
detail the notions related to randomised on-line algorithms.
In the k-server problem a metric space is given, and there are k servers which
can move in the space. The decision maker has to satisfy a list of requests appearing
at the points of the metric space by sending a server to the point where the request
appears.
The problem is on-line which means that the requests arrive one by one, and we
must satisfy each request without any information about the further requests. The
goal is to minimise the total distance travelled by the servers. In the remaining parts
of the section the multiset which contains the points where the servers are is called
the configuration of the servers. We use multisets, since different servers can be
at the same points of the space.
The first important results for the k-server problem were achieved by Manasse,
McGeoch and Sleator. They developed the following algorithm called Balance,
which we denote by BAL. During the procedure the servers are in different points.
The algorithm stores for each server the total distance travelled by the server. The
servers and the points in the space where the servers are located are denoted by
s1 , . . . , sk . Let the total distance travelled by the server si be Di . After the arrival of
a request at point P algorithm BAL uses server i for which the value Di + d(si , P )
is minimal. This means that the algorithm tries to balance the distances travelled by
the servers. Therefore the algorithm maintains server configuration S = {s1 , . . . , sk }
and the distances travelled by the servers which distances have starting values D1 =
= Dk = 0. The behaviour of the algorithm on input I = P1 , . . . , Pn can be given
by the following pseudocode:
400 9. Competitive Analysis
BAL(I)
1 for j 1 to n
2 do i argmin{Di + d(si , Pj )}
3 serve the request with server i
4 Di Di + d(si , Pj )
5 si Pj
Example 9.1 Consider the two dimensional Euclidean space as the metric space. The
points
p are two dimensional real vectors (x, y), and the distance between (a, b) and (c, d) is
(a c)2 + (b d)2 . Suppose that there are two servers which are located at points (0, 0)
and (1, 1) at the beginning. Therefore at the beginning D1 = D2 = 0, s1 = (0, 0), s2 =(1, 1).
Suppose that the first request appears at point (1, 4). Then D1 + d((0, 0), (1, 4)) = 17 >
D2 + d((1, 1), (1, 4)) = 3, thus the second server is used to satisfy the request and after the
action of the server D1 = 0, D2 = 3, s1 = (0, 0), s2 = (1, 4). Suppose that the second request
appears at point (2, 4), so D1 +d((0, 0), (2, 4)) = 20 > D2 +d((1, 4), (2, 4)) = 3+1 = 4, thus
again the second server is used, and after serving the request D1 = 0, D2 = 4, s1 = (0, 0),
s2 = (2, 4). Suppose that the third request appears at point (1, 4), so D1 + d((0, 0), (1, 4)) =
17 < D2 + d((2,
4), (1, 4)) = 4 + 1 = 5, thus the first server is used, and after serving the
request D1 = 17, D2 = 4, s1 = (1, 4), s2 = (2, 4).
Theorem 9.1 Algorithm Balance is weakly k-competitive for the metric spaces
containing k + 1 points.
The following statement shows that there is no on-line algorithm which is better
than k-competitive for the general k-server problem.
where Qn+1 denotes the point from which the server was sent to serve Qn . (This
is the point where the (n + 1)-th request would appear.) Now consider the cost
9.2. The k-server problem 401
OPT(I). Instead of calculating the optimal off-line cost we define k different off-line
algorithms, and we use the mean of the costs resulting from these algorithms. Since
the cost of each off-line algorithm is at least as much as the optimal off-line cost,
the calculated mean is an upper bound for the optimal off-line cost.
We define the following k off-line algorithms, denoted by OFF1 , . . . , OFFk . Sup-
pose that the servers are at points P1 , P2 , . . . , Pj1 , Pj+1 , . . . Pk+1 in the starting
configuration of OFFj . We can move the servers into this starting configuration
using an extra constant cost Cj .
The algorithms satisfy the requests as follows. If an algorithm OFFj has a server
at point Qi , then none of the servers moves. Otherwise the request is served by the
server located at point Qi1 . The algorithms are well-defined, if Qi does not contain
a server, then each of the other points P1 , P2 , . . . , Pk+1 contains a server, thus there is
a server located at Qi1 . Moreover Q1 = Pk+1 , thus at the beginning each algorithm
has a server at the requested point.
We show that the servers of algorithms OFF1 , . . . , OFFk are always in different
configurations. At the beginning this property is valid because of the definition of
the algorithms. Now consider the step where a request is served. Call the algorithms
which do not move a server for serving the request stable, and the other algorithms
unstable. The server configurations of the stable algorithms remain unchanged, so
these configurations remain different from each other. Each unstable algorithm moves
a server from point Qi1 . This point is the place of the last request, thus the stable
algorithms have server at it. Therefore, an unstable algorithm and a stable algorithm
cannot have the same configuration after serving the request. Furthermore, each
unstable algorithms moves a server from Qi1 to Qi , thus the server configurations
of the unstable algorithms remain different from each other.
So at the arrival of the request at point Qi the servers of the algorithms are in
different configurations. On the other hand, each configuration has a server at point
Qi1 , therefore there is only one configuration where there is no server located at
point Qi . Consequently, the cost of serving Qi is d(Qi1 , Qi ) for one of the algorithms
and 0 for the other algorithms.
Therefore
k
X n
X
OFFj (I) = C + d(Qi , Qi1 ) ,
j=1 i=2
Pk
where C = j=1 Cj is an absolute constant which is independent of the input
(this is the cost of moving the servers to the starting configuration of the defined
algorithms).
On the other hand, the optimal off-line cost cannotPbe larger than the cost of
k
any of the above defined algorithms, thus k OPT(I) j=1 OFFj (I). This yields
n
X
k OPT(I) C + d(Qi , Qi1 ) C + ONL(I) ,
i=2
which inequality shows that the weak competitive ratio of ONL cannot be smaller
than k, since the value OPT(I) can be arbitrarily large as the length of the input
402 9. Competitive Analysis
is increasing.
There are many interesting results in connection with this problem.have ap-
peared during the next few years. For the general case the first constant-competitive
algorithm (O(2k )-competitive) was developed by Fiat, Rabani and Ravid. Later
Koutsoupias and Papadimitriou could analyse an algorithm based on the work func-
tion technique and they could prove that it is (2k 1)-competitive. They could not
determine the competitive ratio of the algorithm, but it is a widely believed hypoth-
esis that the algorithm is k-competitive. Determining the competitive ratio of the
algorithm, or developing a k-competitive algorithm is still among the most impor-
tant open problems in the area of on-line algorithms. We present the work function
algorithm below.
Denote the starting configuration of the on-line servers by A0 . Then after the t-th
request the work function value belonging to multiset X is the minimal cost needed
to serve the first t requests starting at configuration A0 and ending at configuration
X. This value is denoted by wt (X). The Work-Function algorithm is based on the
above defined work function. Suppose that At1 is the server configuration before
the arrival of the t-th request, and denote the place of the t-th request by Rt . The
Work-Function algorithm uses server s to serve the request for which the value
wt1 (At1 \ {P } {Rt }) + d(P, Rt ) is minimal, where P denotes the point where
the server is actually located.
Example 9.2 Consider the metric space containing three points A, B and C with the
distances d(A, B) = 1, d(B, C) = 2, d(A, C) = 3. Suppose that we have two servers and
the starting configuration is {A, B}. In this case the starting work function values are
w0 ({A, A}) = 1, w0 ({A, B}) = 0, w0 ({A, C}) = 2, w0 ({B, B}) = 1, w0 ({B, C}) = 3,
w0 ({C, C}) = 5. Suppose that the first request appears at point C. Then w0 ({A, B} \
{A} {C}) + d(A, C) = 3 + 3 = 6 and w0 ({A, B} \ {B} {C}) + d(B, C) = 2 + 2 = 4, thus
algorithm Work Function uses the server from point B to serve the request.
Besides the general problem many particular cases have been investigated. If
the distance of any pair of points is 1, then we obtain the on-line paging problem
as a special case. Another well investigated metric space is the line. The points
of the line are considered as real numbers, and the distance of points a and b is
|a b|. In this special case a k-competitive algorithm was developed by Chrobak
and Larmore, which algorithm is called Double-Coverage. A request at point P
is served by server s which is the closest to P . Moreover, if there are servers also on
the opposite side of P , then the closest server among them moves distance d(s, P )
into the direction of P . Hereafter we denote the Double-Coverage algorithm by
DC. The input of the algorithm is the list of requests which is a list of points (real
numbers) denoted by I = P1 , . . . , Pn and the starting configuration of the servers is
denoted by S = (s1 , . . . , sk ) which contains points (real numbers) too. The algorithm
can be defined by the following pseudocode:
9.2. The k-server problem 403
DC(I, S)
1 for j 1 to n
2 do i argminl d(Pj , sl )
3 if si = minl sl or si = maxl sl
4 then the request is served by the i-th server
5 si Pj
6 else if si Pj
7 then m argminl:sl >Pj d(sl , Pj )
8 the request is served by the i-th server
9 sm sm d(si , Pj )
10 si Pj
11 else if si Pj
12 then r argminl:sl <Pj d(sl , Pj )
13 the request is served by the i-th server
14 sr sr + d(si , Pj )
15 si Pj
Example 9.3 Suppose that there are three servers s1 , s2 , s3 located at points 0, 1, 2. If the
next request appears at point 4, then DC uses the closest server s3 to serve the request.
The locations of the other servers remain unchanged, the cost of serving the request is 2
and the servers are at points 0, 1, 4. If the next request appears at point 2, then DC uses
the closest server s2 to serve the request, but there are servers on the opposite side of the
request, thus s3 also travels distance 1 into the direction of 2. Therefore the cost of serving
the request is 2 and the servers will be at points 0, 2, 3.
The following statement, which can be proved by the potential function tech-
nique, is valid for algorithm DC. This technique is often used in the analysis of
on-line algorithms.
Theorem 9.4 Algorithm DC is weakly k-competitive on the line.
Proof Consider an arbitrary sequence of requests and denote this input by I. During
the analysis of the procedure we suppose that one off-line optimal algorithm and DC
are running parallel on the input. We also suppose that each request is served first
by the off-line algorithm and then by the on-line algorithm. The servers of the on-
line algorithm and also the positions of the servers (which are real numbers) are
denoted by s1 , . . . , sk , and the servers of the optimal off-line algorithm and also the
positions of the servers are denoted by x1 , . . . , xk . We suppose that for the positions
s1 s2 sk and x1 x2 xk are always valid, this can be achieved by
swapping the notations of the servers.
We prove the theorem by the potential function technique. The potential function
assigns a value to the actual positions of the servers, so the on-line and off-line costs
are compared using the changes of the potential function. Let us define the following
potential function:
Xk X
=k |xi si | + (sj si ) .
i=1 i<j
404 9. Competitive Analysis
Thus we proved that the second property of the potential function is also valid in
this case.
Exercises
9.2-1 Suppose that (M, d) is a metric space. Prove that (M, q) is also a metric space
where q(x, y) = min{1, d(x, y)}.
9.2-2 Consider the greedy algorithm which serves each request by the server which
is closest to the place of the request. Prove that the algorithm is not constant com-
petitive for the line.
9.3. Models related to computer networks 405
9.2-3 Prove that for arbitrary k-element multisets X and Z and for arbitrary t
the inequality wt (Z) wt (X) + d(X, Z) is valid, where d(X, Z) is the cost of the
minimal matching of X and Z, (the minimal cost needed to move the servers from
configuration X to configuration Z).
9.2-4 Consider the line as a metric space. Suppose that the servers of the on-line al-
gorithm are at points 2, 4, 5, 7, and the servers of the off-line algorithm are at points
1, 3, 6, 9. Calculate the value of the potential function used in the proof of Theorem
9.4. How does this potential function change, if the on-line server moves from point
7 to point 8?
of the packets already arrived and has no information about the further packets. We
denote the set of the unacknowledged packets at the arrival time ai by i .
For the solution of the problem the class of the alarming algorithms has been de-
veloped. An alarming algorithm works as follows. At the arrival time aj an alarm
is set for time aj + ej . If no packet arrives before time aj + ej , then an acknowledge-
ment is sent at time aj + ej which acknowledges all of the unacknowledged packets.
Otherwise at the arrival of the next packet at time aj+1 the alarm is reset for time
aj+1 + ej+1 . Below we analyse an algorithm from this class in details. This algorithm
sets the alarm to collect total latency 1 by the acknowledgement. The algorithm is
called Alarm. We obtain the above defined rule from the general definition using
the solution of the following equation as value ej :
X
1 = |j |ej + (aj ai ) .
ai j
Example 9.4 Consider the following example. The first packet arrives at time 0 (a1 = 0),
so Alarm sets an alarm with value e1 = 1 for time 1. Suppose that the next arrival time
is a2 = 1/2. This arrival is before the alarm time, thus the first packet has not been
acknowledged yet and we reset the alarm with value e2 = (1 1/2)/2 = 1/4 for time
1/2 + 1/4. Suppose that the next arrival time is a3 = 5/8. This arrival is before the alarm
time, thus the first two packets have not been acknowledged yet and we reset the alarm
with value e3 = (1 5/8 1/8)/3 = 1/12 for time 5/8 + 1/12. Suppose that the next arrival
time is a4 = 1. No packet arrived before the alarm time 5/8 + 1/12, thus at that time the
first three packets were acknowledged and the alarm is set for the new packet with value
e4 = 1 for time 2.
As the following theorem shows, algorithm Alarm has the smallest possible
competitive ratio.
Theorem 9.6 There is no on-line algorithm for the data acknowledgement problem
which has smaller competitive ratio than 2.
Proof Consider an arbitrary on-line algorithm and denote it by ONL. Analyse the
9.3. Models related to computer networks 407
following input. Consider a long sequence of packets where the packets always arrive
immediately after the time when ONL sends an acknowledgement. The on-line cost
of a sequence containing 2n packets is ONL(I2n ) = 2n + t2n , since the cost resulted
from the acknowledgements is 2n, and the latency of the i-th acknowledgement is
ti ti1 , where the value t0 = 0 is used.
Consider the following two on-line algorithms. ODD sends the acknowledge-
ments after the odd numbered packets and EVEN sends the acknowledgements
after the even numbered packets.
The costs achieved by these algorithms are
n1
X
EVEN(I2n ) = n + (t2i+1 t2i ) ,
i=0
and
n
X
ODD = n + 1 + (t2i t2i1 ) .
i=1
can be used, the algorithm has no information about the further pages. We assume
that the size of the cache and also the sizes of the pages are positive integers.
For the solution of the problem and for its special cases many algorithms have
been developed. Here we present algorithm Landlord which was developed by
Young.
The algorithm stores a credit value 0 cr(f ) c(f ) for each page f which is
contained in the current cache. In the rest of the section the set of the pages in the
current cache of Landlord is denoted by LA. If Landlord has to retrieve a page
g then the following steps are performed.
Landlord(LA, g)
1 if g is not contained in LA
2 then while there is not enough space for g
3 do minf LA cr(f )/s(f )
4 for each f LA let cr(f ) cr(f ) s(f )
5 evict some pages with cr(f ) = 0
6 place g into cache LA and let cr(g) c(g)
7 else reset cr(g) to any value between cr(g) and c(g)
Example 9.5 Suppose that k = 10 and LA contains the following three pages: g1 with
s(g1 ) = 2, cr(g1 ) = 1, g2 with s(g2 ) = 4, cr(g2 ) = 3 and g3 with s(g3 ) = 3, cr(g3 ) = 3.
Suppose that the next requested page is g4 , with parameters s(g4 ) = 4 and c(g4 ) = 4.
Therefore, there is not enough space for it in the cache, so some pages must be evicted.
Landlord determines the value = 1/2 and changes the credits as follows: cr(g1 ) =
0, cr(g2 ) = 1 and cr(g3 ) = 3/2, thus g1 is evicted from cache LA. There is still not enough
space for g4 in the cache. The new value is = 1/4 and the new credits are: cr(g2 ) =
0, cr(g3 ) = 3/4, thus g2 is evicted from the cache. Then there is enough space for g4 , thus
it is placed into cache LA with the credit value cr(g4 ) = 4.
X X
= (h 1) cr(f ) + k (c(f ) cr(f )) .
f LA f OPT
The changes of the potential function during the different steps are as follows.
OPT places g into its cache.
In this case OPT has cost c(g). In the potential function only the second part
may change. On the other hand, cr(g) 0, thus the increase of the potential
function is at most k c(g).
Landlord decreases the credit value for each f LA.
In this case for each f LA the decrease of cr(f ) is s(f ), thus the decrease
of is
where s(LA) and s(OPTLA) denote the total size of the pages contained in sets
LA and OPT LA, respectively. At the time when this step is performed, OPT
have already placed page g into its cache OP T , but the page is not contained
in cache LA. Therefore s(OPT LA) h s(g). On the other hand, this step
is performed if there is not enough space for the page in LA thus s(LA) >
k s(g), which yields s(LA) k s(g) + 1, because the sizes are positive
integers. Therefore we obtain that the decrease of is at least
(h 1)(k s(g) + 1) k(h s(g)) .
has the minimal cost. Below we define and analyse the exponential algorithm for
the throughput model. Let be a constant which depends on the parameters of
the problem; its value will be given later. Let ce (j) = le (j) , for each request j and
edge e. The exponential algorithm performs the following steps after the arrival of
a request (sj , tj , rj , bj ).
EXP(sj , tj , rj , bj )
1 let Uj be the set ofP
the paths (sj , tj )
rj
2 Pj argminP Uj { eP u(e) ce (j)}
P rj
3 if C(Pj ) = ePj u(e) ce (j) 2mbj
4 then reserve bandwidth rj on path Pj
5 else reject the request
Example 9.6 Consider the network which contains vertices A, B, C, D and edges
(A, B), (B, D), (A, C), (C, D), where the available bandwidths of the edges are u(A, B) =
1, u(B, D) = 3/2, u(A, C) = 2, u(C, D) = 3/2. Suppose that = 10 and that the reserved
bandwidths are: 3/4 on path (A, B, D), 5/4 on path (A, C, D), 1/2 on path (B, D), 1/2 on
path (A, C). The next request j is to reserve bandwidth 1/8 on some path between A and D.
Therefore values le (j) are: l(A,B) (j) = (3/4) : 1 = 3/4, l(B,D) (j) = (3/4+1/2) : (3/2) = 5/6,
l(A,C) (j) = (5/4 + 1/2) : 2 = 7/8, l(C,D) (j) = (5/4) : (3/2) = 5/6. There are two paths
between A and D and the costs are:
reserved bandwidths is not more than the available bandwidth for each edge.
Proof We prove the statement by contradiction. Suppose that there is an edge f
where the available bandwidth is violated. Let j be the first accepted request which
violates the available bandwidth on f .
The inequality rj /u(f ) 1/ lg is valid for j and f (it is valid for all edges and
requests). Furthermore, after the acceptance of request j the sum of the bandwidths
is greater than the available bandwidth on edge f , thus we obtain that lf (j) >
1 1/ lg . On the other hand, this yields that the inequality
X rj rj rj 11/ lg
C(Pj ) = ce (j) cf (j) >
u(e) u(f ) u(f )
ePj
holds for value C(Pj ) used in algorithm EXP. Using the assumption on P we obtain
rj
that u(e) P1 , and 11/ lg = /2, thus from the above inequality we obtain that
1
C(P ) > = 2mB .
P 2
On the other hand, this inequality is a contradiction, since EXP would reject the
request. Therefore we obtained a contradiction thus we proved the statement of the
lemma.
Lemma 9.9 For the solution given by OPT the following inequality holds:
X 1 X
bj ce (v) .
2m
jA eE
1
P rj
Proof Since EXP rejected each j A , thus bj < 2m ePj u(e) ce (j) for each
j A , and this inequality is valid for all paths between sj and tj . Therefore
X 1 X X rj
bj < ce (j) .
2m
u(e)
jA jA ePj
On the other hand, ce (j) ce (v) holds for each e, thus we obtain that
X 1 X X rj
bj < ce (v) .
2m u(e)
jA eE jA :ePj
Lemma 9.10 For the solution given by algorithm EXP the following inequality
holds:
1 X X
ce (v) (1 + lg ) bj .
2m
eE jA
P
Proof It is enough to show that the inequality ePj (ce (j+1)ce (j)) 2mbj log2
is valid for each request j A. On the other hand,
rj rj
ce (j + 1) ce (j) = le (j)+ u(e) le (j) = le (j) (2log2 u(e) 1) .
r
Since 2x 1 < x, if 0 x 1, and because of the assumptions 0 log2 u(e)
j
1,
we obtain that
rj
ce (j + 1) ce (j) le (j) log2 .
u(e)
Summarising the bounds given above we obtain that
X X rj
(ce (j + 1) ce (j)) log2 le (j) = log2 C(Pj ) .
u(e)
ePj ePj
Since EXP accepts the requests with the property C(Pj ) 2mbj , the above in-
equality proves the required statement.
With the help of the above lemmas we can prove the following theorem.
Proof From Lemma 9.8 it follows that the algorithm results in a feasible solution
where the available bandwidths are not violated. Using the notations defined
P above
we obtain that the benefit of algorithm
P EXP on the input I is EXP(I) = jA bj ,
and the benefit of OPT is at most jAA bj . Therefore by Lemma 9.9 and Lemma
9.10 it follows that
X X
OPT(I) bj (2 + log2 ) bj (2 + log2 )EXP(I) ,
jAA jA
Exercises
9.3-1 Consider the modifiedPk version of the data acknowledgement problem with
the objective function k + j=1 j , where k is the number of acknowledgements and
j = maxtj1 <ai tj {tj ai } is the maximal latency of the j-th acknowledgement.
Prove that algorithm Alarm is also 2-competitive in this modified model.
414 9. Competitive Analysis
9.3-2 Represent the special case of the web caching problem, where s(g) = c(g) = 1
for each page g as a special case of the k-server problem. Define the metric space
which can be used.
9.3-3 In the web caching problem cache LA of size 8 contains three pages a, b, c
with the following sizes and credits: s(a) = 3, s(b) = 2, s(c) = 3, cr(a) = 2, cr(b) =
1/2, cr(c) = 2. We want to retrieve a page d of size 3 and retrieval cost 4. The optimal
off-line algorithm OPT with cache of size 6 already placed the page into its cache,
so its cache contains the pages d and c. Which pages are evicted by Landlord to
place d? In what way does the potential function defined in the proof of Theorem
9.7 change?
9.3-4 Prove that if in the throughput model no bounds are given for the ratios
r(j)/u(e), then there is no constant-competitive on-line algorithm.
NF() 2n 1
= 2 1/n .
OPT() n
Consequently, we proved that the algorithm is asymptotically 2-competitive.
Now we prove that the bound is tight. Consider the following sequence for each
n denoted by n . The sequence contains 4n 2 items, the size of the 2i 1-th item is
1/2, the size of the 2i-th item is 1/(4n 2), i = 1, . . . , 2n 1. Algorithm NF puts the
(2i 1)-th and the 2i-th items into the i-th bin for each bin, thus NF(n ) = 2n 1.
The optimal off-line algorithm puts pairs of 1/2 size items into the first n1 bins and
it puts one 1/2 size item and the small items into the n-th bin, thus OPT(n ) = n.
Since NF(n )/OPT(n ) = 2 1/n and this function tends to 2 as n tends to ,
we proved that the asymptotic competitive ratio of the algorithm is at least 2.
If k > 1, then there are better algorithms than NF for the k-bounded space
model. The best known bounded space on-line algorithms belong to the family of
harmonic algorithms, where the basic idea is that the interval (0, 1] is divided
into subintervals and each item has a type which is the subinterval of its size.
The items of the different types are packed into different bins. The algorithm runs
several NF algorithms simultaneously; each for the items of a certain type.
Proof In the proof we use the weight function technique whose idea is that a weight
is assigned to each item to measure in some way how difficult it can be to pack
the certain item. The weight function and the total size of the items are used to
416 9. Competitive Analysis
bound the off-line and on-line objective function values. We use the following weight
function:
6x/5, if 0 x 1/6
9x/5 1/10, if 1/6 x 1/3
w(x) =
6x/5 + 1/10, if 1/3 x 1/2
6x/5 + 2/5, if 1/2 < x .
P
Let w(H) = iH w(ai ) for any set H of items. The properties of the weight
function are summarised in the following two lemmas. Both lemmas can be proven
by case disjunction based on the sizes of the possible items. The proofs are long and
contain many technical details, therefore we omit them.
P
Lemma 9.14 If iH ai 1 is valid for a set H of items, then w(H) 17/10
also holds.
Using these lemmas we can prove that the algorithm is asymptotically 1.7-
competitive. Consider an arbitrary list L of items. The optimal off-line algorithm
can pack the items of the list into OPT(L) bins. The algorithm packs items
with total size at most 1 into each bin, thus from Lemma 9.14 it follows that
w(L) 1.7OPT(L). On the other hand considering Lemma 9.15 we obtain that
FF(L) 2 w(L), which yields that F F (L) 1.7OPT(L) + 2, and this inequality
proves that the algorithm is asymptotically 1.7-competitive.
It is important to note that the bound is tight, i.e. it is also true that the
asymptotic competitive ratio of FF is 1.7. Many algorithms have been developed
with smaller asymptotic competitive ratio than 17/10, the best algorithm known at
present time is asymptotically 1.5888-competitive.
Lower bounds
In this part we consider the techniques for proving lower bounds on the possible
asymptotic competitive ratio. First we present a simple lower bound and then we
show how the idea of the proof can be extended into a general method.
Theorem 9.16 No on-line algorithm for the bin packing problem can have smaller
asymptotic competitive ratio than 4/3.
beginning, thus it also uses k bins for packing two items from the part L1 . Therefore
among the items of size 1/2 + only n 2k can be paired with earlier items and
the other ones need separate bin. Thus A(L1 L2 ) n k + (n (n 2k)) = n + k.
On the other hand, the optimal off-line algorithm can pack a smaller (size 1/3 + )
item and a larger (size 1/2 + ) item into each bin, thus OPT(L1 L2 ) = n.
So we obtained that there is a list for algorithm A where
nk n+k
A(L)/OPT(L) max , 4/3 .
n/2 n
Moreover for the above constructed lists OPT(L) is at least dn/2e, which can be
arbitrarily great. This yields that the above inequality proves that the asymptotic
competitive ratio of A is at least 4/3, and this is what we wanted to prove.
The fundamental idea of the above proof is that a long sequence (in this proof
L1 L2 ) is considered, and depending on the behaviour of the algorithm a prefix of
the sequence is selected as input for which the ratio of the costs is maximal. It is
an evident extension to consider more difficult sequences. Many lower bounds have
been proven based on different sequences. On the other hand, the computations
which are necessary to analyse the sequence have become more and more difficult.
Below we show how the analysis of such sequences can be interpreted as a mixed
integer programming problem, which makes it possible to use computers to develop
lower bounds.
Consider the following sequence of items. Let L = L1 L2 . . . Lk , where Li contains
ni = i n identical items of size ai . If algorithm A is asymptotically C-competitive,
then the inequality
A(L1 . . . Lj )
C lim sup
n OPT(L1 . . . Lj )
is valid for each j. It is enough to consider an algorithm for which the technique can
achieve the minimal lower bound, thus our aim is to determine the value
A(L1 . . . Lj )
R = minA maxj=1,...,k lim sup ,
n OPT(L1 . . . Lj )
which value gives a lower bound on the possible asymptotic competitive ratio. We
can determine this value as an optimal solution of a mixed integer programming
problem. To define this problem we need the following definitions.
The contain of a bin can be described by the packing pattern of the bin, which
gives that how many elements are contained in the bin from each subsequence. For-
mally, a packing pattern is a k-dimensional vector (p1 , . . . , pk ), where coordinate
pj is the number of elements contained in the bin from subsequence Lj . For the
Pk
packing patterns the constraint j=1 aj pj 1 must hold. (This constraint ensures
that the items described by the packing pattern fit into the bin.)
Classify the set T of the possible packing patterns. For each j let Tj be the set
of the patterns for which the first positive coordinate is the j-th one. (Pattern p
belongs to class Tj if pi = 0 for each i < j and pj > 0.)
418 9. Competitive Analysis
Consider the packing produced by A. Each bin is packed by some packing pat-
tern, therefore the packing can be described by the packing patterns. For each p T
denote the number of bins which are packed by the pattern p by n(p). The packing
produced by the algorithm is given by variables n(p).
Observe that the bins which are packed by a pattern from class Tj receive their
first element from subsequence Lj . Therefore we obtain that the number of bins
opened by A to pack the elements of subsequence L1 . . . Lj can be given by variables
n(p) as follows:
j X
X
A(L1 . . . Lj ) = n(p) .
i=1 pTi
Min R
P
pT pj n(p) = nj , 1 j k,
Pj P
i=1 pTi n(p) R OPT(L1 . . . Lj ), 1 j k,
n(p) {0, 1, . . . }, p T.
The first k constraints describe that the algorithm has to pack all items. The
second k constraints describe that R is at least as large as the ratio of the on-line
and off-line costs for the subsequences considered.
The set T of the possible packing patterns and also the optimal solutions
OP T (L1 . . . Lj ) can be determined by the list L1 L2 . . . Lk .
In this problem the number and the value of the variables can be large, thus
instead of the problem its linear programming relaxation is considered. Moreover,
we are interested in the solution under the assumption that n tends to and it
can be proven that the integer programming and the linear programming relaxation
give the same bound in this case.
The best currently known bound was proven by this method and it states that
no on-line algorithm can have smaller asymptotic competitive ratio than 1.5401.
items are coming one by one and the algorithm has to pack them into the cubes
without any information about the further items.
Shelf algorithms
A basic way of packing into the strip is to define shelves and pack the rectangles
onto the shelves. By shelf we mean a rectangular part of the strip. Shelf packing
algorithms place each rectangle onto one of the shelves. If the algorithm decides
which shelf will contain the rectangle, then the rectangle is placed onto the shelf as
much to the left as it is possible without overlapping the other rectangles placed
onto the shelf earlier. Therefore, after the arrival of a rectangle, the algorithm has
to make two decisions. The first decision is whether to create a new shelf or not. If
the algorithm creates a new shelf, it also has to decide the height of the new shelf.
The created shelves always start from the top of the previous shelf. The first shelf is
placed to the bottom of the strip. The algorithm also has to choose which shelf to
put the rectangle onto. Hereafter we will say that it is possible to pack a rectangle
onto a shelf, if there is enough room for the rectangle on the shelf. It is obvious that
if a rectangle is higher than a shelf, we cannot place it onto the shelf.
We consider only one algorithm in details. This algorithm was developed and
analysed by Baker and Schwarz in 1983 and it is called Next-Fit-Shelf (NFSr )
algorithm. The algorithm depends on a parameter r < 1. For each j there is at most
one active shelf with height rj . We define how the algorithm works below.
After the arrival of a rectangle pi = (wi , hi ) choose a value for k which satisfies
rk+1 < hi rk . If there is an active shelf with height rk and it is possible to pack
the rectangle onto it, then pack it there. If there is no active shelf with height rk ,
or it is not possible to pack the rectangle onto the active shelf with height rk , then
create a new shelf with height rk , put the rectangle onto it, and let this new shelf
be the active shelf with height rk (if we had an active shelf with height rk earlier,
then we close it).
Example 9.7 Let r = 1/2. Suppose that the size of the first item is (w/2, 3/4). Therefore,
it is assigned to a shelf of height 1. We define a shelf of height 1 at the bottom of the strip;
420 9. Competitive Analysis
this will be the active shelf with height 1 and we place the item into the left corner of this
shelf. Suppose that the size of the next item is (3w/4, 1/4). In this case it is placed onto
a shelf of height 1/4. There is no active shelf with this height so we define a new shelf of
height 1/4 on the top of the previous shelf. This will be the active shelf of height 1/4 and
the item is placed onto its left corner. Suppose that the size of the next item is (3w/4, 5/8).
This item is placed onto a shelf of height 1. It is not possible to pack it onto the active
shelf, thus we close the active shelf and we define a new shelf of height 1 on the top of the
previous shelf. This will be the active shelf of height 1 and the item is placed into its left
corner. Suppose that the size of the next item is (w/8, 3/16). This item is placed onto a
shelf of height 1/4. We can pack it onto the active shelf of height 1/4, thus we pack it onto
that shelf as left as it is possible.
For the competitive ratio of NFSr the following statements are valid.
Theorem 9.17 Algorithm NFSr is 2r + r(1r) 1
-competitive. Algorithm NFSr is
asymptotically 2/r-competitive.
Proof First we prove that the algorithm is 2r + r(1r)
1
-competitive. Consider an
arbitrary list of rectangles and denote it by L. Let HA denote the sum of the heights
of the shelves which are active at the end of the packing, and let HC be the sum
of the heights of the other shelves. Let h be the height of the highest active shelf
(h = rj for some j), and let H be the height of the highest rectangle. Since the
algorithm created a shelf with height h, we have H > rh. As there is at most 1
active shelf for each height,
X h H
HA h ri = .
i=0
1r r(1 r)
Consider the shelves which are not active at the end. Consider the shelves of
height hri for each i, and denote the number of the closed shelves by ni . Let S be
one of these shelves with height hri . The next shelf S 0 with height hri contains one
rectangle which would not fit onto S. Therefore, the total width of the rectangles
is at least w. Furthermore, the height of these rectangles is at least hri+1 , thus
the total area of the rectangles packed onto S and S 0 is at least hwri+1 . If we
pair the shelves of height hri for each i in this way, using the active shelf if the
number of the shelves of the considered height is odd, we obtain that the total
area of the rectangles assigned to the shelves of height
P hr isi+1
i
at least wni hri+1 /2.
Thus the total area
Pof the rectangles is at least i=0 wni hr /2, and this yields
that OPT(L) P i=0 ni hri+1 /2. On the other hand, the total height of the closed
shelves is HZ = i=0 ni hri , and we obtain that HZ 2OPT(L)/r.
Since OPT(L) H is valid we proved the required inequality
Since the heights of the rectangles are bounded by 1, H and HA are bounded
by a constant, so we obtain the result about the asymptotic competitive ratio im-
mediately.
9.5. On-line scheduling 421
Besides this algorithm some other shelf algorithms have been investigated for
the solution of the problem. We can interpret the basic idea of NFSr as follows. We
define classes of items belonging to types of shelves, and the rectangles assigned to
the classes are packed by the classical bin packing algorithm NF. It is an evident idea
to use other bin packing algorithms. The best shelf algorithm known at present time
was developed by Csirik and Woeginger in 1997. That algorithm uses the harmonic
bin packing algorithm to pack the rectangles assigned to the classes.
Exercises
9.4-1 Suppose that the size of the items is bounded above by 1/3. Prove that under
this assumption the asymptotic competitive ratio of NF is 3/2.
9.4-2 Suppose that the size of the items is bounded above by 1/3. Prove Lemma
9.15 under this assumption.
9.4-3 Suppose that the sequence of items is given by a list L1 L2 L3 , where L1
contains n items of size 1/2, L2 contains n items of size 1/3, L3 contains n items of
size 1/4. Which packing patterns can be used? Which patterns belong to class T2 ?
9.4-4 Consider the version of the strip packing problem where one can lengthen the
rectangles keeping the area fixed. Consider the extension of NFSr which lengthen
the rectangles before the packing to the same height as the shelf which is chosen to
1
pack them onto. Prove that this algorithm is 2 + r(1r) -competitive.
Many objective functions are considered for scheduling problems, but here we
consider only such models where the goal is the minimisation of the makespan (the
maximal completion time).
In the next subsection we define the two most fundamental on-line scheduling
models, and in the following two subsections we consider these models in details.
LIST model
In this model we have a fixed number of machines denoted by M1 , M2 , . . . , Mm ,
and the jobs arrive from a list. This means that the jobs and their processing times
are revealed to the on-line algorithm one by one. When a job is revealed, the on-line
algorithm has to assign the job to a machine with a starting time and a completion
time irrevocably.
By the load of a machine, we mean the sum of the processing times of all jobs
assigned to the machine. Since the objective function is to minimise the maximal
completion time, it is enough to consider the schedules where the jobs are scheduled
on the machines without idle time. For these schedules the maximal completion
time is the load for each machine. Therefore this scheduling problem is reduced to
a load balancing problem, i.e. the algorithm has to assign the jobs to the machines
minimising the maximum load, which is the makespan in this case.
Example 9.8 Consider the LIST model and two identical machines. Consider the following
sequence of jobs where the jobs are given by their processing time: I = {j1 = 4, j2 = 3, j3 =
2, j4 = 5}. The on-line algorithm first receives job j1 from the list, and the algorithm has
to assign this job to one of the machines. Suppose that the job is assigned to machine
M1 . After that the on-line algorithm receives job j2 from the list, and the algorithm has
to assign this job to one of the machines. Suppose that the job is assigned to machine
M2 . After that the on-line algorithm receives job j3 from the list, and the algorithm has
to assign this job to one of the machines. Suppose that the job is assigned to machine
M2 . Finally, the on-line algorithm receives job j4 from the list, and the algorithm has to
assign this job to one of the machines. Suppose that the job is assigned to machine M1 .
Then the loads on the machines are 4 + 5 and 3 + 2, and we can give a schedule where the
maximal completion times on the machines are the loads: we can schedule the jobs on the
first machine in time intervals (0, 4) and (4, 9), and we can schedule the jobs on the second
machine in time intervals (0, 3) and (3, 5).
TIME model
In this model there are a fixed number of machines again. Each job has a pro-
cessing time and a release time. A job is revealed to the on-line algorithm at its
release time. For each job the on-line algorithm has to choose which machine it will
run on and assign a start time. No machine may simultaneously run two jobs. Note
that the algorithm is not required to assign a job immediately at its release time.
9.5. On-line scheduling 423
However, if the on-line algorithm assigns a job at time t then it cannot use informa-
tion about jobs released after time t and it cannot start the job before time t. Our
aim is to minimise the makespan.
Example 9.9 Consider the TIME model with two related machines. Let M1 be the first
machine with speed 1, and M2 be the second machine with speed 2. Consider the following
input I = {j1 = (1, 0), j2 = (1, 1), j3 = (1, 1), j4 = (1, 1)}, where the jobs are given by the
(processing time, release time) pairs. Thus a job arrives at time 0 with processing time 1,
and the algorithm can either start to process it on one of the machines or wait for jobs with
larger processing time. Suppose that the algorithm waits till time 1/2 and then it starts
to process the job on machine M1 . The completion time of the job is 3/2. At time 1 three
further jobs arrive, and at that time only M2 can be used. Suppose that the algorithm
starts to process job j2 on this machine. At time 3/2 both jobs are completed. Suppose
that the remaining jobs are started on machines M1 and M2 , and the completion times are
5/2 and 2, thus the makespan achieved by the algorithm is 5/2. Observe that an algorithm
which starts the first job immediately at time 0 can make a better schedule with makespan
2. But it is important to note that in some cases it can be useful to wait for larger jobs
before starting a job.
Theorem 9.18 The competitive ratio of algorithm LIST is 2 1/m in the case
of identical machines.
On the other
Pnhand, OPT also processes all of the jobs, thus we obtain that
1
OPT() m ( j=1 pj ). Furthermore, pl is scheduled on one of the machines of
424 9. Competitive Analysis
m1
LIST () (1 + )OPT() ,
m
which inequality proves that LIST is 2 1/m-competitive.
Now we prove that the bound is tight. Consider the following input. It contains
m(m 1) jobs with processing time 1/m and one job with processing time 1. LIST
assigns m 1 small jobs to each machine and the last large job is assigned to M1 .
Therefore its makespan is 1 + (m 1)/m. On the other hand, the optimal algorithm
schedules the large job on M1 and m small jobs on the other machines, and its
makespan is 1. Thus the ratio of the makespans is 2 1/m which shows that the
competitive ratio of LIST is at least 2 1/m.
Although it is hard to imagine any other algorithm for the on-line case, many
other algorithms have been developed. The competitive ratios of the better algo-
rithms tend to smaller numbers than 2 as the number of machines tends to . Most
of these algorithms are based on the following idea. The jobs are scheduled keeping
the load uniformly on most of the machines, but in contrast to LIST, the loads are
kept low on some of the machines, keeping the possibility of using these machines
for scheduling large jobs which may arrive later.
Below we consider the more general cases where the machines are not identical.
LIST may perform very badly, and the processing time of a job can be very large
on the machine where the actual load is minimal. However, we can easily change the
greedy idea of LIST as follows. The extended algorithm is called Greedy and it
assigns the job to the machine where the load with the processing time of the job is
minimal. If there are several machines which have minimal value, then the algorithm
chooses the machine where the processing time of the job is minimal from them, if
there are several machines with this property, the algorithm chooses the one with
the smallest index from them.
Example 9.10 Consider the case of related machines where there are 3 machines
M1 , M2 , M3 and the speeds are s1 = s2 = 1, s2 = 3. Suppose that the input is
I = {j1 = 2, j2 = 1, j3 = 1, j4 = 3, j5 = 2}, where the jobs are defined by their pro-
cessing weight. The load after the first job is 2/3 on machine M3 and 2 on the other
machines, thus j1 is assigned to M3 . The load after job j2 is 1 on all of the machines, and
its processing time is minimal on machine M3 , thus Greedy assigns it to M3 . The load
after job j3 is 1 on M1 and M2 , and 4/3 on M3 , thus the job is assigned to M1 . The load
after job j4 is 4 on M1 , 3 on M2 , and 2 on M3 , thus the job is assigned to M3 . Finally, the
load after job j5 is 3 on M1 , 2 on and M2 , and 8/3 on M3 , thus the job is assigned to M2 .
Example 9.11 Consider the case of unrelated machines with two machines and the follow-
ing input: I = {j1 = (1, 2), j2 = (1, 2), j3 = (1, 3), j4 = (1, 3)}, where the jobs are defined
by the vectors of processing times. The load after job j1 is 1 on M1 and 2 on M2 , thus the
job is assigned to M1 . The load after job j2 is 2 on M1 and also on M2 , thus the job is
assigned to M1 , because it has smaller processing time. The load after job j3 is 3 on M1
and M2 , thus the job is assigned to M1 because it has smaller processing time. Finally, the
9.5. On-line scheduling 425
To investigate the case of the related machines consider an arbitrary input. Let
L and L denote the makespans achieved by Greedy and OPT respectively. The
analysis of the algorithm is based on the following lemmas which give bounds on the
loads of the machines.
Lemma 9.20 The load on the fastest machine is at least L L .
Proof Consider the schedule produced by Greedy. Consider a job J which causes
the makespan (its completion time is maximal). If this job is scheduled on the fastest
426 9. Competitive Analysis
machine, then the lemma follows immediately, i.e. the load on the fastest machine
is L. Suppose that J is not scheduled on the fastest machine. The optimal maximal
load is L , thus the processing time of J on the fastest machine is at most L . On
the other hand, the completion time of J is L, thus at the time when the job was
scheduled the load was at least (L L ) on the fastest machine, otherwise Greedy
would assign J to the fastest machine.
Lemma 9.21 If the loads are at least l on all machines having a speed of at least
v then the loads are at least l 4L on all machines having a speed of at least v/2.
Proof If l < 4L , then the statement is obviously valid. Suppose that l 4L .
Consider the jobs which are scheduled by Greedy on the machines having a speed
of at least v in the time interval [l 2L , l]. The total processing weight of these
jobs is at least 2L times the total speed of the machines having a speed of at least
v. This yields that there exists a job among them which is assigned by OPT to a
machine having a speed of smaller than v (otherwise the optimal off-line makespan
would be larger than L ). Let J be such a job.
Since OPT schedules J on a machine having a speed of smaller than v, thus
the processing weight of J is at most vL . This yields that the processing time of J
is at most 2L on the machines having a speed of at least v/2. On the other hand,
Greedy produces a schedule where the completion time of J is at least l 2L ,
thus at the time when the job was scheduled the loads were at least l 4L on the
machines having a speed of at most v/2 (otherwise Greedy would assign J to one
of these machines).
On the other hand, Greedy schedules the same jobs, thus the load on some
machine not included in I is smaller than 2L in the schedule produced by Greedy
9.5. On-line scheduling 427
(otherwise we would obtain that the sum of the processing weights is greater than
W ).
Therefore we obtain that
L (1 + 4dlg me)L 2L ,
which yields that L 3 + 4dlg me)L , which proves that Greedy is O(lg m)-
competitive.
Now we prove that the competitive ratio of the algorithm is at least (lg m).
Consider the following set of machines: G0 contains one machine with speed 1 and G1
contains 2 machines with speed 1/2. For each i = 1, 2, . . . , k, Gi contains machines
Pi1
with speed 2i , and Gi contains |Gi | = j=0 |Gj |2ij machines. Observe that the
number of jobs of processing weight 2i which can be scheduled during 1 time unit is
the same on the machines of Gi and on the machines of G0 G1 . . . , Gi1 . It is easy
to calculate that |Gi | = 22i1 , if i 1, thus the number of machines is 1 + 32 (4k 1).
Consider the following input sequence. In the first phase |Gk | jobs arrive having
processing weight 2k , in the second phase |Gk1 | jobs arrive having processing
weight 2(k1) , in the i-th phase |Gi | jobs arrive with processing weight 2i , and the
sequence ends with the k +1-th phase, which contains one job with processing weight
1. An off-line algorithm can schedule the jobs of the i-th phase on the machines of
set Gk+1i achieving maximal load 1, thus the optimal off-line cost is at most 1.
Investigate the behaviour of algorithm Greedy on this input. The jobs of the
first phase can be scheduled on the machines of G0 , . . . , Gk1 during 1 time unit, and
it takes also 1 time unit to process these jobs on the machines of Gk . Thus Greedy
schedules these jobs on the machines of G0 , . . . , Gk1 , and each load is 1 on these
machines after the first phase. Then the jobs of the second phase are scheduled
on the machines of G0 , . . . , Gk2 , the jobs of the third phase are scheduled on the
machines of G0 , . . . , Gk3 and so on. Finally, the jobs of the k-th and k + 1-th phase
are scheduled on the machine of set G0 . Thus the cost of Greedy is k + 1, (this
is the load on the machine of set G0 ). Since k = (lg m), we proved the required
statement.
INTV(I)
1 while not end of sequence
2 let Hi be the set of the unscheduled jobs released till ti
3 let OF Fi be an optimal off-line schedule of the jobs of Hi
4 schedule the jobs as it is determined by OF Fi starting the schedule at ti
5 let qi be the maximal completion time
6 if a new job is released in time interval (ti , qi ] or the sequence is ended
7 then ti+1 qi
7 else let ti+1 be the release time of the next job
8 ii+1
Example 9.12 Consider two identical machines. Suppose that the sequence of jobs is
I = {j1 = (1, 0), j2 = (1/2, 0), j3 = (1/2, 0), j4 = (1, 3/2), j5 = (1, 3/2), j6 = (2, 2)},
where the jobs are defined by the (processing time, release time) pairs. In the first iteration
j1 , j2 , j3 are scheduled: an optimal off-line algorithm schedules j1 on machine M1 and j2 , j3
on machine M2 , so the jobs are completed at time 1. Since no new job have been released in
the time interval (0, 1], the algorithm waits for a new job until time 3/2. Then the second
iteration starts: j4 and j5 are scheduled on M1 and M2 respectively in the time interval
[3/2, 5/2). During this time interval j6 has been released thus at time 5/2 the next iteration
starts and INTV schedules j6 on M1 in the time interval [5/2, 9/2].
The following statement holds for the competitive ratio of algorithm INTV.
Theorem 9.23 In the TIME model algorithm INTV is 2-competitive.
Proof Consider an arbitrary input and the schedule produced by INTV. Denote
the number of iterations by i. Let T3 = ti+1 ti , T2 = ti ti1 , T1 = ti1 and let
TOPT denote the optimal off-line cost. In this case T2 TOPT . This inequality is
obvious if ti+1 6= qi . If ti+1 = qi , then the inequality holds, because also the optimal
off-line algorithm has to schedule the jobs which are scheduled in the i-th iteration
by INTV, and INTV uses an optimal off-line schedule in each iteration. On the
other hand, T1 + T3 TOPT . To prove this inequality first observe that the release
time is at least T1 = ti1 for the jobs scheduled in the i-th iteration (otherwise the
algorithm would schedule them in the i 1-th iteration).
Therefore also the optimal algorithm has to schedule these jobs after time T1 .
On the the other hand, it takes at least T3 time units to process these jobs, because
INTV uses optimal off-line algorithm in the iterations. The makespan of the schedule
produced by INTV is T1 + T2 + T3 , and we have shown that T1 + T2 + T3 2TOPT ,
thus we proved that the algorithm is 2-competitive.
Some other algorithms have also been developed in the TIME model. Vestjens
proved that the on-line LPT algorithm is 3/2-competitive. This algorithm sched-
ules the longest unscheduled, released job at each time when some machine is avail-
able. The following lower bound for the possible competitive ratios of the on-line
algorithms is also given by Vestjens.
Theorem 9.24 The competitive ratio of any on-line algorithm is at least 1.3473
Notes for Chapter 9 429
Exercises
9.5-1 Prove that the competitive ratio is at least 3/2 for any on-line algorithm in
the case of two identical machines.
9.5-2 Prove that LIST is not constant competitive in the case of unrelated ma-
chines.
9.5-3 Prove that the modification of INTV which uses a c-approximation schedule
(a schedule with at most c times more cost than the optimal cost) instead of the
optimal off-line schedule in each step is 2c-competitive.
Problems
Analyse the algorithm which serves the requests not having server on their place
by the server which was used least recently. (This algorithm is equivalent with the
LRU paging algorithm.) Prove that the algorithm is k-competitive.
9-2 ALARM2 algorithm
Consider the following alarming algorithm for the data acknowledgement problem.
ALARM2 is obtained from the general definition with the values ej = 1/|j |. Prove
that the algorithm is not constant-competitive.
9-3 Bin packing lower bound
Prove, that no on-line algorithm can have smaller competitive ratio than 3/2 using
a sequence which contains items of size 1/7 + , 1/3 + , 1/2 + , where is a small
positive number.
9-4 Strip packing with modifiable rectangles
Consider the following version of the strip packing problem. In the new model the
algorithms are allowed to lengthen the rectangles keeping the area fixed. Develop a
4-competitive algorithm for the solution of the problem.
9-5 On-line LPT algorithm
Consider the algorithm in the TIME model which starts the longest released job to
schedule at each time when a machine is available. This algorithm is called on-line
LPT. Prove that the algorithm is 3/2-competitive.
Chapter Notes
More details about the results on on-line algorithms can be found in the books
[30, 72].
The first results about the k-server problem (Theorems 9.1 and 9.2) are published
by Manasse, McGeoch and Sleator in [166]. The presented algorithm for the line
(Theorem 9.3) was developed by Chrobak, Karloff, Payne and Viswanathan (see
[46]). Later Chrobak and Larmore extended the algorithm for trees in [44]. The
first constant-competitive algorithm for the general problem was developed by Fiat,
Rabani and Ravid (see [71]). The best known algorithm is based on the work function
technique. The first work function algorithm for the problem was developed by
Chrobak and Larmore in [45]. Koutsoupias and Papadimitriou have proven that
the work function algorithm is 2k 1-competitive in [143].
The first mathematical model for the data acknowledgement problem and the
first results (Theorems 9.5 and 9.6) are presented by Dooly, Goldman, and Scott in
[63]. Online algorithms with lookahead property are presented in [118]. Albers and
Bals considered a different objective function in [11]. Karlin Kenyon and Randall
investigated randomised algorithms for the data acknowledgement problem in [133].
The Landlord algorithm was developed by Young in [265]. The detailed description
of the results in the area of on-line routing can be found in the survey [156] written
by Leonardi. The exponential algorithm for the load balancing model is investigated
by Aspnes, Azar, Fiat, Plotkin and Waarts in [13]. The exponential algorithm for
the throughput objective function is applied by Awerbuch, Azar and Plotkin in [16].
A detailed survey about the theory of on-line bin packing is written by Csirik
and Woeginger (see [55]). The algorithms NF and FF are analysed with competitive
Notes for Chapter 9 431
analysis by Johnson, Demers, Ullman, Garey and Graham in [127, 128], further
results can be found in the PhD thesis of Johnson ([126]). Our Theorem 9.12 is a
special case of Theorem 1 in [120] and Theorem 9.13 is a special case of Theorems
5.8 and 5.9 of the book [47] and Corollary 20.13 in the twentieth chapter of this book
[?]. Van Vliet applied the packing patterns to prove lower bounds for the possible
competitive ratios in [256, 269]. For the on-line strip packing problem algorithm
NFSr was developed and analysed by Baker and Schwarz in [20]. Later further shelf
packing algorithms were developed, the best shelf packing algorithm for the strip
packing problem was developed by Csirik and Woeginger in [56].
A detailed survey about the results in the area of on-line scheduling was written
by Sgall ([226]). The first on-line result is the analysis of algorithm LIST, it was
published by Grahamin [92]. Many further algorithms were developed and analysed
for the case of identical machines, the algorithm with smallest competitive ratio
(tends to 1.9201 as the number of machines tends to ) was developed by Fleischer
and Wahl in [75]. The lower bound for the competitive ratio of Greedy in the related
machines model was proved by Cho and Sahni in [42]. The upper bound, the related
machines case and a more sophisticated exponential function based algorithm were
presented by Aspnes, Azar, Fiat, Plotkin and Waarts in [13]. A summary of further
results about the applications of the exponential function technique in the area of
on-line scheduling can be found in the paper of Azar ([17]). The interval algorithm
presented in the TIME model and Theorem 9.23 are based on the results of Shmoys,
Wein and Williamson (see [231]). A detailed description of further results (on-line
LPT, lower bounds) in the area TIME model can be found in the PhD thesis of
Vestjens [270]. We presented only the most fundamental on-line scheduling models
in the chapter, although an interesting model has been developed recently, where
the number of the machines is not fixed, and the algorithm is allowed to purchase
machines. The model is investigated in papers [65, 66, 117, 119].
Problem 9-1 is based on [238], Problem 9-2 is based on [63], Problem 9-3 is based
on [264], Problem 9-4 is based on [116] and Problem 9-5 is based on [270].
10. Game Theory
In many situations in engineering and economy there are cases when the conflicting
interests of several decision makers have to be taken into account simultaneously,
and the outcome of the situation depends on the actions of these decision makers.
One of the most popular methodology and modeling is based on game theory.
Let N denote the number of decision makers (who will be called players), and
for each k = 1, 2, . . . , N let Sk be the set of all feasible actions of player Pk . The
elements sk Sk are called strategies of player Pk , Sk is the strategy set of this
player. In any realization of the game each player selects a strategy, then the vector
s = (s1 , s2 , . . . , sN ) (sk Sk , k = 1, 2, . . . , N ) is called a simultaneous strategy
vector of the players. For each s S = S1 S2 SN each player has an
outcome which is assumed to be a real value. This value can be imagined as the
utility function value of the particular outcome, in which this function represents
how player Pk evaluates the outcomes of the game. If fk (s1 , . . . , sN ) denotes this
value, then fk : S R is called the payoff function of player Pk . The value
fk (s) is called the payoff of player Pk and (f1 (s), . . . , fN (s)) is called the payoff
vector. The number N of players, the sets Sk of strategies and the payoff functions
fk (k = 1, 2, . . . , N ) completely determine and define the N -person game. We will
also use the notation G = {N ; S1 , S2 , . . . , SN ; f1 , f2 , . . . , fN } for this game.
The solution of game G is the Nash-equilibrium, which is a simultaneous
strategy vector s? = (s?1 , . . . , s?N ) such that for all k,
1. s?k Sk ;
2. for all sk Sk ,
fk (s?1 , s?2 , . . . , s?k1 , sk , s?k+1 , . . . , s?N )fk (s?1 , s?2 , . . . , s?k1 , s?k , s?k+1 , . . . , s?N ).
(10.1)
Condition 1 means that the k-th component of the equilibrium is a feasible strategy
of player Pk , and condition 2 shows that none of the players can increase its payoff
by unilaterally changing its strategy. In other words, it is the interest of all players
to keep the equilibrium since if any player departs from the equilibrium, its payoff
does not increase.
10.1. Finite games 433
P layer P2
N C
N (2, 2) (10, 1)
P layer P1
C (1, 10) (5, 5)
Example 10.1 The players are two prisoners who committed a serious crime, but the
prosecutor has only insufficient evidence to prosecute them. The prisoners are held in
separate cells and cannot communicate, and the prosecutor wants them to cooperate with
the authorities in order to get the needed additional information. So N = 2, and the strategy
sets for both players have two elements: cooperating (C), or not cooperating (N ). It is told
to both prisoners privately that if he is the only one to confess, then he will get only a light
sentence of 1 year, while the other will go to prison for a period of 10 years. If both confess,
then their reward will be a 5 year prison sentence each, and if none of them confesses, then
they will be convicted to a less severe crime with sentence of 2 years each. The objective
of both players are to minimize the time spent in prison, or equivalently to maximize its
negative. Figure 10.1 shows the payoff values, where the rows correspond to the strategies
of player P1 , the columns show the strategies of player P2 , and for each strategy pair the
first number is the payoff of player P1 , and the second number is the payoff of player P2 .
Comparing the payoff values, it is clear that only (C, C) can be equilibrium, since
f2 (N,N) = 2 < f2 (N,C) = 1 ,
f1 (N,C) = 10 < f1 (C,C) = 5 ,
f2 (C,N) = 10 < f2 (C, C) = 5 .
The strategy pair (C, C) is really an equilibrium, since
f1 (C,C) = 5 > f1 (N,C) = 10 ,
f2 (C,C) = 5 > f2 (C,N) = 10 .
In this case we have a unique equilibrium.
Example 10.2 Modify the payoff values of Figure 10.1 as shown in Figure 10.2. It is easy
to see that no equilibrium exists:
f1 (N,N) = 1 < f1 (C,N) = 2 ,
f2 (C,N) = 4 < f2 (C,C) = 5 ,
f1 (C,C) = 0 < f1 (N,C) = 2 ,
f2 (N,C) = 1 < f2 (N,N) = 2 .
434 10. Game Theory
P layer P2
N C
N (1, 2) (2, 1)
P layer P1
C (2, 4) (0, 5)
If all payoff values are identical, then we have multiple equilibria: any strategy
pair is an equilibrium.
10.1.1. Enumeration
Let N denote the number of players, and for the sake of notational conve-
(1) (n )
nience let sk , . . . , sk k denote the feasible strategies of player Pk . That is, Sk =
(1) (n ) (i ) (i )
{sk , . . . , sk k }. A strategy vector s? = (s1 1 , . . . , sNN ) is an equilibrium if and
only if for all k = 1, 2, . . . , N and j {1, 2, . . . , nk } \ ik ,
(i ) (i ) (j) (i ) (i )
fk (s1 1 , . . . , sk1
k1 k+1
, sk , sk+1 , . . . , sNN )
(i ) (i ) (i ) (i ) (i )
fk (s1 1 , . . . , sk1
k1 k+1
, sk k , sk+1 , . . . , sNN ). (10.2)
Notice that in the case of finite games inequality (10.1) reduces to (10.2).
In applying the enumeration method, inequality (10.2) is checked for all possible
(i ) (i )
strategy N -tuples s? = (s1 1 , . . . , sNN ) to see if (10.2) holds for all k and j. If it
does, then s is an equilibrium, otherwise not. If during the process of checking for
?
N
! N
!
Y X
nk (nk 1) ,
k=1 k=1
however in practical cases it might be much lower, since if (10.2) is violated with
some j, then the comparison must stop for the same strategy vector.
The algorithm can formally be given as follows:
10.1. Finite games 435
Prisoner-Enumeration(Sk )
1 for i1 1 to n1
2 do for i2 1 to n2
..
3 .
4 do for iN 1 to nN
5 do key 0
6 for k 1 to N
7 do for j 1 to nk
8 do if (10.2) fails
9 then key 1 and go to 10
10 if key = 0
(i ) (i )
11 then (s1 1 , . . . , sNN ) is equilibrium
(i ) (i )
12 return (s1 1 , . . . , sNN )
Consider next the two-person case, N =2, and introduce the n1 n2 real matrixes
A(1) and A(2) with (i, j) elements f1 (i, j) and f2 (i, j) respectively. Matrixes A(1)
and
A
(2)
called the payoff matrixes of the two players. A strategy vector
are
(i1 ) (i2 )
s1 , s2 is an equilibrium if and only if the (i1 , i2 ) element in matrix A(1) is the
largest in its column, and in matrix A(2) it is the largest in its row. In the case when
f2 = f1 , the game is called zero-sum, and A(2) = A(1) , so the game can be
completely described by the payoff matrix A(1) of the first player. In this special case
(i ) (i )
a strategy vector (s1 1 , s2 2 ) is an equilibrium if and only if the element (i1 , i2 ) is
the largest in its column and smallest in its row. In the zero-sum cases the equilibria
are also called the saddle points of the games. Clearly, the enumeration method to
find equilibria becomes more simple since we have to deal with a single matrix only.
The simplified algorithm is as follows:
EquilibriumA(2)
1 for i1 1 to n1
2 do for i2 1 to n2
3 do key 0
4 for j 1 to n1
(1) (1)
5 do if aji2 > ai1 i2
6 then key 1
7 go to 12
8 for j 1 to n2
(2) (2)
9 do if ai1 j > ai1 i2
10 then key 1
11 go to 12
12 if key = 0
(1) (2)
13 then return (si1 , si2 )
436 10. Game Theory
Theorem 10.1 All games represented by finite trees have at least one equilibrium.
Proof We present the proof of this result here, since it suggests a practical algorithm
to find equilibria. The proof goes by induction with respect to the number of nodes of
the game tree. If the game has only one node, then clearly it is the only equilibrium.
Assume next that the theorem holds for any tree with less than n nodes (n
2), and consider a game T0 with n nodes. Let R be the root of the tree and let
r1 , r2 , . . . , rm (m < n) be the nodes connected to R by an arc. If T1 , T2 , . . . , Tm
denote the disjoint subtrees of T0 with roots r1 , r2 , . . . , rm , then each subtree has
less than n nodes, so each of them has an equilibrium. Assume that player Pk is
assigned to R. Let e1 , e2 , . . . , em be the equilibrium payoffs of player Pk on the
subtrees T1 , T2 , . . . , Tm and let ej = max{e1 , e2 , . . . , em }. Then player Pk will move
to node rj from the root, and then the equilibrium continues with the equilibrium
obtained on the subtree Tj . We note that not all equilibria can be obtained by this
method, however the payoff vectors of all equilibria, which can obtained by this
method, are identical.
We note that not all equilibria can be obtained by this method, however the
payoff vectors of all equilibria, which can be obtained by this method, are identical.
The proof of the theorem suggests a dynamic programming-type algorithm which
is called backward induction. It can be extended to the more general case when
the tree has chance nodes from which the continuations of the game are random
10.1. Finite games 437
(1, 2, 0)
11
3 (2, 3, 3)
5 12
(1, 1, 1)
13
3
2 (2, 1, 2)
6 14
2
(0, 0, 0)
15
2
(2, 1, 3)
7
1 3 16
1 3 (1, 1, 1)
2 17
8 (0, 3, 1)
18
2 (3, 2, 2)
3
19
4
9
(4, 1, 4)
20
3 (2, 0, 0)
10 21
(1, 0, 1)
22
Assume that the maximal value occurs at node ji , then we assign p(i) = p(ji ) to node
i, and move to node i 1. After all payoff vectors p(n) , p(n1) , . . . , p(2) and p(1)
are determined, then vector p(1) gives the equilibrium payoffs and the equilibrium
path is obtained by nodes:
1 i1 = j1 i2 = ji1 i3 = ji2 . . . ,
Backward-Induction
1 for i n to 1
(j ) (l)
2 do pKii max{pKi , l J(i)}
3 p(i) p(ji )
4 print sequence 1, i1 (= j1 ), i2 (= ji1 ), i3 (= ji2 ), . . .
until an endpoint is reached
Example 10.3 Figure 10.3 shows a finite tree. In the circle at each nonterminal node we
indicate the player assigned to that node. The payoff vectors are also shown at all terminal
nodes. We have three players, so the payoff vectors have three elements.
First we number the nodes such that the beginning of each arc has a smaller number
than its endpoint. We indicated these numbers in a box under each node. All nodes i for
i 11 are terminal nodes, as we start the backward induction with node 10. Since player
P3 is assigned to this node we have to compare the third components of the payoff vectors
(2, 0, 0) and (1, 0, 1) associated to the endpoints of the two arcs originating from node 10.
Since 1 > 0, player P3 will select the arc to node 22 as his best choice. Hence j10 = 22,
and p(10) = p(22) = (1, 0, 1). Then we check node 9. By comparing the third components
of vectors p(19) and p(20) it is clear that player P3 will select node 20, so j9 = 20, and
p(9) = p(20) = (4, 1, 4). In the graph we also indicated the choices of the players by thicker
arcs. Continuing the procedure in the same way for nodes 8, 7, . . . , 1 we finally obtain the
payoff vector p(1) = (4, 1, 4) and equilibrium path 1 4 9 20.
Exercises
10.1-1 An entrepreneur (E) enters to a market, which is controlled by a chain store
(C). Their competition is a two-person game. The strategies of the chain store are
soft (S), when it allows the competitor to operate or tough (T), when it tries to drive
out the competitor. The strategies of the entrepreneur are staying in (I) or leaving
(L) the market. The payoff tables of the two player are assumed to be
I L I L
S 2 5 S 2 1
T 0 5 T 0 1
payoffs of C payoffs of E
10.1. Finite games 439
(5, 1)
L
E S (2, 2)
I C
T (0, 0)
player P2
0 1 2 3
0
1 23 13
player P1
2 2 31 35 43
3 3 2 43
10.1-3 Assume that in the previous problem the payoff of the second player is the
negative of the payoff of the salesman. Give a complete description of the number
of equilibria as a function of the parameter values , , . Determine the equilibria
in all cases.
10.1-4 Assume that the payoff function of the equipment is its value (V if all parts
are good, and zero otherwise) in the previous exercise. Is there an equilibrium point?
10.1-5 Exercise 10.1-1 can be represented by the tree shown in Figure 10.4.
Find the equilibrium with backward induction.
10.1-6 Show that in the one-player case backward induction reduces to the classical
dynamic programming method.
10.1-7 Assume that in the tree of a game some nodes are so called chance nodes"
from which the game continuous with given probabilities assigned to the possible
next nodes. Show the existence of the equilibrium for this more general case.
10.1-8 Consider the tree given in Figure 10.3, and double the payoff values of player
P1 , change the sign of the payoff values of player P2 , and do not change those for
Player P3 . Find the equilibrium of this new game.
440 10. Game Theory
which is the set of the best choices of player Pk with given strategies s1 , s2 , . . . , sk1 ,
sk+1 , . . . , sN of the other players. Note that Bk (s) does not depend on sk , it depends
only on all other strategies sl , k 6= l. P There is no guarantee that maximum exists
for all s S1 S2 P SN . Let S be the subset of S such that Bk (s)
exists for all k and s . A simultaneous P strategy vector s? = (s?1 , s?2 , . . . , s?N ) is
an equilibrium if and only if s , and s?k Bk (s? ) for all k. By introducing
?
the best reply mapping, Bk (s) = (B1 (s), . . . , BN (s)) we can further simplify the
above reformulation:
P
Theorem 10.2 Vector s? is equilibrium if and only if s? and s? B(s? ).
Example 10.4 Consider a 2-person game, N = 2, with strategy sets S1 = S2 = [0, 1], and
payoff functions f1 (s1 , s2 ) = s1 s2 2s21 + 5, and f2 (s1 , s2 ) = s1 s2 2s22 + s2 + 3. We will
first find the best responses of both players. Both payoff functions are concave parabolas
10.2. Continuous games 441
Example 10.5 Consider a portion of a sea-channel, assume it is the unit interval [0, 1].
Player P2 is a submarine hiding in location s2 [0, 1], player P1 is an airplane drop-
2
ping a bomb at certain location s1 [0, 1] resulting in a damage e(s1 s2 ) to the
submarine. Hence a special two-person game is defined in which S1 = S2 = [0, 1],
2
f1 (s1 , s2 ) = e(s1 s2 ) and f2 (s1 , s2 ) = f1 (s1 , s2 ). With fixed s2 , f1 (s1 , s2 ) is max-
imal if s1 = s2 , therefore the best response of player P1 is B1 (s) = s2 . Player P2 wants to
minimize f1 which occurs if |s1 s2 | is as large as possible, which implies that
(
1, if s1 < 1/2,
B2 (s) = 0, if s1 > 1/2,
{0, 1}, if s1 = 1/2.
Clearly, there is no (s1 , s2 ) [0, 1][0, 1] such that s1 = B1 (s) and s2 B2 (s), consequently
no equilibrium exists.
for all s = (s1 , . . . , sN ) and z = (z1 , . . . , zN ) from S and some r = (r1 , r2 , . . . , rN ) >
0.
for all z S.
442 10. Game Theory
Proof Assume first that s? is an equilibrium, then inequality (10.1) holds for all
k and sk Sk . Adding the rk -multiples of these relations for k = 1, 2, . . . , N we
immediately have (10.5).
Assume next that (10.5) holds for all z S. Select any k and sk Sk , define
z = (s?1 , . . . , s?k1 , sk , s?k+1 , . . . , s?N ), and apply inequality (10.5). All but the k-th
terms cancel and the remaining term shows that inequality (10.1) holds. Hence s?
is an equilibrium.
Since (s, s) = 0 for all s S, relation (10.6) holds if and only if s? (s? ), that is
s? is a fixed-point of mapping : S 2S . Therefore any method to find fixed point
is applicable for computing equilibria.
The computation cost depends on the type and size of the fixed point problem
and also on the selected method.
Example 10.6 Consider again the problem of Example 10.4. In this case
f1 (z1 , s2 ) = z1 s2 2z12 + 5 ,
f2 (s1 , z2 ) = s1 z2 2z22 + z2 + 3 ,
so the aggregate function has the form with r1 = r2 = 1 :
Hr (s, z) = z1 s2 2z12 + s1 z2 2z22 + z2 + 8 .
Therefore
Hr (s, s) = 2s1 s2 2s21 2s22 + s2 + 8 ,
and
(s, z) = z1 s2 2z12 + s1 z2 2z22 + z2 2s1 s2 + 2s21 + 2s22 s2 .
Notice that this function is strictly concave in z1 and z2 , and is separable in these variables.
At the stationary points:
= s2 4z1 = 0
z1
= s1 4z2 + 1 = 0
z2
implying that at the optimum
s2 s1 + 1
z1 = and z2 = ,
4 4
since both right hand sides are feasible. At the fixed point:
s2 s1 + 1
s1 = and s2 = ,
4 4
10.2. Continuous games 443
uk 0
gk (sk ) 0
(10.9)
k fk (s) + ukT k gk (sk ) = 0T
ukT gk (sk ) = 0,
Theorem 10.5 If s? is an equilibrium, then there are vectors uk? such that relations
(10.9) are satisfied.
Example 10.7 Consider again the two-person game of the previous example. Clearly,
subjective to uk 0
(10.10)
gk (sk ) 0
k fk (s) + ukT k gk (sk ) = 0 .
10.2. Continuous games 445
The two first constraints imply that the objective function is nonnegative, so is
the minimal value of it. Therefore system (10.9) has feasible solution if and only if
the optimal value of the objective function of problem (10.10) is zero, and in this
case any optimal solution satisfies relations (10.9).
Theorem 10.6 The N -person game has equilibrium only if the optimal value of
the objective function is zero. Then any equilibrium is optimal solution of problem
(10.10). If in addition all components of gk are concave and fk is concave in sk for
all k, then any optimal solution of problem (10.10) is equilibrium.
Hence the equilibrium problem of the N -person game has been reduced to finding
the optimal solutions of this (usually nonlinear) optimization problem. Any nonlinear
programming method can be used to solve the problem.
The computation cost in solving the optimization problem (10.10) depends on
its type and the chosen method. For example, if (10.10) is an LP, and solved by the
simplex method, then the maximum number of operations is exponential. However
in particular cases the procedure terminates with much less operations.
Example 10.8 In the case of the previous problem the optimization problem has the
following form:
Mixed extension of finite games We have seen earlier that a finite game does
not necessary have equilibrium. Even if it does, in the case of repeating the game
many times the players wish to introduce some randomness into their actions in order
to make the other players confused and to seek an equilibrium in the stochastic sense.
This idea can be modeled by introducing probability distributions as the strategies
of the players and the expected payoff values as their new payoff functions.
Keeping the notation of Section 10.1. assume that we have N players, the finite
(1) (n )
strategy set of player Pk is Sk = {sk , . . . , sk k }. In the mixed extension of this
finite game each player selects a discrete probability distribution on its strategy set
and in each realization of the game an element of Sk is chosen according to the
446 10. Game Theory
which is the set of all nk -element probability vectors. The new payoff function of
this player is the expected value:
f k (x1 , . . . , xN ) =
X n2
n1 X nN
X (i ) (i ) (i ) (i ) (i ) (i )
... fk (s1 1 , s2 2 , . . . , sNN )x1 1 x2 2 . . . xNN . (10.12)
i1 =1 i2 =1 iN =1
(i)
Notice that the original pure strategies sk can be obtained by selecting xk as the
k-th basis vector. This is a continuous game and as a consequence of Theorem 10.3
it has at least one equilibrium. Hence if a finite game is without an equilibrium, its
mixed extension has always at least one equilibrium, which can be obtained by using
the methods outlined in the previous sections.
Example 10.9 Consider the two-person case in which N = 2, and as in section 10.1
(i) (j) (i) (j)
introduce matrices A(1) and A(2) with (i, j) elements f1 (s1 , s2 ) and f2 (s1 , s2 ). In this
special case
X X
n1 n2
(k) (1) (2)
f k (x1 , x2 ) = aij xi xj = x1T A(k) x2 . (10.13)
i=1 j=1
so we may select
(1)
xk
..
.
gk (xk ) = (nk )
xk . (10.14)
Pnk (i)
xk 1
Pi=1
nk (i)
i=1 xk + 1
The optimization problem (10.10) now reduces to the following:
P2 nkP (i) (i) (n +1) nk P
(j) (nk +2) Pnk (j)
minimize k=1
[ i=1 uk xk + uk k ( j=1 xk 1) + uk ( j=1
xk + 1)]
(i)
subject to uk 0 (1 i nk + 2)
(i)
xk 0 (1 i nk )
1T xk = 1
(n +1) (n +2)
x2T (A(1) )T + vT1 + (u1 1 u1 1 )1T1 = 0T1
T (2) T (n2 +1) (n2 +2)
x1 (A ) + v2 + (u2 u2 )1T2 = 0T2 ,
(10.15)
10.2. Continuous games 447
(1) (nk )
where vTk = (uk , . . . .uk ), 1Tk = (1(1) , . . . , 1(nk ) ) and 0Tk = (0(1) , . . . , 0(nk ) ), k = 1, 2 .
Bimatrix games. Mixed extensions of two-person finite games are called bi-
matrix games. They were already examined in Example 10.9. For notational con-
venience introduce the simplifying notation:
implying that
v1T = 1Tm yT AT and v2T = 1Tn xT B , (10.17)
so we may rewrite the objective function again:
= + xT (A + B)y ,
since
1Tm x = 1Tn y = 1 .
Hence we have the following quadratic programming problem:
maximize xT (A + B)y
subject to x0
y0
1Tm x = 1 (10.18)
1Tn y = 1
Ay 1m
BT x 1n ,
where the last two conditions are obtained from (10.17) and the nonnegativity of
vectors v1 , v2 .
448 10. Game Theory
Theorem 10.7 Vectors x? and y? are equilibria of the bimatrix game if and only
if with some ? and ? , (x? , y? , ? , ? ) is optimal solution of problem (10.18). The
optimal value of the objective function is zero.
where x = (x1 , x2 )T and y = (y1 , y2 )T . We also know from Theorem 10.7 that the optimal
objective function value is zero, therefore any feasible solution with zero objective function
value is necessarily optimal. It is easy to see that the solutions
1 0
x= , y= , = 2, = 1 ,
0 1
0 1
x= , y= , = 1, = 2 ,
1 0
0.6 0.4
x= , y= , = 0.2, = 0.2
0.4 0.6
One might apply relations (10.9) to find equilibria by solving the equality-
inequality system instead of solving an optimization problem. In the case of bimatrix
10.2. Continuous games 449
xT Ay =
xT By =
Ay 1m
BT x 1n (10.19)
x 0m
y 0n
1Tm x = 1Tn y = 1,
which can be proved along the lines of the derivation of the quadratic optimization
problem.
The computation cost of the solution of system (10.19) depends on the particular
method being selected.
Example 10.11 Consider again the bimatrix game of the previous example. Substitute the
first and second constraints = xT Ay and = xT By into the third and fourth condition
to have
2y1 y2 2x1 y1 x1 y2 x2 y1 + x2 y2
y1 + y2 2x1 y1 x1 y2 x2 y1 + x2 y2
x1 x2 x1 y1 x1 y2 x2 y1 + 2x2 y2
x1 + 2x2 x1 y1 x1 y2 x2 y1 + 2x2 y2
x1 , x2 , y1 , y2 0
x1 + x2 = y1 + y2 = 1.
It is easy to see that the solutions given in the previous example solve this system, so they
are equilibria.
0 1m Ay 1m u 1m x
0 1n BT x 1n v 1n y
x 0m (10.20)
y 0n
1Tm x = 1Tn y = 1,
satisfied. Define
1, if xi > 0 , 1, if yj > 0 ,
ui = and vj =
0, if xi = 0 , 0, if yj = 0 .
Since all elements of A and B are between 0 and 1, the values = xT Ay and
= xT By are also between 0 and 1. Notice that
0 x u 1m and 0 y v 1n .
implying that = xT Ay. We can similarly show that = xT By. Thus (10.19) is
satisfied, so, x, y is an equilibrium.
The computation cost of the solution of system (10.20) depends on the particular
method being seleced.
Example 10.12 In the case of the bimatrix game introduced earlier in Example 10.10 we
have the following:
0 2y1 + y2 1 u1 1 x1
0 + y1 y2 1 u2 1 x2
0 x1 + x2 1 v1 1 y1
0 + x1 2x2 1 v2 1 y2
x1 + x2 = y1 + y2 = 1
x1 , x2 , y1 , y2 0
u1 , u 2 , v 1 , v 2 {0, 1} .
Notice that all three solutions given in Example 10.10 satisfy these relations with
minimize +
subject to x0
y0
1m x = 1 (10.21)
1n y = 1
Ay 1m
AT x 1n .
From this formulation we see that the set of the equilibrium strategies is a convex
polyhedron. Notice that variables (x, ) and (y, ) can be separated, so we have the
following result.
Theorem 10.9 Vectors x? and y? give an equilibrium of the matrix game if and
only if with some ? and ? , (x? , ? ) and (y? , ? ) are optimal solutions of the linear
programming problems:
minimize minimize
subject to y 0n subject to x 0m
(10.22)
1Tn y = 1 1Tm x = 1
Ay 1m AT x 1n .
Notice that at the optimum, + = 0. The optimal value is called the value of
the matrix game.
Solving problem (10.22) requires exponential number of operations if the simplex
method is chosen. With polynomial algorithm (such as the interior point method)
the number of operations is only polynomial.
The application of the simplex method shows that the optimal solutions are = 9/7,
y = (3/7, 3/7, 1/7)T , = 9/7, and x = (4/7, 4/21, 5/21)T .
We can also obtain the equilibrium by finding feasible solutions of a certain set
452 10. Game Theory
x, y 0
1Tm x = 1
1Tn y = 1 (10.23)
Ay 1m
AT x 1n .
The first phase of the simplex method has to be used to solve system (10.23),
where the number of operations might be experimental. However in most practical
examples much less operations are needed.
Example 10.14 Consider again the matrix game of the previous example. In this case
system (10.23) has the following form:
x1 , x2 , x3 , y1 , y2 , y3 0
x1 + x2 + x3 = y1 + y2 + y3 = 1
2y1 + y2
2y1 + 3y3
y1 + 3y2 + 3y3
2x1 + 2x2 x3
x1 + 3x3
3x2 + 3x3 .
It is easy to see that = 9/7, x = (4/7, 4/21, 5/21)T , y = (3/7, 3/7, 1/7)T satisfy these
relations, so x, y is an equilibrium.
Let then
1
xk = ((k 1)xk1 + xk ) , (10.27)
k
and select yk = ejk so that
By repeating the general step for k = 2, 3, . . . two sequences are generated: {xk },
and {yk }. We have the following result:
Matrix-Equilibrium(A, xT1 )
1 k1
2 define j1 such that x1T Aej1 = minj {x1T Aej }
3 y1 ej1
4 k k+1
1
5 yk1 k1 ((k 2)yk2 + yk1 )
6 define ik such that eTik Ayk1 = maxi {eTi Ayk1 }
7 xk eik
8 xk k1 ((k 1)xk1 + xk )
9 define jk such that xTk Aejk = minj {xTk Aej }
10 yk ejk
11 if ||xk xk1 || < and ||yk1 xk2 || <
12 then xk , yk1 is equilibrium
13 else go back to 4
Example 10.15 We applied the above method for the matrix game of the previous
example and started the procedure with x1 = (1, 0, 0)T . After 100 steps we obtained
x101 = (0.446, 0.287, 0.267)T and y101 = (0.386, 0.436, 0.178)T . Comparing it to the true
values of the equilibrium strategies we see that the error is below 0.126, showing the very
slow convergence of the method.
454 10. Game Theory
x1 , x2 0
x1 + x2 = 1
x2 0
x1 0.
Clearly the only solution is x1 = 1 and x2 = 0, that is the first pure strategy.
We will see in the next subsection that linear programming problems are equiva-
lent to symmetric matrix games so any method for solving such games can be applied
to solve linear programming problems, so they serve as alternative methodology to
the simplex method. As we will see next, symmetry is not a strong assumption, since
any matrix game is equivalent to a symmetric matrix game.
Consider therefore a matrix game with matrix A, and construct the skew-
symmetric matrix
0mm A 1m
P = AT 0nn 1n ,
T
1m 1n T
0
where all components of vector 1 equal 1. Matrix games A and P are equivalent in the
following sense. Assume that A > 0, which is not a restriction, since by adding the
same constant to all element of A they become positive without changing equilibria.
Theorem 10.12
u
1. If z = v is an equilibrium strategy of matrix game P then with a =
(1 )/2, x = (1/a)u and y = (1/a)v is an equilibrium of matrix game A with
value v = /a;
10.2. Continuous games 455
uT Av uT 1m 0,
T T T
v A u + u 1n 0
v T 1n u T 1m 0 ,
and combining this relation with the third inequality of (10.30) we see that 1Tm u
1Tn v = 0.
Select a = (1 )/2 6= 0, then 1Tm u = 1Tn v = a, so both x = u/a, and y = v/a
are probability vectors, furthermore from (10.30),
1 T
AT x = aA u a 1n ,
1
Ay = a Av a 1m .
Av b 0
AT u + c 0 (10.32)
bT u cT v 0 .
Since z 0 and > 0, both vectors x = (1/)v, and y = (1/)u are nonnegative,
and by dividing the first two relations of (10.32) by ,
Ax b and AT y c ,
showing that x and y are feasible for the primal and dual, respectively. From the
last condition of (10.32) we have
bT y cT x .
However
bT y (xT AT )y = xT (AT y) xT c = cT x ,
consequently, bT y = cT x, showing that the primal and dual objective functions are
equal. The duality theorem implies the optimality of x and y.
maximize x1 + 2x2
subject to x1 0
x1 + x2 1
5x1 + 7x2 25 .
10.2. Continuous games 457
First we have to rewrite the problem as a primal problem. Introduce the new variables:
x2 , if x2 0 ,
x+
2 =
0 otherwise ,
x2 , if x2 < 0 ,
x
2 =
0 otherwise .
and multiply the -type constraint by 1. Then the problem becomes the following:
maximize x1 + 2x+
2 2x2
subject to x1 , x+
2 , x2 0
x1 x+
2 + x2 1
5x1 + 7x+
2 7x2 25 .
Hence
1 1 1 1
A= , b= , cT = (1, 2, 2),
5 7 7 25
and so matrix P becomes:
.. ..
0 0 . 1 1 1 . 1
.. ..
0 0 . 5 7 7 . 25
.. ..
1 5 . 0 0 0 . 1
P=
.
.. ..
1 7 . 0 0 0 . 2
.. ..
1 7 . 0 0 0 . 2
.. ..
1 25 . 1 2 2 . 0
For arbitrary probability vector y0 solve the following nonlinear initial-value prob-
lem:
Since the right-hand side is continuous, there is at least one solution. The right hand
side of the equation can be interpreted as follows. Assume that (uj (y(t))) > 0. If
player P2 selects strategy y(t), then player P1 is able to obtain a positive payoff
by choosing the pure strategy ej , which results in a negative payoff for player P2 .
However if player P2 increases yj (t) to one by choosing the same strategy ej its
payoff eTj Pej becomes zero, so it increases. Hence it is the interest of player P2 to
increase yj (t). This is exactly what the first term represents. The second term is
needed to ensure that y(t) remains a probability vector for all t 0.
The computation of the right hand side of equations (10.34) for all t requires
n2 + n multiplications. The total computation cost depends on the length of solution
interval, on the selected step size, and on the choice of the differential equation
solver.
Proof First we have to show that y(t) is a probability vector for all t 0. Assume
that with some j and t1 > 0, yj (t1 ) < 0. Define
Since yj (t) is continuous and yj (0) 0, clearly yj (t0 ) = 0, and for all (t0 , t1 ),
yj ( ) < 0. Then for all (t0 , t1 ],
and the Lagrange mean-value theorem implies that with some (t0 , t1 ),
X n X n
d
(ui (y(t))) = pij yj0 (t) = pij [(uj (y(t))) (y(t))yj (t)]
dt j=1 j=1
n
(10.36)
X
= pij (uj (y(t))) (y(t))(ui (y(t))) .
j=1
By multiplying both sides by (ui (y(t))) and adding the resulted equations for
i = 1, 2, . . . , n we have:
n
X XX n n
d
(ui (y(t))) (ui (y(t))) = pij (ui (y(t)))(uj (y(t)))
i=1
dt i=1 j=1
(10.37)
Xn
(y(t))( 2 (ui (y(t)))) .
i=1
The first term is zero, since P is skew-symmetric. Notice that this equation re-
mains valid even as (ui (y(t))) = 0 except the break-points (where the derivative of
(ui (y(t))) does not exist) since (10.36) remains true.
Assume next that with a positive t, (y(t)) = 0. Then for all i, (ui (y(t))) = 0.
Since equation (10.37) can be rewritten as
1 d
(y(t)) = (y(t))(y(t)) (10.38)
2 dt
with
n
X
: Rn R and (y(t)) = 2 (ui (y(t))) ,
i=1
we see that (y(t)) satisfies a homogeneous equation with zero initial solution at t,
so the solution remains zero for all t. Therefore (ui (y( ))) = 0 showing that
Py( ) 0, that is, y( ) is equilibrium strategy.
If (y(t)) > 0 for all t 0, then (y(t)) > 0, and clearly
1 d p
(y(t)) (y(t))(y(t)) ,
2 dt
that is
1 d 3
(y(t))((y(t))) 2 1 .
2 dt
460 10. Game Theory
(y(t))(1/2) + c t ,
1
((y(t)))1/2 . (10.39)
c+t
which is valid even at the break points because of the continuity of functions ui . And
finally, take a sequence {y(tk )} with tk increasingly converging to . The sequence
is bounded (being probability vectors), so there is at least one cluster point y? . From
(10.40), by letting tk we have that Py? 0 showing that y? is an equilibrium
strategy.
which was the subject of our earlier Example 10.13 In order to apply the method of von
Neumann we have to find first an equivalent symmetric matrix game. The application of
the method given in Theorem 10.12. requires that the matrix has to be positive. Without
changing the equilibria we can add 2 to all matrix elements to have
!
4 3 2
Anew = 4 2 5 ,
1 5 5
The differential equations (10.34) were solved by using the 4th order RungeKutta method
in the interval [0, 100] with the step size h = 0.01 and initial vector y(0) = (1, 0, . . . , 0)T .
From y(100) we get the approximations
Theorem 10.15 Under the above conditions the game has exactly one equilibrium.
Proof The existence of the equilibrium follows from Theorem 10.3. In proving
uniqueness assume that s(1) and s(2) are both equilibria, and both satisfy relations
(10.9). Therefore for l = 1, 2,
(l) T (l)
uk gk (sk ) = 0
(l)T (l)
k fk (s(l) ) + uk k gk (sk ) = 0T ,
462 10. Game Theory
(l) (l)
where ukj and gkj are the jth components of uk and gk , respectively. Multiplying
(2) (1) (1) (2)
(10.43) by (rk (sk sk )T ) for l = 1 and by rk (sk sk )T for l = 2 and adding
the resulted equalities for k = 1, 2, . . . , N we have
Notice that the sum of the first two terms is positive by the diagonally strict con-
cavity of the game, the concavity of the components of gk implies that
and
(1) (2) (2) (1) (2)
(sk sk )T k gkj (sk ) gkj (sk ) gkj (sk ) .
Therefore from (10.44) we have
mk
N X
X (1) (2) (1) (2) (1) (2)
0> rk [ukj (gkj (sk ) gkj (sk )) + ukj (gkj (sk ) gkj (sk ))]
k=1 j=1
mk
N X
X (1) (2) (2) (1)
= rk [ukj gkj (sk ) + ukj gkj (sk )] 0 ,
k=1 j=1
Proof Let s(1) 6= s(2) , s(1) , s(2) S. Then for all [0, 1], s() = s(1) + (1
)s(2) S and
d
h(s(), r) = J(s(), r)(s(1) s(2) ) .
d
Integrate both side in [0, 1] to have
Z 1
(1) (2)
h(s , r) h(s , r) = J(s(), r)(s(1) s(2) )d ,
0
Example 10.20 Consider a simple two-person game with strategy sets S1 = S2 = [0, 1],
and payoff functions
f1 (s1 , s2 ) = s21 + s1 s1 s2
and
f2 (s1 , s2 ) = s22 + s2 s1 s2 .
Clearly all conditions, except diagonally strict concavity, are satisfied. We will use Theorem
10.16 to show this additional property. In this case
1 f1 (s1 , s2 ) = 2s1 + 1 s2 , 2 f2 (s1 , s2 ) = 2s2 + 1 s1 ,
so
r1 (2s1 + 1 s2 )
h(s, r) =
r2 (2s2 + 1 s1
with Jacobian
2r1 r1
J(s, r) = .
r2 2r2
We will show that
4r1 r1 r2
J(s, r) + J(s, r)T =
r1 r2 4r2
is negative definite with some r 0. For example, select r1 = r2 = 1, then this matrix
becomes
4 2
2 4
with characteristic polynomial
4 2
() = det = 2 + 8 + 12 ,
2 4
having negative eigenvalues 1 = 2, 2 = 6.
464 10. Game Theory
for all s S, where Hr is the aggregation function (10.4). In the following analysis
we assume that the N -person game satisfies all conditions presented at the beginning
of Subsection 10.2.9 and (10.42) holds with some positive r.
We first show the equivalence of (10.45) and a variational inequality.
Hr (s? , s? ) Hr (s? , s) h(s, r)T (s? s) h(s, r)T (s? s) + h(s? , r)T (s s? ) > 0 ,
so s? satisfies (10.45).
Hence any method available for solving variational inequalities can be used to
find equilibria.
Next we construct a special two-person, game the equilibrium problem of which
is equivalent to the equilibrium problem of the original N -person game.
Proof
Assume first that s? S satisfies (10.45). Then it satisfies (10.46) as well, so
f (s, s? ) 0 = f (s? , s? ).
f (s? , s) 0 = f (s? , s? ).
0 > f (s? , s) = h(s, r)T (s? s) > h(s, r)T (s? s) + (s s? )T (h(s, r) h(s? , r))
= h(s? , r)T (s? s) 0,
Continuous-Equilibrium
1 k1
2 solve problem (10.47), let s(2) be optimal solution
3 if f (s(2) , s(1) ) = 0
4 then s(1) is equilibrium
5 return s(1)
6 k k+1
7 solve problem (10.48), let s(k+1) be optimal solution
8 if ||s(k+1) s(k) || <
9 then s(k+1) is equilibrium
10 return s(k+1)
11 else go to 5
466 10. Game Theory
Before stating the convergence theorem of the algorithm we notice that in the
special case when the strategy sets are defined by linear inequalities (that is, all
functions gk are linear) then all constraints of problem (10.48) are linear, so at each
iteration step we have to solve a linear programming problem.
In this linear case the simplex method has to be used in each iteration step with
exponential computational cost, so the overall cost is also exponential (with prefixed
number of steps).
Theorem 10.19 There is a subsequence {s(ki ) } of {s(k) } generated by the method
that converges to the unique equilibrium of the N -person game.
Proof The proof consists of several steps.
First we show that k 0 as k . Since at each new iteration an addi-
tional constraint is added to (10.48), sequence {k } is nonincreasing. Since it is also
nonnegative, it must be convergent. Sequence {s(k) } is bounded, since it is from the
bounded set S, so it has a convergent subsequence {s(ki ) }. Notice that from (10.48)
we have
0 ki 1 = min h(s(k) , r)T (s(ki ) s(k) ) h(s(ki1 ) , r)T (s(ki ) s(ki1 ) ) ,
1kki 1
where the right hand side tends to zero. Thus ki 1 0 and since the entire sequence
{k } is monotonic, the entire sequence converges to zero.
Let next s? be an equilibrium of the N -person game, and define
(t) = min{(h(s, r) h(z, r))T (z s)|ks zk t, z, s S} . (10.49)
By (10.42), (t) > 0 for all t > 0. Define the indices ki so that
(ks(ki ) s? k) = min (ks(k) s? k) (i = 1, 2, . . .) ,
1ki
1. (t) is continuous in t;
2. (t) > 0 if t > 0 (as it was shown just below relation (10.49));
3. if for a convergent sequence {t(k) }, (t(k) ) 0, then necessarily t(k) 0.
By applying property 3. with sequence {ks(ki ) s? k} it is clear that ks(ki ) s? k 0
so s(ki ) s? . Thus the proof is complete.
Exercises
10.2-1 Consider a 2-person game with strategy sets S1 = S2 = [0, 1], and payoff
functions f1 (x1 , x2 ) = x21 + x1 x2 + 2 and f2 (x1 , x2 ) = x1 + x2 . Show the existence
of a unique equilibrium point by computing it. Show that Theorem 10.3. cannot be
applied to prove existence.
10.2-2 Consider the price war" game in which two firms are price setting. Assume
that p1 and p2 are the strategies of the players, p1 , p2 [0, pmax ] and the payoff
functions are:
p1 , if p1 p2 ,
f1 (p1 , p2 ) =
p1 c, if p1 > p2 ,
p2 , if p2 p1 ,
f2 (p1 , p2 ) =
p2 c, if p2 > p1 ,
by assuming that c < pmax . Is there an equilibrium? How many equilibria were
found?
10.2-3 A portion of the sea is modeled by the unit square in which a submarine
is hiding. The strategy of the submarine is the hiding place x [0, 1] [0, 1]. An
airplane drops a bomb in a location y = [0, 1] [0, 1],j which is its strategy. The
payoff of the airplane is the damage ekxyk occurred by the bomb, and the payoff
of the submarine is its negative. Does this 2-person game have an equilibrium?
10.2-4 In the second-price auction they sell one unit of an item to N bidders.
They value the item as v1 < v2 < < vN . Each of them offers a price for the
item simultaneously without knowing the offers of the others. The bidder with the
highest offer will get the item, but he has to pay only the second highest price. So
the strategy of bidder k is [0, ], so xk [0, ], and the payoff function for this
bidder is:
vk maxj6=k xj , if xk = maxj xj ,
fk (x1 , x2 , . . . , xN ) =
0 otherwise .
What is the best response function of bidder k? Does this game have equilibrium?
10.2-5 Formulate Fans inequality for Exercise 10.2-1
10.2-6 Formulate and solve Fans inequality for Exercise 10.2-2.
10.2-7 Formulate and solve Fans inequality for Exercise 10.2-4.
10.2-8 Consider a 2-person game with strategy sets S1 = S2 = [0, 1], and payoff
functions
f1 (x1 , x2 ) = (x1 x2 )2 + 2x1 x2 + 1
f2 (x1 , x2 ) = (x1 2x2 )2 2x1 + x2 1 .
468 10. Game Theory
maximize x1 + x2
subject to x1 , x2 0
3x1 + x2 4
x1 + 3x2 4 .
10.3. The oligopoly problem 469
10.2-27 Solve the LP problem given in Example 8.17 by the method of fictitious
play.
10.2-28 Solve Exercise 10.2-21 by the method of von Neumann.
10.2-29 Solve Exercise 10.2-24 by the method of von Neumann.
10.2-30 Solve Exercise 10.2-17 by the method of von Neumann.
10.2-31? Check the solution obtained in the previous exercises by verifying that all
constraints of (10.21) are satisfied with zero objective function. Hint. What and
should be selected?
10.2-32 Solve exercise 10.2-26 by the method of von Neumann.
10.2-33 Let N = 2, S1 = S2 = [0, 10], f1 (x1 , x2 ) = f2 (x1 , x2 ) = 2x1 + 2x2 (x1 +
x2 )2 . Show that both payoff functions are strictly concave in x1 and x2 respectively.
Prove that there are infinitely many equilibria, that is , the strict concavity of the
payoff functions does not imply the uniqueness of the equilibrium.
10.2-34 Can matrix games be strictly diagonally concave?
10.2-35 Consider a two-person game with strategy sets S1 = S2 = [0, 1], and payoff
functions f1 (x1 , x2 ) = 2x21 + x1 (1 x2 ), f2 (x1 , x2 ) = 3x22 + x2 (1 x1 ). Show that
this game satisfies all conditions of Theorem 10.16.
10.2-36 Solve the problem of the previous exercise by algorithm (10.47)(10.48).
P
Best reply mappings. Notice that with the notation sk = l6=k xl , the payoff
function of player Pk can be rewritten as
Since Sk is a compact set and this function is strictly concave in xk , with fixed sk
there is a unique profit maximizing production level of player Pk , which is its best
reply and is denoted by Bk (sk ).
It is easy to see that there are three cases: Bk (sk ) = 0 if p(sk ) c0k (0) 0,
Bk (sk ) = Lk if p(sk + Lk ) + Lk p0 (sk + Lk ) c0k (Lk ) 0, and otherwise Bk (sk ) is
the unique solution of the monotonic equation
which is also true for the other two cases except for the break points.
As in Subsection 10.2.1. we can introduce the best reply mapping:
X X
B(x1 , . . . , xN ) = B1 xl , . . . , BN xl (10.53)
l6=1 l6=N
and look for its fixed points. Another alternative is to introduce dynamic process
which converges to the equilibrium.
Similarly to the method of fictitious play a discrete system can be developed in
which each firm selects its best reply against the actions of the competitors chosen
at the previous time period:
X
xk (t + 1) = Bk ( xl (t)) (k = 1, 2, . . . , N ) . (10.54)
l6=k
Based on relation (10.52) we see that for N = 2 the right hand side mapping R2 R2
is a contraction, so it converges, however if N > 2, then no convergence can be
established. Consider next a slight modification of this system: with some Kk > 0:
X
xk (t + 1) = xk (t) + Kk (Bk ( xl (t)) xk (t)) (10.55)
l6=k
for k = 1, 2, . . . , N . Clearly the steady-states of this system are the equilibria, and it
10.3. The oligopoly problem 471
can be proved that if Kk is sufficiently small, then sequences xk (0), xk (1), xk (2), . . .
are all convergent to the equilibrium strategies.
Consider next the continuous counterpart of model (10.55), when (similarly to
the method of von Neumann) continuous time scales are assumed:
X
xk (t) = Kk (Bk ( xl (t)) xk (t)) (k = 1, 2, . . . , N ) . (10.56)
l6=k
Proof It is sufficient to show that the eigenvalues of the Jacobian of the system
have negative real parts. Clearly the Jacobian is as follows:
K1 K 1 b1 K 1 b1
K 2 b2 K2 K2 b2
J= .. .. .. , (10.57)
. . .
K N bN K N bN KN
P
where bk = Bk0 ( l6=k xl ) at the equilibrium. From (10.52) we know that 1 < bk 0
for all k. In order to compute the eigenvalues of J we will need a simple but very
useful fact. Assume that a and b are N -element real vectors. Then
where I is the N N identity matrix. This relation can be easily proved by using
finite induction with respect to N . By using (10.58), the characteristic polynomial
of J can be written as
The roots of the first factor are all negative: = Kk (1 + bk ), and the other
472 10. Game Theory
N
X K k bk
1+ = 0.
Kk (1 + bk )
k=1
Notice that by adding the terms with identical denominators this equation becomes
m
X k
1+ =0 (10.59)
k +
l=1
with k , k > 0, and the k s are different. If g() denotes the left hand side then
clearly the values = k are the poles,
so g() strictly decreases locally. The graph of the function is shown in Figure 10.3.
Notice first that (10.59) is equivalent to a polynomial equation of degree m, so there
are m real or complex roots. The properties of function g() indicate that there is
one root below 1 , and one root between each k and k+1 (k = 1, 2, . . . , m1).
Therefore all roots are negative, which completes the proof.
The general discrete model (10.55) can be examined in the same way. If Kk = 1
for all k, then model (10.55) reduces to the simple dynamic process (10.54).
ck (xk ) = kx3k + xk (k = 1, 2, 3) .
The best reply of play k can be obtained as follows. Following the method outlined at the
beginning of Section 10.3 we have the following three cases. If 1 2sk s2k 0, then xk = 0
is the best choice. If (63k)6sk s2k 0, then xk = 1 is the optimal decision. Otherwise
xk is the solution of equation
[xk (2 2xk 2sk s2k 2sk xk x2k ) kx3k xk ]
xk
= 2 4xk 2sk s2k 4sk xk 3x2k 3kx2k 1 = 0 ,
10.3. The oligopoly problem 473
g()
1 2 m1 m
After the best replies are found, we can easily construct any of the methods presented
before.
and define
has been reduced to find fixed points of only one-dimensional mappings. This is
a significant reduction in the difficulty of the problem, since best replies are N -
dimensional mappings.
If conditions 13 are satisfied, then Xk (s) has exactly one element for all s and
k:
0, if p(s) c0k (0) 0 ,
X(s) = Lk , if p(s) + Lk p0k (s) c0k (Lk ) 0 , (10.63)
?
z otherwise ,
where z ? is the unique solution of the monotonic equation
in the interval (0, Lk ). In the third case, the left hand side is positive at z = 0,
negative at z = Lk , and by conditions 23, it is strictly decreasing, so there is a
unique solution. PN
In the entire interval [0, k=1 Lk ], Xk (s) is nonincreasing. In the first two cases
it is constant and in the third case strictly decreasing. Consider finally the single-
dimensional equation
XN
Xk (s) s = 0 . (10.65)
k=1
PN
At s = 0 the left hand side is nonnegative, at s = k=1 Lk it is nonpositive, and is
strictly decreasing. Therefore there is a unique solution (that is, fixed point of map-
ping X), which can be obtained by any method known to solve single-dimensional
equations.
Let [0, Smax ] be the initial interval for the solution of equation (10.65). After K
bisection steps the accuracy becomes Smax /2K , which will be smaller than an error
tolerance > 0 if K > log2 (Smax /).
Oligopoly-Equilibrium(p(s), X(s))
1 solve equation (10.65) for s
2 for k 1 to n
3 do solve equation (10.64), and let xk z
4 (x1 , . . . , xN ) is equilibrium
Example 10.22 Consider the 3-person oligopoly examined in the previous example. From
10.3. The oligopoly problem 475
(10.63) we have
(
0, if 1 2s s2 0,
X(s) = 1, if (1 + 3k) 4s s2 0,
z? otherwise,
where z ? is the unique solution of equation
3kz 2 + z(2s + 2) + (1 + 2s + s2 ) = 0.
The first case occurs for s 2 1, the second case never occurs, and in the third case
there is a unique positive solution:
p
? (2s + 2) + (2s + 2)2 12k(1 + 2s + s2 )
z = . (10.66)
6k
And finally equation (10.65) has the special form
p
X
3
(s + 1) + (s + 1)2 3k(1 + 2s + s2 )
s=0 .
3k
k=1
A single program based on the bisection method gives the solution s? 0.2982 and then
equation (10.66) gives the equilibrium strategies x?1 0.1077, x?2 0.0986, x?3 0.0919.
Example 10.23 In the case of the three-person oligopoly introduced in Example 10.21 we
have
X
3
(1) (2)
minimize (uk xk + uk (1 xk ))
k=1
(1) (2)
subject to uk , u k 0
xk 0
1 xk 0
(1) (2)
1 2s s2 2xk 2xk s 3kx2k + uk uk = 0
x1 + x2 + x3 = s.
fk
(x) vk + zk = 0 (10.72)
xk
and by the definition of the slack variables
zk xk = 0 (10.73)
10.3. The oligopoly problem 477
vk wk = 0 , (10.74)
and if we add the nonnegativity conditions
xk , zk , vk , wk 0 , (10.75)
t 0
g(t) 0 (10.76)
tT g(t) = 0.
Example 10.24 In the case of the 3-person oligopoly introduced and examined in the
previous examples we have:
P3 P3 P3
x1 1 + 2 l=1 xl + ( l=1 xl )2 + 2x1 + 2x1 l=1 xl + 3x21 + v1
P3 P3 P3
x2 1 + 2 l=1 xl + ( l=1 xl )2 + 2x2 + 2x2 l=1 xl + 6x22 + v2
P3 P3 P3
x3 2
1 + 2 l=1 xl + ( l=1 xl ) + 2x3 + 2x3 l=1 xl + 9x23 + v3
t = and g(t) = .
v1 1 x1
v2 1 x2
v3 1 x3
p(s) = As + B, ck (xk ) = bk xk + ck (k = 1, 2, . . . , N ) ,
478 10. Game Theory
where B, bk , and ck are positive, but A < 0. Assume again that the strategy set of
player Pk is the interval [0, Lk ]. In this special case
where we changed the order of them. Introduce the following vectors and matrixes:
2A A A B b1
A 2A A B b2
Q= . . . , B = . , b = . ,
.. .. .. .. ..
A A 2A B bN
v1 w1 z1 L1
v2 w2 z2 L2
v= .. , w= .. , z= .. , and L= .. .
. . . .
vN wN zN LN
Then the above relations can be summarized as:
Qx + B b v + z = 0
x+w = L
(10.79)
x T z = vT w = 0
x, v, z, w 0.
Next we prove that matrix Q is negative definite. With any nonzero vector a = (ai ),
X XX X X
aT Qa = 2A a2i + A ai aj = A( a2i + ( ai )2 ) < 0 ,
i i j6=i i i
and since the feasible set is a bounded linear polyhedron and the objective function
is strictly concave, the Kuhn-Tucker conditions are sufficient and necessary. Conse-
quently a vector x? is an equilibrium if and only if it is the unique optimal solution
of problem (10.80). There are standard methods to solve problem (10.80) known
from the literature.
Since (10.79) is a convex quadratic programming problem, several algorithms are
available. Their costs are different, so computation cost depends on the particular
method being selected.
Example 10.25 Consider now a duopoly (two-person oligopoly) where the price function
is p(s) = 10 s and the cost functions are c1 (x1 ) = 4x1 + 1 and c2 (x2 ) = x2 + 1 with
capacity limits L1 = L2 = 5. That is,
B = 10, A = 1, b1 = 4, b2 = 1, c1 = c2 = 1 .
Therefore,
2 1 10 4 5
Q= , B= , b= , L= ,
1 2 10 1 5
It is easy to see by simple differentiation that the global optimum at the objective function
without the constraints is reached at x?1 = 1 and x?2 = 4. They however satisfy the con-
straints, so they are the optimal solutions. Hence they provide the unique equilibrium of
the duopoly.
Exercises
10.3-1 Consider a duopoly with S1 = S2 = [0, 1], p(s) = 2 s and costs c1 (x) =
c2 (x) = x2 + 1. Examine the convergence of the iteration scheme (10.55).
10.3-2 Select n = 2, S1 = S2 = [0, 1.5], ck (xk ) = 0.5xk (k = 1, 2) and
1.75 0.5s, if 0 s 1.5 ,
p(s) = 2.5 s, if 1.5 s 2.5 ,
0, if 2.5 s .
10.3-3 Consider the duopoly of Exercise 10.3-1 above. Find the best reply mappings
of the players and determine the equilibrium.
10.3-4 Consider again the duopoly of the previous problem.
480 10. Game Theory
(a) Construct the one-dimensional fixed point problem of mapping (10.62) and solve
it to obtain the equilibrium.
(b) Formulate the Kuhn-Tucker equations and inequalities (10.69).
(c) Formulate the complementarity problem (10.76) in this case.
Chapter Notes
(Economic) Nobel Prize was given only once, in 1994 in the field of game theory. One
of the winner was John Nash , who received this honor for his equilibrium concept,
which was introduced in 1951 [184].
Backward induction is a more restrictive equilibrium concept. It was developed
by Kuhn and can be found in [148]. Since it is more restrictive equilibrium, it is also
a Nash equilibrium.
The existence and computation of equilibria can be reduced to those of fixed
points. the different variants of fixed point theorems-such as that of Brouwer [32],
Kakutani[129], Tarski [249] are successfully used to prove existence in many game
classes. The article [188] uses the fixed point theorem of Kakutani. The books [248]
and [76] discuss computer methods for computing fixed points. The most popular
existence result is the well known theorem of Nikaido and Isoda [188].
The Fan inequality is discussed in the book of Aubin [15]. The Kuhn-Tucker con-
ditions are presented in the book of Martos [169]. By introducing slack and surplus
variables the Kuhn-Tucker conditions can be rewritten as a system of equations. For
their computer solutions well known methods are available ([248] and [169]).
The reduction of bimatrix games to mixed optimization problems is presented in
the papers of Mills [177] and Shapiro [230]. The reduction to quadratic programming
problem is given in ([167]).
The method of fictitious play is discussed in the paper of Robinson [209]. In
order to use the Neumann method we have to solve a system of nonlinear ordinary
differential equations. The RungeKutta method is the most popular procedure for
doing it. It can be found in [248].
The paper of Rosen [210] introduces diagonally strictly concave games. The
computer method to find the equilibria of N -person concave games is introduced in
Zuhovitsky et al. [268].
The different extensions and generalizations of the classical Cournot model can
be found in the books of Okuguchi and Szidarovszky [190, 191]. The proof of The-
orem 10.20 is given in [247]. For the proof of Lemma (10.58) see the monograph
[191]. The bisection method is described in [248]. The paper [131] contains methods
which are applicable to solve nonlinear complementarity problems. The solution of
problem (10.80) is discussed in the book of Hadley [99].
The book of von Neumann and Morgenstern [186] is considered the classical
textbook of game theory. There is a large variety of game theory textbooks (see for
example [76]).
11. Recurrences
Fn+2 = Fn+1 + Fn , if n 0 .
We are interested in an explicit form of the numbers Fn for all natural numbers n.
Actually, the problem is to solve an equation where the unknown is given recursively,
in which case the equation is called a recurrence equation. The solution can be
considered as a function over natural numbers, because Fn is defined for all n. Such
recurrence equations are also known as difference equations, but could be named
as discrete differential equations for their similarities to differential equations.
Definition 11.1 A kth th order recurrence equation (k 1) is an equation of
the form
f (xn , xn+1 , . . . , , xn+k ) = 0, n0, (11.1)
where xn has to be given in an explicit form.
For a unique determination of xn , k initial values must be given. Usually these values
are x0 , x1 , . . . , xk1 . These can be considered as initial conditions. In case of the
equation for Fibonacci-numbers, which is of second order, two initial values must be
given.
A sequence xn = g(n) satisfying equation (11.1) and the corresponding initial
conditions is called a particular solution. If all particular solutions of equation
(11.1) can be obtained from the sequence xn = h(n, C1 , C2 , . . . , Ck ), by adequately
choosing of the constants C1 , C2 , . . . , Ck , then this sequence xn is a general solu-
tion.
Solving recurrence equations is not an easy task. In this chapter we will discuss
methods which can be used in special cases. For simplicity of writing we will use
the notation xn instead of x(n) as it appears in several books (sequences can be
considered as functions over natural numbers).
The chapter is divided into three sections. In Section 11.1 we deal with solving
linear recurrence equations, in Section 11.2 with generating functions and their use
in solving recurrence equations and in Section 11.3 we focus our attention on the
numerical solution of recurrence equations.
482 11. Recurrences
a polynomial equation with real coefficients. This equation has k roots in the field
of complex numbers. It can easily be seen after a simple substitution that if r0 is
a real solution of the characteristic equation, then C0 r0n is a solution of (11.2), for
arbitrary C0 .
The general solution of equation (11.2) is
(i)
where xn (i = 1, 2, . . . , k) are the linearly independent solutions of equation (11.2).
The constants C1 , C2 , . . . , Ck can be determined from the initial conditions by solving
a system of k equations.
The linearly independent solutions are supplied by the roots of the characteristic
equation in the following way. A fundamental solution of equation (11.2) can be
associated with each root of the characteristic equation. Let us consider the following
cases.
Distinct real roots. Let r1 , r2 , . . . , rp be distinct real roots of the characteristic
equation. Then
r1n , r2n , . . . , rpn
are solutions of equation (11.2), and
xn+2 = xn+1 + xn , x0 = 0, x1 = 1 .
r2 r 1 = 0 ,
The constants C1 and C2 can be determined using the initial conditions. From x0 = 0,
x1 = 1 the following system of equations can be obtained.
C1 + C2 = 0,
1+ 5 1 5
C1 + C2 = 1.
2 2
The solution of this system of equations is C1 = 1/ 5, C2 = 1/ 5 . Therefore the
general solution is n n
1 1+ 5 1 1 5
xn = ,
5 2 5 2
which is the nth Fibonacci number Fn .
Multiple real roots. Let r be a real root of the characteristic equation with mul-
tiplicity p. Then
rn , nrn , n2 rn , . . . , np1 rn
are solutions of equation (11.2) (fundamental solutions corresponding to r), and
C0 + C1 n + C2 n2 + + Cp1 np1 rn (11.5)
xn = (C0 + C1 n)2n
C0 = 1,
2C0 + 2C1 = 3.
Distinct complex roots. If the complex number a(cos b + i sin b), written
in trigonometric form, is a root of the characteristic equation, then its conjugate
a(cos b i sin b) is also a root, because the coefficients of the characteristic equation
are real numbers. Then
an cos bn and an sin bn
are solutions of equation (11.2) and
is also a solution, for any constants C1 and C2 . If these are the only solutions of a
second order characteristic equation, then (11.6) is a general solution.
r2 2r + 2 = 0 ,
with roots 1 + iand 1 i. These can be written in trigonometric form as 2(cos(/4) +
i sin(/4)) and 2(cos(/4) i sin(/4)). Therefore
n n
xn = C1 ( 2)n cos + C2 ( 2)n sin
4 4
is a general solution of the recurrence equation. From the initial conditions
C1 = 0,
C1 2 cos + C2 2 sin = 1.
4 4
Therefore C1 = 0, C2 = 1. Hence the general solution is
n n
xn = 2 sin .
4
and
an sin bn, nan sin bn, . . . , np1 an sin bn
are solutions of the recurrence equation (11.2). Then
(C0 + C1 n + + Cp1 np1 )an cos bn + (D0 + D1 n + + Dp1 np1 )an sin bn
xn+4 + 2xn+2 + xn = 0, x0 = 0, x1 = 1, x2 = 2, x3 = 3 .
C0 = 0,
(C0 + C1 ) cos + (D0 + D1 ) sin = 1,
2 2
(C0 + 2C1 ) cos + (D0 + 2D1 ) sin = 2,
3 3
(C0 + 3C1 ) cos + (D0 + 3D1 ) sin = 3,
2 2
that is
C0 = 0,
D0 + D1 = 1,
2C1 = 2,
D0 3D1 = 3.
Using these four cases all linear homogeneous equations with constant coefficients
can be solved, if we can solve their characteristic equations.
r3 4r2 + 6r 4 = 0 ,
The general solution. The characteristic equation of the kth order linear
homogeneous equation (11.2) has k roots in the field of complex numbers, which are
not necessarily distinct. Let these roots be the following:
r1 real, with multiplicity p1 (p1 1),
r2 real, with multiplicity p2 (p2 1),
...
rt real, with multiplicity pt (pt 1),
s1 = a1 (cos b1 + i sin b1 ) complex, with multiplicity q1 (q1 1),
s2 = a2 (cos b2 + i sin b2 ) complex, with multiplicity q2 (q2 1),
...
sm = am (cos bm + i sin bm ) complex, with multiplicity qm (qm 1).
Since the equation has k roots, p1 + p2 + + pt + 2(q1 + q2 + + qm ) = k.
In this case the general solution of equation (11.2) is
t
X
(j) (j) (j)
xn = C0 + C1 n + + Cpj 1 npj 1 rjn
j=1
m
X
(j) (j) (j)
+ D0 + D1 n + + Dqj 1 nqj 1 anj cos bj n
j=1
m
X
(j) (j) (j)
+ E0 + E1 n + + Eqj 1 nqj 1 anj sin bj n , (11.7)
j=1
where
(j) (j) (j)
C0 , C1 , . . . , Cpj 1 , j = 1, 2, . . . , t ,
(l) (l) (l) (l) (l) (l)
D0 , E0 , D1 , E1 , . . . , Dpl 1 , Epl 1 , l = 1, 2, . . . , m are constants, which
can be determined from the initial conditions.
The above statements can be summarised in the following theorem.
The proof of the theorem is left to the Reader (see Exercise 11.1-5).
The algorithm for the general solution is the following.
Linear-Homogeneous
1 determine the characteristic equation of the recurrence equation
2 find all roots of the characteristic equation with their multiplicities
3 find the general solution (11.7) based on the roots
4 determine the constants of (11.7) using the initial conditions, if these exists.
xn = x(0) (1)
n + xn
The proof of the theorem is left to the Reader (see Exercise 11.1-6).
x(0) n
n = C1 (2) + C2 ,
since the roots of the characteristic equation are 2 and 1. It is easy to see that
xn = C1 (2)n + C2 + 2n2
(1)
f (n) xn
np an (C0 + C1 n + + Cp np )an
The constants C1 and C2 can be determined using the initial conditions. Thus,
0, if n is even ,
xn =
2n1 , if n is odd .
Exercises
11.1-1 Solve the recurrence equation
Hn = 2Hn1 + 1, if n 1, and H0 = 0 .
(Here Hn is the optimal number of moves in the problem of the Towers of Hanoi.)
11.1-2 Analyse the problem of the Towers of Hanoi if n discs have to be moved
from stick A to stick C in such a way that no disc can be moved directly from A to
C and vice versa.
Hint. Show that if the optimal number of moves is denoted by Mn , and n 1,
then Mn = 3Mn1 + 2.
11.1-3 Solve the recurrence equation
(n + 1)Rn = 2(2n 1)Rn1 , if n 1, and R0 = 1 .
11.2. Generating functions and recurrence equations 489
xn = 2n 2 + 2xn1 , if n 2, and x1 = 0 .
F (z) = F0 + F1 z + F2 z 2 + F3 z 3 + + Fn z n + ,
zF (z) = F0 z + F1 z 2 + F2 z 3 + + Fn1 z n + ,
z 2 F (z) = F0 z 2 + F1 z 3 + + Fn2 z n + .
If we subtract the second and the third equations from the first one term by term,
then use the defining formula of the Fibonacci numbers, we get
F (z)(1 z z 2 ) = z ,
that is
z
F (z) = . (11.9)
1 z z2
The correctness of these operations can be proved mathematically, but here we do
not want to go into details. The formulae obtained using generating functions can
usually also be proved using other methods.
490 11. Recurrences
The generating functions A(z) and B(z) are equal, if and only if an = bn for all
n natural numbers.
Now we define the following operations with the generating functions: addition,
multiplication by real number, shift, multiplication, derivation and integration.
Addition and multiplication by real number.
X
A(z) + B(z) = (an + bn )z n .
n0
1 X X
k
(A(z) a0 a1 z a2 z 2 ak1 z k1 ) = an z nk = ak+n z n
z
nk n0
n
X
where sn = ak bnk .
k=0
Derivation.
X
A0 (z) = a1 + 2a2 z + 3a3 z 2 + = (n + 1)an+1 z n .
n0
we obtain X 1
A0 (z) = nz n1 = .
(1 z)2
n1
Integration.
Z z X1
1 1
A(t)dt = a0 z + a1 z 2 + a2 z 3 + = an1 z n .
0 2 3 n
n1
1 1 1
where Hn = 1 + + + + (H0 = 0, H1 = 1) are the so-called harmonic numbers.
2 3 n
P
Changing the arguments. Let A(z) P = n n0 an z n represent the se-
quence ha0 , a1 , a2 , . . .i, then A(cz) = n0 c an z
n
represents the sequence
ha0 , ca1 , c2 a2 , . . . cn an , . . .i. The following statements holds
1
A(z) + A(z) = a0 + a2 z 2 + + a2n z 2n + ,
2
1
A(z) A(z) = a1 z + a3 z 3 + + a2n1 z 2n1 + .
2
492 11. Recurrences
1
Example 11.10 Let A(z) = 1 + z + z 2 + z 3 + = . Then
1z
1
1 1 1 1
1 + z2 + z4 + = A(z) + A(z) = + = ,
2 2 1z 1+z 1 z2
which can also be obtained by substituting z by z 2 in A(z). We can obtain the sum of the
odd power terms in the same way,
1
1 1 1 z
z + z3 + z5 + = A(z) A(z) = = .
2 2 1z 1+z 1 z2
X n k 2 c
b n+1
X nk
Fn+1 = = . (11.12)
k k
k0 k=0
Remember that the binomial formula can be generalised for all real r, namely
X r
r
(1 + z) = zn ,
n
n0
r
which is the generating function of the binomial coefficients for a given r. Here
n
is a generalisation of the number of combinations for any real number r, that is
r(r 1)(r 2) . . . (r n + 1)
, if n > 0 ,
r n(n 1) . . . 1
=
n
1, fi n = 0 ,
0, if n < 0 .
We can obtain useful formulae using this generalisation for negative r. Let
1 X m
m
= (1 z) = (z)k .
(1 z)m k
k0
Then
zm X m + k X m + k Xk
m+k m+k
= z = z = zk ,
(1 z)m+1 k m m
k0 k0 k0
and
Xk zm
zk = , (11.13)
m (1 z)m+1
k0
Then
X a1 X ak X X
a0 xn z n + xn+1 z n+1 + + k xn+k z n+k = f (n)z n .
z z
n0 n0 n0 n0
Let X X
X(z) = xn z n and F (z) = f (n)z n .
n0 n0
Example 11.11 Solve the following equation using the above method
and
1 2 2
X(z) x0 2X(z) = .
z 1 2z 1z
Since x0 = 0, after decomposing the right-hand side into partial fractions1 ), the solution of
the equation is
2z 2 2
X(z) = + .
(1 2z)2 1z 1 2z
After differentiating the generating function
1 X n n
= 2 z
1 2z
n0
Thus X X X X
X(z) = n2n z n + 2 zn 2 2n z n = (n 2)2n + 2 z n ,
n0 n0 n0 n0
therefore
xn = (n 2)2n + 2 .
11.2. Generating functions and recurrence equations 495
n=2 n=3
The number of binary trees. Let us denote by bn the number of binary trees
with n vertices. Then b1 = 1, b2 = 2, b3 = 5 (see Figure 11.2). Let b0 = 1. (We will
see later that this is a good choice.)
In a binary tree with n vertices, there are altogether n 1 vertices in the left and
right subtrees. If the left subtree has k vertices and the right subtree has n 1 k
vertices, then there exists bk bn1k such binary trees. Summing over k = 0, 1, . . . , n
1, we obtain exactly the number bn of binary trees. Thus for any natural number
n 1 the recurrence equation in bn is
Then the right-hand side of (11.16) is exactly A(z)B(z), which is zB 2 (z). Therefore
1 For decomposing the fraction into partial fractions we can use the Method of Undetermined
Coefficients.
496 11. Recurrences
The number of leaves of all binary trees of n vertices. Let us count the
number of leaves (vertices with degree 1) in the set of all binary trees of n vertices.
Denote this number by fn . We remark that the root is not considered leaf even if
it is of degree 1. It is easy to see that f2 = 2, f3 = 6. Let f0 = 0 and f1 = 1,
conventionally. Later we will see that this choice of the initial values is appropriate.
As in the case of numbering the binary trees, consider the binary trees of n
vertices having k vertices in the left subtree and n k 1 vertices in the right
subtree. There are bk such left subtrees and bn1k right subtrees. If we consider
such a left subtree and all such right subtrees, then together there are fn1k leaves
in the right subtrees. So for a given k there are bn1k fk + bk fn1k leaves. After
summing we have
n1
X
fn = (fk bn1k + bk fn1k ) .
k=0
By an easy computation we get
fn = 2(f0 bn1 + f1 bn2 + + fn1 b0 ), n 2 . (11.17)
This is a recurrence equation, with solution fn . Let
X X
F (z) = fn z n and B(z) = bn z n .
n0 n0
11.2. Generating functions and recurrence equations 497
Since f0 = 0 and f1 = 1,
F (z) z = 2zF (z)B(z) .
Thus
z
F (z) = ,
1 2zB(z)
and since
1
B(z) = 1 1 4z ,
2z
we have
z X 1/2
F (z) = = z(1 4z)1/2 = z (4z)n .
1 4z n0
n
and
2n 2 2n
fn = or fn+1 = = (n + 1)bn .
n1 n
The number of binary trees with n vertices and k leaves. A bit harder
problem: how many binary trees are there with n vertices and k leaves? Let us denote
(k) (k)
this number by bn . It is easy to see that bn = 0, if k > b(n + 1)/2c. By a simple
(1)
reasoning the case k = 1 can be solved. The result is bn = 2n1 for any natural
(0)
number n 1. Let b0 = 1, conventionally. We will see later that this choice of
the initial value is appropriate. Let us consider, as in case of the previous problems,
the left and right subtrees. If the left subtree has i vertices and j leaves, then the
right subtree has n i 1 vertices and k j leaves. The number of these trees is
(j) (kj)
bi bni1 . Summing over k and j gives
X k1
n2 X
(k) (j) (kj)
bn(k) = 2bn1 + bi bni1 . (11.18)
i=1 j=1
will be used. Multiplying both sides of equation (11.18) by z n and summing over
n = 0, 1, 2, . . ., we get
X X (k) X k1
X n2 X (j) (kj)
bn(k) z n = 2 bn1 z n + bi bni1 z n .
n1 n1 n1 i=1 j=1
Thus
k1
X
B (k) (z) = 2zB (k) (z) + z B (j) (z)B (kj) (z)
j=1
or
k1
X
z
B (k) (z) = B (j) (z)B (kj) (z) . (11.19)
1 2z j=1
z (1) 2
B (2) (z) = B (z) ,
1 2z
2z 2 (1) 3
B (3) (z) = B (z) ,
(1 2z)2
5z 3 (1) 4
B (4) (z) = B (z) .
(1 2z)3
Let us try to find the solution in the form
ck z k1 (1) k
B (k) (z) = B (z) ,
(1 2z)k1
thus
3
1 4z
C(z) = .
2
Since C(0) = 1, only the negative sign can be chosen. After expanding the generating
function we get
3 1 3 1 X 1 2n n
C(z) = (1 4z)1/2 = z
2 2 2 2 2n 1 n
n0
3 X 1 2n n X 1 2n n
= + z =1+ z .
2 2(2n 1) n 2(2n 1) n
n0 n1
From this
1 2n
cn = , n1.
2(2n 1) n
(1)
Since bn = 2n1 for n 1, it can be proved easily that B (1) = z/(1 2z). Thus
1 2k z 2k1
B (k) (z) = .
2(2k 1) k (1 2z)2k1
therefore
X
(k) 1 2k 2k + n 2 n 2k+n1
B (z) = 2 z
2(2k 1) k n
n0
X
1 2k n1
= 2n2k+1 z n .
2(2k 1) k n 2k + 1
n2k1
Thus
1 2k n 1 n2k
b(k)
n = 2
2k 1 k 2k 2
or
1 2k n
b(k)
n = 2n2k .
n k 2k 1
Let us first consider the case when the denominator has distinct roots
1 , 2 , . . . , k . Then
P (z) A1 Ai Ak
= + + + + .
Q(z) z 1 z i z k
It is easy to see that
P (z)
Ai = lim (z i ) , i = 1, 2, . . . , k .
zi Q(z)
But
Ai Ai Ai i
= = ,
z i 1 1 i z
i 1 z
i
where i = 1/i . Now, by expanding this partial fraction, we get
Ai i
= Ai i (1 + i z + + in z n + ) .
1 i z
P (z)
Ci (n) = Ai in+1 = in+1 lim (z i ) ,
zi Q(z)
or
(z i )P (z)
Ci (n) = in+1 lim .
zi Q(z)
After the transformation z 1/z and using i = 1/i we obtain
n1 p(z)
Ci (n) = lim (z i )z ,
zi q(z)
where
p(z) P (1/z)
= .
q(z) Q(1/z)
P (z)
Thus in the expansion of X(z) = the coefficient of z n is
Q(z)
P (z) 2z z p(z) 2
= , then = .
Q(z) (1 z)(1 2z) q(z) (z 1)(z 2)
If case of multiple roots, e.g. if i has multiplicity p, their contribution to the solution
is
1 dp1 p n1 p(z)
Ci (n) = lim (z i ) z .
(p 1)! zi dz p1 q(z)
11.2. Generating functions and recurrence equations 501
dp
Here p f (z) is the derivative of order p of the function f (z).
dz
All these can be summarised in the following algorithm. Suppose that the coef-
ficients of the equation are in array A, and the constants of the solution are in array
C.
Linear-Nonhomogeneous(A, k, f )
1 let a0 xn + a1 xn+1 + + ak xn+k = f (n) be the equation, where f (n)
is a rational fraction; multiply both sides by z n , and sum over all n
2 transform thePequation into the form X(z) = P (z)/Q(z), where
X(z) = n0 xn z n , P (z) and Q(z) are polynomials
3 use the transformation z 1/z, and let the result be
p(z)/q(z), where p(z) are q(z) are polynomials
4 denote the roots of q(z) by
1 , with multiplicity p1 , p1 1,
2 , with multiplicity p2 , p2 1,
...
k , with multiplicity pk , pk 1;
then the general solution of the original equation is
xn = C1 (n) + C2 (n) + + Ck (n), where
dpi 1
Ci (n) = 1/((pi 1)!) limzi dz pi 1 (z i )pi z n1 (p(z)/q(z)) , i = 1, 2, . . . , k.
5 return C
or X
1 2 2
X(z) 2X(z) = , where X(z) = xn z n .
z 1 2z 1z
n0
Thus
2z 2
X(z) = .
(1 z)(1 2z)2
After the transformation z 1/z we get
p(z) 2z
= ,
q(z) (z 1)(z 2)2
where the roots of the denominator are 1 with multiplicity 1 and 2 with multiplicity 2.
502 11. Recurrences
Thus
2z n
C1 = lim =2 and
z1 (z 2)2
nz n1 (z 1) z n
d 2z n
C2 = lim = 2 lim = 2n (n 2) .
z2 dz z1 z2 (z 1)2
Therefore the general solution is
xn = 2n (n 2) + 2, n0.
so
1 2
F (z) z = F (z) 2F (z) ,
z2 z
that is
1 2 1
F (z) +2 = .
z2 z z
Then
z
F (1/z) = .
z 2 2z + 2
The roots of the denominator are 1 + i and 1 i. Let us compute C1 (n) and C2 (n):
Hn = 2Hn1 + 1, H0 = 0 .
11.2-4 Solve the following recurrent equation using the Z-transform method.
un = vn1 + un2 ,
vn = un + un1 ,
where u0 = 1, u1 = 2, v0 = 1.
Recurrence(A, X, k, n, f )
1 for j k to n
2 do v A[0] X[0]
3 for i 1 to k 1
4 do v v + A[i]
X[i]
5 v f (j k) v /A[k]
6 if j 6= n
7 then for i 0 to k 2
8 do X[i] X[i + 1]
9 X[k 1] v
10 return v
Exercises
11.3-1 How many additions, subtractions, multiplications and divisions are required
using the algorithm Recurrence, while it computes x1000 using the data given in
Example 11.4?
504 11. Recurrences
Problems
Chapter Notes
Recurrence equations are discussed in details by Agarwal [1], Elaydi [69], Flajolet
and Sedgewick [224], Greene and Knuth [94], Mickens [174], and also in the recent
books written by Drmota [64], further by Flajolet and Sedgewick [74].
Knuth [140] and Graham, Knuth and Patashnik [93] deal with generating func-
tions. In the book of Vilenkin [257] there are a lot of simple and interesting problems
about recurrences and generating functions.
In [162] Lovsz also presents problems on generating functions.
Counting the binary trees is from Knuth [140], counting the leaves in the set of
all binary trees and counting the binary trees with n vertices and k leaves are from
Zoltn Ksa [147].
12. Scientific Computing
exact computations (operations) and seek for the error bound of the final result. Let
x and y be exact values with approximations a and b, respectively. Assume that the
absolute error bounds of approximations a and b are a and b, respectively. Using
the classical error analysis approach we obtain the following error bounds for the
four basic arithmetic operations:
(a + b) a b
(a + b) = a + b, = max , (ab > 0) ,
|a + b| |a| |b|
(a b) a + b
(a b) = a + b, = (ab > 0) ,
|a b| |a b|
(ab) a b
(ab) |a| b + |b| a + (ab 6= 0) ,
|ab| |a| |b|
|a| b + |b| a (a/b) a b
(a/b) 2 + (ab 6= 0) .
|b| |a/b| |a| |b|
We can see that the division with a number near to 0 can make the absolute
error arbitrarily big. Similarly, if the result of subtraction is near to 0, then its
relative error can become arbitrarily big. One has to avoid these cases. Especially
the subtraction operation can be quite dangerous.
Example
12.1 Calculate the quantity 1996 1995 with approximations 1996 44.67
and 1995 44.66 whose common absolute andrelative error bounds are 0.01 and 0.022%,
respectively. One obtains the approximate value 1996 1995 0.01, whose relative error
bound is
0.01 + 0.01
=2,
0.01
that is 200%. The true relative error is about 10.66%. Yet it is too big, since it is approx-
imately 5 102 times bigger than the relative error of the initial data. We can avoid the
subtraction operation by using the following trick
1996 1995 1 1
1996 1995 = = 0.01119 .
1996 + 1995 1996 + 1995 89.33
Here the nominator is exact, while the absolute error of the denominator is 0.02. Hence
the relative error (bound) of the quotient is about 0.02/89.33 0.00022 = 0.022%. The
latter result is in agreement with the relative error of the initial data and it is substantially
smaller than the one obtained with direct subtraction operation.
The first order error terms of twice differentiable functions can be obtained by
their first order Taylor polynomial:
(f (a)) |f 0 (a)| a, f : R R ,
Xn
f (a)
(f (a)) n
xi ai , f : R R .
i=1
value and the input data (the Jacobian matrix of functions F : Rn Rm is denoted
by F 0 (a) at the point a Rn ):
|f 0 (a)| |a|
c(f, a) = , f :RR,
|f (a)|
kak kF 0 (a)k
c(F, a) = , F : Rn Rm .
kF (a)k
We can consider the condition number as the magnification number of the input
relative error. Therefore the functions is considered numerically stable (or well-
conditioned) at the point a, if c (f, a) is small. Otherwise f is considered as
numerically unstable (ill-conditioned.) The condition number depends on the
point a. A function can be well-conditioned at point a, while it is ill-conditioned at
point b. The term small is relative. It depends on the problem, the computer
and the required precision.
The condition number of matrices can be defined as the upper bound of a func-
tion condition number. Let us define the mapping F : Rn Rn by the solution of
the equation Ay = x (A Rnn , det(A) 6= 0), that is, let F (x) = A1 x . Then
F 0 A1 and
kak
A1
kAyk
A1
c(F, a) = 1
= kAk
A1
(Ay = a) .
kA ak kyk
The upper bound of the right side is called the condition number of the
matrix A. This bound
1
is sharp, since there exists a vector a Rn such that
c(F, a) = kAk A
.
for any x it gives a computed value y with small backward error x. Again, the
term small is relative to the problem environment.
The connection of the forward and backward errors is described by the approx-
imate thumb rule
y x
/ c (f, x) , (12.1)
|y| |x|
which means that
Example 12.2 Consider the function f (x) = log x the condition number of which is
c (f, x) = c (x) = 1/ |log x|. For x 1 the condition number c (f, x) is big. Therefore the
relative forward error is big for x 1.
n F (, t, L, U ) = o
1
= m e | m < 1, m = 0.d1 d2 . . . dt , L e U {0} ,
where
- is the base (or radix) of the number system,
- m is the mantissa in the number system with base ,
- e is the exponent,
12.1. Floating point arithmetic and error analysis 509
The parameters of the three most often used number systems are indicated in
the following table
Name Machines
binary 2 most computer
decimal 10 most calculators
hexadecimal 16 IBM mainframe computers
where 0 di 1 (i = 1, . . . , t) and 1 d1 .
Example 12.3 The set F (2, 3, 1, 2) contains 33 elements and its positive elements are
given by n o
1 5 6 7 1 5 6 7 10 12 14 20 28
, , , , , , , , 1, , , , 2, , 3, .
4 16 16 16 2 8 8 8 8 8 8 8 8
The elements of F are not equally distributed on the real line. The distance of
two consecutive numbers in [1/, 1] F is t . Since the elements of F are of the
form m e , the distance of two consecutive numbers in F is changing with the
exponent. The maximum distance of two consecutive floating point numbers is U t ,
while the minimum distance is Lt .
For the mantissa we have m [1/, 1 1/ t ] , since
1 d1 d2 dt 1 1 1 1
m= + 2 + + t + + + = 1 t.
2 t
Using this observation we can easily prove the following result on the range of
floating point numbers.
ML = L1 , MU = U (1 t ).
510 12. Scientific Computing
Let a, b F and denote any of the four arithmetic operations (+, , , /). The
following cases are possible:
(1) ab F (exact result),
(2) |ab| > MU (arithmetic overflow),
(3) 0 < |ab| < ML (arithmetic underflow),
(4) ab / F , ML < |ab| < MU (not representable result).
In the last two cases the floating point arithmetic is rounding the result ab to
the nearest floating point number in F . If two consecutive floating point numbers
are equally distant from ab, then we generally round to the greater number. For
example, in a five digit decimal arithmetic, the number 2.6457513 is rounded to the
number 2.6458.
Let G = [MU , MU ]. It is clear that F G. Let x G. The f l (x) denotes an
element of F nearest to x. The mapping x f l (x) is called rounding. The quantity
|x f l (x)| is called the rounding error. If f l (x) = 1, then the rounding error is at
most 1t /2. The quantity u = 1t /2 is called the unit roundoff. The quantity
u is the relative error bound of f l (x).
f l(x) = x(1 + ), || u .
m 1 e x m2 e .
|m2 m1 | e et
|f l (x) x| =
2 2
|f l (x) x| |f l (x) x| et t 1
= 1t = u .
|x| m1 e 2m1 e 2m1 2
f l (x) = x(1 + ) ( = u)
Thus we proved that the relative error of the rounding is bounded in floating
point arithmetic and the bound is the unit roundoff u.
Another quantity used to measure the rounding errors is the so called the ma-
chine epsilon M = 2u = 1t (M = 2u). The number M is the distance of 1 and
its nearest neighbour greater than 1. The following algorithm determines M in the
12.1. Floating point arithmetic and error analysis 511
Machine-Epsilon
1 x1
2 while 1 + x > 1
3 do x x/2
4 M 2x
5 return M
Assume that we have a guard digit and the arithmetic complies with standard
model (12.4). Introduce the following notations:
T
|z| = [|z1 | , . . . , |zn |] (z Rn ) , (12.7)
m,n
|A| = [|aij |]i,j=1 A Rmn , (12.8)
A B aij bij A, B Rmn . (12.9)
The following results hold:
f l xT y xT y 1.01nu |x|T |y| (nu 0.01) , (12.10)
We can have a similar result on Pentium1 machine with the choice b = c = 1.15 1016 .
The example also indicates that for different (numerical) processors may produce
different computational results for the same calculations. The P commutativity can
n
also be lost in addition. Consider the computation of the sum i=1 xi . The usual
algorithm is the recursive summation.
Recursive-Summation(n, x)
1 s0
2 for i 1 to n
3 do s s + xi
4 return s
X
n
1
sn = 1 +
i2 + i
i=1
for n = 4999. The recursive summation algorithm (and MATLAB) gives the result
1.999800000000002e + 000 .
12.1. Floating point arithmetic and error analysis 513
If the summation is done in the reverse (increasing) order, then the result is
1.999800000000000e + 000 .
If the two values are compared with the exact result sn = 2 1/(n + 1), then we can see
that the second summation gives better result. In this case the sum of smaller numbers
gives significant digits to the final result unlike in the first case.
The last example indicates that the summation of a large number of data varying
in modulus and sign is a complicated task. The following algorithm of W. Kahan is
one of the most interesting procedures to solve the problem.
Compensated-Summation(n, x)
1 s0
2 e0
3 for i 1 to n
4 do t s
5 y xi + e
6 st+y
7 e (t s) + y
8 return s
In both formats one bit is reserved as a sign bit. Since the floating point numbers
are normalized and the first digit is always 1, this bit is not stored. This hidden bit
is denoted by the +1 in the table.
The arithmetic standard contains the handling of arithmetic exceptions.
(The numbers of the form m Lt , 0 < m < t1 are called subnormal num-
bers.) The IEEE arithmetic is a closed system. Every arithmetic operations has a
result, whether it is expected mathematically or not. The exceptional operations
raise a signal and continue. The arithmetic standard conforms with the standard
model (12.4).
The first hardware implementation of the IEEE standard was the Intel 8087
mathematical coprocessor. Since then it is generally accepted and used.
Remark. In the single precision we have about 7 significant digit precision in the
decimal system. For double precision we have approximately 16 digit precision in
decimals. There also exists an extended precision format of 80 bits, where t = 63
and the exponential has 15 bits.
Exercises
12.1-1 The measured values of two resistors are R1 = 110.2 0.3 and R2 =
65.6 0.2. We connect the two resistors parallel and obtain the circuit resistance
Re = R1 R2 /(R1 + R2 ). Calculate the relative error bounds of the initial data and
the approximate value of the resistance Re . Evaluate the absolute and relative error
bounds Re and Re /Re , respectively in the following three ways:
(i) Estimate first Re using only the absolute error bounds of the input data, then
estimate the relative error bound Re /Re .
(ii) Estimate first the relative error bound Re /Re using only the relative error
bounds of the input data, then estimate the absolute error bound Re .
(iii) Consider the circuit
resistance as a two variable function Re = F (R1 , R2 ).
12.1-2 Assume that 2 is calculated with the absolute error bound 108 . The fol-
lowing two expressions are theoretically equal:
6
(i) 1/ 1 + 2 ;
(ii) 99 70 2.
Which expression can be calculated with less relative error and why?
12.1-3 Consider the arithmetic operations as two variable functions of the form
f (x, y) = xy, where {+, , , /}.
(i) Derive the error bounds of the arithmetic operations from the error formula of
two variable functions.
(ii) Derive the condition numbers of these functions. When are they ill-conditioned?
(iii) Derive error bounds for the power function assuming that both the base and
the exponent have errors. What is the result if the exponent is exact?
(iv) Let y = 16x2 , x a and y b = 16a2 . Determine the smallest and the greatest
value of a as a function of x such that the relative error bound of b should be at
most 0.01.
12.1-4 Assume that the number C = EXP(4 2 / 83) (= 76.1967868 . . .) is calcu-
lated in a 24 bit long mantissa and the exponential function is also calculated with
24 significant bits. Estimate the absolute error of the result. Estimate the relative
error without using the actual value of C.
12.1-5 Consider the emphfloating point number set F (, t, L, U ) and show that
(i) Every arithmetic operation can result arithmetic overflow;
(ii) Every arithmetic operation can result arithmetic underflow.
12.1-6 Show that the following expressions are numerically unstable for x 0:
12.2. Linear systems of equations 515
Ax = b , (12.15)
where
m,n
A = [aij ]i,j=1 Rmn , x Rn , b Rm .
The systems is called underdetermined if m < n. For m > n, the systems is called
overdetermined. Here we investigate only the case m = n, when the coefficient matrix
A is square. We also assume that the inverse matrix A1 exists (or equivalently
det (A) 6= 0). Under this assumption the linear system Ax = b has exactly one
solution: x = A1 b.
Definition 12.4 The matrix A = [aij ]ni,j=1 is upper triangular if aij = 0 for all
i > j. The matrix A is lower triangular if aij = 0 for all i < j.
516 12. Scientific Computing
For example the general form of the upper triangular matrices is the following:
..
0 .
.. .. .. .. .
. . . .
. ..
.. .
0 0
We note that the diagonal matrices are both lower and upper triangular. It is easy to
show that det(A) = a11 a22 . . . ann holds for the upper or lower triangular matrices.
It is easy to solve linear systems with triangular coefficient matrices. Consider the
following upper triangular linear system:
a11 x1 + +a1i xi + +a1n xn = b1
.. .. .. ..
. . . .
aii xi + +ain xn = bi
.. .. ..
. . .
ann xn = bn
This can be solved by the so called back substitution algorithm.
Back-Substitution(A, b, n)
1 xn bn /ann
2 for i n 1 downto
Pn 1
3 do xi (bi j=i+1 aij xj )/aii
4 return x
three types:
1. Add a multiple of one equation to another equation.
2. Interchange two equations.
3. Multiply an equation by a nonzero constant.
The elimination phase of GE is based on the following observation. Multiply
equation k by 6= 0 and subtract it from equation i:
If akj 6= 0, then by choosing = aij /akj , the coefficient of xj becomes 0 in the new
equivalent equation, which replaces equation i. Thus we can eliminate variable xj
(or coefficient aij ) from equation i.
The Gauss method eliminates the coefficients (variables) under the main diagonal
of A in a systematic way. First variable x1 is eliminated from equations i = 2, . . . , n
using equation 1, then x2 is eliminated from equations i = 3, . . . , n using equation
2, and so on.
Assume that the unknowns are eliminated in the first (k 1) columns under the
main diagonal and the resulting linear system has the form
Since aik akk = 0 for = aik /akk , we eliminated the coefficient aik (variable xk )
from equation i > k. Repeating this process for i = k + 1, . . . , n we can eliminate
the coefficients under the main diagonal entry akk . Next we denote by A [i, j] the
element aij of matrix A and by A [i, j : n] the vector [aij , ai,j+1 , . . . , ain ]. The Gauss
method has the following form (where the pivoting discussed later is also included):
518 12. Scientific Computing
Gauss-Method(A, b)
1 Forward phase:
2 n rows[A]
3 for k 1 to n 1
4 do {pivoting and interchange of rows and columns}
5 for i k + 1 to n
6 do ik A [i, k] /A [k, k]
7 A [i, k + 1 : n] A [i, k + 1 : n] ik A [k, k + 1 : n]
8 bi bi ik bk
9 Backward phase: see the back substitution algorithm.
10 return x
The algorithm overwrites the original matrix A and vector b. It does not write
however the zero entries under the main diagonal since these elements are not neces-
sary for the second phase of the algorithm. Hence the lower triangular part of matrix
A can be used to store information for the LU decomposition of matrix A.
The above version of the Gauss method can be performed only if the elements akk
occurring in the computation are not zero. For this and numerical stability reasons
we use the Gaussian elimination with pivoting.
The Gauss method with pivoting. If akk = 0, then we can interchange row
k with another row, say i, so that the new entry (aki ) at position (k, k) should be
nonzero. If this is not possible, then all the coefficients akk , ak+1,k , . . . , ank are zero
and det (A) = 0. In the latter case Ax = b has no unique solution. The element
akk is called the k th pivot element. We can always select new pivot elements by
interchanging the rows. The selection of the pivot element has a great influence on
the reliability of the computed results. The simple fact that we divide by the pivot
2
element indicates this influence. We recall that (a/b) is proportional to 1/ |b| . It is
considered advantageous if the pivot element is selected so that it has the greatest
possible modulus. The process of selecting the pivot element is called pivoting. We
mention the following two pivoting processes.
Partial pivoting: At the k th step, interchange the rows of the matrix so the
largest remaining element, say aik , in the k th column is used as pivot. After the
pivoting we have
|akk | = max |aik | .
kin
Complete pivoting: At the k th step, interchange both the rows and columns
of the matrix so that the largest element, say aij , in the remaining matrix is used
as pivot After the pivoting we have
Note that the interchange of two columns implies the interchange of the corre-
sponding unknowns. The significance of pivoting is well illustrated by the following
12.2. Linear systems of equations 519
1017 x + y = 1
x + y = 2
is x = 1/(1 1017 ) and y = 1 1017 /(1 1017 ). The MATLAB program gives the
result x = 1, y = 1 and this is the best available result in standard double precision
arithmetic. Solving this system with the Gaussian elimination without pivoting (also in
double precision) we obtain the catastrophic result x = 0 and y = 1. Using partial pivoting
with the Gaussian elimination we obtain the best available numerical result x = y = 1.
In case of symmetric and positive definite matrices we use the Cholesky method which
is a special version of the Gauss-type methods.
Note that matrices A(k) are stored in the place of A = A(0) . The last coefficient
matrix of phase I has the form
(0) (0) (0)
a11 a12 a1n
(1) (1)
0 a22 a2n
A (n1)
= . .. ,
..
.. . .
(n1)
0 ann
(k1)
where akk is the k th pivot element. The growth factor of pivot elements is
given by
(k1) (0)
= n = max akk /a11 .
1kn
Wilkinson proved that the error of the computed solution is proportional to the
growth factor and the bounds
1 1
21 1 1
n 2 3 2 n n1 cn 2 n 4 log(n)
and
2n1
520 12. Scientific Computing
hold for complete and partial pivoting, respectively. Wilkinson conjectured that
n for complete pivoting. This has been proved by researchers for small values of n.
Statistical investigations
on random matrices (n 1024) indicate that the average of
is n2/3 for the partial pivoting and n1/2 for the complete pivoting. Hence
the case > n hardly occurs in the statistical sense.
We remark that Wilkinson constructed a linear system on which = 2n1 for
the partial pivoting. Hence Wilkinsons bound for is sharp in the case of partial
pivoting. There also exist examples of linear systems concerning discretisations of
differential and integral equations, where is increasing exponentially if Gaussian
elimination is used with partial pivoting.
The growth factor can be very large, if the Gaussian elimination is used without
pivoting. For example, = 4 (A) = 1.23 105 , if
1.7846 0.2760 0.2760 0.2760
3.3848 0.7240 0.3492 0.2760
A= 0.2760 0.2760
.
1.4311 0.2760
0.2760 0.2760 0.2760 0.7240
Operations counts. The Gauss method gives the solution of the linear system
Ax = b (A Rnn ) in a finite number of steps and arithmetic operations ( +, ,
, / ). The amount of necessary arithmetic operations is an important characteristic
of the direct linear system solvers, since the CPU time is largely proportional to the
number of arithmetic operations. It was also observed that the number of additive
and multiplicative operations are nearly the same in the numerical algorithms of
linear algebra. For measuring the cost of such algorithms C. B. Moler introduced
the concept of flop.
Definition 12.6 One (old) flop is the computational work necessary for the op-
eration s = s + x y (1 addition + 1 multiplication). One (new) flop is the com-
putational work necessary for any of the arithmetic operations +, , , /.
The new flop can be used if the computational time of additive and multiplicative
operations are approximately the same. Two new flops equals to one old flop. Here
we use the notion of old flop.
For the Gauss method a simple counting gives the number of additive and mul-
tiplicative operations.
Theorem 12.7 The computational cost of the Gauss method is n3 /3+(n2 ) flops.
V. V. Klyuyev and N. Kokovkin-Shcherbak proved that if only elementary row
and column operations (multiplication of row or column by a number, interchange of
rows or columns, addition of a multiple of row or column to another row or column)
are allowed, then the linear system Ax = b cannot be solved in less than n3 /3+(n2 )
flops.
Using fast matrix inversion procedures we can solve the n n linear system
Ax = b in O(n2.808 ) flops. These theoretically interesting algorithms are not used in
practice since they are considered as numerically unstable.
The LU -decomposition. In many cases it is easier to solve a linear system if
the coefficient matrix can be decomposed into the product of two triangular matrices.
12.2. Linear systems of equations 521
Definition 12.9 A matrix P Rnn whose every row and column has one and
only one non-zero element, that element being 1, is called a permutation matrix.
In case of partial pivoting we permute the rows of the coefficient matrix (multiply
(k1)
A by a permutation matrix on the left) so that akk 6= 0 (k = 1, . . . , n) holds for
a nonsingular matrix. Hence we have
LU -Method(A, b)
1 Determine the LU -decomposition A = LU .
2 Solve Ly = b.
3 Solve U x = y.
4 return x
Ax = b1 , Ax = b2 , . . . , Ax = bk .
In such a case we determine the LU -decomposition of matrix A only once, and then
we solve the linear systems Lyi = bi , U xi = yi (xi , yi, bi Rn , i = 1, . . . , k). The
computational cost of this process is n3 /3 + kn2 + (kn) flops.
The inversion of a matrix A Rnn can be done as follows:
1. Determine the LU -decomposition A = LU . .
2. Solve Lyi = ei , U xi = yi (ei is the ith unit vector i = 1, . . . , n).
The inverse of A is given by A1 = [x1 , . . . , xn ]. The computational cost of the
algorithm is 4n3 /3 + n2 flops.
LU-Method-with-Pointers(A, b)
1 n rows[A]
2 P [1, 2, . . . , n]
3 for k 1 to n 1
4 do compute index t such that |A [P [t] , k]| = maxkin |A [P [i] , k]| .
5 if k < t
6 then exchange the components P [k] and P [t].
7 for i k + 1 to n
8 do A [P [i] , k] A [P [i] , k] /A [P [k] , k]
9 A [P [i] , k + 1 : n]
A [P [i] , k + 1 : n] A [P [i] , k] A [P [k] , k + 1 : n]
12.2. Linear systems of equations 523
10 for i 1 to n
11 do s 0
12 for j 1 to i 1
13 do s s + A [P [i] , j] x [j]
14 x [i] b[P [i]] s
15 for i n downto 1
16 do s 0
17 for j i + 1 to n
18 s s + A [P [i] , j] x [j]
19 x [i] (x [i] s) /A [P [i] , i]
20 return x
a11 a1n l11 0 0 l11 l21 ln1
a21 a2n .. .. 0 l22 ln2
l21 l22 . .
A= .. .. = .. .. .. .. .. .. .
. .
.. . . . .
. . . 0
an1 ann ln1 ln2 lnn 0 0 lnn
Observing that only the first k elements may be nonzero in the k th column of LT
we obtain that
2 2 2 2
akk = lk1 + lk2 + + lk,k1 + lkk ,
aik = li1 lk1 + li2 lk2 + + li,k1 lk,k1 + lik lkk (i = k + 1, . . . , n) .
k1
X
2 1/2
lkk = (akk lkj ) ,
j=1
k1
X
lik = (aik lij lkj )/lkk (i = k + 1, . . . , n) .
j=1
Pk
Using the notation j=i sj = 0 (k < i) we can formulate the Cholesky-method
as follows.
524 12. Scientific Computing
Cholesky-Method(A)
1 n rows[A]
2 for k 1 to n
Pk1
3 do akk (akk j=1 a2kj )1/2
4 for i k + 1 to n
Pk1
5 do aik (aik j=1 aij akj )/akk
6 return A
The lower triangular part of A contains L. The computational cost of the al-
gorithm is n3 /6 + (n2 ) flops and n square roots. The algorithm, which can be
considered as a special case of the Gauss-methods, does not require pivoting, at
least in principle.
Definition 12.11 Matrix A Rnn is banded with lower bandwidth p and upper
bandwidth q if
a11 a12 a1,1+q 0 0
.. ..
a21 a22 . .
.. .. .. ..
. . . .
.. ..
a1+p,1
. . 0
.. ..
A= 0 . . anq,n .
.. .. .. ..
. . . .
. .. .. ..
.. . . .
. .. ..
.. . . an1,n
0 0 an,np an,n1 ann
The banded matrices yield very efficient algorithms if p and q are significantly less
than n. If a banded matrix A with lower bandwidth p and upper bandwidth q has
an LU -decomposition, then both L and U are banded with lower bandwidth p and
upper bandwidth q, respectively.
Next we give the LU -method for banded matrices in three parts.
12.2. Linear systems of equations 525
The-LU-Decomposition-of-Banded-Matrix(A, n, p, q)
1 for k 1 to n 1
2 do for i k + 1 to min {k + p, n}
3 do aik aik /akk
4 for j k + 1 to min {k + q, n}
5 do aij aij aik akj
6 return A
Solution-of-Banded-Unit-Lower-Triangular-System(L, b, n, p)
1 for i 1 to n
Pi1
2 do bi bi j=max{1,ip} lij bj
3 return b
The total cost of the algorithm is np p2 /2 flops. The next algorithm overwrites
vector b by the solution of U x = b.
Solution-of-Banded-Upper-Triangular-System(U, b, n, q)
1 for i n downto
1
Pmin{i+q,n}
2 do bi bi j=i+1 uij bj /uii
3 return b
Cholesky-decomposition-of-Banded-Matrices(A, n, p)
1 for i 1 to n
2 do for j max {1,
i p} to i 1
Pj1
3 do aij aij k=max{1,ip} aik ajk /ajj
Pi1 1/2
4 aii aii k=max{1,ip} a2ik
5 return A
The elements aij are overwritten by lij (i j). The total amount of work is
given by np2 /2 p3 /3 + (3/2) np p2 flops s n square roots.
Remark. If A Rnn has lower bandwidth p and upper bandwidth q and partial
pivoting takes place, then the upper bandwidth of U increases up to q = p + q.
526 12. Scientific Computing
xi = Gxi1 + b (i = 1, 2, . . .)
where G Rnn s x0 , b Rn . It is known that {xi }i=0 converges for all x0 , b Rn
if and only if the spectral radius of G satisfies (G) < 1 ( (G) = max || | is an
1
eigenvalue of G). In case of convergence xi x = (I G) b, that is we obtain
the solution of the equation (I G) x = b. The speed of convergence depends on the
spectral radius (G). Smaller the spectral radius (G), faster the convergence.
Consider now the linear system
Ax = b ,
Multisplitting-Iteration(x0 , b, L, Ml , Nl , El , l = 1, . . . , L)
1 i0
2 while exit condition = false
3 do i i + 1
4 for l 1 to L
5 do Ml yl Nl xi1 + b
PL
6 xi l=1 El yl
7 return xi
Thus the condition of convergence is (H) < 1. The multisplitting iteration is a true
parallel algorithm because we can solve L linear systems parallel in each iteration
12.2. Linear systems of equations 527
Nl = Ml A,
h in
(l) (l) 1, if i = j Sl
El = Eij , Eij =
i,j=1 0, otherwise
for l = 1, . . . , L.
Define now the simple splitting
A=M N ,
where M is nonsingular,
n aij , if i, j Sl for some l {1, . . . , n} ,
M= [Mij ]i,j=1 , Mij =
0, otherwise.
el = M
N fl A,
h in
(l) (l)
eel = eeij , Eii = 0, if i
/ Tl
i,j=1
for l = 1, . . . , L.
A nonsingular matrix A Rnn is called an M -matrix, if aij 0 (i 6= j) and
all the elements of A1 are nonnegative.
528 12. Scientific Computing
L
Theorem 12.12 Assume that A Rnn is nonsingular M -matrix, {Mi , Ni , Ei }i=1
n oL
is a non-overlapping, Mfi , N
ei , Ei is an overlapping block Jacobi multisplitting
i=1
of A, where the weighting matrices Ei are the same. The we have
H e (H) < 1 ,
PL e = PL El M el .
f1 N
where H = l=1 El Ml1 Nl and H l=1 l
We can observe that both iteration procedures are convergent and the conver-
gence of the overlapping multisplitting is not slower than that of the non-overlapping
procedure. The theorem remains true if we use block Gauss-Seidel multisplittings
instead of the block Jacobi multisplittings. In this case we replace the above defined
matrices Mi and M fi with their lower triangular parts.
The multisplitting algorithm has multi-stage and asynchronous variants as well.
r (x) = Ax b = A (x x) = Ax .
We use various models to estimate the inverse error. In the most general case we
assume that the computed solution x satisfies the linear systemAx = b, where A =
A + A and b = b + b. The quantities A and b are called the inverse errors.
One has to distinguish between the sensitivity of the problem and the stability
of the solution algorithm. By sensitivity of a problem we mean the sensitivity
of the solution to changes in the input parameters (data). By the stability (or
sensitivity) of an algorithm we mean the influence of computational errors on the
computed solution. We measure the sensitivity of a problem or algorithm in various
ways. One such characterization is the condition number condition number, which
compares the relative errors of the input and output values.
The following general principles are used when applying any algorithm:
- We use only stable or well-conditioned algorithms.
- We cannot solve an unstable (ill-posed or ill-conditioned) problem with a
general purpose algorithm, in general.
Ax = b + b (12.16)
Here we can see that the condition number of A may strongly influence the
relative error of the perturbed solution x b. A linear algebraic system is said to be
well-conditioned if cond(A) is small, and ill-conditioned, if cond(A) is big. It is
clear that the terms small and big are relative and the condition number
depends on the norm chosen. We identify
the applied
norm if it is essential for some
reason. For example cond (A) = kAk
A1
. The next example gives possible
geometric characterization of the condition number.
1000x1 + 999x2 = b1
999x1 + 998x2 = b2
is ill-conditioned (cond (A) = 3.99 106 ). The two lines, whose meshpoint defines the
system, are almost parallel. Therefore if we perturb the right hand side, the new meshpoint
of the two lines will be far from the previous meshpoint.
(A + A) x = b (12.18)
instead of Ax = b. It can be proved that for this perturbation model there exist
more than one inverse errors inverse error among which A = r (b x) x
bT /b b is
xT x
the inverse error with minimal spectral norm, provided that x b, r (b
x) 6= 0.
The following theorem establish that for small relative residual error the relative
inverse error is also small.
If the relative inverse error and the condition number of A are small, then the
relative residual error is small.
(A + A) x = b + b (12.20)
Theorem 12.18 (Bunch). A linear system solver is weakly stable on a matrix class
H, if for all well-conditioned A H and for all b, the computed solution x
b of the
linear system Ax = b satisfies any of the following conditions:
(1) kx xk / kxk is small;
(2) kr (x)k / kbk is small;
(3) There exists A such that (A + A) x = b and kAk / kAk are small.
Theorem 12.19 (Bauer, Skeel). Let A Rn be nonsingular and assume that the
approximate solution x b of Ax = b satisfies the linear system (A + E) x b = b + e. If
S
Rnn
, s Rn
and > 0 are such that S 0, s 0, |E| S, |e| s and
A1 S
< 1, then
A1 (S |x| + s)
kbx xk . (12.23)
1 k|A1 | Sk
Therefore the above estimate is not worse than the traditional one that uses the
standard condition number.
The inverse error can be estimated componentwise by the following result of
Oettli and Prager. Let A, A Rnn and b, b Rn . Assume that A 0 and b
0. Furthermore let
D = A Rnn : |A| A , G = {b Rn : |b| b} .
532 12. Scientific Computing
We do not need the condition number to apply this theorem. In practice the
entries A and b are proportional to the machine epsilon.
(A + A) x
b=b (12.28)
with
kAk 8n3 n kAk u + O(u2 ) , (12.29)
where n denotes the groth factor of the pivot elements and u is the unit roundoff.
Example 12.10 Consider the following linear system whose coefficients can be represented
exactly:
888445x1 + 887112x2 = 1 ,
887112x1 + 885781x2 = 0 .
Here cond(A) is big, but cond (A)kAk /kAk is negligible. The exact solution of
the problem is x1 = 885781, x2 = 887112. The MATLAB gives the approximate solution
x1 = 885827.23, x2 = 887158.30 with the relative error
kx xk
= 5.22 105 .
kxk
Since s 16 and cond (A) 3.15 1012 , the result essentially corresponds to the Wilkin-
son theorem or the thumb rule. The Wilkinson theorem gives the bound
kAk 1.26 108
12.2. Linear systems of equations 533
for the inverse error. If we use the Oettli-Prager theorem with the choice A = M |A| and
b = M |b|, then we obtain the estimate |r (x)| A |x| + b. Since k|A|k = 3.94 1010 ,
this estimate is better than that of Wilkinson.
has cond2 (Hn ) e3.5n , if n . There exist 2n 2n matrices with integer entries
that can be represented exactly in standard IEEE754 floating point arithmetic while
their condition number is approximately 4 1032n .
We have two main techniques to solve linear systems with large condition num-
bers. Either we use multiple precision arithmetic or decrease the condition number.
There are two known forms of decreasing the condition number.
1. Scaling. We replace the linear system Ax = b with the equation
(RAC) y = (Rb) , (12.32)
where R and C are diagonal matrices.
We apply the Gauss method to this scaled system and get the solution y. The
quantity x = Cy defines the requested solution. If the condition number of the
matrix RAC is smaller then we expect a smaller error in y and consequently in x.
Various strategies are given to choose the scaling matrices R and C. One of the best
known strategies is the balancing which forces every column and row of RAC to
have approximately the same norm. For example, if
!
1 1
D = diag
aT
, . . . , kaTn k2
1 2
where aTi is the ith row vector of A, the Euclidean norms of the rows of DA will be
1 and the estimate
cond2 DA n min cond2 (DA)
DD+
holds with D+ = {diag (d1 , . . . , dn ) | d1 , . . . , dn > 0}. This means that D optimally
scales the rows of A in an approximate sense.
The next example shows that the scaling may lead to bad results.
Since
1 T
kwk
A A d
= T
,
kyk kA dk
we can interpret the process as an application of the power method of the eigenvalue
problem. The estimate can be used with the 1, 2 and -norms. The entries of
vector d are 1 possibly with random signs.
If the linear system Ax = b is solved by the LU -method, then the solution of
further linear systems costs (n2 ) flops per system. Thus
the
total cost of the LIN-
PACK estimate remains small. Having the estimate
A1
we can easily estimate
cond(A) and the error of the approximate solution (cf. Theorem 12.16 or the thumb
rule). We remark that several similar processes are known in the literature.
|r (x)i |
= max ,
i (E |x| + f )i
where 0/0 is set to 0-nak, /0 is set to , if 6= 0. Symbol (y)i denotes the ith
component of the vector y. If 6= , then there exist a matrix A and a vector b
for which
|A| E, |b| f
holds and
(A + A) x = b + b .
Moreover is the smallest number for which A and b exist with the above
properties. The quantity measures the relative inverse error in terms of E and
f . If for a given E, f and x, the quantity is small, then the perturbed problem
(and its solution) are close to the original problem (and its solution). In practice,
the choice E = |A| and f = |b| is preferred
Iterative-Refinement(A, b, x, tol)
1 k1
2 x1 x
3 d inf
4 while
d
/ kxk k > tol
5 do r Axk b
6 Compute the approximate solution d of Ad = r with the LU -method.
7 xk+1 xk d
8 k k+1
9 return xk
There are other variants of this process. We can use other linear solvers instead
of the LU -method.
Let be the smallest bound of relative inverse error with
Furthermore let
(A, x) = max (|A| |x|)k / min (|A| |x|)k , min (|A| |x|)k > 0 .
k k k
Theorem 12.23 (Skeel). If kr A1 (A, x) c1 < 1/M , then for sufficiently
large k we have
This result often holds after the first iteration, i.e. for k = 2. Jankowski and
Wozniakowski investigated the iterative refinement for any method which produces
an approximate solution x b with relative error less than 1. They showed that the
iterative refinement improves the precision of the approximate solution even in single
precision arithmetic and makes method to be weakly stable.
Exercises
12.2-1 Prove Theorem 12.7.
12.2-2 Consider the linear systems Ax = b and Bx = b, where
1 1/2 1 1/2
A= , B=
1/2 1/3 1/2 1/3
and b R2 . Which equation is more sensitive to the perturbation of b? What should
be the relative error of b in the more sensitive equation in order to get the solutions
of both equations with the same precision?
12.2-3 Let = 3/229 , = 214 and
1
A = 1 1 0 , b = 1 + .
1
1 1 1
12.3. Eigenvalue problems 537
Solve the linear systems Ax = b for = 101 , 103 , 105 , 107 , 1010 . Explain the
results.
12.2-4 Let A be a 10 10 matrix and choose the band matrix consisting of the
main and the neighbouring two subdiagonals of A as a preconditioning matrix. How
much does the condition number of A improves if (i) A is a random matrix; (ii) A
is a Hilbert matrix?
12.2-5 Let
1/2 1/3 1/4
A = 1/3 1/4 1/5 ,
1/4 1/5 1/6
and assume that is the common error bound of every component of b R3 . Give the
T
sharpest possible error bounds for the solution [x1 , x2 , x3 ] of the equation Ax = b
and for the sum (x1 + x2 + x3 ).
12.2-6 Consider the linear system Ax = b with the approximate solution x.
(i) Give an error bound for x, if (A + E)x = b holds exactly and both A and A + E
is nonsingular.
(ii) Let
10 7 8 25
A= 7 5 6 , b = 18
8 6 10 24
and consider the solution of Ax = b. Give (if possible) a relative error bound for the
entries of A such that the integer part of every solution component remains constant
within the range of this relative error bound.
Ax = x. (12.37)
() = (1)n (n p1 n1 . . . pn1 pn ) .
and
Di = {z C| |z aii | ri } (i = 1, . . . , n) .
Then for any eigenvalue of A we have ni=1 Di .
For certain matrices the solution of the characteristic equation (12.38) is very
easy. For example, if A is a triangular matrix, then its eigenvalues are entries of
the main diagonal. In most cases however the computation of all eigenvalues and
eigenvectors is a very difficult task. Those transformations of matrices that keeps
the eigenvalues unchanged have practical significance for this problem. Later we see
that the eigenvalue problem of transformed matrices is simpler.
The eigenvalues of A and the perturbed matrix A + A may differ from each other
significantly. Besides the multiplicity of the eigenvalues may also change under per-
turbation. The following theorems and examples show the very sensitivity of the
eigenvalue problem.
We can observe that the eigenvalues are changing continuously and the size of
change is proportional to the nth root of kAk2 .
Example 12.12 Consider the following perturbed Jordan matrix of the size r r:
1 0 ... 0
.. ..
0 1 . .
. .. .. ..
.
. . . . 0 .
..
0 . 1
0 ... 0
instead of the original eigenvalue with multiplicity r. The size of change is 1/r , which
corresponds to Theorem (12.29 ). If || 1, r = 16 and = M 2.2204 1016 , then the
perturbation size of the eigenvalues is 0.1051. This is a significant change relative to the
input perturbation .
For special matrices and perturbations we may have much better perturbation
bounds.
This result is better than that of Ostrowski and Elsner. Nevertheless cond2 (X),
which is generally unknown, can be very big.
The eigenvalues are continuous functions of the matrix entries. This is also true
for the normalized eigenvectors if the eigenvalues are simple. The following example
shows that this property does not hold for multiple eigenvalues.
The eigenvalues of A (t) are 1 = 1 + t and 2 = 1 t. Vector [sin (1/t) , cos (1/t)]T is the
eigenvector belonging to 1 . Vector [cos (1/t) , sin (1/t)]T is the eigenvector belonging to
2 . If t 0, then
1 0
A (t) I = , 1 , 2 1 ,
0 1
while the eigenvectors do not have limit.
We study the numerical solution of the eigenvalue problem in the next section.
Unfortunately it is very difficult to estimate the goodness of numerical approxima-
tions. From the fact that Ax x = 0 holds with a certain error we cannot conclude
anything in general.
10
If = 10 , then the residual error under estimate the true error 105 by five order.
Remark 12.31 We can define the condition number of eigenvalues for simple
eigenvalues:
kxk2 kyk2
(1 ) ,
|xH y|
where x and y are the right and left eigenvectors, respectively. For multiple eigen-
values the condition number is not finite.
The power method. This method is due to von Mieses. Assume that A Rnn
has exactly n different real eigenvalues. Then the eigenvectors x1 , . . . , xn belonging
to the corresponding eigenvalues 1 , . . . , n are linearly independent. Assume that
the eigenvalues satisfy the condition
|1 | > |2 | |n |
and let v (0) Rn be a given vector. This vector is a unique linear combination of
the eigenvectors, that is v (0) = 1 x1 + 2 x2 + + n xn . Assume that 1 6= 0
12.3. Eigenvalue problems 541
and compute the sequence v (k) = Av (k1) = Ak v (0) (k = 1, 2, . . .). The initial
assumptions imply that
k+1
Pn
k+1
1 1 y T
x1 + i
i=2 i 1 y T
xi
y T Av (k) y T v (k+1)
= = 1 .
y T v (k) y T v (k) Pn k
k1 1 y T x1 + i=2 i 1i y T xi
Given the initial vector v (0) Rn , the power method has the following form.
Power-Method(A, v (0) )
1 k0
2 while exit condition = false
3 do k k + 1
4 z (k) Av (k1)
5 Select vector y such that y T v (k1) 6= 0
6 k y T z (k) /y T (k1)
v
(k)
(k)
7 (k)
v z / z
8 return k , v (k)
It is clear that
v (k) x1 , k 1 .
The convergence v (k) x1 here means that v (k) , x1 ] 0, that is the action line
of v (k) tends to the action line of x1 . There are various strategies to select y. We can
(k)
select y = ei , where i is defined by vi =
v (k)
. If we select y = v (k1) , then
k = v (k1)T Av (k1) / v (k1)T v (k1) will be identical with the Rayleigh quotient
R v (k1) . This choice gives an approximation of 1 that have the minimal residual
norm (Example 12.14 shows that this choice is not necessarily the best option).
The speed of convergence depends on the quotient |2 /1 |. The method is very
sensitive to the choice of the initial vector v (0) . If 1 = 0, then the process does
not converge to the dominant eigenvalue 1 . For certain matrix classes the power
method converges with probability 1 if the initial vector v (0) is randomly chosen.
In case of complex eigenvalues or multiple 1 we have to use modifications of the
algorithm. The speed of convergence can be accelerated if the method is applied to
the shifted matrix A I, where is an appropriately chosen number. The shifted
matrix A I has the eigenvalues 1 , 2 , . . . , n and the corresponding
convergence factor |2 | / |1 |. The latter quotient can be made smaller than
542 12. Scientific Computing
gives an estimate for the condition number of 1 (see Remark 12.31). In such a case
we use the exit condition
(1 ) kEk k2 .
The power method is very useful for large sparse matrices. It is often used to
determine the largest and the smallest eigenvalue. We can approximate the smallest
eigenvalue as follows. The eigenvalues of A1 are 1/1 , . . . , 1/n . The eigenvalue
1/n will be the eigenvalue with the largest modulus. We can approximate this
value by applying the power method to A1 . This requires only a small modification
of the algorithm. We replace line 4. with the following:
The modified algorithm is called the inverse power method. It is clear that
k 1/n and v (k) * xn hold under appropriate conditions. If we use the LU -
method to solve Az (k) = v (k1) , we can avoid the inversion of A.
If the inverse power method is applied to the shifted matrix A I, then the
1 1
eigenvalues of (A I) are (i ) . If approaches, say, to t , then i
i t . Hence the inequality
1 1
|t | > |i | (i 6= t)
holds for the eigenvalues of the shifted matrix. The speed of convergence is deter-
mined by the quotient
q = |t | / {max |i |} .
If is close enough to t , then q is very small and the inverse power iteration
converges very fast. This property can be exploited in the calculation of approx-
imate eigenvectors if an approximate eigenvalue, say , is known. Assuming that
det (A I) 6= 0, we apply the inverse power method to the shifted matrix A I.
In spite of the fact that matrix A I is nearly singular and the linear equation
(A I) z (k) = v (k) cannot be solved with high precision, the algorithm gives very
often good approximations of the eigenvectors.
Finally we note that in principle the von Mieses method can be modified to
determine all eigenvalues and eigenvectors.
12.3. Eigenvalue problems 543
We note that the QR-decomposition can be applied for solving linear systems
of equations, similarly to the LU -decomposition. If the QR-decomposition of A is
known, then the equation Ax = QRx = b can be written in the equivalent form
Rx = QT b. Thus we have to solve only an upper triangular linear system.
There are several methods to determine the QR-decomposition of a matrix. In
practice the Givens-, the Householder- and the MGS-methods are used.
The MGS (Modified Gram-Schmidt) method is a stabilised, but algebraically
equivalent version of the classical Gram-Schmidt orthogonalisation algorithm. The
m
basic problem is the following: We seek for an orthonormal basis {qj }j=1 of the
subspace
Xm
L {a1 , . . . , am } = j aj | j R, j = 1, . . . , m ,
j=1
qiT qj = 0 (i 6= j) , kqi k2 = 1 (i = 1, . . . , m)
and
L {a1 , . . . , am } = L {q1 , . . . , qm } .
The basic idea of the classical Gram-Schmidt-method is the following:
Let r11 = ka1 k2 and q1 = a1 /r11 . Assume that vectors q1 , . . . , qk1 are already
Pk1
computed and orthonormal. Assume that vector qk = ak j=1 rjk qj is such that
Pk1
qk qi , that is qkT qi = aTk qi j=1 rjk qjT qi = 0 holds for i = 1, . . . , k 1. Since
q1 , . . . , qk1 are orthonormal, qjT qi = 0 (i 6= j) and rik = aTk qi (i = 1, . . . , k 1).
After normalisation we obtain qk = qk / kqk k2 .
The algorithm is formalised as follows.
CGS-Orthogonalization(m, a1 , . . . , am )
1 for k 1 to m
2 do for i 1 to k 1
3 do rik aTk ai
4 ak ak rik ai
5 rkk kak k2
6 ak ak /rkk
7 return a1 , . . . , am
544 12. Scientific Computing
r11 r12 r13 ... r1m
0 r22 r23 ... r2m
0 0 r33 ... r3m
A = [a1 , . . . , am ] = [q1 , . . . , qm ] = QR .
| {z } .. .. .. .. ..
Q . . . . .
0 0 0 ... rmm
| {z }
R
MGS-Orthogonalisation(m, a1 , . . . , am )
1 for k 1 to m
2 do rkk kak k2
3 ak ak /rkk
4 for j k + 1 to m
5 do rkj aTj ak
6 aj aj rkj ak
7 return a1 , . . . , am
QT Q = I + E, kEk2
= cond (A) u ,
(A) and the lower triangular part of Ak tends to a diagonal matrix, whose entries will
be the eigenvalues of A. Here Qk is the orthogonal factor of the QR-decomposition
Ak = Qk Rk . Therefore Ak+1 = QTk (Qk Rk )Qk = Rk Qk . The basic algorithm is given
12.3. Eigenvalue problems 545
QR-Method(A)
1 k1
2 A1 A
3 while exit condition = false
4 do Compute the QR-decomposition Ak = Qk Rk
5 Ak+1 Rk Qk
6 k k+1
7 return Ak
where the entries of the submatrix denoted by do not converge. However the
eigenvalues of this submatrix will converge. This submatrix can be identified and
properly handled. A real matrix may have real and complex eigenvalues. If there is
a complex eigenvalues, than there is a corresponding conjugate eigenvalue as well.
For pairs of complex conjugated eigenvalues p is at least 2. Hence the sequence Ak
will show this phenomenon .
The QR-decomposition is very expensive. Its cost is (n3 ) flops for general nn
matrices. If A has upper Hessenberg form, the cost of QR-decomposition is (n2 )
flops.
546 12. Scientific Computing
Shifted-QR-Method(A)
1 H1 U 1 AU (H1 is of upper Hessenberg form)
2 k1
3 while exit condition = false
4 do compute the QR-decomposition Hk k I = Qk Rk
5 Hk+1 Rk Qk + k I
6 k k+1
7 return Hk
Exercises
1 1
12.3-1 Apply the power method to the matrix A = with the initial vector
0 2
1
v =
(0)
. What is the result of the 20th step?
1
12.4. Numerical program libraries and software tools 547
12.3-2 Apply the power method, the inverse power method and the QR-method to
the matrix
4 3 7
2 3 2 .
4 2 7
12.3-3 Apply the shifted QR-method to the matrix of the previous exercise with
the choice i = ( is fixed).
The word saxpy means that scalar alpha x plus y. The saxpy operation is imple-
mented in the following way.
Saxpy(, x, y)
1 n elements [x]
2 for i 1 to n
3 do z [i] = x [i] + y [i]
4 return z
The saxpy is a software driven operation. The cost of BLAS 1 routines is (n)
flops.
BLAS 2 routines. The matrix-vector operations of BLAS 2 requires n2
flops. These operations are y = Ax + y, y = Ax, y = A1 x, y = AT x, A
A + xy T and their variants. Certain operations work only with triangular matrices.
We analyse two operations in detail. The outer or dyadic product update
A A + xy T A Rmn , x Rm , y Rn
The notation : denotes all allowed indices. In our case this means the indices
1 j n. Thus A [i, :] denotes the ith row of matrix A.
The columnwise or ji variant:
Outer-Product-Update-Versionji(A, x, y)
1 n columns[A]
2 for j 1 to n
3 do A [:, j] A [:, j] + y [j] x
4 return A
Here A [:, j] denotes the j th column of matrix A. Observe that both variants are
based on the saxpy operation.
The gaxpy operation is defined by
z = y + Ax x Rn , y Rm , A Rmn .
The word gaxpy means that general A x plus y. The gaxpy operation is also
software driven and implemented in the following way:
12.4. Numerical program libraries and software tools 549
Gaxpy(A, x, y)
1 n columns[A]
2 zy
3 for j 1 to n
4 do z z + x [j] A [:, j]
5 return z
Observe that the computation is done columnwise and the gaxpy operation is
essentially a generalised saxpy.
BLAS 3 routines. These routines are the implementations of n3 matrix-
matrix and matrix-vector operations such as the operations C AB + C, C
AB T + C, B T 1 B (T is upper triangular) and their variants. BLAS 3
operations can be implemented in several forms. For example, the matrix product
C = AB can be implemented at least in three ways. Let A Rmr , B Rrn .
Matrix-Product-Dot-Version(A, B)
1 m rows[A]
2 r columns[A]
3 n columns[B]
4 C [1 : m, 1 : n] 0
5 for i 1 to m
6 do for j 1 to n
7 do for k 1 to r
8 do C [i, j] C [i, j] + A [i, k] B [k, j]
9 return C
This algorithm computes cij as the dot (inner) product of the ith row of A and
the j th column of B. This corresponds to the original definition of matrix products.
Now let A, B and C be partitioned columnwise as follows
A = [a1 , . . . , ar ] (ai Rm ) ,
B = [b1 , . . . , bn ] (bi Rr ) ,
C = [c1 , . . . , cn ] (ci Rm ) .
r
X
cj = bkj ak (j = 1, . . . , n) .
k=1
Matrix-Product-Gaxpy-Variant(A, B)
1 m rows[A]
2 r columns[A]
3 n columns[B]
4 C [1 : m, 1 : n] 0
5 for j 1 to n
6 do for k 1 to r
7 do for i 1 to m
8 do C [i, j] C [i, j] + A [i, k] B [k, j]
9 return C
Matrix-Product-with-Gaxpy-Call(A, B)
1 m rows[A]
2 n columns[B]
3 C [1 : m, 1 : n] 0
4 for j 1 to n
5 do C [:, j] = gaxpy (A, B [:, j] , C [:, j])
6 return C
bT1
B = ...
(bi Rn ) .
bTr
Pr
Then C = AB = k=1 ak bTk .
Matrix-Product-Outer-Product-Variant(A, B)
1 m rows[A]
2 r columns[A]
3 n columns[B]
4 C [1 : m, 1 : n] = 0
5 for k 1 to r
6 do for j 1 to n
7 do for i 1 to m
8 do C [i, j] C [i, j] + A [i, k] B [k, j]
9 return C
The inner loop realizes a saxpy operation: it gives the multiple of ak to the j th
column of matrix C.
12.4. Numerical program libraries and software tools 551
The MATLAB system. The MATLAB software was named after the expres-
sion MATrix LABoratory. The name indicates that the matrix operations are very
easy to make. The initial versions of MATLAB had only one data type: the complex
matrix. In the later versions high dimension arrays, cells, records and objects also
appeared. The MATLAB can be learned quite easily and even a beginner can write
programs for relatively complicated problems.
The coding of matrix operations is similar to their standard mathematical form.
For example if A and B are two matrices of the same size, then their sum is given
by the command C = A + B. As a programming language the MATLAB contains
only four control structures known from other programming languages:
the simple statement Z =expression, the if statement of the form
if expression, commands {else/elseif commands} end,
the for loop of the form
for the values of the loop variable, commands end
the while loop of the form
while expression, commands end.
The MATLAB has an extremely large number of built in functions that help efficient
programming. We mention the following ones as a sample.
max(A) selects the maximum element in every column of A,
[v, s] =eig(A) returns the approximate eigenvalues and eigenvectors of A,
The command A\b returns the numerical solution of the linear system Ax = b.
The entrywise operations and partitioning of matrices can be done very efficiently
in MATLAB. For example, the statement
exchange the second and third rows of A while it takes the reciprocal of each element.
The above examples only illustrate the possibilities and easy programming of
MATLAB. These examples require much more programming effort in other lan-
guages, say e.g. in PASCAL. The built in functions of MATLAB can be easily sup-
plemented by other programs.
The higher number versions of MATLAB include more and more functions and
special libraries (tool boxes) to solve special problems such as optimisation, statistics
and so on.
There is a built in automatic technique to store and handle sparse matrices
that makes the MATLAB competitive in solving large computational problems. The
recent versions of MATLAB offer very rich graphic capabilities as well. There is an
552 12. Scientific Computing
extra interval arithmetic package that can be downloaded from the WEB site
http:/www.ti3.tu-harburg.de\%7Erump\intlab
Problems
202 1212 2121 1131
1212 8181 15271 8484
B=
2121
.
15271 29694 16968
1131 8484 16968 9898
Thus an x0 approximation of the true solution x is given by x0 = Bb. Although
the true solution is also integer x0 is not an acceptable approximation. Apply the
iterative refinement with B instead of A1 to find an acceptable integer solution.
12-6 Consistent norm
Let kAk be a consistent norm and consider the linear system Ax = b
(i) Prove that if A + A is singular, then cond(A) kAk / kAk.
(ii)
1Show
that
for the
2-norm equality holds in (i), if A = bx /(b x) and
T t
A
kbk =
A1 b
.
2 2 2
(iii) Using the result of (i) give a lower bound to cond (A), if
1 1 1
A = 1 .
1
12-7 Cholesky-method
Use the Cholesky-method to solve the linear system Ax = b, where
5.5 0 0 0 0 3.5 1
0 5.5 0 0 0 1.5 1
0 0 6.25 0 3.75 0 1
A= 0 , b= .
0 0 5.5 0 0.5
1
0 0 3.75 0 6.25 0 1
3.5 1.5 0 0.5 0 5.5 1
Also give the exact Cholesky-decomposition A = LLT and the true solution of
Ax = b. The approximate Cholesky-factor L e satisfies the relation LLT = A + F. It
can proved that in a floating point arithmetic with t-digit mantissa and base the
entries of F satisfy the inequality |fi,j | ei,j , where
11 0 0 0 0 3.5
0 11 0 0 0 1.5
1t 0 0 0 0 0 0
E= .
0 0 0 11 0 0.5
0 0 0 0 0 0
3.5 1.5 0 0.5 0 11
Give a bound for the relative error of the approximate solution x, if = 16 and
t = 14 (IBM3033).
554 12. Scientific Computing
Chapter Notes
The a posteriori error estimates of linear algebraic systems are not completely
re-
liable. Demmel, Diament s Malajovich [60] showed that for the n2 number
estimators there are always cases when the estimate is unreliable (the error of the
estimate exceeds a given order). The first appearance of the iterative improvement
is due to Fox, Goodwin, Turing and Wilkinson (1946). The experiences show that
the decrease of the residual error is not monotone.
Young [?], Hageman and Young [100] give an excellent survey of the theory and
application of iterative methods. Barett, Berry et al. [22] give a software oriented
survey of the subject. Frommer [77] concentrates on the parallel computations.
The convergence of the QR-method is a delicate matter. It is analyzed in great
depth and much better results than Theorem 12.34 exist in the literature. There
are QR-like methods that involve double shifting. Batterson [23] showed that there
exists a 3 3 Hessenberg matrix with complex eigenvalues such that convergence
cannot be achieved even with multiple shifting.
Several other methods are known for solving the eigenvalue problems (see, e.g.
[259, 260]). The LR-method is one of the best known ones. It is very effective
on positive definite Hermitian matrices. The LR-method computes the Cholesky-
decomposition Ak = LL and sets Ak+1 = L L.
Bibliography
[1] R. P. Agarwal. Difference equations and inequalities. Marcel Dekker, New York, 2000. 504
[2] M. Agrawal, N. Kayal, N. Saxena. Primes is in p. Annals of Mathematics, 160(2):781793,
2004. 353
[3] M. Agrawal, N. Kayal, N. Saxena. PRIMES is in P.
http://www.cse.iitk.ac.in/users/manindra/, 2002. 353
[4] R. Ahlswede, B. Balkenhol, L. Khachatrian. Some properties of fix-free codes. In Proceedings
of the 1st International Seminarium on Coding Theory and Combinatorics, 1996 (Thahkad-
zor, Armenia), pages 2023. 167
[5] A. V. Aho, R. Sethi, J. D. Ullman. Compilers, Principles, Techniques and Tools. Addison-
Wesley, 1986. 130
[6] A. V. Aho, J. D. Ullman. The Theory of Parsing, Translation and Compiling Vol. I. Prentice-
Hall, 1972. 79, 130
[7] A. V. Aho, J. D. Ullman. The Theory of Parsing, Translation and Compiling Vol. II.
Prentice-Hall, 1973. 79, 130
[8] M. Ajtai. The shortest vector problem in L2 is NP-hard for randomized reductions. In Pro-
ceedings of the 30th Annual ACM Symposium on Theory of Computing, pages 1018, 1998.
274, 275
[9] M. Ajtai, J. Komls, E. Szemerdi. Sorting in c log n parallel steps. Combinatorica, 3(1):119,
1983. 213
[10] A. G. Akritas. Elements of Computer Algebra with Applications. John Wiley & Sons, 1989.
333
[11] S. Albers, H. Bals. Dynamic TCP acknowledgement, penalizing long delays. In Proceedings
of the 25th ACM-SIAM Symposium on Discrete Algorithms, pages 4755, 2003. 430
[12] V. Arvind, P. Kurur. Graph isomorphism is in SPP. In Proceedings of the 43rd IEEE Sym-
posium on Foundations of Computer Science, 743750 pages. IEEE Computer Society Press,
2002. 395
[13] J. Aspnes, Y. Azar, A. Fiat, S. Plotkin, O. Waarts. On-line load balancing with applications
to machine scheduling and virtual circuit routing. Journal of the ACM, 44:486504, 1997.
430, 431
[14] A. Asteroth, C. Christel. Theoretische Informatik. Pearson Studium, 2002. 79
[15] J-P. Aubin. Mathematical Methods of Game and Economic Theory. North-Holland, 1979.
480
[16] B. Awerbuch, Y. Azar S. Plotkin. Throughput-competitive online routing. In Proceedings of
the 34th Annual Symposium on Foundations of Computer Science, pages 3240, 1993. 430
[17] Y. Azar. On-line load balancing. Lecture Notes in Computer Science, Vol. 1442. Springer-
Verlag, pages 178195, 1998. 431
[18] L. Babai. Trading group theory for randomness. In Proceedings of the 17th ACM Symposium
on Theory of Computing, 421429 pages. ACM Press, 1985. 366
[19] L. Babai, S. Moran. Arthur-Merlin games: A randomized proof system, and a hierarchy of
complexity classes. Journal of Computer and Systems Sciences, 36(2):254276, 1988. 366
556 Bibliography
[20] B. S. Baker, J. S. Schwartz. Shelf algorithms for two dimensional packing problems. SIAM
Journal on Computing, 12:508525, 1983. 431
[21] B. Balkenhol, S. Kurtz. Universal data compression based on the Burrows-Wheeler transform:
theory and practice. IEEE Transactions on Computers, 49(10):10431053953, 2000. 168
[22] R. Barett, M. Berry, T. F. Chan, J. Demmel, J. Donato, J. Dongarra, V. Eijkhout, R. Pozzo,
C. Romine, H. van der Vorst. Templates for the Solution of Linear Systems: Building Blocks
for Iterative Methods. SIAM, 1994. 554
[23] S. Batterson. Convergence of the shifted QR algorithm on 33 normal matrices. Numerische
Mathematik, 58:341352, 1990. 554
[24] T. C. Bell, I. H. Witten, J. G. Cleary. Modeling for text compression. Communications of
the ACM, 21:557591, 1989. 167
[25] T. C. Bell, I. H. Witten, J. G. Cleary. Text Compression. Prentice Hall, 1990. 167, 168
[26] E. Bender, R. Canfield. The asymptotic number of labeled graphs with given degree se-
quences. Combinatorial Theory Series A, 24:296307, 1978. 213
[27] A. Beygelzimer, L. A. Hemaspaandra, C. Homan, J. Rothe. One-way functions in worst-case
cryptography: Algebraic and security properties are on the house. SIGACT News, 30(4):25
40, 1999. 366
[28] D. Boneh. Twenty years of attacks on the RSA cryptosystem. Notices of the AMS, 46(2):203
213, 1999. 366
[29] B. Borchert, L. A. Hemaspaandra, J. Rothe. Restrictive acceptance suffices for equivalence
problems. London Mathematical Society Journal of Computation and Mathematics, 86:86
95, 2000. 395
[30] A. Borodin R. El-Yaniv. Online computation and competitive analysis. Cambridge University
Press, 1998. 430
[31] J. G. Brookshear. Theory of Computation Formal Langauges, Automata, and Complexity.
The Benjamin/Cummings Publishing Company, 1989. 79
[32] L. E. J. Brouwer. ber Abbildung von Manningfaltigkeiten. Mathematische Annalen, 82(3
4):286292, 1921. 480
[33] T. Brueggemann, W. Kern. An improved deterministic local search algorithm for 3-SAT.
Theoretical Computer Science, 329(13):303313, 2004. 378, 394, 395
[34] B. Buchberger. Ein Algorithmus zum Auffinden der Basiselemente des Restklassenringes
nach einem nulldimensionalen Polynomideal, 1965. PhD dissertation, Leopold-Franzens-
Universitt, Innsbruck. 333
[35] M. Burrows, D. J. Wheeler. A block-sorting lossless data compression algorithm. Research
Report 124,
http://gatekeeper.dec.com/pub/DEC/SRC/research-reports/abstracts/src-rr-124.html,
1994. 167
[36] Calgary. The Calgary/Canterbury Text Compression.
ftp://ftp.cpsc.ucalgary.ca/pub/projects/text.compression. corpus, 2004. 168
[37] Canterbury. The Canterbury Corpus. http://corpus.canterbury.ac.nz, 2004. 168
[38] M. Capalbo, O. Reingold, S. Vadhan, A. Widgerson. Randomness conductors and constant-
degree lossless expanders. In Proceedings of the 34th ACM Symposium on Theory of Com-
puting, pages 443452, 2001. IEEE Computer Society. 214
[39] J. Carroll, D. Long. Theory of Finite Automata. Prentice Hall, 1989. 79
[40] J. L. Carter, M. N. Wegman. Universal classes of hash functions. Journal of Computer and
System Sciences, 18(2):143154, 1979. 386, 395
[41] B. F. Caviness. Computer algebra: past and future. Journal of Symbolic Computations,
2:217263, 1986. 333
[42] Y. Cho, S. Sahni. Bounds for list schedules on uniform processors. SIAM Journal on Com-
puting, 9(1):91103, 1980. 431
[43] S. M. Christensen. Resources for computer algebra. Computers in Physics, 8:308315, 1994.
333
[44] M. Chrobak, L. Larmore. An optimal algorithm for k-servers on trees. SIAM Journal on
Computing, 20:144148, 1991. 430
Bibliography 557
[45] M. Chrobak, L. Larmore. The server problem and on-line games. DIMACS Series in Discrete
Mathematics and Theoretical Computer Science, Vol. 7, pages 11-64. American Mathematical
Society, 1992. 430
[46] M. Chrobak, H. J. Karloff, T. Payne, S. Vishwanathan. New results on the server problem.
SIAM Journal on Discrete Mathematics, 4:172181, 1991. 430
[47] E. Coffman. Computer and Job Shop Scheduling. John Wiley & Sons, 1976. 431
[48] A. M. Cohen, L. van Gasten, S. Lunel (Eds.). Computer Algebra for Industry 2, Problem
Solving in Practice. John Wiley & Sons, 1995. 333
[49] A. M. Cohen (Ed.). Computer Algebra for Industry: Problem Solving in Practice. John Wiley
& Sons, 1993. 333
[50] S. Cook. The complexity of theorem proving procedures. In Proceedings of the 3th Annual
ACM Symposium on Theory of Computing, 151158 pages. ACM Press, 1971. 394
[51] K. D. Cooper, L. Torczon. Engineering a Compiler. Morgan Kaufman Publisher, 2004. 130
[52] D. Coppersmith. Small solutions to polynomial equations, and low exponent RSA vulnera-
bilities. Journal of Cryptology, 10(4):233260, 1997. 366
[53] T. H. Cormen, C. E. Leiserson, R. L. Rivest, C. Stein. Introduction to Algorithms (3rd edition,
second corrected printing). The MIT Press/McGraw-Hill, 2010. 167, 333
[54] T. M. Cover, J. A. Thomas. Elements of Information Theory. John Wiley & Sons, 1991. 168
[55] J. Csirik, G. Woeginger. On-line packing and covering problems. Lecture Notes in
Computer Science, Vol. 1442, pages 147177. Springer-Verlag, 1998. 430
[56] J. Csirik, G. J. Woeginger. Shelf algorithms for on-line strip packing. Information Processing
Letters, 63:171175, 1997. 431
[57] I. Csiszr, J. Krner. Coding Theorems for Discrete Memoryless Systems. Akadmiai Kiad,
1981. 168
[58] E. Dantsin, A. Goerdt, R. Kannan, J. Kleinberg, C. Papadimitriou, P. Raghavan, U. Schning.
A deterministic (2 2/(k + 1))n algorithm for k-sat based on local search. Theoretical Com-
puter Science, 289(1):6983, 2002. 378, 394, 395
[59] J. Davenport, Y. Siret, E. Tournier. Computer Algebra: Systems and Algorithms for Algebraic
Computation. Academic Press, 2000. 333
[60] J. Demmel, D. Malajovich. On the complexity of computing error bounds. Foundations of
Computational Mathematics, 1:101125, 2001. 554
[61] R. Dobrushin, S. Ortyukov. Lower bound for the redundancy of self-correcting arrangements
of unreliable functional elements. Problems of Information Transmission (translated from
Russian), 13(1):5965, 1977. 213
[62] R. Dobrushin, S. Ortyukov. Upper bound for the redundancy of self-correcting arrangements
of unreliable elements. Problems of Information Transmission (translated from Russian),
13(3):201208, 1977. 213
[63] D. R. Dooly, S. A. Goldman, S. D. Scott. On-line analysis of the TCP acknowledgement delay
problem. Journal of the ACM, 48:243273, 2001. 430, 431
[64] M. Drmota. Random Trees. SpringerWienNewYork, 2009. 504
[65] Gy. Dsa, Y. He. Better online algorithms for scheduling with machine cost. SIAM Journal
on Computing, 33(5):10351051, 2004. 431
[66] Gy. Dsa, Z. Tan. New upper and lower bounds for online scheduling with machine cost.
Discrete Optimization, 7(3):125135, 2010. 431
[67] D.-Z. Du, K-I. Ko. Problem Solving in Automata, Languages, and Complexity. John Wiley
& Sons, 2001. 79
[68] M. Effros, K. Viswesvariah, S. Kulkarni, S. Verd. Universal lossless source coding with the
Burrows-Wheeler transform. IEEE Transactions on Information Theory, 48(5):10611081,
2002. 168
[69] S. N. Elaydi. An Introduction to Difference Equations. Springer-Verlag, 1999 (2nd edition).
504
558 Bibliography
[70] S. Fenner, L. Fortnow, S. Kurtz. Gap-definable counting classes. Journal of Computer and
System Sciences, 48(1):116148, 1994. 389, 395
[71] A. Fiat, Y. Rabani, Y. Ravid. Competitive k-server algorithms. Journal of Computer and
System Sciences, 48:410428, 1994. 430
[72] A. Fiat, G. Woeginger (Eds.). Online Algorithms. The State of Art. Springer-Verlag, 1998.
430
[73] C. N. Fischer, R. LeBlanc (Eds.). Crafting a Compiler. The Benjamin/Cummings Publishing
Company, 1988. 130
[74] P. Flajolet, R. Sedgewick. Analytic Combinatorics. Addison-Wesley, 2009. 504
[75] R. Fleischer, M. Wahl. On-line scheduling revisited. Journal of Scheduling, 3(6):343353,
2000. 431
[76] F. Forg, J. Szp, F. Szidarovszky. Introduction to the Theory of Games: Concepts, Methods
and Applications. Kluwer Academic Publishers, 1999. 480
[77] A. Frommer. Lsung linearer Gleichungssysteme auf Parallelrechnern. Vieweg Verlag, 1990.
554
[78] I. Gal. Diophantine Equations and Power Integral Bases: New Computational Methods.
Birkhuser Boston, 2002. 275
[79] R. Gallager. Low-density Parity-check Codes. The MIT Press, 1963. 213
[80] M. R. Garey, D. S. Johnson. Computers and Intractability: A Guide to the Theory of NP-
Completeness. W. H. Freeman, 1979. 372, 373, 376, 394
[81] J. Gathen, von zur, J. Gerhard. Modern Computer Algebra second edition). Cambridge Uni-
versity Press, 2003. 274, 275
[82] J. Gathen, von zur. 333, 334
[83] F. Gcseg, I. Pek. Algebraic Theory of Automata. Akadmiai Kiad, 1972. 79
[84] P. Gcs. Reliable cellular automata with self-organization. Journal of Statistical Physics,
103(12):45267, 2001. See also www.arXiv.org/abs/math.PR/0003117 and The Proceedings
of the 1997 Symposium on the Theory of Computing. 214
[85] P. Gcs, A. Gl. Lower bounds for the complexity of reliable Boolean circuits with noisy
gates. IEEE Transactions on Information Theory, 40(2):579583, 1994. 213
[86] P. Gcs, J. Reif. A simple three-dimensional real-time reliable cellular array. Journal of
Computer and System Sciences, 36(2):125147, 1988. 214
[87] K. O. Geddes, S. Czapor, G. Labahn. Algorithms for Computer Algebra. Kluwer Academic
Publishers, 1992. 333, 334
[88] D. Giammarresi, R. Montalbano. Deterministic generalized automata. Theoretical Computer
Science, 215(12):191208, 1999. 79
[89] O. Goldreich, S. Micali, A. Wigderson. Proofs that yield nothing but their validity or all
languages in NP. Journal of the ACM, 38(3):691729, 1991. 362
[90] O. Goldreich. Foundations of Cryptography. Cambridge University Press, 2001. 366
[91] S. Goldwasser, S. Micali, C. Rackoff. The knowledge complexity of interactive proof systems.
SIAM Journal on Computing, 18(1):186208, 1989. 366
[92] R. L. Graham. Bounds for certain multiprocessor anomalies. The Bell System Technical
Journal, 45:15631581, 1966. 431
[93] R. L. Graham, D. E. Knuth, O. Patashnik. Concrete Mathematics. Addison-Wesley, 1994
(2nd edition). 504
[94] D. H. Greene, D. E. Knuth. Mathematics for the Analysis of Algorithms. Birkhuser, 1990
(3rd edition). 504
[95] D. Gries. Compiler Construction for Digital Computers. John Wiley & Sons, 1971. 130
[96] R. Grossman. Symbolic Computation: Applications to Scientific Computing. Frontiers in
Applied Mathematics. Vol. 5 SIAM, 1989. 333
[97] D. Grune, H. Bal, C. J. H. Jacobs, K. Langendoen. Modern Compiler Design. John Wiley
& Sons, 2000. 130
Bibliography 559
[98] J. Hstad. Solving simultaneous modular equations of low degree. SIAM Journal on Com-
puting, 17(2):336341, 1988. Special issue on cryptography. 366
[99] G. Hadley. Nonlinear and Dynamic Programming. Addison-Wesley, 1964. 480
[100] L. Hageman, D. Young. Applied Iterative Methods. Academic Press, 1981. 554
[101] T. S. Han, K. Kobayashi. Mathematics of Information and Coding. American Mathematical
Society, 2002. 168
[102] D. Hankerson, G. A. Harris, P. D. Johnson. Introduction to Information Theory and Data
Compression. Chapman & Hall, 2003 (2nd edition). 168
[103] D. Harper, C. Wooff, D. Hodginson. A Guide to Computer Algebra Systems. John Wiley &
Sons, 1991. 333
[104] M. A. Harrison. Introduction to Formal Language Theory. Addison-Wesley, 1978. 79
[105] A. C. Hearn. Future Directions for Research in Symbolic Computation. SIAM Reports on
Issues in the Mathematical Sciences. SIAM, 1990. 333
[106] L. A. Hemaspaandra, M. Ogihara. The Complexity Theory Companion. EATCS Texts in
Theoretical Computer Science. Springer-Verlag, 2002. 394
[107] L. A. Hemaspaandra, K. Pasanen, J. Rothe. If P 6= NP then some strongly noninvertible
functions are invertible. Theoretical Computer Science, 362(13):5462, 2006. 359, 366
[108] L. A. Hemaspaandra, J. Rothe. Creating strong, total, commutative, associative one-way
functions from any one-way function in complexity theory. Journal of Computer and Systems
Sciences, 58(3):648659, 1999. 359, 366
[109] C. Hoffman (Ed.). Group-Theoretic Algorithms and Graph Isomorphism. Lecture Notes in
Computer Science. Springer-Verlag, Vol. 136, 1982. 394
[110] C. Homan. Tight lower bounds on the ambiguity in strong, total, associative, one-way func-
tions. Journal of Computer and System Sciences, 68(3):657674, 2004. 366
[111] J. E. Hopcroft, R. Motwani, J. D. Ullman. Introduction to Automata Theory, Languages, and
Computation. Addison-Wesley, 2006 (in German: Einfhrung in Automatentheorie, Formale
Sprachen und Komplexittstheorie, Pearson Studium, 2002). 3rd edition. 79
[112] J. E. Hopcroft, J. D. Ullman. Introduction to Automata Theory, Languages, and Computa-
tion. Addison-Wesley, 1979. 79
[113] D. A. Huffman. A method for the construction of minimum-redundancy codes. Proceedings
of the IRE, 40(9):10981101, 1952. 167
[114] T. W. Hungerford. Abstract Algebra: An Introduction. Saunders College Publishers, 1990.
274
[115] R. W. Hunter. Compilers, Their Design and Construction using Pascal. John Wiley & Sons,
1985. 130
[116] Cs. Imreh. Online strip packing with modifiable boxes. Operations Research Letters, 66:79
86, 2001. 431
[117] Cs. Imreh. Online scheduling with general machine cost functions. Discrete Applied Mathe-
matics, 157(9):20702077, 2009. 431
[118] Cs. Imreh, T. Nmeth. On time lookahead algorithms for the online data acknowledgement
problem. In Proceedings of MFCS 2007 32nd International Symposium on Mathematical
Foundations of Computer Science, Lecture Notes in Computer Science, Vol. 4708. Springer-
Verlag, 2007, pages 288297. 430
[119] Cs. Imreh, J. Noga. Scheduling with machine cost. In Proceedings of APPROX99, Lecture
Notes in Computer Science, Vol. 1540, pages 168176, 1999. 431
[120] A. Ivnyi. Performance bounds for simple bin packing algorithms. Annales Universitatis
Scientiarum Budapestinensis de Rolando Etvs Nominatae, Sectio Computarorica, 5:77
82, 1984. 431
[121] A. Ivnyi (Ed.). Informatikai algoritmusok 1 (Algorithms of Informatics, Vol. 1). ELTE
Etvs Kiad, 2004. Elektronic version: ELTE Informatikai Kar, 2005. 10
[122] A. Ivnyi (Ed.). Informatikai algoritmusok 2 (Algorithms of Informatics, Vol. 2). ELTE
Etvs Kiad, 2005. 10
560 Bibliography
[123] A. Ivnyi (Ed.). Algorithms of Informatics, Vol. 1. mondAt Kiad, 2007. Elektronic version:
AnTonCom, Budapest, 2010. 10
[124] A. Ivnyi (Ed.). Algorithms of Informatics, Vol. 2. mondAt Kiad, 2007. Elektronic version:
AnTonCom, Budapest, 2010. 10
[125] K. Iwama, S. Tamaki. Improved upper bounds for 3-SAT. In J. Munro (Ed.) Proceedings
of the Fifteenth Annual ACM-SIAM Symposium on Discrete Algorithms, pages 328329.
Society for Industrial and Applied Mathematics, 2004. 394, 395
[126] D. S. Johnson. Near-Optimal Bin Packing Algorithms. PhD thesis, MIT Department of
Mathematics, 1973. 431
[127] D. S. Johnson. Fast algorithms for bin packing. Journal of Computer and System Sciences,
8:272314, 1974. 431
[128] D. S. Johnson, A. Demers, J. D. Ullman, M. R. Garey, R. L. Graham. Worst-case performance-
bounds for simple one-dimensional bin packing algorithms. SIAM Journal on Computing,
3:299325, 1974. 431
[129] S. Kakutani. A generalization of Brouwers fixed point theorem. Duke Mathematical Journal,
8:457459, 1941. 480
[130] B. Kaliski, M. Robshaw. The secure use of RSA. CryptoBytes, 1(3):713, 1995. 366
[131] S. Karamardian. The nonlinear complementarity problems with applications. I, II. Journal
of Optimization Theory and Applications, 4:8798 and 167181, 1969. 480
[132] Z. Karian, A. Starrett. Use of symbolic computation in probability and statistics. In Z. Karian
(Ed.), Symbolic Computation in Undergraduate Mathematics Education, Number 24 in Notes
of Mathematical Association of America. Mathematical Association of America, 1992. 334
[133] A. R. Karlin, C. Kenyon, D. Randall. Dynamic TCP acknowledgement and other stories about
e/(e1). In Proceedings of the 31st Annual ACM Symposium on Theory of Computing, 502
509 pages, 2001. 430
[134] R. M. Karp. Reducibility among combinatorial problems. In R. E. Miller, J. W. Thatcher
(Eds.), Complexity of Computer Computations, 85103 pages. Plenum Press, 1972. 394
[135] J. Kbler, U. Schning, S. Toda, J. Torn. Turing machines with few accepting computations
and low sets for PP. Journal of Computer and System Sciences, 44(2):272286, 1992. 365,
389, 395
[136] J. Kbler, U. Schning, J. Torn. Graph isomorphism is low for PP. Computational Com-
plexity, 2:301330, 1992. 389, 391, 395
[137] J. Kbler, U. Schning, J. Torn. The Graph Isomorphism Problem: Its Structural Complex-
ity. Birkhuser, 1993. 366, 394
[138] D. Kelley. Automata and Formal Languages. Prentice Hall, 1995. 79
[139] J. Kim, V. Vu. Generating random regular graphs. In Proceedings of the Thirty Fifth ACM
Symposium on Theory of Computing, pages 213222, 2003. 213
[140] D. E. Knuth. Fundamental Algorithms. The Art of Computer Programming. Vol. 1. Addison-
Wesley, 1968 (3rd updated edition). 333, 504
[141] D. E. Knuth. Seminumerical Algorithms. The Art of Computer Programming. Vol. 2.
Addison-Wesley, 1969 (3rd corrected edition). 333
[142] D. E. Knuth. Sorting and Searching. The Art of Computer Programming. Vol. 3. Addison-
Wesley, 1973 (3rd corrected edition). 333
[143] E. Koutsoupias, C. Papadimitriou. On the k-server conjecture. Journal of the ACM, 42:971
983, 1995. 430
[144] A. Kovcs. Computer algebra: Impact and perspectives. Nieuw Archief voor Wiskunde,
17(1):2955, 1999. 333
[145] D. C. Kozen. Automata and Computability. Springer-Verlag, 1995. 79
[146] R. Krichevsky, V. Trofimov. The performance of universal encoding. IEEE Transactions on
Information Theory, 27:199207, 1981. 167
[147] Z. Ksa. Combinatoric cu aplicaii (Combinatorics with Applications). Presa Universitar
Clujean, 2003. 504
Bibliography 561
[148] H. W. Kuhn, A. Tucker (Eds.). Contributions to the Theory of Games. II. Princeton Uni-
versity Press, 1953. 480
[149] S. Kurtz, B. Balkenhol. Space efficient linear time computation of the Burrows and Wheeler
transformation. In I. Althfer, N. Cai, G. Dueck, L. Khachatrian, M. Pinsker, A. Srkzy, I.
Wegener, Z. Zhang (Eds.), Numbers, Information and Complexity. Kluwer Academic Pub-
lishers, 2000, pages 375383. 168
[150] A. V. Kuznetsov. Information storage in a memory assembled from unreliablecomponents.
Problems of Information Transmission (translated from Russian), 9(3):254264, 1973. 213
[151] R. Ladner, N. A. Lynch, A. Selman. A comparison of polynomial time reducibilities.
Theoretical Computer Science, 1(2):103124, 1975. 382, 394
[152] G. Langdon. An introduction to arithmetic coding. IBM Journal of Research and Develop-
ment, 28:135149, 1984. 167
[153] M. V. Lawson. Finite Automata. Chapman & Hall/CRC, 2004. 79
[154] A. Lenstra, H. Lenstra. The Development of the Number Field Sieve. Lecture Notes in
Mathematics. Vol. 1554, Springer-Verlag, 1993. 357
[155] A. K. Lenstra, H. W. Lenstra, Jr., L. Lovsz. Factoring polynomials with integer coefficients.
Mathematische Annalen, 261:513534, 1982. 275, 330
[156] S. Leonardi. On-line network routing. Lecture Notes in Computer Science, Vol. 1442, pages
242267. Springer-Verlag, 1998. 430
[157] R. Lidl, H. Niederreiter. Introduction to Finite Fields and Their Applications. Cambridge
University Press, 1986. 274
[158] P. Linz. An Introduction to Formal Languages and Automata. Jones and Barlett Publishers,
2001. 79
[159] P. Linz. An Introduction to Formal Language and Automata. Jones and Bartlett Publishers,
Inc., 2006. 4th edition. 79
[160] M. Lothaire. Algebraic Combinatorics on Words. Cambridge University Press, 2002. 79
[161] K. Louden. Compilers and interpreters. In A. B. Tucker (ed.) Computer Science Handbook,
pages 99/199/30. Chapman & Hall/CRC, 2004. 130
[162] L. Lovsz. Combinatorial Problems and Exercises. Akadmiai Kiad/North Holland Publ.
House, 1979. 504
[163] L. Lovsz, P. Gcs. Algoritmusok (Algorithms). Mszaki Knyvkiad s Tanknyvkiad, 1978
and 1987. 9
[164] O. B. Lupanov. On a method of circuit synthesis. Izvestia VUZ (Radiofizika), pages 120140,
1958. 213
[165] R. Mak. Writing Compilers and Interpreters. Addison-Wesley, 1991. 130
[166] M. Manasse, L. McGeoch, D. Sleator. Competitive algorithms for server problems. Journal
of Algorithms, 11:208230, 1990. 430
[167] O. Mangasarian, H. Stone. Two-person zero-sum games and quadratic programming. Journal
of Mathematical Analysis and its Applications, 9:348355, 1964. 480
[168] Z. Manna. Mathematical Theory of Computation. McGraw-Hill Book Co., 1974. 79
[169] B. Martos. Nonlinear Programming Theory and Methods. Akadmiai Kiad, 1975. 480
[170] R. Mathon. A note on the graph isomorphism counting problem. Information Processing
Letters, 8(3):131132, 1979. 391
[171] A. Meduna. Automata and Languages: Theory and Applications. Springer-Verlag, 2000. 79
[172] A. Meyer, L. J. Stockmeyer. The equivalence problem for regular expressions with squaring
requires exponential space. In Proceedings of the 13th IEEE Symposium on Switching and
Automata Theory, pages 129129. 1972. 395
[173] D. Micciancio, S. Goldwasser. Complexity of Lattice Problems: A Cryptographic Perspective.
Vol. 671.,The Kluwer International Series in Engineering and Computer Science. Kluwer
Academic Publishers, 2002. 366
[174] R. E. Mickens. Difference Equations. Theory and Applications. Van Nostrand Reinhold,
1990. 504
562 Bibliography
[175] M. E. Mignotte. Mathematics for Computer Algebra. Springer, 1992. 333, 334
[176] G. L. Miller. Riemanns hypothesis and tests for primality. Journal of Computer and Systems
Sciences, 13(3):300317, 1976. 354
[177] H. Mills. Equilibrium points of finite games. SIAM Journal of Applied Mathematics, 8:397
402, 1976. 480
[178] B. E. Mishra. Algorithmic Algebra. Springer, 1993. 333
[179] R. N. Moll, M. A. Arbib, A. J. Kfoury. An Introduction to Formal Language Theory. Springer-
Verlag, 1988. 79
[180] B. Monien, E. Speckenmeyer. Solving satisfiability in less than 2n steps. Discrete Applied
Mathematics, 10:287295, 1985. 378, 395
[181] J. Moore. Protocol failures in cryptosystems. In G. Simmons (Ed.), Contemporary Cryptol-
ogy: The Science of Information Integrity, 541558 pages. IEEE Computer Society Press,
1992. 366
[182] R. Motwani, P. Raghavan. Randomized Algorithms. Cambridge University Press, 1995. 213
[183] S. Muchnick. Advanced Compiler Design and Implementation. Morgan Kaufman Publisher,
1997. 130
[184] J. Nash. Noncooperative games. Annals of Mathematics, 54:286295, 1951. 480
[185] M. Nelson, J. L. Gailly. The Data Compression Book. M&T Books, 1996. 168
[186] J. Neumann, O. Morgenstern. Theory of Games and Economical Behaviour. Princeton Uni-
versity Press, 1947 (2nd edition). 480
[187] J. Neumann. Probabilistic logics and the synthesis of reliable organisms from unreliable
components. In C. Shannon and P. J. McCarthy Eds. Automata Studies. Princeton University
Press, 1956, pages 4398. 213
[188] H. Nikaido, K. Isoda. Note on noncooperative games. Pacific Journal of Mathematics, 5:807
815, 1955. 480
[189] A. Odlyzko. Applications of Symbolic Mathematics to Mathematics. Kluwer Academic Pub-
lishers, 1985. 333
[190] K. Okuguchi. Expectation and Stability of Oligopoly Models. Springer, 1976. 480
[191] K. Okuguchi, F. Szidarovszky. The Theory of Oligopoly with Multi-Product Firms. Springer,
1999 (2nd edition). 480
[192] C. H. Papadimitriou. Computational Complexity. Addison-Wesley, 1994. 366, 394
[193] R. Pasco. Source Coding Algorithms for Fast Data Compression. PhD thesis, Stanford Uni-
versity, 1976. 167
[194] R. Paturi, P. Pudlk, M. Saks, F. Zane. An improved exponential-time algorithm for k-SAT.
In Proceedings of the 39th IEEE Symposium on Foundations of Computer Science, pages
628637. IEEE Computer Society Press, 1998. 394, 395
[195] R. Pavelle, M. Rothstein. Computer algebra. Scientific American, 245(12):102113, 1981.
333
[196] M. Pinsker. On the complexity of a concentrator. International Teletraffic Congr., 7:318/1
318/4, 1973. 213, 214
[197] N. Pippenger, G. Staomulis, J. N. Tsitsiklis. On a lower bound for the redundancy of reliable
networks with noisy gates. IEEE Transactions on Information Theory, 37(3):639643, 1991.
213
[198] N. Pippenger. Analysis of error correction by majority voting. In S. Micali (Ed.) Randomness
in Computation. JAI Press, 1989, 171198. 213
[199] N. Pippenger. On networks of noisy gates. In Proceeding of the 26th IEE FOCS Symposium,
pages 3038, 1985. 213
[200] T. Pittman. The Art of Compiler Design, Theory and Practice. Prentice Hall, 1992. 130
[201] J. M. Pollard. Theorems on factorization and primality testing. Proceedings of the Cambridge
Philosophical Society, 76:521528, 1974. 357
[202] M. Rabi, A. Sherman. An observation on associative one-way functions in complexity theory.
Information Processing Letters, 64(5):239244, 1997. 366
Bibliography 563
[203] M. O. Rabin. Probabilistic algorithms for testing primality. Journal of Number Theory,
12(1):128138, 1980. 354
[204] R. Rao, J. Rothe, O. Watanabe. Upward separation for FewP and related classes. Information
Processing Letters, 52(4):175180, 1994 (Corrigendum appears in the same journal,74(1
2):89, 2000). 395
[205] R. Reischuk, B. Schmelz, B.. Reliable computation with noisy circuits and decision treesa
general n log n lower bound. In Proceedings of the 32-nd IEEE FOCS Symposium, pages
602611, 1991. 213
[206] J. J. Rissanen. Generalized Kraft inequality and arithmetic coding. IBM Journal of Research
and Development, 20:198203, 1976. 167
[207] J. Ritt. Integration in Finite Terms. Columbia University Press, 1948. 333
[208] R. L. Rivest, A. Shamir, L. M. Adleman. A method for obtaining digital signatures and
public-key cryptosystems. Communications of the ACM, 21(2):120126, 1978. 352
[209] J. Robinson. An iterative method of solving a game. Annals of Mathematics, 154:296301,
1951. 480
[210] J. Rosen. Existence and uniqueness of equilibrium points for concave n-person games.
Econometrica, 33:520534, 1965. 480
[211] J. Rothe. Some facets of complexity theory and cryptography: A five-lecture tutorial. ACM
Computing Surveys, 34(4):504549, 2002. 356, 366
[212] J. Rothe. A promise class at least as hard as the polynomial hierarchy. Journal of Computing
and Information, 1(1):92107, 1995. 395
[213] J. Rothe. Complexity Theory and Cryptology. An Introduction to Cryptocomplexity. EATCS
Texts in Theoretical Computer Science. Springer-Verlag, 2005. 357, 366, 394
[214] G. Rozenberg, A. Salomaa. Handbook of Formal Languages, Volumes IIII. Springer-Verlag,
1997. 79
[215] A. Salomaa. Theory of Automata. Pergamon Press, 1969. 79
[216] A. Salomaa. Formal Languages. Academic Press, 1987 (2nd updated edition). 79
[217] A. Salomaa. Public-Key Cryptography. EATCS Monographs on Theoretical Computer Sci-
ence. Vol. 23., Springer-Verlag., 1996 (2nd edition). 366
[218] D. Salomon. Data Compression. Springer-Verlag, 2004 (3rd edition). 168
[219] K. Sayood. Introduction to Data Compression. Morgan Kaufman Publisher, 2000 (2nd edi-
tion). 168
[220] U. Schning. A low and a high hierarchy within NP. Journal of Computer and System
Sciences, 27:1428, 1983. 382, 385, 395
[221] U. Schning. Graph isomorphism is in the low hierarchy. Journal of Computer and System
Sciences, 37:312323, 1987. 395
[222] U. Schning. A probabilistic algorithm for k-SAT based on limited local search and restart.
In Proceedings of the 40th IEEE Symposium on Foundations of Computer Science, 410414
pages. IEEE Computer Society Press, 1999. 378, 394, 395
[223] U. Schning. Algorithmik. Spektrum Akademischer Verlag, 2001. 395
[224] R. Sedgewick, P. Flajolet. An Introduction to the Analysis of Algorithms. Addison-Wesley,
1996. 504
[225] A. Selman. Polynomial time enumeration reducibility. SIAM Journal on Computing,
7(4):440457, 1978. 394
[226] J. Sgall. On-line scheduling. Lecture Notes in Computer Science, Vol. 1442, pages 196231.
Springer-Verlag, 1998. 431
[227] A. Shamir. IP = PSPACE. Journal of the ACM, 39(4):869877, 1992. 361
[228] A. Shamir. RSA for paranoids. CryptoBytes, 1(3):14, 1995. 366
[229] C. Shannon. The synthesis of two-terminal switching circuits. The Bell Systems Technical
Journal, 28:5998, 1949. 213
[230] H. N. Shapiro. Note on a computation method in the theory of games. Communications on
Pure and Applied Mathematics, 11:587593, 1958. 480
564 Bibliography
[231] D. B. Shmoys, J. Wein, D. P. Williamson. Scheduling parallel machines online. SIAM Journal
on Computing, 24:13131331, 1995. 431
[232] I. E. Shparlinski. Finite Fields: Theory and Computation The Meeting Point of Number
Theory, Computer Science, Coding Theory, and Cryptography. Kluwer Academic Publishers,
1999. 274
[233] M. Simon. Automata Theory. World Scientific Publishing Company, 1999. 79
[234] D. A. Simovoci, R. L. Tenney. Theory of Formal Languages with Applications. World
Scientific Publishing Company, 1999. 79
[235] S. Singh. The Code Book. The Secret History of Codes and Code Breaking. Fourth Estate,
1999. 366
[236] M. Sipser. Introduction to the Theory of Computation. PWS Publishing Company, 1997. 79
[237] M. Sipser, D. A. Spielman. Expander codes. IEEE Transactions on Information Theory,
42(6):17101722, 1996. 214
[238] D. Sleator R. E. Tarjan. Amortized efficiency of list update and paging rules. Communications
of the ACM, 28:202208, 1985. 431
[239] N. P. Smart. The Algorithmic Resolution of Diophantine Equations. London Mathematical
Society Student Text, Vol. 41. Cambridge University Press, 1998. 275
[240] R. Solovay, V. Strassen. A fast Monte Carlo test for primality. SIAM Journal on Computing,
6:8485, 1977. Erratum appears in the same journal, 7(1):118, 1978. 354
[241] D. Spielman. Linear-time encodable and decodable error-correcting codes. In Proceedings of
the 27th ACM STOC Symposium, 1995, 387397 (further IEEE Transactions on Information
Theory 42(6):17231732). 213
[242] D. Spielman. Highly fault-tolerant parallel computation. In Proceedings of the 37th IEEE
Foundations of Computer Science Symposium, pages 154163, 1996. 213
[243] D. Stinson. Cryptography: Theory and Practice. CRC Press, 2002 (2nd edition). 357, 366
[244] L. J. Stockmeyer. The polynomial-time hierarchy. Theoretical Computer Science, 3(1):122,
1977. 395
[245] H. Straubing. Finite Automata, Formal Logic, and Circuit Complexity. Birkhuser, 1994. 79
[246] T. A. Sudkamp. Languages and Machines. Addison-Wesley, 1997. 79
[247] F. Szidarovszky, C. Chiarella. Dynamic oligopolies, stability and bifurcation. Cubo Math-
emtica Educational, 3(2):267284, 2001. 480
[248] F. Szidarovszky, S. Yakowitz. Principles and Procedures of Numerical Analysis. Plenum
Press, 1998. 480
[249] A. Tarski. A lattice-theoretical fixpoint theorem and its application. Pacific Journal of Math-
ematics, 5:285308, 1955. 480
[250] D. S. Taubman, M. W. Marcelin. JPEG 2000 Image Compression, Fundamentals, Stan-
dards and Practice. Society for Industrial and Applied Mathematics, 1983. 168
[251] M. G. Taylor. Reliable information storage in memories designed from unreliable components.
The Bell Systems Technical Journal, 47(10):22992337, 1968. 213
[252] J-P. Tremblay, P. G. Sorenson. Compiler Writing. McGraw-Hill Book Co., 1985. 130
[253] A. Turing. On computable numbers, with an application to the Entscheidungsproblem. Pro-
ceedings of the London Mathematical Society, ser. 2, 2:230265, 1936 (Correction, ibid, vol.
43, pages 544546, 1937). 368
[254] J. J. Uhl. Mathematica and Me. Notices of AMS, 35:13451345, 1988. 334
[255] L. G. Valiant. The relative complexity of checking and evaluating. Information Processing
Letters, 5(1):2023, 1976. 395
[256] A. van Vliet. An improved lower bound for on-line bin packing algorithms. Information
Processing Letters, 43:277284, 1992. 431
[257] N. J. Vilenkin. Combinatorial Mathematics for Recreation. Mir, 1972. 504
[258] G. Wallace. The JPEG still picture compression standard. Communications of the ACM,
34:3044, 1991. 168
Bibliography 565
[259] D. Watkins. Bulge exchanges in algorithms of QR type. SIAM Journal on Matrix Analysis
and Application, 19(4):10741096, 1998. 554
[260] J. Wilkinson. Convergence of the LR, QR, and related algorithms. The Computer Journal,
8(1):7784, 1965. 554
[261] F. M. J. Willems, Y. M. Shtarkov, T. J. Tjalkens. The context-tree weighting method: basic
properties. IEEE Transactions on Information Theory, 47:653664, 1995. 167
[262] F. M. J. Willems, Y. M. Shtarkov, T. J. Tjalkens. The context-tree weighting method: basic
properties. IEEE Information Theory Society Newsletter, 1:1 and 2027, 1997. 167
[263] I. H. Witten, R. M. Neal, J. G. Cleary. Arithmetic coding for sequential data compression.
Communications of the ACM, 30:520540, 1987. 167
[264] A. C. C. Yao. New algorithms for bin packing. Journal of the ACM, 27:207227, 1980. 431
[265] N. Young. On-line file caching. Algorithmica, 33:371383, 2002. 430
[266] J. Ziv, A. Lempel. A universal algorithm for sequential data compression. IEEE Transactions
on Information Theory, 23:337343, 1977. 167
[267] J. Ziv, A. Lempel. Compression of individual sequences via variable-rate coding. IEEE Trans-
actions on Information Theory, 24:530536, 1978. 167
[268] S. I. Zuhovitsky, R. A. Polyak, M. E. Primak. Concave n-person games (numerical methods).
konomika i Matematicheskie Methody, 7:888900, 1971 (in Russian). 480
[269] A. van Vliet. Lower and upper bounds for on-line bin packing and scheduling heuristics. PhD
thesis, Erasmus University, Rotterdam, 1995. 431
[270] A. Vestjens. On-line machine scheduling. PhD thesis, Eindhoven University of Technology,
1997. 431
This bibliography is made by HBibTEX. First key of the sorting is the name of the
authors (first author, second author etc.), second key is the year of publication, third
key is the title of the document.
Underlying shows that the electronic version of the bibliography on the homepage
of the book contains a link to the corresponding address.
Index
This index uses the following conventions. Numbers are alphabetised as if spelled out; for
example, 2-3-4-tree" is indexed as if were two-three-four-tree". When an entry refers to a place
other than the main text, the page number is followed by a tag: ex for exercise, fig for figure, pr
for problem and fn for footnote.
The numbers of pages containing a definition are printed in italic font, e.g.
A encryption-key, 341
abelian monoid, see monoid known-plaintext, 341
absolute error, 514exe
accept, 100, 119 attribute
action table, 119, 125 grammar, 92
actual augmented grammar, 110
symbol, 99, 104 automata
aggregation function, 441 equivalence, 34
minimization, 45
Alarm algorithm, 406, 430pr nondeterministic pushdown, 61
alarming algorithm, 406 pushdown, 60
algebra, 216275, 273 Automaton-Minimization, 46
algebraic automaton
element, 318 deterministic
extension, 315, 319, 323, 327 finite, 85
number field, 319, 321 finite, 26
algebraic number field, 274 pushdown, 78exe
algorithms of compilers, 80 automorhism
alphabet, 13 of a graph, 345
ambiguous CF grammar, 71 automorphism, 234
analyser, 82 average case analysis, 397
lexical, 81, 82
semantic, 81, 83, 92
syntactic, 81, 82, 92 B
arithmetic coding, 142 Back-Substitution, 516
Arithmetic-Decoder, 144 Backtracking-SAT, 377
Arithmetic-Encoder, 143 backward error, 507
arithmetic overflow, 514exe backward error analysis, 507
Arithmetic-Precision-Encoder, 146 backward induction, 436
arithmetic underflow, 514exe Backward-Induction, 438
ascending chain of ideals, 306, 308 backward stable, 507
assembly language program, 83 BAL, see Balance
associate polynomials, 222 Balance, 400
associative, 217 balancing, 533
asymptotically C-competitive, 398 banded matrix, 524
asymptotic competitive ratio, 398 basis
attack of a lattice, 249, 251, 270, 272
chosen-plaintext, 341 reduced, 257259, 260exe, 270
ciphertext-only, 341 weakly reduced, 256, 257
of a vector space, 219, 230, 273, 274
Index 567
This index uses the following conventions. If we know the full name of a cited person, then we
print it. If the cited person is not living, and we know the correct data, then we print also the year
of her/his birth and death.
CS G
Csrnyei, Zoltn, 3, 10, 11 Gal, Istvn, 275, 558
Csirik, Jnos, 421, 430, 431, 557 Gcs, Pter, 3, 9, 10, 214, 558, 561
Csiszr, Imre, 168, 557 Gailly, J. L., 562
Gl, Anna, 3, 11, 558
Galntai, Aurl, 3, 10
D Gallager, Robert G., 213, 558
Dmsi, Pl, 3, 11 Garey, Michael R., 394, 430, 558, 560
Dantsin, E., 394, 557 Gathen, Joachim von zur, 274, 558
Davenport, J. H., 557 Gauss, Johann Carl Friedrich (17771855),
Demers, Alan, 430, 560 253, 280, 288, 297, 330, 516, 518, 520522,
Demetrovics, Jnos, 3, 11 524, 526, 546
Demmel, J., 556, 557 Gcseg, Ferenc, 79, 558
De Remer, F. L., 130 Geddes, Keith Oliver, 333, 558
Diament, B., 554 Gerhard, Jrgen, 274, 558
Dickson, Leonard Eugene, 306, 311 Gersgorin, S. A., 538
Diffie, Whitfield, 335 Giammarresi, Dora, 79, 558
Dobrushin, Roland Lvovitsch (19291995), Givens, Wallace J., 543
213, 557 Goerdt, A., 557
Domoszlai, Lszl, 11 Goldman, A. Sally, 405, 430, 557
Donato, J., 556 Goldreich, Oded, 366, 558
Dongarra, Jack, 556 Goldwasser, Shaffi, 558, 561
Dooly, R. Dan, 405, 430, 557 Gonda, Jnos, 3, 11
Dsa, Gyrgy, 557 Gonnet, Haas Gaston Henry, 333
Drmota, Michael, 504, 557 Goodwin, E. T., 554
Du, Ding-Zhu, 557 Goos, Gerhard, 130
Dueck, Gunter, 560 Grbner, Wolfgang Anton Maria, 277, 302,
306, 308, 309, 311, 329
Graham, Ronald Lewis, 421, 430, 431, 504,
E 558, 560
Earley, J., 130 Gram, Jorgen Pedersen (18501916), 251,
Eastern Hungarian Informatics Books 255, 543, 544
Repository, 3 Greene, Daniel H., 504, 558
Effros, Michelle, 557 Gries, David, 130, 558
Eijkhout, V., 556 Grossman, R., 558
Elaydi, Saber N., 504, 557 Grune, Dick, 130, 558
Elias, Peter, 138 Gyres, Tibor, 3, 11
Elsner, Ludwig, 539
El-Yaniv, Ran, 556
Englert, Burkhard, 3, 10 H
Erdlyi, Gbor, 395 Hstad, Johan, 558
Euclid of Alexandria (i.e. 365300), 283 Hadamard, Jacques Salomon (18651963),
Euler, Leonhard (17071783), 220, 343 256
European Social Fund, 3 Hadley, George F., 480, 558
European Union, 3 Hageman, L. A., 554, 558
Han, Te Sun, 558
Hankerson, D., 559
F Harper, D., 559
Flp, Zoltn, 3, 11 Harris, G. A., 559
Fan, Ky, 441, 442, 467, 480 Harrison, Michael A., 79, 559
Fano, Robert M., 138 He, Yong, 557
Fenner, S., 557 Hearn, Anthony Clern, 333, 559
Fermat, Pierre, de (16011655), 230 Hellman, Martin E., 335
Fiat, Amos, 402, 430, 431, 555, 557, 558 Hemaspaandra, Lane A., 394, 556, 559
Fibonacci, Leonardo Pisano (11701250), Hensel, Kurt Wilhelm Sebastian
481, 483, 489, 492 (18611913), 265, 330
Fischer, C. N., 130, 558 Hermite, Charles (18221901), 259, 312314,
Flajolet, Philippe, 504, 558, 563 325, 333
Fleischer, Rudolf, 431, 558 Hessenberg, Gerhard, 546, 554
Fohry, Claudia, 3, 11 Hilbert, David, 533, 537, 552
Forg, Ferenc, 480, 558 Hilbert, David (18621943), 305307, 330
Fortnow, L., 557 Hironaka, Heisuke, 333
Fox, L., 554 Hodginson, D., 559
Fridli, Sndor, 3, 11 Hoffman, C., 394, 559
Frobenius, Ferdinand Georg (18491917), Homan, C., 556, 559
232, 330 Hopcroft, John E., 79, 559
Frommer, Andreas, 554, 558 Horowitz, Ellis, 314
Householder, Alston Scott, 543
Huang, Ming-Deh, 274
Name Index 577
Huffman, David A. (19251999), 139, 167, Kurtz, Stefan, 556, 557, 560
559 Kurur, P., 395, 555
Hungerford, Thomas W., 274, 559 Kutta, Wilhelm Martin (18671944), 461
Hunter, Robin, 130, 559 Kuznetsov, A. V., 560
I L
emel, J., 554 Labahn, G., 558
Imreh, Csand, 3, 10, 430, 559 Ladner, Richard E., 394, 561
Isoda, K., 562 Lagrange, Joseph Louis (17361813), 220,
Ivnyi, Anna Barbara, 3, 11 458
Ivnyi, Antal Mikls, 3, 9, 11, 431, 559 Landau, Edmund Georg Hermann
Ivanyos, Gbor, 3, 10, 11 (18771938), 290, 298, 300, 301
Iwama, K., 394, 559 Langdon, G. G., Jr., 561
Langendoen, Koen G., 130, 558
Larmore, Lawrence, 402, 430, 556
J Laurent, Pierre Alphonse (18131854), 299,
Jacobi, Carl Gustav Jacob (18041851), 443, 311, 325
526, 527 Lawson. M. V., 561
Jacobs, Ceriel J. H., 130, 558 Lazard, Daniel, 316
Jankowski, T., 536 LeBlanc, R. J., 130, 558
Jrai, Antal, 3, 10 Leibniz, Gottfried Wilhelm (16461716),
Jeney, Andrs, 3, 10 228, 312
Johnson, David S., 394, 430, 431, 560 Leiserson, Charles E., 167, 557
Johnson, P. D., 559 Lempel, Abraham, 132, 167, 565
Jordan, Camille, 539 Lenstra, Arjen Klaas, 248, 269, 275, 330, 561
Lenstra, Hendrik Willem, Jr., 248, 269, 275,
330, 561
K Leonardi, Stefano, 430, 561
Kbler, J., 366, 394, 395, 560 Lidl, Rudolf, 274, 561
Krner, Jnos, 168, 557 Lie, Marius Sophus, 329
Kahan, W., 513 Linz, P., 561
Kakutani, Shizou, 440, 480, 560 Linz, Peter, 79, 561
Kaliski, B. Jr., 560 Liouville, Joseph, 277, 317, 320, 323, 327
Kaltofen, Erich L., 274 Locher, Kornl, 11
Kannan, Ravindran, 557 Long, Darrell, 556
Karamardian, S., 560 Lothaire, M., 79, 561
Karian, Z. A., 560 Louden, Kenneth C., 130, 561
Karlin, Anna R., 430, 560 Lovsz, Lszl, 3, 9, 248, 257, 269, 275, 330,
Karloff, J. Howard, 430, 557 504, 561
Karp, Richard M., 560 Lunel, Sjoerd Verduyn, 557
Ksa, Zoltn, 3, 10, 504, 560 Lupanov, Oleg Borisovitsch, 213, 561
Kasami, T., 130 Lynch, Nancy Ann, 394, 561
Katsnyi, Istvn, 3, 11
Kayal, Neeraj, 353, 555
Kelley, D., 560 M
Kenyon, Claire, 430, 560 Majzik, Istvn, 3, 11
Kern, W., 556 Mak, Ronald, 130, 561
Kfoury, A. J., 562 Malajovich, Diement G., 554, 557
Khachatrian, Levon (19542002), 167, 555, Malewicz, Grzegorz, 3, 11
560 Manasse, Mark, 399, 430, 561
Kim, J. H., 213, 560 Mangasarian, Olvi L., 561
Kiss, Attila, 3, 11 Manna, Zohar, 79, 561
Kleene, Stephen C., 51 Marcelin, M. W., 564
Kleinberg, J., 557 Marton 2001. Kft., 11
Klyuyev, v. v., 520 Martos, Bla, 480, 561
Knuth, Donald Ervin, 130, 333, 504, 558, 560 Mathon, R., 391, 561
Ko, Ker-I, 557 Mayer, Jnos, 3, 11
Kobayashi, Kingo, 558 McCarthy, Paul J., 562
Kokovkin-Shcherbak, N., 520 McGeoch, Lyle, 399, 430, 561
Komls, Jnos, 555 Meduna, A., 561
Koutsoupias, Elias, 402, 430, 560 Meyer, A., 395, 561
Kovcs, Attila, 3, 10, 333, 560 Micali, Silvio, 558, 562
Kowalski, Dariusz, 3, 10 Micciancio, D., 561
Kozen, D. C., 560 Mickens, Ronald Elbert, 504, 561
Krichevsky, R. E., 147, 560 Mignotte, Maurice, 262, 290, 298301, 333,
Kuhn, Harold W., 443, 480, 560 561
Kulkarni, S. R., 557 Mikls, Istvn, 3, 11
Kung, H. T., 223 Miller, Gary L., 354, 561
578 Name Index