Finite Automata Part Three

Similar documents
Finite Automata Part Three

Finite Automata Part Three

CHAPTER TWO LANGUAGES. Dr Zalmiyah Zakaria

Glynda, the good witch of the North

Automata Theory TEST 1 Answers Max points: 156 Grade basis: 150 Median grade: 81%

(Refer Slide Time: 0:19)

1. (10 points) Draw the state diagram of the DFA that recognizes the language over Σ = {0, 1}

CS402 Theory of Automata Solved Subjective From Midterm Papers. MIDTERM SPRING 2012 CS402 Theory of Automata

Proof Techniques Alphabets, Strings, and Languages. Foundations of Computer Science Theory

CSE 105 THEORY OF COMPUTATION

Finite Automata. Dr. Nadeem Akhtar. Assistant Professor Department of Computer Science & IT The Islamia University of Bahawalpur

DVA337 HT17 - LECTURE 4. Languages and regular expressions

CS103 Handout 35 Spring 2017 May 19, 2017 Problem Set 7

Chapter Seven: Regular Expressions

Finite automata. We have looked at using Lex to build a scanner on the basis of regular expressions.

Strings, Languages, and Regular Expressions

CMPSCI 250: Introduction to Computation. Lecture #36: State Elimination David Mix Barrington 23 April 2014

Languages and Strings. Chapter 2

Regular Languages. MACM 300 Formal Languages and Automata. Formal Languages: Recap. Regular Languages

Welcome! CSC445 Models Of Computation Dr. Lutz Hamel Tyler 251

Ambiguous Grammars and Compactification

1.3 Functions and Equivalence Relations 1.4 Languages

Last lecture CMSC330. This lecture. Finite Automata: States. Finite Automata. Implementing Regular Expressions. Languages. Regular expressions

Languages and Finite Automata

Formal Languages and Automata

NFAs and Myhill-Nerode. CS154 Chris Pollett Feb. 22, 2006.

Notes for Comp 454 Week 2

CS402 - Theory of Automata FAQs By

14.1 Encoding for different models of computation

CMPSCI 250: Introduction to Computation. Lecture #28: Regular Expressions and Languages David Mix Barrington 2 April 2014

Multiple Choice Questions

I have read and understand all of the instructions below, and I will obey the Academic Honor Code.

CS103 Handout 13 Fall 2012 May 4, 2012 Problem Set 5

Lexical Analysis. Lecture 2-4

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

CS103 Handout 39 Winter 2018 February 23, 2018 Problem Set 7

Chapter 4: Regular Expressions

Automating Construction of Lexers

Complexity Theory. Compiled By : Hari Prasad Pokhrel Page 1 of 20. ioenotes.edu.np

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Regular Expressions. Lecture 10 Sections Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2016

HKN CS 374 Midterm 1 Review. Tim Klem Noah Mathes Mahir Morshed

CMPSCI 250: Introduction to Computation. Lecture 20: Deterministic and Nondeterministic Finite Automata David Mix Barrington 16 April 2013

Implementation of Lexical Analysis

CS103 Handout 42 Spring 2017 May 31, 2017 Practice Final Exam 1

Decision Properties of RLs & Automaton Minimization

6 NFA and Regular Expressions

CSE 105 THEORY OF COMPUTATION

CS103 Handout 50 Fall 2018 November 30, 2018 Problem Set 9

UNIT I PART A PART B

Converting a DFA to a Regular Expression JP

Dr. D.M. Akbar Hussain

Lexical Analysis. Lecture 3-4

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

Context-Free Grammars

COMP Logic for Computer Scientists. Lecture 25

Skill 1: Multiplying Polynomials

Automata Theory CS S-FR Final Review

CS 403 Compiler Construction Lecture 3 Lexical Analysis [Based on Chapter 1, 2, 3 of Aho2]

Turing Machines Part Two

Implementation of Lexical Analysis. Lecture 4

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Actually talking about Turing machines this time

Regular Languages and Regular Expressions

Definition: A context-free grammar (CFG) is a 4- tuple. variables = nonterminals, terminals, rules = productions,,

Lexical Analysis. Chapter 2

lec3:nondeterministic finite state automata

CS 432 Fall Mike Lam, Professor. Finite Automata Conversions and Lexing

8 ε. Figure 1: An NFA-ǫ

CS 314 Principles of Programming Languages

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Formal Languages and Compilers Lecture IV: Regular Languages and Finite. Finite Automata

Ling/CSE 472: Introduction to Computational Linguistics. 4/6/15: Morphology & FST 2


