Automata Theory. Lecture on Discussion Course of CS120. Runzhe SJTU ACM CLASS

Similar documents
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154. Finite Automata, Nondeterminism, Regular Expressions

CS 154, Lecture 2: Finite Automata, Closure Properties Nondeterminism,

CS 154 Introduction to Automata and Complexity Theory

Equivalence of DFAs and NFAs

CS 154, Lecture 3: DFA NFA, Regular Expressions

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Intro to Theory of Computation

Great Theoretical Ideas in Computer Science. Lecture 4: Deterministic Finite Automaton (DFA), Part 2

Theory of Computation (I) Yijia Chen Fudan University

CS 455/555: Finite automata

CS 154. Finite Automata vs Regular Expressions, Non-Regular Languages

UNIT-II. NONDETERMINISTIC FINITE AUTOMATA WITH ε TRANSITIONS: SIGNIFICANCE. Use of ε-transitions. s t a r t. ε r. e g u l a r

Finite Automata and Regular languages

CISC 4090: Theory of Computation Chapter 1 Regular Languages. Section 1.1: Finite Automata. What is a computer? Finite automata

Nondeterministic finite automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Sri vidya college of engineering and technology

Nondeterministic Finite Automata

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

CSE 105 THEORY OF COMPUTATION

Name: Student ID: Instructions:

Non-deterministic Finite Automata (NFAs)

Introduction to the Theory of Computation. Automata 1VO + 1PS. Lecturer: Dr. Ana Sokolova.

Lecture 3: Nondeterministic Finite Automata

HKN CS/ECE 374 Midterm 1 Review. Nathan Bleier and Mahir Morshed

Finite Automata (contd)

Lecture Notes On THEORY OF COMPUTATION MODULE -1 UNIT - 2

T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

CS243, Logic and Computation Nondeterministic finite automata

UNIT-III REGULAR LANGUAGES

CS 530: Theory of Computation Based on Sipser (second edition): Notes on regular languages(version 1.1)

Theory of Computation Lecture 1. Dr. Nahla Belal

CSE 105 THEORY OF COMPUTATION

3515ICT: Theory of Computation. Regular languages

1 More finite deterministic automata

Harvard CS 121 and CSCI E-207 Lecture 4: NFAs vs. DFAs, Closure Properties

Deterministic Finite Automata. Non deterministic finite automata. Non-Deterministic Finite Automata (NFA) Non-Deterministic Finite Automata (NFA)

CSE 105 Theory of Computation Professor Jeanne Ferrante

Proving languages to be nonregular

CSC173 Workshop: 13 Sept. Notes

Languages, regular languages, finite automata

Closure Properties of Regular Languages. Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism

Theory of Computation (II) Yijia Chen Fudan University

Further discussion of Turing machines

Formal Languages, Automata and Models of Computation

Final exam study sheet for CS3719 Turing machines and decidability.

CS21 Decidability and Tractability

Introduction to the Theory of Computing

Nondeterministic Finite Automata

Chapter Five: Nondeterministic Finite Automata

CS:4330 Theory of Computation Spring Regular Languages. Finite Automata and Regular Expressions. Haniel Barbosa

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Theory of Computation

SYLLABUS. Introduction to Finite Automata, Central Concepts of Automata Theory. CHAPTER - 3 : REGULAR EXPRESSIONS AND LANGUAGES

DM17. Beregnelighed. Jacob Aae Mikkelsen

CSE 105 THEORY OF COMPUTATION

CSCE 551 Final Exam, Spring 2004 Answer Key

Theory of Computation p.1/?? Theory of Computation p.2/?? Unknown: Implicitly a Boolean variable: true if a word is

What we have done so far

September 7, Formal Definition of a Nondeterministic Finite Automaton

The Pumping Lemma and Closure Properties

Automata & languages. A primer on the Theory of Computation. Laurent Vanbever. ETH Zürich (D-ITET) September,

Fooling Sets and. Lecture 5

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

Lecture 24: Randomized Complexity, Course Summary

Deterministic Finite Automata (DFAs)

Computational Models Lecture 2 1

Languages. Non deterministic finite automata with ε transitions. First there was the DFA. Finite Automata. Non-Deterministic Finite Automata (NFA)

