Lecture 2: Regular Expression

Similar documents
Lecture 1: Finite State Automaton

Lecture 13: Turing Machine

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

Regular Expressions. Definitions Equivalence to Finite Automata

Lecture 4 Nondeterministic Finite Accepters

DFA to Regular Expressions

TWO-WAY FINITE AUTOMATA & PEBBLE AUTOMATA. Written by Liat Peterfreund

Lecture 14: Recursive Languages

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Chapter Five: Nondeterministic Finite Automata

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

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

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

CS 154 Formal Languages and Computability Assignment #2 Solutions

CS 455/555: Finite automata

Automata and Languages

Theory of Computation (I) Yijia Chen Fudan University

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CS 154, Lecture 3: DFA NFA, Regular Expressions

CS 154. Finite Automata, Nondeterminism, Regular Expressions

Parsing Regular Expressions and Regular Grammars

Nondeterministic Finite Automata

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

What we have done so far

Regular Expressions and Language Properties

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

Computational Models Lecture 2 1

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Algorithms for NLP

Equivalence of DFAs and NFAs

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

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

Computational Models Lecture 2 1

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

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

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

Deterministic Finite Automaton (DFA)

Automata and Formal Languages - CM0081 Non-Deterministic Finite Automata

Chapter 5. Finite Automata

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

Finite Automata and Formal Languages

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

Nondeterministic Finite Automata. Nondeterminism Subset Construction

Recitation 2 - Non Deterministic Finite Automata (NFA) and Regular OctoberExpressions

CS5371 Theory of Computation. Lecture 10: Computability Theory I (Turing Machine)

Nondeterminism and Epsilon Transitions

Equivalence of Regular Expressions and FSMs

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

Please give details of your answer. A direct answer without explanation is not counted.

Nondeterministic Finite Automata

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

Nondeterministic Finite Automata

Lecture 5: Minimizing DFAs

September 7, Formal Definition of a Nondeterministic Finite Automaton

THEORY OF COMPUTATION

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

CSE 311 Lecture 25: Relating NFAs, DFAs, and Regular Expressions. Emina Torlak and Kevin Zatloukal

ECS 120 Lesson 15 Turing Machines, Pt. 1

Regular Language Equivalence and DFA Minimization. Equivalence of Two Regular Languages DFA Minimization

Most General computer?

Theory of Computation (II) Yijia Chen Fudan University

Nondeterministic Finite Automata

Finite Automata and Regular languages

Lecture 3: Nondeterministic Finite Automata

Sri vidya college of engineering and technology

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

Formal Language and Automata Theory (CS21004)

Turing Machines (TM) Deterministic Turing Machine (DTM) Nondeterministic Turing Machine (NDTM)

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

TDDD65 Introduction to the Theory of Computation

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

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

CMSC 330: Organization of Programming Languages

Computational Models - Lecture 1 1

2. Elements of the Theory of Computation, Lewis and Papadimitrou,

CS 121, Section 2. Week of September 16, 2013

Inf2A: Converting from NFAs to DFAs and Closure Properties

Outline. Summary. DFA -> Regex. Finish off Regex -> e-nfa -> NFA -> DFA -> Regex Minimization/equivalence (Myhill-Nerode theorem)

Nondeterministic finite automata

COMP4141 Theory of Computation

Languages. A language is a set of strings. String: A sequence of letters. Examples: cat, dog, house, Defined over an alphabet:

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

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

(Refer Slide Time: 0:21)

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

Introduction to Turing Machines. Reading: Chapters 8 & 9

CS21 Decidability and Tractability

Theory of Languages and Automata

Lecture 17: Language Recognition

Kleene Algebras and Algebraic Path Problems

Deterministic Finite Automata (DFAs)

CS243, Logic and Computation Nondeterministic finite automata

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

Deterministic Finite Automata (DFAs)

Computational Models - Lecture 3

FS Properties and FSTs

Deterministic Finite Automata (DFAs)

Languages, regular languages, finite automata

Uses of finite automata

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

Transcription:

Lecture 2: Regular Expression Instructor: Ketan Mulmuley Scriber: Yuan Li January 8, 2015 In the last lecture, we proved that DFA, NFA, and NFA with ϵ-moves are equivalent. Recall that a language L Σ is called regular if L = L(M) for some DFA M (or equivalently NFA, or NFA with ϵ-moves). In this lecture, we will give a syntactic characterization of regular languages. 1 Regular Expression For example, R = (0 + 1) 00(0 + 1) is a regular expression representing all binary strings containing two consecutive zeros. Here, + means or, means repetition any number of times (including zero times). Formally, regular expression is defined by the following rules. ϕ is a regular expression, which denotes {} Σ. ϵ is a regular expression, which denotes {ϵ}. For each a Σ, a is a regular expression, which denotes {a}. If r and s are regular expressions, r + s, rs, r are also regular expressions. If r, s denote R, S Σ respectively, then r + s denotes R S, rs denotes RS = {uv : u R, v S}, and r denotes R = i 0 Ri, where R 0 = {ϵ} and R i = RR }{{ R}. i times The next theorem says a language is regular if and only if it can be described by regular expression. 1

Theorem 1.1. Regular expression is equivalent to NFA with ϵ-moves (and thus equivalent to DFA, NFA). Proof. (Regular expression NFA with ϵ-moves) We will prove, if L is accepted by a regular expression, then there exists an NFA with ϵ-moves M such that L = L(M). Basis: if r =, let M be an NFA with only initial state (no final state); if r = ϵ, let M be an NFA with one state, which is both the initial state and final state. If r = a, let M be an NFA with one initial state, and one final state, connected by an arrow a. For induction step, let r and s are two regular expressions equivalent to M 1, M 2 respectively, and assume both r and s have at most one final state. Expression r + s is equivalent to M defined as follows. Figure 1: ϵ-nfa accepting expression r + s Expression rs is equivalent to M defined as follows. Figure 2: ϵ-nfa accepting expression rs Expression r is equivalent to M defined as follows. Since in the last class, we see that NFA with ϵ-moves is equivalent to DFA. For the other direction, we need to prove DFA regular expression, 2

Figure 3: ϵ-nfa accepting expression r that is, given any DFA M, there exists a regular expression r such that L(M) is denoted by r. The idea is to define recursively like dynamic programming. Let M = (Q, Σ, δ, q, F Q), where Q = {q 1, q 2,..., q n }. We will recursively define regular expression R k ij, 1 i, j, k n and i, j could be greater than k. Let L(Rij) k be the set of all strings in Σ that take M from state i to state j without going through (enter and leave) any state numbered higher than k. By definition, Rij n is the set of all strings that take M from state i to state j. Thus, L(M) = j F L(Rn 1j). Let R = j F Rn 1j, and we have L(R) = L(M). Do induction on k. Let R k ij = R k 1 ij + R k 1 ik (Rk 1 kk ) R k 1 kj. In words, consider a path from state i to state j without going through any state numbered higher than k. There are two possibilities either the path does not going through any state numbered higher than k 1, or the path first goes from i to k (without going through any state numbered higher than k 1), then loops at state k (without going through any state numbered higher than k 1), and finally goes from state k to state j (without going through any state numbered higher than k 1). 3

For the induction basis, i.e., k = 0, let { Rij 0 a 1 +... + a s, if i j, = a 1 +... + a s + ϵ, if i = j, where a 1,..., a s are the labels of the arrows from i to j. Note that in above construction, the length of the regular expression could be exponential in n. 2 Two-way Finite Automaton A two-way finite automaton is a finite automaton where its head can move in both directions. It accepts the input string if it moves its head to the right end and enter a final state at the same time. Formally, a two-way deterministic finite automaton M = (Q, Σ, δ, q 0, F ), where δ : Q Σ Q {L, R}. In order to formally define the language accepted by M, let us define instantaneous description (ID) first. An instantaneous description is a snapshot of runtime DFA. An ID of a two-way finite automaton is a string wqx, where w, q Σ and q Q, which means the current state is q, and the head is on the first symbol of x. Define a relation M, where I M J means that J is the next ID of I. Specifically, if I = a 1 a i 1 qa i a n, i > 1, then J = a 1 a i pa i+1 a n if δ(q, a i ) = (p, R). J = a 1 a i 2 pa i 1 a n if δ(q, a i ) = (p, L). 4

Figure 4: Instantaneous Description of 2-DFA If i = 1 and δ(q, a 1 ) = (p, L), then the string is rejected. Let M denote the reflexive transitive closure of M, that is, I M J if J can be reached from I by applying M any number of times (including zero times). Let w Σ be the input string, then L(M) = {w Σ : q 0 w M wp for some p F }. Is two-way DFA strictly stronger than DFA? The answer is not so obvious. In the next lecture, we will prove that two-way DFA and DFA are in fact equivalent. 5