CPSC 421 [index]

  1. (1)
    LoremLorem
    ipsumipsum
    dolordolor
    sitsit
    amet,amet,
    consecteturconsectetur
    adipiscingadipiscing
    elit,elit,
    sedsed
    dodo
    eiusmodeiusmod
    temportempor
    incididuntincididunt
    utut
    laborelabore
    etet
    doloredolore
    magnammagnam
    aliquamaliquam
    quaerat.quaerat.

Introduction to the Theory of Computing [cpsc421/intro]

Overview of the course [cpsc421/overview]

Broad categories of lectures:

Why study models of computation? [cpsc421/motivation]

  1. This helps us understand what is/isn’t possible.
  2. This helps us think about unconventional computing methods (brains, molecules, etc).

Class Logistics [cpsc421/logistics]

Prerequisites [cpsc421/prereqs]

  • Proofs, by induction especially
  • CPSC 213 and 221 (kind of)
  • Sets, graphs, discrete math, a little bit of linear algebra

Assignments [cpsc421/assignments]

  • Assignments available on Piazza
  • Assignment #1 should take an hour
  • In total: 10 assignments
  • Typically hard, include bonus questions
  • Groups of 2 allowed
  • LaTeX, Gradescope

Main concepts of the course [cpsc421/concepts]

Computational Problems. We want to understand things like: can I solve this problem? can I solve it fast?

  1. ex. Given a list, sort it.
  2. ex. Given an integer, find its prime factors.
  3. ex. Given a polynomial, find its roots.

Some Notation [cpsc421/notation]

Representation: We’ll consider everything to be a string.

To first talk about strings, we need to define an alphabet.

Definition 1. Alphabet [alphabet]

An alphabet is any finite non-empty set.

It is usually represented as Σ\Sigma or Γ\Gamma. Often Σ={0,1}\Sigma = \left\{ {0,1} \right\}, or Σ=ASCII\Sigma = \text{ASCII}, or Σ=Unicode\Sigma = \text{Unicode}.

Definition 2. String [string]

Computer science.
A string is a finite sequence of 0+0 + characters from an alphabet.
Programming.
A string is a UTF-8…

Definition 3. Empty string [empty-string]

We often will talk about the empty string, so we have a special symbol for it: ε\varepsilon.

Definition 4. sigma [sigma]

Σ*\Sigma \ast is the set of all strings with alphabet Σ\Sigma.

Definition 5. Language [language]

A language is any set LL (including infinite sets) such that L⊂Σ*L \subset \Sigma \ast. Even L=⌀L = \varnothing is okay.

Definition 6. Computational Problem [problem]

A computational problem is a function mapping strings to strings.

Example.

f(6)=2,3f(6) = \text{2,3}

Example.

f(z8sst)=errorf\left( \text{z8sst} \right) = \text{error}

Note that the definition of a computational problem does not specify how to produce the outputs from the inputs. There is no algorithm here.

We’re often interested in a specific type of computational problem: decision problems.

Definition 7. decision problem [decision-problem]

A decision problem is a computational problem with a Boolean / binary / n-ary output.

We can usually tweak computational problems to become decision problems: e.g. given (x,y)\left( {x,y} \right), does xx have a prime factor that is <y< y?

Important Idea: decision problems are equivalent to languages.

Example.

Let ff be a decision problem. Let LL be the set of all strings that ff maps to “Yes”.

L={x∈Σ*:f(x)=Yes}L = \left\{ {x \in \Sigma \ast :f(x) = \text{Yes}} \right\}T={x∈Σ*:f(x)=No}T = \left\{ {x \in \Sigma \ast :f(x) = \text{No}} \right\}

LL and TT are complementary sets: no element is in both, and every element (of the overarching language) is in one or the other.

Example.

L={x∈Σ*:xis prime}L = \left\{ {x \in \Sigma \ast :x\ \text{is prime}} \right\}

The decision problem is f(x)={Yes ifxis prime; No otherwise}f(x) = \left\{ {\text{Yes if}\ x\ \text{is prime; No otherwise}} \right\}

Definition 8. Set builder notation [set-builder]

{x∈Σ*:f(x)=Yes}\left\{ {x \in \Sigma \ast :f(x) = \text{Yes}} \right\}
reads as for all XX in Σ*\Sigma \ast such that f(x)f(x) is equal to “Yes”

Recap: Learning Goals [cpsc421/intro-goals]

Note
This course and its slides were created for a MWF class, haven’t yet been adapted for TT
  1. What is the theory of computation about?
  2. What is a computational problem?
  3. What is computation?

Our definitions thus far: Alphabet, Computational problem, Decision problem, Finite Automaton (of DFA), Language-accepted-by, Regular Languages

Definitions: alphabet, string, computational problem, decision problem, language, Finite Automaton (of DFA), “Language Accepted By”, Regular Language

Automata Theory [automata-theory]

finite-automata [finite-automata]

computability-theory [computability-theory]

Complexity Theory [complexity-theory]

Definition 1. Elephant Jokes [elephant-jokes]

How do you shoot a blue elephant?
With a blue elephant gun.
How do you shoot a red elephant?
Hold its trunk shut until it turns blue, then shoot it with a blue elephant gun.
How do you shoot a purple elephant?
Paint it red, hold its trunk shut until it turns blue, then shoot it with a blue elephant gun.

Elephants are much like reductions.

Definition 2. Reductions [reductions]

Say we have two problems.

Problem 1.
Shoot a red elephant.
Problem 2.
Shoot a blue elephant.

We can say that P1P_{1} reduces to P2P_{2} if we can design an algorithm for solving P1P_{1} that uses P2P_{2}.

The following are equivalent:

  • P1≤TP2P_{1}\underset{T}{\leq}P_{2}
  • P1P_{1} reduces to P2P_{2}
  • P1P_{1} can be solved in terms of P2P_{2}
  • P1P_{1} can be solved using P2P_{2} as a Subroutine

