CS 275 Automata and Formal Language Theory

Size: px
Start display at page:

Download "CS 275 Automata and Formal Language Theory"

Transcription

1 CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) Anton Setzer (Bsed on book drft by J. V. Tucker nd K. Stephenson) Dept. of Computer Science, Swnse University csetzer/lectures/ utomtformllnguge/current/index.html Mrch 20, 2015 CS 275 Chpter II.5. 1/ 81

2 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.4. The Pumping Lemm for CFG (14.4) II.5.5. Floyd s Theorem CS 275 Chpter II.5. 2/ 81

3 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.4. The Pumping Lemm for CFG (14.4) II.5.5. Floyd s Theorem CS 275 Sect. II / 81

4 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Derivtion Trees or Prse Trees Context free Grmmrs (bbrevited s CFG in the following) llow to pply to non-terminl t position without needing the context. Therefore we cn expnd the non-terminls independently of ech other. This llows us to define derivtion trees (lso clled prse trees). CS 275 Sect. II / 81

5 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Consider the grmmr grmmr G terminls nonterminls strt symbol productions, b S S S Sb S b CS 275 Sect. II / 81

6 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Derivtion We derive bbbb in it: S Sb Sbb bbb CS 275 Sect. II / 81

7 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Derivtion Tree S Sb Sbb bbb S S b S b b CS 275 Sect. II / 81

8 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Form of the Derivtion Tree Nodes re lbelled with elements of N T {ɛ}. A node with lbel A hs subtree A X 1 X 2... X n only if A is non-terminl nd there is production where X i T N. A X 1 X 2 X n All leves of the tree together red from left to right form the string derived, nmely bbb. This is clled the frontier of the derivtion tree. We will s well consider derivtion trees not ending in string of terminls, so the frontier is n element of (T N). CS 275 Sect. II / 81

9 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Definition Derivtion Tree Definition Let G = (T, N, S, P) be CFG. A derivtion tree or prse tree for G is finite tree with nodes lbelled by elements of N T {ɛ}, s.t. node A hs children with lbels X 1,..., X n only if A N nd there is production A X 1 X 2 X n If the node of one of the children of A is ɛ, then this node is the only child of this tree. The frontier of the tree is the set of leves red from left to right in sequence, which is n element (T N). The root of the tree is the node t the to of the derivtion tree. CS 275 Sect. II / 81

10 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Left-Most nd Right-Most Derivtions From derivtion tree we cn obtin derivtion in vrious orders. Consider the grmmr grmmr G terminls nonterminls strt symbol productions, b S, A, B S S AB, A A, A B bbb, B b CS 275 Sect. II / 81

11 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Derivtion Tree S A B A b B b b CS 275 Sect. II / 81

12 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Different Derivtions of bbb We cn derive bbb in different wys: S AB AB B bbb bbb A left most derivtion S AB AbBb Abbb Abbb bbb A right most derivtion S AB AB AbBb bbb bbb S AB AB AbBb Abbb bbb S AB AbBb AbBb bbb bbb S AB AbBb AbBb Abbb bbb CS 275 Sect. II / 81

13 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Left-Most Derivtion Definition Let G = (T, N, S, P) be CFG. A single-step derivtion w w is left-most if rule ws pplied to the left-most non-terminl in w, i.e. w = sat for some A N, s T (consisting only of terminls), t (S T ), nd there exist production A v s.t. w = svt. CS 275 Sect. II / 81

14 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Left-Most Derivtion Definition Let G = (T, N, S, P) be CFG. A single-step derivtion w w is right-most if rule ws pplied to the right-most non-terminl in w, i.e. w = sat for some A N, s (S T ), t T (consisting only of terminls), there exist production A v s.t. w = svt. CS 275 Sect. II / 81

15 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Left/Right-Most Derivtion Sequence Definition Let G = (T, N, S, P) be CFG 1. A derivtion sequence w 0 w 1 w 2 w n is left-most, if ech derivtion step w i w i+1 is left-most. 2. Right-most derivtion sequences re defined nlogously. CS 275 Sect. II / 81

16 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Theorem II (Derivtion Trees nd Lnguge Genertion) Theorem Let G = (T, N, S, P) be CFG, A T, w, w (T N), Then the following re equivlent (1) There exist derivtion tree with root lbelled by A nd frontier w. (2) A w. In cse w T, the derivtion sequence w w cn both be chosen s left-most nd s right-most derivtion sequence CS 275 Sect. II / 81

17 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Proof of Theorem II A proof of this theorem cn be found in the dditionl mteril. We illustrte this theorem by n exmple. We will first present left-most derivtion. Then we will present right most derivtion. CS 275 Sect. II / 81

18 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 1) S S A B A b B b b CS 275 Sect. II / 81

19 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 2) S AB S A B A b B b b CS 275 Sect. II / 81

20 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 3) S AB AB S A B A b B b b Derivtion tree for is trivil. CS 275 Sect. II / 81

21 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 4) S AB AB B S A B A b B b b CS 275 Sect. II / 81

22 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 5) S AB AB B bbb S A B A b B b b CS 275 Sect. II / 81

23 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Left-Most Derivtion (Step 6) S AB AB B bbb bbb S A B A b B b b Finl derivtion. CS 275 Sect. II / 81

24 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 1) S S A B A b B b b CS 275 Sect. II / 81

25 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 2) S AB S A B A b B b b CS 275 Sect. II / 81

26 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 3) S AB AbBb S A B A b B b b CS 275 Sect. II / 81

27 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 4) S AB AbBb Abbb S A B A b B b b CS 275 Sect. II / 81

28 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 5) S AB AbBb Abbb Abbb S A B A b B b b CS 275 Sect. II / 81

29 II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) Exmple Right-Most Derivtion (Step 6) S AB AbBb Abbb Abbb bbb S A B A b B b b CS 275 Sect. II / 81

30 II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.4. The Pumping Lemm for CFG (14.4) II.5.5. Floyd s Theorem CS 275 Sect. II / 81

31 II.5.2. Uniqueness of Derivtion Trees (14.1) Theorem II Uniqueness of Derivtion (Trees) Theorem (II.5.2.4) Let G = (T, N, S, P) be CFG. The following re equivlent: (1) For every w T there exist t most one derivtion tree with lbel S nd frontier w. (2) For every w T there exist t most one left-most derivtion sequence S w. (3) For every w T there exist t most one right-most derivtion sequence S w. Proof: See Additionl Mteril. CS 275 Sect. II / 81

32 II.5.2. Uniqueness of Derivtion Trees (14.1) Ambiguous Grmmrs Definition A CFG G = (T, N, S, P) is mbiguous, if there is string w L(G) hving more thn one derivtion tree (or, equivlently, hving more thn one left-most or right-most derivtion). CS 275 Sect. II / 81

