DFA (Deterministic Finite Automata) q a

Similar documents
CSE303 - Introduction to the Theory of Computing Sample Solutions for Exercises on Finite Automata

FSA. CmSc 365 Theory of Computation. Finite State Automata and Regular Expressions (Chapter 2, Section 2.3) ALPHABET operations: U, concatenation, *

Last time: introduced our first computational model the DFA.

Notes on Finite Automata Department of Computer Science Professor Goldberg Textbooks: Introduction to the Theory of Computation by Michael Sipser

Winter 2016 COMP-250: Introduction to Computer Science. Lecture 23, April 5, 2016

Finite Automata. d: Q S Q. Finite automaton is M=(Q, S, d, q 0, F) Ex: an FA that accepts all odd-length strings of zeros: q 0 q 1. q i. q k.

a b c cat CAT A B C Aa Bb Cc cat cat Lesson 1 (Part 1) Verbal lesson: Capital Letters Make The Same Sound Lesson 1 (Part 1) continued...

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

Theory of Computation Regular Languages

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

AUTOMATA AND LANGUAGES. Definition 1.5: Finite Automaton

1.3 Regular Expressions

Lecture 08: Feb. 08, 2019

Section 3: Antiderivatives of Formulas

Minimum Spanning Trees

The Course covers: Lexical Analysis Syntax Analysis Semantic Analysis Runtime environments Code Generation Code Optimization. CS 540 Spring 2013 GMU 2

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

Multi-Section Coupled Line Couplers

COMP108 Algorithmic Foundations

Integration Continued. Integration by Parts Solving Definite Integrals: Area Under a Curve Improper Integrals

1.4 Nonregular Languages

1 Nondeterministic Finite Automata

1 Introduction to Modulo 7 Arithmetic

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

Math 61 : Discrete Structures Final Exam Instructor: Ciprian Manolescu. You have 180 minutes.

More Foundations. Undirected Graphs. Degree. A Theorem. Graphs, Products, & Relations

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

First Midterm Examination

1 Finite Automata and Regular Expressions

Designing finite automata II

CHAPTER 1 Regular Languages. Contents

12/3/12. Outline. Part 10. Graphs. Circuits. Euler paths/circuits. Euler s bridge problem (Bridges of Konigsberg Problem)

5/9/13. Part 10. Graphs. Outline. Circuits. Introduction Terminology Implementing Graphs

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

Walk Like a Mathematician Learning Task:

CSE 373: More on graphs; DFS and BFS. Michael Lee Wednesday, Feb 14, 2018

Lecture 4: Lexical and Syntax Analysis

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

Harvard University Computer Science 121 Midterm October 23, 2012

Paths. Connectivity. Euler and Hamilton Paths. Planar graphs.

EEO 401 Digital Signal Processing Prof. Mark Fowler

CS 6353 Compiler Construction, Homework #1. 1. Write regular expressions for the following informally described languages:

Module graph.py. 1 Introduction. 2 Graph basics. 3 Module graph.py. 3.1 Objects. CS 231 Naomi Nishimura

# 1 ' 10 ' 100. Decimal point = 4 hundred. = 6 tens (or sixty) = 5 ones (or five) = 2 tenths. = 7 hundredths.

TOPIC 5: INTEGRATION

Some Theory of Computation Exercises Week 1

Non-deterministic Finite Automata

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

CMSC 330: Organization of Programming Languages

INTEGRALS. Chapter 7. d dx. 7.1 Overview Let d dx F (x) = f (x). Then, we write f ( x)

Formal languages, automata, and theory of computation

Minimal DFA. minimal DFA for L starting from any other

CISC 4090 Theory of Computation

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

Garnir Polynomial and their Properties

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

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

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

b. How many ternary words of length 23 with eight 0 s, nine 1 s and six 2 s?

CS375: Logic and Theory of Computing

Lecture 11 Waves in Periodic Potentials Today: Questions you should be able to address after today s lecture:

Homework 3 Solutions

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

Let's start with an example:

Cycles and Simple Cycles. Paths and Simple Paths. Trees. Problem: There is No Completely Standard Terminology!

Non Deterministic Automata. Formal Languages and Automata - Yonsei CS 1

Propositional Logic. Combinatorial Problem Solving (CPS) Albert Oliveras Enric Rodríguez-Carbonell. May 17, 2018

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

S i m p l i f y i n g A l g e b r a SIMPLIFYING ALGEBRA.

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.

ECE COMBINATIONAL BUILDING BLOCKS - INVEST 13 DECODERS AND ENCODERS

First Midterm Examination

Today s Topics Automata and Languages

Automata and Languages

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

Ch 1.2: Solutions of Some Differential Equations

CSC Design and Analysis of Algorithms. Example: Change-Making Problem

Finite-State Automata: Recap

Graphs. Graphs. Graphs: Basic Terminology. Directed Graphs. Dr Papalaskari 1

, each of which is a tree, and whose roots r 1. , respectively, are children of r. Data Structures & File Management

Basic Polyhedral theory

CS 330 Formal Methods and Models

Worked out examples Finite Automata

Graph Isomorphism. Graphs - II. Cayley s Formula. Planar Graphs. Outline. Is K 5 planar? The number of labeled trees on n nodes is n n-2

Lecture 6 Regular Grammars

Chapter 2 Finite Automata

Finite Automata-cont d

Deterministic Finite Automata

Nondeterminism and Nodeterministic Automata

1 From NFA to regular expression

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

Graphs. CSC 1300 Discrete Structures Villanova University. Villanova CSC Dr Papalaskari

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

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY. FLAC (15-453) - Spring L. Blum

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

CS 361 Meeting 12 10/3/18

Coalgebra, Lecture 15: Equations for Deterministic Automata

Linear Algebra Existence of the determinant. Expansion according to a row.

Recall that by Theorems 10.3 and 10.4 together provide us the estimate o(n2 ), S(q) q 9, q=1

Transcription:

Big pictur All lngugs Dcidl Turing mchins NP P Contxt-fr Contxt-fr grmmrs, push-down utomt Rgulr Automt, non-dtrministic utomt, rgulr xprssions

DFA (Dtrministic Finit Automt) 0 q 0 0 0 0 q

DFA (Dtrministic Finit Automt) 0 q 0 0 0 0 q Stts, this DFA hs 4 stts Trnsitions llld with lmnts of th lpht S = {0,}

DFA (Dtrministic Finit Automt) 0 q 0 0 Computtion on input w: Bgin in strt stt 0 q 0 0 q Rd input string in on-wy fshion Follow th rrows mtching input symols Whn input nds: ACCEPT if in ccpt stt REJECT if not

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) lwys strt in strt stt q 0 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00 ACCEPT cus nd in ccpt stt

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) lwys strt in strt stt q 0 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 00 REJECT cus dos not nd in ccpt stt

DFA (Dtrministic Finit Automt) 0 q 0 0 0 q 0 Exmpl: Input string w = 0 ACCEPT w = 00 REJECT w = 00 ACCEPT w = 000 REJECT

Exmpl: 00 is n lmnt of L(M), 00 L(M) M := DFA (Dtrministic Finit Automt) q 0 0 M rcognizs lngug L(M) = { w : w strts with 0 nd nds with } L(M) is th lngug of strings cusing M to ccpt 0 0 0 q

Exmpl S = {0,} M := q 0 q 0 0 00 cuss M to ccpt, so 00 is in L(M) 00 L(M) 0 dos not cus M to ccpt, so 0 not in L(M), 00 L(M) 0000 L(M) 000 L(M) 0 L(M)

Exmpl M := q 0 q S = {0,} 0 0 L(M) = {w : w hs n vn numr of } Not: If thr is no, thn thr r zro, zro is n vn numr, so M should ccpt. Indd 0000000 L(M)

