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

CSE 105 THEORY OF COMPUTATION

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

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

DVA337 HT17 - LECTURE 4. Languages and regular expressions

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

Languages and Strings. Chapter 2

Chapter Seven: Regular Expressions

Lexical Analysis. Lecture 2-4

Lexical Analysis. Chapter 2

Lexical Analysis. Lecture 3-4

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

CSE 105 THEORY OF COMPUTATION

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

Strings, Languages, and Regular Expressions

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

Implementation of Lexical Analysis. Lecture 4

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

CSE 105 THEORY OF COMPUTATION

Languages and Finite Automata

Notes for Comp 454 Week 2

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

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

CS402 - Theory of Automata FAQs By

Ambiguous Grammars and Compactification

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

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

Decision Properties of RLs & Automaton Minimization

Formal Languages and Automata

ECS 120 Lesson 7 Regular Expressions, Pt. 1

Implementation of Lexical Analysis

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

KHALID PERVEZ (MBA+MCS) CHICHAWATNI

Introduction to Lexical Analysis

JNTUWORLD. Code No: R

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

Lexical Analysis. Implementation: Finite Automata

CSE 431S Scanning. Washington University Spring 2013

Multiple Choice Questions

Implementation of Lexical Analysis

CSE 105 THEORY OF COMPUTATION

Actually talking about Turing machines this time

Implementation of Lexical Analysis

Chapter 4: Regular Expressions

CSE 105 THEORY OF COMPUTATION

Dr. D.M. Akbar Hussain

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

Regular Languages and Regular Expressions

1.3 Functions and Equivalence Relations 1.4 Languages

Regular Expressions & Automata

Lexical Analysis. Prof. James L. Frankel Harvard University

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

(Refer Slide Time: 0:19)

CSE 105 THEORY OF COMPUTATION

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

Zhizheng Zhang. Southeast University


CS 314 Principles of Programming Languages

COMP Logic for Computer Scientists. Lecture 25

UNION-FREE DECOMPOSITION OF REGULAR LANGUAGES

Learn Smart and Grow with world

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

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

Converting a DFA to a Regular Expression JP

Regular Expressions. Chapter 6

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

lec3:nondeterministic finite state automata

6 NFA and Regular Expressions

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

Implementation of Lexical Analysis

Implementation of Lexical Analysis

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

Models of Computation II: Grammars and Pushdown Automata

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

8 ε. Figure 1: An NFA-ǫ

Front End: Lexical Analysis. The Structure of a Compiler

Automating Construction of Lexers

TOPIC PAGE NO. UNIT-I FINITE AUTOMATA

CS 314 Principles of Programming Languages. Lecture 3

14.1 Encoding for different models of computation

CS103 Handout 14 Winter February 8, 2013 Problem Set 5

Automata Theory CS S-FR Final Review

Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

UNIT I PART A PART B

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Compiler Construction

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

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

Compiler Construction

Theory of Computation Dr. Weiss Extra Practice Exam Solutions

Lexical Analysis. Lecture 3. January 10, 2018

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

QUESTION BANK. Formal Languages and Automata Theory(10CS56)

Name: Finite Automata

CS308 Compiler Principles Lexical Analyzer Li Jiang

MA/CSSE 474. Today's Agenda

Transcription:

Finite Automata Part Three

Friday Four Square! Today at 4:15PM, Outside Gates.

Announcements Problem Set 4 due right now. Problem Set 5 out, due next Friday, November 2. Play around with finite automata and regular languages. No checkpoint problems.

Midterm Midterm is next Monday, October 29 in Cubberly Auditorium from 7PM 10PM. Covers material up through and including this Monday's lecture on finite automata and DFAs. Review session this Saturday, October 27 in Gates 104 at 2PM.

Designing NFAs

NFAs An NFA is a Nondeterministic Finite Automaton Conceptually similar to a DFA, but equipped with the vast power of nondeterminism. There can be many or no transitions defined on certain inputs. An NFA accepts a string if any series of choices causes the string to enter an accepting state.

Guess-and-Check L = { w {0, 1}* w ends in 010 or 101 } 1 0 0 start Σ 1 0 1