33 II.5.2. Uniqueness of Derivtion Trees (14.1) Exmple 1 grmmr terminls nonterminls strt symbol productions G S, b S S S S b S b CS 275 Sect. II / 81

34 II.5.2. Uniqueness of Derivtion Trees (14.1) Exmple 1 There re two left-most derivtions of b: S S b nd S b And two derivtion trees: S S S b b CS 275 Sect. II / 81

35 II.5.2. Uniqueness of Derivtion Trees (14.1) Exmple 2: Dngling Else Assume the following grmmr which is cut down version of the grmmr G while introduced in I.2.4 with if then else fi replced by if then nd if then else ): grmmr import G Dngling else terminls if, then, else, := nonterminls strt symbol productions G Identifier, G Arithmetic Expression, G Boolen Expression Progrm Progrm Progrm Id := AExp Progrm if BExp then Progrm else Progrm Progrm if BExp then Progrm import mens tht we dd ll the ingredients of the grmmrs mentioned, including the terminls The grmmrs G Identifier, G Arithmetic Expression, G Boolen Expression hve strt symbols Id, AExp, BExp, respectively. CS 275 Sect. II / 81

36 II.5.2. Uniqueness of Derivtion Trees (14.1) Exmple 2: Dngling Else Assume strings b 1, b 2 deriving from BExp nd string s 1, s 2 deriving from Progrm. The string if b 1 then if b 2 then s 1 else s 2 hs two derivtion trees (we omit the derivtion trees for b i, s i.) CS 275 Sect. II / 81

37 II.5.2. Uniqueness of Derivtion Trees (14.1) First Derivtion Tree Progrm if BExp then Progrm b 1 if BExp then Progrm else Progrm b 2 s 1 s 2 CS 275 Sect. II / 81

38 II.5.2. Uniqueness of Derivtion Trees (14.1) Second Derivtion Tree Progrm if BExp then Progrm else Progrm b 1 if BExp then Progrm s 2 b 2 s 1 CS 275 Sect. II / 81

39 II.5.2. Uniqueness of Derivtion Trees (14.1) Different Interprettions of the Progrm The two different derivtion trees of the progrm if b 1 then if b 2 then s 1 else s 2 correspond to two different wys of executing the progrm: CS 275 Sect. II / 81

40 II.5.2. Uniqueness of Derivtion Trees (14.1) Execution following the Derivtion Tree 1 In the first the else cse belongs to the second if. It is executed if b 1 is true nd b 2 is flse. The progrm cn be using suggestive indenttion be written s follows: if b 1 then if b 2 then s 1 else s 2 CS 275 Sect. II / 81

41 II.5.2. Uniqueness of Derivtion Trees (14.1) Execution following the Derivtion Tree 2 In the second derivtion tree, the else cse belongs to the first if. It is executed if b 1 is flse. The progrm cn be using suggestive indenttion be written s follows: if b 1 then if b 2 else s 2 then s 1 CS 275 Sect. II / 81

42 II.5.2. Uniqueness of Derivtion Trees (14.1) 2 Solutions for Solving the Problem There re 2 solutions for solving this problem. The first solution is to dd to if then nd if then else symbol fi (or some other keyword such s endif). lbelling the end of the sttement. grmmr import G Unmbiguous if terminls if, then, else, := nonterminls strt symbol productions G Identifier, G Arithmetic Expression, G Boolen Expression Progrm Progrm Progrm Id := AExp Progrm if BExp then Progrm else Progrm fi Progrm if BExp then Progrm fi CS 275 Sect. II / 81

43 II.5.2. Uniqueness of Derivtion Trees (14.1) Solution 1 Now the two interprettions of the originl string would be written in s two different strings: Else belonging to the second if is written s if b 1 then if b 2 then s 1 else s 2 fi fi Else belong to the first if is written s if b 1 then if b 2 then s 1 fi else s 2 fi This solution hs been tken for instnce in Algol, in the bsh shell (Linux), nd in Ad (where fi is replced by end if ). CS 275 Sect. II / 81

44 II.5.2. Uniqueness of Derivtion Trees (14.1) Solution 2 The 2nd solution is to modify the grmmr so tht the derivtion tree will be possible only for one of the two choices. For this we modify the grmmr so tht the sttement s 1 in if b 1 then s 1 else s 2 is not mtched by if b 1 then s 1 but only by if b 1 then s 1 else s 2 This solution hs been tken in most other progrmming lnguges. CS 275 Sect. II / 81

45 II.5.2. Uniqueness of Derivtion Trees (14.1) Solution 2 For this we split Progrms into two ctegories: Those derived from MtchedIf. In progrm deriving from MtchedIf, ech if is mtched by n else cluse. Those derived from UnmtchedIf. These hve t lest one if with no mtching else cluse. CS 275 Sect. II / 81

46 Solution 2 The grmmr will mke sure tht else will lwys be ssocited with the first if to the left, which hs no unmtched else yet. So if then mthbf else expression will be prsed s in the first derivtion tree.

47 Solution 2 Here is the grmmr: grmmr import G Dngling Else terminls if, then, else, := nonterminls strt symbol G Identifier, G Arithmetic Expression, G Boolen Expression Progrm Progrm productions Progrm UnmtchedIf Progrm MtchedIf MtchedIf Id := AExp MtchedIf if BExp then MtchedIf else MtchedIf UnmtchedIf if BExp then Progrm UnmtchedIf if BExp then MtchedIf else UnmtchedIf

48 II.5.2. Uniqueness of Derivtion Trees (14.1) Unique Derivtion Tree 2nd Solution Progrm UnmtchedIf if BExp then Progrm b 1 MtchedIf if BExp then MtchedIf else MtchedIf b 2 s 1 s 2 CS 275 Sect. II / 81

49 II.5.2. Uniqueness of Derivtion Trees (14.1) Exmple: Grmmr for Arithmetic Expressions Remember the grmmr for rithmetic expressions (using elements of BNF nottion) grmmr import G Arithmetic Expression G Identifier, G Number terminls +,,, /, (, ) nonterminls strt symbol AExp, AOp AExp productions AExp Id Number AExp ( AExp ) AExp AExp AOp AExp AOp + / CS 275 Sect. II / 81

50 II.5.2. Uniqueness of Derivtion Trees (14.1) First Prse tree for AExp AExp AOp AExp AExp AOp AExp Number Number + Number CS 275 Sect. II / 81

51 II.5.2. Uniqueness of Derivtion Trees (14.1) Second Prse tree for AExp AExp AOp AExp Number + AExp AOp AExp 2 Number Number 3 4 CS 275 Sect. II / 81