Lexical Analysis. Dragon Book Chapter 3 Formal Languages Regular Expressions Finite Automata Theory Lexical Analysis using Automata

Introduction to Lexical Analysis

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Chapter Seven: Regular Expressions. Formal Language, chapter 7, slide 1

1. Draw the state graphs for the finite automata which accept sets of strings composed of zeros and ones which:

Decidable Problems. We examine the problems for which there is an algorithm.

Lexical Analysis. Implementation: Finite Automata

Turing Machine Languages

COMP 330 Autumn 2018 McGill University

MA/CSSE 474. Today's Agenda

Introduction to Computers & Programming

CS2 Language Processing note 3

Implementation of Lexical Analysis

Regular Expressions & Automata

Implementation of Lexical Analysis

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2016

Lecture 2 Finite Automata

Lecture 6,

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Lexical Analysis. Prof. James L. Frankel Harvard University

Non-deterministic Finite Automata (NFA)

Automata & languages. A primer on the Theory of Computation. The imitation game (2014) Benedict Cumberbatch Alan Turing ( ) Laurent Vanbever

CSE450. Translation of Programming Languages. Lecture 20: Automata and Regular Expressions

How to Improve Your Campaign Conversion Rates

CS308 Compiler Principles Lexical Analyzer Li Jiang

Transcription:

Finite Automata Part Three

Recap from Last Time

A language L is called a regular language if there exists a DFA D such that L( D) = L.

NFAs An NFA is a Nondeterministic Finite Automaton Can have missing transitions or multiple transitions defined on the same input symbol. Accepts if any possible series of choices leads to an accepting state.

ε-transitions NFAs have a special type of transition called the ε-transition. An NFA may follow any number of ε-transitions at any time without consuming any input. start a q a 0 q 1 a q 2 ε q 03 ε b, ε q 4 b q 5 b b a a b b

New Stuff!

NFAs and DFAs Any language that can be accepted by a DFA can be accepted by an NFA. Why? Just use the same set of transitions as before. Question: Can any language accepted by an NFA also be accepted by a DFA? Surprisingly, the answer is yes!

Finite Automata NFAs and DFAs are finite automata; there can only be finitely many states in an NFA or DFA. An NFA can be in any combination of its states, but there are only finitely many possible combations. Idea: Build a DFA where each state of the DFA corresponds to a set of states in the NFA.

Simulating an NFA with a DFA 0 start q 0 0 1 q 1 q 2 ε q 3 0 q 4 0 q 5 1

Simulating an NFA with a DFA start ε q 0 q 3 0 1 0 q 1 q 4 0 0 q 2 q 5 q 14 0 0 1 1 0, 1 q 03 start q 1 0 2 q q 5 1 1 0 0 1 0 q 1 q 4 0 1 q 3 1

The Subset Construction This construction for transforming an NFA into a DFA is called the subset construction (or sometimes the powerset construction). Each state in the DFA is associated with a set of states in the NFA. The start state in the DFA corresponds to the start state of the NFA, plus all states reachable via ε-transitions. If a state q in the DFA corresponds to a set of states S in the NFA, then the transition from state q on a character a is found as follows: Let S' be the set of states in the NFA that can be reached by following a transition labeled a from any of the states in S. (This set may be empty.) Let S'' be the set of states in the NFA reachable from some state in S' by following zero or more epsilon transitions. The state q in the DFA transitions on a to a DFA state corresponding to the set of states S''. Read Sipser for a formal account.

The Subset Construction In converting an NFA to a DFA, the DFA's states correspond to sets of NFA states. Useful fact: (S) = 2 S for any finite set S. In the worst-case, the construction can result in a DFA that is exponentially larger than the original NFA. Interesting challenge: Find a language for which this worst-case behavior occurs (there are infinitely many of them!)

a, b q₁ ε a, c start q₀ ε q₂ ε b, c q₃

a, b *q₀₁₂₃ a b c q₁₂ q₁₃ q₂₃ q₁ *q₁₂ q₁₂ q₁ q₂ ε a, c *q₁₃ q₁ q₁₃ q₃ start q₀ ε q₂ *q₂₃ q₂ q₃ q₂₃ ε b, c *q₁ *q₂ q₁ q₁ q q₂ q q₂ q₃ *q₃ q q₃ q₃ q q q q

A language L is called a regular language if there exists a DFA D such that L( D) = L.

