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

Size: px
Start display at page:

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

Transcription

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

2 Expressions Weʼre used to using expressions to describe mathematical objects Example: the arithmetic expression (2*11)+20 describes the value 42 Expressions are useful because they are precise, compact, and (often) can be simplified using algebraic laws Regular expressions describe languages (sets of strings) over an alphabet 2

3 Regular Expressions The regular expressions over an alphabet Σ are defined inductively: Base cases: a is an r.e., for each a Σ ε is an r.e. is an r.e. Inductive cases: (R1. R2) is an r.e. when R1,R2 are r.e.ʼs (R1 + R2) is an r.e. when R1,R2 are r.e.ʼs (R*) is an r.e. when R is a r.e. Nothing else is an r.e. 3

4 The meaning of an r.e. Each r.e. corresponds to a language. Weʼll write L for the function that maps each r.e. to its corresponding language L[ a ] = {a} L[ ε ] = {ε} L[ ] = { } L[(p. q)] = L[p]. L[q] (concatenation) L[(p + q)] = L[p] L[q] (union) L[(p*) ] = L[p]* (0 or more from L[p]) 4

5 Examples 1. L[ ((a. (b*)) + c) ] = 2. L[ (((a + b). (a + b))*) ] = 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = 4. L[ (a. ) ] = 5

6 Examples 1. L[ ((a. (b*)) + c) ] = 2. L[ (((a + b). (a + b))*) ] = L1 = {a, ab, abb, abbb,, c} 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = 4. L[ (a. ) ] = 5

7 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = 4. L[ (a. ) ] = 5

8 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

9 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

10 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

11 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

12 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

13 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

14 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = 5

15 Examples 1. L[ ((a. (b*)) + c) ] = L1 = {a, ab, abb, abbb,, c} 2. L[ (((a + b). (a + b))*) ] = L2 = {ε, aa, ab, ba, abab, bbaa, baabbaabab, } 3. L[ ((( ε + b). ((a. b)*)). (ε + a)) ] = {ε, ab, abab, ababab, bab, baba, aba, } 4. L[ (a. ) ] = L4 ={ } 5

16 Common Shorthands Concatenation (.) is usually not written More precisely: written as juxtaposition We assign precedence to the operators and then omit parentheses if possible * groups most tightly, then., then + e.g., a+bc* means (a + (b.(c*))) Write R + for RR* (one or more from R) Write R k for RR...R k times (k from R) If our alphabet Σ = {a1,a2,...,an}, then we write Σ for the r.e. (a1+a an) 6

17 More compact examples L [(ε + 1)(01)*(ε + 0)] = L [Σ*001Σ* ] = (assuming Σ={0,1}) L [ ] = {w {0,1}* w starts and ends with the same symbol} L [ ] = {w {0,1}* w contains an odd number of 0s } 7

18 Simplifying r.e.s Just as for arithmetic expressions, r.e.s can be simplified by algebraic laws. Some useful laws: R + P = P + R R + = R Rε = R = εr R = = R * = ε 8

19 Simplifying r.e.s Just as for arithmetic expressions, r.e.s can be simplified by algebraic laws. Some useful laws: R + P = P + R R + = R Rε = R = εr R = = R * = ε See Hein and slides for more! 8

20 Practical uses for r.e.s Widely used for specifying text patterns typically with extended r.e. syntax for ASCII e.g., unix grep command %grep ^e[a-z]i[a-z]*a\$ /etc/dict/words -enigma epiblastema epiblema... eria e.g., lexical analyzer generation for compilers [A-Za-z_][A-Za-z_0-9]* describes format of identifiers in C programs 9

21 Regular Expressions and Regular Languages are equivalent! That is, they describe exactly the same class of languages (hence their names) Must prove this in two directions: Every r.e. defines a regular language Weʼve already done most of the work, so this shouldnʼt be too surprising Every regular language is defined by an r.e. This is harder 10

22 R is an r.e. => L(R) is regular Claim: For each r.e. R, we can construct an NFA N that recognizes L(R) We can then convert N to a DFA M recognizing L(R), so L(R) is regular Proof is by structural induction on R One case for each rule for constructing R Inductive hypothesis is: if claim is true for each sub-expression of R, then itʼs true for R itself 11

23 Proof Outline: Six Cases R = a for some a in Σ. Then L(R) = {a}. So... R = ε. Then L(R) = {ε}. So... R =. Then L(R) = {}. So... R = R 1 + R2. Then L(R) = L(R1) L(R2). - By the inductive hypothesis we can construct NFAʼs N1 recognizing L(R1) and N2 recognizing L(R2). So... R = R 1. R2. Then L(R) = L(R1). L(R2). - By the inductive hypothesis... R = (R 1)*. Then L(R) = (L(R1))*. By... 12

