SWEN 224 Formal Foundations of Programming WITH ANSWERS
|
|
- Homer Hardy
- 5 years ago
- Views:
Transcription
1 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 WITH ANSWERS Instructions: Answer ll four questions. The exm will e mrked out of one hundred nd eighty (180). Clcultors ARE NOT ALLOWED. Non-electronic foreign lnguge dictionries re llowed. No other reference mteril is llowed. SWEN 224 continued...
2 Question 1. Assertions nd Verifiction [60 mrks] () [15 mrks : 5 for ech prt] Write n ssertion formlising ech of the following sttements, where A is n rry of size N. You my use either JML or ordinry mthemticl nottion. (i) All elements of A re different. i, j : 0 i, j < N i = j : A[i] = A[j] or i, j : 0 i < j < N : A[i] = A[j] (ii) A contins exctly one occurrence of z. i : 0 i < N : A[i] = z ( j : 0 j < N i = j : A[j] = z) or {i 0 i < N A[i] = z = 1 (iii) Between ny two occurrences of z in A, there is t lest one occurrence of y. i, j : 0 i < j < N : A[i] = z A[i] = z ( k : i < k < j : A[j] = y) () [15 mrks : 5 for ech prt] For ech of the following correctness ssertions, write down the verifiction condition(s) tht must hold in order for the correctness ssertion to e vlid, nd give rief explntion of why these verifiction conditions hold. (i) { k = 0s := 0{s = k 1 i=0 A[i] k = 0 0 = k 1 i=0 A[i] This holds ecuse 1 i=0 A[i] = 0. (ii) { x yif x > z then x := z else skip fi{x y x z x y x > z z y z z This holds ecuse: x y x > z implies z y (y trnsitivity), nd z z lwys holds. x y (x > z) x y x z The holds ecuse x y implies x y, nd (x > z) is equivlent to x z. (iii) { 0 k < n 1 s = k 1 i=0 A[i]k := k+1; s := s+a[k]{0 k < n s = k 1 i=0 A[i] 0 k < n s = k 1 i=0 A[i] k = n 1 0 k+1 < n s+[k+1] = k i=0 A[i] This holds ecuse: 0 k implies 0 k+1 k < n k = n 1 implies k+1 < n s = k 1 i=0 A[i] implies s+[k+1] = k i=0 A[i] (0 k < n k = n 1 ensures tht [k+1] is well-defined) SWEN continued...
3 (c) Consider the following Jv method, which counts the numer of times 0 occurs in n integer rry A. //@ requires A!= null; //@ ensures \result == (\num_of int k; 0 <= k && k < A.length; A[k] == 0); int countzeroes(int[] A) { int i = 0; int c = 0; while (i < A.length) { if ( A[i] == 0 ) c = c + 1; i = i + 1; return c; (i) [4 mrks] Therequires ndensures nnottions give the pre nd postconditions for the method. Wht re the pre nd postconditions for the loop? Precondition: //@ ssert A!= null && i == 0 && c == 0; Postcondition: //@ ssert c == (\num_of int k; 0 <= k && k < A.length; A[k] == 0); (ii) [5 mrks] Give loop invrint tht cn e used to verify the loop in this method. /*@ loop_invrint A!= null && 0 <= i && i <= A.length && c == (\num_of int k; 0 <= k && k < i; A[k] == (iii) [15 mrks] Stte the three verifiction conditions tht must e proved in order to show tht the loop is prtilly correct, nd give rief rgument to show tht ech of them holds. (You my use ordinry mthemticl nottion insted of JML if you prefer.) The precondition for the loop implies the loop invrint. A = null i = 0 c = 0 A = null 0 i i A.length c = (count k : 0 k k < i : A[k] = 0) c = (count k : 0 k k < i : A[k] = 0) holds ecuse c = 0, i = 0, nd count over n empty rnge is 0. The other conjuncts follow directly from the precondition, nd the fct tht rry size is nturl numer. The loop invrint is preserved when the loop test holds. When the if test holds: A = null 0 i i A.length c = (count k : 0 k k < A.length : A[k] = 0) i < A.length A[i] = 0 A = null 0 i+1 i+1 A.length c+1 = (count k : 0 k k < i+1 : A[k] = 0) SWEN continued...
4 This holds, ecuse (count k : 0 k k < i+1 : A[k] = 0) = (count k : 0 k k < A.length : A[k] = 0)+1 when A[i] = 0. When the if test fils: A = null 0 i i A.length c = (count k : 0 k k < i : A[k] = 0) i < A.length A[i] = 0 A = null 0 i+1 i+1 A.length c = (count k : 0 k k < i+1 : A[k] = 0) This holds, ecuse (count k : 0 k k < i+1 : A[k] = 0) = (count k : 0 k k < A.length : A[k] = 0) when A[i] = 0. The loop invrint implies the postcondition when the loop test fils. A = null 0 i i A.length c = (count k : 0 k k < i : A[k] = 0) (i < A.length) c = (count k : 0 k k < A.length : A[k] = 0) This holds ecuse (count k : 0 k k < i : A[k] = 0) = (count k : 0 k k < A.length : A[k] = 0) when i = A.length. (iv) [6 mrks] Give rief rgument to show tht the method termintes properly, i.e. tht it does not give run-time error or exception nd does not loop forever. (You my ignore the possiility of rithmetic overflow.) The only wy the progrm could get run-time error (ignoring the possiility of rithmetic overflow) is y getting n rry index error. This cnnot occur, however, ecuse the loop invrint nd loop test ensure tht 0 i < A.length in the if sttement. The progrm cnnot loop forever ecuse it termintes fter A.length itertions. We cn prove this formlly using A.length i s loop vrint. This vlue decreses on ech itertion of the loop, nd cnnot go negtive, since the loop will exit when it ecomes zero. SWEN continued...
5 Question 2. Alloy [20 mrks] Consider the following Alloy model for Nondeterministic Finite Acceptors: sig Symol { sig Stte { sig NFA { initil: Stte, next: Stte -> Symol -> Stte, finl: set Stte sig Config { stte: Stte, input: seq Symol pred move[m: NFA, c1, c2: Config] { c2.stte = m.next[c1.stte][c1.input.first] && c2.input = c1.input.rest pred ccepts[m: NFA, s: seq Symol] { some ss: seq Config ss.first.stte = m.initil && ss.lst.stte in m.finl && (ll i: ss.inds-#ss move[m, ss[i], ss[i+1]]) () [3 mrks] Write predicte to determine whether n NFA hs no finl stte. pred nofinl[m: NFA] { no m.finl () [3 mrks] Write predicte to determine whether n NFA hs t lest two finl sttes. pred twoplusfinls[m: NFA] { #m.finl <= 2 (c) [3 mrks] Write predicte to determine whether n NFA is deterministic. SWEN continued...
6 pred isdeterministic[m: NFA] { ll s: Stte ll : Symol #m.next[s][] <= 1 (d) [3 mrks] Write predicte to determine whether n NFA ccepts the empty string. pred cceptsempty[m: NFA] { m.initil in m.finl (e) [3 mrks] Write predicte to determine whether the lnguges ccepted y two NFAs hve ny strings in common. pred ccceptnondisjointlnguges[m1: NFA, m2: NFA] { some s: seq Symol ccepts[m1, s] nd ccepts[m2, s] (f) [5 mrks] Write predicte to determine whether two NFAs hs ny common sttes; i.e. sttes tht re rechle from the initil sttes of oth mchines. pred rechle[m: NFA, s: Stte] { some ss: seq Stte ss.first = s && ss.lst = m.initil && (ll i: ss.inds-#ss some : Symol ss[i+1] in m.next[ss[i]][]) pred CommonSttes[m1, m2: NFA] { some s: Stte rechle[m1, s] nd rechle[m1, s] or: pred CommonSttes [m1, m2: NFA] { some s: Stte some ss1, ss2: seq Stte ss1.first = m1.initil && ss1.lst = s && ss2.first = m1.initil && ss2.lst = s && (ll i: ss1.inds-#ss1 some : Symol ss1[i+1] in m1.next[ss1[i]][]) && (ll i: ss2.inds-#ss1 some : Symol ss1[i+1] in m2.next[ss1[i]][]) SWEN continued...
7 Question 3. Regulr Lnguges [55 mrks] () [8 mrks : 4 for ech prt] Write Regulr Expression or Regulr Grmmr to descrie ech of the following lnguges, over the lphet{,, c: (i) All strings in which ll s come efore ll s nd ll c s. ( c) (ii) All strings of even length in which ll s come efore ll s. (( c)( c)) (( c)( c)) ( c)(( c)( c)) ( c)(( c)( c)) or: (( c)( c)) ( λ)(( c)( c)) () Consider the NFA M = (Q, q I, A, N, F), where: Q = {1, 2, 3, 4, 5 q I = 1 A = {, N = {(1,, 1),(1,, 2),(1,, 1),(1,, 3),(2,, 4),(2,, 2), (3,, 3),(3,, 5),(4,, 4),(4,, 4),(5,, 5),(5,, 5) F = {4, 5 (i) [4 mrks] Drw trnsition digrm for M.,, 2 4 1, 3 5 (ii) [4 mrks] Show the sequence of configurtions tht M psses through in ccepting the input. Note tht you should show ll sttes tht M my e in fter ccepting prt of the input. Sttes Input {1 {1, 2 {1, 2, 3 {1, 2, 3, 4 {1, 2, 3, 4, 5 {1, 2, 3, 4, 5 Accept SWEN continued...
8 (iii) [4 mrks] Write regulr expression descriing the lnguge ccepted y M. ( ) ( )( ) (i.e. ll strings over s nd s with either (t lest) two two s.) (iv) [8 mrks] Drw trnsition digrm for the DFA otined y pplying the suset construction to M. Show the correspondence etween sttes of the DFA nd those of the NFA. You only need to show rechle sttes ,, The stte correspondence is: DFAStte NFASttes 1 {1 2 {1, 2 3 {1, 2, 3 4 {1, 2, 3, 4 5 {1, 2, 3, 4 (c) [10 mrks] Given n NFA M = (Q, q I, A, N, F), show how to construct n NFA, M = (Q, q I, A, N, F ), which ccepts the lnguge consisting of ll strings in L(M) enclosed in pir of s. For exmple, if L(M) = {,,, then L(M ) = {,,, nd if L(M) = {λ,, c, c, then L(M ) = {,, c, c. Give rief rgument to show tht the resulting NFA does in fct ccept the required lnguge. M = (Q, q I, A, N, F ) where: Q = Q {q 1, q 2 ), where q 1 nd q 2 re new sttes, not in Q q I = q 1 A = A { N = N {(q 1,, q I ) {(q f,, q 2 ) q f F F = {q 2 M ccepts string γ iff M cn trverse pth from q I to some stte q n F, while consuming γ. But in this cse, M cn consume γ while pssing through sttes q 1, q I,..., q f, q 2, since M hs ll of the trnsitions of M, nd hs trnsitions(q 1,, q I), nd(q f,, q 2 ). So M ccepts γ. Similrly, M ccepts string γ iff γ is of the form γ, where γ is consumed on pth from q I to some stte q f F, since the only trnsition out of q 1 is (q 1,, q I), nd the only trnsitions leding to q 2 re of the form (q f,, q 2 ). But in this cse, M cn consume α while trversing the sme pth from q I to q f F. So M ccepts γ. (d) [6 mrks] Drw trnsition digrm for n NFA ǫ tht ccepts the lnguge defined y the regulr expression ( c) ( ) c. SWEN continued...
9 ,c 2 4 1, c 3 5 (e) [3 mrks] Explin riefly why llowing null trnsition mkes it esier to construct n NFA from regulr expression. Allowing null trnsitions llows us to uild the NFA in modulr wy, using null trnsitions to glue together NFAs uilt from the suexpressions. (f) [8 mrks] Prove tht, for ny regulr expressions x, y nd z, x(y z) = xy xz. We hve to show tht L(x(y z)) = L(xy xz). We prove this s follows: L(x(y z)) = L(x) (L(y) L(z)) Definition of L = {s v s L(x) v (L(y) L(z)) defn of = {s v s L(x) (v L(y) v L(z)) defn of = {s v (s L(x) v L(y)) (s S v L(z)) distriutes over = {s v s L(x) v L(y) {s v s L(x) v L(z) defn of = (L(x) L(y)) (L(x) L(z)) defn of = L(xy xz) Definition of L (The min prt of this proof ws given in the solutions to Assignment 4.) SWEN continued...
10 Question 4. Context-Free Lnguges [45 mrks] () [10 mrks : 5 for ech prt] Write Context Free Grmmr to descrie ech of the following lnguges. You re not required to give full forml definition of these grmmrs just write the list of rules. (i) All strings consisting of one or more d s, optionlly followed y n nd one or more further d s. For exmple, d, ddd, dd nd dddd re in this lnguge, ut dd, dd nd dd re not. S T T T T d d T or S T U T d d T U λ T (ii) All strings formed y conctenting two non-empty plindromes over{,, c, where plindrome is strings tht reds the sme forwrds nd ckwrds (e.g.,,, cccc). Thus,,,, nd cccc re in this lnguge, ut,, c nd cc re not. S T T T U T T c T c U λ c () Consider the following grmmr, where!, $,,, ( nd ) re terminl symols: S T! T T!! (1, 2) T T $ T U (3, 4) U ( T) (5, 6, 7) (i) [3 mrks] Construct prse tree for $!. Write the numer of the rule pplied eside ech nonterminl in the prse tree; likewise for prts (ii) nd (iii). S (1) T (3)! T (4) $ T (4) U (5) U (6) SWEN continued...
11 (ii) [4 mrks] Construct prse tree for ( $ )!!. S (2) T (4) T (4)!! U (7) U (5) ( T (3) ) T (4) $ T (4) U (5) U (6) (iii) [6 mrks] Demonstrte tht the grmmr is miguous y drwing two differrent prse trees for $ $!. S (1) S (1) T (3)! T (3)! T (3) $ T (4) T (4) $ T (3) T (4) $ T (4) U (5) U (5) T (4) $ T (4) U (5) U (6) U (5) U (6) (iv) [6 mrks] Write n equivlent, non-miguous grmmr, treting $ s left-ssocitive. S T! T T!! (1, 2) T T $ U U (3, 4) U ( T) (5, 6, 7) (v) [8 mrks] Write n equivlent LL(1) grmmr, nd show tht it is LL(1). SWEN continued...
12 S T S (1) S! T!! (2, 3) T U T (3, 4) T λ $ T (5, 6) U ( T) (7, 8, 9) In the definition of S, first(!) = {! nd first(t!!) = {,,(, which re disjoint. In the definition of T, first(λ) = { nd first($t ) = {$, which re disjoint. In the definition of U, first() = {, first() = { nd first((t)) = {(, which re disjoint. T λ, so we hve to show tht first(t ) follow(t ) =. first(t ) = {$ nd follow(t ) = {!,), which re indeed disjoint. (c) [8 mrks] Prove tht the union of two context-free lnguges is context-free. Hint: Recll tht lnguge is context-free if nd only if it cn e defined using contextfree grmmr. Suppose lnguges L 1 nd L 2 re defined y CFG s G 1 = (N 1, T 1, S 1, P 1 ) nd G 2 = (N 2, T 2, S 2, P 2 ), we show how to construct grmmr G 3 which defines L 3 = L 1 L 2. First, we renme nonterminls to ensure tht N 1 nd N 2 re disjoint. We cn do this ecuse renming nonterminls does not lter the lnguge defined y grmmr. The required grmmr hs ll of the terminls, non-terminls nd rules of the given grmmrs, long with one new nonterminl, S 3, which is the strt symol, nd one new rule, llowing S 3 to e rewritten s either S 1 or S 2, i.e.: G 3 = (N 1 N 2 {S 3, T 1 T 2, S 3, P 1 P 2 {S 3 S 1 S 2 ) To show tht L(G 3 ) = L 1 L 2, we must show tht for ny string α (V T V T ) there is prse tree for α from G 3 iff there is prse tree for α from G 1 or from G 2. Suppose tht α is in L 1, then there must e prse tree T for α from G 1, with S 1 s its root, nd α s its fringe. But in tht cse, we cn extend T to otin prse tree from α from G 3, y dding new root, lelled S 3, with single edge to the root of T. This is prse tree from G 3 ecuse it hs S 3 s its root; the edge under the root corresponds to n ppliction of the rule S 3 S 1, nd the rest of the tree uses rules form G 1 which re lso in G 3. Similrly, if α is in L 2, there is prse tree from α from G 2, which cn e extended to otin prse tree for α from G 3 y dding n ppliction of the rule S 3 S 2. In the other direction, suppose tht T is prse tree for α from G 3. Since the only rule in G 3 with S 3 on the left hnd side is S 3 S 1 S 2, the root of T hs single child, lelled either S 1 or S 2. Thus, if we delete the root nd tht edge, the resulting tree is either prse tree for α from G 1 or prse tree for α from G 2, so α is either in L 1 or in L 2, i.e. it is in L 1 L 2. ******************************** SWEN
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 informationFinite 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 informationThe 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 informationHomework 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 informationMinimal 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 informationCS 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 informationConvert 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 informationLet'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 informationChapter 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 informationHarvard 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 informationAssignment 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 informationWorked out examples Finite Automata
Worked out exmples Finite Automt Exmple Design Finite Stte Automton which reds inry string nd ccepts only those tht end with. Since we re in the topic of Non Deterministic Finite Automt (NFA), we will
More information1 Nondeterministic Finite Automata
1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you
More informationCS 311 Homework 3 due 16:30, Thursday, 14 th October 2010
CS 311 Homework 3 due 16:30, Thursdy, 14 th Octoer 2010 Homework must e sumitted on pper, in clss. Question 1. [15 pts.; 5 pts. ech] Drw stte digrms for NFAs recognizing the following lnguges:. L = {w
More informationFirst 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 informationCS 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 informationLecture 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 informationDesigning finite automata II
Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of
More informationFirst 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 informationCS 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 information1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.
York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech
More informationFormal 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 informationCMSC 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 informationCSE : Exam 3-ANSWERS, Spring 2011 Time: 50 minutes
CSE 260-002: Exm 3-ANSWERS, Spring 20 ime: 50 minutes Nme: his exm hs 4 pges nd 0 prolems totling 00 points. his exm is closed ook nd closed notes.. Wrshll s lgorithm for trnsitive closure computtion is
More informationHomework 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 informationAUTOMATA 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 informationCHAPTER 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 informationCS 330 Formal Methods and Models
CS 330 Forml Methods nd Models Dn Richrds, section 003, George Mson University, Fll 2017 Quiz Solutions Quiz 1, Propositionl Logic Dte: Septemer 7 1. Prove (p q) (p q), () (5pts) using truth tles. p q
More informationClosure 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 informationCS375: 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 informationCS 330 Formal Methods and Models
CS 0 Forml Methods nd Models Dn Richrds, George Mson University, Fll 2016 Quiz Solutions Quiz 1, Propositionl Logic Dte: Septemer 8 1. Prove q (q p) p q p () (4pts) with truth tle. p q p q p (q p) p q
More informationTypes of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.
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 informationTypes 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 informationTalen 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 informationSome Theory of Computation Exercises Week 1
Some Theory of Computtion Exercises Week 1 Section 1 Deterministic Finite Automt Question 1.3 d d d d u q 1 q 2 q 3 q 4 q 5 d u u u u Question 1.4 Prt c - {w w hs even s nd one or two s} First we sk whether
More information5. (±±) Λ = 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 informationFinite-State Automata: Recap
Finite-Stte Automt: Recp Deepk D Souz Deprtment of Computer Science nd Automtion Indin Institute of Science, Bnglore. 09 August 2016 Outline 1 Introduction 2 Forml Definitions nd Nottion 3 Closure under
More informationFormal Languages and Automata
Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University
More informationNon-deterministic Finite Automata
Non-deterministic Finite Automt Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd T. vn Lrhoven Institute for Computing nd Informtion Sciences Intelligent
More information1 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 informationIntermediate 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 informationParse 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ɛ-closure, Kleene s Theorem,
DEGefW5wiGH2XgYMEzUKjEmtCDUsRQ4d 1 A nice pper relevnt to this course is titled The Glory of the Pst 2 NICTA Resercher, Adjunct t the Austrlin Ntionl University nd Griffith University ɛ-closure, Kleene
More informationNon-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 informationRegular 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 informationContext-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 informationCS 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 informationNondeterminism and Nodeterministic Automata
Nondeterminism nd Nodeterministic Automt 61 Nondeterminism nd Nondeterministic Automt The computtionl mchine models tht we lerned in the clss re deterministic in the sense tht the next move is uniquely
More informationName Ima Sample ASU ID
Nme Im Smple ASU ID 2468024680 CSE 355 Test 1, Fll 2016 30 Septemer 2016, 8:35-9:25.m., LSA 191 Regrding of Midterms If you elieve tht your grde hs not een dded up correctly, return the entire pper to
More informationCSCI 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 information3 Regular expressions
3 Regulr expressions Given n lphet Σ lnguge is set of words L Σ. So fr we were le to descrie lnguges either y using set theory (i.e. enumertion or comprehension) or y n utomton. In this section we shll
More informationThe University of Nottingham
The University of Nottinghm SCHOOL OF COMPUTR SCINC AND INFORMATION TCHNOLOGY A LVL 1 MODUL, SPRING SMSTR 2004-2005 MACHINS AND THIR LANGUAGS Time llowed TWO hours Cndidtes must NOT strt writing their
More informationRegular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*
Regulr Expressions (RE) Regulr Expressions (RE) Empty set F A RE denotes the empty set Opertion Nottion Lnguge UNIX Empty string A RE denotes the set {} Alterntion R +r L(r ) L(r ) r r Symol Alterntion
More information1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.
York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech
More informationScanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:
Scnner Specifying ptterns source code tokens scnner prser IR A scnner must recognize the units of syntx Some prts re esy: errors mps chrcters into tokens the sic unit of syntx x = x + y; ecomes
More informationGrammar. 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 informationa,b a 1 a 2 a 3 a,b 1 a,b a,b 2 3 a,b a,b a 2 a,b CS Determinisitic Finite Automata 1
CS4 45- Determinisitic Finite Automt -: Genertors vs. Checkers Regulr expressions re one wy to specify forml lnguge String Genertor Genertes strings in the lnguge Deterministic Finite Automt (DFA) re nother
More informationMore 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 informationOverview 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 information1.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 informationExercises 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 informationLecture 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 informationChapter 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 information1.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 informationinput tape head moves current state
CPS 140 - Mthemticl Foundtions of CS Dr. Susn Rodger Section: Finite Automt (Ch. 2) (lecture notes) Things to do in clss tody (Jn. 13, 2004): ffl questions on homework 1 ffl finish chpter 1 ffl Red Chpter
More informationCS 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 informationCS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University
CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted
More informationCMPSCI 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 informationTheory 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 information80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES. 2.6 Finite State Automata With Output: Transducers
80 CHAPTER 2. DFA S, NFA S, REGULAR LANGUAGES 2.6 Finite Stte Automt With Output: Trnsducers So fr, we hve only considered utomt tht recognize lnguges, i.e., utomt tht do not produce ny output on ny input
More informationCHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)
Finite Automt (FA or DFA) CHAPTER Regulr Lnguges Contents definitions, exmples, designing, regulr opertions Non-deterministic Finite Automt (NFA) definitions, equivlence of NFAs DFAs, closure under regulr
More informationCS 275 Automata and Formal Language Theory
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)
More informationCS 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 informationTheory 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 informationFormal Language and Automata Theory (CS21004)
Forml Lnguge nd Automt Forml Lnguge nd Automt Theory (CS21004) Khrgpur Khrgpur Khrgpur Forml Lnguge nd Automt Tle of Contents Forml Lnguge nd Automt Khrgpur 1 2 3 Khrgpur Forml Lnguge nd Automt Forml Lnguge
More informationNFAs continued, Closure Properties of Regular Languages
Algorithms & Models of Computtion CS/ECE 374, Fll 2017 NFAs continued, Closure Properties of Regulr Lnguges Lecture 5 Tuesdy, Septemer 12, 2017 Sriel Hr-Peled (UIUC) CS374 1 Fll 2017 1 / 31 Regulr Lnguges,
More informationCISC 4090 Theory of Computation
9/6/28 Stereotypicl computer CISC 49 Theory of Computtion Finite stte mchines & Regulr lnguges Professor Dniel Leeds dleeds@fordhm.edu JMH 332 Centrl processing unit (CPU) performs ll the instructions
More informationTable of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...
Tle of contents: Lecture N0.... 3 ummry... 3 Wht does utomt men?... 3 Introduction to lnguges... 3 Alphets... 3 trings... 3 Defining Lnguges... 4 Lecture N0. 2... 7 ummry... 7 Kleene tr Closure... 7 Recursive
More informationNon 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 informationFinite 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 informationPART 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 informationConverting 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 informationThoery of Automata CS402
Thoery of Automt C402 Theory of Automt Tle of contents: Lecture N0. 1... 4 ummry... 4 Wht does utomt men?... 4 Introduction to lnguges... 4 Alphets... 4 trings... 4 Defining Lnguges... 5 Lecture N0. 2...
More informationTutorial 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 informationFABER 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 informationFinite 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 informationFinite 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 informationJava II Finite Automata I
Jv II Finite Automt I Bernd Kiefer Bernd.Kiefer@dfki.de Deutsches Forschungszentrum für künstliche Intelligenz Finite Automt I p.1/13 Processing Regulr Expressions We lredy lerned out Jv s regulr expression
More informationCompiler Design. Fall Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz
University of Southern Cliforni Computer Science Deprtment Compiler Design Fll Lexicl Anlysis Smple Exercises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sciences Institute 4676 Admirlty Wy, Suite
More informationNon-deterministic Finite Automata
Non-deterministic Finite Automt From Regulr Expressions to NFA- Eliminting non-determinism Rdoud University Nijmegen Non-deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion
More informationFundamentals of Computer Science
Fundmentls of Computer Science Chpter 3: NFA nd DFA equivlence Regulr expressions Henrik Björklund Umeå University Jnury 23, 2014 NFA nd DFA equivlence As we shll see, it turns out tht NFA nd DFA re equivlent,
More informationFormal Languages and Automata Theory. D. Goswami and K. V. Krishna
Forml Lnguges nd Automt Theory D. Goswmi nd K. V. Krishn Novemer 5, 2010 Contents 1 Mthemticl Preliminries 3 2 Forml Lnguges 4 2.1 Strings............................... 5 2.2 Lnguges.............................
More informationThe University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS
The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their
More informationNFAs 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 informationLecture 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 informationLexical Analysis Finite Automate
Lexicl Anlysis Finite Automte CMPSC 470 Lecture 04 Topics: Deterministic Finite Automt (DFA) Nondeterministic Finite Automt (NFA) Regulr Expression NFA DFA A. Finite Automt (FA) FA re grph, like trnsition
More information12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2016
CS125 Lecture 12 Fll 2016 12.1 Nondeterminism The ide of nondeterministic computtions is to llow our lgorithms to mke guesses, nd only require tht they ccept when the guesses re correct. For exmple, simple
More informationDeterministic Finite Automata
Finite Automt Deterministic Finite Automt H. Geuvers nd J. Rot Institute for Computing nd Informtion Sciences Version: fll 2016 J. Rot Version: fll 2016 Tlen en Automten 1 / 21 Outline Finite Automt Finite
More informationLanguages & Automata
Lnguges & Automt Dr. Lim Nughton Lnguges A lnguge is sed on n lphet which is finite set of smols such s {, } or {, } or {,..., z}. If Σ is n lphet, string over Σ is finite sequence of letters from Σ, (strings
More informationCSCI 340: Computational Models. Transition Graphs. Department of Computer Science
CSCI 340: Computtionl Models Trnsition Grphs Chpter 6 Deprtment of Computer Science Relxing Restrints on Inputs We cn uild n FA tht ccepts only the word! 5 sttes ecuse n FA cn only process one letter t
More information