An Important Result Theorem: A language L is regular iff there is some NFA N such that L( N) = L. Proof Sketch: If L is regular, there exists some DFA for it, which we can easily convert into an NFA. If L is accepted by some NFA, we can use the subset construction to convert it into a DFA that accepts the same language, so L is regular.

Why This Matters We now have two perspectives on regular languages: Regular languages are languages accepted by DFAs. Regular languages are languages accepted by NFAs. We can now reason about the regular languages in two different ways.

Time-Out for Announcements!

Problem Sets Problem Set Five is due right now. Feel free to use late days if you'd like. Problem Set Six goes out now. It's due on Friday, November 6. Play around with finite automata, regular expressions, and their properties! Some of the material requires Monday's lecture; it should be well-marked as such. A note: the printed problem sets are missing the last page. Sorry about that I'm not sure what went wrong there. Check the website for the most up-to-date version. Problem Set Four should be graded by the end of class today.

My Questions

This is a really rough time of the quarter for a lot of people. How are you doing? How are your dormmates / roommates / friends doing? What can we do to help out?

Your Questions

Tell us a cool story from your undergrad I'm I'm just just going going to to tell tell this this story story in in class. class. Sorry Sorry for for those those of of you you reading reading online! online!

Why isn't a domino called a biomino? Is a square a monomino? Three Three things things is is a a triple. triple. Four Four things things is is a a quadruple. quadruple. Why Why isn't isn't a a pair pair a a duple? duple? Or Or a a buple? buple? I I think think the the answer answer is is that that sounds sounds silly. silly. And And I I think think that's that's the the answer answer to to your your question. question.

What are the consequences associated with getting a No Credit on your transcript? (I'm in CS107 right now but seriously feel that I don't have time for this. I want to take it next quarter but am afraid it will cause me trouble later on) To To be be perfectly perfectly honest honest it's it's not not as as bad bad as as you you might might think. think. It It hurts hurts your your GPA GPA for for a a quarter quarter and and you you might might get get a a call call from from the the registrar, registrar, but but if if you you retake retake the the course course your your old old grade grade is is replaced replaced (you (you get get an an RP RP on on your your transcript) transcript) and and there there shouldn't shouldn't be be any any lingering lingering effects. effects. If If you you get get a a lot lot of of NC NC or or NP NP grades, grades, then then it's it's a a different different story. story. Als0, Als0, if if you're you're on on a a scholarship, scholarship, it it might might be be a a problem, problem, but but generally generally the the university university is is supportive supportive when when this this happens. happens. The The main main questions questions they'll they'll ask ask are are is is everything everything okay? okay? and and what what can can we we do do to to help? help? rather rather than than why why didn't didn't you you pass? pass?

What are your favorite novels? I I confess confess that that I I haven't haven't read read as as many many as as I I would would have have liked liked (I (I tend tend to to read read a a lot lot more more nonfiction nonfiction than than fiction). fiction). I I really really liked liked The The Trial Trial by by Kafka Kafka and and Radetzky Radetzky March March by by Joseph Joseph Roth. Roth. Do Do you you have have any any suggestions suggestions for for me? me? If If so, so, please please send send me me an an email! email!

Back to CS103!

Properties of Regular Languages

The Union of Two Languages If L1 and L 2 are languages over the alphabet Σ, the language L 1 L 2 is the language of all strings in at least one of the two languages. If L1 and L 2 are regular languages, is L 1 L 2? ε Machine for L 1 start Machine for L 1 L 2 ε Machine for L 2

The Intersection of Two Languages If L 1 and L 2 are languages over Σ, then L 1 L 2 is the language of strings in both L 1 and L 2. Question: If L 1 and L 2 are regular, is L 1 L 2 regular as well? L 1 L 2 Hey, Hey, it's it's De De Morgan's Morgan's laws! laws!

Concatenation

String Concatenation If w Σ* and x Σ*, the concatenation of w and x, denoted wx, is the string formed by tacking all the characters of x onto the end of w. Example: if w = quo and x = kka, the concatenation wx = quokka. Analogous to the + operator for strings in many programming languages.

Concatenation The concatenation of two languages L₁ and L₂ over the alphabet Σ is the language L₁L₂ = { wx Σ* w L₁ x L₂ } =Two views of L₁L₂: The set of all strings that can be made by concatenating a string in L₁ with a string in L₂. The set of strings that can be split into two pieces: a piece from L₁ and a piece from L₂. Conceptually similar to the Cartesian product of two sets, only with strings.

