Docsity

Theory of Computation Notes [COMPLETE], Lecture notes of Theory of Computation

Toggle sidebar
bg1
Theory of Computation
TOC is an extension ofMCS, and as such extends on the topics originally covered in MCS, such
as:
Inductive proofs and definitions (also covered in ICM)
Finite automata
Kleene's Theorem
Non-deterministic finite automata
Grammars
Regular grammars
Context-free grammars
Pushdown automata
Chomsky hierarchy
Level Grammars/Languages Grammar Productions Machines
0Unrestricted/recursively
enumerable α → β [α ∈ (V∪Σ)+, β ∈
(V∪Σ)*] Turing Machine
1Context-sensitive α → β [α, β ∈ (V∪Σ)+, |α| ≤ |β|] Linear-bounded
automaton
2Context-free A → β [A ∈V, β ∈ (V∪Σ)*] Pushdown automaton
3Regular A → a, A → aB, A → Λ [A, B
∈V, a ∈Σ]Finite automaton
We could also consider a level 2.5, which is a deterministic context free grammars.
Context-Sensitive Languages
A grammar is context sensitive if α → β satisfies |α| ≤ |β|, with the possible exception of S → Λ.
If S → Λ is present, then S must not occur in any right-hand side. The length restrictions here
mean that you can generate all strings in a language up to a certain length (derivation trees).
Context-sensitive grammars generate context-sensitive languages, and every context free
language is context sensitive.
Linear Bounded Automata
A linear bounded automata (LBA) is defined like a nondeterministic Turing machine (see next
section), M, except that the initial config for input w has the form (q0,<w>) and the tape head
can only move between < and >.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download Theory of Computation Notes [COMPLETE] and more Lecture notes Theory of Computation in PDF only on Docsity!

Theory of Computation

TOC is an extension of MCS , and as such extends on the topics originally covered in MCS, such as:  Inductive proofs and definitions (also covered in ICM)  Finite automata  Kleene's Theorem  Non-deterministic finite automata  Grammars  Regular grammars  Context-free grammars  Pushdown automata  Chomsky hierarchy Level Grammars/Languages Grammar Productions Machines 0 Unrestricted/recursively enumerable α → β [α ∈ ( V ∪ Σ )+, β ∈ ( V ∪ Σ )] Turing Machine 1 Context-sensitive α → β [α, β ∈ ( V ∪ Σ )+, |α| ≤ |β|] Linear-bounded automaton 2 Context-free A → β [A ∈ V , β ∈ ( V ∪ Σ )] Pushdown automaton 3 Regular A → a, A → aB, A → Λ [A, B ∈ V , a ∈ Σ ] Finite automaton We could also consider a level 2.5, which is a deterministic context free grammars.

Context-Sensitive Languages

A grammar is context sensitive if α → β satisfies |α| ≤ |β|, with the possible exception of S → Λ. If S → Λ is present, then S must not occur in any right-hand side. The length restrictions here mean that you can generate all strings in a language up to a certain length (derivation trees). Context-sensitive grammars generate context-sensitive languages, and every context free language is context sensitive.

Linear Bounded Automata

A linear bounded automata (LBA) is defined like a nondeterministic Turing machine (see next section), M, except that the initial config for input w has the form (q 0 , ) and the tape head can only move between < and >.

An equivalent definition allows inital configurations of the form (q 0 , <wΔ n >), where n = cM|w|, for some constant cM ≥ 0. This allows to have multi-track machines, where cM represents the number of tracks. Theorem: A language L is context sensitive if and only if L is accepted by some LBA. Open research problem: Are deterministic linear bound automata as powerful as non- deterministic LBAs? Turing Machines Turing machines were introduced by Alan Turing in "On Computable Numbers with an Application to the Entscheidungsproblem" (The Entscheidungsproblem is whether or not a procedure of algorithm exists for a general problem). A Turing Machine is an automata with consits of a 5-tuple (Q, Σ, Γ, q 0 , δ)  Q is a finite set of states including ha and hr (the halting accept and reject states)  Σ - the alphabet of input symbols  Γ - the alphabet of tape symbols, including the blank symbol Δ, such that Σ ⊆ Γ - {Δ}  q 0 - the initial state, such that q 0 ∈ Q  δ - the transition function such that δ : (Q - {ha, hr}) × Γ → Q × Γ × {L, R, S} Intuitively, a Turing machine has a potentially infinite set of squares and a head moving on a type when reading character a whilst in state q, δ(q, a) = (r, b, D), which denotes a new state r, a is overwritten with b and the head either moves to the left (D = L), right (D = R), or remains stationary (D = S).

