Computability & Complexity Theory
Computability & Complexity Theory
Complexity Theory
Charles E. Hughes
COT 6410 – Spring 2014
Notes
Who, What, Where and When
• Instructor: Charles Hughes;
Harris Engineering 247C; 823-2762
(phone is not a good way to get me);
[email protected]
(e-mail is a good way to get me)
Subject: COT6410
• Web Page: http://www.cs.ucf.edu/courses/cot6410/spr20124
• Meetings: TR 1:30PM-2:45PM, CB1-120;
28 periods, each 75 minutes long.
Final Exam (Tuesday, April 29 from 1:00PM to 3:50PM) is
separate from class meetings
• Office Hours: TR 3:00PM-4:15PM
• AND, you know (1) is Yes and (2) is No. (Maybe you have a secret
program that has analyzed the two instance.)
• We can assume the output of the program was an actual coloring of G. Just
give that to a doubter who can easily check that no adjacent vertices are
colored the same, and that no more than k colors were used.
• What could the program have given that allows us to quickly "verify" (2) is a
No instance?
• No One Knows!!
• No one has yet proven this claim, but most researchers believe it to
be true.
Exponential – vs – polynomial
(area of Computational Complexity)
We Can’t Do It All
Classic Unsolvable Problem
Given an arbitrary program P, in some language L, and
an input x to P, will P eventually stop when run with input
x?
The above problem is called the “Halting Problem.” It is
clearly an important and practical one – wouldn't it be
nice to not be embarrassed by having your program run
“forever” when you try to do a demo?
Unfortunately, there’s a fly in the ointment as one can
prove that no algorithm can be written in L that solves
the halting problem for L.
with inverses
<z>1 = log2(z+1)
<z>2 = ((( z + 1 ) // 2 <z>1 ) – 1 ) // 2
Semi_Decide_Halting() {
Read P, x;
P(x);
Print “yes”;
}
Univ(x,y) = ϕx(y)
F(x) = Fx
where F0, F1, F2, … is a list of indexes of all and only the
algorithms
• It sometimes helps
– Push Down Automata
• It sometimes hinders
– Factor Replacement Systems, Petri Nets
Turing Machines
Register Machines
Factor Replacement Systems
Recursive Functions
Turing Machines
1st Model
A Linear Memory Machine
Basic Description
• We will use a simplified form that is a variant of Post’s and Turing’s
models.
• Here, each machine is represented by a finite set of states of states
Q, the simple alphabet {0,1}, where 0 is the blank symbol, and each
state transition is defined by a 4-tuple of form
qaXs
where q a is the discriminant based on current state q, scanned
symbol a; X can be one of {R, L, 0, 1}, signifying move right, move
left, print 0, or print 1; and s is the new state.
• Limiting the alphabet to {0,1} is not really a limitation. We can
represent a k-letter alphabet by encoding the j-th letter via j 1’s in
succession. A 0 ends each letter, and two 0’s ends a word.
• We rarely write quads. Rather, we typically will build machines from
simple forms.
2nd Model
Feels Like Assembly Language
Register Machine Concepts
• A register machine consists of a finite length program,
each of whose instructions is chosen from a small
repertoire of simple commands.
• The instructions are labeled from 1 to m, where there are
m instructions. Termination occurs as a result of an
attempt to execute the m+1-st instruction.
• The storage medium of a register machine is a finite set
of registers, each capable of storing an arbitrary natural
number.
• Any given register machine has a finite, predetermined
number of registers, independent of its input.
3⋅5x → x
3x → 2x
5x → x
… …
Marker
Place
Transition
Arc
4/10/14 © UCF EECS 98
Vector Addition
• Start with a finite set of vectors in integer n-space.
• Start with a single point with non-negative integral
coefficients.
• Can apply a vector only if the resultant point has non-
negative coefficients.
• Choose randomly among acceptable vectors.
• This generates the set of reachable points.
• Vector addition systems are equivalent to Petri Nets.
• If order vectors, these are equivalent to FRS.
An Incomplete Model
Basis of PRFs
• The primitive recursive functions are defined by
starting with some base set of functions and
then expanding this set via rules that create new
primitive recursive functions from old ones.
• The base functions are:
Ca(x1,…,xn) = a : constant functions
n(x ,…,x ) = x
Ii 1 n i : identity functions
: aka projection
S(x) = x+1 : an increment function
x!:
0! = 1
(x+1)! = (x+1) * x!
x && y:
x&&y = signum(x*y)
x || y:
x||y = ~((x==0) && (y==0))
Can use induction to prove this is true for all k>0, where
g1(x) if P1(x)
g2(x) if P2(x) && ~P1(x)
f(x) = …
gk(x) if Pk(x) && ~(P1(x) || … || ~Pk-1(x))
h(x) otherwise
x | y: x is a divisor of y
x|y = ((y//x) * x) == y
isPrime(x):
isPrime(x) = firstFactor(x) == x && (x>1)
• with inverses
<z>1 = exp(z+1,0)
<z>2 = ((( z + 1 ) // 2 <z>1 ) – 1 ) // 2
• These are very useful and can be extended to
encode n-tuples
<x,y,z> = <x, <y,z> > (note: stack analogy)
The above shows that <x,y>+1 is 1-1 onto Z+, but then <x,y> is 1-1
onto ℵ, as was desired.
Proof is by construction
4th Model
A Simple Extension to Primitive
Recursive
µ Recursive Concepts
• All primitive recursive functions are algorithms
since the only iterator is bounded. That’s a clear
limitation.
• There are algorithms like Ackerman’s function
that cannot be represented by the class of
primitive recursive functions.
• The class of recursive functions adds one more
iterator, the minimization operator (µ), read “the
least value such that.”
Equivalency of computation by
Turing machines, register machines,
factor replacement systems,
recursive functions
Our Plan of Attack
• We will now show
TURING ≤ REGISTER ≤ FACTOR ≤
RECURSIVE ≤ TURING
where by A ≤ B, we mean that every
instance of A can be replaced by an
equivalent instance of B.
• The transitive closure will then get us the
desired result.
1 2
2
j
j
where the pi's are distinct primes and the ki's are non-zero values,
except that the number 1 would be represented by 20.
• Let R be an arbitrary n-register machine, having m instructions.
Since our Turing Machine simulator can produce the same value for
any arbitrary PRF, F, we show that Turing Machines are closed under
induction (primitive recursion).
F(x1,…,xn) = µy (G(x1,…,xn, y) == 1)
Properties of re Sets
Definition of re
• Some texts define re in the same way as I have defined
semi-decidable.
S ⊆ ℵ is semi-decidable iff there exists a partially
computable function g where
S = { x ∈ ℵ | g(x)↓ }
• I prefer the definition of re that says
S ⊆ ℵ is re iff S = ∅ or there exists a totally computable
function f where
S = { y | ∃x f(x) == y }
• We will prove these equivalent. Actually, f can be a
primitive recursive function.
µy [y == y+1] if S == Ø
ψS(x) =
signum((µy[FS(y)==x])+1), otherwise
This achieves our result as the domain of ψS is
the range of FS, or empty if S == Ø.
F(x) = Fx
TOT = { f ∈ ℵ | Wf =ℵ }
• Theorem: TOT is not re.
EMPTY = Le = { f | ∀ x ϕf (x) ↑ }
f ∈ Le ⇔ ∀ <x,t> ~STP( f, x, t)
⇔ ~∃ <x,t> STP( f, x, t)
⇔ f ∉ Lne
• Trivial properties are not very discriminating in the way they divide
up the re languages (all or nothing).
x
ϕ (y)
y x
∀z f (z)=ϕ (z) If ϕ (y)↓
x,y,r r x
rng(f )=rng(ϕ ) If ϕ (y)↓
x,y,r r x
dom(f )=dom(ϕ ) If ϕ (y)↓
ϕ (z) x,y,r r x
z r
dom(f )=φ If ϕ (y)↑
x,y,r x
rng(f )=φ If ϕ (y)↑
x,y,r x
Black is for standard Rice’s Theorem; ∃z f (z)≠ϕ (z) If ϕ (y)↑
x,y,r r x
Black and Red are needed for Strong Version
Blue is just another version based on range
Undecidability Continued
PCP and Traces
Post Correspondence Problem
• Many problems related to grammars can be shown to be
no more complex than the Post Correspondence
Problem (PCP).
• Each instance of PCP is denoted: Given n>0, Σ a finite
alphabet, and two n-tuples of words
( x1, … , xn ), ( y1, … , yn ) over Σ,
does there exist a sequence i1, … , ik , k>0, 1 ≤ ij ≤ n,
such that
xi1 … xik = yi1 … yik ?
• Example of PCP:
n = 3, Σ = { a , b }, ( a b a , b b , a ), ( b a b , b , b a a ).
Solution 2 , 3, 1 , 2
bb a aba bb = b baa bab b
• Insertion
– A w B = { xyz | y ∈ A, xz ∈ B, x, y, z ∈ Σ*}
– Clearly, since x can be λ, A • B ⊆ A w B
• Shuffle closure
– A ¯* B = ∪ k ≥ 0 (A ¯[ k ] B)
Axiomatizable Fragments
Propositional Calculus
• Mathematical of unquantified logical
expressions
• Essentially Boolean algebra
• Goal is to reason about propositions
• Often interested in determining
– Is a well-formed formula (wff) a tautology?
– Is a wff refutable (unsatisfiable)?
– Is a wff satisfiable? (classic NP-complete)
4/10/14 © UCF EECS 320
Tautology and Satisfiability
• The classic approaches are:
– Truth Table
– Axiomatic System (axioms and inferences)
• Truth Table
– Clearly exponential in number of variables
• Axiomatic Systems Rules of Inference
– Substitution and Modus Ponens
– Resolution / Unification
4/10/14 © UCF EECS 321
Proving Consequences
• Start with a set of axioms (all tautologies)
• Using substitution and MP
(P, P ⊃Q ⇒ Q)
derive consequences of axioms (also
tautologies, but just a fragment of all)
• Can create complete sets of axioms
• Need 3 variables for associativity, e.g.,
(p1 ∨ p2) ∨ p3 ⊃ p1 ∨ (p2 ∨ p3)
If this value is
0 A is faster than B
constant A and B are "equally slow/fast"
infinity A is slower than B.
• As an Optimization Problem:
• Instances: A graph G.
• Question: What is the smallest k for which G possesses a vertex
cover?
an optimization problem.
Exponential – vs – polynomial
(area of Computational Complexity)
This means that rather than the next action being totally
specified (deterministic) by the current state and input
character, we now can have many next actions -
simultaneously. That is, a NDTM can be in many states at
once. (That raises some interesting problems with writing
on the tape, just where the tape head is, etc., but those
little things can be explained away).
NDTM's
We also require that there be only one halt
state - the 'accept' state. That also raises an
interesting question - what if we give it an
instance that is not 'acceptable'? The answer -
it blows up (or goes into an infinite loop).
An 'Oracle Machine.'
NDTM's
This is not totally unreasonable. We can look
at a non deterministic decision as a
deterministic algorithm in which, when an
"option" is to be tested, it is very lucky, or
clever, to make the correct choice the first
time.
NP 'Nondeterministic' Polynomial
P 'Deterministic' Polynomial,
The 'easiest' problems in NP
This actually defines our first Class, NP, the set of decision
problems whose Yes instances can be solved by a
Nondeterministic Turing Machine in polynomial time.
P is a subset of NP.
Class – P
This has been the case for several problems that for
many years were not known to be in P, but both the
problem and its complement were known to be in NP.
End For
Compute AnswerA
End proc
Reductions
"A ➤ B"
Theorem.
If A ➤ B and B ➤ C then A ➤ C.
Definition.
If A ➤ B and B ➤ A, then A and B are
polynomially equivalent.
Reductions
A ➤ B means:
Polynomial Transformation
(Refer to the definition of Turing Reductions)
Cooks Theorem:
1) SAT is in NP
2) For every problem A in NP,
A ➤P SAT
The best set of items from {I0, I1, I2} is {I0, I1, I2}
BUT the best set of items from {I0, I1, I2, I3} is {I0,
I2, I3}.
◦ In this example, note that this optimal solution, {I0, I2, I3},
does NOT build upon the previous optimal solution, {I0, I1,
I2}.
(Instead it builds upon the solution, {I0, I2}, which is really the
optimal subset of {I0, I1, I2} with weight 12 or less.)
Knapsack 0-1 problem
So now we must re-work the way we build upon previous
sub-problems…
◦ Let B[k, w] represent the maximum total value of a subset Sk
with weight w.
◦ Our goal is to find B[n, W], where n is the total number of items
and W is the maximal weight the knapsack can carry.
Second case: wk ≤ w
◦ Then the item k can be in the solution, and we
choose the case with greater value.
Knapsack 0-1 Algorithm
for w = 0 to W { // Initialize 1st row to 0’s
B[0,w] = 0
}
for i = 1 to n { // Initialize 1st column to 0’s
B[i,0] = 0
}
for i = 1 to n {
for w = 0 to W {
if wi <= w { //item i can be in the solution
if vi + B[i-1,w-wi] > B[i-1,w]
B[i,w] = vi + B[i-1,w- wi]
else
B[i,w] = B[i-1,w]
}
else B[i,w] = B[i-1,w] // wi > w
}
}
Knapsack 0-1 Problem
Let’s run our algorithm on the following
data:
◦ n = 4 (# of elements)
◦ W = 5 (max weight)
◦ Elements (weight, value):
(2,3), (3,4), (4,5), (5,6)
Knapsack 0-1 Example
i/w 0 1 2 3 4 5
0 0 0 0 0 0 0
1 0
2 0
3 0
4 0
for i = 1 to n
B[i,0] = 0
Items:
We’re DONE!!
The max possible value that can be carried in this knapsack is $7
Knapsack 0-1 Problem – Run
for w = 0 to W Time
B[0,w] = 0 O(W)
for i = 1 to n
B[i,0] = 0 O(n)
for i = 1 to n
for w = 0 to W
Repeat n times
< the rest of the code > O(W)
A ➤P B
Polynomial Transformations
Following Garey and Johnson, we recognize three
forms of polynomial transformations.
(a) restriction,
(b) local replacement, and
(c) component design.
Polynomial Transformations
Restriction allows nothing much more complex
than renaming the objects in IA so that they are,
in a straightforward manner, objects in IB.
• Theorem. The given instance of 3-SAT is satisfiable if and only if the constructed
instance of VC has a vertex cover with at most k vertices.
X ~X
a ~c
a + b + ~c
T F
K=3
4/10/14 © UCF EECS 501
Register allocation
• Liveness: A variable is live if its current assignment may be used at some
future point in a program’s flow
• Optimizers often try to keep live variables in registers
• If two variables are simultaneously live, they need to be kept in separate
registers
• Consider the K-coloring problem (can the nodes of a graph be colored with
at most K colors under the constraint that adjacent nodes must have
different colors?
• Register Allocation reduces to K-coloring by mapping each variable to a
node and inserting an edge between variables that are simultaneously live
• K-coloring reduces to Register Allocation by interpreting nodes as variables
and edges as indicating concurrent liveness
• This is a simple because it’s an isomorphism
Theorem: Level Strategy is optimal for unit execution, m=2, dag precedence.
Now show what would happen if the times were sorted non-decreasing.
Now show what would happen if the times were sorted non-increasing.
Co–GC
Given: A graph G and an integer k.
Question: Do all proper colorings of G
require more than k colors?
Co–NP
Notice that Co–GC is a problem that does
not appear to be in the set NP. That is, we
know of no way to check in polynomial
time the answer to a "Yes" instance of Co–
GC.
∨ ∨
∨
x ~x y ~y z ~z w ~w
• As Triangle Mesh
• Generated by triangulating the
geometry
Triangle List vs Triangle Strip