Guess-and-Check L = { w {a, b, c}* at least one of a, b, or c is not in w } a, b ε a, c start ε ε b, c

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!

Simulation Simulation is a key technique in computability theory. If we can build an automaton A' whose behavior simulates that of another automaton A, then we can make a connection between A and A'. To show that any language accepted by an NFA can be accepted by a DFA, we will show how to make a DFA that simulates the execution of an NFA.

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). Intuitively: States of the new DFA correspond to sets of states of the NFA. The initial state is the start state, plus all states reachable from the start state via ε-transitions. Transition on state S on character a is found by following all possible transitions on a for each state in S, then taking the set of states reachable from there by ε-transitions. Accepting states are any set of states where some state in the set is an accepting state. 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. 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 language L is called a regular language iff 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.

The Union of Two Languages If L 1 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 L 1 and L 2 are regular languages, is L 1 L 2? ε L 1 start ε 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

Concatenation The concatenation of two languages L 1 and L 2 over the alphabet Σ is the language L 1 L 2 = { wx Σ* w L 1 x L 2 } The set of strings that can be split into two pieces: a string from L 1 and a string from L 2.

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

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

Concatenating Regular Languages ε start ε ε

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.

The Kleene Closure An important operation on languages is the Kleene Closure, which is defined as L * = L i i = 0 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 How do we prove properties of this infinite union? 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 So their infinite union is regular.

Reasoning about Infinity x x

Reasoning about Infinity x x

Reasoning About the Infinite If a series of finite objects all have some property, their infinite union does not necessarily have that property! No matter how many times we zigzag that line, it's never straight. Concluding that it must be equal in the limit is not mathematically precise. (This is why calculus is interesting). A better intuition: Can we convert an NFA for the language L to an NFA for the language L*?

The Kleene Star ε ε start ε

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, difference, complement, concatenation, and Kleene closure of regular languages are all regular languages.

Another View of Regular Languages

Rethinking Regular Languages We currently have several tools for showing a language is regular. Construct a DFA for it. Construct an NFA for it. Apply closure properties to existing languages. We have not spoken much of this last idea.

Constructing Regular Languages Idea: Build up all regular languages as follows: Start with a small set of simple languages we already know to be regular. Using closure properties, combine these simple languages together to form more elaborate languages. A bottom-up approach to the regular languages.

Regular Expressions Regular expressions are a family of descriptions that can be used to capture the regular languages. Often provide a compact and humanreadable description of the language. Used as the basis for numerous software systems (Perl, flex, grep, etc.)

Atomic Regular Expressions The regular expressions begin with three simple building blocks. The symbol Ø is a regular expression that represents the empty language Ø. The symbol ε is a regular expression that represents the language { ε } This is not the same as Ø! For any a Σ, the symbol a is a regular expression for the language { a }

Compound Regular Expressions We can combine together existing regular expressions in four ways. If R 1 and R 2 are regular expressions, R 1 R 2 is a regular expression represents the concatenation of the languages of R 1 and R 2. If R 1 and R 2 are regular expressions, R 1 R 2 is a regular expression representing the union of R 1 and R 2. If R is a regular expression, R* is a regular expression for the Kleene closure of R. If R is a regular expression, (R) is a regular expression with the same meaning as R.

Operator Precedence Regular expression operator precedence is (R) R* R 1 R 2 R 1 R 2 So ab*c d is parsed as ((a(b*))c) d

Regular Expression Examples The regular expression trick treat represents the regular language { trick, treat } The regular expression booo* represents the regular language { boo, booo, boooo, } The regular expression candy!(candy!)* represents the regular language { candy!, candy!candy!, candy!candy!candy!, }

Regular Expressions, Formally The language of a regular expression is the language described by that regular expression. Formally: L(ε) = {ε} L(Ø) = Ø L(a) = {a} L(R 1 R 2 ) = L(R 1 ) L(R 2 ) L(R 1 R 2 ) = L(R 1 ) L(R 2 ) L(R*) = L(R)* L((R)) = L(R)