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

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

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

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

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

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

Designing finite automata II

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

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

Let's start with an example:

Formal languages, automata, and theory of computation

Some Theory of Computation Exercises Week 1

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

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

Minimal DFA. minimal DFA for L starting from any other

Nondeterminism and Nodeterministic Automata

1 From NFA to regular expression

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

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.

Regular Language. Nonregular Languages The Pumping Lemma. The pumping lemma. Regular Language. The pumping lemma. Infinitely long words 3/17/15

Chapter 2 Finite Automata

Lecture 3: Equivalence Relations

Lecture 09: Myhill-Nerode Theorem

3 Regular expressions

1 Nondeterministic Finite Automata

Homework 3 Solutions

CMSC 330: Organization of Programming Languages

Finite Automata-cont d

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

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

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.

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

Non-deterministic Finite Automata

Converting Regular Expressions to Discrete Finite Automata: A Tutorial

Convert the NFA into DFA

Harvard University Computer Science 121 Midterm October 23, 2012

First Midterm Examination

Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem. Kleene s Theorem 2/16/15

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

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

First Midterm Examination

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

Non-deterministic Finite Automata

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

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

Parse trees, ambiguity, and Chomsky normal form

Coalgebra, Lecture 15: Equations for Deterministic Automata

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

Deterministic Finite Automata

Java II Finite Automata I

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

2.4 Linear Inequalities and Interval Notation

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

Lecture 08: Feb. 08, 2019

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

State Minimization for DFAs

CSCI 340: Computational Models. Transition Graphs. Department of Computer Science

Name Ima Sample ASU ID

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

Formal Languages and Automata

Theory of Computation Regular Languages

Quadratic Forms. Quadratic Forms

Finite-State Automata: Recap

E 1 (n) = E 0 (n-1) E 0 (n) = E 0 (n-1)+e 0 (n-2) T(n -1)=2E 0 (n-2) + E 0 (n-3)

CHAPTER 1 Regular Languages. Contents

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

Bases for Vector Spaces

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

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

Improper Integrals. The First Fundamental Theorem of Calculus, as we ve discussed in class, goes as follows:

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

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

CSE396 Prelim I Answer Key Spring 2017

Riemann Sums and Riemann Integrals

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

Riemann Sums and Riemann Integrals

