CS21 Decidability and Tractability

Similar documents
CS21 Decidability and Tractability

Outline. CS21 Decidability and Tractability. Regular expressions and FA. Regular expressions and FA. Regular expressions and FA

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

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

September 7, Formal Definition of a Nondeterministic Finite Automaton

Computational Models Lecture 2 1

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Computational Models Lecture 2 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Theory of Computation (II) Yijia Chen Fudan University

Examples of Regular Expressions. Finite Automata vs. Regular Expressions. Example of Using flex. Application

Lecture 3: Nondeterministic Finite Automata

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

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

Algorithms for NLP

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

Clarifications from last time. This Lecture. Last Lecture. CMSC 330: Organization of Programming Languages. Finite Automata.

Regular Expressions. Definitions Equivalence to Finite Automata

Chapter Five: Nondeterministic Finite Automata

CS 455/555: Finite automata

Outline. CS21 Decidability and Tractability. Machine view of FA. Machine view of FA. Machine view of FA. Machine view of FA.

Nondeterministic Finite Automata

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

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

Intro to Theory of Computation

Foundations of

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

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

CS311 Computational Structures Regular Languages and Regular Expressions. Lecture 4. Andrew P. Black Andrew Tolmach

Decision, Computation and Language

Theory of Computation (I) Yijia Chen Fudan University

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,

Lecture 4 Nondeterministic Finite Accepters

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computation Prof. Raghunath Tewari Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

COMP4141 Theory of Computation

Non-Deterministic Finite Automata

Regular Expressions and Language Properties

Equivalence of DFAs and NFAs

Theory of Languages and Automata

Non-deterministic Finite Automata (NFAs)

What we have done so far

Finite Automata and Regular languages

TDDD65 Introduction to the Theory of Computation

How do regular expressions work? CMSC 330: Organization of Programming Languages

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

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

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

Lecture 3: Finite Automata

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

Name: Student ID: Instructions:

CS21 Decidability and Tractability

Harvard CS 121 and CSCI E-207 Lecture 6: Regular Languages and Countability

Computational Theory

Incorrect reasoning about RL. Equivalence of NFA, DFA. Epsilon Closure. Proving equivalence. One direction is easy:

Introduction to Languages and Computation

Nondeterministic finite automata

Uses of finite automata

CSE 105 THEORY OF COMPUTATION

CSE 105 THEORY OF COMPUTATION

Lecture 4: Finite Automata

acs-04: Regular Languages Regular Languages Andreas Karwath & Malte Helmert Informatik Theorie II (A) WS2009/10

CS243, Logic and Computation Nondeterministic finite automata

Lecture 3: Finite Automata

Automata: a short introduction

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

CS 301. Lecture 18 Decidable languages. Stephen Checkoway. April 2, 2018

3515ICT: Theory of Computation. Regular languages

CSE 105 THEORY OF COMPUTATION

Finite Automata. BİL405 - Automata Theory and Formal Languages 1

Closure under the Regular Operations

Nondeterministic Finite Automata

CMSC 330: Organization of Programming Languages. Theory of Regular Expressions Finite Automata

Johns Hopkins Math Tournament Proof Round: Automata

Theory of computation: initial remarks (Chapter 11)

Concatenation. The concatenation of two languages L 1 and L 2

Let us first give some intuitive idea about a state of a system and state transitions before describing finite automata.

TAFL 1 (ECS-403) Unit- II. 2.1 Regular Expression: The Operators of Regular Expressions: Building Regular Expressions

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

CSE 105 Theory of Computation Professor Jeanne Ferrante

Automata and Languages

Computer Sciences Department

Mapping Reducibility. Human-aware Robotics. 2017/11/16 Chapter 5.3 in Sipser Ø Announcement:

Nondeterministic Finite Automata

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

Computability Theory

10. The GNFA method is used to show that

Deterministic Finite Automaton (DFA)

Chapter 6: NFA Applications

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

CMPSCI 250: Introduction to Computation. Lecture #22: From λ-nfa s to NFA s to DFA s David Mix Barrington 22 April 2013

Theory of computation: initial remarks (Chapter 11)

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

Lecture 2: Connecting the Three Models

Theory of Computation

CSC236 Week 11. Larry Zhang

CS 322 D: Formal languages and automata theory

Transcription:

CS21 Decidability and Tractability Lecture 3 January 9, 2017 January 9, 2017 CS21 Lecture 3 1

Outline NFA, FA equivalence Regular Expressions FA and Regular Expressions January 9, 2017 CS21 Lecture 3 2

