Notes
Notes
In this course we will see how logic can be used to study complexity
theory. In particular, we will look at how complexity relates to
definability.
3 4
Complexity is usually defined in terms of running time or space For simplicity, we often focus on decision problems.
asymptotically required by an algorithm. E.g.
• Merge Sort runs in time O(n log n). As an example, consider the following three decision problems on
graphs.
• Any sorting algorithm that can sort an arbitrary list of n
numbers requires time Ω(n log n). 1. Given a graph G = (V, E) does it contain a triangle?
2. Given a directed graph G = (V, E) and two of its vertices
Complexity theory is concerned with the hardness of problems s, t ∈ V , does G contain a path from s to t?
rather than specific algorithms. 3. Given a graph G = (V, E) is it 3-colourable? That is,
We will mostly be concerned with broad classification of is there a function χ : V → {1, 2, 3} so that whenever
complexity: logarithmic vs. polynomial vs. exponential. (u, v) ∈ E, χ(u) 6= χ(v).
5 6
1. Checking if G contains a triangle can be solved in polynomial In what kind of formal language can these decision problems be
time and logarithmic space. specified or defined?
2. Checking if G contains a path from s to t can be done in The graph G = (V, E) contains a triangle.
polynomial time.
Can it be done in logarithmic space?
∃x ∈ V ∃y ∈ V ∃z ∈ V (x 6= y∧y 6= z∧x 6= z∧E(x, y)∧E(x, z)∧E(y, z))
Unlikely. It is NL-complete.
3. Checking if G is 3-colourable can be done in exponential time The other two properties are provably not definable with only
and polynomial space. first-order quantification over vertices.
Can it be done in polynomial time?
Unlikely. It is NP-complete.
7 8
3-Colourability and reachability can be defined with quantification This course is concerned with the questions of (1) how definability
over sets of vertices. relates to computational complexity and (2) how to analyse
definability.
∃R ⊆ V ∃B ⊆ V ∃G ⊆ V
∀x(Rx ∨ Bx ∨ Gx)∧ 1. Complexity Theory—a review of the major complexity classes
and their interrelationships (3L).
∀x(¬(Rx ∧ Bx) ∧ ¬(Bx ∧ Gx) ∧ ¬(Rx ∧ Gx))∧
∀x∀y(Exy → (¬(Rx ∧ Ry)∧ 2. First-order and second-order logic—their expressive power and
computational complexity (3L).
¬(Bx ∧ By)∧
¬(Gx ∧ Gy))) 3. Lower bounds on expressive power—the use of games and
locality (3L).
∀S ⊆ V (s ∈ S ∧ ∀x∀y((x ∈ S ∧ E(x, y)) → y ∈ S) → t ∈ S) 4. Fixed-point logics and descriptive complexity (3L).
5. Monadic Second-Order Logic and Automata (4L).
9 10
11 12
For our purposes, a Turing Machine consists of: A complete description of the configuration of a machine can be
given if we know what state it is in, what are the contents of its
• K — a finite set of states;
tape, and what is the position of its head. This can be summed up
• Σ — a finite set of symbols, including ⊔. in a simple triple:
• s ∈ K — an initial state; Definition
• δ : (K × Σ) → (K ∪ {a, r}) × Σ × {L, R, S} A configuration is a triple (q, w, u), where q ∈ K and w, u ∈ Σ⋆
Computations Computations
Given a machine M = (K, Σ, s, δ) we say that a configuration The relation →⋆M is the reflexive and transitive closure of →M .
(q, w, u) yields in one step (q ′ , w′ , u′ ), written A sequence of configurations c1 , . . . , cn , where for each i,
ci →M ci+1 , is called a computation of M .
(q, w, u) →M (q ′ , w′ , u′ )
The language L(M ) ⊆ Σ⋆ accepted by the machine M is the set of
if strings
• w = va ;
{x | (s, ⊲, x) →⋆M (acc, w, u) for some w and u}
′
• δ(q, a) = (q , b, D); and
• either D = L and w′ = v u′ = bu
or D = S and w′ = vb and u′ = u
A machine M is said to halt on input x if for some w and u, either
or D = R and w′ = vbc and u′ = x, where u = cx. If u is
(s, ⊲, x) →⋆M (acc, w, u) or (s, ⊲, x) →⋆M (rej, w, u)
empty, then w′ = vb⊔ and u′ is empty.
15 16
Complexity Nondeterminism
For any function f : IN → IN, we say that a language L is in If, in the definition of a Turing machine, we relax the condition on
TIME(f (n)) if there is a machine M = (K, Σ, s, δ), such that: δ being a function and instead allow an arbitrary relation, we
obtain a nondeterministic Turing machine.
• L = L(M ); and
• The running time of M is O(f (n)). δ ⊆ (K × Σ) × (K ∪ {a, r} × Σ × {R, L, S}).
The last statement means that for each x ∈ L(M ), there is a (q00 , u00 , w00 ) (rej, u2 , w2 )
computation of M that accepts x and whose length is bounded by
(q10 , u10 , w10 ) (q11 , u11 , w11 )
O(f (|x|)). . .
. .
. .
19 20
A complexity class is a collection of languages determined by three By making the bounds broad enough, we can make our definitions
things: fairly independent of the model of computation.
• A model of computation (such as a deterministic Turing The collection of languages recognised in polynomial time is
machine, or a nondeterministic TM, or a parallel Random the same whether we consider Turing machines, register
Access Machine). machines, or any other deterministic model of computation.
• A resource (such as time, space or number of processors). The collection of languages recognised in linear time, on
the other hand, is different on a one-tape and a two-tape
• A set of bounds. This is a set of functions that are used to
Turing machine.
bound the amount of resource we can use.
We can say that being recognisable in polynomial time is a
property of the language, while being recognisable in linear time is
sensitive to the model of computation.
21 22
23 24
∞
[ ∞
[
k
P= TIME(n ) NP = NTIME(nk )
k=1 k=1
The class of languages decidable in polynomial time.
That is, NP is the class of languages accepted by a
The complexity class P plays an important role in complexity
nondeterministic machine running in polynomial time.
theory.
Since a deterministic machine is just a nondeterministic machine in
• It is robust, as explained.
which the transition relation is functional, P ⊆ NP.
• It serves as our formal definition of what is feasibly computable
25 26
The complexity class NP can be characterised as the collection of If L = {x | ∃y R(x, y)} we can define a nondeterministic machine
languages of the form: M that accepts L.
Where R is a relation on strings satisfying two key conditions In the other direction, suppose we are given a nondeterministic
machine M which runs in time p(n).
1. R is decidable in polynomial time.
Suppose that for each (q, σ) ∈ K × Σ (i.e. each state, symbol pair)
2. R is polynomially balanced. That is, there is a polynomial p there are at most k elements in δ(q, σ).
such that if R(x, y) and the length of x is n, then the length of
y is no more than p(n).
27 28
For y a string over the alphabet {1, . . . , k}, we define the relation L = SPACE(log n)
R(x, y) by: The class of languages decidable in logarithmic space.
• |y| ≤ p(|x|); and NL = NSPACE(log n)
The class of languages decidable by a nondeterministic machine in
• the computation of M on input x which, at step i takes the
logarithmic space.
“y[i]th transition” is an accepting computation. S∞
PSPACE = k=1 SPACE(nk )
The class of languages decidable in polynomial space.
Then, L(M ) = {x | ∃y R(x, y)} S∞
NPSPACE = k=1 NSPACE(nk )
29 30
We have the following inclusions: To simulate a nondeterministic machine M running in time t(n) by
a deterministic one, it suffices to carry out a depth-first search of
L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE ⊆ NPSPACE ⊆ EXP the computation tree.
We keep a counter to cut off branches that exceed t(n) steps.
S∞ nk
where EXP = k=1 TIME(2 ) The space required is:
Of these, the following are direct from the definitions: • a counter to count up to t(n); and
• a stack of configurations, each of size at most O(t(n)).
L ⊆ NL The depth of the stack is at most t(n).
P ⊆ NP Thus, if t is a polynomial, the total space required is polynomial.
PSPACE ⊆ NPSPACE
31 32
Given a nondeterministic machine M that works with work space M accepts x if, and only if, some accepting configuration is
bounded by s(n) and an input x of length n, there is some constant reachable from the starting configuration in the configuration graph
c such that of M, x.
Define the configuration graph of M, x to be the graph whose nodes c′ (ncs(n) )2 ∼ c′ c2(log n+s(n)) ∼ d(log n+s(n))
are the possible configurations, and there is an edge from i to j if,
for some constant d.
and only if, i →M j.
If Reachability were solvable by a deterministic machine with O((log n)2 ) space Reachability algorithm:
logarithmic space, then
L = NL. Path(a, b, i)
if i = 1 and (a, b) is not an edge reject
else if (a, b) is an edge or a = b accept
In fact, Reachability is solvable by a deterministic machine with else, for each node x, check:
space O((log n)2 ). 1. is there a path a − x of length i/2; and
This implies 2. is there a path x − b of length i/2?
NSPACE(s(n)) ⊆ SPACE((s(n)2 )).
if such an x is found, then accept, else reject.
In particular PSPACE = NPSPACE. The maximum depth of recursion is log n, and the number of bits
of information kept at each stage is 3 log n.
35 36
This leaves us with the following: If we interchange accepting and rejecting states in a deterministic
machine that accepts the language L, we get one that accepts L.
L ⊆ NL ⊆ P ⊆ NP ⊆ PSPACE ⊆ EXP If a language L ∈ P, then also L ∈ P.
Hierarchy Theorems proved by diagonalization can show that: Complexity classes defined in terms of nondeterministic machine
models are not necessarily closed under complementation of
languages.
L 6= PSPACE NL 6= NPSPACE P 6= EXP
Define,
For other inclusions above, it remains an open question whether co-NP – the languages whose complements are in NP.
they are strict.
co-NL – the languages whose complements are in NL.
37 38
Relationships Reductions
P ⊆ NP ∩ co-NP and any of the situations is consistent with our Given two languages L1 ⊆ Σ⋆1 , and L2 ⊆ Σ⋆2 ,
present state of knowledge:
• P = NP = co-NP a reduction of L1 to L2 is a computable function
• P = NP ∩ co-NP 6= NP 6= co-NP
f : Σ⋆1 → Σ⋆2
• P 6= NP ∩ co-NP = NP = co-NP
such that for every string x ∈ Σ⋆1 ,
• P 6= NP ∩ co-NP 6= NP 6= co-NP
39 40
If f is computable by a polynomial time algorithm, we say that L1 If L1 ≤ L2 we understand that L1 is no more difficult to solve than
is polynomial time reducible to L2 . L2 .
If f is also computable in SPACE(log n), we write We can get an algorithm to decide L1 by first computing f , and
then using the C-algorithm for L2 .
L1 ≤L L2 Provided that C is closed under such reductions.
41 42
The usefulness of reductions is that they allow us to establish the Examples of complete problems for various complexity classes.
relative complexity of problems, even when we cannot prove
NL
absolute lower bounds.
Reachability
P
Cook (1972) first showed that there are problems in NP that are
Game, Circuit Value Problem
maximally difficult.
NP Satisfiability of Boolean Formulas, Graph 3-Colourability,
For any complexity class C, a language L is said to be C-hard if for Hamiltonian Cycle
every language A ∈ C, A ≤ L. co-NP
Validity of Boolean Formulas, Non 3-colourability
A language L is C-complete if it is in C and it is C-hard.
PSPACE
Geography, The game of HEX
43 44
47 48
SAT VAL
Input: A Boolean formula φ Input: A Boolean formula φ
Decide: if there is an assignment of truth values to the Decide: if every assignment of truth values to the variables
variables of φ that makes φ true. of φ makes φ true.
Hamiltonicity Non-3-colourability
Input: A graph G = (V, E) Input: A graph G = (V, E)
Decide: if there is a cycle in G that visits every vertex Decide: if there is no function χ : V → {1, 2, 3} such that
exactly once. the two endpoints of every edge are differently coloured.
49 50
51 52
In general a signature (or vocabulary) σ is a finite sequence of A structure A over the signature σ is a tuple:
relation, function and constant symbols:
A = (A, R1A , . . . , Rm
A
, f1A , . . . , fnA , cA A
1 , . . . , cn ),
σ = (R1 , . . . , Rm , f1 , . . . , fn , c1 , . . . , cp )
where,
where, associated with each relation and function symbol is an
• A is a non-empty set, the universe of the strucure A,
arity.
• each RiA is a relation over A of the appropriate arity.
• each fiA is a function over A of the appropriate arity.
• each cA
i is an element of A.
53 54
Formulas are defined by induction: Any such map Q which associates to every structure A a (n-ary)
relation on A, and is isomorphism invariant, is called a (n-ary)
• atomic formulas – R(t1 , . . . , ta ), t1 = t2
query.
• Boolean operations – φ ∧ ψ, φ ∨ ψ, ¬φ
Q is isomorphism invariant if, whenever f : A → B is an
• first-order quantifiers – ∃xφ, ∀xφ isomorphism between A and B, it is also an isomorphism between
(A, Q(A)) and (B, Q(B)).
55 56
Graphs Complexity
For example, take the signature (E), where E is a binary relation For a first-order sentence φ, we ask what is the computational
symbol. complexity of the problem:
Finite structures (V, E) of this signature are directed graphs. Input: a structure A
Decide: if A |= φ
Moreover, the class of such finite structures satisfying the sentence
In other words, how complex can the collection of finite models of φ
∀x¬Exx ∧ ∀x∀y(Exy → Eyx)
be?
can be identified with the class of (loop-free, undirected) graphs.
In order to talk of the complexity of a class of finite structures, we
need to fix some way of representing finite structures as strings.
57 58
[A]< = |1 ·{z
· · 1} #[R1 ]< # · · · #[Rm ]< #[f1 ]< # · · · #[fl ]< This runs in time O(lnm ) and O(m log n) space, where m is the
n nesting depth of quantifiers in φ.
59 60
The following problem: We define quantified Boolean formulas inductively as follows, from
FO satisfaction a set X of propositional variables.
63 64
Given a quantified Boolean formula φ and an assignment of truth Note that a Boolean formula φ without quantifiers and with
values to its free variables, we can ask whether φ evaluates to true variables X1 , . . . , Xn is satisfiable if, and only if, the formula
or false.
∃X1 · · · ∃Xn φ is true.
In particular, if φ has no free variables, then it is equivalent to
either true or false. Similarly, φ is valid if, and only if, the formula
To see that QBF is in PSPACE, consider the algorithm that To prove that QBF is PSPACE-complete, we want to show:
maintains a 1-bit register X for each Boolean variable appearing in
Given a machine M with a polynomial space bound and an
the input formula φ and evaluates φ in the natural fashion.
input x, we can define a quantified Boolean formula φMx
which evaluates to true if, and only if, M accepts x.
The crucial cases are:
Moreover, φMx can be computed from x in polynomial time
• If φ is ∃X ψ then return T if either (X ← T ; evaluate ψ) or (or even logarithmic space).
(X ← F ; evaluate ψ) returns T.
• If φ is ∀X ψ then return T if both (X ← T ; evaluate ψ) and The number of distinct configurations of M on input x is bounded
k
(X ← F ; evaluate ψ) return T. by 2n for some k (n = |x|).
Each configuration can be represented by nk bits.
67 68
Constructing φM
x
Reducing QBF to FO satisfaction
We use tuples A, B of nk Boolean variables each to encode We have seen that FO satisfaction is in PSPACE.
configurations of M . To show that it is PSPACE-complete, it suffices to show that
Inductively, we define a formula ψi (A, B) which is true if the QBF ≤L FO sat.
configuration coded by B is reachable from that coded by A in at
most 2i steps. The reduction maps a quantified Boolean formula φ to a pair
(A, φ∗ ) where A is a structure with two elements: 0 and 1
ψ0 (A, B) ≡ “A = B′′ ∨ “A →M B′′ interpreting two constants f and t respectively.
ψi+1 (A, B) ≡ ∃Z∀X∀Y [(X = A ∧ Y = Z) ∨ (X = Z ∧ Y = B)
⇒ ψi (X, Y)] φ∗ is obtained from φ by a simple inductive definition.
φ ≡ ψnk (A, B) ∧ “A = start′′ ∧ “B = accept′′
69 70
For any fixed sentence φ of first-order logic, the class of structures We extend first-order logic by a set of relational variables.
Mod(φ) is in L.
For each m ∈ N there is an infinite collection of variables
V m = {V1m , V2m , . . .} of arity m.
There are computationally easy properties that are not definable in
first-order logic. Second-order logic extends first-order logic by allowing second-order
quantifiers
• There is no sentence φ of first-order logic such that A |= φ if,
∃X φ for X ∈ V m
and only if, |A| is even.
A structure A satisfies ∃X φ if there is an m-ary relation R on the
• There is no formula φ(E, x, y) that defines the transitive
universe of A such that (A, X → R) satisfies φ.
closure of a binary relation E.
71 72
Examples Examples
75 76
One direction is easy: Given A and ∃P1 . . . ∃Pm φ. of length at most nk on input [A]<
79 80
The formula φM,k is built up as the conjunction of a number of If x = x1 , . . . , xk and y = y1 , . . . , yk are k-tuples of variables, we
W
formulas. The first of these simply says that < is a linear order use x = y as shorthand for the formula i<k xi = yi and x < y as
shorthand for the formula
∀x(¬x < x)∧ _ _
∀x∀y(x < y → ¬y < x)∧ ( xj = yj ) ∧ xi < yi
i<k j<i
∀x∀y(x < y ∨ y < x ∨ x = y)
∀x∀y∀z(x < y ∧ y < z → x < z) We also write y = x + 1 for the following formula:
x < y ∧ ∀z x < z → (y = z ∨ y < z)
We can use a linear order on the elements of A to define a
lexicographic order on k-tuples.
81 82
Let M = (K, Σ, s, δ). Intuitively, these relations are intended to capture the following:
The tuple X of second-order variables appearing in φM,k contains • Sq (x) – the state of the machine at time x is q.
the following:
• Tσ (x, y) – at time x, the symbol at position y of the tape is σ.
Sq a k-ary relation symbol for each q ∈ K • H(x, y) – at time x, the tape head is pointing at tape cell y.
Tσ a 2k-ary relation symbol for each σ ∈ Σ
H a 2k-ary relation symbol
We now have to see how to write the formula φM,k , so that it
enforces these meanings.
83 84
Initial state is s and the head is initially at the beginning of the Initial Tape Contents
tape.
∀x (∀y x ≤ y) → Ss (x) ∧ H(x, x) The initial contents of the tape are [A]< .
The head is never in two places at once
∀x x ≤ n → T1 (1, x)∧
∀x∀y H(x, y) → (∀z(y 6= z) → (¬H(x, z))) x ≤ na → (T1 (1, x + n + 1) ↔ R1 (x|a ))
The machine is never in two states at once ...
^ ^
∀x (Sq (x) → (¬Sq′ (x))) where,
^
q q ′ 6=q x < na : xi = 0
i≤(k−a)
Each tape cell contains only one symbol
^ ^
∀x∀y (Tσ (x, y) → (¬Tσ′ (x, y)))
σ σ ′ 6=σ
85 86
∃x Sacc (x)
87 88
NP co-NP
Recall that a languge L is in NP if, and only if, USO—universal second-order logic consists of those formulas of
second-order logic of the form:
L = {x | ∃yR(x, y)}
∀X1 · · · ∀Xk φ
where R is polynomial-time decidable and polynomially-balanced.
where φ is a first-order formula.
Fagin’s theorem tells us that polynomial-time decidability can, in
some sense, be replaced by first-order definability. A corollary of Fagin’s theorem is that a class C of finite structures
is definable by a sentence of existential second-order logic if, and
only if, it is decidable by a nondeterminisitic machine running in
polynomial time.
USO = co-NP
89 90
We can define further classes by allowing other second-order We have, for each n:
quantifier prefixes.
Σ1n ∪ Π1n ⊆ Σ1n+1 ∩ Π1n+1
Σ11 = ESO
Π11 = USO
The classes together form the polynomial hierarchy or PH.
Σ1n+1 is the collection of properties definable by a sentence of the
form: ∃X1 · · · ∃Xk φ where φ is a Π1n formula.
NP ⊆ PH ⊆ PSPACE
Π1n+1 is the collection of properties definable by a sentence of the
P = NP if, and only if, P = PH
form: ∀X1 · · · ∀Xk φ where φ is a Σ1n formula.
Note: every formula of second-order logic is Σ1n and Π1n for some n.
91 92
We noted that there are computationally easy properties that are The quantifier rank of a formula φ, written qr(φ) is defined
not definable in first-order logic. inductively as follows:
• There is no sentence φ of first-order logic such that A |= φ if, 1. if φ is atomic then qr(φ) = 0,
and only if, |A| is even.
2. if φ = ¬ψ then qr(φ) = qr(ψ),
• There is no sentence φ that defines exactly the connected
3. if φ = ψ1 ∨ ψ2 or φ = ψ1 ∧ ψ2 then
graphs.
qr(φ) = max(qr(ψ1 ), qr(ψ2 )).
How do we prove these facts?
4. if φ = ∃xψ or φ = ∀xψ then qr(φ) = qr(ψ) + 1
Our next aim is to develop the tools that enable such proofs. More informally, qr(φ) is the maximum depth of nesting of
quantifiers inside φ.
95 96
Note: For the rest of this lecture, we assume that our signature If qr(φ) = 0 then φ is a Boolean combination of atomic formulas. If
consists only of relation and constant symbols. That is, there are it is has m variables, it is equivalent to a formula using the
no function symbols of non-zero arity. variables x1 , . . . , xm . There are finitely many formulas, up to logical
equivalence.
With this proviso, it is easily proved that in a finite vocabulary, for
Suppose qr(φ) = q + 1 and the free variables of φ are among
each q, there are (up to logical equivalence) only finitely many
x1 , . . . , xm . Then φ is a Boolean combination of formulas of the
sentences φ with qr(φ) ≤ q.
form
∃xm+1 ψ
To be precise, we prove by induction on q that for all m, there are
where ψ is a formula with qr(ψ) = q and free variables
only finitely many formulas of quantifier rank q with at most m
x1 , . . . , xm , xm+1 .
free variables.
By induction hypothesis, there are only finitely many such
formulas, and therefore finitely many Boolean combinations.
97 98
For two structures A and B, we say A ≡q B if for any sentence φ A map f is a partial isomorphism between structures A and B, if
with qr(φ) ≤ q,
• the domain of f = {a1 , . . . , al } ⊆ A, including the
A |= φ if, and only if, B |= φ. interpretation of all constants;
• the range of f = {b1 , . . . , bl } ⊆ B, including the interpretation
of all constants; and
More generally, if a and b are m-tuples of elements from A and B
respectively, then we write (A, a) ≡q (B, b) if for any formula φ • f is an isomorphism between its domain and range.
with m free variables qr(φ) ≤ q, Note that if f is a partial isomorphism taking a tuple a to a tuple
A |= φ[a] if, and only if, B |= φ[b]. b, then for any quantifier-free formula θ
99 100
The q-round Ehrenfeucht game on structures A and B proceeds as Write A ∼q B to denote the fact that Duplicator has a winning
follows: strategy in the q-round Ehrenfeucht game on A and B.
• There are two players called Spoiler and Duplicator. The relation ∼q is, in fact, an equivalence relation.
Proof Proof
To prove A ∼q B ⇒ A ≡q B, it suffices to show that if there is a We prove by induction on q the stronger statement that if φ is a
sentence φ with qr(φ) ≤ q such that formula with qr(φ) ≤ q and a = (a1 , . . . , am ) and b = (b1 , . . . , bm )
are tuples of elements from A and B respectively such that
A |= φ and B 6|= φ
A |= φ[a] and B 6|= φ[b]
then Spoiler has a winning strategy in the q-round Ehrenfeucht
game on A and B. then Spoiler has a winning strategy in the q-round Ehrenfeucht
game which starts from a position in which a1 , . . . , am and
Assume that φ is in negation normal form, i.e. all negations are in front b1 , . . . , bm have already been selected.
of atomic formulas.
103 104
When q = 0, φ is a quantifier-free formula. Thus, if To show that a class of structures S is not definable in FO, we find,
for every q, a pair of structures Aq and Bq such that
A |= φ[a] and B 6|= φ[b]
• Aq ∈ S, Bq ∈ S; and
there is an atomic formula θ that distinguishes the two tuples and
therefore the map taking a to b is not a partial isomorphism. • Duplicator wins a q-round game on Aq and Bq .
Let A be a structure in the empty vocabulary with q elements and B Let Ln denote the structure in one binary relation ≤ which is a
be a structure with q + 1 elements. linear order of n elements. Then L6 6≡3 L7 but L7 ≡3 L8 .
Then, it is easy to see that A ∼q B.
In general, for m, n ≥ 2p − 1,
It follows that there is no first-order sentence that defines the Lm ≡p Ln
structures with an even number of elements.
Duplicator’s strategy is to maintain the following condition after r
rounds of the game:
If S ⊆ N is a set such that
for 1 ≤ i < j ≤ r,
{A | |A| ∈ S}
• either length(ai , aj ) = length(bi , bj )
is definable by a first-order sentence then S is finite or co-finite.
• or length(ai , aj ), length(bi , bj ) ≥ 2p−r − 1
Evenness is not first order definable, even on linear orders.
107 108
Connectivity Proof
Consider the signature (E, <). Suppose there was such a formula γ.
Consider structures G = (V, E, <) in which E is a graph relation Let γ ′ be the formula obtained by replacing every occurrence of
and < is a linear order. E(x, y) in γ by the following formula
111 112
Proof Reduction
It follows from the above that there is no first order formula that
can express the transitive closure query on graphs.
Any such formula would also work on ordered graphs.
On a structure A, define the binary relation: We say A and B are Hanf equivalent with radius r (A ≃r B) if, for
every a ∈ A the two sets
E(a1 , a2 ) if, and only if, there is some relation R and some
tuple a containing both a1 and a2 with R(a). {a′ ∈ a | NbdA ∼ A ′
{b ∈ B | NbdA ∼ B
r (a) = Nbdr (a )} and r (a) = Nbdr (b)}
The graph GA = (A, E) is called the Gaifman graph of A. have the same cardinality
and, similarly for every b ∈ B.
dist(a, b) — the distance between a and b in the graph (A, E).
Theorem (Hanf )
NbdA
r (a) — the substructure of A given by the set: For every vocabulary σ and every p there is r ≤ 3p such that for
any σ-structures A and B: if A ≃r B then A ≡p B.
{b | dist(a, b) ≤ r}
In other words, if r ≥ 3p , the equivalence relation ≃r is a
refinement of ≡p .
115 116
Duplicator’s strategy is to maintain the following condition: The Hanf locality theorem immediately yields, as special cases, the
After k moves, if a1 , . . . , ak and b1 , . . . , bk have been selected, then proofs of undefinability of:
[
∼
[ • connectivity;
NbdA 3p−k (ai ) = NbdB3p−k (bi )
i i • 2-colourability
• acyclicity
If Spoiler plays on a within distance 2 · 3p−k−1 of a previously
chosen point, play according to the isomorphism, otherwise, find b • planarity
such that
Nbd3p−k−1 (a) ∼
= Nbd3p−k−1 (b) A simple illustration can suffice.
p−k−1
and b is not within distance 2 · 3 of a previously chosen point.
Such a b is guaranteed by ≃r .
117 118
Connectivity Acyclicity
To illustrate the undefinability of connectivity and 2-colourability, A figure illustrating that acyclicity is not first-order definable.
consider on the one hand the graph consisting of a single cycle of
length 4r + 6 and, on the other hand, a graph consisting of two
disjoint cycles of length 2r + 3.
119 120
A figure illustrating that planarity is not first-order definable. MSO consists of those second order formulas in which all relational
variables are unary.
The method of games and locality can also be used to show Recall that connectivity of graphs can be defined by a Mon.Π11
inexpressibility results in MSO. sentence.
123 124
The m-round monadic Ehrenfeucht game on structures A and B • If, after m rounds, the map
proceeds as follows:
ai 7→ bi
• At the ith round, Spoiler chooses one of the structures (say B)
and plays either a point move or a set move. is a partial isomorphism between
In a point move, he chooses one of the elements of the (A, R1 , . . . , Rq ) and (B, S1 , . . . , Sq )
chosen structure (say bi ) – Duplicator must respond with
then Duplicator has won the game, otherwise Spoiler has won.
an element of the other structure (say ai ).
In a set move, he chooses a subset of the universe of the
chosen structure (say Si ) – Duplicator must respond
with a subset of the other structure (say Ri ).
125 126
If we define the quantifier rank of an MSO formula by adding the The m, p-move existential game on (A,B):
following inductive rule to those for a formula of FO:
• First Spoiler makes m set moves on A, and Duplicator replies
if φ = ∃Sψ or φ = ∀Sψ then qr(φ) = qr(ψ) + 1 on B.
then, we have • This is followed by an Ehrenfeucht game with p point moves.
Duplicator has a winning strategy in the m-round monadic
Ehrenfeucht game on structures A and B if, and only if, for If Duplicator has a winning strategy, then for every Mon.Σ11
every sentence φ of MSO with qr(φ) ≤ m sentence:
φ ≡ ∃R1 . . . ∃Rm ψ
A |= φ if, and only if, B |= φ
with qr(ψ) = p,
if A |= φ then B |= φ
127 128
Variation Application
To show that a Boolean query Q is not Mon.Σ11 definable, find for Write Cn for the graph that is a simple cycle of length n.
each m and p
• A ∈ Q; and For n sufficiently large, and any colouring of Cn , we can find an
n′ < n and a colouring of
• B 6∈ P ; such that
Cn′ ⊕ Cn−n′ the disjoint union of two cycles—one of length
• Duplicator wins the m, p move game on (A, B).
n′ , the other of length n − n′
Or,
So that the graphs Cn and Cn′ ⊕ Cn−n′ are ≃r equivalent.
• Duplicator chooses A.
m
131 132
We have seen that the expressive power of first-order logic, in terms LFP is a logic that formalises inductive definitions.
of computational complexity is weak.
Unlike in second-order logic, we cannot quantify over
Second-order logic allows us to express all properties in the arbitrary relations, but we can build new relations
polynomial hierarchy. inductively.
Are there interesting logics intermediate between these two? Inductive definitions are pervasive in mathematics and computer
science.
We have seen one—monadic second-order logic.
The syntax and semantics of various formal languages are typically
We now examine another—LFP—the logic of least fixed points.
defined inductively.
viz. the definitions of the syntax and semantics of
first-order logic seen earlier.
133 134
The transitive closure of a binary relation E is the smallest relation In order to introduce LFP, we briefly look at the theory of
T satisfying: monotone operators, in our restricted context.
• E ⊆ T ; and
We write Pow(A) for the powerset of A.
• if (x, y) ∈ T and (y, z) ∈ E then (x, z) ∈ T .
An operator in A is a function
135 136
Least and Greatest Fixed Points Least and Greatest Fixed Points
A fixed point of F is any set S ⊆ A such that F (S) = S. For any monotone operator F , define the collection of its pre-fixed
points as:
S is the least fixed point of F , if for all fixed points T of F , S ⊆ T . Pre = {S ⊆ A | F (S) ⊆ S}.
Note: A ∈ Pre.
S is the greatest fixed point of F , if for all fixed points T of F ,
T ⊆ S. Taking
\
L= Pre,
we can show that L is a fixed point of F .
137 138
139 140
Iteration Iteration
F (F i ) ⊆ F (F i+1 )
For each i, F i ⊆ F i+1 (proved by induction).
and so F i+1 ⊆ F i+2 .
141 142
If A has n elements, then Suppose φ contains a relation symbol R (of arity k) not interpreted
in the structure A and let x be a tuple of k free variables of φ.
F n = F n+1 = F m for all m>n
For any relation P ⊆ Ak , φ defines a new relation:
Thus, F n is a fixed point of F .
FP = {a | (A, P ) |= φ[a]}.
Let P be any fixed point of F . We can show induction on i, that
Fi ⊆ P.
F0 = ∅ ⊆ P The operator Fφ : Pow(Ak ) → Pow(Ak ) defined by φ is given by the
map
If F i ⊆ P then
P 7→ FP .
F i+1 = F (F i ) ⊆ F (P ) = P.
Or, Fφ,b if we fix parameters b.
143 144