Exmpl S = {0,} M := 0 L(M) =?

Exmpl S = {0,} M := 0 L(M) = vry possil string ovr {0,} = {0,}*

Exmpl S = {0,} M := 0 0 q 0 0 L(M) =?

Exmpl S = {0,} M := 0 0 q 0 0 L(M) = ll strings ovr {0,} xcpt mpty string = {0,}* - { }

Exmpl S = {0,} M := 0 q 0 L(M) =? 0 0 0 0

Exmpl S = {0,} M := 0 q 0 0 0 0 0 L(M) = { w : w strts nd nds with sm symol } Mmory is ncodd in wht?

Exmpl S = {0,} M := 0 q 0 0 0 0 0 Rmmr 0 Rmmr L(M) = { w : w strts nd nds with sm symol } Mmory is ncodd in stts. DFA hv finit stts, so finit mmory

M := Convntion: q 0 0 W lrdy sw tht 0 0 L(M) = { w : w strts with 0 nd nds with } 0 q Th rrow q 0 lds to sink stt. If followd, M cn nvr ccpt

Convntion: M := q 0 0 0 0 q Don't nd to writ such rrows: If, from som stt, rd symol with no corrsponding rrow, imgin M gos into sink stt tht is not shown, nd REJECT. This mks picturs mor compct.

Anothr convntion: List multipl trnsition on sm rrow: 0,,2 Mns 2 0 This mks picturs mor compct.

Exmpl = {0,} M = 0, 0, L(M) =?

Exmpl = {0,} M = 0, 0, L(M) = 2 = {00,0,0,}

Exmpl from progrmming lngugs: Rcogniz strings rprsnting numrs: S = {0,,2,3,4,5,6,7,8,9, +, -,. } + - 0,...,9 0,...,9. 0,...,9 0,...,9 Not: 0,...,9 mns 0,,2,3,4,5,6,7,8,9: 0 trnsitions

Exmpl from progrmming lngugs: Rcogniz strings rprsnting numrs: S = {0,,2,3,4,5,6,7,8,9, +, -,. } + - 0,...,9 0,...,9. 0,...,9 Possily put sign (+, -) 0,...,9 Follow with ritrrily mny digits, ut t lst on Possily put dciml point Follow with ritrrily mny digits, possily non

Exmpl from progrmming lngugs: Rcogniz strings rprsnting numrs: S = {0,,2,3,4,5,6,7,8,9, +, -,. } + - 0,...,9 0,...,9. 0,...,9 Input w = 7 ACCEPT Input w = + REJECT Input w = -3.25 ACCEPT Input w = +2.35-. REJECT 0,...,9

Exmpl S = {0,} Wht out { w : w hs sm numr of 0 nd } Cn you dsign DFA tht rcognizs tht? It sms you nd infinit mmory W will prov ltr tht thr is no DFA tht rcognizs tht lngug!

Nxt: forml dfinition of DFA Usful to prov vrious proprtis of DFA Espcilly importnt to prov tht things CANNOT rcognizd y DFA. Usful to prctic mthmticl nottion

Stt digrm of DFA: On or mor stts Exctly on strt stt Som numr of ccpt stts Llld trnsitions xiting ch stt, for vry symol in S

Dfinition: A finit utomton (DFA) is 5-tupl (Q, S, d, q 0, F) whr Q is finit st of stts S is th input lpht d : Q X S Q is th trnsition function q 0 in Q is th strt stt F Q is th st of ccpt stts Q X S is th st of ordrd pirs (,) : Q, Exmpl {q,r,s}x{0,}={(q,0),(q,),(r,0),(r,),(s,0),(s,)}

q 0 q 0 0 Exmpl: ov DFA is 5-tupl (Q, S, d, q0, F) whr Q = { q 0, q } S = {0,} d(q0,0) =?

q 0 q 0 0 Exmpl: ov DFA is 5-tupl (Q, S, d, q0, F) whr Q = { q 0, q } S = {0,} d(q0,0) = q 0 d(q 0,) =?

q 0 q 0 0 Exmpl: ov DFA is 5-tupl (Q, S, d, q0, F) whr Q = { q 0, q } S = {0,} d(q0,0) = q 0 d(q 0,) = q d(q,0) = q d(q,) = q 0 q 0 in Q is th strt stt F =?

q 0 q 0 0 Exmpl: ov DFA is 5-tupl (Q, S, d, q0, F) whr Q = { q 0, q } S = {0,} d(q0,0) = q 0 d(q 0,) = q d(q,0) = q d(q,) = q 0 q 0 in Q is th strt stt F = { q0 } Q is th st of ccpt stts

Dfinition: A DFA (Q, S, d, q0, F) ccpts string w if w = w w 2 w k whr, i k, w i is in S (th k symols of w) Th squnc of k+ stts r 0, r,.., r k such tht: () r 0 = q 0, nd (2) r i+ = d(r i,w i+ ) 0 i < k hs r k in F (r i = stt DFA is in ftr rding i-th symol in w)

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 =

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 = W must show tht Th squnc of 3+=4 stts r 0, r, r 2, r 3 such tht: () r 0 = q 0 (2) r i+ = d(r i,w i+ ) 0 i < 3 hs r 3 in F

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 = r 0 = q 0 r :=?

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 = r 0 = q 0 r = d(r 0,w )=d(q 0,0 ) = q 0 r 2 :=?

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 = r 0 = q 0 r = d(r 0,w )=d(q 0,0 ) = q 0 r 2 = d(r,w 2 )=d(q 0, ) = q r 3 :=?

Exmpl q 0 q 0 0 Aov DFA (Q, S, d, q0, F) ccpts w = 0 w = 0 = w w 2 w 3 w = 0 w 2 = w 3 = r 0 = q 0 r = d(r 0,w )=d(q 0,0 ) = q 0 r 2 = d(r,w 2 )=d(q 0, ) = q r 3 = d(r 2,w 3 )=d(q, ) = q 0 r 3 = q 0 in F OK DONE!

Dfinition: For DFA M, w dnot y L(M) th st of strings ccptd y M: L(M) := { w : M ccpts w} W sy M ccpts or rcognizs th lngug L(M) Dfinition: A lngug L is rgulr if $ DFA M : L(M) = L

In th nxt lcturs w wnt to: Undrstnd powr of rgulr lngugs Dvlop ltrnt, compct nottion to spcify rgulr lngugs Exmpl: Unix commnd grp '\<c.*h\>' fil slcts ll words strting with c nd nding with h in fil

Undrstnd powr of rgulr lngugs: Suppos A, B r rgulr lngugs, wht out not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } Ar ths lngugs rgulr?

Undrstnd powr of rgulr lngugs: Suppos A, B r rgulr lngugs, wht out not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } Trminology: Ar rgulr lngugs closd undr not, U, o, *?

Thorm: If A is rgulr lngug, thn so is (not A)

Thorm: If A is rgulr lngug, thn so is (not A) Proof id:?????????? th st of ccpt stts

Thorm: If A is rgulr lngug, thn so is (not A) Proof id: Complmnt th st of ccpt stts Exmpl

Thorm: If A is rgulr lngug, thn so is (not A) Proof id: Complmnt th st of ccpt stts Exmpl: M := L(M) = q 0 q 0 0 { w : w hs vn numr of }

Thorm: If A is rgulr lngug, thn so is (not A) Proof id: Complmnt th st of ccpt stts Exmpl: M := q 0 q 0 0 M' := q 0 q 0 0 L(M) = { w : w hs vn numr of } L(M') = not L(M) = { w : w hs odd numr of }