NFA, FA equivalence Theorem: a language L is recognized by a FA if and only if L is recognized by a NFA. Must prove two directions: (Þ) L is recognized by a FA implies L is recognized by a NFA. (Ü) L is recognized by a NFA implies L is recognized by a FA. (usually one is easy, the other more difficult) January 9, 2017 CS21 Lecture 3 3

NFA, FA equivalence (Þ) L is recognized by a FA implies L is recognized by a NFA Proof: a finite automaton is a nondeterministic finite automaton that happens to have no ε-transitions, and for which each state has exactly one outgoing transition for each symbol. January 9, 2017 CS21 Lecture 3 4

NFA, FA equivalence (Ü) L is recognized by a NFA implies L is recognized by a FA. Proof: we will build a FA that simulates the NFA (and thus recognizes the same language). alphabet will be the same what are the states of the FA? January 9, 2017 CS21 Lecture 3 5

NFA, FA equivalence 1 0,ε 1 0,1 0,1 given NFA M = (Q, Σ, δ, q 0, F) construct FA M = (Q, Σ, δ, q 0, F ) same alphabet: Σ = Σ states are subsets of M s states: Q = Ã(Q) if we are in state RÎQ and we read symbol aîσ, what is the new state? January 9, 2017 CS21 Lecture 3 6

NFA, FA equivalence 1 0,ε 1 0,1 0,1 given NFA M = (Q, Σ, δ, q 0, F) construct FA M = (Q, Σ, δ, q 0, F ) Helpful def n: E(S) = {q Î Q : q reachable from S by traveling along 0 or more ε-transitions} new transition fn: δ (R, a) = È rîr E(δ(r, a)) = all nodes reachable from R by following an a-transition, and then 0 or more ε-transitions January 9, 2017 CS21 Lecture 3 7

NFA, FA equivalence 1 0,ε 1 0,1 0,1 given NFA M = (Q, Σ, δ, q 0, F) construct FA M = (Q, Σ, δ, q 0, F ) new start state: q 0 = E({q 0 }) new accept states: F = {R Î Q : R contains an accept state of M) January 9, 2017 CS21 Lecture 3 8

NFA, FA equivalence We have proved (Ü) by construction. Formally we should also prove that the construction works, by induction on the number of steps of the computation. at each step, the state of the FA M is exactly the set of reachable states of the NFA M January 9, 2017 CS21 Lecture 3 9

So far Theorem: the set of languages recognized by NFA is closed under union, concatenation, and star. Theorem: a language L is recognized by a FA if and only if L is recognized by a NFA. Theorem: the set of languages recognized by FA is closed under union, concatenation, and star. January 9, 2017 CS21 Lecture 3 10

Next Describe the set of languages that can be built up from: unions concatenations star operations Called patterns or regular expressions Theorem: a language L is recognized by a FA if and only if L is described by a regular expression. January 9, 2017 CS21 Lecture 3 11

Regular expressions R is a regular expression if R is a, for some a Î Σ ε, the empty string Ø, the empty set (R 1 È R 2 ), where R 1 and R 2 are reg. exprs. (R 1 R 2 ), where R 1 and R 2 are reg. exprs. (R 1 *), where R 1 is a regular expression A reg. expression R describes the language L(R). January 9, 2017 CS21 Lecture 3 12

Regular expressions example: R = (0 È 1) if Σ = {0,1} then use Σ as shorthand for R example: R = 0 Σ* shorthand: omit R = 0Σ* precedence: *, then, then È, unless override by parentheses in example R = 0(Σ*), not R = (0Σ)* January 9, 2017 CS21 Lecture 3 13

Some examples {w : w has at least one 1} = Σ*1Σ* {w : w starts and ends with same symbol} = 0Σ*0 È 1Σ*1 È 0 È 1 {w : w 5} = (ε È Σ)(ε È Σ)(ε È Σ)(ε È Σ)(ε È Σ) {w : every 3 rd position of w is 1} = (1ΣΣ)*(ε È 1 È 1Σ) alphabet Σ = {0,1} January 9, 2017 CS21 Lecture 3 14

Manipulating regular expressions The empty set and the empty string: R È Ø = R Rε = εr = R RØ = ØR = Ø È and behave like +, x; Ø, ε behave like 0,1 additional identities: R È R = R (here + and È differ) (R 1 *R 2 )*R 1 * = (R 1 È R 2 )* R 1 (R 2 R 1 )* = (R 1 R 2 )*R 1 January 9, 2017 CS21 Lecture 3 15