52 II.5.2. Uniqueness of Derivtion Trees (14.1) Difference in Evlution The first prse tree corresponds to prsing it s if it were (2 + 3) 4 Evlution will return 20. The second prse tree corresponds to prsing it s if it were 2 + (3 4) Evlution will return 14. CS 275 Sect. II / 81

53 II.5.2. Uniqueness of Derivtion Trees (14.1) Unmbiguous Version grmmr import Arithmetic Expression Gunmbiguous G Identifier, G Number terminls +,,, /, (, ) nonterminls strt symbol AExp, Term, Fctor AExp productions AExp AExp + Term AExp Term Term Term Term Fctor Term/Fctor Fctor Fctor Id Number ( AExp ) CS 275 Sect. II / 81

54 II.5.2. Uniqueness of Derivtion Trees (14.1) Arithmetic Expression Unique Prse Tree for in Gunmbiguous AExp AExp + Term Term Term Fctor Fctor Fctor Number Number Number CS 275 Sect. II / 81

55 II.5.2. Uniqueness of Derivtion Trees (14.1) Mking Context Free Grmmrs Unmbiguous The following is known bout Context Free Grmmrs: There re lnguges defined by context free grmmrs which cnnot be defined by n unmbiguous grmmr. Context free grmmrs, for which there exist no equivlent unmbiguous grmmr, re clled inherently mbiguous grmmrs. See Hopcroft/Motwni/Ullmn, 5.4.4, p It is undecidble whether grmmr is mbiguous. (Sme book, 7.4.5, p. 307.) It is undecidble whether grmmr is inherently mbiguous grmmrs. (Sme book, nd 9.5.2, p. 413). CS 275 Sect. II / 81

56 II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.2. Norml Forms for Context-Free Grmmrs (14.2) This section hs been moved to Additionl Mteril. CS 275 Sect. II / 81

57 II.5.4. The Pumping Lemm for CFG (14.4) II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.4. The Pumping Lemm for CFG (14.4) II.5.5. Floyd s Theorem CS 275 Sect. II / 81

58 II.5.4. The Pumping Lemm for CFG (14.4) Ide of the Pumping Lemm for CFG The Pumping Lemm for Regulr Lnguges is bsed on the fct tht if string derived by finite stte utomton is sufficiently big, we pss through t lest one stte twice. We could equivlently hve used the fct tht in left- or right-liner grmmr, if string derived is sufficiently big, we pss through one non-terminl t lest twice. For CFG, we need tht if string derived is sufficiently big, we pss through one non-terminl t lest twice. However, if this occurrence is in two disjoint subtrees of the derivtion trees, there is no reltion between them. Wht we need tht there is pth in the subtree which psses through one non-terminl t lest twice. CS 275 Sect. II / 81

59 II.5.4. The Pumping Lemm for CFG (14.4) Picture S D A D i D j A u v w x y CS 275 Sect. II / 81

60 II.5.4. The Pumping Lemm for CFG (14.4) Ide of the Pumping Lemm for CFG If in derivtion tree of CFG with l non-terminls there is no repetition of non-terminl in ny pth, then the tree cn hve height t most l. Here the height of tree consisting of the root only is defined s 0. Since t ny node of derivtion tree there re only finitely mny rules to pply to, one cn esily see tht there re only finitely mny derivtion trees in CFG with height t most l + 1 nd rbitrry non-terminl s root. Let k be the mximum length of ny string derived from ny non-terminl with height t most l + 1. Let k := k + 1. Assume derivtion of string z with z k. We cn omit in the derivtion ny subderivtions where A A nd this derivtion tkes more thn one step. The derivtion must hve height l + 1, nd therefore contin subderivtion of height exctly l + 1 of string from some non-terminl. CS 275 Sect. II / 81

61 II.5.4. The Pumping Lemm for CFG (14.4) Picture S D A D i D j A u v w x y CS 275 Sect. II / 81

62 II.5.4. The Pumping Lemm for CFG (14.4) Ide of the Pumping Lemm for CFG In this subderivtion there is pth from the root to terminl, in which t lest one non-terminl A occurs twice. And we cn hve tht subtree strting with upper occurrence of A hs height l + 1. Therefore the string derived from tht A hs length t most k < k. Let w be the string deriving from the lower A, vwx be the string deriving from the upper A, with v nd x deriving to the left nd right of the lower A, z = uvwxy, with u, y, deriving to the left nd right of the upper A, Then vwx k < k. CS 275 Sect. II / 81

63 II.5.4. The Pumping Lemm for CFG (14.4) Picture S D A D i D j A u v w x y CS 275 Sect. II / 81

64 II.5.4. The Pumping Lemm for CFG (14.4) Ide of the Pumping Lemm for CFG So for ny CFG G we cn find constnt k s.t. in ny derivtion tree of word z L(G) s.t. z k, we cn decompose z = uvwxy find nonterminl A, nd derivtions S uay (written blue on the next slide), A vax (written green on the next slide), A w (written red on the next slide) The subderivtion A vax plys the role of the loop we hd in the pumping lemm for regulr lnguges. Furthermore the middle prt vwx cn be chosen to be of length k. vx ɛ since we omited subderivtions A A tking more thn one step. The following pictures don t come out well on the blck nd white hndouts. Plese look t them on the online version. CS 275 Sect. II / 81

65 II.5.4. The Pumping Lemm for CFG (14.4) Picture S D A D i D j A u v w x y CS 275 Sect. II / 81

66 II.5.4. The Pumping Lemm for CFG (14.4) Ide of the Pumping Lemm for CFG Now we cn repet the subderivtion A vax severl times nd obtin S uay uvaxy uvvaxxy uv i Ax i y uv i vx i y And therefore we obtin tht for ll i 0 we hve uv i vx i y L(G) CS 275 Sect. II / 81

67 II.5.4. The Pumping Lemm for CFG (14.4) Pumping it up to uv 3 vx 3 y S A A A u v A x y v x v w x CS 275 Sect. II / 81

68 II.5.4. The Pumping Lemm for CFG (14.4) Pumping it down to uv 0 vx 0 yy S A w u y CS 275 Sect. II / 81

69 II.5.4. The Pumping Lemm for CFG (14.4) Pumping Lemm for CFG Theorem Let L be context free lnguge. Then there exists constnt k s.t. for ll strings z of L s.t. z k there exist u, v, w, x, y s.t. z = uvwxy, vwx k, i.e. the middle portion is not too long, vx 1, i.e. v or x re not ɛ, i 0.uv i wx i y L. CS 275 Sect. II / 81

70 II.5.4. The Pumping Lemm for CFG (14.4) Proof of the Pumping Lemm for CFG A forml proof cn be found in the Additionl Mteril CS 275 Sect. II / 81