Concatenation Example Let Σ = { a, b,, z, A, B,, Z } and consider these languages over Σ: Noun = { Puppy, Rainbow, Whale, } Verb = { Hugs, Juggles, Loves, } The = { The } The language TheNounVerbTheNoun is { ThePuppyHugsTheWhale, TheWhaleLovesTheRainbow, TheRainbowJugglesTheRainbow, }

Concatenation The concatenation of two languages L₁ and L₂ over the alphabet Σ is the language L₁L₂ = { wx Σ* w L₁ x L₂ } Two views of L₁L₂: The set of all strings that can be made by concatenating a string in L₁ with a string in L₂. The set of strings that can be split into two pieces: a piece from L₁ and a piece from L₂. Conceptually similar to the Cartesian product of two sets, only with strings.

Concatenating Regular Languages If L1 and L 2 are regular languages, is L 1 L 2? Intuition can we split a string w into two strings xy such that x L 1 and y L 2? Idea: Run the automaton for L1 on w, and whenever L 1 reaches an accepting state, start start optionally hand the rest off w to L 2. If L2 accepts the remainder, then L 1 accepted the first part and the string is in L 1 L 2. Machine for L 1 Machine for L 2 If L2 rejects the remainder, then the split was incorrect. b o o k k e e p e r

Concatenating Regular Languages If L1 and L 2 are regular languages, is L 1 L 2? Intuition can we split a string w into two strings xy such that x L 1 and y L 2? Idea: Run the automaton for L1 on w, and whenever L 1 reaches an accepting state, optionally hand the rest off w to L 2. If L2 accepts the remainder, then L 1 accepted the first part and the string is in L 1 L 2. If L2 rejects the remainder, then the split was incorrect.

Concatenating Regular Languages ε start ε ε Machine for L 1 Machine for L 2 Machine for L 1 L 2

Lots and Lots of Concatenation Consider the language L = { aa, b } LL is the set of strings formed by concatenating pairs of strings in L. { aaaa, aab, baa, bb } LLL is the set of strings formed by concatenating triples of strings in L. { aaaaaa, aaaab, aabaa, aabb, baaaa, baab, bbaa, bbb} LLLL is the set of strings formed by concatenating quadruples of strings in L. { aaaaaaaa, aaaaaab, aaaabaa, aaaabb, aabaaaa, aabaab, aabbaa, aabbb, baaaaaa, baaaab, baabaa, baabb, bbaaaa, bbaab, bbbaa, bbbb}

Language Exponentiation We can define what it means to exponentiate a language as follows: L 0 = {ε} The set containing just the empty string. Idea: Any string formed by concatenating zero strings together is the empty string. L n+1 = LL n Idea: Concatenating (n+1) strings together works by concatenating n strings, then concatenating one more. Question: Why define L 0 = {ε}?

The Kleene Closure An important operation on languages is the Kleene Closure, which is defined as Mathematically: L * = L i i = 0 w L* iff n N. w L n Intuitively, all possible ways of concatenating any number of copies of strings in L together.

The Kleene Closure If L = { a, bb }, then L* = { ε, a, bb, aa, abb, bba, bbbb, aaa, aabb, abba, abbbb, bbaa, bbabb, bbbba, bbbbbb, }

Reasoning about Infinity If L is regular, is L* necessarily regular? A Bad Line of Reasoning: L 0 = { ε } is regular. L 1 = L is regular. L 2 = LL is regular L 3 = L(LL) is regular Regular languages are closed under union. So the union of all these languages is regular.

Reasoning about Infinity x x

Reasoning about Infinity x x

Reasoning about Infinity 2x x x

Reasoning about Infinity 0.999 < 1

Reasoning about Infinity 0.99999 < 1

Reasoning about Infinity 2 is finite

Reasoning about Infinity is finite ^ not

Reasoning About the Infinite If a series of finite objects all have some property, the limit of that process does not necessarily have that property. In general, it is not safe to conclude that some property that always holds in the finite case must hold in the infinite case. (This is why calculus is interesting).

Idea: Can we directly convert an NFA for language L to an NFA for language L*?

The Kleene Star ε ε start ε Machine for L Machine for L*

The Kleene Star ε ε start ε Question: Question: Why Why add add the the new new state state out out front? front? Why Why not not just just make make the the old old start start state state accepting? accepting? Machine for L Machine for L*

Summary NFAs are a powerful type of automaton that allows for nondeterministic choices. NFAs can also have ε-transitions that move from state to state without consuming any input. The subset construction shows that NFAs are not more powerful than DFAs, because any NFA can be converted into a DFA that accepts the same language. The union, intersection, complement, concatenation, and Kleene closure of regular languages are all regular languages.