24 L is recognized by a DFA an r.e. R such that L(R) = L Challenge: start with an arbitrary DFA and find a corresponding r.e. Thereʼs more than one way to do this (see IALC) 1st idea: use generalization of NFAs in which transitions can be labeled by r.e.s. 13

25 NFA r.e. by State Elimination Allow the labels on an NFAʼs transitions to be r.e.s rather than just single symbols. Any string that is in the language of the r.e. enables the transition. Remove states one at a time, keeping language the same by making labels more complex Ultimately, machine has one transition; label is desired r.e. for original machine 14

26 Example 0. If there is no arc from state i to state j, imagine one with label. 1. If the initial state has a selftransition, create a new initial state with a single ε-transition to the old initial state. 2. Create a new final state with a ε-transition to it from each of the old final states. 15

27 Example 3. For each pair of states i, j with more than one transition from i to j, replace them all by a single transition labeled with the r.e. that is the sum of the old labels. 4. Eliminate one state at a time until the only states that remain are the start state and the final state: 16

28 How to Eliminate State k For each pair of nodes i, j (i k, j k), label the transition from i to j with: (i, j ) + (i, k )(k, k )*(k, j ) Remove state k and all its transitions. 17

29 How to Eliminate State k For each pair of nodes i, j (i k, j k), label the transition from i to j with: (i, j ) + (i, k )(k, k )*(k, j ) Remove state k and all its transitions. + 17

30 How to Eliminate State k For each pair of nodes i, j (i k, j k), label the transition from i to j with: (i, j ) + (i, k )(k, k )*(k, j ) Remove state k and all its transitions. 17

31 The Algorithm from Hein: Finite Automaton to Regular Expression (11.5) Assume that we have a DFA or an NFA. Perform the following steps: 1. Create a new start state s, and draw a new edge labeled with " from s to the original start state. 2. Create a new final state f, and draw new edges labeled with " from all the original final states to f. 3. For each pair of states i and j that have more than one edge from i to j, replace all the edges from i to j by a single edge labeled with the regular expression formed by the sum of the labels on each of the edges from i to j. 4. Construct a sequence of new machines by eliminating one state at a time until the only states remaining are s and f. As each state is eliminated, a new machine is constructed from the previous machine as follows: Eliminate State k 18

32 The Algorithm from Hein: Finite Automaton to Regular Expression (11.5) Assume that we have a DFA or an NFA. Perform the following steps: 1. Create a new start state s, and draw a new edge labeled with " from s to the original start state. 2. Create a new final state f, and draw new edges labeled with " from all the original final states to f. 3. For each pair of states i and j that have more than one edge from i to j, replace all the edges from i to j by a single edge labeled with the regular expression formed by the sum of the labels on each of the edges from i to j. 4. Construct a sequence of new machines by eliminating one state at a time until the only states remaining are s and f. As each state is eliminated, a new machine is constructed from the previous machine as follows: Eliminate State k ε ε 18

33 Eliminate State k For convenience we ll let old(i, j) denote the label on edge (i, j) of the current machine. If there is no edge (i, j), then set old(i, j) =!. Now for each pair of edges (i, k) and (k, j), where i! k and j! k, calculate a new edge label, new(i, j), as follows: new(i, j) = old(i, j) + old(i, k) old(k, k)* old(k, j). For all other edges (i, j) where i! k and j! k, set new(i, j) = old(i, j). The states of the new machine are those of the current machine with state k eliminated. The edges of the new machine are the edges (i, j) for which label new(i, j) has been calculated. Now s and f are the two remaining states. If there is an edge (s, f), then the regular expression new(s, f) represents the language of the original automaton. If there is no edge (s, f), then the language of the original automaton is empty, which is signified by the regular expression!. 19

34 Essentially the same algorithm is in Hopcroft et. al

35 From DFA to r.e. by paths 2nd idea: r.e.s correspond to paths in DFA The language recognized by a DFA M is the set of strings accepted by M. Each accepted string defines a path through M from the start state to some final state. Show how to construct an r.e. corresponding to any path in the DFA, using induction. Combine appropriate path r.e.s to build an r.e. for the accepting paths 21