71 II.5.4. The Pumping Lemm for CFG (14.4) Exmple 1 Lemm The lnguge L = { i b i c i i 0} is not context free. CS 275 Sect. II / 81

72 II.5.4. The Pumping Lemm for CFG (14.4) Proof (Exmple 1) Assume L is context free. Let k be the constnt from the pumping lemm. Let z := k b k c k L. By the pumping lemm, z = uvwxy s.t. vwx k, vx 1 nd i 0.uv i wx i y L. If v contins s nd b s or b s nd c s, uv 2 wx 2 y is not n element of b b (i.e. the lnguge defined by this regulr expression), since there is n fter b or b fter c. Therefore v is prt of k, b k or c k, similrly for x. But now uv 2 wx 2 y = k+i b k+j c k+l where t most 2 of (i, j, l) cn be 0, nd t lest one is 0. But then k+i b k+j c k+l L, contrdiction. CS 275 Sect. II / 81

73 II.5.4. The Pumping Lemm for CFG (14.4) Exmple 2 Lemm The lnguge L = { n b m n b m n, m 0} is not context free. CS 275 Sect. II / 81

74 II.5.4. The Pumping Lemm for CFG (14.4) Proof (Exmple 2) Assume L is context free. Let k be the constnt from the pumping lemm. Let z := k b k k b k L. By the pumping lemm, z = uvwxy s.t. vwx k, vx 1 nd i 0.uv i wx i y L. If v contins both s nd b s uv 2 wx 2 y is not n element of b b, since there re more thn 3 switches between s nd bs. Therefore v is prt of one of the subwords k, b k, similrly for x. But now uv 2 wx 2 y = k+i b k+j k+l b k+m where t most 2 of (i, j, l, m) cn be 0, if there re two they re consecutive, t lest one is 0. But then k+i b k+j k+l b k+m L, contrdiction. CS 275 Sect. II / 81

75 II.5.4. The Pumping Lemm for CFG (14.4) Exmple 3 Lemm The lnguge L = {ww w {, b} } is not context free. CS 275 Sect. II / 81

76 II.5.4. The Pumping Lemm for CFG (14.4) Proof (Exmple 3) We use the fct tht the intersection of context free nd regulr grmmr is context free. This fct is not shown in this module. It cn be shown using the equivlence of context free lnguges nd lnguges definble by Push Down Automt. If L were context free, so were L := L ( b b ). But L is just the lnguge of Exmple 2, which is not context free, contrdiction. CS 275 Sect. II / 81

77 II.5.4. The Pumping Lemm for CFG (14.4) Intersection of CFG In Exmple 3 we used the fct tht the intersection of context free nd regulr lnguge is context free. The intersection of two context free lnguges is in generl not context free: Consider L 1 := { n b n c m n, m N} L 2 := { n b m c m n, m N} Both L 1, L 2 re context free. However L 1 L 2 = { n b n c n n N} which is th lnguge of Exmple 1 which is not context free. CS 275 Sect. II / 81

78 II.5.5. Floyd s Theorem II.5.1. Derivtion Trees for Context-Free Grmmrs (14.1) II.5.2. Uniqueness of Derivtion Trees (14.1) II.5.4. The Pumping Lemm for CFG (14.4) II.5.5. Floyd s Theorem CS 275 Sect. II / 81

79 II.5.5. Floyd s Theorem Repetition of words is not context free We hve seen in Exmple 3 of II.5.4 (using Pumping Lemm for Context Free Grmmrs), tht is not context free. L := {ww w {, b} } Note tht {ww R w {, b} } is context free. A progrm lnguge which expresses tht vrible needs to be declred before contins s sublnguge L. More precisely, if we hd context free grmmr for such lnguge, we could derive from it context free grmmr for L. This cn be generlised to Floyd s theorem. CS 275 Sect. II / 81

80 II.5.5. Floyd s Theorem II.5.5. Floyd s Theorem Theorem Under wek ssumptions progrmming lnguge, which requires tht vribles need to be declred before used, cnnot be defined by context free grmmr. A precise formultion nd proof of Floyd s theorem cn be found in Additionl Mteril. CS 275 Sect. II / 81

81 II.5.5. Floyd s Theorem II.5.5. Floyd s Theorem Therefore most progrmming lnguges cnnot be defined by context free grmmr. However, one cn define in most cses context free grmmr defining the bsic syntx of lnguge. Grmmr llows to define prse tree. Lnguges which re defined by this grmmr re those which cn be prsed in such wy. Then one dds progrm, which fterwrds checks semntic properties of the progrm, E.g. tht vrible is declred before being used. Or even more complicted fetures such s correctness of type checking. Full detils cn be found in the Additionl Mteril. CS 275 Sect. II / 81

