DM17 Beregnelighed Jacob Aae Mikkelsen January 12, 2007
CONTENTS Contents 1 Introduction 2 1.1 Operations with languages...................... 2 2 Finite Automata 3 2.1 Regular expressions/languages.................... 3 2.2 DFA - Deterministic Finite Automaton............... 3 2.3 NDFA - Nondeterministic Finite Automaton............ 3 2.4 Pumping Lemma for regular languages............... 4 2.5 Myhill & Nerode........................... 4 3 Context-free Languages 6 3.1 Context Free Grammar........................ 6 3.2 Chomsky Normal Form........................ 6 3.3 Pushdown Automata......................... 7 3.4 Pumping Lemma for context free languages............ 7 4 Turing Machines 9 4.1 Turing Machines........................... 9 4.2 Relationship among classes og languages.............. 10 4.3 Grammars............................... 10 5 Undecidability 12 5.1 The Halting Problem......................... 12 5.2 Unsolvale problems about grammars................ 12 5.3 Rice s Theorem............................ 13 Kokken January 12, 2007 1
1. Introduction 1 Introduction 1.1 Operations with languages Complement L := Σ \ L = {w Σ w / L} Union A B = {x x A or x B} Intersection A B = {x x A and x B} Concatenation A B = {xy x A and y B} Kleene-star A = {x 1 x 2...Xk k 0 and each x i A} Definition: Countable A set A is countable if either it is finite or it has the same size as N R is uncountable. Kokken January 12, 2007 2
2. Finite Automata 2 Finite Automata 2.1 Regular expressions/languages Remark: The expression ǫ represents the language containing a single string - namely, the empty string - whereas represents the language that doesn t contain any strings Definition: Regular Language A language L for which there is a regular expression x so that L(x) = L. Or: A language is called a regular language if some finite automaton recognizes it. The class of regular languages is closed under the union operation. In other words, if A 1 and A 2 are regular languages, so is A 1 A 1 The class of regular languages is closed under the concatenation operation. In other words, if A 1 and A 2 are regular languages, so is A 1 A 1 The class of regular languages is closed under the Kleene-star operation. The class of regular languages are closed under the complementation and intersection operation. 2.2 DFA - Deterministic Finite Automaton A DFA M consists of 5 elements: Σ Finite alphabet K Finite set of states s K Starting state F K Set of final states δ : K Σ K Transition function of M 2.3 NDFA - Nondeterministic Finite Automaton A DFA M has 5 elements, where Σ, K, s, F as a DFA, and: is a subset of K (Σ {e}) K) Kokken January 12, 2007 3
2.4 Pumping Lemma for regular languages Every nondeterministic finite automaton has an equivalent deterministic finite automaton 2.4 Pumping Lemma for regular languages The Pumping Lemma for regular languages If A is a regular language, then there is a number p (the pumping length) where, if s is any string in A of length at least p, then s may be divided into three pieces, s = xyz, satisfying the following conditions: 1. for each i 0 xy i z A 2. y > 0 3. xy p Remark: If L(M) is finite, it only contains words of length < n (n = number of states of M) 2.5 Myhill & Nerode Definition: Equivalent with respect to L Let L Σ be a language, and let x, y Σ. We say that x and y are equivalent with respect to L, denoted x L y, if for all z Σ, the following is true: xz L if and only if yz L. Notice L is an equivalence relation. Definition: Equivalent with respect to M Let M = (K, Σ, δ, s, F) be a deterministic finite automaton. We say that two strings x, y Σ are equivalent with respect to M, denoted x M y, if, intuitively, they both drive M from s to the same state. Formally, x M y if there is a state q such that (s, x) M (q, e) and (s, y) M (q, e).again, x M y is an equivalence relation. Its equivalence classes can be reachable from s and therefore have at least one string in the corresponding equivalence class. We denote the equivalence class corresponding to state q of M as E q For any deterministic finite automaton M = (K, Σ, δ, s, F) and any strings x, y Σ, if x M y, then L(M) The Myhill-Nerode Theorem Let L Σ be a regular language. Then there is a deterministic finite automaton Kokken January 12, 2007 4
2.5 Myhill & Nerode with precisely as many states as there are equivalence classes in L that accepts L. Corollary: A language L is regular if and only if L has finitely many equivalence classes. Kokken January 12, 2007 5
3. Context-free Languages 3 Context-free Languages Grammars: Methodology to generate words in a language 3.1 Context Free Grammar Definition: Context free grammar G is context-free iff R V Σ V (i.e. we replace all the time one non-terminal) a language L Σ is context-free iff there is a context free grammar G, s.t. L(G) = L G is a regular grammer (right-linear grammer) if R V Σ Σ (V Σ) Σ (i.e. rules have the form A wb, w Σ ora w, w Σ ) Remark: The generation process is not deterministic, it is unclear which rule to apply next if there are several possible ones. (A deterministic version might be less powerfull). 3.2 Chomsky Normal Form Definition: Chomsky normal form A context-free grammar is in Chomsky normal form if every rule is on the form A BC A a where a is any is any terminal and A, B and C are any variables - except that B and C may not be the start variable. In adition we permit the rule S ǫ, where S is the start variable. Any context free language is generated by a context-free grammar in Chomsky normal form. The context-free languages are closed under union, concatenation, and Kleene star. Corollary: Kokken January 12, 2007 6
3.3 Pushdown Automata Given 2 context free languages L 1 and L 2, their intersection is not necessarily again context free. (Context free languages are not closed under intersection). Given L Σ context free, then L := Σ \ L is not necessarily cfr The intersection of a context free grammar with a regular language is again context free 3.3 Pushdown Automata Definition: Push-down automaton A push-down automaton PDA is a 6-tuple (Q, Σ, Γ, δ, q 0, F) Q is the set of states Σ is the finite input alphabet Γ is the stack alphabet δ : Q Σ ǫ Γ ǫ P(Q Γ ǫ ) Transition function q o Q Starting state F Q is the set of accept states A language is context free if and only if some pushdown automaton recognizes it. Corollary: Every regular language is context free 3.4 Pumping Lemma for context free languages Pumping Lemma for context free languages If A is a context free language, then there is a number p (the punping length) where, if s is any string in A of length at least p, then s may be divided into five pieces, s = uvxyz, satisfying the following conditions: 1. for each i 0 uv i xy i z A 2. vy > 0 3. vxy p Kokken January 12, 2007 7
3.4 Pumping Lemma for context free languages Remark: Usually the pumping lemma is used to prove a language NOT to be context free. In these applications we therefore do not need to have to construct CNF The context-free languages are not closed under intersection or complementation. Kokken January 12, 2007 8
4. Turing Machines 4 Turing Machines 4.1 Turing Machines Definition: Turing Machine A turing machine is a 5-tuple M = (K, Σ, δ, s, F) K Finite set of states Σ Finite alphabet, w.o.l.g. Σ contains two symbols (left-end) and (blank), and L, R, N / Σ s K Starting state F K Set of final states δ : (K F) Σ K Σ {L, R, N} Transition function of M If M reaches a q F it stops. If M stops, it is said to accept w L(M) = {w M accepts w} is the language accepted by M If F consists of two distinguished halting states {y, n}. The machine can halt in an accepting state {y} or an rejecting state {n}. We say that M accepts an input w if it yields an accepting configuration, and rejects if it yields an rejecting configuration. Definition: Decides A TM M decides a language L Σ 0 if for any string w Σ 0 the following is true: If w L then M acccepts w, and if w / L then M rejects w Definition: Recursive language We call a language L recursive if there is a Turing machine that decides it. Definition: Turing Decidable A language is called Turing decidable or simply decidable if some Turing Machine decides it. Also called recursive language Definition: Semidecides A TM M semidecides a language L Σ 0 if for any string w Σ 0 the following is true: w L if and only if M halts on input w Kokken January 12, 2007 9
4.2 Relationship among classes og languages Definition: Recursively enumerable A language L is recursively enumerable if and only if there is a Turing machine M that semidecides L. Definition: Turing Acceptable A language L is Turing acceptable iff: TMM so that L(M) = L Definition: Turing Computable A function f is Turing computable iff: TMM so that f M f Definition: Turing Recognizable A language is called Turing recognizable if some Turing Machine recognizes it. Also called recursively enumerable language Every context free language is decidable Definition: co-turing recognizable A language is co-turing recognizable if it is the complement of a Turing-recognizable language A language is decidable iff it is Turing recognizable and co-turing recognizable. If a language is recursive, then it is recursively enumerable. If L is a recursive language, then its complement L is also. 4.2 Relationship among classes og languages The relationship among classes of languages Turing-recognizable decidable context-free regular 4.3 Grammars A language is generated by a grammar if and only if it is recursively enumerable. Kokken January 12, 2007 10
4.3 Grammars Kokken January 12, 2007 11
5. Undecidability 5 Undecidability 5.1 The Halting Problem The language H is not recursive; therefore, the class of recursive languages is a strict subset of the class of recursively enuerable languages. The class of recursively enuerable languages is not closed under complement. Definition: Reduction from L 1 to L 2 Let L 1 and L 2 Σ be languages. A Reduction from L 1 to L 2 is a recursive function τ : Σ Σ such that x L 1 if and only if τ(x) L 2. If L 1 is not recursive, and there is a reduction from L 1 to L 2, then L 2 is also not recursive. The following problems about Turing machines are undecidable: 1. Given a Turing Machine M and an input string w, does M halt on input w? 2. Given a Turing Machine M, does M halt on the empty tape. 3. Given a Turing Machine M, is there any string at all on which M halts? 4. Given two Turing machines M 1 and M 2, do they halt on the same input strings? 5. Given a Turing machine M, is the language that M semidecides regular? Is it context free? Is it recursive? 6. Furthermore, there is a certain fixed machine M, for which the following problem is undecidable: Given w, does M halt on W? 5.2 Unsolvale problems about grammars The following problems about Grammars are undecidable: 1. For a given grammar G and a string w, to determine whether w L(G) 2. For a given grammar G, to determine whether ǫ L(G) Kokken January 12, 2007 12
5.3 Rice s Theorem 3. For two given grammars G 1 and G 2, to determine whether L(G 1 ) = L(G 2 ) 4. For an arbitrary grammar G, to determine whether L(G) = 5. Furthermore, there is a certain fixed grammar G 0, such that it is undecidable to determine whether any given string w is in L(G 0 ) Each of the following problems is undecidable: 1. Given context free grammar G is L(G) = Σ 2. Given two context free grammars G 1 and G 2, is L(G 1 ) = L(G 2 ) 3. Given two pushdown automata M 1 and M 2, do they accept precisely the same language 4. Given a pushdown automaton M, find an equivalent pushdown automaton with as few states as possible. A language is recursive if and only if both it and its complement are recursively enumerable. 5.3 Rice s Theorem Rice s Theorem Suppose that C is a proper, nonempty subset of the class of alll recursively enumerable languages. Then the following prolem is undecidable: Given a Turing machine M, is L(M) C Kokken January 12, 2007 13