36 Inductive path definitions Assume Mʼs states are named 1,2,...,n. Define Rij = an r.e. whose language is {w w drives M from state i to state j} If start state = s and final states = {f1,f2,...,fm }, then r.e. for M is R = Rsf 1 + R sf Rsf m To set-up the induction: let Rij (k) = an r.e. whose language is {w w drives M from state i to state j without going through any intermediate state > k} Note that path endponts i,j are allowed to be > k Weʼll construct Rij (k) by induction on k. Rij = Rij (n) represents all paths from i to j 22

37 i j State number k 1 A path from state i to state j that does not pass through any state > k 23

38 Base case: define R (0) Since all states are numbered 1 or above, the paths in this case must have no intermediate states at all. If i j, path must have length 1 and be a single transition from state i to state j Here Rij (0) = + a1 + a an, where a1,..., an are the labels of all transitions from state i to state j If i = j, path may have length 0 or 1 Here Rii (0) = ε + a1 + a an, where a1,...,an are the labels of all transitions from state i to itself 24

39 Inductive step: define R (k) using R (k-1) There are two possible cases for a path: 1. The path does not go through state k at all Then the path is already in Rij (k-1) 2. The path goes through state k at least once Then we can break it into three pieces: - a piece from state i to state k, described by Rik (k-1) - zero or more pieces going from state k back to state k (using only states lower than k), described by (Rkk (k-1) )* - a piece from state k to state j, described by Rkj (k-1) The overall path is given by Rik (k-1) (Rkk (k-1) )* Rkj (k-1) So the full r.e. is Rij (k-1) + Rik (k-1) (Rkk (k-1) )* Rkj (k-1) 25

40 For the details See Hopcroft et al. Theorem

41 Example: DFA to r.e. R = R12 (3) = R12 (2) + R13 (2) (R33 (2) )*R32 (2) R = R12 (2) = R12 (1) + R12 (1) (R22 (1) )*R22 (1)!! R32 (2) = b 1 2 a 3 a,b a,b R12 (1) = R12 (0) + R11 (0) (R11 (0) )*R12 (0) = b + εε*b = b R22 (1) = R22 (0) + R21 (0) (R11 (0) )*R12 (0)!! R21 (0) = R22 (1) = R22 (0) = (ε + a + b) = (a + b) R = b + b(a + b)*(a + b) = b(a+b)* (why?) 27

42 Basic algebraic laws (1) 1. Union properties 1.1. R + T = T + R 1.2. R + = R 1.3. R + R = R 1.4. (R + S) + T = R + (S + T) R S L(R) = L(S) 2. Concatenation properties 2.1. R = R = 2.2. Rε = εr = R 2.3. (RS)T = R(ST) 3. Distributive properties 3.1. R(S + T) = RS + RT 3.2. (S + T)R = SR + TR 28

43 Basic algebraic laws (2) 4. Kleene-* properties 4.1. R* = ε + RR* = ε + R*R 4.2. If R + ST T then S*R T 4.3. If R + TS T then RS* T (We don t normally use these laws directly) R S L(R) L(S) R S R + S = S R = S R S and S R 29

44 Useful Derived Properties 5. Properties derivable from previous laws 5.1. * = ε* = ε 5.2. R* = R*R* = (R*)* = R + R* 5.3. R* = ε + R* = (ε + R)* = (ε + R)R* 5.4. R* = (R R k )* for any k R* = ε + R R k-1 + R k R* for any k R*R = RR* 5.7. (R + S)* = (R* + S*)* = (R*S*)* = (R*S)*R* = R*(SR*)* 5.8. R(SR)* = (RS)*R 5.9. (R*S)* = ε + (R + S)*S 5.10.(RS*)* = ε + R (R + S)* 30

45 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

46 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

47 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

48 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

49 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

50 Use laws to prove equalities Example: prove that a*(b + ab*) = b + aa*b*. Proof: a*(b+ab*) = (by 3.1) a*b + a*ab* = (by 4.1) (ε+aa*)b + a*ab* = (by 3.1) εb + aa*b + a*ab* = (by 2.2) b + aa*b + a*ab* = (by 5.6) b + aa*b + aa*b* = (by 3.1) b + aa*(b+b*) = (by 5.2) b + aa*b* 31

### Finite Automata and Formal Languages

Finite Automata and Formal Languages TMV26/DIT32 LP4 2 Lecture 6 April 5th 2 Regular expressions (RE) are an algebraic way to denote languages. Given a RE R, it defines the language L(R). Actually, they

### Finite Automata and Formal Languages TMV026/DIT321 LP4 2012