Recap DFA,NFA, DTM. Slides by Prof. Debasis Mitra, FIT.

Computational Models - Lecture 3

CSE 311: Foundations of Computing. Lecture 23: Finite State Machine Minimization & NFAs

Computational Models - Lecture 4

Computer Sciences Department

Computational Models Lecture 2 1

Regular Languages. Problem Characterize those Languages recognized by Finite Automata.

Critical CS Questions

CPS 220 Theory of Computation REGULAR LANGUAGES

CS Lecture 29 P, NP, and NP-Completeness. k ) for all k. Fall The class P. The class NP

CHAPTER 1 Regular Languages. Contents

Finite Automata. Mahesh Viswanathan

Automata: a short introduction

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

Theory of Computation

Closure under the Regular Operations

CSE 105 THEORY OF COMPUTATION

Automata Theory, Computability and Complexity

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

CSE 105 THEORY OF COMPUTATION

Deterministic Finite Automaton (DFA)

Deterministic Finite Automata (DFAs)

CSE 105 THEORY OF COMPUTATION

V Honors Theory of Computation

False. They are the same language.

September 11, Second Part of Regular Expressions Equivalence with Finite Aut

More Properties of Regular Languages

Theory of computation: initial remarks (Chapter 11)

Nondeterminism and Epsilon Transitions

Transcription:

Automata Theory Lecture on Discussion Course of CS2

This Lecture is about Mathematical Models of Computation.

Why Should I Care? - Ways of thinking. - Theory can drive practice. - Don t be an Instrumentalist.

Mathematical Models of Computation (predated computers as we know them) Automata and Languages: (94 s) finite automata, regular languages, pushdown automata, context-free languages, pumping lemmas. 2 Computability Theory: (93-4 s) Turing Machines, decidability, reducibility, the arithmetic hierarchy, the recursion theorem, the Post correspondence problem. 3 Complexity Theory and Applications: (96-7 s) time complexity, classes P and NP, NP-completeness, space complexity PSPACE, PSPACE-completeness, the polynomial hierarchy, randomized complexity, classes RP and BPP.

Let me emphasize Proofs a bit more. A good proof:. Correct 2. Easy to understand

Suppose with. True or False: There are always two numbers in one divides the other. such that

LEVEL HINT : THE PIGEONHOLE PRINCIPLE If you put 6 pigeons in 5 holes then at least one hole will have more than one pigeon

LEVEL HINT : THE PIGEONHOLE PRINCIPLE If you put 6 pigeons in 5 holes then at least one hole will have more than one pigeon

LEVEL HINT : THE PIGEONHOLE PRINCIPLE If you put 6 pigeons in 5 holes then at least one hole will have more than one pigeon HINT 2: Every integer can be written as, where is an odd number

LEVEL 2 Proof Idea: Given: with. Show: There is an integer and and. such that

LEVEL 3 Proof: Suppose with. Write every number in A as a = 2 k m, where m is an odd number. How many odd numbers in {,,2n-}? n Since A = n+, there must be two numbers in A with the same odd part. Say a and a 2 have the same odd part m. Then a = 2 i m and a 2 = 2 j m, so one must divide the other.

We expect your proofs to have three levels: The first level should be a one-word or one-phrase HINT of the proof (e.g. Proof by contradiction, Proof by induction, Follows from the pigeonhole principle ) The second level should be a short oneparagraph description or KEY IDEA The third level should be the FULL PROOF

Double standards :-) HINT + KEY IDEA (+ FULL PROOF)

Deterministic Finite Automata (DFA)

NOTATION An alphabet Σ is a finite set (e.g., Σ = {,}) A string over Σ is a finite-length sequence of elements of Σ Σ* denotes the set of finite length sequences of elements of Σ For x a string, x is the length of x The unique string of length will be denoted by ε and will be called the empty or null string A language over Σ is a set of strings over Σ, ie, a subset of Σ*

Finite Automata finite # of internal states Input (String) -> -> Output (Yes/No) Divice

A Deterministic Finite Automata, Read string left to right The machine accepts a string if the process ends in a double circle.

A Deterministic Finite Automata states q, q q 3 q 2 states The machine accepts a string if the process ends in a double circle.