82 II.5.5. Floyd s Theorem Chpter II.6.: Push Down Automt This Chpter will not be tught this yer. CS 275 Sect. II / 81

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 Automt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Problem (II) Chpter II.6.: Push Down Automt Remrk: This mteril is no longer tught nd not directly exm relevnt Anton Setzer (Bsed

More information

1.4 Nonregular Languages

1.4 Nonregular Languages 74 1.4 Nonregulr Lnguges The number of forml lnguges over ny lphbet (= decision/recognition problems) is uncountble On the other hnd, the number of regulr expressions (= strings) is countble Hence, ll

More information

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir

For convenience, we rewrite m2 s m2 = m m m ; where m is repeted m times. Since xyz = m m m nd jxyj»m, we hve tht the string y is substring of the fir CSCI 2400 Models of Computtion, Section 3 Solutions to Homework 4 Problem 1. ll the solutions below refer to the Pumping Lemm of Theorem 4.8, pge 119. () L = f n b l k : k n + lg Let's ssume for contrdiction

More information

1.3 Regular Expressions

1.3 Regular Expressions 56 1.3 Regulr xpressions These hve n importnt role in describing ptterns in serching for strings in mny pplictions (e.g. wk, grep, Perl,...) All regulr expressions of lphbet re 1.Ønd re regulr expressions,

More information

Automata and Languages

Automata and Languages Automt nd Lnguges Prof. Mohmed Hmd Softwre Engineering Lb. The University of Aizu Jpn Grmmr Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Regulr Lnguges Context Free Lnguges Context Sensitive

More information

Closure Properties of Regular Languages

Closure Properties of Regular Languages Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L

More information

Lecture 6 Regular Grammars

Lecture 6 Regular Grammars Lecture 6 Regulr Grmmrs COT 4420 Theory of Computtion Section 3.3 Grmmr A grmmr G is defined s qudruple G = (V, T, S, P) V is finite set of vribles T is finite set of terminl symbols S V is specil vrible

More information

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages

Grammar. Languages. Content 5/10/16. Automata and Languages. Regular Languages. Regular Languages 5//6 Grmmr Automt nd Lnguges Regulr Grmmr Context-free Grmmr Context-sensitive Grmmr Prof. Mohmed Hmd Softwre Engineering L. The University of Aizu Jpn Regulr Lnguges Context Free Lnguges Context Sensitive

More information

Parse trees, ambiguity, and Chomsky normal form

Parse trees, ambiguity, and Chomsky normal form Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs

More information

Context-Free Grammars and Languages

Context-Free Grammars and Languages Context-Free Grmmrs nd Lnguges (Bsed on Hopcroft, Motwni nd Ullmn (2007) & Cohen (1997)) Introduction Consider n exmple sentence: A smll ct ets the fish English grmmr hs rules for constructing sentences;

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines CI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 16: Non-Context-Free Lnguges Chpter 16: Non-Context-Free Lnguges I. Theory of utomt II. Theory of Forml Lnguges III. Theory of Turing Mchines

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages C 314 Principles of Progrmming Lnguges Lecture 6: LL(1) Prsing Zheng (Eddy) Zhng Rutgers University Ferury 5, 2018 Clss Informtion Homework 2 due tomorrow. Homework 3 will e posted erly next week. 2 Top

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. Mary Cryan. 21 September School of Informatics University of Edinburgh Finite Automt Informtics 2A: Lecture 3 Mry Cryn School of Informtics University of Edinburgh mcryn@inf.ed.c.uk 21 September 2018 1 / 30 Lnguges nd Automt Wht is lnguge? Finite utomt: recp Some forml definitions

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh

Finite Automata. Informatics 2A: Lecture 3. John Longley. 22 September School of Informatics University of Edinburgh Lnguges nd Automt Finite Automt Informtics 2A: Lecture 3 John Longley School of Informtics University of Edinburgh jrl@inf.ed.c.uk 22 September 2017 1 / 30 Lnguges nd Automt 1 Lnguges nd Automt Wht is

More information

First Midterm Examination

First Midterm Examination Çnky University Deprtment of Computer Engineering 203-204 Fll Semester First Midterm Exmintion ) Design DFA for ll strings over the lphet Σ = {,, c} in which there is no, no nd no cc. 2) Wht lnguge does

More information

THEOTY OF COMPUTATION

THEOTY OF COMPUTATION Pushdown utomt nd Prsing lgorithms: Pushdown utomt nd context-free lnguges; Deterministic PDNondeterministic PD- Equivlence of PD nd CFG-closure properties of CFL. PUSHDOWN UTOMT ppliction: Regulr lnguges

More information

CSC 473 Automata, Grammars & Languages 11/9/10

CSC 473 Automata, Grammars & Languages 11/9/10 CSC 473 utomt, Grmmrs & Lnguges 11/9/10 utomt, Grmmrs nd Lnguges Discourse 06 Decidbility nd Undecidbility Decidble Problems for Regulr Lnguges Theorem 4.1: (embership/cceptnce Prob. for DFs) = {, w is

More information

First Midterm Examination

First Midterm Examination 24-25 Fll Semester First Midterm Exmintion ) Give the stte digrm of DFA tht recognizes the lnguge A over lphet Σ = {, } where A = {w w contins or } 2) The following DFA recognizes the lnguge B over lphet

More information

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages

Assignment 1 Automata, Languages, and Computability. 1 Finite State Automata and Regular Languages Deprtment of Computer Science, Austrlin Ntionl University COMP2600 Forml Methods for Softwre Engineering Semester 2, 206 Assignment Automt, Lnguges, nd Computility Smple Solutions Finite Stte Automt nd

More information

Harvard University Computer Science 121 Midterm October 23, 2012

Harvard University Computer Science 121 Midterm October 23, 2012 Hrvrd University Computer Science 121 Midterm Octoer 23, 2012 This is closed-ook exmintion. You my use ny result from lecture, Sipser, prolem sets, or section, s long s you quote it clerly. The lphet is

More information

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38

Theory of Computation Regular Languages. (NTU EE) Regular Languages Fall / 38 Theory of Computtion Regulr Lnguges (NTU EE) Regulr Lnguges Fll 2017 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of Finite Automt A finite utomton hs finite set of control

More information

Theory of Computation Regular Languages

Theory of Computation Regular Languages Theory of Computtion Regulr Lnguges Bow-Yw Wng Acdemi Sinic Spring 2012 Bow-Yw Wng (Acdemi Sinic) Regulr Lnguges Spring 2012 1 / 38 Schemtic of Finite Automt control 0 0 1 0 1 1 1 0 Figure: Schemtic of

More information

CS 330 Formal Methods and Models

CS 330 Formal Methods and Models CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 2 1. Prove ((( p q) q) p) is tutology () (3pts) y truth tle. p q p q

More information

FABER Formal Languages, Automata and Models of Computation

FABER Formal Languages, Automata and Models of Computation DVA337 FABER Forml Lnguges, Automt nd Models of Computtion Lecture 5 chool of Innovtion, Design nd Engineering Mälrdlen University 2015 1 Recp of lecture 4 y definition suset construction DFA NFA stte

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch. Overview H9 Vertlerouw H 9: Prsing: op-down & LL(1) do 3 mei 2001 56 heo Ruys h. 8 - Prsing 8.1 ontext-free Grmmrs 8.2 op-down Prsing 8.3 LL(1) Grmmrs See lso [ho, Sethi & Ullmn 1986] for more thorough

More information

More on automata. Michael George. March 24 April 7, 2014

More on automata. Michael George. March 24 April 7, 2014 More on utomt Michel George Mrch 24 April 7, 2014 1 Automt constructions Now tht we hve forml model of mchine, it is useful to mke some generl constructions. 1.1 DFA Union / Product construction Suppose

More information

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER LANGUAGES AND COMPUTATION ANSWERS The University of Nottinghm SCHOOL OF COMPUTER SCIENCE LEVEL 2 MODULE, SPRING SEMESTER 2016 2017 LNGUGES ND COMPUTTION NSWERS Time llowed TWO hours Cndidtes my complete the front cover of their nswer ook

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tle of Contents: Week 1: Preliminries (set lger, reltions, functions) (red Chpters 1-4) Weeks

More information

Handout: Natural deduction for first order logic

Handout: Natural deduction for first order logic MATH 457 Introduction to Mthemticl Logic Spring 2016 Dr Json Rute Hndout: Nturl deduction for first order logic We will extend our nturl deduction rules for sententil logic to first order logic These notes

More information

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1

Non-Deterministic Finite Automata. Fall 2018 Costas Busch - RPI 1 Non-Deterministic Finite Automt Fll 2018 Costs Busch - RPI 1 Nondeterministic Finite Automton (NFA) Alphbet ={} q q2 1 q 0 q 3 Fll 2018 Costs Busch - RPI 2 Nondeterministic Finite Automton (NFA) Alphbet