Finite Automata and Formal Languages TMV26/DIT32 LP4 22 Lecture 7 Ana Bove March 27th 22 Overview of today s lecture: Regular Expressions From FA to RE Regular Expressions Regular expressions (RE) are

### Author: Vivek Kulkarni ( )

Author: Vivek Kulkarni ( vivek_kulkarni@yahoo.com ) Chapter-3: Regular Expressions Solutions for Review Questions @ Oxford University Press 2013. All rights reserved. 1 Q.1 Define the following and give

### Regular Expressions. Definitions Equivalence to Finite Automata

Regular Expressions Definitions Equivalence to Finite Automata 1 RE s: Introduction Regular expressions are an algebraic way to describe languages. They describe exactly the regular languages. If E is

### CS21 Decidability and Tractability

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

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

CMSC 330: Organization of Programming Languages Last Lecture Languages Sets of strings Operations on languages Finite Automata Regular expressions Constants Operators Precedence CMSC 330 2 Clarifications

### This Lecture will Cover...

Last Lecture Covered... DFAs, NFAs, -NFAs and the equivalence of the language classes they accept Last Lecture Covered... This Lecture will Cover... Introduction to regular expressions and regular languages

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

: Organization of Programming Languages Theory of Regular Expressions Finite Automata Previous Course Review {s s defined} means the set of string s such that s is chosen or defined as given s A means

### UNIT II REGULAR LANGUAGES

1 UNIT II REGULAR LANGUAGES Introduction: A regular expression is a way of describing a regular language. The various operations are closure, union and concatenation. We can also find the equivalent regular

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

How do regular expressions work? CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata What we ve learned What regular expressions are What they can express, and cannot

### UNIT-III REGULAR LANGUAGES

Syllabus R9 Regulation REGULAR EXPRESSIONS UNIT-III REGULAR LANGUAGES Regular expressions are useful for representing certain sets of strings in an algebraic fashion. In arithmetic we can use the operations

### Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions

Automata and Formal Languages - CM0081 Finite Automata and Regular Expressions Andrés Sicard-Ramírez Universidad EAFIT Semester 2018-2 Introduction Equivalences DFA NFA -NFA RE Finite Automata and Regular

### Recap from Last Time

Regular Expressions Recap from Last Time Regular Languages A language L is a regular language if there is a DFA D such that L( D) = L. Theorem: The following are equivalent: L is a regular language. There

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

Second Part of Regular Expressions Equivalence with Finite Automata September 11, 2013 Lemma 1.60 If a language is regular then it is specified by a regular expression Proof idea: For a given regular language

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

Examples of Regular Expressions 1. 0 10, L(0 10 ) = {w w contains exactly a single 1} 2. Σ 1Σ, L(Σ 1Σ ) = {w w contains at least one 1} 3. Σ 001Σ, L(Σ 001Σ ) = {w w contains the string 001 as a substring}

### CS 154, Lecture 3: DFA NFA, Regular Expressions

CS 154, Lecture 3: DFA NFA, Regular Expressions Homework 1 is coming out Deterministic Finite Automata Computation with finite memory Non-Deterministic Finite Automata Computation with finite memory and

### Nondeterministic Finite Automata and Regular Expressions

Nondeterministic Finite Automata and Regular Expressions CS 2800: Discrete Structures, Spring 2015 Sid Chaudhuri Recap: Deterministic Finite Automaton A DFA is a 5-tuple M = (Q, Σ, δ, q 0, F) Q is a finite

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

Regular Expressions Regular Languages Fundamental Question -- Cardinality Alphabet = Σ is finite Strings = Σ is countable Languages = P(Σ ) is uncountable # Finite Automata is countable -- Q Σ +1 transition

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

Tasks of lexer CISC 5920: Compiler Construction Chapter 2 Lexical Analysis Arthur G. Werschulz Fordham University Department of Computer and Information Sciences Copyright Arthur G. Werschulz, 2017. All

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

CS 121, Section 2 Week of September 16, 2013 1 Concept Review 1.1 Overview In the past weeks, we have examined the finite automaton, a simple computational model with limited memory. We proved that DFAs,

### Automata: a short introduction

ILIAS, University of Luxembourg Discrete Mathematics II May 2012 What is a computer? Real computers are complicated; We abstract up to an essential model of computation; We begin with the simplest possible

### Foundations of

91.304 Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.3: Regular Expressions) David Martin dm@cs.uml.edu d with some modifications by Prof. Karen Daniels, Spring 2012

### FABER Formal Languages, Automata. Lecture 2. Mälardalen University

CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2010 1 Content Languages, g Alphabets and Strings Strings & String Operations Languages & Language Operations

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

