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

Similar documents
CS 455/555: Mathematical preliminaries

Regular Expressions. Definitions Equivalence to Finite Automata

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

CS 154, Lecture 3: DFA NFA, Regular Expressions

Finite Automata and Regular languages

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Sri vidya college of engineering and technology

Computational Theory

CS 154. Finite Automata, Nondeterminism, Regular Expressions

The Pumping Lemma and Closure Properties

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

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

Lecture 3: Nondeterministic Finite Automata

V Honors Theory of Computation

CS 455/555: Finite automata

Non-deterministic Finite Automata (NFAs)

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

Regular Expression Unit 1 chapter 3. Unit 1: Chapter 3

1 More finite deterministic automata

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

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

Regular Expressions and Language Properties

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

Properties of Regular Languages. BBM Automata Theory and Formal Languages 1

Closure under the Regular Operations

CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

Before we show how languages can be proven not regular, first, how would we show a language is regular?

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,

Inf2A: Converting from NFAs to DFAs and Closure Properties

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

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

Theory of Computation (II) Yijia Chen Fudan University

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

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

Proving languages to be nonregular

3515ICT: Theory of Computation. Regular languages

CS243, Logic and Computation Nondeterministic finite automata

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

Decidability (What, stuff is unsolvable?)

Theory of Computation (I) Yijia Chen Fudan University

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

Formal Languages. We ll use the English language as a running example.

Tasks of lexer. CISC 5920: Compiler Construction Chapter 2 Lexical Analysis. Tokens and lexemes. Buffering

CSE 105 THEORY OF COMPUTATION

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

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

THEORY OF COMPUTATION (AUBER) EXAM CRIB SHEET

UNIT-III REGULAR LANGUAGES

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

} Some languages are Turing-decidable A Turing Machine will halt on all inputs (either accepting or rejecting). No infinite loops.

Foundations of

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

CSE 105 THEORY OF COMPUTATION. Spring 2018 review class

Nondeterministic Finite Automata

CSci 311, Models of Computation Chapter 4 Properties of Regular Languages

Theory of Languages and Automata

Constructions on Finite Automata

Assignment #2 COMP 3200 Spring 2012 Prof. Stucki

CSE 105 Homework 1 Due: Monday October 9, Instructions. should be on each page of the submission.

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

COM364 Automata Theory Lecture Note 2 - Nondeterminism

Chapter Five: Nondeterministic Finite Automata

Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

Lecture 2: Connecting the Three Models

CSE 105 THEORY OF COMPUTATION

CS 154 Introduction to Automata and Complexity Theory

Properties of Regular Languages (2015/10/15)

Büchi Automata and their closure properties. - Ajith S and Ankit Kumar

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

CSC236 Week 10. Larry Zhang

Chapter 3. Regular grammars

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

Unit 6. Non Regular Languages The Pumping Lemma. Reading: Sipser, chapter 1

Formal Languages. We ll use the English language as a running example.

Formal Languages, Automata and Models of Computation

Theory of computation: initial remarks (Chapter 11)

CPS 220 Theory of Computation REGULAR LANGUAGES

Nondeterministic finite automata

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

DM17. Beregnelighed. Jacob Aae Mikkelsen

Deterministic Finite Automaton (DFA)

Finite Automata and Regular Languages

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

Finite Automata Part Two

Chapter 6. Properties of Regular Languages

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

CSE 105 THEORY OF COMPUTATION

Comment: The induction is always on some parameter, and the basis case is always an integer or set of integers.

Context Free Language Properties

CSE 105 Theory of Computation Professor Jeanne Ferrante

Lecture 23 : Nondeterministic Finite Automata DRAFT Connection between Regular Expressions and Finite Automata

Constructions on Finite Automata

Foundations of Computer Science Lecture 23 Languages: What is Computation?

Introduction to the Theory of Computing

Lecture 4: More on Regexps, Non-Regular Languages

CPSC 421: Tutorial #1

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

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

UNIT II REGULAR LANGUAGES

Transcription:

Regular Expressions

Regular Languages Fundamental Question -- Cardinality Alphabet = Σ is finite Strings = Σ is countable Languages = P(Σ ) is uncountable # Finite Automata is countable -- Q Σ +1 transition functions -- 2 Q accepting states -- Q starting states Problem Characterize those Languages recognized by Finite Automata. Solution Regular Languages

Concatenation of Languages Definitions and Notation L 1 L 2 = {x y x L 1 and y L 2 } L 2 = L L L k = L L k 1 Examples L 1 = {0,1} L 2 = {a, b} L 1 L 2 = {0a, 0b, 1a 1b} L 2 L 1 = {a 0, b0, a1, b1} L 2 L 1 2 L 1 = {00, 01, 10, 11}

Kleene Closure Recursive Definition Base Cases: -- ε L where ε is the empty string -- ω L whenever ω L Recursive Step: -- ω L and υ L ωυ L Explicit Definitions L* = {x 1 x 2 x n x k L and n 0} L* = {ε} L L 2 = k 0 L k L+ = L L = L L 2 = k 1 L k

Kleene Closure (continued) Example 1 L= {0,1} L = all bit strings including the empty string Example 2 L = {10, 1} L = {ε, 1, 10, 11, 110, 101, } Example 3 φ = ε

