theory of computation theorems
A L is R if and only if L is RE and L complement is RE
- If language A is R (decidable), easy to see that A and its complement are RE (turing recognizable) since a decider must exist - If language A and its complement are RE, have M1 recognize A and M2 recognize A's complement: - Machine M: - Run both M1 and M2 on w simultaneously - If M1 accepts, accept. If M2 accepts, reject. details of M: M uses two tapes, one for M1 and one for M2 and takes turns simulating one step of each machine, continuing until one or the other accepts - every string w must exist in either A or A complement, therefore one machine will accept at some point - since M halts when one or the other accepts, M is a decider - additionally, it accepts all strings in A and rejects those not in A - therefore, it is a decider for A
NFA and DFA have equal computing power
-DFA is already an NFA, trivial. -Show NFA can be simulated with a DFA: DFA can simulate an NFA by having 2^k states to simulate all of the NFA's substates (powerset) -Decide where arrows should go - For any epsilon arrows, make computation go immediately to those steps from current state
Accept TM is RE \ R
Accept TM : { w#s | w is a code and Mw accepts s } - Accept TM is RE as Accept TM = L(U) -> U is Universal TM - Assume Accept TM is R -> there should exist a decider D with the language Accept TM Run D': - Simulate D on input w#s -D' rejects if w is not a code for a machine -If yes, feed w#w to Mw, and reject iff Mw accepts input - D' = diagonal language which is NOT recursively enumerable (contradiction!) - Accept TM is not recursive, according to corollary: if B is not R, and B is mapping reducible to A, then A is not recursive
lang is RE if and only if an enumerator enumerates all words
Given E, let M do the following on w: - simulate E - whenever E sends "s" to the printer, compares s to input w: - if s = w, accept (if input string is sent to printer, then input string is in language) - if s never = w, then enter a loop (and reject) Given M, design E: in rounds: - E in i,j round simulates M on word i for j steps, if accepted within j steps (each stage takes a finite number of steps, so E will get to all stages), send w i to the printer - makes sure that there is no loop, bc if there is a loop on word i, then E would never get to any word after word i
lang is R if and only if an enumerator enumerates all words in increasing order
Given decider D, on enumerator E, simulate D on w1, w2, w3, ... (in lexicographic order) - send wi to printer if D accepts it - Deciders don't loop so it is ok Given enumerator E, on decider D, simulate E - if s > w (in lexicographic order), D rejects input w - if L(E) is infinite, we are done.
HALT TM is RE \ R
HALT TM = { <M,w> | M is a TM and M halts on input w} idea: reduce Accept TM (which is RE\R) to HALT TM. Assume that HALT TM is decidable to show that Accept TM is decidable, which is a contradiction proof: Assume R decides HALT TM (indicates whether input M halts on input w) - Construct S to decide Accept TM Run S on input <M,w>: - Run R on input <M,w> - If R rejects, reject bc we know that <M,w> does not belong to Accept TM - If R accepts, simulate M on w until M halts - If M has accepted, accept. If M has rejected, reject. Therefore, if R decides HALT TM, then S decides Accept TM which is a contradiction because Accept TM is undecidable, so HALT TM must also be undecidable.
if language is described by reg expression, it is regular
Idea: if an NFA recognizes A then A is regular Convert R into NFA N. Consider six cases in formal def of regular expressions 1. R = a for some a in alphabet sigma 2. R = epsilon 3. R = empty string 4. R1 U R2 where R1 and R2 are regular expressions 5. R1 ◦ R2 where R1 and R2 are regular expressions 6. R1* where R1 is a regular expression
pumping lemma for CFL
If A is a context-free language, then there is a number p (the pumping length) where, if string s ∈ A and |s| ≥ p, , then s may be written in five pieces s = uvxyz satisfying the conditions: 1. |vxy| ≤ p 2. |vy| > 0 3. u(v^i)x(y^i)z ∈ A, for each i = 0,1,2,... Idea: -If |s| ≥ p A is a CFL and G is the CFG that generates it - show that any sufficiently long string in A can be pumped and still exist in A - since s is in A, it is derivable from G and therefore has a parse tree - because s is very long, the branch from the start variable (root) to the terminal symbol (leaf) must be very long - therefore, one variable symbol R along path must repeat bc of the PHP - can replace the subtree under the second occurrence of R with the subtree from under the first occurrence and still get legal subtree - therefore, can pump second and 4th parts of string and still obtain string in language
pumping lemma for reg languages
If A is a reg language, then there is a number p (pumping length) where if string s ∈ A and |s| ≥ p, then s can be written in three pieces, xyz satisfying the conditions: 1. |xy| ≤ p. 2. |y| > 0 3. x(y^i)z ∈ A for each i = 0,1,2,... Idea: assign pumping length p to be the number of states in M (DFA that recognizes A) -if |s| ≥ p: -if n = |s|: running a string s ∈ A on a machine that accepts A, will go through a number of states equal to n + 1 (bc of the start state) before accepting - since |s| = n ≥ p (number of states) the length of the sequence of states (n + 1), n + 1 > p - by the pigeonhole principle, the sequence must contain a repeated state - using partition xyz, y will be the part of s between the two repeated states. Thus, changing i (i = 2: xyyz) will not change the final state - |xy| ≤ p in order to ensure that first partition occurs within y
KNAPSACK is NP Complete
KNAPSACK P = {(w1, . . . ,wm, v1, . . . , vm,w, k|∃I ⊆ {1, 2 . . . , m} : SUM i∈I wi ≤ w, SUM i∈I vi ≥ k} - we try to put the most valuable objects into a knapsack: the ith object has weight wi and value vi. Can we gather a total value of at least k, while total weight is not more than w? SUBSET-SUM is a special case of KNAPSACK! (so KNAPSACK is NP-complete) given (s1, . . . ,sm,t) we let wi = vi = si and t = w = k.
MAXCLIQUE is NP Complete
MAXCLIQUE = {(G, k)|G contains a clique K with |K| = k} proof: - witness is a clique of size k - MAXSTABLE ≤P MAXCLIQUE: (G, k) → (G complement, k) where G complement is the graph with the same vertex set as G and a pair u, v forms an edge in G complement if and only if it is not in G (the complement graph)
MAXSTABLE is NP Complete
MAXSTABLE = {(G, k)|G contains a stable set U with |U| = k} proof: - a witness is a stable set of size k. - we will prove 3COL ≤P MAXSTABLE - let us define the reduction f as follows: for any graph G, let G' consist of 3 vertex disjoint copies G1, G2, G3 of G and for any vertex v ∈ V(G) -- let us add a triangle to G' containing the three copies v1, v2, v3 of v. - let f (G) = (G', |V(G)|) - note that |V(G')| = 3|V(G)| and E(G') = 3(|E(G)| + |V(G)|). - furthermore, G' is computable in polynomial time from G.
one way infinite 1-tape TM is equivalent to two-way infinite 1-tape TM
NEED TO EDIT/UNDERSTAND - simulate a one-way on a two-way by never going to negative - simulate two-way on one-way: - store two elements in each cell representing negative and positive - change names of tape states and symbols, indexing them with L and R to denote left and right machines. - modify transitions so there are individual transition states for L and for R, merged using set union - add set of transitions for each state, so that if tape reaches end, it changes to counterpart (L -> R, R -> L) https://cs.stackexchange.com/questions/22863/turing-machine-infinite-tape-in-one-or-two-directions
The diagonal language is not RE
On machine H: - Start with infinite matrix with TM codes enumerated on one axis, and corresponding machines on other axis (this is possible because all TM characters are finite). The i, j entry is accepted if code i is a code for machine j. - Run each i code on the corresponding j machine On machine D: - Run machine H - Reject when machine H accepts (if M accepts a code, reject) - Accept when machine H rejects - Therefore, D will reject its own code only when D accepts its own code in the table -> CONTRADICTION
Witness theorem
The following are equivalent: 1. L is in NP 2. there exists a positive real c and a language L1 ∈ P consisting of pairs (x, y) ∈ Σ∗ × Σ∗ such that: a. if (x, y) ∈ L1, then |y| ≤ n^c b. x ∈ L if and only if ∃ y with (x, y) ∈ L1 (i.e. L1 is a witness language of L)
regular langs are closed under regular operations
Union: simulate N1 and N2 on N by creating new start state with epsilon arrows pointing to start states of N1 and N2. N will accept if either N1 or N2 accepts Concatenation: Use an NFA, simulate N1 first, if accept state is reached, simulate N2 using epsilon arrow. Accept if accept state reached in N2. (N is non-deterministically guessing where to split input) Star: Use an NFA, add accept state at beginning to handle empty case, add epsilon arrows from accept states to beginning , so that A* accepts any combination of words in A
Properties of polynomial time mapping reduction
i. If A ≤P B and B ∈ P, then A ∈ P holds. proof: Let f be a reduction from A to B computable in time c1*n^k and let M be a TM recognizing B in running time c2*n^l. Then the machine N that on input w computes f (w) then runs M on f (w) recognizes A. The running time of N on w is at most c1*|w|^k + c2(c1*|w|^k)^l ≤ 2*c2*c1^l*|w|^(kl) ii. If A ≤P B and B ≤P C hold, then so does A ≤P C. proof: Let f be a reduction from A to B computable in time c1*n^k and g be a reduction from B to C computable in time c2*n^l. Then consider h = g ◦ f . w ∈ A ⇔ f (w) ∈ B ⇔ g(f (w)) = h(w) ∈ C. h is computable using first the machine computing f and then the machine computing g. the running time to compute f (w) is at most c1*|w|^k and thus f (w) has length at most c1*|w|^k. computing then h(w) = g(f (w)) needs at most c2(c1*|w|^k)^l = c2*c1^l*(|w|)^kl steps altogether at most 2*c2*c1^l*|w|^(kl) steps
HAMCYCLE is NP Complete
proof: - A Hamiltonian cycle is a witness - HAMPATH ≤P HAMCYCLE as shown by the reduction G → G', where G' is obtained from G by adding one new vertex v joined to all vertices of G. - HAMCYLE ≤P HAMPATH Given a graph G, let v be an arbitrary vertex of G and define G' as follows: - Double the vertex v: introduce v1, v2 such that v1, v2 are joined to the vertices of G to which v was joined to. - Add two new vertices s and t with s joined only to v1 and t joined only to v2
4-COLOR is NP Complete
proof: - a proper 4-coloring is a short witness - 3COL ≤P 4COL with the following reduction: for any graph G define G' by adding a new vertex v to G joined to all vertices of G. As in every proper coloring of G' the vertex v must be colored differently than all other vertices therefore G is 3 colorable if and only if G' is 4-colorable
3-SAT is NP-complete
proof: - in the theorem about CNF we already obtained the four formulas as CNFs - a clause of 4 ORs x1 ∨ x2 ∨ x3 ∨ x4 can be replaced by (x1 ∨ x2 ∨ z1) ∧ (z1 ∨ x3 ∨ x4) - in general x1 ∨ x2 ∨ · · · ∨ xl can be replaced by (x1 ∨x2 ∨z1)∧(z1 ∨x3 ∨z2)∧(z2 ∨x4 ∨z3)∧ · · · ∧(zl−3 ∨xl−1 ∨xl) - a clause of length l is replaced by l − 2 clauses of length 3, so the total length increases by a factor of 3