CS21 Decidability and Tractability

Similar documents
CS21 Decidability and Tractability

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

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Theory of Computation (I) Yijia Chen Fudan University

Nondeterministic Finite Automata

COM364 Automata Theory Lecture Note 2 - Nondeterminism

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 455/555: Finite automata

Chapter Five: Nondeterministic Finite Automata

CS 154, Lecture 3: DFA NFA, Regular Expressions

September 7, Formal Definition of a Nondeterministic Finite Automaton

Lecture 3: Nondeterministic Finite Automata

Theory of Computation (II) Yijia Chen Fudan University

Inf2A: Converting from NFAs to DFAs and Closure Properties

Finite Automata and Regular languages

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

Nondeterministic finite automata

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

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

Lecture 4 Nondeterministic Finite Accepters

Computational Models Lecture 2 1

Fooling Sets and. Lecture 5

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

Intro to Theory of Computation

CSC236 Week 11. Larry Zhang

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,

Computational Models Lecture 2 1

Closure under the Regular Operations

Theory of Languages and Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

Non-Deterministic Finite Automata

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

Chap. 1.2 NonDeterministic Finite Automata (NFA)

Automata: a short introduction

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

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

Automata and Languages

Computational Theory

Nondeterministic Finite Automata

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata (cont )

Algorithms for NLP

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)

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

Introduction to Languages and Computation

Non-deterministic Finite Automata (NFAs)

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

UNIT-III REGULAR LANGUAGES

Lecture 17: Language Recognition

CSE 105 THEORY OF COMPUTATION

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

Outline. Nondetermistic Finite Automata. Transition diagrams. A finite automaton is a 5-tuple (Q, Σ,δ,q 0,F)

CS21 Decidability and Tractability

Theory of Computation

Equivalence of DFAs and NFAs

TDDD65 Introduction to the Theory of Computation

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

CS243, Logic and Computation Nondeterministic finite automata

Nondeterminism and Epsilon Transitions

Computer Sciences Department

Nondeterministic Finite Automata. Nondeterminism Subset Construction

CPS 220 Theory of Computation REGULAR LANGUAGES

INF Introduction and Regular Languages. Daniel Lupp. 18th January University of Oslo. Department of Informatics. Universitetet i Oslo

Lecture 1: Finite State Automaton

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Uses of finite automata

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

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

Theory of computation: initial remarks (Chapter 11)

CSE 105 Theory of Computation Professor Jeanne Ferrante

CISC 4090 Theory of Computation

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

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

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

CSE 135: Introduction to Theory of Computation Nondeterministic Finite Automata

Finite Automata and Languages

Computability and Complexity

CMSC 330: Organization of Programming Languages

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

Decision, Computation and Language

Formal Definition of Computation. August 28, 2013

CS 154 Introduction to Automata and Complexity Theory

Finite Automata. Dr. Neil T. Dantam. Fall CSCI-561, Colorado School of Mines. Dantam (Mines CSCI-561) Finite Automata Fall / 35

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

Computational Models - Lecture 1 1

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

Finite Automata (contd)

Foundations of

Nondeterministic Finite Automata

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

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

Proofs, Strings, and Finite Automata. CS154 Chris Pollett Feb 5, 2007.

CS 208: Automata Theory and Logic

3515ICT: Theory of Computation. Regular languages

Further discussion of Turing machines

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

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

Closure under the Regular Operations

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

Transcription:

CS21 Decidability and Tractability Lecture 2 January 5, 2018 January 5, 2018 CS21 Lecture 2 1

Outline Finite Automata Nondeterministic Finite Automata Closure under regular operations NFA, FA equivalence January 5, 2018 CS21 Lecture 2 2

Finite Automata simple model of computation reads input from left to right, one symbol at a time maintains state: information about what seen so far ( memory ) finite automaton has finite # of states: cannot remember more things for longer inputs 2 ways to describe: by diagram, or formally January 5, 2018 CS21 Lecture 2 3

FA diagrams (single) start state 1 0,1 alphabet Σ = {0,1} states 0 (several) accept states 0,1 transition for each symbol read input one symbol at a time; follow arrows; accept if end in accept state January 5, 2018 CS21 Lecture 2 4

Example FA Σ = {A,B,C} {Q,N,D} C B B B 5 10 15 A C C A B C A rej A,B,C Try: A AC CBCC AA BBBBBBB CCBC A A,C A,B,C A B B B 20 25 30 35 C C 35 cents January 5, 2018 CS21 Lecture 2 5

FA formal definition A finite automaton is a 5-tuple (Q, Σ, δ, q 0, F) Q is a finite set called the states Σ is a finite set called the alphabet δ:q x Σ Q is a function called the transition function q 0 is an element of Q called the start state F is a subset of Q called the accept states January 5, 2018 CS21 Lecture 2 6

FA formal definition 0 1 0 even odd 1 Specification of this FA in formal terms: Q = {even, odd} Σ = {0,1} q 0 = even F = {even} function δ: δ(even, 0) = even δ(even, 1) = odd δ(odd, 0) = odd δ(odd, 1) = even January 5, 2018 CS21 Lecture 2 7

Formal description of FA operation finite automaton accepts a string M = (Q, Σ, δ, q 0, F) w = w 1 w 2 w 3 w n Î Σ* if $ sequence r 0,r 1,r 2,,r n of states for which r 0 = q 0 δ(r i, w i+1 ) = r i+1 for i = 0,1,2,, n-1 r n Î F January 5, 2018 CS21 Lecture 2 8