CS 154 Finite Automata vs Regular Expressions, Non-Regular Languages Deterministic Finite Automata Computation with finite memory Non-Deterministic Finite Automata Computation with finite memory and guessing

### Deterministic Finite Automaton (DFA)

1 Lecture Overview Deterministic Finite Automata (DFA) o accepting a string o defining a language Nondeterministic Finite Automata (NFA) o converting to DFA (subset construction) o constructed from a regular

### CSE443 Compilers. Dr. Carl Alphonce 343 Davis Hall

CSE443 Compilers Dr. Carl Alphonce alphonce@buffalo.edu 343 Davis Hall http://www.cse.buffalo.edu/faculty/alphonce/sp17/cse443/index.php https://piazza.com/class/iybn4ndqa1s3ei Syllabus Posted on website

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

Regular Expressions Problem Problem Set Set Four Four is is due due using using a late late period period in in the the box box up up front. front. Concatenation The concatenation of two languages L 1

### Sri vidya college of engineering and technology

Unit I FINITE AUTOMATA 1. Define hypothesis. The formal proof can be using deductive proof and inductive proof. The deductive proof consists of sequence of statements given with logical reasoning in order

### Regular Expressions and Language Properties

Regular Expressions and Language Properties Mridul Aanjaneya Stanford University July 3, 2012 Mridul Aanjaneya Automata Theory 1/ 47 Tentative Schedule HW #1: Out (07/03), Due (07/11) HW #2: Out (07/10),

### Automata Theory CS F-08 Context-Free Grammars

Automata Theory CS411-2015F-08 Context-Free Grammars David Galles Department of Computer Science University of San Francisco 08-0: Context-Free Grammars Set of Terminals (Σ) Set of Non-Terminals Set of

### CSCI 340: Computational Models. Regular Expressions. Department of Computer Science

CSCI 340: Computational Models Regular Expressions Chapter 4 Department of Computer Science Yet Another New Method for Defining Languages Given the Language: L 1 = {x n for n = 1 2 3...} We could easily

### Theory of computation: initial remarks (Chapter 11)

Theory of computation: initial remarks (Chapter 11) For many purposes, computation is elegantly modeled with simple mathematical objects: Turing machines, finite automata, pushdown automata, and such.

### CMPSCI 250: Introduction to Computation. Lecture #23: Finishing Kleene s Theorem David Mix Barrington 25 April 2013

CMPSCI 250: Introduction to Computation Lecture #23: Finishing Kleene s Theorem David Mix Barrington 25 April 2013 Finishing Kleene s Theorem A Normal Form for λ-nfa s Building λ-nfa s by Induction Why

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

Unit 1: Chapter 3 (Regular Expression (RE) and Language) In previous lectures, we have described the languages in terms of machine like description-finite automata (DFA or NFA). Now we switch our attention

### Regular Expressions [1] Regular Expressions. Regular expressions can be seen as a system of notations for denoting ɛ-nfa

Regular Expressions [1] Regular Expressions Regular expressions can be seen as a system of notations for denoting ɛ-nfa They form an algebraic representation of ɛ-nfa algebraic : expressions with equations

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC 330 Spring 2017 1 How do regular expressions work? What we ve learned What regular expressions are What they

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

CMSC 330: Organization of Programming Languages Regular Expressions and Finite Automata CMSC330 Spring 2018 1 How do regular expressions work? What we ve learned What regular expressions are What they

### Finite-State Machines (Automata) lecture 12

Finite-State Machines (Automata) lecture 12 cl a simple form of computation used widely one way to find patterns 1 A current D B A B C D B C D A C next 2 Application Fields Industry real-time control,

### CS 133 : Automata Theory and Computability

CS 133 : Automata Theory and Computability Lecture Slides 1 Regular Languages and Finite Automata Nestine Hope S. Hernandez Algorithms and Complexity Laboratory Department of Computer Science University

### CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages Theory of Regular Expressions DFAs and NFAs Reminders Project 1 due Sep. 24 Homework 1 posted Exam 1 on Sep. 25 Exam topics list posted Practice homework

### CS Automata, Computability and Formal Languages

Automata, Computability and Formal Languages Luc Longpré faculty.utep.edu/longpre 1 - Pg 1 Slides : version 3.1 version 1 A. Tapp version 2 P. McKenzie, L. Longpré version 2.1 D. Gehl version 2.2 M. Csűrös,

### Uses of finite automata