More information

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30

Talen en Automaten Test 1, Mon 7 th Dec, h45 17h30 Tlen en Automten Test 1, Mon 7 th Dec, 2015 15h45 17h30 This test consists of four exercises over 5 pges. Explin your pproch, nd write your nswer to ech exercise on seprte pge. You cn score mximum of 100

More information

The Regulated and Riemann Integrals

The Regulated and Riemann Integrals Chpter 1 The Regulted nd Riemnn Integrls 1.1 Introduction We will consider severl different pproches to defining the definite integrl f(x) dx of function f(x). These definitions will ll ssign the sme vlue

More information

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions

CS 330 Formal Methods and Models Dana Richards, George Mason University, Spring 2016 Quiz Solutions CS 330 Forml Methods nd Models Dn Richrds, George Mson University, Spring 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Ferury 9 1. (4pts) ((p q) (q r)) (p r), prove tutology using truth tles. p

More information

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute

Anatomy of a Deterministic Finite Automaton. Deterministic Finite Automata. A machine so simple that you can understand it in less than one minute Victor Admchik Dnny Sletor Gret Theoreticl Ides In Computer Science CS 5-25 Spring 2 Lecture 2 Mr 3, 2 Crnegie Mellon University Deterministic Finite Automt Finite Automt A mchine so simple tht you cn

More information

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.)

CS 373, Spring Solutions to Mock midterm 1 (Based on first midterm in CS 273, Fall 2008.) CS 373, Spring 29. Solutions to Mock midterm (sed on first midterm in CS 273, Fll 28.) Prolem : Short nswer (8 points) The nswers to these prolems should e short nd not complicted. () If n NF M ccepts

More information

Lecture 09: Myhill-Nerode Theorem

Lecture 09: Myhill-Nerode Theorem CS 373: Theory of Computtion Mdhusudn Prthsrthy Lecture 09: Myhill-Nerode Theorem 16 Ferury 2010 In this lecture, we will see tht every lnguge hs unique miniml DFA We will see this fct from two perspectives

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

Finite Automata-cont d

Finite Automata-cont d Automt Theory nd Forml Lnguges Professor Leslie Lnder Lecture # 6 Finite Automt-cont d The Pumping Lemm WEB SITE: http://ingwe.inghmton.edu/ ~lnder/cs573.html Septemer 18, 2000 Exmple 1 Consider L = {ww

More information

SWEN 224 Formal Foundations of Programming WITH ANSWERS

SWEN 224 Formal Foundations of Programming WITH ANSWERS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Time Allowed: 3 Hours EXAMINATIONS 2011 END-OF-YEAR SWEN 224 Forml Foundtions of Progrmming

More information

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun:

NFAs and Regular Expressions. NFA-ε, continued. Recall. Last class: Today: Fun: CMPU 240 Lnguge Theory nd Computtion Spring 2019 NFAs nd Regulr Expressions Lst clss: Introduced nondeterministic finite utomt with -trnsitions Tody: Prove n NFA- is no more powerful thn n NFA Introduce

More information

Before we can begin Ch. 3 on Radicals, we need to be familiar with perfect squares, cubes, etc. Try and do as many as you can without a calculator!!!

Before we can begin Ch. 3 on Radicals, we need to be familiar with perfect squares, cubes, etc. Try and do as many as you can without a calculator!!! Nme: Algebr II Honors Pre-Chpter Homework Before we cn begin Ch on Rdicls, we need to be fmilir with perfect squres, cubes, etc Try nd do s mny s you cn without clcultor!!! n The nth root of n n Be ble

More information

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS

CS 310 (sec 20) - Winter Final Exam (solutions) SOLUTIONS CS 310 (sec 20) - Winter 2003 - Finl Exm (solutions) SOLUTIONS 1. (Logic) Use truth tles to prove the following logicl equivlences: () p q (p p) (q q) () p q (p q) (p q) () p q p q p p q q (q q) (p p)

More information

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines

I. Theory of Automata II. Theory of Formal Languages III. Theory of Turing Machines CI 3104 /Winter 2011: Introduction to Forml Lnguges Chter 13: Grmmticl Formt Chter 13: Grmmticl Formt I. Theory of Automt II. Theory of Forml Lnguges III. Theory of Turing Mchines Dr. Neji Zgui CI3104-W11

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton 25. Finite Automt AUTOMATA AND LANGUAGES A system of computtion tht only hs finite numer of possile sttes cn e modeled using finite utomton A finite utomton is often illustrted s stte digrm d d d. d q

More information

TREE AUTOMATA AND TREE GRAMMARS

TREE AUTOMATA AND TREE GRAMMARS TREE AUTOMATA AND TREE GRAMMARS rxiv:1510.02036v1 [cs.fl] 7 Oct 2015 by Joost Engelfriet DAIMI FN-10 April 1975 Institute of Mthemtics, University of Arhus DEPARTMENT OF COMPUTER SCIENCE Ny Munkegde, 8000

More information

Coalgebra, Lecture 15: Equations for Deterministic Automata

Coalgebra, Lecture 15: Equations for Deterministic Automata Colger, Lecture 15: Equtions for Deterministic Automt Julin Slmnc (nd Jurrin Rot) Decemer 19, 2016 In this lecture, we will study the concept of equtions for deterministic utomt. The notes re self contined

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

Lecture 08: Feb. 08, 2019

Lecture 08: Feb. 08, 2019 4CS4-6:Theory of Computtion(Closure on Reg. Lngs., regex to NDFA, DFA to regex) Prof. K.R. Chowdhry Lecture 08: Fe. 08, 2019 : Professor of CS Disclimer: These notes hve not een sujected to the usul scrutiny

More information

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA

PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA PART 2. REGULAR LANGUAGES, GRAMMARS AND AUTOMATA RIGHT LINEAR LANGUAGES. Right Liner Grmmr: Rules of the form: A α B, A α A,B V N, α V T + Left Liner Grmmr: Rules of the form: A Bα, A α A,B V N, α V T

More information

1 From NFA to regular expression

1 From NFA to regular expression Note 1: How to convert DFA/NFA to regulr expression Version: 1.0 S/EE 374, Fll 2017 Septemer 11, 2017 In this note, we show tht ny DFA cn e converted into regulr expression. Our construction would work

More information

CS375: Logic and Theory of Computing

CS375: Logic and Theory of Computing CS375: Logic nd Theory of Computing Fuhu (Frnk) Cheng Deprtment of Computer Science University of Kentucky 1 Tble of Contents: Week 1: Preliminries (set lgebr, reltions, functions) (red Chpters 1-4) Weeks