IMPORTANT: Note the order! This is easy to flip-flop!

Given our original problems: this means that the problem of shooting a red elephant can be solved by shooting a blue elephant.

What else does this tell us?

  • If P2P_{2} is easy, then P1P_{1} is easy
  • If P1P_{1} is hard, then P2P_{2} is hard (we’ll use this idea a lot)
  • P1P_{1} is no harder than P2P_{2}
  • P2P_{2} is at least as hard as P1P_{1}

We can similarly talk about languages this way. L1≤L2L_{1} \leq L_{2} means:

  • deciding L1L_{1} is no harder than deciding L2L_{2}, or
  • deciding L2L_{2} is at least as hard as deciding L1L_{1}.

Example. Showing the Halting problem to be undecidable

Last time: ATMA_{\text{TM}} is undecidable.

  • ATM={⟨M,w⟩:Macceptsw}A_{\text{TM}} = \left\{ {\left\langle {M,w} \right\rangle:M\ \text{accepts}\ w} \right\}
  • HALTTM={⟨M,w⟩:Mhalts on inputw}\text{HALT}_{\text{TM}} = \left\{ {\left\langle {M,w} \right\rangle:M\ \text{halts on input}\ w} \right\}

Recall: HALTTM\text{HALT}_{\text{TM}} is recognizable

  • You can create a Turing machine UU that takes an ⟨M,w⟩\left\langle {M,w} \right\rangle and simulate it: if UU halts, our original Turing machine MM accepts

We want to show that ATM≤THALTTMA_{\text{TM}}\underset{T}{\leq}\text{HALT}_{\text{TM}}.

Proof. (by contradiction.)

Suppose there is a Turing machine RR that decides HALTTM\text{HALT}_{\text{TM}} (it doesn’t exist).

We want to use RR to design a Turing machine SS that decides ATMA_{\text{TM}}.

Design:

  • Use RR to reject if the input runs forever
  • Otherwise, simply simulate the input (it is now guaranteed to be decidable)

So we can, and we do, and we arrive at a contradiction: as we know there is no such decider for ATMA_{\text{TM}}.

Then as ATMA_{\text{TM}} reduces to HALTTM\text{HALT}_{\text{TM}}: HALTTM\text{HALT}_{\text{TM}} is at least as hard as ATMA_{\text{TM}}, which is undecidable.

So HALTTM\text{HALT}_{\text{TM}} is undecidable.

Aside.

Reduction can go both ways! ATMA_{\text{TM}} reduces to HALTTM\text{HALT}_{\text{TM}}, and vice versa. There are (probably) problems that cannot be related, however.

Example. Showing that ETME_{\text{TM}} is undecidable

We will show by reduction: by reducing ATMA_{\text{TM}} to ETME_{\text{TM}}.

