CS 330 Formal Methods and Models

Similar documents
CS 330 Formal Methods and Models

CS 330 Formal Methods and Models

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

Homework 3 Solutions

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

Let's start with an example:

Harvard University Computer Science 121 Midterm October 23, 2012

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

Finite Automata-cont d

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

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.

Some Theory of Computation Exercises Week 1

First Midterm Examination

Lecture 08: Feb. 08, 2019

First Midterm Examination

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

Deterministic Finite Automata

Minimal DFA. minimal DFA for L starting from any other

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

CS 311 Homework 3 due 16:30, Thursday, 14 th October 2010

1.4 Nonregular Languages

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

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

Convert the NFA into DFA

SWEN 224 Formal Foundations of Programming WITH ANSWERS

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

CHAPTER 1 Regular Languages. Contents

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

Finite-State Automata: Recap

Normal Forms for Context-free Grammars

Formal languages, automata, and theory of computation

Theory of Computation Regular Languages

Name Ima Sample ASU ID

a,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

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

Non-deterministic Finite Automata

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

1 From NFA to regular expression

CS375: Logic and Theory of Computing

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

Worked out examples Finite Automata

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

Context-Free Grammars and Languages

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

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

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

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

CSC 311 Theory of Computation

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

CS375: Logic and Theory of Computing

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

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

5.1 Definitions and Examples 5.2 Deterministic Pushdown Automata

Closure Properties of Regular Languages

Lecture 6 Regular Grammars

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

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

3 Regular expressions

Chapter 2 Finite Automata

Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Regular Expressions (RE) Kleene-*

State Minimization for DFAs

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Nondeterminism and Nodeterministic Automata

11.1 Finite Automata. CS125 Lecture 11 Fall Motivation: TMs without a tape: maybe we can at least fully understand such a simple model?

Lexical Analysis Finite Automate

Coalgebra, Lecture 15: Equations for Deterministic Automata

Thoery of Automata CS402

Table of contents: Lecture N Summary... 3 What does automata mean?... 3 Introduction to languages... 3 Alphabets... 3 Strings...

NFAs continued, Closure Properties of Regular Languages

Boolean Algebra. Boolean Algebra

1 Nondeterministic Finite Automata

Automata and Languages

Formal Language and Automata Theory (CS21004)

CMSC 330: Organization of Programming Languages

CHAPTER 1 Regular Languages. Contents. definitions, examples, designing, regular operations. Non-deterministic Finite Automata (NFA)

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

Fast Boolean Algebra

1.3 Regular Expressions

a b b a pop push read unread

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

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

Non-deterministic Finite Automata

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

Midterm 1 Practice. CS 350 Fall 2018 gilray.org/classes/fall2018/cs350/

CS 275 Automata and Formal Language Theory

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

USA Mathematical Talent Search Round 1 Solutions Year 21 Academic Year

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

DFA Minimization and Applications

CSE396 Prelim I Answer Key Spring 2017

ɛ-closure, Kleene s Theorem,

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

12.1 Nondeterminism Nondeterministic Finite Automata. a a b ε. CS125 Lecture 12 Fall 2014

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

Scanner. Specifying patterns. Specifying patterns. Operations on languages. A scanner must recognize the units of syntax Some parts are easy:

Formal Languages and Automata

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

Types of Finite Automata. CMSC 330: Organization of Programming Languages. Comparing DFAs and NFAs. NFA for (a b)*abb.

CS 275 Automata and Formal Language Theory

Transcription:

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 q (q p) p q p T T F F T F T T T F F F T T T T F T T T T F T T F F T F F T F F () (4pts) lgericlly. q (q p) p q ((q p) p) q ((q p) p) (q (q p)) p q p Conditionl lw Lw of negtion Associtivity Susumption 2. (2pts) Prove (α β) γ ((α γ) (β γ)). (α β) γ γ (α β) (γ α) (γ β) (α γ) (β γ) Commuttivity Distriutivity Commuttivity This result cn lso e shown using truth tle. 1

Quiz 2, Rules of Inference Dte: Septemer 15 1. (4pts) Prove (( p q) q) p. 1 [( p q) q] Assumption 2 p q elimintion 1 q elimintion 1 4 p Modus tollens 2, 5 p Doule negtion 4 6 (( p q) q) p introduction 1,5 2. (6pts) Prove ((p q) r) (p (q r)). 1 [(p q) r] Assumption 2 [p] Assumption [q] Assumption 4 p q introduction 2, 5 r Modus ponens 1,4 6 q r introduction,5 7 p (q r) introduction 2,6 8 ((p q) r) (p (q r)) introduction 1,7 9 [p (q r)] Assumption 10 [p q] Assumption 11 p elimintion 10 12 q elimintion 10 1 q r Modus ponens 9,11 14 r Modus ponens 1,12 15 (p q) r introduction 10,14 16 (p (q r)) ((p q) r) introduction 9,15 17 ((p q) r) (p (q r)) introduction 8,16 2