More information

Bernoulli Numbers Jeff Morton

Bernoulli Numbers Jeff Morton Bernoulli Numbers Jeff Morton. We re interested in the opertor e t k d k t k, which is to sy k tk. Applying this to some function f E to get e t f d k k tk d k f f + d k k tk dk f, we note tht since f

More information

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama

Homework 4. 0 ε 0. (00) ε 0 ε 0 (00) (11) CS 341: Foundations of Computer Science II Prof. Marvin Nakayama CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 4 1. UsetheproceduredescriedinLemm1.55toconverttheregulrexpression(((00) (11)) 01) into n NFA. Answer: 0 0 1 1 00 0 0 11 1 1 01 0 1 (00)

More information

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!)

CMSC 330: Organization of Programming Languages. DFAs, and NFAs, and Regexps (Oh my!) CMSC 330: Orgniztion of Progrmming Lnguges DFAs, nd NFAs, nd Regexps (Oh my!) CMSC330 Spring 2018 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All

More information

Normal Forms for Context-free Grammars

Normal Forms for Context-free Grammars Norml Forms for Context-free Grmmrs 1 Linz 6th, Section 6.2 wo Importnt Norml Forms, pges 171--178 2 Chomsky Norml Form All productions hve form: A BC nd A vrile vrile terminl 3 Exmples: S AS S AS S S

More information

Tutorial Automata and formal Languages

Tutorial Automata and formal Languages Tutoril Automt nd forml Lnguges Notes for to the tutoril in the summer term 2017 Sestin Küpper, Christine Mik 8. August 2017 1 Introduction: Nottions nd sic Definitions At the eginning of the tutoril we

More information

Formal Languages Simplifications of CFGs

Formal Languages Simplifications of CFGs Forml Lnguges implifictions of CFGs ubstitution Rule Equivlent grmmr b bc ubstitute b bc bbc b 2 ubstitution Rule b bc bbc ubstitute b bc bbc bc Equivlent grmmr 3 In generl: xz y 1 ubstitute y 1 xz xy1z

More information

Homework 3 Solutions

Homework 3 Solutions CS 341: Foundtions of Computer Science II Prof. Mrvin Nkym Homework 3 Solutions 1. Give NFAs with the specified numer of sttes recognizing ech of the following lnguges. In ll cses, the lphet is Σ = {,1}.

More information

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018

CS 301. Lecture 04 Regular Expressions. Stephen Checkoway. January 29, 2018 CS 301 Lecture 04 Regulr Expressions Stephen Checkowy Jnury 29, 2018 1 / 35 Review from lst time NFA N = (Q, Σ, δ, q 0, F ) where δ Q Σ P (Q) mps stte nd n lphet symol (or ) to set of sttes We run n NFA

More information

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA

Nondeterminism. Nondeterministic Finite Automata. Example: Moves on a Chessboard. Nondeterminism (2) Example: Chessboard (2) Formal NFA Nondeterminism Nondeterministic Finite Automt Nondeterminism Subset Construction A nondeterministic finite utomton hs the bility to be in severl sttes t once. Trnsitions from stte on n input symbol cn

More information

Exam 2, Mathematics 4701, Section ETY6 6:05 pm 7:40 pm, March 31, 2016, IH-1105 Instructor: Attila Máté 1

Exam 2, Mathematics 4701, Section ETY6 6:05 pm 7:40 pm, March 31, 2016, IH-1105 Instructor: Attila Máté 1 Exm, Mthemtics 471, Section ETY6 6:5 pm 7:4 pm, Mrch 1, 16, IH-115 Instructor: Attil Máté 1 17 copies 1. ) Stte the usul sufficient condition for the fixed-point itertion to converge when solving the eqution

More information

1.9 C 2 inner variations

1.9 C 2 inner variations 46 CHAPTER 1. INDIRECT METHODS 1.9 C 2 inner vritions So fr, we hve restricted ttention to liner vritions. These re vritions of the form vx; ǫ = ux + ǫφx where φ is in some liner perturbtion clss P, for

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

Review of Calculus, cont d

Review of Calculus, cont d Jim Lmbers MAT 460 Fll Semester 2009-10 Lecture 3 Notes These notes correspond to Section 1.1 in the text. Review of Clculus, cont d Riemnn Sums nd the Definite Integrl There re mny cses in which some

More information

THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS.

THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS. THE EXISTENCE-UNIQUENESS THEOREM FOR FIRST-ORDER DIFFERENTIAL EQUATIONS RADON ROSBOROUGH https://intuitiveexplntionscom/picrd-lindelof-theorem/ This document is proof of the existence-uniqueness theorem

More information

CHAPTER 1 Regular Languages. Contents

CHAPTER 1 Regular Languages. Contents Finite Automt (FA or DFA) CHAPTE 1 egulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, euivlence of NFAs nd DFAs, closure under regulr

More information

Lesson 1: Quadratic Equations

Lesson 1: Quadratic Equations Lesson 1: Qudrtic Equtions Qudrtic Eqution: The qudrtic eqution in form is. In this section, we will review 4 methods of qudrtic equtions, nd when it is most to use ech method. 1. 3.. 4. Method 1: Fctoring

More information

Math 1B, lecture 4: Error bounds for numerical methods

Math 1B, lecture 4: Error bounds for numerical methods Mth B, lecture 4: Error bounds for numericl methods Nthn Pflueger 4 September 0 Introduction The five numericl methods descried in the previous lecture ll operte by the sme principle: they pproximte the

More information

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014

CMPSCI 250: Introduction to Computation. Lecture #31: What DFA s Can and Can t Do David Mix Barrington 9 April 2014 CMPSCI 250: Introduction to Computtion Lecture #31: Wht DFA s Cn nd Cn t Do Dvid Mix Brrington 9 April 2014 Wht DFA s Cn nd Cn t Do Deterministic Finite Automt Forml Definition of DFA s Exmples of DFA

More information

This lecture covers Chapter 8 of HMU: Properties of CFLs

This lecture covers Chapter 8 of HMU: Properties of CFLs This lecture covers Chpter 8 of HMU: Properties of CFLs Turing Mchine Extensions of Turing Mchines Restrictions of Turing Mchines Additionl Reding: Chpter 8 of HMU. Turing Mchine: Informl Definition B

More information

Riemann is the Mann! (But Lebesgue may besgue to differ.)

Riemann is the Mann! (But Lebesgue may besgue to differ.) Riemnn is the Mnn! (But Lebesgue my besgue to differ.) Leo Livshits My 2, 2008 1 For finite intervls in R We hve seen in clss tht every continuous function f : [, b] R hs the property tht for every ɛ >

More information