A Deterministic Finite Automata states final states (F) q, q q 3 start state (q ) q 2 states The machine accepts a string if the process ends in a double circle.

A Deterministic Finite Automata is represented by a 5-tuple M = (Q, Σ, δ, q, F) : Q is the set of states (finite) Σ is the alphabet (finite) δ : Q Σ Q is the transition function q Q is the start state F Q is the set of accept states Let w,..., w n Σ and w = w... w n Σ* Then M accepts w if there are r, r,..., r n Q, s.t. r =q δ(r i, w i+ ) = r i+, for i =,..., n-, and r n F

A Deterministic Finite Automata is represented by a 5-tuple M = (Q, Σ, δ, q, F) : Q is the set of states (finite) Σ is the alphabet (finite) δ : Q Σ Q is the transition function q Q is the start state F Q is the set of accept states L(M) = the language of machine M = set of all strings machine M accepts

Warming-up q, L(M) ={,}*

Warming-up L(M) ={,}*

Warming-up L(M) = { w w has an even number of s}

Warming-up q q L(M) = { w w has an even number of s}

Warming-up Build an automaton that accepts all and only those strings that contain

Warming-up Build an automaton that accepts all and only those strings that contain, q q q q

Regular Language A language L is regular if it is recognized by a deterministic finite automaton (DFA), i.e. if there is a DFA M such that L = L (M). L = { w w contains } is regular L = { w w has an even number of s} is regular

UNION THEOREM Given two languages, L and L 2, define the union of L and L 2 as L L 2 = { w w L or w L 2 } Theorem: The union of two regular languages is also a regular language.

Theorem: The union of two regular languages is also a regular language. Proof: Let M = (Q, Σ, δ, q, F ) be finite automaton for L and 2 M 2 = (Q 2, Σ, δ 2, q, F 2 ) be finite automaton for L 2 We want to construct a finite automaton M = (Q, Σ, δ, q, F) that recognizes L = L L 2

Theorem: The union of two regular languages is also a regular language. Idea: Run both M and M 2 at the same time! Q = pairs of states, one from M and one from M 2 = { (q, q 2 ) q Q and q 2 Q 2 } = Q Q 2 2 q = (q, q ) F = { (q, q 2 ) q F or q 2 F 2 } δ( (q,q 2 ), σ) = (δ (q, σ), δ 2 (q 2, σ))

Theorem: The union of two regular languages is also a regular language. M = q q M 2 = p p

Theorem: The union of two regular languages is also a regular language. q,p q,p M = q,p q,p

INTERSECTION THEOREM Given two languages, L and L 2, define the intersection of L and L 2 as L L 2 = { w w L and w L 2 } Theorem: The intersection of two regular languages is also a regular language.

COMPLEMENT THEOREM Given language L, define the complement of L as L= { w Σ* w L } Theorem: The complement of a regular languages is also a regular language.

THE REGULAR OPERATIONS Union: L L 2 = { w w L or w L 2 } Intersection: L L 2 = { w w L and w L 2 } Negation: L = { w Σ* w L } Reverse: L R = { w w k w k w L } Concatenation: L L 2 = { vw v L and w L 2 } Star: L* = { w w k k and each w i L }

REVERSE THEOREM Given language L, define the reverse of L R as L R = { w w k w k w L } Theorem: The reverse of a regular languages is also a regular language.

Theorem: The reverse of a regular languages is also a regular language. Proof: Let M = (Q, Σ, δ, q, F) that recognizes L. If M accepts w then w describes a directed path in M from start to an accept state We want to construct a finite automaton M R as M with the arrows reversed.

M R IS NOT ALWAYS A DFA! - It may have many start states - Some states may have too many outgoing edges, or none

M R IS NOT ALWAYS A DFA!,

M R IS NOT ALWAYS A DFA!,

Non-Determinism, We will say that the machine accepts if there is some way to make it reach an accept state

Example,,,ε At each state, possibly zero, one or many out arrows for each σ Σ or with label ε

Example, ε Possibly many start states

Example L(M)={,}