Thorm: If A is rgulr lngug, thn so is (not A) Proof: Givn DFA M = (Q, S, d, q 0, F) such tht L(M) = A. Dfin DFA M' =?????????????????????????? This dfinition is th crtiv stp of this proof, th rst is (prhps complictd ut) mchnicl unwrpping dfinitions

Thorm: If A is rgulr lngug, thn so is (not A) Proof: Givn DFA M = (Q, S, d, q 0, F) such tht L(M) = A. Dfin DFA M' = (Q, S, d, q 0, F'), whr F' := not F. W nd to show L(M') = not L(M), tht is: for ny w,??????????????????????????

Thorm: If A is rgulr lngug, thn so is (not A) Proof: Givn DFA M = (Q, S, d, q 0, F) such tht L(M) = A. Dfin DFA M' = (Q, S, d, q 0, F'), whr F' := not F. W nd to show L(M') = not L(M), tht is: for ny w, M' ccpts w M dos not ccpt w. So lt w ny string of lngth k, nd considr th k+ stts r 0, r,.., r k from th dfinition of ccpt: () r 0 = q 0, nd (2) r i+ = d(r i,w i+ ) 0 i < k. How do w conclud?

Thorm: If A is rgulr lngug, thn so is (not A) Proof: Givn DFA M = (Q, S, d, q 0, F) such tht L(M) = A. Dfin DFA M' = (Q, S, d, q 0, F'), whr F' := not F. W nd to show L(M') = not L(M), tht is: for ny w, M' ccpts w M dos not ccpt w So lt w ny string of lngth k, nd considr th k+ stts r 0, r,.., r k from th dfinition of ccpt: () r 0 = q 0, nd (2) r i+ = d(r i,w i+ ) 0 i < k. Not tht r k in F' r k not in F, sinc F' = not F.

Wht is proof? A proof is n xplntion, writtn in English, of why somthing is tru. Evry sntnc must logiclly connctd to th prvious ons, oftn y so, hnc, sinc, tc. Your udinc is humn ing, NOT mchin.

Thorm: If A is rgulr lngug, thn so is (not A) Proof: DFA M = (Q, S, d, q 0, F) such tht L(M) = A. DFA M' = (Q, S, d, q 0, F'), whr F' := not F. L(M') = not L(M) M' ccpts w M dos not ccpt w k+ stts r 0, r,.., r k () r 0 = q 0, nd (2) r i+ = d(r i,w i+ ) 0 i < k. r k in F' r k not in F, F' = not F.

To know proof mns to know ll th pyrmid Wht is proof? Complmnt th st of ccpt stts Givn DFA M = (Q, S, d, q 0, F) such tht L(M) = A. Dfin DFA M' = (Q, S, d, q 0, F'), whr F' := not F. W nd to show L(M') = not L(M), tht is: for ny w, M' ccpts w M dos not ccpt w Considr th k+ stts r 0, r,.., r k such tht: () r 0 = q 0, nd (2) r i+ = d(r i,w i+ ) 0 i < k. Not tht r k in F' r k not in F, sinc F' = not F.

Exmpl = {0,} M = 0, 0, L(M) = 2 = {00,0,0,} Wht is DFA M' : L(M') = not 2 = ll strings xcpt thos of lngth 2?

Exmpl = {0,} M' = 0, 0, 0, 0, L(M') = not 2 = {0,}* - {00,0,0,} Do not forgt th convntion out th sink stt!

Suppos A, B r rgulr lngugs, wht out not A := { w : w is not in A } REGULAR A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i }