Quiz, Predicte Logic Dte: Septemer 22 1. (4pts) Evlute i I + : j I i : j 2 = i. True. If i = 1, then I i = {1}, so j must e 1 s well. Since (1) 2 = 1, nd it is sufficient to find single vlue of i which stisfies the expression, the expression evlutes to true. 2. (6pts) Given ODD(i) nd P RIM E(i) ssert every even integer greter thn two is the sum of two primes. To express tht x is even nd greter thn 2 : ODD(x) (x > 2) To express tht x is the sum of two primes : y I + : z I + : PRIME(y) PRIME(z) (x = y +z) Altogether ( if ny x is n even integer greter thn 2, then it is the sum of two primes ): x I + : ( ODD(x) (x > 2)) ( y I + : z I + : PRIME(y) PRIME(z) (x = y +z)) Note: the ssertion given here is lso known s Goldch s conjecture. The conjecture hs no known proof s of yet, ut it hs een numericlly verified to e true for s fr s it hs een computtionlly fesile.

Quiz 4, Mthemticl Induction Dte: Septemer 29 1. (6pts) Prove y induction n i=0 i(i+1) = n(n+1)(n+2) for n 0 When n = 0, we hve 0 i=0 i(i+1) = 0(0+1) = 0 = 0(0+1)(0+2) = 0 Assume tht for some k 0, k i(i+1) = i=0 k(k +1)(k +2) We would like to prove the k +1 cse, k+1 i(i+1) = i=0 (k +1)((k +1)+1)((k +1)+2) = (k +1)(k +2)(k +) To do this, we egin with the left hnd side, nd sustitute the inductive hypothesis, k+1 i(i+1) = (k +1)((k +1)+1)+ i=0 = (k +1)((k +1)+1)+ = (k +1)(k +2) = + k i(i+1) i=0 k(k +1)(k +2) k(k +1)(k +2) (k +1)(k +2)(k +) This proves the inductive conclusion, thus y mthemticl induction, the theorem is proved. 4

2. (4pts) Give forml outline of the proof of x N : p(x). 1 p(0) Bse cse 2 [k N] Assumption [p(k)] Assumption 4 p(k +1) proof of IC 5 p(k) p(k +1) introduction,4 6 x N : p(x) p(x+1) introduction 2,5 7 x N : p(x) Mthemticl induction 1,6 5

Quiz 5, Progrm Verifiction Dte: Octoer 6 1. Assume n 0. i 0 s 1 while i < n do s 2 s i i+1 s s 6 () (pts) Give the loop invrint. (i n) (s = 4 i ) After initiliztion, i = 0 nd s = 1, so (0 n) (1 = 4 0 ). () (5pts) Prove the loop invrint. (i n) (s = 4 i ) (i < n) {s 2 s} (i n) (s = 2 4i ) (i < n) (i n) (s = 2 4i ) (i < n) {i i+1} (i n) (s = 2 4i 1 ) (i n) (s = 2 4i 1 ) {s s 6} (i n) (s = 2 4i 1 6 = 4 4 i 1 = 4 i ) (i n) (s = 4 i ) (i < n) {s 2 s;i i+1;s s 6} (i n) (s = 4i ) (c) (2pts) Apply the loop invrint. (i n) (s = 4 i ) (i < n) {s 2 s;i i+1;s s 6} (i n) (s = 4i ) (i n) (s = 4 i ){whilei < ndos 2 s;i i+1;s s 6}(i n) (s = 4i ) (i < n) 6

Quiz 6, Regulr Expressions Dte: Octoer 27 1. (5pts) Give regulr expression for Σ = {,}, L = {x x does not contin }. If string does not contin, nd there re s in the string, then they must either e preceded y n, or they must e prt of sustring of s t the eginning of the string. If (+) is the set of ll strings, then (+) is the set of strings in which every is preceded y n, nd the finl nswer is: (+) 2. (5pts) Give regulr expression for L = {x x contins n efore every }. ex. L, L There re two cses to consider, one in which there re no s nd one in which there re s. If there re no s, then the resulting string cn e expressed s. If there re s, then the string cn e constructed s follows. There is first, with t lest two s efore it, nd nything fter it. Thus, ( )(+). Altogether, the solution is: +( )(+) 7