In other words, we will construct a Turing-machine for deciding ATMA_{\text{TM}} that uses ETME_{\text{TM}} as a subroutine.

  • ATM={⟨M,w⟩:Macceptsw}A_{\text{TM}} = \left\{ {\left\langle {M,w} \right\rangle:M\ \text{accepts}\ w} \right\}
  • ETM={⟨M⟩:Mis a Turing machine andL(M)is emptyE_{\text{TM}} = \{\left\langle M \right\rangle:M\ \text{is a Turing machine and}\ L(M)\ \text{is empty} (i.e. MM accepts nothing)
Proof.

Assume we have a decider RR that decides ETME_{\text{TM}}.

Idea: create a new Turing machine NN with M,wM,w hardcoded inside.

  • if y != w: reject
  • if y == w: then run MM on input ww
  • So the language is either ww or ⌀\varnothing.

Simulating a Turing machine SS on input xx:

  • if xx not of form ⟨M,w⟩\left\langle {M,w} \right\rangle then reject
  • Construct the Turing-machine NN above
  • Run RR on input NN
  • If RR accepts, then we know MM does not accept ww
  • If RR accepts, SS rejects, and if RR rejects, SS accepts.

Computability vs. Complexity [computability-complexity]

What is the difference between this theory of computation and Turing machines, vs. complexity?

Computability-theory studies whether problems have any algorithmic solution whatsoever.

Complexity theory studies whether problems have efficient algorithmic solutions.

  • How much time is required?
  • How much space is required?
  • Does randomness help?

Definition 1. Worst case analysis [worst-case-analysis]

Usually theorists do worst case analysis, i.e. as a function of the input length nn, what is the maximum amount of resources used over all inputs of length nn? (note: nn is a commonly used variable!)

The idea here is that it’s helpful to analyze the worst case, as every input will then result in equal or better time.

Definition 1. Runtime [runtime]

  1. Complexity theory.

    1. The runtime of a Turing machine MM is f:ℕ→ℕf:{\mathbb{N}}\rightarrow{\mathbb{N}}: f(n)=max⁡(x∈Σ*,|x|=n)f(n) = \max\left( {x \in \Sigma \ast ,|x| = n} \right). (the number of steps of MM on input nn until it halts) (assume MM is a decider for simplicity)
    2. The runtime of a nondeterministic Turing machine NTM\text{NTM} on input XX is max-length of any root-leaf path. For deciders – no infinite paths!

Definition 2. Class [class]

  1. Complexity theory. A class is a set of languages (or equivalently, computational problems).

Definition 3. Complexity class [complexity-class]

A complexity class is a class defined by Turing machine resource constraints.

Definition 4. TIME(t(n)) [TIME-tn]

TIME(t(n))\text{TIME}\left( {t(n)} \right) is the class of all languages LL such that there exists a Turing machine with runtime O(t(n))O\left( {t(n)} \right) that decides LL.

In briefer notation: TIME(t(n))={languageL:∃TMMthat decidesLin timeO(t(n))}\text{TIME}\left( {t(n)} \right) = \left\{ {\text{language}\ L:\exists\ \text{TM}\ M\ \text{that decides}\ L\ \text{in time}\ O\left( {t(n)} \right)} \right\}

Definition 1. P (complexity class) [P]

P=⋃c>0TIME(nc)P = \bigcup_{c > 0}\text{TIME}\left( n^{c} \right)

Why is P a good definition for efficient computation?

  • Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
  • Closed under composition: can use polynomial time algorithm as a subroutine
  • In practice: algorithms usually can be improved. If we find an O(n30)O\left( n^{30} \right) time algorithm, it typically can be improved to, say, O(n5)O\left( n^{5} \right) time.

Example. 2COLORMAP

Let GG be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.

Question. The two color map does not work for every map. So consider it as a problem: 2COLORMAP={⟨G⟩:Ghas valid red/blue coloring}\text{2COLORMAP} = \left\{ {\left\langle G \right\rangle:G\ \text{has valid red/blue coloring}} \right\}. Is 2COLORMAP ∈\in P?

Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.

It’s unknown if the three color map is in P. It’s known to be in EXP: O(3nn2)∈O(4n)O\left( {3^{n}n^{2}} \right) \in O\left( 4^{n} \right)

Recall: different machine models have different efficiencies: our multi-tape Turing machines were broadly more efficient than our single-tape Turing machines.

Example.

PAL={wwR:w∈Σ*}\text{PAL} = \left\{ {ww^{R}:w \in \Sigma \ast} \right\}

  • Decided by a single-tape Turing machine in O(n2)O\left( n^{2} \right) time
  • Decided by a multi-tape Turing machine in O(n)O(n) time

Revising the Church-Turing thesis [extended-church-turing]

The extended Church-Turing thesis is the belief that Turing machines capture our intuitive notion of what is efficiently computable. It postulates that everything we can compute in time t(n)t(n) on any physical computer can be computed on a Turing machine in time O(t(n)c)O\left( {t(n)}^{c} \right), for some constant cc.

Is this true, does it hold? Maybe not, with newer forms of computation like quantum computers.

Definition 3. P and EXP [P-EXP]

Definition 1. P (complexity class) [P]

P=⋃c>0TIME(nc)P = \bigcup_{c > 0}\text{TIME}\left( n^{c} \right)

Why is P a good definition for efficient computation?

  • Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
  • Closed under composition: can use polynomial time algorithm as a subroutine
  • In practice: algorithms usually can be improved. If we find an O(n30)O\left( n^{30} \right) time algorithm, it typically can be improved to, say, O(n5)O\left( n^{5} \right) time.

Example. 2COLORMAP

Let GG be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.

Question. The two color map does not work for every map. So consider it as a problem: 2COLORMAP={⟨G⟩:Ghas valid red/blue coloring}\text{2COLORMAP} = \left\{ {\left\langle G \right\rangle:G\ \text{has valid red/blue coloring}} \right\}. Is 2COLORMAP ∈\in P?

Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.

It’s unknown if the three color map is in P. It’s known to be in EXP: O(3nn2)∈O(4n)O\left( {3^{n}n^{2}} \right) \in O\left( 4^{n} \right)

Definition 2. EXP (complexity class) [EXP]

EXP=⋃k>0TIME(2nk)\text{EXP} = \bigcup_{k > 0}\text{TIME}\left( 2^{n^{k}} \right)

The four color map works for all maps, so 4COLORMAP={⟨G⟩:Gis a valid map}\text{4COLORMAP} = \left\{ {\left\langle G \right\rangle:G\ \text{is a valid map}} \right\}.

Theorem 1. Time Hierarchy Theorem [time-hierarchy]

Question: is EXP == P? Answer: No!

The time hierarchy theorem tells us that given an f:ℕ→ℕf:{\mathbb{N}}\rightarrow{\mathbb{N}} that is “reasonable” where f(n)=Ω(nlogn)f(n) = \Omega\left( {n\log n} \right), then the TIME(f(n))⊂TIME(f(n)4)\text{TIME}\left( {f(n)} \right) \subset \text{TIME}\left( {f(n)}^{4} \right).

Notably, TIME(f(n))≠TIME(f(n)4)\text{TIME}\left( {f(n)} \right) \neq \text{TIME}\left( {f(n)}^{4} \right)!

Corollary.

TIME(nc)≠TIME(n4c)\text{TIME}\left( n^{c} \right) \neq \text{TIME}\left( {n^{4}c} \right) for any c≥1c \geq 1.

Corollary.

TIME(nc)≠TIME(2n)\text{TIME}\left( n^{c} \right) \neq \text{TIME}\left( 2^{n} \right) for any c≥1c \geq 1.

TIME(2nk)≠TIME\text{TIME}\left( 2^{n^{k}} \right) \neq \text{TIME}

Question. How do you prove the Time hierarchy theorem?

Answer. By diagonalization. Look at Turing machines that are “fast” and Turing machines that are “slow”. Come up with a language that the “fast” Turing machines cannot possibly decide, that is decidable by a “slow” machine.

A language that is in EXP and not in P: ???

Time Complexity [time-complexity]

Where is 3colormap? We know it is in EXP, and either in Np (complexity class) or in both NP and P.

The Time Hierarchy theorem tells us that there is something in EXP ∖\smallsetminus P. (why? still not clear)

Figure 1: Complexity hierarchy

NP and Time Complexity [cpsc/NP-complexity]

NP is very important! Contains a large about of natural problems.

  • ex. Hamilton path, 3COLORGRAPH, graph isomorphism, satisfiable boolean formulas

Many problems in NP have “identical complexity”, i.e., are complete. (We’ll talk about this later.)

Definition 1. Runtime [runtime]

  1. Complexity theory.

    1. The runtime of a Turing machine MM is f:ℕ→ℕf:{\mathbb{N}}\rightarrow{\mathbb{N}}: f(n)=max⁡(x∈Σ*,|x|=n)f(n) = \max\left( {x \in \Sigma \ast ,|x| = n} \right). (the number of steps of MM on input nn until it halts) (assume MM is a decider for simplicity)
    2. The runtime of a nondeterministic Turing machine NTM\text{NTM} on input XX is max-length of any root-leaf path. For deciders – no infinite paths!

Recall:

Definition 2. TIME(t(n)) [TIME-tn]

TIME(t(n))\text{TIME}\left( {t(n)} \right) is the class of all languages LL such that there exists a Turing machine with runtime O(t(n))O\left( {t(n)} \right) that decides LL.

In briefer notation: TIME(t(n))={languageL:∃TMMthat decidesLin timeO(t(n))}\text{TIME}\left( {t(n)} \right) = \left\{ {\text{language}\ L:\exists\ \text{TM}\ M\ \text{that decides}\ L\ \text{in time}\ O\left( {t(n)} \right)} \right\}

Definition 1. P (complexity class) [P]

P=⋃c>0TIME(nc)P = \bigcup_{c > 0}\text{TIME}\left( n^{c} \right)

Why is P a good definition for efficient computation?

  • Insensitive to model of computation: by the extended Church-Turing thesis, switching computational models “only” involves a polynomial slowdown
  • Closed under composition: can use polynomial time algorithm as a subroutine
  • In practice: algorithms usually can be improved. If we find an O(n30)O\left( n^{30} \right) time algorithm, it typically can be improved to, say, O(n5)O\left( n^{5} \right) time.

Example. 2COLORMAP

Let GG be a “map” of countries in the plane, where a coloring is valid if neighboring countries have different colors.

Question. The two color map does not work for every map. So consider it as a problem: 2COLORMAP={⟨G⟩:Ghas valid red/blue coloring}\text{2COLORMAP} = \left\{ {\left\langle G \right\rangle:G\ \text{has valid red/blue coloring}} \right\}. Is 2COLORMAP ∈\in P?

Answer. Yes! Start with an arbitrary country, set it to red, set their neighbors to blue, and continue. If there is a conflict, reject, if there is no conflict, accept.

It’s unknown if the three color map is in P. It’s known to be in EXP: O(3nn2)∈O(4n)O\left( {3^{n}n^{2}} \right) \in O\left( 4^{n} \right)

Definition 3. NTIME(t(n)) [NTIME-tn]

NTIME(𝑡(𝑛))={language𝐿:∃NTM𝑀thatdecides𝐿in time𝑂(𝑡(𝑛))}

NP (complexity class) [cpsc/NP]

NP=⋃c>0NTIME(nc)\text{NP} = \bigcup_{c > 0}\text{NTIME}\left( n^{c} \right)

Obvious: P ⊂\subset NP

Example. 3colormap ∈\in NP

Let’s prove that 3colormap is in NP.

Proof: Design a nondeterministic Turing machine to decide 3colormap in polynomial time.

  • Iterate through vertices
  • Nondetermistically pick a color for each vertex (a “lucky guess”)
  • Check all pairs of neighbors to see if they are the same color
  • If so reject, otherwise accept

Theorem 2. Certificates and Verifiers [certificates-verifiers]

NP has two main, equivalent definitions:

  1. There exists a nondeterministic polytime TM MM that decides LL.
  2. There exists a deterministic polytime TM VV and a constant cc s.t.:

L={x∈Σ*:∃y∈Σ*s.t.|y|≤|x|c∧Vaccepts(x,y)}L = \left\{ {x \in \Sigma \ast :\exists y \in \Sigma \ast \text{s.t.}\ |y| \leq |x|^{c} \land V\ \text{accepts}\ \left( {x,y} \right)} \right\}

Where xx is the “input”, yy is the “certificate”, VV is the “verifier”. i.e. for the three color graph, give us a colored graph and we can verify it

The certificate yy serves as the verifier VV’s substitute for nondeterminism.

Example. Verifying 3colormap

Claim: 3colormap ∈\in Np (complexity class).

  • {⟨G⟩:Gis 3-colorable}\left\{ {\left\langle G \right\rangle:G\ \text{is 3-colorable}} \right\}
  • Must find a deterministic polytime TM V s.t. 3COLOR={x:∃y,|y|≤|x|c,Vaccepts(x,y)}\text{3COLOR} = \left\{ {x:\exists y,|y| \leq |x|^{c},V\ \text{accepts}\ \left( {x,y} \right)} \right\}
  • Code for VV: on input (x,y)\left( {x,y} \right)

    • If xx not of form , where is a Graph, reject
    • From yy, extract values color(v)∈{1,2,3}\text{color}(v) \in \left\{ {1,2,3} \right\} for each v∈Vv \in V
    • For every edge {u,v}∈E\left\{ {u,v} \right\} \in E: if color(u) == color(v), reject
    • Otherwise accept
  • yy does exist, it’s simply a valid coloring of the graph

To show correctness of VV, we need three things:

  1. If x=⟨G⟩x = \left\langle G \right\rangle and G is 3-colorable: need ∃ys.t.|y|≤|x|c\exists y\ \text{s.t.}\ |y| \leq |x|^{c} and Vaccepts(x,y)V\ \text{accepts}\ \left( {x,y} \right).

    • It does exist, yy can be a valid 3 coloring of GG. Note: |y|=O(n)|y| = O(n) and |x|=Ω(n)|x| = \Omega(n)
  2. If x≠⟨G⟩x \neq \left\langle G \right\rangle where G is 3-colorable: then no certificate yy should make VV erroneously accept.

    • If xx not of form ⟨G⟩\left\langle G \right\rangle: vv definitely rejects.
    • If xx of form ⟨G⟩\left\langle G \right\rangle by not 3-colorable, then VV must reject because it always checks that yy is a valid coloring.
  3. Must check that VV runs in time polynomial in |xy||xy|.

Example. Proofs of equivalence of our NP definitions

Proof. (2)⇒(1)(2)\Rightarrow(1)
  • Given verifier VV, must construct a NTM MM deciding LL
  • Inputs to the verifier are xx and yy, with |y|≤|x|c|y| \leq |x|^{c}

  • Code for MM:

    • On input xx, nondeterministically pick y∈Σ*y \in \Sigma \ast with |y|≤|x|c|y| \leq |x|^{c}
    • Run VV on input (x,y)\left( {x,y} \right)
    • Accept if VV accepts. Reject if VV rejects.

    i.e. Suppose x∈L⇒∃ys.t.Vaccepts(x,y)⇒there is a leaf whereMacceptsx \in L\Rightarrow\exists y\ \text{s.t.}\ V\ \text{accepts}\ \left( {x,y} \right)\Rightarrow\text{there is a leaf where}\ M\ \text{accepts}. If x∉L⇒∄ys.t.Vaccepts(x,y)⇒∄leafx \notin L\Rightarrow\nexists y\ \text{s.t}.V\ \text{accepts}\ \left( {x,y} \right)\Rightarrow\nexists\ \text{leaf}, so MM does not accept xx.

Proof. (1)⇒(2)(1)\Rightarrow(2)
  • Given an NTM MM, you can convert that into a verifier VV for LL.
  • Input to MM is xx, runtime is at most |x|c|x|^{c}
  • Idea: VV simulates the tree, but only on a single branch of configuration tree. yy specifies which branch. nondeterminism comes into play by letting us pick the correct branch.

    • our nondeterminism lets us pick the correct branch: then the cc term is the depth of the path, which is at most polynomial
  • Code for MM:

    • Simulate MM deterministically on input xx, using yy as the sequence of nondeterministic decisions
    • Accept if MM accepts. Reject if MM rejects.

Why NP is nice [cpsc/why-NP]

We’ll spend the next couple of lectures talking about NP. Why?

Because nondeterministic Turing machines are ridiculously impractical!

Many problems that we’re interested in have the form L={x:∃y,|y|≤|x|c,Vaccepts(x,y)}L = \left\{ {x:\exists y,|y| \leq |x|^{c},V\ \text{accepts}\ \left( {x,y} \right)} \right\} (where xx is the problem input and yy is the object we are seeking).

Efficient test: is yy a valid solution?

We showed 3COLOR ∈\in NP

Np (complexity class) has lots of problems that are interesting and nice to solve, but that we don’t know of any polynomial time solution. But: if any of these problems are in P, then all of them are in P. NP-completeness!

Problem. SAT [SAT]

SAT is the canonical problem in NP (like how ATMA_{\text{TM}} was our canonical undecidable problem).

SAT={⟨φ⟩:φis a Boolean formula for which there exists a satisfying truth assignment}\text{SAT} = \left\{ {\left\langle \varphi \right\rangle:\varphi\ \text{is a Boolean formula for which there exists a satisfying truth assignment}} \right\}

  • e.g. φ(x1,x2,x3,x4,x5)=(((x1∨x2)∧(x1∨¬x3∨x4))∨¬(x2∧x3)∨x4)∧¬x5\varphi\left( {x_{1},x_{2},x_{3},x_{4},x_{5}} \right) = \left( {\left( {\left( {x_{1} \vee x_{2}} \right) \land \left( {x_{1} \vee \neg x_{3} \vee x_{4}} \right)} \right) \vee \neg\left( {x_{2} \land x_{3}} \right) \vee x_{4}} \right) \land \neg x_{5}

    • helpful to visualize with a tree diagram

A satisfying truth assignment is an assignment of true/false to each variable so that the whole formula is true.

Problem. 3SAT [3SAT]

Definition 1. Conjunctive Normal Form [cnf]

A problem is in conjunctive normal form (CNF) if it is a product of sums: i.e. an AND of ORs.

Example. 3SAT\text{3SAT}

3SAT={⟨φ⟩:φis a Boolean formula in CNF with 3 literals per clause for which there exists a satisfying truth assignment}\text{3SAT} = \left\{ {\left\langle \varphi \right\rangle:\varphi\ \text{is a Boolean formula in CNF with 3 literals per clause for which there exists a satisfying truth assignment}} \right\}

  • e.g. (x1∨¬x2∨x3)∧(x5∨x4∨¬x2)∧(¬x4∨x1∨x3)∧(¬x3∨x2∧¬x1)\left( {x_{1} \vee \neg x_{2} \vee x_{3}} \right) \land \left( {x_{5} \vee x_{4} \vee \neg x_{2}} \right) \land \left( {\neg x_{4} \vee x_{1} \vee x_{3}} \right) \land \left( {\neg x_{3} \vee x_{2} \land \neg x_{1}} \right)

Definition 4. Polytime Reduction [polytime-reduction]

Definition 1. Polytime Computable [polytime-computable]

For some function f:Σ*→Σ*f:\Sigma \ast \rightarrow\Sigma \ast, it is polytime computable if there exists a Turing machine that when given xx as input terminates with f(x)f(x) on the tape and runs in time poly(|x|)\text{poly}\left( |x| \right).

Let A,B⊆Σ*A,B \subseteq \Sigma \ast (Let AA and BB be languages). ff is a polytime reduction from AA to BB if:

  • ff is a polytime computable function
  • x∈A⇒f(x)∈Bx \in A\Rightarrow f(x) \in B (f(A)⊆Bf(A) \subseteq B)
  • x∉A⇒f(x)∉Bx \notin A\Rightarrow f(x) \notin B (f(A_⊆B_f(A^{\_} \subseteq B^{\_})

We then may say A≤PBA\underset{P}{\leq}B.

…helpful image…

Example. Polytime Reduction

Suppose A={0n10n:n≥0}A = \left\{ {0^{n}10^{n}:n \geq 0} \right\}, and B={1n01n:n≥0}B = \left\{ {1^{n}01^{n}:n \geq 0} \right\}. Claim: A≤PBA\underset{P}{\leq}B

What does this mean? It means there exists some function that can take a string, map it, and manipulate it so that if x∈Ax \in A, then x∈Bx \in B, and same for converses.

Proof.

Let ff be the function that flips the bits of its input. Then, we’re done.

  • x∈A⇒f(x)∈Bx \in A\Rightarrow f(x) \in B
  • x∉A⇒f(x)∉Bx \notin A\Rightarrow f(x) \notin B
  • f(x)∈B⇒x∈Af(x) \in B\Rightarrow x \in A
  • x∈A⇔f(x)∈Bx \in A\Leftrightarrow f(x) \in B
  • Note: these do not need to be bijections!

    • A reduction that simply sends all satisfiable inputs to 0 is fine.

Facets of Reductions [cpsc/reduction-facets]

Reductions are helpful!

  • Method: find a way to map:

    • yes-instances of P1P_{1} to yes-instances of P2P_{2}
    • no-instances of P1P_{1} to no-instances of P2P_{2}
  • Notation: P1≤PP2P_{1}\underset{P}{\leq}P_{2}
  • Logic: if P2P_{2} is easy, P1P_{1} is easy
  • Contrapositive: if P1P_{1} is hard, P2P_{2} is hard
Theorem.

If A≤PBA\underset{P}{\leq}B and B∈PB \in P, then A∈PA \in P.

  • There is a polytime Turing machine N that decides BB.
  • There is a polytime reduction ff from AA to BB.
Proof.

We want a Turing machine MM that decides AA in polynomial time.

  • On input xx: compute z=f(x)z = f(x) and then simulate NN on input zz. Accept iff NN accepts.
  • If x∈A⇒f(x)∈B⇒Nacceptsx \in A\Rightarrow f(x) \in B\Rightarrow N\ \text{accepts}.
  • If x∈A_⇒f(x)∉B⇒Nrejectsx \in A^{\_}\Rightarrow f(x) \notin B\Rightarrow N\ \text{rejects}.

Question. If we know AA reduces to BB and BB is in NP\text{NP}, is AA in NP\text{NP}?

Answer. Yes, P\text{P} is a subset of NP\text{NP}. Mind the direction!

When we talked about Turing machines, we had a notion of what it meant to be hard: undecidability. But now we’re talking about NP. So which problems in NP are hard?

Maybe P=NP\text{P} = \text{NP}, and so all problems in NP are easy.

Definition 5. NP-Hardness [NP-hard]

A language L is NP-hard if it is at least as hard as every problem in NP, i.e. A≤PL,∀A∈NPA\underset{P}{\leq}L,\forall A \in \text{NP}.

There’s nothing in this definition that’s really specific for NP. We could switch it out for other complexity classes if we’d like.

Note: we don’t require our language to be in NP! ATMA_{\text{TM}} is NP-hard.

Definition 1. NP-Completeness [NP-complete]

A language LL is NP-complete if LL is NP-hard and L∈NPL \in \text{NP}.

Theorem. Cook-Levin Theorem

SAT is NP-complete.

Corollary.

3SAT is also NP-complete.

Theorem.

If B is NP-complete, C∈NPC \in \text{NP}, and B≤PCB\underset{P}{\leq}C, then CC is NP-complete.

Proof.
  • Need to show: A≤PC,∀A∈NPA\underset{P}{\leq}C,\forall A \in \text{NP}
  • We know A≤PBA\underset{P}{\leq}B, i.e. you can solve AA in terms of BB.

    • So ∃\exists a polytime computable f:x∈A⇔f(x)∈Bf:x \in A\Leftrightarrow f(x) \in B.
  • We know B≤PCB\underset{P}{\leq}C: ∃\exists a polytime computable g:y∈B⇔g(y)∈Cg:y \in B\Leftrightarrow g(y) \in C
  • Let h:Σ*→Σ*h:\Sigma \ast \rightarrow\Sigma \ast be h(x)=g(f(x))h(x) = g\left( {f(x)} \right). This is polytime computable.

    • Has the properties: x∈A⇔f(x)∈B⇔g(f(x)∈Cx \in A\Leftrightarrow f(x) \in B\Leftrightarrow g(f(x) \in C.

Problem. CLIQUE [CLIQUE]

Figure 1: Simple Clique

Given G=(V,E)G = \left( {V,E} \right) and kk, does there exist U⊆VU \subseteq V with |U|≥k|U| \geq k such that {u,v}∈E\left\{ {u,v} \right\} \in E for all distinct vertices u,v∈Uu,v \in U?

CLIQUE={⟨G,K⟩:Ghas a clique of sizek}\text{CLIQUE} = \left\{ {\left\langle {G,K} \right\rangle:G\ \text{has a clique of size}\ k} \right\}

  • No specification on size: in our example above, there are cliques of size 0 through 3
Theorem.

CLIQUE is NP-complete: i.e. CLIQUE is NP-hard, and CLIQUE is in NP.

Proof.

CLIQUE is in NP: because there exists a verifier that can check a possible clique in polytime.

CLIQUE is NP-hard: because 3SAT (known NP-hard problem) reduces to CLIQUE. How can we do that?

Proof. 3SAT≤PCLIQUE\text{3SAT}\underset{P}{\leq}\text{CLIQUE} (reduction)

x∈3SATx \in \text{3SAT} maps to f(x)∈CLIQUEf(x) \in \text{CLIQUE}

  • If x=⟨φ⟩x = \left\langle \varphi \right\rangle where φ\varphi is a satisfiable 3CNF formula, then f(x)=⟨G,k⟩f(x) = \left\langle {G,k} \right\rangle where GG has a clique of size kk.

x∉3SATx \notin \text{3SAT} maps to f(x)∉CLIQUEf(x) \notin \text{CLIQUE}

  • If x=⟨φ⟩x = \left\langle \varphi \right\rangle where φ\varphi has no satisfiable assignments, then f(x)=⟨G,k⟩f(x) = \left\langle {G,k} \right\rangle where GG has no clique of size kk.
  • junk can map to junk
Figure 2: Complex Clique

We can show 3SAT can be solved by finding a clique of size kk.

  • Connect every vertex in a block to every other vertex that is not its inverse.
  • Then, every clique of size kk is a possible satisfiable assignment.
  • We can’t have xix_{i} and xi_x_{i}^{\_} both being true: which is represented by no connecting edges.

We still need to “decode” f(x)∈Bf(x) \in B to x∈Ax \in A… i.e. f(x)∈CLIQUE⇒x∈3SATf(x) \in \text{CLIQUE}\Rightarrow x \in \text{3SAT}.

  • Let UU be a clique of size kk. We must divy it up so that there is exactly one vertex in each group.
  • Given a f(x)∈CLIQUEf(x) \in \text{CLIQUE} constructed from a 3SAT\text{3SAT} problem, then we find a satisfying x∈3SATx \in \text{3SAT}.

Aside: suppose we want to ensure there is a clique of at least size k−1k - 1. We can make a separate, disconnected clique of k−1k - 1 vertices. What’s this useful for? Don’t know yet…

When designing a reduction: if you want to show that your reduction is correct: you need to show that

  • f is polytime computable
  • x∈A⇒f(x)∈Bx \in A\Rightarrow f(x) \in B
  • f(x)∈B⇒x∈Af(x) \in B\Rightarrow x \in A (the converse)
  • or, x∉A⇒f(x)∉Bx \notin A\Rightarrow f(x) \notin B (the inverse)

In a reduction, it’s more typical to show x∈A⇒f(x)∈Bx \in A\Rightarrow f(x) \in B (often straightforward).

  • Often want to “decode” f(x)∈Bf(x) \in B to obtain x∈Ax \in A.

Theorem 3. Cook-Levin Theorem [cook-levin]

Theorem.

SAT is in NP (you can construct a verifier that runs in polynomial time)

Corollary.

SAT is NP-complete.

Proof.

To prove this, we must show that ∀A∈NP,A≤PSAT\forall A \in \text{NP},A\underset{P}{\leq}\text{SAT}.

Idea: given a deterministic Turing machine MM and an input WW, we can create a circuit ff such that MM accepts ww if and only if ff evaluates to true.

That’s great, but we really want to construct it for a nondeterministic Turing machine MM: how can we do that?

  • Given MM and an input ww, construct a boolean formula ff with variables as inputs such that MM accepts ww if and only if ff is satisfiable.
  • i.e. the nondeterminism is each permutation of the variables, then it’s deterministic to satisfy it

Recall: Behavior of a deterministic Turing machine

  • Start = Config(1)
  • Config(2) = …
  • Config(3) = …
  • Config(i) uniquely determines Config(i+1)
  • The total amount of configurations we have to look at is nkn^{k}, and the total amount of tape we have to look at is also nkn^{k}.

Simulating a Turing machine with a tableau [cpsc/tm-tableau]

Main idea: an algorithm can be converted to a Boolean circuit

…table…

M accepts w if and only if the tableau can be filled such that:

  • The first row is the starting configuration of M on input w
  • (i+1)st\left( {i + 1} \right)^{\text{st}} configuration follows from the ithi^{\text{th}} configuration
  • Eventually reach an accepting configuration

So how can this tableau be converted into a boolean formula? We’ll come up with some boolean variables to represent what is happening in the cells.

Let cell[i,j]\text{cell}\left\lbrack {i,j} \right\rbrack refer to the according tableau entry.

  • Note: row i: time step, column j: head position, i,j≤nki,j \leq n^{k}
  • Our cell entries are not boolean values: but we still want to encode them as such!
  • Create boolean variables xi,j,sx_{i,j,s} where i,j≤nki,j \leq n^{k} and s∈γ∪Qs \in \gamma \cup Q
  • cell[i,j]=s⇔xi,j,s=true∧xi,j,s=false∀s≠s\text{cell}\left\lbrack {i,j} \right\rbrack = s\Leftrightarrow x_{i,j,s} = \text{true} \land x_{i,j,s} = \text{false}\ \forall s \neq s

For a nondeterministic Turing machine:

  • The same table as the deterministic Turing machine:
  • only the (i+1)st\left( {i + 1} \right)^{\text{st}} configuration follows from the ithi^{\text{th}} configuration using some nondeterministic choice

φ=φcell∧φstart∧φmove∧φaccept\varphi = \varphi_{\text{cell}} \land \varphi_{\text{start}} \land \varphi_{\text{move}} \land \varphi_{\text{accept}}

  • φcell=∧i,j(∨s∈Γ∪Q(xi,j,s∧¬(∨t≠sxi,j,t)))\varphi_{\text{cell}} = \land_{i,j}\left( {\vee_{s \in \Gamma \cup Q}\left( {x_{i,j,s} \land \neg\left( {\vee_{t \neq s}x_{i,j,t}} \right)} \right)} \right)
  • φstart=x1,1,#∧x1,2,q0∧x1,3,w∧x1,4,w…\varphi_{\text{start}} = x_{1,1,\#} \land x_{1,2,q_{0}} \land x_{1,3,w} \land x_{1,4,w}\ldots
  • φaccept=∨i,jxi,j,qaccept\varphi_{\text{accept}} = \vee_{i,j}x_{i,j,q_{\text{accept}}}: check if any cell is accepting

Window[i,j]: six cells of the table (six cells is convenient: 3x2, we need three to read the current, state, and next items)

  • i.e. the window is size 3x2 because that’s exactly what we need to check that it is valid

φmove=∧1≤i≤nk−1,1≤j≤nk−2(Window[i,j]is legal)\varphi_{\text{move}} = \land_{1 \leq i \leq n^{k} - 1,1 \leq j \leq n^{k} - 2}\left( {\text{Window}\left\lbrack {i,j} \right\rbrack\ \text{is legal}} \right)

note: pull examples, when there is no head the last two columns cannot change

… online lecture …

Definition 6. Probabilistic Turing machine [prob-turing-machine]

A computation model that begins with a tree. When you reach a branch, you flip a coin!

We can define complexity classes based on the probability of reaching accept/reject leaves.

Definition 1. Randomized Polynomial Time [RP]

The following are equivalent:

  1. L∈RPL \in \text{RP} (Randomized Polytime) if there is a probabilistic Turing machine that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right), and has a greater than or equal to 50% chance of reaching an accepting leaf.

    • L∉RPL \notin \text{RP} if the probabilistic Turing machine has a 0% chance of reaching an accepting leaf. (must reach reject state)
    Algorithm’s Output Accept Reject
    Correct Output
    Accept ≥50%\geq 50\% / true positive ≤50%\leq 50\% / false negative
    Reject 0 / false positive 1 / true negative
  2. L∈RPL \in \text{RP} if there is a PTM that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right) and has behavior:

    • x∈Lx \in L: Pr(accept)≥50%\text{Pr}\left( \text{accept} \right) \geq 50\%
    • x∉Lx \notin L: Pr(reject)=100%\text{Pr}\left( \text{reject} \right) = 100\%
  3. L∈RPL \in \text{RP} if there exists a deterministic polytime TM V such that:

    • x∈Lx \in L: for at least half of all yy with |y|=poly(|x|)|y| = \text{poly}\left( |x| \right), Vaccepts(x,y)V\ \text{accepts}\ \left( {x,y} \right)
    • x∉Lx \notin L: for all y with |y|=poly(|x|)|y| = \text{poly}\left( |x| \right), Vrejects(x,y)V\ \text{rejects}\ \left( {x,y} \right)

Question. Why is RP useful?

Answer. Because we can build things that compute in RP, but we cannot easily simulate NP.

…useful picture…

If there was an NP-complete language in RP, then RP would equal NP.

L∈NPL \in \text{NP} if there is a TM that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right) and has behavior: Pr(reaching accept)>0\text{Pr}\left( \text{reaching accept} \right) > 0

Definition. co-RP

L∈coRPL \in \text{coRP} if there is a PTM that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right), and has the following behavior:

  • x∈Lx \in L (strings in the language) have a 100% chance of being accepted
  • x∉Lx \notin L have at least or equal to 50% chance of being rejected

Example. A Probabilistic Puzzle

Let a=[a1,a2,a3,…an]a = \left\lbrack {a_{1},a_{2},a_{3},\ldots a_{n}} \right\rbrack be a vector of nn bits.

There are two possibilities:

  • aa is all zeros
  • exactly half of aa are zeros

Question. How many bits must you look at to tell?

Answer.

  • Non-probabilistically: n/2 + 1
  • Probabilistically: just one!

Definition 2. Bounded-error Probabilistic Polynomial Time [BPP]

L∈BPPL \in \text{BPP} (Bounded-error Probabilistic Polytime) if there is a probabilistic Turing machine that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right) and has behavior:

  • x∈Lx \in L if the probability of accepting is greater than 23\frac{2}{3}
  • x∈Lx \in L if the probability of rejecting is greater than 23\frac{2}{3}
  • (23\frac{2}{3} is arbitrary: we just need pq>12\frac{p}{q} > \frac{1}{2})
Correct Output / Algorithm’s Output Accept Reject
Accept ≥23\geq \frac{2}{3} / true positive ≤13\leq \frac{1}{3} / false negative
Reject ≤13\leq \frac{1}{3} / false positive ≥23\geq \frac{2}{3} / true negative

…helpful diagram…

Definition 3. Amplification [amplification]

Modifying the definition of RP\text{RP} a little bit: L∈RP(p)L \in \text{RP}(p) if there is a PTM that, on input xx, runs in time poly(|x|)\text{poly}\left( |x| \right) and has behavior:

  • Pr(reaching accept)≥p\text{Pr}\left( \text{reaching accept} \right) \geq p
  • Pr(reaching reject)=1\text{Pr}\left( \text{reaching reject} \right) = 1

Example. Claim: RP(12)=RP(34)\text{RP}\left( \frac{1}{2} \right) = \text{RP}\left( \frac{3}{4} \right)

Proof.

Let L∈RP(12)L \in \text{RP}\left( \frac{1}{2} \right). There exists PTM MM such that x∈L:P(Macceptx)≥12x \in L:P\left( {M\ \text{accept}\ x} \right) \geq \frac{1}{2}, x∉L:Pr(Mrejectsx)=1x \notin L:\text{Pr}\left( {M\ \text{rejects}\ x} \right) = 1.

Let NN be the Turing machine on input xx

  • Run MM on input xx
  • Run MM on input xx
  • if either accepted, then accept
  • else reject

Advertisement: take CPSC 436R! Nick Harvey’s other course, on Randomized Algorithms

Definition 7. Chemoff Bound [chemoff-bound]

A Chemoff Bound will let us assert that BPP(23)=BPP(0.99)\text{BPP}\left( \frac{2}{3} \right) = \text{BPP}(0.99).

communication-theory [communication-theory]