A Non-Deterministic Finite Automata (NFA) is represented by a 5-tuple N = (Q, Σ, δ, Q, F) : Q is the set of states (finite) Σ is the alphabet (finite) δ : Q Σ {ε} 2 Q is the transition function Q Q is the set of start state F Q is the set of accept states Let w,..., w n Σ {ε} and w = w... w n Σ ε * Then N accepts w if there are r, r,..., r n Q, s.t. r =Q r i+ δ(r i, w i+ ), for i =,..., n-, and r n F

A Non-Deterministic Finite Automata (NFA) is represented by a 5-tuple N = (Q, Σ, δ, Q, F) : Q is the set of states (finite) Σ is the alphabet (finite) δ : Q Σ {ε} 2 Q is the transition function Q Q is the set of start state F Q is the set of accept states L(N) = the language of machine N = set of all strings machine N accepts

Deterministic Computation Non-Deterministic Computation reject accept or reject accept

NFAs ARE SIMPLER THAN DFAs An NFA that recognizes the language {}: A DFA that recognizes the language {}:,,

FROM NFA TO DFA Theorem: Every NFA has an equivalent DFA N is equivalent to M if L(N) = L (M) Corollary: A language is regular iff it is recognized by an NFA Corollary: L is regular iff L R is regular

FROM NFA TO DFA Input: N = (Q, Σ, δ, Q, F) Output: M = (Q, Σ, δ, q, F ) reject To learn if NFA accepts, we could do the computation in parallel, maintaining the set of states where all threads are. Idea: Q = 2 Q accept

FROM NFA TO DFA Input: N = (Q, Σ, δ, Q, F) Output: M = (Q, Σ, δ, q, F ) Q = 2 Q δ : Q Σ Q ε ε ε δ (R,σ) = ε( δ(r,σ) ), r R q = ε(q ) F = { R Q f R for some f F } For R Q, the ε-closure of R, ε(r) = {q that can be reached from some r R by traveling along zero or more ε arrows},

FROM NFA TO DFA () + () +

Regular Languages Closure Under Concatenation DFA -> DFA2 NFA Given DFAs M and M 2, construct NFA by connecting all accept states in M to start states in M 2.

Regular Languages Closure Under Star Let L be a regular language and M be a DFA for L We construct an NFA N that recognizes L* ε, ε ε

THE REGULAR OPERATIONS Union: L L 2 = { w w L or w L 2 } Intersection: L L 2 = { w w L and w L 2 } Negation: L = { w Σ* w L } Reverse: L R = { w w k w k w L } Concatenation: L L 2 = { vw v L and w L 2 } Star: L* = { w w k k and each w i L }

Are all languages regular?

Consider the language L = { n n n > } No finite automaton accepts this language. Can you prove this?

Idea? n n is not regular. No machine has enough states to keep track of the number of s it might encounter

That is a fairly weak argument Consider the following example

L = { w w has equal number of occurrences of and } No machine has enough states to keep track of the number of s it might encounter.

THE PUMPING LEMMA Let L be a regular language with L = Then there exists a positive integer P such that Any x L, x P can be written as x = uvw where:. v > 2. uv P 3. uv i w L for any i

THE PUMPING LEMMA Assume x L is such that x P Let P be the number of states in M We show x = uvw where:. v > 2. uv P 3. uv i w L for any i PIGEONHOLE: There must be j > i such that q i = q j u v w q q i q j q x

THE PUMPING LEMMA Assume x L is such that x P Let P be the number of states in M We show x = uvw where:. v > 2. uv P 3. uv i w L for any i PIGEONHOLE: There must be j > i such that q i = q j u v w q q i q j q x

THE PUMPING LEMMA L = { n n n > } HINT: Assume L is regular, and try pumping. u v w q q i q j q x

THE PUMPING LEMMA L = { n n n > } HINT: Assume L is regular, and try pumping. u v w q q i q j q x

References: CMU FLAC: 5-453 Formal Languages, Automata and Computation, http://www.cs.cmu.edu/~lblum/flac/schedule.html, Spring 24 Stanford CS54: Introduction to Automata and Complexity Theory, http://infolab.stanford.edu/~ullman/ialc/spr/spr.html, Spring 29 John E. Hopcroft, etc., Introduction to Automata Theory, Languages, and Computation(Third Edition). Pearson; 26