Configurations and Transitions

A configuration is a pair (q, uav) where q ∈ Q, a ∈ Γ and u, v ∈ Γ. This configuration is considered to be the same as (q, uavΔ) - the rightmost blanks can be ignored. A transition (q, uav) ├ (r, xby) describes a single move of a Turing machine, and we can write (q, uav) ├ (r, xby) for a sequence of transitions. This can be represented diagramatically as: Convention also dictates that if there is no transition for what you want to do, a transition to hr is implied.

  1. at each point in the computation, the contents of tape 1 has the form Δ#w 1 #w 2 #...#w n v, where n ≥ 0, w 1 ∈ L, # ∈ (Γ - Σ) and v ∈ Σ*
  2. Every w ∈ L will eventually appear as one of the strings w on tape 1. Theorem: A language L is recursively enumerable if and only if L is enumerated by some multitape Turing machine. Computability

Decidability

A language L is decidable (or recursive) if it is accepted by some Turing machine M, that on every inputs eventually reaches a halting state (ha or hr), i.e., it does not get stuck and loop. We say that M decides L. To decide whether w ∈ Σ* is in L, we run M on w until M reaches a halting configuration, then w ∈ L if and only if M is in state ha. Theorem:

  1. Every context sensitive language is decidable - however as the converse is not true, we can consider decidable languages as level 0.5 on the Chomsky hierarchy.
  2. If a language L is decidable, then the complement L = Σ* - L is also decidable
  3. If both L and L are recursively enumerable, then L is decidable Proof of Theorem 2 Let M be a Turing machine that accepts L and reaches a halting config on every input (is decidable). Modify M to machine M as follows.
  4. Swap ha and hr by defining ha = hr and hr = ha.
  5. Put a new symbol at the start of the string (to detect the crash condition) i. Shift existing string one position to the right ii. Put a special symbol (e.g., #) at the first square iii. Move tape head to the second square (the old first square) iv. Continue as for a normal TM v. δ is extended as δ(q, #) = (ha, #, S) ∀ q ∈ Q. Therefore, L(M) = L(M), and L is decidable, as neither of the modifications described above can introduce looping. Proof of Theorem 3

Intuitively, L(M) = L and L(M) = L. For a string w, w ∈ L ∨ w ∈ L - so at least one of those machines will accept the string. If the two machines are run in parallel and terminate as soon as one reaches an accept state, then it is impossible to get into a loop. This can be accomplished on a two-tape machine. The string is copied to tape 2 in the first instance, and then M is run on tape 1 and M is run on tape 2. We can express this formally as: Let M = (Q, Σ, Γ, q 0 , δ) and M = (Q, Σ, Γ, q 0 , δ) be Turing machines that accept L and L respectively. Without a loss of generality, we can assume that M and M cannot crash at the left end of the tape. We can construct a two-tape Turing machine M′ that decides L by copying its input to tape 2 and simulating M and M in parallel.  Let Q′ ⊇ Q × Q (we need additional states for initial copying, which are Q′

  • (Q × Q)).  Let δ′((q, q), (x, x)) = ((r, r), (y, y), (D, D)), where δ(q, x) = (r, y, D) and δ(q, x) = (r, y, D). Also, we need to define:
  1. δ′((ha, q), (x, x)) = (ha′, (x, x), (S, S)) ∀ q ∈ Q, x ∈ Γ, x ∈ Γ
  2. δ′((hr, q), (x, x)) = (hr′, (x, x), (S, S)) ∀ q ∈ Q, x ∈ Γ, x ∈ Γ
  3. δ′((q, ha), (x, x)) = (hr′, (x, x), (S, S)) ∀ q ∈ Q, x ∈ Γ, x ∈ Γ
  4. δ′((q, hr), (x, x)) = (ha′, (x, x), (S, S)) ∀ q ∈ Q, x ∈ Γ, x ∈ Γ To show that M′ decides L, we can consider two cases:
  5. w ∈ L. Then, on input w, M will reach ha. M will either reach state hr, or it will loop. In both cases, M′ reaches state ha.
  6. w ∉ L, or w ∈ L and M on input w will reach accept state ha. M will either terminate in state hr, or will loop. In both cases, M′ reaches state hr′ Thus, L(M′) = L and M′ reaches a halting configuration on every input. We can transform M′ into a one-tape Turing machine M″ that accepts L and halts on the same inputs as M′. Thus, L is decidable.

Encoding Turing Machines

For whatever Turing machine we encounter, we want to encode the Turing machine into a string that represents the Turing machine. If we let Q = {q 1 , q 2 , ...} and S = {a 1 , a 2 , ...}, such that for every Turing machine (Q, Σ, Γ, q, δ), Q ⊆ Q and Γ ⊆ S , then we can define:  s(Δ) = 0  s(a i ) = 0 i^ + 1, for i ≥ 1  s(ha) = 0  s(hr) = 00  s(q i ) = 0 i^ + 2  s(S) = 0  s(L) = 00

This is done by contradiction (indirect proof), or reducio ad absurdum and relies on the principle of tertium non dafur. If we suppose that NSA is recursively enumerable, then there is a Turing machine that accepts NSA (for Turing machine M, L(M) = NSA). If we consider the code e(M), then we have two cases:

  1. e(M) ∈ L(M). Then, by assumption, e(M) ∈ NSA. But then, by definition of NSA, e(M) ∉ L(M). This is obviously a contradiction.
  2. e(M) ∉ L(M). Then, by definition of NSA, e(M) ∈ NSA, hence by assumption e(M) ∈ L(M). This is again a contradiction. It therefore follows that our assumption must be wrong. That is, NSA is not recursively enumerable. The corollary of this is that SA is not decidable, and the proof of this is by definition of a decidable languages - "If a language is decidable, L is also decidable". As NSA is not r.e., it is not decidable, therefore SA is not decidable. Proof of Theorem 1 The corollary of the proof from theorem 2 is that SA is not decidable, and the proof of this is by definition of a decidable languages - "If a language is decidable, L is also decidable". As NSA is not r.e., it is not decidable, therefore SA is not decidable. We also need to consider the theorem that SA is recursively enumerable. To prove this, we need to consider a Turing machine TSA accepts SA by working as follows: TSA first checks that its input w is the code of some Turing machine M (i.e., w = e(M)) and then Σ(M) includes {0, 1}. if this is not the case, TSA rejects w. Otherwise, TSA computes e(w) = e(e(M)) and runs U (the universal Turing machine) on e(M)e(w). It follows that TSA accepts w if and only if M accepts w. Hence L(TSA) = SA.

The Universal Turing Machine

The universal Turing machine is basically a Turing machine interpreter. It takes inputs of the form e(M)e(w), where M is a Turing machine and w is a string over Σ(M)*. The universal Turing machine will run machine M on input w, and accepts e(M)e(w) if w ∈ L(M) (M accepts w), rejects e(M)e(w) if w ∉ L(M) (M rejects w) and e(M)e(w) loops when M loops on w.

Most Languages are not Recursively Enumerable

A set S is countably infinite is there exists a bijective function N → S and is countable if it is countably infinite or finite. e.g., countable sets, N , Z , N × N and uncountable sets: R , 2 N Cantor said that if you plot a matrix of pairs of numbers, and move diagonally you can represent any number with a bijective function, so pairs of numbers are countably infinite, as long as the base number is.

Lemmas:

  1. If S 0 , S 1 , ... are countable, then S = ∪∞ i = 0S i is countable
  2. If S is an infinite set, then its power set 2S^ is uncountable
  3. If S is uncountable, and T is a countable subset of S, then S - T is uncountable Proof of lemma 2: Let S be countably infinite, as otherwise 2S^ is obviously uncountable (there are uncountably many singleton subsets). We proceed by contradiction. Suppose 2S^ is countably infinite, then there is an infinite listing S 0 , S 1 , ... of the elements of 2S^ (i.e., of all the subsets of S). Since S is countably infinite, there is a bijection ƒ: N → S. We can define some subset of S as S′ by S′ = {ƒ(i) | i ≥ 0 ^ ƒ(i) ∉ Si}. Since S′ ⊆ S, there is some n such that S′ = Sn. We can consider two cases:
  4. ƒ(n) ∈ Sn, then ƒ(n) ∉ S′ = Sn, which is a contradiction
  5. ƒ(n) ∉ Sn, then ƒ(n) ∈ S′ = Sn, which is again a contradiction. Theorem: For every nonempty alphabet Σ, there are uncountably many languages over Σ that are not recursively enumerable. Proof: Every recursively enumerable language is accepted by some Turing machine. Since Turing machines can be encoded as strings over {0, 1} and {0, 1}* is countably infinite, the set of all Turing machines over Σ is countable as well (every subset of a countable set is countable). Hence, the set of all recusively enumerable languages over Σ is countable too. But, 2Σ, the set of all languages over Σ is uncountable by lemma 2, thus by lemma 3: 2Σ^ - {L ⊆ Σ* | L is r.e.} is uncountable as well.

Turing-computable Functions

A Turing machine M = (Q, Σ, Γ, q 0 , δ) computes the partial function ƒm(x) = {y if (q 0 , Δx) ├* (ha, Δy), undefined otherwise} - which says that ƒm(x) = the resulting string on the tape if it halts, otherwise it is undefined. We can generally change this unary function into a k-ary function by saying that M computes for every k ≥ 1. The k-ary partial function ƒm : (Σ)k^ → Σ is defined by ƒm(x 1 , ..., xk) = {y, if (q 0 , Δx 1 Δs 2 ...Δxk) ├* (ha, Δy), undefined otherwise}.

Decision Problems

A decision problem is a set of questions, each of which has the answer yes or no. We can say that these questions are instances of the decision problem; depending on their answers, they are either 'yes'-instances or 'no'-instances. To solve decision problems by Turing machines, instances are encoded as strings. A decision problem P is decidable, or solvable, if its language of encoded 'yes'-instances is decidable. Otherwise, P is undecidable or unsolvable. A decision problem P is semi-decidable if its language of encoded 'yes'-instances is recursively enumerable. The Membership Problem for Regular Languages Input: A regular expression r and w ∈ Σ* Question: Is w ∈ L( r ) Problem: {( r , w ) | r is a regular expression, w ∈ Σ} 'Yes'-instances: {( r , w ) | r is a regular expression and w ∈ L( r ) Encoded 'Yes'-instances: {encode( r )encode( w ) | r is a regular expression and w ∈ L( r )} This problem is decidable, as it can be turned into an automata. The Self-Accepting Problem Input: A Turing machine M Question: Does M accept e(M)? Problem: {M | M is a Turing machine} 'Yes'-instances: {M | M is a Turing machine and e(M) ∈ L(M)} Encoded 'Yes'-instances: {e(M) | M is a Turing machine and e(M) ∈ L(M)} The encoded 'Yes'-instances is the language SA, which is recursively enumerable (L(SA) can be enumerated), but not decidable, therefore this problem is semi-decidable. The Membership Problem for Recursively Enumerable Languages Input: A Turing machine M and w ∈ Σ Question: Is w ∈ L(M)? Problem: {(M, w ) | M is a Turing machine and w ∈ Σ*} 'Yes'-instances: {(M, w ) | M is a Turing machine and w ∈ L(M)} Encoded 'Yes'-instances: {e(M)e( w ) | M is a Turing machine and w ∈ L(M)} The encoded 'Yes'-instances is MP, the membership problem.

Theorem: The membership problem for recursively enumerable languages is undecidable, but semi-decidable. Proof: We reduce the self accepting problem (SA) to the membership problem for recursively enumerable languages (MP). That is, we show that if MP is decidable, then SA is also decidable. Since SA was proved to be undecidable, MP must be undecidable too. Suppose that MP is decidable. Then L(MP) is decidable, i.e., there is a Turing machine T that terminates for all inputs and accepts MP. We can construct a Turing machine T′ that decides SA as follows: T′ transforms its input e(M) into e(M)e(e(M)) (where e(M) = w and is placed in e(M)e( w )). T then starts on this string. This can be represented diagramatically: T′ terminates for all inputs because T always terminates. Moreover, T′ accepts e(M) if and only if T accepts e(M)e(e(M)), that is, T′ accepts e(M) if and only if e(M) ∈ L(M). Hence, T′ decides SA, therefore, if we can solve MP, we can solve SA. But, as SA was proved to be undecidable, this is a contradiction. Hence, our assumption that MP is decidable is false, i.e., MP is undecidable. We can summarise this as: reduction of SA to MP - "If we can solve MP, we can also solve SA" ⇔ "SA is not more difficult than MP" ⇔ "MP is at least as difficult as SA"

Reducing Languages and Decision Problems

Let L 1 , L 2 ⊆ Σ* be languages. L 1 is reducible to L 2 if there is a computable total function (i.e., there exists a Turing machine) ƒ : Σ* → Σ* such that for all x ∈ Σ*, x ∈ L 1 if and only if ƒ( x ) ∈ L 2. Let P 1 , P 2 be decision problems and e(P 1 ), e(P 2 ) be the associated languages of the encoded 'Yes'- instances. We say that P 1 is reducible to P 2 if e(P 1 ) is reducible to e(P 2 ). Theorem 1: Let L 1 , L 2 be languages such that L 1 is reducible to L 2. If L 2 is decidable, so is L 1.

Note that if Thalt outputs 'yes' then U will terminate on e(M)e(w) with either Yes or No. Hence, T′ solves MP. Since MP is undecidable, our assumption that HP is decidable must be false. Accept# Theorem: The following problem (Accept#) is undecidable. Input: A Turing machine M such that # ∈ Σ Question: Is # ∈ L(M) Proof: We reduce MP to Accept#. Suppose Accept# is decidable, then there is a Turing machine that halts on all inputs, accepting input e(M) if and only if # ∈ L(M). We can construct a Turing machine T′ as follows: Where C is a Turing machine that transforms e(M)e( w ) into the output e(Mw), where Mw is a Turing machine that ignores its input and runs M on input w. Now, T′ solves MP. We can consider two cases:

Case 1: w ∈ L(M). Then, by construction of Mw, Mw accepts every input and hence # ∈ L(Mw), thus T# accepts e(Mw) and T′ accepts e(M)e(w). Case 2: w ∉ L(M). Then, by construction of Mw, Mw accepts no input and hence # ∉ L(Mw), this T# rejects e(Mw) and T′ rejects e(M)e(w). Since MP is undecidable, Accept# must be undecidable as well. More Undecidable Problems These can all be proved by reduction.  Input: A Turing machine M. Question: Does M accept no input ("Is L(M) = ∅")?  Input: Two Turing machines M 1 and M 2. Question: Do M 1 and M 2 accept the same inputs ("Is L(M 1 ) = L(M 2 )")?  Input: A Turing machine M Question: Is L(M) finite?  Input: A Turing machine M Question: Is L(M) regular?  Input: A Turing machine M Question: Is L(M) decidable?

Rice's Theorem (1953)

Let C be a proper, non-empty subset of all recursively enumerable languages. Then, the following problem is undecidable: Input: A Turing machine M Question: Is L(M) ∈ C? In other words, every nontrivial property of recursively enumerable languages is undecidable. A property is nontrivial if it is satisfied by a proper, nonempty subset C of the class of all recursively enumerable languages. e.g., for the problem "Is L(M) finite?" C = {L = Σ* | L is finite} Beware, Rice's theorem is about the languages accepted by Turing machines, not about the machines themselves.

Undecidable Problems About Context Free Grammars

Input: A context free grammar G Question: Is L(G) = Σ* Input: Two context free grammars G 1 and G 2 Question: Is L(G 1 ) = L(G 2 )

Growth Rate of Functions

Given a function f , g : N → N , f is of order g , written as f = Ο( g ), or f ∈ Ο( g ), if there is c , n 0 such that ƒ( n ) ≤ c. g ( n ) ∀ n ≥ n 0. Theorem, for a , b , r ∈ N with a , b > 1

  1. log a ( n ) = Ο( n ) but n ≠ Ο(log a ( n ))
  2. nr^ = Ο( bn ) but bn^ ≠ Ο( nr )
  3. bn^ = Ο( n !) but n! ≠ Ο( bn ) Using this 'Big-O' notation, we can create a hierarchy of complexity: Name Ο Constant 1 Logarithmic log n Linear n Log-linear n log n Quadratic n^2 Cubic n^3 Polynomial n p Exponential b n Factorial ∞ The table below shows examples of different growth rates for different values of n. log 2 ( n ) n n^2 n^3 2 n^ n****! 2 5 25 125 32 120 3 10 100 1000 1024 3628800 4 20 400 8000 1048576 2.4 × 10^14 5 50 2500 125000 1.1 × 10^15 3.0 × 10^64 6 100 10000 1000000 1.2 × 10^30 > 10^157

Properties of Time Complexity

Theorem - multiple tapes vs. one tape: For every k -tape Turing machine M there is Turing machine M′ such that L(M′) = L(M) and τM′ = Ο(τM^2 ). Theorem - there are aribtrarily complex languages. Let ƒ be a total computable function. Then there is a decidable language L such that for every Turing machine M accepting L, τM is not bounded by ƒ.

Theorem - there need not exist a best Turing machine. There is a decidable language L such that for every Turing machine M accepting L, there is a Turing machine M′ such that L(M′) = L(M) and τM′ = Ο(log(τM)).

The Classes P and PSpace

A language L is recognisable in polynomial time if there is a deterministic Turing machine M accepting L such that τM = Ο( nr ) for some r ∈ N. The class of all languages recognisable in polynomial time is denoted by P. A language L is recognisable in polynomial space if there is a deterministic Turing machine M accepting L such that sM = Ο( nr ) for some r ∈ N. The class of all languages recognisable in polynomial space is denoted by PSpace. A decision problem is said to be in P resp. PSpace if its language of encoded 'yes'-instances is in P resp. PSpace.

The Classes NP and NPSpace

A language L is recognisable in nondeterministic polynomial time if there is a nondeterministic Turing machine N accepting L such that ΤN = Ο( nr ), for some r ∈ N. The class of all languages recognisable in nondeterministic polynomial time is denoted by NP. A language L is recognisable in nondeterministic polynomial space if there is a nondeterministic Turing machine N accepting L such that sN = Ο( nr ) for some r ∈ N. The class of all languages recognisable in nondeterministic polynomial space is denoted by NPSpace. A decision problem is said to be in NP resp. NPSpace if its language of encoded 'yes'-instances is in NP resp. NPSpace.

Example: A problem in P

A graph G = (V, E) consists of a finite set, V, of vertices (or nodes) and a finite set, E, of edges such that each edge is an unordered pair of nodes. A path is a sequence of nodes connected by edges. A complete graph (or clique) is a graph where each two nodes are connected by an edge. The path problem has input of a graph G and nodes s and t in G and the question does G have a path from s to t? The theorem is that the path problem is in P, and the proof for this is the following algorithm which solves the path problem: On input (G, s , t ) where G = (V, E) is a graph with nodes s and t :

  1. Mark node s
  2. Repeat until no additional nodes are marked

(Only P ≠ ExpTime is known, but it is not known whether the other subsets above are proper or not) Inclusions P ⊆ NP and PSpace ⊆ NPSpace, as every deterministic Turing machine can be represented by a nondeterministic Turing machine. Inclusions P ⊆ PSpace and NP ⊆ NPSpace, as every Turing machine (deterministic or nondeterministic) satisfies sM( n ) ≤ τM( n ) + 1, as we can not visit more squares than we can do transitions. Hence τM = Ο( nr ) implies sM = Ο( nr ). Inclusions NPSpace ⊆ PSpace. This can be proved using Savitch's Theorem (which is nontrivial), which states that for every nondeterministic Turing machine N there is a Turing machine M such that L(M) = L(N) and sM = sN^2 , and a polynomial squared is still a polynomial. Inclusions PSpace ⊆ ExpTime. For an input of length n each configuration of the Turing machine M can be written as follows: (q, a 0 ...a i ...asM( n )). For each part, there are |Q| possible states, sM( n ) possible tape head positons and |Γ|sM( n )^ possible tape content configurations. Hence, the maximum number of configurations is |Q| × sm( n ) × |Γ|sM( n )^ = Ο(Γ|sM. A Turing machine computation that halts does not repeat any configurations. Hence τM = Ο( k sM for some k , and it follows our inclusion, hence PSpace ⊆ ExpTime (for k ≤ 2 m^ we have knr^ ≤ (2 m ) nr^ = 2 mnr^ = 2 nm^ +^ r ).

Polynomial-time Reductions

A function ƒ is polynomial-time computable if there is a Turing machine M with τM = Ο( nr ) that computes ƒ. Let L 1 , L 2 ⊆ Σ* be languages. L 1 is polynomial-time reducible to L 2 if there is a polynomial-time computable total function ƒ : Σ* → Σ* such that for all x ∈ Σ, x ∈ L 1 if and only if ƒ( x ) ∈ L 2. Theorem: Let L 1 be polynomial-time reducible to L 2. Then: L 2 ∈ P implies L 1 ∈ P; L 2 ∈ NP implies L 1 ∈ NP. Proof Since L 2 ∈ P there is a Turing machine M 2 with polynomial time complexity that decides L 2. Moreover, since L 1 is polynomial-time reducible to L 2 , there is a Turing machine M with polynomial-time complexity such that ƒM : Σ → Σ* satisfies for all x ∈ Σ*, x ∈ L 1 if and only if ƒM( x ) ∈ L 2. Let M 1 be the composite Turing machine MM 2 which first runs M and then runs M 2 on the output of M, then L(M 1 ) = L 1. Since |ƒM( x )| can not exceed max(τM(| x |), |x|), the number of transitions of M 1 is bounded by the sum of the following estimates of the seperate computations: (a) τM1( n ) ≤ τM( n ) + τM2(max(τM( n ), n )) Let τM = Ο( nr ), then there are constants c and n 0 with τM( n ) ≤ c. nr^ ∀ n ≥ n 0. Let τM2 = Ο( nt ), then there are constants c 2 and n 2 with τM2( n ) ≤ c 2. nt^ ∀ n ≥ n 2. Hence τM2( n ) ≤ c 2. nt^ + d 2 , ∀ n ≥ 0, where d 2 = {τM2( k ) | k < n 2 }. It follows τM2(τM( n )) ≤ c 2. (τM( n )) t^ + d 2 , for all n ≥ 0, and hence τM2(τM( n )) ≤ c 2. ( c. nr ) t^ + d 2 , for all n ≥ 0 So, τM2(τM( n )) ≤ c 2 c t^. nrt^ + d 2 ∀ n ≥ 0. Thus, by formula (a) above, τM1 = Ο( nrt ), hence L 1 ∈ P ( r and t are constants, therefore nrt^ ∈ P)

Hardness

If L 1 is polynomial-time reducible to L 2 , then L 1 is no harder than L 2. Equivalently, L 2 is at least as hard as L 1. A language L is NP-hard if every language in NP is polynomial-time reducible to L; A NP-hard language is at least as hard to decide as every language in NP. Equivalently, no language in NP is harder to decide than any NP-hard language.