Download presentation
Presentation is loading. Please wait.
Published byMitchell Jordan Modified over 8 years ago
1
Automata & Formal Languages Mostafa M. Aref l Text Book: “An Introduction to Formal Languages & Automata” by Peter Linz, Jones & Bartlett Publishers, Inc. January 2001; ISBN: 0763714224 “Theory of Computation an Introduction" by James L. Hein, Jones & Bartlett Publishers 1996; ISBN: 0-86720-497-4.
2
Chapter 1: Introduction l Why study theory? l Theory provides concepts and principles l The discussed ideas have immediate & important applications: digital design, programming languages & compilers l The subject matter is fun l Automaton is a construct that possesses all the indispensable feature of a digital computer l A formal language is an abstract of a programming language l Algorithm 2
3
Mathematical Background l Set: union, intersection, difference, complementation, universal set, empty (null) set, DeMorgan’s laws, subset, proper subset, disjoint, l power set 2 S is the set of all subsets of set S | 2 S | = 2 |S| l Functions and relations f: S 1 S 2 domain, range, total function, partial function, relation, equivalence l Graph and trees l Proof techniques –Proof by induction l Basis step l Induction assumption l Induction step –Proof by contradiction l Homework: page 12-14: 1, 7, 22, 29 3
4
Noam Chomsky l http://www.chomsky.info/ l Avram Noam Chomsky is an American linguist, philosopher, [2][3][4] cognitive scientist, political activist, author, and lecturer. He is an Institute Professor and professor emeritus of linguistics at the Massachusetts Institute of Technology. [5] Chomsky is well known in the academic and scientific community as one of the fathers of modern linguistics. [6][7][8] Since the 1960s, he has become known more widely as a political dissident, an anarchist, [9] and a libertarian socialist intellectual. [2][3][4] cognitive scientistpolitical activist Institute Professoremerituslinguistics Massachusetts Institute of Technology [5]fatherslinguistics [6][7][8]political dissidentanarchist [9]libertarian socialist l In the 1950s, Chomsky began developing his theory of generative grammar, which has undergone numerous revisions and has had a profound influence on linguistics. His approach to the study of language emphasizes "an innate set of linguistic principles shared by all humans" known as universal grammar, "the initial state of the language learner," and discovering an "account for linguistic variation via the most general possible mechanisms." [10] He also established the Chomsky hierarchy, a classification of formal languages in terms of their generative power. In 1959, Chomsky published a widely influential review of B. F. Skinner's theoretical book Verbal Behavior, which was the first attempt by a behaviorist to provide a functional, operant analysis of language. Chomsky used this review to broadly and aggressively challenge the behaviorist approaches to studies of behavior dominant at the time, and contributed to the cognitive revolution in psychology. His naturalistic [11] approach to the study of language has influenced the philosophy of language and mind. [10]generative grammarlinguisticsuniversal grammar [10]Chomsky hierarchy formal languagesB. F. SkinnerVerbal Behaviorbehavioristoperantbehavioristcognitive revolution [11] philosophy of languagemind [10] 4
5
The Chomsky Hierarchy Lre LcsGcf LcfGreg Lregfa pda TM 5
6
6 Three Basic Concepts l Language: A language is a subset of * Examples: = {a, b }, * = {, a, b, aa, ab, ba, bb, aaa, bbb, …} + = * - { } L 1 = { a, aa, bbb} finite L 2 = {a n b n : n>= 0}infinite L = * - L L R = {w R : w L} L 1 L 2 = {xy: x L 1, y L 2 } L o = { }L 1 = L L * = L o L 1 L 2 … L + = L 1 L 2 L 3 … if L = {a n b n : n>= 0} L 2 = {a n b n a m b m : n>= 0, m>= 0} L R = {b n a n : n>= 0}
7
Grammars –A grammar G is defined as quadruple, G = (V, T, S, P), where Vis a finite set of symbols, called variables. Tis a finite set of symbols, called terminal symbols. Sis a special symbol called the start symbol. Pis finite set of productions. –Example 1: Consider the grammar G = ({S}, {a,b}, S, P) With P given by S aSb, S Then S aSb aaSbb aaaSbbb We can write S * aabb G defines L(G) = {a n b n : n>= 0} –Example 2: Find a grammar that generates L = {a n b n+1 :n>= 0} S Ab, A aAb, A –Example 3: = {a, b}, n a (w) = n b (w) the grammar G with productions S SS | aSb | bSa | generates the language L = {w: n a (w) = n b (w)} –Example 4: G 1 = ({A, S}, {a, b}, S, P 1 ) P1: S aAb |, A aAb | G1 is equivalent to G in example 1 Two grammars are equivalent if they generate the same language. 7
8
8Automata Input file Control unit Storage Output – An abstract model of a digital computer – Operate in a discrete time frame by the next-step or transition function – Configuration will be used to refer to a particular state of the control unit – The transition from one configuration to the next is called a move – Deterministic and nondeterministic automata – Accepter is an automaton whose output is limited to “yes” or “no” – A transducer is a more general automaton that capable of producing strings or symbols as output l Homework: page 26-28: 10, 13-16, 20-21
9
Chapter 2: Finite Automata l Deterministic Finite Automata – A deterministic finite accepter or dfa is defined as quintuple M = (Q, , , q 0, F), where Q is a finite set of internal states. is a finite set of symbols, called input alphabet. : Q X Q is a total function called the transition function. q 0 Q is the initial state. F Q is a set of final states. –Example 1: M =({q 0, q 1, q 2 }, {0,1}, , q 0, {q 1 }), where is (q 0, 0) = q 0 (q 0, 1) = q 1 (q 1, 0) = q 0 (q 1, 1) = q 2 (q 2, 0) = q 2 (q 2, 1) = q 1 0 01 q 0 q 1 q 21 –It is convenient to introduce the extended transition function * : Q X * Q –The second argument of * is a string rather than a single symbol, and its value gives the state the automaton will be in after reading that string. 9
10
Languages and Dfa’s –The language accepted by a dfa M = (Q, , , q 0, F) is the set of all strings on accepted by M. Formally, L(M) = {w * : *(q 0, w) F} L(M) = {w * : *(q 0, w) F} –Example 2: a a,b q 0 bq 1 a, bq 2 trap state L = { a n b: n >= 0} 10
11
Deterministic Finite Automata l Theorem 2.1 –Let M = (Q, , , q 0, F) be a deterministic finite accepter, and let G M be its associate transition graph. Then for every q i, q j Q, and w +, *(q i, w) = q j if and only if there is in G M a walk with label w from q i to q j. –Example 3: Find a deterministic finite accepter that recognizes the set of all strings on = {a, b} staring with a prefix ab. a,b q 0 a q 1 b q 2 b a q 3 a,b –Example 4: Find a dfa that accepts all strings on {0, 1}, except those containing the substring 001. 1 0 0,1 1 0 0 00 1 001 0 11
12
Regular Languages –Definition: A language L is called regular language if and only if there exits some dfa M such that L = L(M). –Example 5: show that L = {awa: w {a, b}*} is regular. –Example 6: show that L 2 is regular. b ab b a b b b q 0 a q 2 q 3 q 0 a q 2 q 3 a q 4 q 5 a a a b q 1 q 1 a,b l Homework: page 45-47: 7, 11-16, 24 12
13
Nondeterministic Finite Automata –A nondeterministic finite accepter or nfa is defined as quintuple M = (Q, , , q 0, F), where Q, , q 0, F are defined as for dfa but : Q X ( ) 2 Q –There are three major differences: l The range of is in the power set 2 Q, so that its value defines a set of all possible states that can be reach by the transition l We allow as the second argument, this means that nfa can make a transition without consuming any input symbol l The value of may be empty, meaning that there is no transition defined for this specific situation. –Example 7: q 0 a q 1 a q 2 a q 3 a a q 4 q 5 a 13
14
14nfa –Example 8: 0 q 0 q 1 0,1 q 2 1 –Example 9: q 0 a q 1 q 2 l *(q 1, a) = {q 0, q 1, q 2 }, *(q 2, ) = {q 0, q 2 }, l *(q 2, aa) = {q 0, q 1, q 2 }, –Definition: The language accepted by a nfa M = (Q, , , q 0, F) is the set of all strings on accepted by M. Formally, L(M) = {w * : *(q 0, w) F } –Example 10: L = {(10) n : n >=0} for example 8 l Input: 110dead configuration *(q 2, 110) = –Why nondeterministic? –Equivalence of dfa and nfa: l Two finite acceptor M 1 and M 2 are said to be equivalent if L(M 1 ) = L(M 2 ), that is, if both accept the same language l Homework: page 53-54: 2, 4, 6-7, 11, 15-16
15
15 Equivalence of dfa and nfa –Example 11: 0 0, 1 q 0 q 1 1 q 2 1 This is equivalent to example 8 0 –Example 12: Convert the following nfa into dfa b b a q 0 a q 1 q 2 {q 0 } {q 1,q 2 } a b a –Theorem: Let L be accepted by M N a,b M N = (Q N, , N, q 0, F N ), Then there exists M D = (Q D, , D, q 0, F D ), Such that L = L(M D )
16
Procedure nfa to dfa l Create a Graph G D with vertex {q 0 } l Repeat until no more edges are missing –Take any vertex {q i, q j,.. q k } of G D that has no outgoing edge –Compute *(q i, a), *(q j, a).. *(q k, a) –Form a union of all these * {q l, q m,.. q n } –Create a vertex for G D labeled {q l, q m,.. q n }, if does not exist –Add an edge a from {q i, q j,.. q k } to {q l, q m,.. q n } l Any vertex has q f F N is identified as a final state l If M N accepts, the vertex {q 0 } in G D is a final state –Example 13: Convert the following nfa 0 1 {q 0 } q 0 0,1 q 1 0,1q 2 01 {q 0,q 1 } {q 1 } 0 1 0,1 {q 0,q 1,q 2 } 1 {q 1,q 2 } 0,1 {q 2 } 1 0 0 Homework: page 61-62: 2, 3, 8, 11 0,1 16
17
Chapter 3: Regular Languages l Regular Expressions –Definition: Let be a given alphabet. Then l , and a are regular expression. These are called primitive regular expression. l If r 1 and r 2 are regular expressions, so are r 1 + r 2, r 1. r 2, r 1 *, and ( r 1 ). l A string is a regular expression if and only if it can be derived from the primitive regular expression by a finite number of applications of the rules in 2. –Example 1: For = {a, b, c}, the string (a+b.c)*.(c+ ) is regular expression –Definition: The language L(r) denoted by any regular expression r is defined by the following rules l is a regular expression denoting empty set l is a regular expression denoting { } l For every a , a is a regular expression {a}. 17
18
18 Regular Expressions –If r 1 and r 2 are regular expressions, then l L(r 1 + r 2 ) = L(r 1 ) L(r 2 )L(r 1. r 2 ) = L(r 1 ) L(r 2 ) l L((r 1 )) = L(r 1 )L((r 1 *)) = L(r 1 )* –Example 2: Exhibit L(a*. (a+b)) in set notation l L = {, a, aa, aaa, …} {a, b} = {a, aa, aaa, …, b, ab, aab, …} –Example 3: = {a, b}, r = (a+b)* (a+bb) l L(r) = (a, bb, aa, abb, ba, bbb, …} –Example 4: r = (aa)* (bb)* b, L(r) = {a 2n b 2m+1, n>=0, m>=0} –Example 5: = {0, 1}, L(r) {w *: w has at least one pair of consecutive zeros}. r = (0 + 1)* 00 (0 + 1)* –Example 6: = {0, 1}, L(r) {w *: w has no pair of consecutive zeros}. r = (1*011*)*(0+ ) + 1*(0+ ) or r = (1+01)*(0 + ) l Homework: pages 76-77: 1, 3, 5, 8, 14, l Theorem: If r is a regular expression then there exists nfa that accepts L(r). L(r) is a regular language. M(r) M(r 1 ) –Proof q 0 a q 1 q 0 q 1 M(r 2 ) M(r 1 ) M(r 2 ) q 0 q 1
19
Connection Between RE and RL l L(r 1 *) M(r 1 ) –Example 7: Find an nfa that accepts L(r), where r= (a+bb)*(ba*+ ) a a b b b –Generalized transition graphs is a transition graph whose edges are labeled with regular expression r 1 r 4 –Theorem: Let L be a regular language. Then there exits r 3 a regular expression r such that L = L(r) q 0 r 3 q f –Homework: page 86-89: 4, 8-12 19
20
20 Regular Grammar –Definition: l A grammar G = (V, T, S, P) is said to be right-linear if all productions are of the form A xB | x, where A, B V and x T* l A grammar is said to be left-linear if all P are of the form A Bx | x. –A Regular grammar is one that is either right-linear or left- linear. –Example 11: G 1 = ({S}, {a, b}, S, P 1 ), P 1 given by S abS | a is right-linear, and G 2 = ({S, S 1, S 2 }, {a, b}, S, P 2 ), P 1 given by S S 1 ab, S 1 S 1 ab | S 2, S 2 a is left-linear. Both of G 1 and G 2 are regular grammar. linear grammar –Example 12: G = ({S, A, B}, {a, b}, S, P), P is S A, A aB |, B Ab is not regular. It is a linear grammar in which at most one variable can occur on the right side of the production. –A regular grammar is always linear, but not all linear grammar are regular.
21
Right-linear grammar l Right-linear grammar generate regular Language –Theorem: Let G = (V, T, S, P) be a right-linear grammar. Then L(G) is a regular language. V 0 a V 1 b V f l Example 13: V 0 aV 1, V 1 abV 0 | b b a l Right-linear grammar for regular Language –Theorem: If L is a regular language on the alphabet , then there exits a right-linear grammar G = (V, T, S, P) such that L = L(G). l Example 14: construct a right-linear grammar for L(aab*a). q 0 aq 1, q 1 aq 2, q 2 bq 2, q 2 aq f, q f 21
22
22 Chapter 4: Properties of Regular Languages l Equivalence of RL and RG –Theorem: A language L is a regular language if and only if there exits a left-linear grammar G such that L = L(G). –Theorem: A language L is a regular if and only if there exits a regular grammar G such that L = L(G). –Homework: page 97-98: 1, 4, 5, 12-13 l Closure Properties of regular languages –If L 1 and L 2 are regular languages, then so are L 1 L 2, L 1 L 2, L 1 L 2, L 1, and L 1 *, Regular languages are closed under , ,.,, * –Example: show that RL is closed under difference L 1 - L 2 = L 1 L 2 –Theorem: Regular languages are closed under reversal Regular Expression Regular Grammar dfa or nfa
23
Elementary Questions about RL –Theorem: There exits an algorithm for determining whether or not w is in a regular language L –Theorem: There exits an algorithm for determining whether a regular language is empty, finite or infinite –Theorem: There exits an algorithm for determining whether or not two regular languages L 1 = L 2. L 3 = (L 1 L 2 ) (L 1 L 2 ) is if and only if L 1 = L 2. –Homework: page 113-114: 1-6 23
24
Identifying Nonregular Languages –Pumping Lemma: Let L be an infinite regular language. Then there exits some positive integer m such that any w L with |w| >= m can be decompose as w = xyz, with |xy| = = 1 such that w i = xy i z is also in l for all i = 0, 1, 2, … –Example 7: Show that L = {a n b n : n>= 0} is not regular l Assume L is regular. Suppose |y| = k. for i = 0, w 0 = a m-k b m. We cannot pump y. Therefore L is not a regular language. 24
25
25 Pumping Lemma l The opponent picks m l Given m we pick a string w in L of length >= m. We are free to choose any w, subject to w L and |w| >= m l The opponent chooses the decomposition xyz, subject to |xy|= = 1. l We try to pick i in such a way that pumped string w i is not in L –Example 8: For = {a, b}, Show that L = {ww R : w *} is not regular m m m m a... ab... bb... ba... a x y z l If w is too short, the opponent may choose a y with even number of b’s. If w consists of all a’s w = a 2m, then the opponent need only pick y = aa
26
Pumping Lemma: Examples –Example 9: For = {a, b}, Show that l L = {w *, n a (w) < n b (w)} is not regular. l Given m, we pick w = a m b m+1, |xy| cannot be greater than m. The opponent can only pick a y with all a’s. y = a k, 1 =<k=<m. l For i = 2, w = a m+k b m+1 L –Example 10: L = {(ab) n a k :n>k, k>=0} is not regular l Given m, we pick w = (ab) m+1 a m. |xy| =< m. If y = a, l for i = 0, w is not in L. If y = ab, for i = 0, w is not in L –Example 12: L = {a n b k c n+k :n>=0, k>=0} is not regular –Homework: page 121-124: 3, 4, 9, 10, 18 26
27
Chapter 5: Chapter 5: Context-free Grammar –A grammar G = (V, T, S, P) is context-free if all productions in P have the form A x, where A V and x (V T)* –A language is said to be context-free if L=L(G) and G is context-free –Example 1: G = ({S}, {a, b}, S, P), S aSa | bSb |. l is context-free. L(G) = {ww R : w {a, b}*} –Example 2: G with S abB, A aaBb |, B bbA, l is context-free. L(G) = {ab(bbaa) n bba(ba) n : n >=0} –Both examples 1 and 2 are context-free and linear. 27
28
28 Context-Free Languages –Example 3: Show that L= {a n b m : n m} is context-free l S AS 1, S 1 aS 1 b |, A aA | a, or not linear l S AS 1 | S 1 B, S 1 aS 1 b |, A aA | a, B bB | b not linear –Example 4: S aSb | SS |, l L = {n a (w) = n b (w), n a (v) >= n b (v) for v is any prefix of w} (()), (() () ()) l Leftmost and rightmost derivations –Definition: The derivation is said to be leftmost if in each step the leftmost variable in the sentential form is replaced. If in each step the rightmost variable is replaced, we call the derivation rightmost. l S AB, A aaA |, B Bb |, L(G) = {a 2n b m : n>=0, m>=0} l S AB aaAB aaB aaBb aab leftmost derivation l S AB ABb Ab aaAb aab rightmost derivation –Example 5: S aAB, A bBb, B A | l S aAB abBbB abAbB abbBbbB abbbbB abbbb leftmost l S aAB aA abBb abAb abbBbb abbbb rightmost
29
Derivation Trees –Definition: Let G = (V, T, S, P) be a context-free grammar. An ordered tree is a derivation tree for G if and only if it has the following properties: l The root is labeled S. l Every leaf has a label from T { } –Every node has a label from V T { } is said to be a partial derivation tree l Every interior vertex has a label from V l If a vertex has label A V and its children are labeled a 1, a 2, a 3 then p must contain A a 1 a 2 a 3... A k S l A leaf labeled has no children a A B –Example 6: S aAB, A bBb, B A | b B b A b B b l Relation between sentential forms and derivation l Theorem: Let G = (V, T, S, P) be a context-free grammar. Then for every w L(G), there exits a derivation tree. –Homework: pages 133-136: 7, 8, 10, 12, 18, 19, 22, 23 29
30
30 Parsing and Ambiguity –Example 7: S SS | aSb | bSa |, generate w = aabb (exhaustive) l S aSb aaSbb aabb –Exhaustive search parsing may never terminate. To overcome we need to restrict the grammar of having A or A B –Example 8: S SS | aSb | bSa | ab | ba, l Exhaustive search parsing terminates in no more than |w| rounds. l Theorem: Let G = (V, T, S, P) be a context-free grammar which does not have any rules of the form A or A B where A, B V. Then the ex haustive search parsing method for any w *, either produce a parsing of w or tells us that no parsing possible. l Theorem: For every context-free grammar there exits an algorithm that parsed any w L(G) in a number of steps proportional to |w| 3 l Definition: A context-free grammar G = (V, T, S, P) is said to be a simple grammar or s-grammar if all productions are of the form A ax, where A V, a T, x V*, and any pair (A, a) occurs at most once in P. –Example 9: S aS | bSS | c is an s-grammar and S aS| bSS| aSS| c is not an s- grammar because the pair (S, a) occurs in two productions l If G is an s-grammar, then any string w in L(G) can be parsed in a number of steps proportional to |w|
31
Ambiguity in Grammars and Languages –Definition: A context-free grammar G is said to be ambiguous if there exits some w L(G) which has at least two distinct derivation trees. –Example 10: S aSb | SS | is ambiguous. aabb has two derivation trees –Example 11: G = (V, T, E, P), with V = {E, I}, T = {a, b, c, +, *, (, )}, E I | E + E | E * E | (E), I a | b | c is ambiguous since there are two derivation trees for a + b * c –Example 12: G = (V, T, E, P), with V = {E, T, F, I}, T = {a, b, c, +, *, (, )}, E T | E + T | T * E, T F | T * F, F I | (E), I a | b | c is unambiguous there is only one derivation tree for a + b * c –Definition: If L is a context-free language for which there exits an unambiguous grammar, then L is said to be unambiguous. If every grammar that generates L is ambiguous, then the language is called inherently ambiguous. –Example 13: The language L = {a n b n c m } {a n b m c m } is inherently ambiguous. L = L 1 L 2. L 1 is generated by S 1 S 1 c|A, A aBb|, L 1 is generated by S 2 aS 2 |B, B bBc|, and L is generated by S S 1 | S 2 –Homework: page 145-146: 1-8, 12-13 31
32
32 Chapter 6: Simplification of CFG l Methods for Transforming Grammars –We can move from L to L – { } and given G we can find G` such that L(G`) = L(G) - { }. -free context-free languages l Theorem: Let G = (V, T, E, P) be a context-free grammar with P has A x 1 Bx 2 and B y 1 | y 2 |... | y n. Let G` = (V, T, E, P`) which P` is constructed by deleting A x 1 Bx 2 from P and adding A x 1 y 1 x 2 | x 1 y 2 x 2 |... | x 1 y n x 2, then L(G`) = L(G) –Example 1: G = ({A, B}, {a, b, c}, A, P) with productions A a | aaA | abBc, B abbA | b. We can get G` with productions A a | aaA | ababbAc | abbc, B abbA | b, G` is equivalent to G l
33
Removing useless productions –Definition: A variable is useful if and only if it occurs in at least one derivation. A variable is not useful is called useless. A production is useless if it involves any useless variable. –Example 2: S A, A aA |, B bA. B is useless. So B bA. –Example 3: Eliminate useless symbols and productions from G l S aS|A|C, A a, B aa, C aCb. C is useless and its productions l S aS|A, A a, B aa, Draw dependency graph S A B l B is useless and the production S aS|A, A a, –Theorem: Let G = (V, T, E, P) be a context-free grammar. Then there exits an equivalent grammar G` = (V, T, E, P`) that does not contain any useless variable or productions. 33
34
Removing -productions –Definition: A is called -production & variable A * is nullable l A grammar may generate a language not containing, yet have some - productions or nullable variables. –Example 4: The grammar S aS 1 b, S 1 aS 1 b | generates -free language {a n b n : n>=1}. -production can be removed S aS 1 b|ab, S 1 aS 1 b | ab –Theorem: Let G = (V, T, E, P) be a context-free grammar with not in L(G), Then there exits an equivalent grammar G` with no -productions. –Example 5: S ABaC, A BC, B b|, C D|, D d S ABaC|BaC|AaC|ABa|aC|Aa|Ba|a, A B|C|BC, B b, C D, D d
35
35 Removing Unit-productions l Definition: A B, where A, B V is called a unit-production l Theorem: Let G = (V, T, E, P) be a context-free grammar without -production. Then there exits an equivalent grammar G` does not have unit-productions and that is equivalent to G. –Find for all A, all variable B such that A * B by drawing dependency graph –G` is generated by putting all non-unit-production of P into P’ –We add to P` A y 1 |y 2 |... |y n where B y 1 |y 2 |... |y n is the set of all rules in P` with B on the left. Non of y i can be a single variable.
36
Example 6: Remove all unit-production from –S Aa|B, A a|bc| B, B A|bb. –Draw dependency graph S A B –The non-unit productions are –S Aa, A a|bc, B bb. –We add S * A, S * B, B * A, A * B –The new rules are S a|bc|bb, A bb, B a|bc. –The equivalent grammar is S a|bc|bb|Aa, A a|bb|bc, B a|bb|bc. –The removing of the unit production has made B rules are useless l Theorem: Let L be a context-free language that does not contain, Then there exits a context-free grammar that generate L and that does not have any useless production, -production or unit-production. –Remove -productions, then unit-productions, then useless productions l Homework: pages 161-164: 5-9, 18 36
37
37 Normal Forms l Chomsky Normal Form –Definition: A context-free grammar is in Chomsky normal form if all productions are of the form A BC, or A a, where A, B, C are in V, and a is in T. –Example 7: The grammar S AS|a, A SA|b is in CNF l The grammar S AS|AAS, A SA|aa is not. because S AAS, A aa l Theorem: Any context-free grammar with no in L(G) has an equivalent grammar G` in Chomsky normal form. –Construct G 1 from G by considering A x 1 x 2... x n, –If n = 1, then x 1 must be terminal, put the production in P 1 –For n >= 2, introduce new variable B a for each a T, form the production in P 1 A C 1 C 2... C n, where C i = x i if x i V, and C i = B a if x i = a –For every B a, we also put B a a –G 1 has A a, or A C 1 C 2... C n, and L(G 1 ) = L(G) –Replace A C 1 C 2... C n by A C 1 D 1, D 1 C 2 D 2,... D n-2 C n-1 C n, –Example 8: Convert S ABa, A aab, B Ac to CNF l S ABB a, A B a B a B b, B AB c, B a a, B b b, B c c, l S AD 1, D 1 BB a, A B a D 2, D 2 B a B b, B AB c, B a a, B b b, B c c,
38
Greibach Normal Form –Definition: A context-free grammar is in Greibach normal form if all productions are of the form A ax, where a T and x V*. –Example 9: The grammar S AB, A aA|bB|b, B b is not in GNF, but S aAB| bBB| bB, A aA|bB|b, B b is in GNF –Example 10: Convert S abSb|aa into GNF. l S aBSB| aA, A a, B b –Theorem: Any context-free grammar with no in L(G) has an equivalent grammar G` in Greibach normal form. –Homework: Pages 170-171: 4-5, 8-13 38
39
39 Chapter 7: Pushdown Automata l Definition: A nondeterministic pushdown acceptor (npda) is defined by M = (Q, , , , q 0, F), where Qis a finite set of internal states. is the input alphabet. is a finite set of symbols, called stack alphabet : Q X ( { } ) X finite set of Q X * is the transition function. q 0 Q is the initial state. z is the stack start symbol F Q is a set of final states. –Example 1: (q 1, a, b) = {(q 2, cd), (q 3, )} q2q2 q1q1 q3q3 a,b/cd a,b/
40
Examples –Example 2: Q={q 0, q 1, q 2, q 3 }, ={a, b}, ={0, 1}, z=0, F= {q 3 } and (q 0, a, 0) = {(q 1, 10), (q 3, )}, (q 0,, 0) = {(q 3, )} (q 1, a, 1) = {(q 1, 11)} (q 1, b, 1) = {(q 2, )} (q 2, b, 1) = {(q 2, )} (q 2,, 0) = {(q 3, )} L = {a n b n : n >= 0} {a} l The language Accepted by a pushdown Automata –Definition: Let M be a nondeterministic pushdown automata, L(M) = {w * :(q0, w, z) M *(p,, u), p F,u *} 40 q0q0 q1q1 q2q2 q3q3 a,0/ a,0/10,0/ a,1/11 b,1/,0/
41
Example 3 – Construct an npda for L={w {a, b}*:n a (w)=n b (w)} M = ({q 0, q f }, {a, b}, {0, 1,z}, , q 0, z, {q f }) (q 0,, z) = {(q f, z)} (q 0, a, z) = {(q 0, 0z)} (q 0, b, z) = {(q 0, 1z)} (q 0, a, 0) = {(q 0, 00)} (q 0, b, 0) = {(q 0, )} (q 0, a, 1) = {(q 0, )} (q 0, b, 1) = {(q 0, 11)} q0q0 b,z/1z a,z/0z,z/z b,0/ a,0/00 b,1/11 a,1/ qfqf
42
Example 4 –Construct an npda for L={ww R : w {a, b}*} M = ({q 0, q 1, q 2 }, {a, b}, {a, b,z}, , q 0, z, {q 2 }) push in the stack (q 0, a, a) = {(q 0, aa)} (q 0, b, a) = {(q 0, ba)} (q 0, a, b) = {(q 0, ab)} (q 0, b, b) = {(q 0, bb)} (q 0, a, z) = {(q 0, az) (q 0, b, z) = {(q 0, bz)} guess middle (q 0,, a) = {(q 1, a)} (q 0,, b) = {(q 1, b)} match w R (q 1, a, a) = {(q 1, )} (q 1, b, b) = {(q 1, )} successful match (q 1,, z) = {(q 2, z)} –Homework: pages 182-184: 3-6, 10-13 q0q0,a/a,b/b q1q1 q2q2 a,a/aa b,a/ba a,z/az a,a/ b,b/,z/z b,z/bz a,b/ab b,b/bb
43
43 Pushdown Automata and CFG –Example 5: Construct a pda that accepts the language generated with productions S aSbb | a l Transform the grammar into GNF l S aSA|a, A bB, B b l Q = {q 0, q 1, q 2 }, with initial state q 0, and final state q 2 b,B/ a,S/ a,S/SA b,A/B q 1,z/ q 2 q 0,z/Sz (q 0,, z) = {(q 1, Sz)} (q 0, a, S) = {(q 1, SA), (q 1, ) } (q 1, b, A) = {(q 1, B)} (q 1, b, B) = {(q 1, )} (q 1,, z) = {(q 2, )} –Theorem: For any context-free language L, there exits an npda M such that L = L(M)
44
Example 6 –For the grammar S aA, A aABC|bB|a, B b, C c c,C/ (q 0,, z) = {(q 1, Sz)} (q 1,, z) = {(q f, )} b,A/B b,B/ (q 1, a, S) = {(q 1, A)} (q 1, a, A) = {(q 1, ABC), (q 1, )} a,S/A a,A/ (q 1, b, A) = {(q 1, B)} (q 1, b, B) = {(q 1, )} a,A/ABC (q 1, c, C) = {(q 1, )} q 0,z/Sz q 1,z/ q f (q 0, aaabc, z) (q 1, aaabc, Sz) (q 1, aabc, Az) (q 1, abc, ABCz) (q 1, bc, ACz) (q 1, c, Cz) (q 1,, z) (q f,, z) 44
45
Context-Free Grammar for Pushdown Automata –Assume npda meets the following requirements: l It has a single final state q f that is entered if and only if the stack is empty l All transition must have the form (q i, a, A) = {c 1, c 2,... c n } where c i = (q j, ) would be (q i Aq j ) a or c i = (q j, BC). would be (q i Aq k ) a (q j Bq l ) (q l Cq k ) for all l and k i. e. stack size +1 or -1
46
46 Deterministic PDA and CFL –Example 7: npda with (q 0, a, z)={(q 0, Az)}, – (q 0, a, A) = {(q 0, A)}, (q 0, b, A) = {(q 1, )}, (q 1,, z) = {(q 2, )}, l New set (q 0, a, z)={(q 0, Az)}, (q 3,, z)={(q 0, Az)}, (q 0, a, A) ={(q 3, )}, (q 0, b, A) = {(q 1, )}, (q 1,, z) = {(q 2, )}, l Productions (q 0 Aq 3 ) a, (q 0 Aq 1 ) b, (q 1 zq 2 ) , (q 0 zq 0 ) a(q 0 Aq 0 )(q 0 zq 0 ) | a(q 0 Aq 1 )(q 1 zq 0 ) | a(q 0 Aq 2 )(q 2 zq 0 )|a(q 0 Aq 3 )(q 3 zq 0 ) (q 0 zq 1 ) a(q 0 Aq 0 )(q 0 zq 1 ) | a(q 0 Aq 1 )(q 1 zq 1 ) | a(q 0 Aq 2 )(q 2 zq 1 )|a(q 0 Aq 3 )(q 3 zq 1 ) (q 0 zq 2 ) a(q 0 Aq 0 )(q 0 zq 2 ) | a(q 0 Aq 1 )(q 1 zq 2 ) | a(q 0 Aq 2 )(q 2 zq 2 )|a(q 0 Aq 3 )(q 3 zq 2 ) (q 0 zq 3 ) a(q 0 Aq 0 )(q 0 zq 3 ) | a(q 0 Aq 1 )(q 1 zq 3 ) | a(q 0 Aq 2 )(q 2 zq 3 )|a(q 0 Aq 3 )(q 3 zq 3 ) (q 3 zq 0 ) (q 0 Aq 0 )(q 0 zq 0 ) | (q 0 Aq 1 )(q 1 zq 0 ) | (q 0 Aq 2 )(q 2 zq 0 ) | (q 0 Aq 3 )(q 3 zq 0 ) (q 3 zq 1 ) (q 0 Aq 0 )(q 0 zq 1 ) | (q 0 Aq 1 )(q 1 zq 1 ) | (q 0 Aq 2 )(q 2 zq 1 ) | (q 0 Aq 3 )(q 3 zq 1 ) (q 3 zq 2 ) (q 0 Aq 0 )(q 0 zq 2 ) | (q 0 Aq 1 )(q 1 zq 2 ) | (q 0 Aq 2 )(q 2 zq 2 ) | (q 0 Aq 3 )(q 3 zq 2 ) (q 3 zq 3 ) (q 0 Aq 0 )(q 0 zq 3 ) | (q 0 Aq 1 )(q 1 zq 3 ) | (q 0 Aq 2 )(q 2 zq 3 ) | (q 0 Aq 3 )(q 3 zq 3 ) l (q 0, aab, z) (q 0, ab, Az) (q 3, b, z) (q 0, b, Az) (q 1,, z) (q 2,, ) l (q 0 zq 2 ) a(q 0 Aq 3 )(q 3 zq 2 ) aa(q 3 zq 2 ) aa(q 0 Aq 1 )(q 1 zq 2 ) aab(q 1 zq 2 ) aab –Theorem: If L = L(M) for some npda M, then L is CFL –Homework: pages 193-194: 1, 3-6, 9-15
47
Deterministic PDA and CFL –Definition: A pushdown automata M = (Q, , , , q 0, F) is said to be deterministic if it is subject to the restriction that for every q Q, a { } and b l (q, a, b) contains at most one element l If (q,, b) is not empty, then (q, c, b) must be empty for every c –Definition: A language L is said to be a deterministic CFL if and only if there exits a dpda M such that L = L (M) –Example 8: L={a n b n : n >=0} is a deterministic CFL. l M = ({q 0, q 1, q 2 },{a, b}, {0,1}, , q 0, 0, {q 0 }) with (q 0, a, 0) = {(q 1, 10)} (q 1, a, 1) = {(q 1, 11)} (q 1, b, 1) = {(q 2, )} (q 2, b, 1) = {(q 2, )} (q 2,, 0) = {(q 0, )}is deterministic –Homework: Page 199: 1-4, 8-9 47
48
48 Chapter 8: Properties of CFL l Pumping Lemma for CFL –Let L be an infinite CF. Then, there exists some positive integer m such that any w L with |w| >= m can be decomposed as w = uvxyz, with |vxy| = = 1, such that uv i cy i z L, for i = 0,1, 2, … –Example 1: Show that the language L = {a n b n c n : n >= 0} is not CFL. –1- given m l Choose w = a m b m c m –If vxy = only a’s and pump, not in the language –If vxy has equal a’s and b’s and pump, a k b k c m not in L –Only way would have equal a’s, b’s, and c’s, is impossible –Example 2: L = {ww: w {a,b}*}.Given m l Choose w = a m b m a m b m m m m m l Pump i =0, a k b j a m b m a... a b... b a... a b... b l u v x y z –Example 4: L = {a n b j : n = j 2 }, given m l Choose w = a m 2 b m m 2 m l Pumping i k 1 k 2 l m 2 + (i-1)k 1 a’sand m + (i-1) k 2 b’s a.. a.. a.. a b.. b.. b..b l (m-k 2 ) 2 =<(m-1) 2 =m 2 –2m + 1<m 2 – K 1 u v x y z –Homework: pages 212-213: 3-5, 7-8 l Closure Properties and Decision Algorithms for CFL
49
Closure Properties and Decision Algorithms for CFL –Theorem: The family of CFL is closed under union, concatenation and star-closure –Theorem: The family of CFL is not closed under intersection and complementation –Theorem: Let L 1 be a CFL and L 2 be a regular. L 1 L 2 is CFL –Example 7: Show that L = {a n b n :n>=0, n 100} is CFL l L = {a n b n : n>=0} L 1, L 1 = {a 100 b 100 } –Example 8: L = w {a, b, c}*: n a (w) = n b (w) = n c (w)} is not CFL l L L(a*b*c*) = {a n b n c n : n>=0} is not CFL, so L is not CFL –Theorem: Given G is CFG, there exists an algorithm for deciding whether or not L(G) is empty or infinite. 49
50
50 Chapter 9: Turing Machines l The Standard Turning Machine –A Turing Machine M is defined by M = (Q, , , , q 0, , F), l Qis a set of internal states. l is the input alphabet. We assume - { } l is a finite set of symbols called the tape alphabet. l is the transition function : Q X Q X X {L, R} l is a special symbol called the blank l q 0 Q is the initial state. l F Q is a set of final states. q 0 q 1 –Example 1: (q 0, a) = (q 1, d, R) a b c d b c –Example 2: Q = {q 0, q 1 }, = {a, b}, = {a, b, }, F = {q 1 } (q 0, a) = (q 0, b, R), (q 0, b) = (q 0, b, R), (q 0, ) = (q 1, , L), q 0 q 0 q 0 q 1 a a b a b b b b –Example 3: F is empty (q 0, a) = (q 1, a, R), (q 0, b) = (q 1, b, R), (q 0, ) = (q 1, , R), (q 1, a) = (q 0, a, L), (q 1, b) = (q 0, b, L), (q 1, ) = (q 0, , L),
51
The Standard Turning Machine l It has unbounded tape in both directions l It is deterministic q l No special input file a 1 a 2... a k-1 a k a k+1... a n l x 1 qx 2 = a 1 a 2...a k-1 qa k a k+1... a n –Example 5: q 0 aa├ bq 0 a ├ bbq 0 ├ bq 1 b == q 0 aa├ * bq 1 b –Definition: M = (Q, , , , q 0, , F) a 1 a 2...a k-1 q 1 a k a k+1... a n ├ a 1 a 2...a k-1 bq 2 a k+1... a n (q 0, a k ) = (q 2, b, R), a 1 a 2...a k-1 q 1 a k a k+1... a n ├ a 1 a 2... q 2 a k-1 ba k+1... a n (q 0, a k ) = (q 2, b, L), l M is said to halt from some initial configuration x 1 q i x 2 if x 1 q i x 2 ├ * y 1 q j ay 2 and (q j, a) is undefined. The sequence of configuration leading to the halt state is called computation. l Turing Machine as Language Acceptor –Definition: Let M = (Q, , , , q 0, , F) –L(M) = {w *: q 0 w ├ * x 1 q f x 2 for some q f F, x 1, x 2 *} 51
52
52 Turing Machine as Transducers –Example 6: Design TM for L(00*). Q= {q 0, q 1 }, F = {q 1 } l (q 0, 0) = (q 0, 0, R), (q 0, ) = (q 1, , R),0/0,R l q 0 q 1 –Example 7: Design TM for L = {a n b n : n>= 1} / R l Q = {q 0, q 1, q 2, q 3, q 4 }, F = {q 4 }, = {a, b}, = {a, b, x, y, } (q 0, a)= (q 1, x, R), (q 1, a)= (q 1, a, R), (q 1, y)=(q 1, y, R), (q 1, b)=(q 2, y, L), (q 2, y)=(q 2, y, L), (q 2, a)=(q 2, a, L), (q 2, x)= (q 0, x, R), (q o, y)=(q 3, y, R), (q 3, y)=(q 3, y, R), (q 3, ) = (q 4, , R), y/y,R a/a,R a/a,L y/y,L y/y,R q 0 a/x, R q 1 b/y,L q 2 q 3 / , R q 4 x,x,R –Example 8: Design TM for L = {a n b n c n : n>= 1}
53
Turing Machine as Transducers –Definition: A function f with domain D is said to be Turing-computable or just computable if there exists some Turing machine l M = (Q, , , , q 0, , F), l such that q 0 w ├ * M q f f(w), q f F for all w D –Example 9: Design TM that computes x + y l x is represented by w(x) = {1} + l w(x) and w(y) separated by 0 l w(x+y) is followed by a single 0, the head at the left end l q 0 w(x)0w(y) ├ * q f w(x+y)0 l Q = {q 0, q 1, q 2, q 3, q 4 }, F = {q 4 }, (q 0, 1)= (q 0, 1, R), (q 0, 0)= (q 1, 1, R), l (q 1, 1)=(q 1, 1, R), (q 1, )= (q 2, , L), (q 2, 1)= (q 3, 0, L), l (q 3, 1)=(q 3, 1, L), (q 3, )= (q 4, , R), 1/1, R 1/1,R 1/1,L q 0 0/1, R q 1 / ,L q 2 1/0,L q 3 / , R q 4 53
54
Turing Machine as Transducers (2) –Example 10: Design TM that copies strings of 1’s. l q 0 w├ * q f ww (q 0, 1)= (q 0, x, R), (q 0, )= (q 1, , L), l (q 1, x)=(q 2, 1, R), (q 2, 1)= (q 2, 1, R), (q 2, )= (q 1, 1, L), l (q 1, 1)=(q 1, 1, L), (q 1, )= (q 3, , R) 1/x, R 1/1,L 1/1,R q 0 / ,L q 1 x/1,R q 2 q 3 /1, L / , R –Example 11: Design TM that l q 0 w(x)0w(y) ├ * q f w (x)0w(y) if x >= y l q 0 w(x)0w(y) ├ * q n w (x)0w(y) if x < y l xx... 110xx... x if x >= y l xx... xx0xx... x 11 if x < y –Homework: Pages 236-238: 5,7,9,11, 54
55
55 Combining TM’s for Complicated Tasks –Example 12: Design a Turing machine that compute the function: –f(x, y) = x + y,if x >= y, = 0,if x < y. Adder A x, y Comparer f(x,y) C Eraser E –Example 13: if a then q j else q k (q i, a) = (q j0, a, R)for all q i Q, (q i, b) = (q k0, b, R)for all q i Q and all b - {a}, (q j0, c) = (q j, c, L)for all c , (q k0, c) = (q k, c, L)for all c . –Example 14: Design a TM that multiplies two positive integers in unary notation. – 0 0 1 1 1 0 1 1 1 0 1... 1 0 1 1 1 0 1 1 1 y x xy y x –Homework: pages 242-244: 3, 5, 8
56
Turing’s Thesis –Anything that can be done on any existing digital computer can also be done by a Turing machine. –No one has yet been able to suggest a problem, solvable by what we intuitively considered an algorithm, for which a Turing machine program cannot be written. –Alternative models have been proposed for mechanical computation, but none of them are more powerful than TM model –Definition: An algorithm for a function f: D R is a Turing machine M, which given as input any d D on its tape, eventually halts with the correct answer f(d) R on its tape. q 0 d├ * M q f f(d), q f F, for all d D l Equivalence of Classes of Automata –Definition: Two automata are equivalent if they accept the same language. Two classes of automata C 1 and C 2. l If for every M 1 in C 1 there is M 2 in C 2, L(M 1 ) = L(M 2 ), C 2 is at least as powerful as C 1. l If for every M 2 in C 2 there is M 1 in C 1, L(M 1 ) = L(M 2 ), C 1 and C 1 are equivalent. 56
57
57 Chapter 10 Other Models of TM l Turing Machine with Stay-Option –Theorem: The class of Turing machine with stay-option : Q X Q X X {L, R, S} is equivalent to the class of standard Turing machine l Turing Machine with Multiple tracks a b c l Turing Machine with Semi-Infinite Tape l The Off-Line Turing Machine l Turing Machine with more Complex Storage –Multitape Turing Machine –Multidimensional Turing Machine –Nondeterministic Turing Machines l Definition: A nondeterministic Turing Machine is an automaton where is now a function : Q X 2 Q X X {L, R} l Example 2: (q 0, a) = {(q 1, b, R), (q 2, c, L)} q 0 aaa ├ bq 1 aaor q 0 aaa ├ q 1 caa l Theorem: The class of deterministic Turing machines and the class of nondeterministic Turing machines are equivalent
58
A Universal Turing Machine –Control unit – of M u l Description of M Tape contents of M Internal state of M –Definition: Let S be a set of strings on some alphabet . Then an enumeration procedure for S is a Turing machine that can carry out the sequence of stepsq 0 ├* q s x 1 # s 1 ├* q s x 2 # s 2.... with x i - {#}, s i S, in such way that any s in S produce in a finite number of steps. The state q s is a state signifying membership in S; that is, whenever q s is entered, the string following # must be in S. –Example 3: Let = {a, b, c}. We can show that the set S = + is countable if we can find an enumeration procedure that produce its elements in some order. We take the length of the string as the first criterion, followed by the alphabet ordering of all equal-length strings.a, b, c, aa, ab, ac, ba, bb, bc, ca, cb, cc, aaa,.... – The above ordering is called the proper order. l Theorem: The set of all Turing Machine, although infinite, is countable. 58
59
59 Linear Bounded Automata l Linear Bounded Automata –Definition: A Linear bounded automaton is a nondeterministic Turing machine M = (Q, , , , q 0, , F), subject to the restriction that must contain two special symbols [ and ], such that (q i, [) can contain only elements of the form (q j, [, R), and (q i, ]) can contain only elements of the form (q j, ], L). –Definition: The language accepted by lba is the set of all w such that, q 0 [w]├ [x 1 q f x 2 ], q f F, x 1, x 2, * –Example 4: L = {a n b n c n : n>=1} is accepted by lba –Example 5: L = {a n! : n>=0} is accepted by lba –Homework: Page 273: 4 l Recursive and Recursively Enumerable Languages –Definition: A language is said to be Recursively Enumerable if there exits a TM that accepts it. –Definition: A language L on is said to be recursive if there exits a TM M that accepts L and that halts on every w in +. l Languages that are not Recursively Enumerable –Theorem: Let S be an infinite countable set. Then its powerset 2 S is not countable.
60
Chapter 11: A Hierarchy of Formal Languages and Automata –Theorem: For any nonempty , there exist languages that are not recursively enumerable. –Theorem: There exists a recursive enumerable language whose complement is not recursive enumerable. l A Language that is Recursively Enumerable but not Recursive –Theorem: If a language L and its complement L is both re, then both languages are recursive. If L is recursive, then L is also recursive, and consequently both are recursive enumerable. –Theorem: There exists a re language that is not r; that is, the family of r languages is a proper subset of the family of re languages. l Unrestricted Grammar –Definition: A grammar G = (V, T, S, P) is called unrestricted if all the productions are of the form u v, where u is in (V T) + and v is in (V T)*. –Theorem: Any language generated by unrestricted grammar is re. –Theorem: For every re language L, there exists an unrestricted grammar G, such that L = L(G). 60
61
61 Context-Sensitive Grammar and Languages –Definition: A grammar G = (V, T, S, P) is said to be context-sensitive if all productions are of the form x y, where x, y (V T)* and |x| =< |y|. l This grammar is noncontracting. The normal form xAy xvy l Context-Sensitive Languages & Linear Bound Automata –Definition: A language L is said to be context-sensitive if there exists a CSG G, such that L =L(G) or L = L(G) { } –Example 2: L = {a n b n c n : n>=1} is a CS language. l S abc|aAbc, Ab bA l Ac Bbcc, bB Bb l aB aa | aaA –Theorem: For Every CSL L not including, there exists some LBA M such that L = L(M).
62
The Chomsky Hierarchy –Theorem: If a language L is accepted by some lba M, then there exists a CSG that generate L. l Relation between Recursive and CSL –Theorem: Every CSL L is recursive. –Theorem: There exists a recursive language that is not CS. l The Chomsky Hierarchy L RE L RE L REC L CS L CF L CS L REG L CF L DCF L REG L CF L LIN L REG L DCF –Example: L = {w:n a (w) = n b (w)} is deterministic context-free language but not linear. L = {a n b n } {a n b 2n } is linear but not deterministic. –Homework: Page 297: 1-3 62
63
63 Some problems that cannot be solved by TM –Computability and decidability – The Turing Machine Halting Problem l Given the description of a Turing machine M and an input w, does M, when started in the initial configuration q 0 w, perform a computation that eventually halts? –Theorem: There does not exist any TM H that behaves such that it does check the halting problem. The halting problem is therefore undecidable. –Theorem: If the halting problem were decidable, then every re language would be r. Consequently, the halting problem is undecidable.
64
64 Chapter 12: Limits of Algorithmic Computations l Reducing One Undecidable problem to Another –The state-entry problem. Given any TM M and any q Q, w +, decide whether or not the state q is ever entered when M is applied to w. This problem is undecidable. –The Blank-tape halting Problem. Given a TM M, determine whether or not M halts if started with a blank tape. l Undecidable Problems for RE Languages –Theorem: Let G be an unrestricted grammar. Then the problem of determining whether or not L(G) = is undecidable. –Theorem: Let M be any TM. Then the question of whether or not L(M) is finite is undecidable. –Example: Show that for an arbitrary TM M with = {a, b}, the problem “L(M) contains two different strings of the same length” is undecidable. l The Post Correspondence Problem –grammars G 1 and G 2.
65
65 The Post Correspondence Problem –Given two sequences of n strings on some alphabet , A=w 1, w 2, …, w n, and B = v 1, v 2,..., v n, we say there exists a Post correspondence solution (PC-solution) for the pair (A, B) if there is a nonempty sequence of integers I, j, …, k, such that w 1 w 2... w n = v 1 v 2...v n. –Example: Let = {0,1} and take A and B as w 1 =11, w 2 =100, w 3 =111, v 1 =111, v 2 =001, v 3 =11. For this case, there exits a PC-solution w 1 w 2 w 3 For w 1 =00, w 2 =001, w 3 =1000, 1 1 1 0 0 1 1 1 v 1 =0, v 2 =11, v 3 =011, v 1 v 2 v 3 there cannot be any PC-solution –Theorem: The Post correspondence problem is undecidable. l Undecidable Problem for Context-free Languages –Theorem: There exits no algorithm for deciding whether any given context-free grammar is ambiguous. –Theorem: There exits no algorithm for deciding whether or not L(G 1 ) L(G 2 ) = , for arbitrary context-free
66
The Chomsky Hierarchy Lre LcsGcf LcfGreg Lregfa pda TM 66
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.