Thorm: If A, B r rgulr, thn so is A U B Proof id: Tk Crtsin product of stts In pir (q,q'), q trcks DFA for A, q' trcks DFA for B. Nxt w s n xmpl. In it w rvit with

Exmpl 0 M M A := B := c d 0 0 L(M L(M A ) = A =? B ) = B =?

Exmpl 0 M M A := B := c d 0 0 L(M A ) = A = L(M B ) = B = { w : w hs vn numr of } { w : w hs odd numr of 0} M AUB := How mny stts?

Exmpl 0 M M A := B := c d 0 0 L(M A ) = A = L(M B ) = B = { w : w hs vn numr of } { w : w hs odd numr of 0} M AUB :=,c,c L(M AUB ) = AUB = { w : w hs vn numr of, or odd numr of 0} 0,d,d 0

Thorm: If A, B r rgulr, thn so is A U B Proof: Givn DFA M A = (Q A,S, δ A,q A, F A ) such tht L(M) = A, DFA M B = (Q B,S, δ B,q B, F B ) such tht L(M) = B. Dfin DFA M = (Q, S, d, q 0, F), whr Q :=?

Thorm: If A, B r rgulr, thn so is A U B Proof: Givn DFA M A = (Q A,S, δ A,q A, F A ) such tht L(M) = A, DFA M B = (Q B,S, δ B,q B, F B ) such tht L(M) = B. Dfin DFA M = (Q, S, d, q 0, F), whr Q := Q A X Q B q 0 :=?

Thorm: If A, B r rgulr, thn so is A U B Proof: Givn DFA M A = (Q A,S, δ A,q A, F A ) such tht L(M) = A, DFA M B = (Q B,S, δ B,q B, F B ) such tht L(M) = B. Dfin DFA M = (Q, S, d, q 0, F), whr Q := Q A X Q B q 0 := (q A, q B ) F :=?

Thorm: If A, B r rgulr, thn so is A U B Proof: Givn DFA M A = (Q A,S, δ A,q A, F A ) such tht L(M) = A, DFA M B = (Q B,S, δ B,q B, F B ) such tht L(M) = B. Dfin DFA M = (Q, S, d, q 0, F), whr Q := Q A X Q B q 0 := (q A, q B ) F := {(q,q') Q : q F A or q' F B } δ( (q,q'), v) := (?,? )

Thorm: If A, B r rgulr, thn so is A U B Proof: Givn DFA M A = (Q A,S, δ A,q A, F A ) such tht L(M) = A, DFA M B = (Q B,S, δ B,q B, F B ) such tht L(M) = B. Dfin DFA M = (Q, S, d, q 0, F), whr Q := Q A X Q B q 0 := (q A, q B ) F := {(q,q') Q : q F A or q' F B } δ( (q,q'), v) := (δ A (q,v), δ B (q',v) ) W nd to show L(M) = A U B tht is, for ny w: M ccpts w M A ccpts w or M B ccpts w

Proof M ccpts w M A ccpts w or M B ccpts w Suppos tht M ccpts w of lngth k. From th dfinitions of ccpt nd M, th squnc (s 0, t 0 ) = q 0 = (q A, q B ), (s i+,t i+ )=d((s i,t i ),w i+ )=( δ A (s i,w i+ ), δ B (t i,w i+ ) 0 i< k hs (s k,t k )?

Proof M ccpts w M A ccpts w or M B ccpts w Suppos tht M ccpts w of lngth k. From th dfinitions of ccpt nd M, th squnc (s 0, t 0 ) = q 0 = (q A, q B ), (s i+,t i+ )=d((s i,t i ),w i+ )=( δ A (s i,w i+ ), δ B (t i,w i+ ) 0 i< k hs (s k,t k ) F. By our dfinition of F, wht cn w sy out (s k,t k )?

Proof M ccpts w M A ccpts w or M B ccpts w Suppos tht M ccpts w of lngth k. From th dfinitions of ccpt nd M, th squnc (s 0, t 0 ) = q 0 = (q A, q B ), (s i+,t i+ )=d((s i,t i ),w i+ )=( δ A (s i,w i+ ), δ B (t i,w i+ ) 0 i< k hs (s k,t k ) F. By our dfinition of F, s k F A or t k F B. Without loss of gnrlity, ssum s k F A. Thn M A ccpts w cus th squnc s 0 = q A, s i+ = δ A (s i, w i+ ) 0 i < k, hs s k F A.

Proof M ccpts w M A ccpts w or M B ccpts w W/out loss of gnrlity, ssum M A ccpts w, w =k. From th dfinition of M A ccpts w, th squnc r 0 := q A, r i+ := δ A (r i,w i+ ) 0 i < k, hs r k in?

Proof M ccpts w M A ccpts w or M B ccpts w W/out loss of gnrlity, ssum M A ccpts w, w =k. From th dfinition of M A ccpts w, th squnc r 0 := q A, r i+ := δ A (r i,w i+ ) 0 i < k, hs r k in F A. Dfin th squnc of k+ stts t 0 := q B, t i+ := δ B (t i,w i+ ) 0 i < k. M ccpts w cus th squnc?????????? (rcll stts in M r pirs)

Proof M ccpts w M A ccpts w or M B ccpts w W/out loss of gnrlity, ssum M A ccpts w, w =k. From th dfinition of M A ccpts w, th squnc r 0 := q A, r i+ := δ A (r i,w i+ ) 0 i < k, hs r k in F A. Dfin th squnc of k+ stts t 0 := q B, t i+ := δ B (t i,w i+ ) 0 i < k. M ccpts w cus th squnc (r 0, t 0 ) = q = (q A, q B ), (r i+,t i+ ) =d((r i,t i ),w i+ )=(δ A (r i,w i+ ),δ B (t i,w i+ ) 0 i< k hs (r,t ) in F, y our dfinition of F.

Suppos A, B r rgulr lngugs, wht out not A := { w : w is not in A } REGULAR A U B := { w : w in A or w in B } REGULAR A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } Othr two r mor complictd! Pln: w introduc NFA prov tht NFA r quivlnt to DFA rprov A U B, prov A o B, A* rgulr, using NFA

Big pictur All lngugs Dcidl Turing mchins NP P Contxt-fr Contxt-fr grmmrs, push-down utomt Rgulr Automt, non-dtrministic utomt, rgulr xprssions

Non dtrministic finit utomt (NFA) DFA: givn stt nd input symol, uniqu choic for nxt stt, dtrministic: Nxt w llow multipl choics, non-dtrministic W lso llow -trnsitions: cn follow without rding nything

Exmpl of NFA q 0 q q, 2 Intuition of how it computs: Accpt string w if thr is wy to follow trnsitions tht nds in ccpt stt Trnsitions llld with symol in S = {,} must mtchd with input trnsitions cn followd without mtching

Exmpl of NFA q 0 q q, 2 Exmpl: Accpt (first follow -trnsition ) Accpt

ANOTHER Exmpl of NFA q 0 q q 3, q 2 Exmpl: Accpt (two ccpting pths, on Rjct uss th -trnsition) (two possil pths, ut nithr hs finl stt = q )

Dfinition: A non-dtrministic finit utomton (NFA) is 5-tupl (Q, S, d, q 0, F) whr Q is finit st of stts S is th input lpht d : Q X (S U {} ) Powrst(Q) q 0 in Q is th strt stt F Q is th st of ccpt stts Rcll: Powrst(Q) = st of ll susts of Q Exmpl: Powrst({,2}) =?

Dfinition: A non-dtrministic finit utomton (NFA) is 5-tupl (Q, S, d, q 0, F) whr Q is finit st of stts S is th input lpht d : Q X (S U {} ) Powrst(Q) q 0 in Q is th strt stt F Q is th st of ccpt stts Rcll: Powrst(Q) = st of ll susts of Q Exmpl: Powrst({,2}) = {, {}, {2}, {,2} }

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) = d(q,0) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) = d(q,0) = d(q,) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) = d(q,0) = d(q,) = d(q,) =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) = d(q,0) = d(q,) = d(q,) = {q 0 } q 0 in Q is th strt stt F =?

0, q 0 q Exmpl: ov NFA is 5-tupl (Q, S, d, q0, F) Q = { q 0, q } S = {0,} d(q0,0) = {q 0 } d(q 0,) = {q 0, q } d(q 0,) = d(q,0) = d(q,) = d(q,) = {q 0 } q 0 in Q is th strt stt F = { q } Q is th st of ccpt stts

Dfinition: A NFA (Q, S, d, q0, F) ccpts string w if $ intgr k, k strings w = w w 2 w k (th symols of w, or ) w, w 2,, w k such tht whr i k, w i S U {} $ squnc of k+ stts r0, r,.., r k in Q such tht: r 0 = q 0 r i+ d(r i,w i+ ) 0 i < k r k is in F Diffrncs with DFA r in grn

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 =?

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r =?

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r = q, r 2 =? Trnsitions: r d(r 0,) = {q }

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r = q, r 2 = q 2, r 3 =? Trnsitions: r d(r 0,) = {q } r 2 d(r,) = {q,q 2 }

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r = q, r 2 = q 2, r 3 = q 0, r 4 =? Trnsitions: r d(r 0,) = {q } r 2 d(r,) = {q,q 2 } r 3 d(r 2,) = {q 0 }

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r = q, r 2 = q 2, r 3 = q 0, r 4 = q 2, r 5 =? Trnsitions: r d(r 0,) = {q } r 2 d(r,) = {q,q 2 } r 3 d(r 2,) = {q 0 } r 4 d(r 3,) = {q 2 }

Bck to first xmpl NFA: q 0 q q, 2 Accpts w = w =, w 2 =, w 3 =, w 4 =, w 5 = Accpting squnc of 5+ = 6 stts: r 0 = q 0, r = q, r 2 = q 2, r 3 = q 0, r 4 = q 2, r 5 = q 0 Trnsitions: r d(r 0,) = {q } r 2 d(r,) = {q,q 2 } r 3 d(r 2,) = {q 0 } r 4 d(r 3,) = {q 2 } r 5 d(r 4,) = {q 0 }

NFA r t lst s powrful s DFA, cus DFA r spcil cs of NFA Ar NFA mor powrful thn DFA? Surprisingly, thy r not: Thorm: For vry NFA N thr is DFA M : L(M) = L(N)

Thorm: For vry NFA N thr is DFA M : L(M) = L(N) Construction without trnsitions Givn NFA N (Q, S, d, q, F) Construct DFA M (Q', S, d', q', F') whr: Q' := Powrst(Q) q' = {q} F' = { S : S Q' nd S contins n lmnt of F} d'(s, ) := U s S d(s,) = { t : t d (s,) for som s S }

It rmins to dl with trnsitions Dfinition: Lt S st of stts. E(S) := { q : q cn rchd from som stt s in S trvling long 0 or mor trnsitions } W think of following trnsitions t ginning, or right ftr rding n input symol in S

Thorm: For vry NFA N thr is DFA M : L(M) = L(N) Construction including trnsitions Givn NFA N (Q, S, d, q, F) Construct DFA M (Q', S, d', q', F') whr: Q' := Powrst(Q) q' = E({q}) F' = { S : S Q' nd S contins n lmnt of F} d'(s, ) := E( U s S d(s,) ) = { t : t E( d (s,) ) for som s S }

Exmpl: NFA DFA convrsion NFA DFA 2 3, {,3} {3} {2} {2,3} {,2,3} Q DFA = Powrst(Q NFA ) = Powrst({,2,3}) = {,{},{2},{3},{,2}...} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, q DFA = E({q NFA }) = E({}) = {,3} {,3} {3} {2} {2,3} {,2,3} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, {,3} {3} {2} {2,3} {,2,3} F DFA = {S : S contins n lmnt of F NFA } {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, {,3} {3} {2} {2,3} {,2,3} d DFA ({}, ) = E(d NFA (, )) = E( ) = {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, {,3} {3} {2} {2,3} {,2,3} d DFA ({}, ) = E(d NFA (, )) = E({2}) = {2} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, {,3} {3} {2} {2,3} {,2,3} d DFA ({2}, ) = E(d NFA (2, )) = E({2,3}) = {2,3} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA {,3} {3} 2 3, {2} {2,3} {,2,3} d DFA ({2}, ) = E(d NFA (2, )) = E({3}) = {3} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA {,3} {3} 2 3, {2} {2,3} {,2,3} d DFA ({3}, ) = E(d NFA (3, )) = E({}) = {,3} {} {,2}

Exmpl: NFA DFA convrsion NFA DFA {,3} {3} 2 3, {2} {2,3} {,2,3} d DFA ({3}, ) = E(d NFA (3, )) = E( ) = {} {,2}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({2,3}, ) = E(d NFA (2,) U d NFA (3,)) = E({2,3} U {}) = {,2,3} {,3} {3} {2} {2,3} {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({2,3}, ) = E(d NFA (2,) U d NFA (3,)) = E({3} U ) = {3} {,3} {3} {2} {2,3} {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,3}, ) = E(d NFA (,) U d NFA (3,)) = E( U {}) = {,3} {,3} {3} {2} {2,3} {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,3}, ) = E(d NFA (,) U d NFA (3,)) = E({2} U ) = {2} {,3} {3} {2} {2,3} {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,2}, ) = E(d NFA (,) U d NFA (2,)) = E( U {2,3}) = {2,3} {,3} {3} {2} {2,3} {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,2}, ) = E(d NFA (,) U d NFA (2,)) = E({2} U {3}) = {2,3} {,3} {3} {2} {2,3}, {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,2,3}, ) =E(d NFA (,) U d NFA (2,) U d NFA (3,)) =E( U {2,3} U {}) = {,2,3} {,3} {3} {2} {2,3}, {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA 2 3, d DFA ({,2,3}, ) =E(d NFA (,) U d NFA (2,) U d NFA (3,)) =E({2} U {3} U ) = {2,3} {,3} {3} {2} {2,3}, {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA, 2 3, d DFA (, ) = d DFA (, ) = {,3} {3} {2} {2,3}, {} {,2} {,2,3}

Exmpl: NFA DFA convrsion NFA DFA, 2 3, {,3} {3} {2} {2,3} {,2,3} W cn dlt th unrchl stts.

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} Q DFA = Powrst(Q NFA ) = Powrst({,2,3}) = {,{},{2},{3},{,2}...} {2,3} {2} {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} q DFA = E({q NFA }) = E({}) {2,3} {2} {,3} {,2} = {}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} F DFA = {S : S contins n lmnt of F NFA } {2,3} {2} {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} d DFA ({}, ) = E(d NFA (, )) = E( ) = {2,3} {2} {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} d DFA ({}, ) = E(d NFA (, )) {2,3} {2} {,3} {,2} = E({2,3}) = {,2,3}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 DFA {3} {} {,2,3} d DFA ({2}, ) = E(d NFA (2, )) {2,3} {2} {,3} {,2} = E({3}) = {,3}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({2}, ) NFA 3 = E(d NFA (2, )) = E( ) = {3} {} {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({3}, ) NFA 3 = E(d NFA (3, )) = E( ) = {3} {} {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({3}, ) NFA 3 = E(d NFA (3, )) = E( ) = {3} {}, {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({,2}, ) NFA = E(d NFA (,) U d NFA (2,)) = E( U {3}) = {,3} 3 {3} {}, {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({,2}, ) NFA = E(d NFA (,) U d NFA (2,)) = E({2,3} U ) = {,2,3} 3 {3} {}, {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({,3}, ) NFA = E(d NFA (,) U d NFA (3,)) = E( U ) = 3 {3} {}, {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({,3}, ) NFA = E(d NFA (,) U d NFA (3,)) = E({2,3} U ) = {,2,3} 3 {3} {}, {,2,3} {2} DFA {,3} {2,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({2,3}, ) NFA = E(d NFA (2,) U d NFA (3,)) = E({3} U ) = {,3} 3 {2,3} {3} {}, {,2,3} {2} DFA {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 d DFA ({2,3}, ) NFA = E(d NFA (2,) U d NFA (3,)) = E( U ) = 3 {2,3} {3} {}, {,2,3} {2} DFA {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 d DFA ({,2,3}, ) =E(d NFA (,) U d NFA (2,) U d NFA (3,)) =E( U {3} U ) = {,3} {2,3} {3} {}, {,2,3} {2} DFA {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 d DFA ({,2,3}, ) =E(d NFA (,) U d NFA (2,) U d NFA (3,)) =E({2,3} U U ) = {,2,3} {2,3} {3} {}, {,2,3} {2} DFA {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 d DFA (, ) = d DFA (, ) = {2,3} {3} {}, {,2,3} {2} DFA, {,3} {,2}

ANOTHER Exmpl: NFA DFA convrsion 2 NFA 3 W cn dlt th unrchl stts. DFA {}, {,2,3} {,3}

Summry: NFA nd DFA rcogniz th sm lngugs W now rturn to th qustion: Suppos A, B r rgulr lngugs, wht out not A := { w : w is not in A } REGULAR A U B := { w : w in A or w in B } REGULAR A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i }

Thorm: If A, B r rgulr lngugs, thn so is A U B := { w : w in A or w in B } Proof id: Givn DFA M A : L(M A ) = A, DFA M B : L(M B ) = B, Construct NFA N : L(N) = A U B N M A M B U =

Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q :=? M A N M U B =

M A Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A U Q B, F :=? N M U B =

Construction: M A Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: M U B = Q := {q} U Q A U Q B, F := F A U F B d(r,x) := { da (r,x) } if r in Q A nd x N d(r,x) :=? if r in QB nd x

Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A U Q B, F := F A U F B d(r,x) := { da (r,x) } if r in Q A nd x d(r,x) := { db (r,x) } if r in Q B nd x d(q,) :=? M A M U B = N

Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A U Q B, F := F A U F B d(r,x) := { da (r,x) } if r in Q A nd x d(r,x) := { db (r,x) } if r in Q B nd x d(q,) := {qa, q B } M A W hv L(N) = A U B M U B = N

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr?

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr? OR is lik U, so try to writ L = L U L 2 whr L, L 2 r rgulr

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr? OR is lik U, so try to writ L = L U L 2 whr L, L 2 r rgulr L = {w : w is div. y 3} L 2 = {w : w strts with }

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr? OR is lik U, so try to writ L = L U L 2 whr L, L 2 r rgulr L = {w : w is div. y 3} L 2 = {w : w strts with } M = 0, 0, 0, L(M ) = L

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr? OR is lik U, so try to writ L = L U L 2 whr L, L 2 r rgulr L = {w : w is div. y 3} L 2 = {w : w strts with } M = 0, M 2 = 0, 0, 0, L(M ) = L L(M 2 ) = L 2

Exmpl Is L = {w in {0,}* : w is divisil y 3 OR w strts with } rgulr? OR is lik U, so try to writ L = L U L 2 whr L, L 2 r rgulr L = {w : w is div. y 3} L 2 = {w : w strts with } M = 0, L(M) = L(M 0, 0, ) U L(M 2 ) = L U L 2 0, = L L is rgulr.

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } REGULAR A U B := { w : w in A or w in B } REGULAR A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i }

Thorm: If A, B r rgulr lngugs, thn so is A o B := { w : w = xy for som x in A nd y in B }. Proof id: Givn DFAs M A, M B for A, B M A construct NFA N : L(N) = A o B. M ob = N

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q :=?

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q :=?

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q := q A, F :=?

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q := q A, F := F B d(r,x) :=? if r in QA nd x

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q := q A, F := F B d(r,x) := { da (r,x) } if r in Q A nd x d(r,) :=? if r in F A

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q := q A, F := F B d(r,x) := { da (r,x) } if r in Q A nd x d(r,) := { q B } if r in F A d(r,x) :=? if r in QB nd x

M A o M B = N Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, DFA M B = (Q B, S, d B, q B, F B ) : L(M B ) = B, Construct NFA N = (Q, S, d, q, F) whr: Q := Q A U Q B, q := q A, F := F B d(r,x) := { da (r,x) } if r in Q A nd x d(r,) := { q B } if r in F A d(r,x) := { db (r,x) } if r in Q B nd x W hv L(N) = A o B

Exmpl Is L = {w in {0,}* : w contins ftr 0} rgulr? Not: L = {0, 00000, 00, }

Exmpl Is L = {w in {0,}* : w contins ftr 0} rgulr? Lt L 0 = {w : w contins 0} L = {w : w contins }. Thn L = L 0 o L.

Exmpl Is L = {w in {0,}* : w contins ftr 0} rgulr? Lt L 0 = {w : w contins 0} L = {w : w contins }. Thn L = L 0 o L. M 0 = 0, 0 L(M 0 ) = L 0

Exmpl Is L = {w in {0,}* : w contins ftr 0} rgulr? Lt L 0 = {w : w contins 0} L = {w : w contins }. Thn L = L 0 o L. M 0 = 0, M = 0 0, 0 L(M 0 ) = L 0 L(M ) = L

Exmpl Is L = {w in {0,}* : w contins ftr 0} rgulr? Lt L 0 = {w : w contins 0} L = {w : w contins }. Thn L = L 0 o L. M = 0, 0 0, 0 L(M) = L(M 0 ) o L(M ) = L 0 o L = L L is rgulr.

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } REGULAR A U B := { w : w in A or w in B } REGULAR A o B := { w w 2 : w A nd w2 B } REGULAR A* := { w w 2 w k : k 0, w i in A for vry i }

Thorm: If A is rgulr lngug, thn so is A* := { w : w = w...w k, w i in A for i=,...,k } Proof id: Givn DFA M A : L(M A ) = A, Construct NFA N : L(N) = A* N M A * =

M A N * = Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, Construct NFA N = (Q, S, d, q, F) whr: Q :=?

M A N * = Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A, F :=?

M A N * = Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A, F := {q} U F A d(r,x) :=? if r in QA nd x

M A N * = Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A, F := {q} U F A d(r,x) := { da (r,x) } if r in Q A nd x d(r,) :=? if r in {q} U FA

M A N * = Construction: Givn DFA MA = (Q A, S, d A, q A, F A ) : L(M A ) = A, Construct NFA N = (Q, S, d, q, F) whr: Q := {q} U Q A, F := {q} U F A d(r,x) := { da (r,x) } if r in Q A nd x d(r,) := { qa } if r in {q} U F A W hv L(N) = A*

Exmpl Is L = {w in {0,}* : w hs vn lngth} rgulr?

Exmpl Is L = {w in {0,}* : w hs vn lngth} rgulr? Lt L 0 = {w : w hs lngth = 2}. Thn L = L 0 *.

Exmpl Is L = {w in {0,}* : w hs vn lngth} rgulr? Lt L 0 = {w : w hs lngth = 2}. Thn L = L 0 *. M 0 = 0, 0, L(M 0 ) = L 0

Exmpl Is L = {w in {0,}* : w hs vn lngth} rgulr? Lt L 0 = {w : w hs lngth = 2}. Thn L = L 0 *. M = 0, 0, L(M) = L(M 0 )* = L 0 * = L L is rgulr.

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } r ll rgulr!

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } Wht out A B := { w : w in A nd w in B }?

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } D Morgn's lws: A B = not ( (not A) U (not B) ) By ov, (not A) is rgulr, (not B) is rgulr, (not A) U (not B) is rgulr, not ( (not A) U (not B) ) = A B rgulr

W now rturn to th qustion: Suppos A, B r rgulr lngugs, thn not A := { w : w is not in A } A U B := { w : w in A or w in B } A o B := { w w 2 : w in A nd w 2 in B } A* := { w w 2 w k : k 0, w i in A for vry i } A B := { w : w in A nd w in B } r ll rgulr

Big pictur All lngugs Dcidl Turing mchins NP P Contxt-fr Contxt-fr grmmrs, push-down utomt Rgulr Automt, non-dtrministic utomt, rgulr xprssions

How to spcify rgulr lngug? Writ pictur complictd Writ down forml dfinition complictd d(q 0,0) = q 0, Us symols from S nd oprtions *, o, U good ({0} * U {}) o {00}

Rgulr xprssions: nything you cn writ with, ε, symols from S, nd oprtions *, o, U Convntions: Writ instd of {} Writ AB for A o B Writ for U So if = {,} thn = U Oprtion * hs prcdnc ovr o, nd o ovr U so U 0* mns U(0()*) Exmpl: 0, 0*, S*, S*00S*, (SS)*, 0 U 0

Dfinition Rgulr xprssions RE ovr r: Ø ε if in S R R' if R, R' r RE R U R' if R, R' r RE R* if R is RE

Dfinition Th lngug dscrid y RE: L(Ø) = Ø L( ε ) = { ε } L() = {} if in L(R R') = L(R) o L(R') L(R U R') = L(R) U L(R') L(R*) = L(R)*

Exmpl = {, } RE Lngug U? * ( U )* ** * * * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * ( U )* ** * * * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ** * * * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ** ll strings * * * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * {w : w hs t lst on } * * ( )* (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * {w : w hs t lst on } * * ( )* {w : w contins th string } (***)* ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * {w : w hs t lst on } * * ( )* (***)* {w : w contins th string } {w : w hs vn lngth} ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * {w : w hs t lst on } * * {w : w contins th string } ( )* {w : w hs vn lngth} (***)* {w : w contins vn numr of } ** Ø

Exmpl = {, } RE Lngug U {, } * {ε,,, } = { w : w hs only } ( U )* ll strings ** {w : w hs xctly on } * * {w : w hs t lst on } * * {w : w contins th string } ( )* {w : w hs vn lngth} (***)* {w : w contins vn numr of } ** Ø Ø (nything o Ø = Ø)

Thorm: For vry RE R thr is NFA M: L(M) = L(R)

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M :=?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M :=?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M := R = M :=?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M := R = M := R = R U R'?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M := R = M := R = R U R' us construction for A U B sn rlir R = R o R'?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M := R = M := R = R U R' us construction for A U B sn rlir R = R o R' us construction for A o B sn rlir R = R*?

Thorm: For vry RE R thr is NFA M: L(M) = L(R) Construction: R = M := R = M := R = M := R = R U R' us construction for A U B sn rlir R = R o R' us construction for A o B sn rlir R = R* us construction for A* sn rlir

Exmpl: RE NFA RE = ( U )*

Exmpl: RE NFA RE = ( U )* M = L(M )=L()

Exmpl: RE NFA RE = ( U )* M = M = L(M )=L() L(M )=L()

Exmpl: RE NFA RE = ( U )* M = L(M )=L()

Exmpl: RE NFA RE = ( U )* M = M = L(M )=L() L(M )=L()

Exmpl: RE NFA RE = ( U )* M U = L(M U )=L( U )

Exmpl: RE NFA RE = ( U )* M ( U )* = L(M ( U )* )=L(( U )*)=L(RE)

ANOTHER Exmpl: RE NFA RE =( U )*

ANOTHER Exmpl: RE NFA RE =( U )* M = L(M )=L()

ANOTHER Exmpl: RE NFA RE =( U )* M = M = L(M )=L() L(M )=L()

ANOTHER Exmpl: RE NFA RE =( U )* M U = L(M U )=L( U )

ANOTHER Exmpl: RE NFA RE =( U )* M U = M = L(M )=L() L(M U )=L( U )

ANOTHER Exmpl: RE NFA RE =( U )* M ( U ) = L(M ( U ) )=L(( U ))

ANOTHER Exmpl: RE NFA RE =( U )* M ( U ) = M = L(M )=L() L(M ( U ) )=L(( U ))

ANOTHER Exmpl: RE NFA RE =( U )* M ( U ) = M * = L(M * )=L(*) L(M ( U ) )=L(( U ))

ANOTHER Exmpl: RE NFA RE =( U )* M ( U )* = L(M ( U )* )=L(( U )*)=L(RE)

Rcp: Hr mns cn convrtd to W hv sn: RE NFA DFA Nxt w s: DFA RE In two stps: DFA Gnrlizd NFA RE

Gnrlizd NFA (GNFA) U * q 0 ** q Nondtrministic Trnsitions llld y RE Rd locks of input symols t tim

Gnrlizd NFA (GNFA) U * q 0 ** q Convntion: Uniqu finl stt Exctly on trnsition twn ch pir of stts xcpt nothing going into strt stt nothing going out of finl stt If rrow not shown in pictur, ll =

Dfinition: A gnrlizd finit utomton (GNFA) is 5-tupl (Q, S, d, q 0, q ) whr Q is finit st of stts S is th input lpht d : (Q - {q }) X (Q {q 0 }) Rgulr Exprssions q 0 in Q is th strt stt q in Q is th ccpt stt

Dfinition: GNFA (Q, S, d, q 0, q ) ccpts string w if intgr k, k strings w, w 2,, w k S* such tht w = w w 2 w k (divid w in k strings) $ squnc of k+ stts r0, r,.., r k in Q such tht: r 0 = q 0 w i+ L(d(r i,r i+ )) 0 i < k r k = q Diffrncs with NFA r in grn

Exmpl * * q 0 q q Accpts w = w =?

Exmpl * * q 0 q q Accpts w = w = w 2 =?

Exmpl * * q 0 q q Accpts w = w = w 2 = w 3 = r 0 =q 0 r =?

Exmpl * * q 0 q q Accpts w = w = w 2 = w 3 = r 0 =q 0 r =q r 2 =? w = L(d(r 0,r )) = L(d(q 0,q )) = L(*)

Exmpl * * q 0 q q Accpts w = w = w 2 = w 3 = r 0 =q 0 r =q r 2 =q r 3 =? w = L(d(r 0,r )) = L(d(q 0,q )) = L(*) w 2 = L(d(r,r 2 )) = L(d(q,q )) = L(*)

Exmpl * * q 0 q q Accpts w = w = w 2 = w 3 = r 0 =q 0 r =q r 2 =q r 3 = q w = L(d(r 0,r )) = L(d(q 0,q )) = L(*) w 2 = L(d(r,r 2 )) = L(d(q,q )) = L(*) w 3 = L(d(r 2,r 3 )) = L(d(q,q )) = L()

Thorm: DFA M GNFA N : L(N) = L(M) Construction: To nsur uniqu trnsition twn ch pir: U 0 0 To nsur uniqu finl stt, no trnsitions ingoing strt stt, no trnsitions outgoing finl stt:

Rpt until 2 stts rmin Thorm: GNFA N RE R : L(R) = L(N) Construction: If N hs 2 stts, thn N = thus R := S q 0 S q If N hs > 2 stts, limint som stt q r q 0, q : for vry ordrd pir q i, q j (possily qul) tht r connctd through q r R 2 R R R 2 *R 3 U R q R 4 i q 3 r q j q i q j R 4

Exmpl: DFA GNFA RE DFA q,c q 2

Exmpl: DFA GNFA RE GNFA q 0 q U c q 2 q

Exmpl: DFA GNFA RE q 0 q U c q 2 q Elimint q : r-drw GNFA with ll othr stts q 0 q 2 q

Exmpl: DFA GNFA RE q 0 q U c q 2 q Elimint q : find pth through q q 0 q 2 q

Exmpl: DFA GNFA RE Ø q 0 q U c q 2 q Elimint q : dd dg to nw GNFA Don't forgt: no rrow mns ll Ø q 0 * ( U c) U Ø q 2 q

Exmpl: DFA GNFA RE q 0 q U c q 2 q Elimint q : simplify RE on nw dg q 0 * ( U c) q 2 q

Exmpl: DFA GNFA RE q 0 q U c q 2 q Elimint q : if no mor pths through q, strt ovr q 0 * ( U c) q 2 q

Exmpl: DFA GNFA RE q 0 * ( U c) q 2 q Elimint q 2 : r-drw GNFA with ll othr stts q 0 q

Exmpl: DFA GNFA RE q 0 * ( U c) q 2 q Elimint q 2 : find pth through q 2 q 0 q

Exmpl: DFA GNFA RE q 0 * ( U c) q 2 q Elimint q 2 : dd dg to nw GNFA q 0 * ( U c) * U Ø q

Exmpl: DFA GNFA RE q 0 * ( U c) q 2 q Elimint q 2 : simplify RE on nw dg q 0 * ( U c) * q

Exmpl: DFA GNFA RE q 0 * ( U c) q 2 q Elimint q 2 : if no mor pths through q 2, strt ovr q 0 * ( U c) * q

Exmpl: DFA GNFA RE q 0 * ( U c) * q Only two stts rmin: RE = * ( U c) *

ANOTHER Exmpl: DFA GNFA RE DFA q c c q 2 q 3

ANOTHER Exmpl: DFA GNFA RE GNFA q 0 q c c q 2 q 3 q

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q r-drw GNFA with ll othr stts q 3 q q 0 q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q find pth through q q 3 q q 0 q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q dd dg to nw GNFA * U Ø q 3 q q 0 q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q find nothr pth through q * U Ø q 3 q q 0 q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q dd dg to nw GNFA * U Ø q 3 q q 0 *c U Ø q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q find nothr pth through q * U Ø q 3 q q 0 *c U Ø q 2

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : dd dg to nw GNFA q c q 0 c q 2 q 3 * U Ø q q 3 don't forgt currnt q 2 q 3 dg! This tim is not Ø! q *c U Ø q 2 c* U

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q find nothr pth through q * U Ø q 3 q q 0 *c U Ø q 2 c* U

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : dd dg to q c c q 2 q 3 q don't forgt currnt q 2 q 2 dg! nw GNFA * U Ø q 3 q q 0 *c U Ø q 2 c* U c*c U

ANOTHER Exmpl: DFA GNFA RE q 0 Elimint q : q c c q 2 q 3 q whn no mor pths through q, strt ovr (nd simplify * q 3 q REs) q 0 *c c* U q 2 c*c U

ANOTHER Exmpl: DFA GNFA RE * q 3 q q 0 *c q 2 c* U Elimint q 2 : c*c U r-drw GNFA with ll othr stts q 0 * q 3 q

ANOTHER Exmpl: DFA GNFA RE * q 3 q q 0 *c q 2 c* U Elimint q 2 : c*c U find pth through q 2 q 0 * q 3 q

ANOTHER Exmpl: DFA GNFA RE * q 3 q q 0 *c q 2 c* U Elimint q 2 : c*c U dd dg to nw GNFA q 0 *c(c*c U )*(c* U ) U * q 3 q

ANOTHER Exmpl: DFA GNFA RE * q 3 q q 0 Elimint q 2 : *c whn no mor pths through q 2, strt ovr q 2 c* U c*c U q 0 *c(c*c U )*(c* U ) U * q 3 q

ANOTHER Exmpl: DFA GNFA RE q 0 *c(c*c U )*(c* U ) U * q 3 q Elimint q 3 : r-drw GNFA with ll othr stts q 0 q

ANOTHER Exmpl: DFA GNFA RE q 0 *c(c*c U )*(c* U ) U * q 3 q Elimint q 3 : find pth through q 3 Ø Ø don't forgt: no rrow mns Ø q 0 q

ANOTHER Exmpl: DFA GNFA RE q 0 *c(c*c U )*(c* U ) U * q 3 q Elimint q 3 : dd dg to nw GNFA Ø Ø (*c(c*c U )*(c* U ) U *) Ø* ε U Ø q 0 q

ANOTHER Exmpl: DFA GNFA RE q 0 *c(c*c U )*(c* U ) U * q 3 q Elimint q 3 : whn no mor pths through q 3, strt ovr (nd simplify REs) don't forgt: Ø*= ε q 0 *c(c*c U )*(c* U ) U * q

ANOTHER Exmpl: DFA GNFA RE q 0 *c(c*c U )*(c* U ) U * q Only two stts rmin: RE = *c(c*c U )*(c* U ) U *

Rcp: Hr mns cn convrtd to RE DFA NFA Any of th thr rcogniz xctly th rgulr lngugs (initilly dfind using DFA)

Ths convrsions r usd vry tim you ntr n RE, for xmpl for pttrn mtching using grp Th RE is convrtd to n NFA Thn th NFA is convrtd to DFA Th DFA rprsnttion is usd to pttrn-mtch Optimiztions hv n dvisd, ut this is still th gnrl pproch.

Wht lngug is NOT rgulr? Is { 0 n n : n 0 } = {ε, 0, 00, 000, } rgulr?

Pumping lmm: L rgulr lngug p 0 w L, w p x,y,z : w= xyz, y > 0, xy p i 0 : xy i z L Rcll y 0 =, y = y, y 2 = yy, y 3 = yyy,...

Pumping lmm: L rgulr lngug p 0 W will not s th proof. But hr's th id: p := Q for DFA rcognizing L w L, w p If w L, w p, thn during computtion 2 stts must th sm q Q y = portion of w tht rings ck to q cn rpt y nd still ccpt string x,y,z : w= xyz, y > 0, xy p i 0 : xy i z L

Pumping lmm: L rgulr lngug p 0 A w L, w p x,y,z : w= xyz, y > 0, xy p i 0 : xy i z L Usful to prov L NOT rgulr. Us contrpositiv: L rgulr lngug A sm s (not A) L not rgulr

Pumping lmm (contrpositiv) p 0 not A w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L L not rgulr To prov L not rgulr it is nough to prov not A Not A is th stuff in th ox.

Proving somthing lik l l l l l mns winning gm Thory is ll out winning gms!

Exmpl NAME THE BIGGEST NUMBER GAME Two plyrs: You, Advrsry. Ruls: First Advrsry sys numr. Thn You sy numr. You win if your numr is iggr. Cn you win this gm?

Exmpl NAME THE BIGGEST NUMBER GAME Two plyrs: You, Advrsry. Ruls: First Advrsry sys numr. Thn You sy numr. You win if your numr is iggr. You hv winning strtgy: if dvrsry sys x, you sy x+

Exmpl NAME THE BIGGEST NUMBER GAME Two plyrs: You, Advrsry. Ruls: First Advrsry sys numr. Thn You sy numr. You win if your numr is iggr., x y : y > x You hv winning strtgy: if dvrsry sys x, you sy x+ Clim is tru

Anothr xmpl: Thorm: NFA N DFA M : L(M) = L(N) W lrdy sw winning strtgy for this gm Wht is it?

Anothr xmpl: Thorm: NFA N DFA M : L(M) = L(N) W lrdy sw winning strtgy for this gm Th powr st construction.

Gms with mor movs: Chss, Chckrs, Tic-Tc-To You cn win if mov of th Advrsry mov You cn mk mov of th Advrsry mov You cn mk : You chckmt

Pumping lmm (contrpositiv) p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Ruls of th gm: Advrsry picks p, You pick w L of lngth p, L not rgulr Advrsry dcomposs w in xyz, whr y > 0, xy p You pick i 0 Finlly, you win if xy i z L

Thorm: L := {0 n n : n 0} is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := 0 p p Advrsry movs x,y,z You mov i := 2 You must show xyyz L: p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Sinc xy p nd w = xyz = 0 p p, y only hs 0 So xyyz = 0 p + y p Sinc y > 0, this is not of th form 0 n n DONE

Thorm: L := {w : w hs s mny 0 s } not rgulr Sm Proof: Us pumping lmm Advrsry movs p You mov w :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {w : w hs s mny 0 s } not rgulr Sm Proof: Us pumping lmm Advrsry movs p You mov w := 0 p p Advrsry movs x,y,z You mov i :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {w : w hs s mny 0 s } not rgulr Sm Proof: Us pumping lmm Advrsry movs p You mov w := 0 p p Advrsry movs x,y,z You mov i := 2 You must show xyyz L: p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Sinc xy p nd w = xyz = 0 p p, y only hs 0 So xyyz =?

Thorm: L := {w : w hs s mny 0 s } not rgulr Sm Proof: Us pumping lmm Advrsry movs p You mov w := 0 p p Advrsry movs x,y,z You mov i := 2 You must show xyyz L: p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Sinc xy p nd w = xyz = 0 p p, y only hs 0 So xyyz = 0 p + y p Sinc y > 0, not s mny 0 s DONE

Thorm: L := {0 j k : j > k} is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {0 j k : j > k} is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := 0 p+ p Advrsry movs x,y,z You mov i :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {0 j k : j > k} is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := 0 p+ p Advrsry movs x,y,z You mov i := 0 You must show xz L: p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Sinc xy p nd w = xyz = 0 p+ p, y only hs 0 So xz = 0 p + - y p Sinc y > 0, this is not of th form 0 j k with j > k

Thorm: L := {uu : u {0,}* } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {uu : u {0,}* } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := 0 p 0 p Advrsry movs x,y,z You mov i :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := {uu : u {0,}* } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := 0 p 0 p Advrsry movs x,y,z You mov i := 2 You must show xyyz L: p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L Sinc xy p nd w = xyz = 0 p 0 p, y only hs 0 So xyyz = 0 p + y 0 p Sinc y > 0, first hlf of xyyz only 0, so xyyz L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := p2 Advrsry movs x,y,z You mov i :=? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := p2 Advrsry movs x,y,z You mov i := 2 You must show xyyz L: Sinc xy p, xyyz? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := p2 Advrsry movs x,y,z You mov i := 2 You must show xyyz L: Sinc xy p, xyyz p 2 + p < (p+) 2 Sinc y > 0, xyyz >? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := p2 Advrsry movs x,y,z You mov i := 2 You must show xyyz L: Sinc xy p, xyyz p 2 + p < (p+) 2 Sinc y > 0, xyyz > p 2 So xyyz cnnot wht? p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Thorm: L := { n2 : n 0 } is not rgulr Proof: Us pumping lmm Advrsry movs p You mov w := p2 Advrsry movs x,y,z You mov i := 2 You must show xyyz L: Sinc xy p, xyyz p 2 + p < (p+) 2 Sinc y > 0, xyyz > p 2 So xyyz cnnot squr. xyyz L p 0 w L, w p x,y,z : w = xyz, y > 0, xy p i 0 : xy i z L

Big pictur All lngugs Dcidl Turing mchins NP P Contxt-fr Contxt-fr grmmrs, push-down utomt Rgulr Automt, non-dtrministic utomt, rgulr xprssions