Regular Expressions Regular Expressions Base Cases φ, ε, a (a ) Recursive Cases -- (r), r s, rs, r Languages for Regular Expressions (Interpretation) Base Cases -- L(φ) = φ, L(ε) = {ε}, L(a) = {a} Recursive Cases -- L((r)) = L(r) -- L(r s) = L(r) L(s) -- L(r s) = L(r) L(s) -- L(r ) = L(r)

Observations {ε} φ because L{ε} = L φ = Lφ ε = φ r + = rr * L(r + ) = L(r) + = L(r)L(r) * L(r r) = L(r) L(r) = L(r) -- Regular Expressions for a Language are NOT unique.

Examples of Regular Languages Examples L = (0 1) = {x x is any string of zeros and ones} L = (0 1) 01101(0 1) = {x x is any bitstring containing 01101} L = 0 1 2 = {x x contains zeros followed by ones followed by twos} L = 1 01 01 = {x x is a string with exactly two zeros} L = 1 (1 0 1 01 ) = {x x is a string an even number of zeros} Observations Regular expressions are not unique. A language can be represented by infinitely different regular expressions.

More Examples Dice -- Rules for Winning Σ = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} r = 7 11 4(2 3 5 6 8 9 10 12) 4 Programming Languages L = a b z D = 0 1 2 3 4 5 6 7 8 9 -- Identifier = L(L + D) -- Integer = D +

Rules for Languages Defined by Regular Expressions Rules r s = s r (r s) t = r (s t) r φ = r rφ = φ = φ r rε = r = ε r r(st) = (rs)t r(s t) = rs rt (r ) = r φ = ε = ε

Rules for that Fail for Languages Defined by Regular Expressions Inequalities rs sr r (st) (r s)(r t) (not a Boolean Algebra) (r s) r s (rs) r s Counterexamples r = {u u has only zeros} s = {v v has only ones}

Fundamental Theorem of Regular Languages Theorem 1: A language L can be recognized by a DFA if and only if L can be represented by a regular expression. Proof: See Diagrams! : Regular expressions DFA. Structural induction. Base Cases: φ : M has no accepting states. ε : Initial state accepting, all other states rejecting. a: M has three states: start state, accept a, reject everything else.

Recursive Steps: Union: Key ideas: Run machines simultaneously and nondeterministically. Build a new start state and transition simultaneously to M 1 and M 2. Concatenation: Key ideas: Follow M 1 with M 2, nondeterministically. For each transitions into accepting states of M 1, build a transition into the starting state of M 2. Star: Key ideas: Build a new transition from each accepting state, mimicking the transitions from the original starting state. Introduce a new starting state to accept ε. : DFA Regular expressions.

Base Cases φ ε a a

Union ε ε M 1 M 2

Concatenation M 1 M 2 ε ε

Kleene Closure ε ε ε ε M 1

: DFA Regular Expressions Algorithm: Basic Idea = Removing States 1. Create New Start State (No Transitions In / ε -Transition Out) 2. Create New Accepting State (ε -Transition In / No Transitions Out) 3. Create a Single Transition to and from Each State a. Collapse multiple transition between states by union b. Insert φ -transition where no transitions occur 4. Rip out state r by inserting new transitions from state p to state q R new (p,q) = R old (p,q) R(p,r)R(r,r) R(r,q) 5. Repeat Step 4 until only the Start and Accept States Remain

: DFA Regular Expressions (continued) Observations 1. Each step of the Algorithm Produces a Regular Expression. 2. At each step of the Algorithm, the New Machine Accepts Exactly the Same Language as the Original Machine. 3. The Final Machine Accepts a Regular Expression. Examples 2 States 3 States

Example 1 1 q 0 0,1 0 q 1

Example 2 q 0 1 0 p 0,1 r

Regular Languages and Finite State Automata Observations Regular Languages are easier to construct when order matters -- Keywords -- Spam -- Low Level Lexical Analysis Finite State Automata are easier to construct when order does not matter. -- Vending Machines

Regular Languages Definition A language L is called regular if L is the language represented by a regular expression or equivalently if L is the language accepted by a DFA. Theorem 2: Regular languages are closed under i,,,, c Proof: We proved this result for union, concatenation, and star in Theorem 1. Complement: If L(M ) = L, then L(M ) = L c, where F = Q F = F c. Intersection: If L(M ) = L 1 and L(N) = L 2, then L(M N ) = L 1 L 2 where F = F 1 F 2. Also follows by De Morgan s Laws since L 1 L 2 = ( c c L 1 L2 ) c. QED

A Non Regular Language Lemma: L = {0 n 1 n } is not regular. Proof: Suppose L is regular, and M is a DFA that recognizes L. Let M have p states, and consider the string 0 p +1 1 p+1. By the pigeonhole principle, M must be in the same state q at least twice during its traversal of the string 0 p +1. Thus M transitions from q back to q on some substring 0 k, k p +1. Therefore -- δ(0 r 0 k 0 p+1 r ) = δ(0 p+1 ) so M cannot distinguish between 0 p +1 and 0 p +k +1 ; M loses count! Hence δ( p+1+k 1 p +1 ) = δ(0 p+1 1 p+1 ) -- Contradiction.