CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Properties.

Slides:



Advertisements
Similar presentations
Finite-state Recognizers
Advertisements

CSC 361NFA vs. DFA1. CSC 361NFA vs. DFA2 NFAs vs. DFAs NFAs can be constructed from DFAs using transitions: Called NFA- Suppose M 1 accepts L 1, M 2 accepts.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Deterministic Finite Automata (DFA)
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
NFAs Sipser 1.2 (pages 47–54). CS 311 Fall Recall… Last time we showed that the class of regular languages is closed under: –Complement –Union.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY (For next time: Read Chapter 1.3 of the book)
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Fall 2006Costas Busch - RPI1 Regular Expressions.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Regular.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
1 Languages and Finite Automata or how to talk to machines...
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
Lecture 7 Sept 22, 2011 Goals: closure properties regular expressions.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Nondeterminism.
Fall 2006Costas Busch - RPI1 Properties of Regular Languages.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Limitations.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Lecture 4UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 4.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 A Single Final State for Finite Accepters. 2 Observation Any Finite Accepter (NFA or DFA) can be converted to an equivalent NFA with a single final.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA minimization.
Fall 2004COMP 3351 Regular Expressions. Fall 2004COMP 3352 Regular Expressions Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong DFA to regular.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Closure.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to DFA.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Text search.
CSCI 2670 Introduction to Theory of Computing September 1, 2005.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong NFA to.
Regular Expressions Costas Busch - LSU.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
CSCI 3130: Formal languages and automata theory Tutorial 3 Chin.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Pushdown.
INHERENT LIMITATIONS OF COMPUTER PROGRAMS CSci 4011.
1 Some Properties of Regular Languages. 2 Properties Concatenation:Star: Union: Are regular Languages For regular languages and.
P Symbol Q E(Q) a b a b a b Convert to a DFA: Start state: Final States:
Lecture 15: Theory of Automata:2014 Finite Automata with Output.
Nondeterminism The Chinese University of Hong Kong Fall 2011
Languages.
Properties of Regular Languages
PROPERTIES OF REGULAR LANGUAGES
CSE 105 theory of computation
Formal Language & Automata Theory
Single Final State for NFA
Intro to Theory of Computation
More on DFA minimization and DFA equivalence
CSE322 PROPERTIES OF REGULAR LANGUAGES
Properties of Regular Languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
CSE322 CONSTRUCTION OF FINITE AUTOMATA EQUIVALENT TO REGULAR EXPRESSION Lecture #9.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Closure Properties of Regular Languages
NFA to DFA conversion and regular expressions
Convert to a DFA: Start state: Final States: P Symbol Q E(Q) a b.
CSE 105 theory of computation
Chapter 1 Regular Language
Text search and closure properties
CSC312 Automata Theory Kleene’s Theorem Lecture # 12
NFAs accept the Regular Languages
COSC 3340: Introduction to Theory of Computation
Nondeterminism The Chinese University of Hong Kong Fall 2010
CSE 105 theory of computation
Presentation transcript:

CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Properties of regular languages Fall 2008

Operations that preserve regularity In the last lecture we saw three operations that preserve regularity: –Union: If L, L’ are regular languages, so is L  L’ –Concatenation: If L, L’ are regular languages, so is LL’ –Star: If L is a regular language, so is L* Exercise: If L is regular, is L 4 also regular? Answer: Yes, because L 4 = ((LL)L)L

Example The language L of strings that end in 101 is regular How about the language L of strings that do not end in 101? (0+1)*101

Example Hint: A string does not end in 101 if and only if it ends in one of the following patterns: (or it has length 0, 1, or 2) So L can be described by the regular expression 000, 001, 010, 011, 100, 110, 111 (0+1)*( ) +  + (0 + 1) + (0 + 1)(0 + 1)

Complement The complement L of a language L is the set of all strings (over  ) that are not in L Examples (  = {0, 1} ) –L 1 = all strings that end in 101 –L 1 = all strings that do not end in 101 = all strings end in 000, …, 111 or have length 0, 1, or 2 –L 2 = 1* = { , 1, 11, 111, …} –L 2 = all strings that contain at least one 0 = (0 + 1)*0(0 + 1)*

Closure under complement If L is a regular language, is L also regular? Previous examples indicate answer should be yes Theorem If L is a regular language, so is L.

Proof of closure under complement To prove this in general, we can use any of the equivalent definitions for regular languages: In this proof DFA definition will be most convenient –We will assume L is accepted by a DFA, and show the same for L regular expression DFANFA

Proof of closure under complement Suppose L is regular, then it is accepted by a DFA M Now consider the DFA M’ with the accepting and rejecting states of M reversed

Proof of closure under complement Now for every input x   * : M accepts x After processing x, M ends in an accepting state After processing x, M’ ends in an rejecting state M’ rejects x Language of M’ is L L is regular

A warning NFA for language of strings ending in 101 Give NFA that accepts strings that do not end in , 1 qq qq qq qq qq qq qq qq wrong!

Intersection The intersection L  L’ is the set of strings that are in both L and L’ Examples: If L, L’ are regular, is L  L’ also regular? L = (0 + 1)*111L’ = 1* L  L’ = ? L = (0 + 1)*101L’ = 1* L  L’ = ?

Closure under intersection Theorem Proof: If L and L’ are regular languages, so is L  L’. L regular L’ regular L regular L’ regular L  L’ regular But L  L’ = L  L’ L  L’ regular L  L’ regular.

Reversal The reversal w R of a string w is w written backwards The reversal L R of a language L is the language obtained by reversing all its strings w = cavew R = evac L = {push, pop}L R = {hsup, pop}

Reversal of regular languages L = all strings that end in 101 is regular How about L R ? This is the language of all strings beginning in 101 Yes, because it is represented by (0+1)* (0+1)*

Closure under reversal Theorem Proof –We will use the representation of regular languages by regular expressions If L is a regular language, so is L R. regular expression DFANFA

Proof of closure under reversal If L is regular, then there is a regular expression E that describes it We will give a systematic way of reversing E Recall that a regular expression can be of the following types: –Special expressions  and  –Alphabet symbols a, b, … –The union, concatenation, or star of simpler expressions In each of these cases we show how to do a reversal

Proof of closure under reversal regular expression E   a (alphabet symbol) E 1 + E 2 reversal E R E1E2E1E2 E1*E1*   a E 1 R + E 2 R E2RE1RE2RE1R (E 1 R )*

Applications: text search Text search: grep –Looks for occurrences of a regular expression in a file Syntax of regular expressions in grep –[atr] means the set { a, t, r } –[b-e] means { b, c, d, e } (in ASCII/Unicode ordering) –| means + (union), * means star –? means “ zero or one ” : R? is  + R –+ means “ one or more ” : R+ is RR* –{n} means “ n copies of ” : R{5} is RRRRR

Regular expressions in grep Say we have a file w.txt Want to know all sunny days > grep ‘sunny’ w.txt Any cloudy days in April ‘08? > grep ‘4/[0-9]*/08 ([0-9]|C| )* cloudy’ w.txt Any consecutive string of 7 sunny days? > grep ‘(([0-9]|/|C| )* sunny\n){7}’ w.txt 1/1/08 14C rain\n 1/2/08 17C sunny\n 1/3/08 18C sunny\n …

Implementation of grep One way to implement grep is to convert the regular expression into a DFA and then “run” the DFA on this text file Two issues that arise: –grep looks for patterns inside text, while the DFA processes the input as a whole –DFA only produces “yes/no” answer, while grep outputs lines that contain given pattern How would you resolve these issues?