What now? We have a model of computation (Maybe this is it. Maybe everything we can do with real computers we can do with FA ) try to characterize the languages FAs can recognize investigate closure under certain operations show that some languages not of this type January 5, 2018 CS21 Lecture 2 9

Characterizing FA languages We will show that the set of languages recognized by FA is closed under: union C = (A È B) concatenation C = (A B) star C = A* Meaning: if A and B are languages recognized by a FA, then C is a language recognized by a FA January 5, 2018 CS21 Lecture 2 10

Characterizing FA languages union C = (A È B) (A È B) = {x : x Î A or x Î B or both} concatenation C = (A B) (A B) = {xy : x Î A and y Î B} star C = A* (note: ε always in A*) A* = {x 1 x 2 x 3 x k : k 0 and each x i Î A} January 5, 2018 CS21 Lecture 2 11

Concatenation attempt (A B) = {xy : x Î A and y Î B} A B What label do we put on the new transitions? January 5, 2018 CS21 Lecture 2 12

Concatenation attempt ε 1 1 A B = 1 1 Need it to happen for free : label with ε (?) allows construct with multiple transitions with the same label (!?) January 5, 2018 CS21 Lecture 2 13

Nondeterministic FA We will make life easier by describing an additional feature (nondeterminism) that helps us to program FAs We will prove that FAs with this new feature can be simulated by ordinary FA same spirit as programming constructs like procedures The concept of nondeterminism has a significant role in TCS and this course. January 5, 2018 CS21 Lecture 2 14

(single) start state NFA diagrams states transitions: (several) accept states may have several with a given label (or none) may be labeled with ε At each step, several choices for next state January 5, 2018 CS21 Lecture 2 15

NFA operation Example of NFA operation: alphabet Σ = {0,1} 1 0,ε 1 0,1 0,1 input: 0 1 0 not accepted January 5, 2018 CS21 Lecture 2 16

NFA operation Example of NFA operation: alphabet Σ = {0,1} 1 0,ε 1 0,1 0,1 input: 1 1 0 accepted January 5, 2018 CS21 Lecture 2 17

NFA operation One way to think of NFA operation: string x = x 1 x 2 x 3 x n accepted if and only if there exists a way of inserting ε s into x x 1 εεx 2 x 3 εx n so that there exists a path of transitions from the start state to an accept state January 5, 2018 CS21 Lecture 2 18

NFA formal definition transitions powerset of Q : labeled with the set of all (Q, Σ, δ, q 0 alphabet, F) subsets of Q Q is a finite set called the symbols statesor ε A nondeterministic FA is a 5-tuple Σ is a finite set called the alphabet δ:q x (Σ È {ε}) Ã(Q) is a function called the transition function q 0 is an element of Q called the start state F is a subset of Q called the accept states January 5, 2018 CS21 Lecture 2 19

NFA formal definition s 1 0,ε 1 1 s 2 s 3 s 4 Specification of this NFA in formal terms: Q = {s 1, s 2, s 3, s 4 } Σ = {0,1} q 0 = s 1 F = {s 4 } 0,1 0,1 δ(s 1, 0) = {s 1 } δ(s 1, 1) = {s 1, s 2 } δ(s 1, ε) = { } δ(s 2, 0) = {s 3 } δ(s 2, 1) = { } δ(s 3, 0) = { } δ(s 3, 1) = {s 4 } δ(s 3, ε) = { } δ(s 4, 0) = {s 4 } δ(s 4, 1) = {s 4 } δ(s 2, ε) = {s 3 } δ(s 4, ε) = { } January 5, 2018 CS21 Lecture 2 20

Formal description of NFA operation NFA M = (Q, Σ, δ, q 0, F) accepts a string w = w 1 w 2 w 3 w n Î Σ* if w can be written (by inserting ε s) as: y = y 1 y 2 y 3 y m Î (Σ È {ε})* and $ sequence r 0,r 1,,r m of states for which r 0 = q 0 r i+1 Î δ(r i, y i+1 ) for i = 0,1,2,, m-1 r m Î F January 5, 2018 CS21 Lecture 2 21

Closures Recall: want to show the set of languages recognized by NFA is closed under: union C = (A È B) concatenation C = (A B) star C = A* January 5, 2018 CS21 Lecture 2 22

Closure under union C = (A È B) = {x : x Î A or x Î B} ε A A ε B C B January 5, 2018 CS21 Lecture 2 23

Closure under concatenation C = (A B) = {xy : x Î A and y Î B} A B ε ε C A B January 5, 2018 CS21 Lecture 2 24

Closure under star C = A* = {x 1 x 2 x 3 x k : k 0 and each x i Î A} C A ε ε ε A January 5, 2018 CS21 Lecture 2 25

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 5, 2018 CS21 Lecture 2 26

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 5, 2018 CS21 Lecture 2 27

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 5, 2018 CS21 Lecture 2 28

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 5, 2018 CS21 Lecture 2 29

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 5, 2018 CS21 Lecture 2 30

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 5, 2018 CS21 Lecture 2 31

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 5, 2018 CS21 Lecture 2 32

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 5, 2018 CS21 Lecture 2 33

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 5, 2018 CS21 Lecture 2 34

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 5, 2018 CS21 Lecture 2 35

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 5, 2018 CS21 Lecture 2 36

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 5, 2018 CS21 Lecture 2 37