Quiz 7, Regulr Grmmrs Dte: Novemer 1. (10pts) Convert this regulr expression into regulr grmmr with unit productions: +c. 6 + 4 5 c 2 1 P 1 = {S 1 A 1,A 1 Λ} P 2 = {S 2 Λ,S 2 S 1,S 1 A 1,A 1 S 2 } P = {S A,A Λ} P 4 = {S 4 S 2,S 2 S,S 2 S 1,S 1 A 1,A 1 S 2, S A,A Λ} P 5 = {S 5 ca 5,A 5 Λ} P 6 = {S 6 S 4,S 6 S 5,S 5 ca 5,A 5 Λ, S 4 S 2,S 2 S,S 2 S 1,S 1 A 1,A 1 S 2,S A,A Λ} Using P 6, the strt symol is S 6. 8

Quiz 8, Regulr Grmmr Conversion Dte: Novemer 10 1. (6pts) P = {S A,S B,A A,B S,A Λ}, convert to regulr expression, removing S then A then B. First, dd S, H, nd missing loopcks. S S S A S B S S A A A H B S B B H Λ Remove S. S S / S S / S A : S A S S / S S / S B : S B B S / S S / S A : B A B S / S S / S B : B B After removing S, the remining productions re: S A S B A A A H B A B (Λ+)B H Λ Remove A. S A / A A / A H : S H B A / A A / A H : B H After removing A, the remining productions re: S B S H B H B (Λ+)B H Λ 9

Remove B. S B / B (Λ+)B / B H : S () H After removing B, the remining productions re: S +() H H Λ Regulr expression: +() 2. (4pts) P = {S A,S B,B S,B A,A S}, convert to regulr grmmr without unit productions. Solution: S A S B B S B A A S B A S S B B B S 10

Quiz 9, Finite Automt Dte: Novemer 17 1. (5pts) Write DFA for L, Σ = {,,c}, L = {x if x hs n nd then x hs c}, c L, c L. Solution: q 0 - no s, s, or cs q - s ut no s or cs q - s ut no s or cs q - s nd s ut no cs q c - t lest one c q c strt q 0 c q c,,c c q, c q 11

2. (5pts) Write n NFA for L, Σ = {,}, L = {x the rd chrcter is the sme s the rd from the end}, L. Solution:,, strt,,,,,,, 12

Quiz 10, Finite Automt nd Regulr Lnguges Dte: Novemer 22 1. (pts)provel = {x xhsthesmenumerofsss}isnotregulr. Solution: Let S = { i i 0}. Let x = i nd y = j e ny pir of distinct elements in S (thus, i j). If z = i, then x nd y re distinguishle, ecuse xz L ut yz / L. Since there is n infinite numer of elements in S, ll of which re mutully distinguishle, then it is impossile to express L s regulr lnguge. 2. (4pts) Convert this into the corresponding regulr grmmr. strt S A B C Solution: S A A A A B B S B B B C B Λ C A. (pts) Prove A B = {x x A or x B, ut not oth} is closed for regulr lnguges. Solution: Let s first rewrite A B in more workle form. The set of x which reonlyinautnotb is(a B), whilethesetofxwhichreonlyinb ut not A is (B A). Altogether, this mkes A B = (A B) (B A). Since A nd B re oth regulr, nd since union, intersection, nd set complement re ll closed under regulr lnguges, then the result of n expression using only those opertions must lso e regulr. 1

Quiz 11, Context Free Grmmrs Dte: Decemer 1 1. (5pts) Give CFG for L = { i j c k j > i+k +}. If j > i+k +, then j = i+k +(l+4), for some l 0. Thus, i j c k cn e rewritten s i i+k+l+4 c k, which equls ( i i )( l )( 4 )( k c k ). ( i i ) cn e generted y A A Λ. ( l ) cn e generted y B B Λ. 4 is simply. ( k c k ) cn e generted y C Cc Λ. Altogether, this gives: S ABC A A Λ B B Λ C Cc Λ 2. (5pts) Give CFG for the set of fully prenthesized propositions using,, nd vriles,, e.g. (( ( )) ). Two different solution types would get credit. The set of fully prenthesized propositions: S ( S) (S S) (S S) The set of prenthesized expressions (which is not the sme s fully prenthesized propositions, ut still receives credit) is: S S S S S S (S) 14

Quiz 12, Pushdown Automt Dte: Decemer 8 1. (10pts) Give stte trnsition digrm for PDA for L = {x x is lnced for [,],{,}}. Solution: For every strting [, push B for squre rcket, nd for every strting {, push C for curly rce. If closing rcket or rce is encountered, pop the corresponding symol from the stck. If there re multiple consecutive sets of lnced rckets nd rces, we do not wnt the stck to ecome empty fter the first set, so when dding new opening rcket or rce, one option will e to preseve the strt symol. The solution cn e implemented in single stte. We use PDA model which does not include ccept sttes, so solutions which use ccept sttes will not receive full credit. strt [,S/B [,S/BS [,B/BB [,C/BC ],B/Λ {,S/C {,S/CS {,B/CB {,C/CC },C/Λ 15