p-adic Egyptian Fractions

p-adic Egyptian Fractions p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction

More information

Parsing and Pattern Recognition

Parsing and Pattern Recognition Topics in IT Prsing nd Pttern Recognition Week Context-Free Prsing College of Informtion Science nd Engineering Ritsumeikn University this week miguity in nturl lnguge in mchine lnguges top-down, redth-first

More information

CS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility)

CS5371 Theory of Computation. Lecture 20: Complexity V (Polynomial-Time Reducibility) CS5371 Theory of Computtion Lecture 20: Complexity V (Polynomil-Time Reducibility) Objectives Polynomil Time Reducibility Prove Cook-Levin Theorem Polynomil Time Reducibility Previously, we lernt tht if

More information

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1

Chapter Five: Nondeterministic Finite Automata. Formal Language, chapter 5, slide 1 Chpter Five: Nondeterministic Finite Automt Forml Lnguge, chpter 5, slide 1 1 A DFA hs exctly one trnsition from every stte on every symol in the lphet. By relxing this requirement we get relted ut more

More information

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints)

Chapter 4 Regular Grammar and Regular Sets. (Solutions / Hints) C K Ngpl Forml Lnguges nd utomt Theory Chpter 4 Regulr Grmmr nd Regulr ets (olutions / Hints) ol. (),,,,,,,,,,,,,,,,,,,,,,,,,, (),, (c) c c, c c, c, c, c c, c, c, c, c, c, c, c c,c, c, c, c, c, c, c, c,

More information

Physics 116C Solution of inhomogeneous ordinary differential equations using Green s functions

Physics 116C Solution of inhomogeneous ordinary differential equations using Green s functions Physics 6C Solution of inhomogeneous ordinry differentil equtions using Green s functions Peter Young November 5, 29 Homogeneous Equtions We hve studied, especilly in long HW problem, second order liner

More information

Homework Solution - Set 5 Due: Friday 10/03/08

Homework Solution - Set 5 Due: Friday 10/03/08 CE 96 Introduction to the Theory of Computtion ll 2008 Homework olution - et 5 Due: ridy 10/0/08 1. Textook, Pge 86, Exercise 1.21. () 1 2 Add new strt stte nd finl stte. Mke originl finl stte non-finl.

More information

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Converting Regular Expressions to Discrete Finite Automata: A Tutorial Converting Regulr Expressions to Discrete Finite Automt: A Tutoril Dvid Christinsen 2013-01-03 This is tutoril on how to convert regulr expressions to nondeterministic finite utomt (NFA) nd how to convert

More information

Let's start with an example:

Let's start with an example: Finite Automt Let's strt with n exmple: Here you see leled circles tht re sttes, nd leled rrows tht re trnsitions. One of the sttes is mrked "strt". One of the sttes hs doule circle; this is terminl stte

More information

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science

CSCI 340: Computational Models. Kleene s Theorem. Department of Computer Science CSCI 340: Computtionl Models Kleene s Theorem Chpter 7 Deprtment of Computer Science Unifiction In 1954, Kleene presented (nd proved) theorem which (in our version) sttes tht if lnguge cn e defined y ny

More information

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa

CS:4330 Theory of Computation Spring Regular Languages. Equivalences between Finite automata and REs. Haniel Barbosa CS:4330 Theory of Computtion Spring 208 Regulr Lnguges Equivlences between Finite utomt nd REs Hniel Brbos Redings for this lecture Chpter of [Sipser 996], 3rd edition. Section.3. Finite utomt nd regulr

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

Bases for Vector Spaces

Bases for Vector Spaces Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything

More information

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3 2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is

More information

The First Fundamental Theorem of Calculus. If f(x) is continuous on [a, b] and F (x) is any antiderivative. f(x) dx = F (b) F (a).

The First Fundamental Theorem of Calculus. If f(x) is continuous on [a, b] and F (x) is any antiderivative. f(x) dx = F (b) F (a). The Fundmentl Theorems of Clculus Mth 4, Section 0, Spring 009 We now know enough bout definite integrls to give precise formultions of the Fundmentl Theorems of Clculus. We will lso look t some bsic emples

More information

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51

Non Deterministic Automata. Linz: Nondeterministic Finite Accepters, page 51 Non Deterministic Automt Linz: Nondeterministic Finite Accepters, pge 51 1 Nondeterministic Finite Accepter (NFA) Alphbet ={} q 1 q2 q 0 q 3 2 Nondeterministic Finite Accepter (NFA) Alphbet ={} Two choices

More information

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. Comparing DFAs and NFAs (cont.) Finite Automata 2 CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 Types of Finite Automt Deterministic Finite Automt () Exctly one sequence of steps for ech string All exmples so fr Nondeterministic Finite Automt

More information

20 MATHEMATICS POLYNOMIALS

20 MATHEMATICS POLYNOMIALS 0 MATHEMATICS POLYNOMIALS.1 Introduction In Clss IX, you hve studied polynomils in one vrible nd their degrees. Recll tht if p(x) is polynomil in x, the highest power of x in p(x) is clled the degree of

More information

Advanced Calculus: MATH 410 Notes on Integrals and Integrability Professor David Levermore 17 October 2004

Advanced Calculus: MATH 410 Notes on Integrals and Integrability Professor David Levermore 17 October 2004 Advnced Clculus: MATH 410 Notes on Integrls nd Integrbility Professor Dvid Levermore 17 October 2004 1. Definite Integrls In this section we revisit the definite integrl tht you were introduced to when

More information

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v.

Exercises Chapter 1. Exercise 1.1. Let Σ be an alphabet. Prove wv = w + v for all strings w and v. 1 Exercises Chpter 1 Exercise 1.1. Let Σ e n lphet. Prove wv = w + v for ll strings w nd v. Prove # (wv) = # (w)+# (v) for every symol Σ nd every string w,v Σ. Exercise 1.2. Let w 1,w 2,...,w k e k strings,

More information

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7

CS103 Handout 32 Fall 2016 November 11, 2016 Problem Set 7 CS103 Hndout 32 Fll 2016 Novemer 11, 2016 Prolem Set 7 Wht cn you do with regulr expressions? Wht re the limits of regulr lnguges? On this prolem set, you'll find out! As lwys, plese feel free to drop

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Orgniztion of Progrmming Lnguges Finite Automt 2 CMSC 330 1 Types of Finite Automt Deterministic Finite Automt (DFA) Exctly one sequence of steps for ech string All exmples so fr Nondeterministic

More information

7.2 The Definite Integral

7.2 The Definite Integral 7.2 The Definite Integrl the definite integrl In the previous section, it ws found tht if function f is continuous nd nonnegtive, then the re under the grph of f on [, b] is given by F (b) F (), where

More information