NFA DFA Example 3 CMSC 330: Organization of Programming Languages. Equivalence of DFAs and NFAs. Equivalence of DFAs and NFAs (cont.

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

Math Lecture 23

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.

Fundamentals of Computer Science

How do we solve these things, especially when they get complicated? How do we know when a system has a solution, and when is it unique?

Tutorial Automata and formal Languages

Bridging the gap: GCSE AS Level

Lecture 2e Orthogonal Complement (pages )

Surface maps into free groups

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

CISC 4090 Theory of Computation

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

Lecture 9: LTL and Büchi Automata

CS375: Logic and Theory of Computing

Worked out examples Finite Automata

Exponentials - Grade 10 [CAPS] *

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

1.4 Nonregular Languages

The practical version

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

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

Turing Machines Part One

Handout: Natural deduction for first order logic

Chapter 0. What is the Lebesgue integral about?

Transcription:

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 of the simplest models of computing. We spent good del of time getting fmilir with how they work, y constructing exmples of DFAs ccepting given lnguges. Tody, we wnt to tke closer look t the kind of lnguges ccepted y DFAs. We give them specil nme regulr lnguges. Ultimtely, we wnt to get feel for wht regulr lnguges look like, to identify them y sight. In tht connection, our first tsk is to figure out how to uild new regulr lnguges out of old ones. The first such construction is tking the complement of lnguge. In other words, if we hve regulr lnguge (one ccepted y some DFA), we wnt to look t the lnguge contining ll nd only the strings tht re not in tht first lnguge. It turns out this lnguge is lwys regulr s well. To get sense for it, let s look t specific exmple. Let s re-visit the ABBA mchine from lst time: 0 1 2 3 4 ; The lnguge ccepted y this mchine is the set of strings where is repeted ny numer of times (including zero). Now, we wnt to uild DFA tht ccepts exctly the opposite kind of strings. In other words, this new DFA should reject the strings where is repeted ny numer of times, ut it should ccept everything else. Is there n esy wy to tke the DFA we hve nd produce DFA ccepting this new lnguge, the complement lnguge? The quick nd esy solution is this: we wnt DFA tht ccepts ll the strings tht used to e rejected, 1

nd rejects ll the strings tht used to e ccepted. If we just swp the ccepting nd rejecting sttes of the originl mchine, we ll get DFA ccepting the complement of the ABBA lnguge: 0 1 2 3 4 ; Given this ide, cn you propose the wy to do this in generl? Given DFA ccepting certin lnguge, how cn we modify it to crete DFA ccepting the complementry lnguge? The sme ide pplies: tke the originl DFA, turn ll its ccepting sttes into rejecting sttes, nd turn ll its rejecting sttes into ccepting sttes. This rgument tells us tht given regulr lnguge, the complement of tht lnguge is lso regulr we ve uilt new regulr lnguge out of n old one. Of course, there re mny more things of this kind tht we cn do. Given two regulr lnguges, which we ll cll L 1 nd L 2, there re two relted lnguges we cn uild. First, we might wnt to uild new DFA ccepting only the strings elonging to oth L 1 nd L 2. Second, we my wnt to uild new DFA ccepting the strings elonging to either L 1 or L 2. Like efore, we will illustrte with n exmple. Lst time, you uilt DFA tht ccepts the strings strting nd ending with, nd you lso uilt one ccepting exctly the strings contining somewhere in the string. In other words, oth these lnguges re regulr. 2

One possile DFA ccepting the first lnguge is: 0 2 3 1 ; One possile DFA ccepting the second lnguge is: 0 1 2 3 ; Given these two DFAs, is there wy to uild DFA ccepting the intersection of the two lnguges? In other words, we wnt DFA ccepting only the strings elonging to oth lnguges. More concretely, it will ccept the strings strting nd ending with tht lso contin somewhere in the string. Tke few minutes to cht this over. We ll tke it up s group shortly. The key to this is tht we need to keep trck of wht s hppening in oth mchines t the sme time. You cn imgine running oth mchines in prllel, giving them oth the sme string independently. Ech mchine will either ccept or reject the string, nd we only wnt to ccept the string in the end if oth mchines hve ccepted the string. The cool prt is tht we cn model this with single DFA. In this new DFA, we keep trck of pirs of sttes, one for ech of the two originl DFAs. Ech stte in the new DFA mtches up with pir of sttes from the old DFAs. Then, when the new DFA reds letter, ech stte in the pir chnges in the sme wy tht the two old DFAs would hve. The ccepting sttes of the new DFA mtch up with pirs of ccepting sttes from the two old DFAs, since we only wnt to ccept the strings tht oth the old DFAs liked. Here s wht we get when ll is sid nd done: 3

(2;3) (0;0) (2;1) (3;2) (3;3) ; (1;0) (1;1) (1;2) (1;3) In this new DFA, ll the sttes re hve pirs of numers in the lels. The first numer represents stte in the first DFA, nd the second numer represents stte in the second DFA. For exmple, stte (2, 1) represents the first DFA eing in stte 2, nd the second eing in stte 1. If you give to oth mchines, the first mchine moves to stte 3 nd the second moves to stte 2, so the new DFA moves to stte (3, 2). If you give to oth mchines insted, oth of them sty in the sme stte, so the DFA stys in stte (2, 1). Notice tht (2, 3) is the only ccepting stte in this new mchine. This is ecuse the only wy oth of the originl DFAs ccept string is if the first ends up in stte 2 nd the second ends up in stte 3. You cn convince yourself tht this DFA ccepts the intersection of the two lnguges: ll the strings strting nd ending with, nd which contin somewhere. Using similr ide, we cn uild DFA ccepting the union of these two lnguges: ll the strings elonging to either lnguge. In our prticulr exmple, this mens the collection of strings tht strt nd end with, OR contin somewhere. In our minds, we get the sme intuitive ide: imgine running the two originl DFAs with the sme input, nd keeping trck of which sttes oth re in t ny given time. After oth finish reding the string, we ccept it if either DFA hs ccepted it. With this in mind, look ck t the DFA ccepting the intersection of the two lnguges. Wht smll djustment cn we mke to it so tht it ccepts the union insted? All we hve to chnge re the ccepting sttes of the mchine. We now wnt the DFA to ccept the string if either stte in the pir is n ccepting stte for the mtching DFA. Since stte 2 is n ccepting stte for the first DFA, ny stte in the new mchine strting with 2 should e n ccepting stte. Likewise, since 4

stte 3 is n ccepting stte in the second DFA, ny stte in the new mchine ending with 3 should e n ccepting stte s well. The end result looks like this: (2;3) (0;0) (2;1) (3;2) (3;3) ; (1;0) (1;1) (1;2) (1;3) This is the mchine ccepting the strings tht either strt nd end with, or else contin somewhere inside of them. All right, let s recp to mke sure you ve got the gist. Let s sy I give you two DFAs, ccepting two different lnguges. How do I uild DFA ccepting only the strings elonging to oth lnguges? To either lnguge? Gret! We hve now descried severl different wys to mke new regulr lnguges out of old ones. We cn tke the complement of lnguge, or the union or intersection of two lnguges. But now the ll-importnt question: is every lnguge regulr lnguge? In other words, if you write down ny old collection of strings, cn we lwys uild DFA ccepting exctly tht collection? Tke five minutes to ply with this question now, chtting it over with your friends. The key to this question is tht DFAs only hve fixed, finite numer of sttes, nd the sttes re the only memory the DFA hs. Any lnguge requiring us to store n unounded mount of informtion cn never e hndled y DFA. The simplest exmple of this phenomenon is the lnguge of strings of the form n n, where n cn e ny whole numer igger thn or equl to 0. In other words, the strings in the lnguge re the empty string,,,, nd so on. The importnt thing is tht there is some numer of s, followed y n equl numer of s. 5

Now tht I ve given you this exmple, cn you explin why this lnguge cn t e regulr? Intuitively, we need to keep count of how mny s hve een red so fr, in order to mtch up the corresponding numer of s. But since ny numer of s re llowed, we seem to need infinitely mny sttes to keep trck of it ll. But let s convince ourselves eyond shdow of ll dout. Let s write down mthemticl proof tht this lnguge is not regulr. This will e n rgument no one cn disgree with. Suppose there ws DFA tht ccepted this lnguge. Necessrily, this DFA hs only finite numer of sttes. Now, let s trck wht sttes the DFA psses through s it reds unch of s in row. There re only so mny sttes to e in, so eventully, we ll e le to find two whole numers m nd n, where the DFA is in the sme stte fter reding m nd n. Mthemticins like to cll this the pigeonhole principle: if you re trying to put pigeons into oxes, nd you hve more pigeons thn oxes, t lest two pigeons must end up in the sme ox. In the lnguge of our prolem: we re trying to put strings of the form k into sttes, nd we hve more strings thn sttes, so t lest two of the strings end up ssocited to the sme stte. Let s sy tht the DFA ends up in stte q fter reding oth m nd n. Without doing ny hrm, we cn ssume m is smller thn n. Since this DFA ccepts the lnguge we re interested in, it ccepts the string m m. Therefore, if you strt in stte q nd red m letter s in row, you ll end up in some ccepting stte, which we ll cll r. But now we hve prolem. After reding n, the mchine lso ends up in stte q, so if the input is n m, we ll end up in stte q, then red m letter s in row, ending in stte r. This mens the DFA hs to ccept n m, ut this cn t e! All in ll, this mens no DFA cn ccept this lnguge we ve found lnguge tht s not regulr! Another very nturl lnguge (for computers) tht isn t regulr is the lnguge of legl rcketings. For this, pretend tht represents left rcket, nd represents right rcket (we could ctully use rckets s our symols, ut letters re esier to red). When you type n expression with rckets into computer or clcultor, wht s the rule you need to follow? You cn t hve right rcket without mtching left rcket coming first. In terms of letters, you cn t hve without mtching tht comes first. So is llowed, ut nything strting with is not, nd isn t either. I ll let you come up with n rgument for why this isn t regulr on your own, ut my hint is to tke close look t the rgument we just finished using for the other lnguge! Conclusion Tody, we got much etter sense of how regulr lnguges work. First, we explored how to uild new regulr lnguges from old ones, y tking complements, unions, nd intersections. Then, we discovered tht not ll lnguges re regulr: some re just too complicted to e ccepted y ny DFA. The nturl question is: how cn we chnge the design of the DFA to ccept more lnguges? Next time, we ll explore one possile option mking the DFA non-deterministic, llowing it to mke choices. This hs some interesting tie-ins with the modern dy concept of quntum computers. 6