Theorem: a language L is recognized by a FA if and only if L is described by a regular expression. Must prove two directions: (Þ) L is recognized by a FA implies L is described by a regular expression (Ü) L is described by a regular expression implies L is recognized by a FA. January 9, 2017 CS21 Lecture 3 16

(Ü) L is described by a regular expression implies L is recognized by a FA Proof: given regular expression R we will build a NFA that recognizes L(R). then NFA, FA equivalence implies a FA for L(R). January 9, 2017 CS21 Lecture 3 17

R is a regular expression if R is a, for some a Î Σ a ε, the empty string Ø, the empty set January 9, 2017 CS21 Lecture 3 18

(R 1 È R 2 ), where R 1 and R 2 are reg. exprs. (R 1 R 2 ), where R 1 and R 2 are reg. exprs. (R 1 *), where R 1 is a regular expression ε ε ε ε ε ε ε January 9, 2017 CS21 Lecture 3 19

(Þ) L is recognized by a FA implies L is described by a regular expression Proof: given FA M that recognizes L, we will 1. build an equivalent machine Generalized Nondeterministic Finite Automaton (GNFA) 2. convert the GNFA into a regular expression January 9, 2017 CS21 Lecture 3 20

GNFA definition: it is a NFA, but may have regular expressions labeling its transitions GNFA accepts string w Î Σ* if can be written w = w 1 w 2 w 3 w k where each w i Î Σ*, and there is a path from the start state to an accept state in which the i th transition traversed is labeled with R for which w i Î L(R) January 9, 2017 CS21 Lecture 3 21

Recall step 1: build an equivalent GNFA Our FA M is a GNFA. We will require normal form for GNFA to make the proof easier: single accept state q accept that has all possible incoming arrows every state has all possible outgoing arrows; exception: start state q 0 has no self-loop January 9, 2017 CS21 Lecture 3 22

converting our FA M into GNFA in normal form: 0,1 0 È 1 ε ε Ø Ø Ø Ø Ø Ø Ø M ε January 9, 2017 CS21 Lecture 3 23

On to step 2: convert the GNFA into a regular expression if normal-form GNFA has two states: R the regular expression R labeling the single transition describes the language recognized by the GNFA January 9, 2017 CS21 Lecture 3 24

if GNFA has more than 2 states: q rip select one q rip ; delete it; repair transitions so that machine still recognizes same language. repeat until only 2 states. January 9, 2017 CS21 Lecture 3 25

how to repair the transitions: for every pair of states q i and q j do q i R 4 q j (R 1 )(R 2 )*(R 3 ) È (R 4 ) R 1 R 3 q rip q i q j R 2 January 9, 2017 CS21 Lecture 3 26

summary: FA M k-state GNFA (k-1)-state GNFA (k-2)-state GNFA 2-state GNFA R want to prove that this procedure is correct, i.e. L(R) = language recognized by M FA M equivalent to k-state GNFA i-state GNFA equivalent to (i-1)-state GNFA (we will prove ) 2-state GFNA equivalent to R January 9, 2017 CS21 Lecture 3 27

Claim: i-state GNFA G equivalent to (i-1)- state GNFA G (obtained by removing q rip ) Proof: if G accepts string w, then it does so by entering states: q 0, q 1, q 2, q 3,, q accept if none are q rip then G accepts w (see slide) else, break state sequence into runs of q rip : q 0 q 1 q i q rip q rip q rip q j q accept transition from q i to q j in G allows all strings taking G from q i to q j using q rip (see slide) thus G accepts w January 9, 2017 CS21 Lecture 3 28

q i R 4 q j (R 1 )(R 2 )*(R 3 ) È (R 4 ) R 1 R 3 q rip q i q j R 2 January 9, 2017 CS21 Lecture 3 29

q i R 4 q j (R 1 )(R 2 )*(R 3 ) È (R 4 ) R 1 R 3 q rip q i q j R 2 January 9, 2017 CS21 Lecture 3 30

Proof (continued): if G accepts string w, then every transition from q i to q j traversed in G corresponds to either a transition from q i to q j in G or transitions from q i to q j via q rip in G In both cases G accepts w. Conclude: G and G recognize the same language. January 9, 2017 CS21 Lecture 3 31

Theorem: a language L is recognized by a FA iff L is described by a regular expr. Languages recognized by a FA are called regular languages. Rephrasing what we know so far: regular languages closed under 3 operations NFA recognize exactly the regular languages regular expressions describe exactly the regular languages January 9, 2017 CS21 Lecture 3 32