Chapter 2 :Finite Automata 2.1 Finite Automata Automata are computational devices to solve language recognition problems. Language recognition problem is to determine whether a word belongs to a language.

### Chapter 4. Regular Expressions. 4.1 Some Definitions

Chapter 4 Regular Expressions 4.1 Some Definitions Definition: If S and T are sets of strings of letters (whether they are finite or infinite sets), we define the product set of strings of letters to be

### Computational Theory

Computational Theory Finite Automata and Regular Languages Curtis Larsen Dixie State University Computing and Design Fall 2018 Adapted from notes by Russ Ross Adapted from notes by Harry Lewis Curtis Larsen

### Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro Diniz

Compiler Design Spring 2010 Lexical Analysis Sample Exercises and Solutions Prof. Pedro Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292 pedro@isi.edu

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

CS:4330 Theory of Computation Spring 2018 Regular Languages Finite Automata and Regular Expressions Haniel Barbosa Readings for this lecture Chapter 1 of [Sipser 1996], 3rd edition. Sections 1.1 and 1.3.

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

Formal Languages We ll use the English language as a running example. Definitions. A string is a finite set of symbols, where each symbol belongs to an alphabet denoted by. Examples. The set of all strings

### Regular expressions and Kleene s theorem

and Kleene s theorem Informatics 2A: Lecture 5 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 29 September 2016 1 / 21 1 More closure properties of regular languages Operations

### CS21 Decidability and Tractability

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

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

TAFL 1 (ECS-403) Unit- II 2.1 Regular Expression: 2.1.1 The Operators of Regular Expressions: 2.1.2 Building Regular Expressions 2.1.3 Precedence of Regular-Expression Operators 2.1.4 Algebraic laws for

### Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design Spring 2011 Lexical Analysis Sample Exercises and Solutions Prof. Pedro C. Diniz USC / Information Sciences Institute 4676 Admiralty Way, Suite 1001 Marina del Rey, California 90292 pedro@isi.edu

### Theory of computation: initial remarks (Chapter 11)

Theory of computation: initial remarks (Chapter 11) For many purposes, computation is elegantly modeled with simple mathematical objects: Turing machines, finite automata, pushdown automata, and such.

### Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Lecture 9 Ana Bove April 19th 2018 Recap: Regular Expressions Algebraic representation of (regular) languages; R, S ::= a R + S RS R......

### Regular expressions and Kleene s theorem

and Informatics 2A: Lecture 5 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 25 September, 2014 1 / 26 1 More closure properties of regular languages Operations on languages

### CS5371 Theory of Computation. Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression)

CS5371 Theory of Computation Lecture 5: Automata Theory III (Non-regular Language, Pumping Lemma, Regular Expression) Objectives Prove the Pumping Lemma, and use it to show that there are non-regular languages

### 3515ICT: Theory of Computation. Regular languages

3515ICT: Theory of Computation Regular languages Notation and concepts concerning alphabets, strings and languages, and identification of languages with problems (H, 1.5). Regular expressions (H, 3.1,

### Formal Languages and Automata

Formal Languages and Automata 5 lectures for 2016-17 Computer Science Tripos Part IA Discrete Mathematics by Ian Leslie c 2014,2015 AM Pitts; 2016,2017 IM Leslie (minor tweaks) What is this course about?

### Introduction to Language Theory and Compilation: Exercises. Session 2: Regular expressions

Introduction to Language Theory and Compilation: Exercises Session 2: Regular expressions Regular expressions (RE) Finite automata are an equivalent formalism to regular languages (for each regular language,

### Computational Models Lecture 2 1

Computational Models Lecture 2 1 Handout Mode Ronitt Rubinfeld and Iftach Haitner. Tel Aviv University. March 16/18, 2015 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice

### Closure under the Regular Operations

September 7, 2013 Application of NFA Now we use the NFA to show that collection of regular languages is closed under regular operations union, concatenation, and star Earlier we have shown this closure

### Formal Languages, Automata and Models of Computation

CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 5 School of Innovation, Design and Engineering Mälardalen University 2011 1 Content - More Properties of Regular Languages (RL)

### FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY THE PUMPING LEMMA FOR REGULAR LANGUAGES and REGULAR EXPRESSIONS TUESDAY Jan 21 WHICH OF THESE ARE REGULAR? B = {0 n 1 n n 0} C = { w w has equal number

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

Formal Languages We ll use the English language as a running example. Definitions. A string is a finite set of symbols, where each symbol belongs to an alphabet denoted by Σ. Examples. The set of all strings

### jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text

On the menu today jflap demo Regular expressions Pumping lemma Turing Machines Sections 12.4 and 12.5 in the text 1 jflap Demo jflap: Useful tool for creating and testing abstract machines Finite automata,

### Figure 1: NFA N. Figure 2: Equivalent DFA N obtained through function nfa2dfa

CS 3100 Models of Computation Fall 2011 FIRST MIDTERM CLOSED BOOK 100 points I ve standardized on @ for representing Epsilons in all my figures as well as my code (liked equally by dot and our Python programs).

### Text Search and Closure Properties

Text Search and Closure Properties CSCI 330 Formal Languages and Automata Theory Siu On CHAN Fall 208 Chinese University of Hong Kong /28 Text Search grep program grep -E regex file.txt Searches for an

### Text Search and Closure Properties

Text Search and Closure Properties CSCI 3130 Formal Languages and Automata Theory Siu On CHAN Chinese University of Hong Kong Fall 2017 1/30 Text Search 2/30 grep program grep -E regexp file.txt Searches

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

Automata & languages A primer on the Theory of Computation Laurent Vanbever www.vanbever.eu ETH Zürich (D-ITET) September, 24 2015 Last week was all about Deterministic Finite Automaton We saw three main

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

CSE 5 Homework Due: Monday October 9, 7 Instructions Upload a single file to Gradescope for each group. should be on each page of the submission. All group members names and PIDs Your assignments in this

### FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

15-453 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY REVIEW for MIDTERM 1 THURSDAY Feb 6 Midterm 1 will cover everything we have seen so far The PROBLEMS will be from Sipser, Chapters 1, 2, 3 It will be

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

Closure Properties of Regular Languages Union, Intersection, Difference, Concatenation, Kleene Closure, Reversal, Homomorphism, Inverse Homomorphism Closure Properties Recall a closure property is a statement

### More Properties of Regular Languages

More Properties of Regular anguages 1 We have proven Regular languages are closed under: Union Concatenation Star operation Reverse 2 Namely, for regular languages 1 and 2 : Union 1 2 Concatenation Star

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

Incorrect reasoning about RL Since L 1 = {w w=a n, n N}, L 2 = {w w = b n, n N} are regular, therefore L 1 L 2 = {w w=a n b n, n N} is regular If L 1 is a regular language, then L 2 = {w R w L 1 } is regular,

### Computational Models Lecture 2 1

Computational Models Lecture 2 1 Handout Mode Iftach Haitner. Tel Aviv University. October 30, 2017 1 Based on frames by Benny Chor, Tel Aviv University, modifying frames by Maurice Herlihy, Brown University.

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

Regular Languages Andreas Karwath & Malte Helmert 1 Overview Deterministic finite automata Regular languages Nondeterministic finite automata Closure operations Regular expressions Nonregular languages

### Regular Expressions Kleene s Theorem Equation-based alternate construction. Regular Expressions. Deepak D Souza

Regular Expressions Deepak D Souza Department of Computer Science and Automation Indian Institute of Science, Bangalore. 16 August 2012 Outline 1 Regular Expressions 2 Kleene s Theorem 3 Equation-based

### Finite Automata and Regular Languages

Finite Automata and Regular Languages Topics to be covered in Chapters 1-4 include: deterministic vs. nondeterministic FA, regular expressions, one-way vs. two-way FA, minimization, pumping lemma for regular

### In English, there are at least three different types of entities: letters, words, sentences.

Chapter 2 Languages 2.1 Introduction In English, there are at least three different types of entities: letters, words, sentences. letters are from a finite alphabet { a, b, c,..., z } words are made up

### GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I

GEETANJALI INSTITUTE OF TECHNICAL STUDIES, UDAIPUR I Internal Examination 2017-18 B.Tech III Year VI Semester Sub: Theory of Computation (6CS3A) Time: 1 Hour 30 min. Max Marks: 40 Note: Attempt all three

### CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

CS311 Computational Structures More about PDAs & Context-Free Languages Lecture 9 Andrew P. Black Andrew Tolmach 1 Three important results 1. Any CFG can be simulated by a PDA 2. Any PDA can be simulated

### Lecture 11 Context-Free Languages

Lecture 11 Context-Free Languages COT 4420 Theory of Computation Chapter 5 Context-Free Languages n { a b : n n { ww } 0} R Regular Languages a *b* ( a + b) * Example 1 G = ({S}, {a, b}, S, P) Derivations:

### Exam 1 CSU 390 Theory of Computation Fall 2007

Exam 1 CSU 390 Theory of Computation Fall 2007 Solutions Problem 1 [10 points] Construct a state transition diagram for a DFA that recognizes the following language over the alphabet Σ = {a, b}: L 1 =

### TDDD65 Introduction to the Theory of Computation

TDDD65 Introduction to the Theory of Computation Lecture 2 Gustav Nordh, IDA gustav.nordh@liu.se 2012-08-31 Outline - Lecture 2 Closure properties of regular languages Regular expressions Equivalence of

### Algorithms for NLP

Regular Expressions Chris Dyer Algorithms for NLP 11-711 Adapted from materials from Alon Lavie Goals of Today s Lecture Understand the properties of NFAs with epsilon transitions Understand concepts and

### COMP4141 Theory of Computation

COMP4141 Theory of Computation Lecture 4 Regular Languages cont. Ron van der Meyden CSE, UNSW Revision: 2013/03/14 (Credits: David Dill, Thomas Wilke, Kai Engelhardt, Peter Höfner, Rob van Glabbeek) Regular

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

Automata Theory Lecture on Discussion Course of CS2 This Lecture is about Mathematical Models of Computation. Why Should I Care? - Ways of thinking. - Theory can drive practice. - Don t be an Instrumentalist.

### Administrivia. Test I during class on 10 March. Bottom-Up Parsing. Lecture An Introductory Example

Administrivia Test I during class on 10 March. Bottom-Up Parsing Lecture 11-12 From slides by G. Necula & R. Bodik) 2/20/08 Prof. Hilfinger CS14 Lecture 11 1 2/20/08 Prof. Hilfinger CS14 Lecture 11 2 Bottom-Up

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

Introduction to the Theory of Computation Automata 1VO + 1PS Lecturer: Dr. Ana Sokolova http://cs.uni-salzburg.at/~anas/ Setup and Dates Lectures and Instructions 23.10. 3.11. 17.11. 24.11. 1.12. 11.12.

### Nondeterministic Finite Automata

Nondeterministic Finite Automata Not A DFA Does not have exactly one transition from every state on every symbol: Two transitions from q 0 on a No transition from q 1 (on either a or b) Though not a DFA,

### Equivalence of Regular Expressions and FSMs

Equivalence of Regular Expressions and FSMs Greg Plaxton Theory in Programming Practice, Spring 2005 Department of Computer Science University of Texas at Austin Regular Language Recall that a language

### Non-Deterministic Finite Automata

Slides modified Yishay Mansour on modification by Benny Chor, based on original slides by Maurice Herlihy, Brown University. p. 8 Non-Deterministic Finite Automata 0,1 0,1 0 0,ε q q 1 q 2 3 1 q 4 an NFA

### Closure Properties of Context-Free Languages. Foundations of Computer Science Theory

Closure Properties of Context-Free Languages Foundations of Computer Science Theory Closure Properties of CFLs CFLs are closed under: Union Concatenation Kleene closure Reversal CFLs are not closed under

### Context-Free Grammars (and Languages) Lecture 7

Context-Free Grammars (and Languages) Lecture 7 1 Today Beyond regular expressions: Context-Free Grammars (CFGs) What is a CFG? What is the language associated with a CFG? Creating CFGs. Reasoning about

### Kleene Algebras and Algebraic Path Problems

Kleene Algebras and Algebraic Path Problems Davis Foote May 8, 015 1 Regular Languages 1.1 Deterministic Finite Automata A deterministic finite automaton (DFA) is a model of computation that can simulate

### CS375 Midterm Exam Solution Set (Fall 2017)

CS375 Midterm Exam Solution Set (Fall 2017) Closed book & closed notes October 17, 2017 Name sample 1. (10 points) (a) Put in the following blank the number of strings of length 5 over A={a, b, c} that

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

Introduction to the Theory of Computation Automata 1VO + 1PS Lecturer: Dr. Ana Sokolova http://cs.uni-salzburg.at/~anas/ Setup and Dates Lectures Tuesday 10:45 pm - 12:15 pm Instructions Tuesday 12:30

### Closure Properties of Regular Languages

Closure Properties of Regular Languages Lecture 13 Section 4.1 Robb T. Koether Hampden-Sydney College Wed, Sep 21, 2016 Robb T. Koether (Hampden-Sydney College) Closure Properties of Regular Languages

### CS 322 D: Formal languages and automata theory

CS 322 D: Formal languages and automata theory Tutorial NFA DFA Regular Expression T. Najla Arfawi 2 nd Term - 26 Finite Automata Finite Automata. Q - States 2. S - Alphabets 3. d - Transitions 4. q -