Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski

Slides:



Advertisements
Similar presentations
Properties of Regular Sets
Advertisements

CSE 105 Theory of Computation Alexander Tsiatas Spring 2012 Theory of Computation Lecture Slides by Alexander Tsiatas is licensed under a Creative Commons.
Deterministic Finite Automata (DFA)
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
January 7, 2015CS21 Lecture 21 CS21 Decidability and Tractability Lecture 2 January 7, 2015.
Erik Jonsson School of Engineering and Computer Science CS 4384 – 001
CS21 Decidability and Tractability
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Regular operations Sipser 1.1 (pages 44 – 47). CS 311 Mount Holyoke College 2 Building languages If L is a language, then its complement is L’ = {w |
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 Lecture4: Regular Expressions Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
Lecture 3UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 3.
Transparency No. 2-1 Formal Language and Automata Theory Chapter 2 Deterministic Finite Automata (DFA) (include Lecture 3 and 4)
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Lecture 3 Goals: Formal definition of NFA, acceptance of a string by an NFA, computation tree associated with a string. Algorithm to convert an NFA to.
1 Languages and Finite Automata or how to talk to machines...
CS 310 – Fall 2006 Pacific University CS310 Finite Automata Sections: September 1, 2006.
Automata & Formal Languages, Feodor F. Dragan, Kent State University 1 CHAPTER 1 Regular Languages Contents Finite Automata (FA or DFA) definitions, examples,
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
CS5371 Theory of Computation Lecture 6: Automata Theory IV (Regular Expression = NFA = DFA)
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
FSA Lecture 1 Finite State Machines. Creating a Automaton  Given a language L over an alphabet , design a deterministic finite automaton (DFA) M such.
Topics Automata Theory Grammars and Languages Complexities
1 Regular Expressions/Languages Regular languages –Inductive definitions –Regular expressions syntax semantics Not covered in lecture.
Nondeterminism (Deterministic) FA required for every state q and every symbol  of the alphabet to have exactly one arrow out of q labeled . What happens.
Great Theoretical Ideas in Computer Science.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Introduction to CS Theory Lecture 1 – Introduction Piotr Faliszewski
Formal Language Finite set of alphabets Σ: e.g., {0, 1}, {a, b, c}, { ‘{‘, ‘}’ } Language L is a subset of strings on Σ, e.g., {00, 110, 01} a finite language,
Finite-State Machines with No Output
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Theory of Languages and Automata
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Great Theoretical Ideas in Computer Science.
1 Module 14 Regular languages –Inductive definitions –Regular expressions syntax semantics.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
MA/CSSE 474 Theory of Computation Regular Expressions Intro.
CHAPTER 1 Regular Languages
Formal Definition of Computation Let M = (Q, ∑, δ, q 0, F) be a finite automaton and let w = w 1 w w n be a string where each wi is a member of the.
CS 203: Introduction to Formal Languages and Automata
Chapter 3 Regular Expressions, Nondeterminism, and Kleene’s Theorem Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction.
Deterministic Finite Automata COMPSCI 102 Lecture 2.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Donghyun (David) Kim Department of Mathematics and Physics North Carolina Central University 1 Chapter 1 Regular Languages Some slides are in courtesy.
Lecture 2 Overview Topics What I forgot from last lecture Proof techniques continued Alphabets, strings, languages Automata June 2, 2015 CSCE 355 Foundations.
Great Theoretical Ideas in Computer Science for Some.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen Department of Computer Science University of Texas-Pan American.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Regular Languages Chapter 1 Giorgi Japaridze Theory of Computability.
Complexity and Computability Theory I Lecture #5 Rina Zviel-Girshin Leah Epstein Winter
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
MA/CSSE 474 Theory of Computation How many regular/non-regular languages are there? Closure properties of Regular Languages (if there is time) Pumping.
1/29/02CSE460 - MSU1 Nondeterminism-NFA Section 4.1 of Martin Textbook CSE460 – Computability & Formal Language Theory Comp. Science & Engineering Michigan.
Languages.
Formal Language & Automata Theory
CSE 105 theory of computation
Hierarchy of languages
CS 154, Lecture 3: DFANFA, Regular Expressions.
COSC 3340: Introduction to Theory of Computation
CSE 2001: Introduction to Theory of Computation Fall 2009
CS21 Decidability and Tractability
CSE 105 theory of computation
Chapter 1 Regular Language
CSCE 355 Foundations of Computation
CSE 105 theory of computation
Presentation transcript:

Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski

Previous Class  Discrete math Induction Recursive definitions  Today: The quiz 3 questions 10 points for each 15 minutes to complete the quiz

Discrete Math Quiz 1.Show, using mathematical induction, that for every n  N it holds that 1 + ∑ i*(i!) = (n+1)! 2.How many functions f: {0,1} n  {0,1} are there? (Hint: There are 2 n strings over {0,1}. Consider all possible sequences of inputs. How many ways of selecting the values of the function are there?) 3.Consider a language L defined as follows 1.ε  L 2.If x  L then x01  L 3.If x  L then 10x  L 4.No string is in L unless it follows from rules 1, 2, 3. (a) Describe L in English (b) How many strings of length 4, 5, and 6 are there in L? i=1 n 0! = 1

Regular Languages  Language L over Σ is regular if it is built from: {}, {ε} {a} for a  Σ using the following operations: Union Concatenation Kleene’s star  Examples ({a}  {b}) * ({a}{b}) * {a} ({a}  {b}) * {a}{a} ({a}  {b}) *  ({a}  {b}) * {b}{b} ({a}  {b}) * This notation is awful!

Regular Languages  Language L over Σ is regular if it is built from: {}, {ε} {a} for a  Σ using the following operations: Union Concatenation Kleene’s star  Examples {a,b} * {ab} * {a} {a,b} * {aa}{a,b} *  {a,b} * {bb} {a,b} * Better… but could be even simpler We can perform some of the simple concatenations and unions

Notation for Regular Expressions  A more convenient notation: Drop set parentheses Use + for union Use · for concatenation (or just drop it) Use (…) * for Kleene’s star  Examples (a+b) * (ab) * a (a+b) * aa (a+b) * + (a+b) * bb(a+b) * These notation conventions essentially define so called regular expressions. See the book for a formal definition. We often use two additional notations helpers: If r is a regular expression and i is an integer the we also use r + and r i

Regular Expression Fun!  Give regular expressions for the following languages! Language of strings over {a,b} of even length The language of strings over {a,b,c} in which all a’s precede all b’s and all b’s precede all c’s The language of strings over {0,1} of length greater than 3 The language of strings of odd length over {a,b} that contain the substring bb The language of strings over {0,1} that do not contain the substring 000. Now… how about L = {a i b i | i  N}. Is L regular? By what regular expression?

Properties of Regular Languages  For each language class it is natural to ask about its closure properties: Are regular languages closed under:  Union?  Intersection?  Subtraction?  Complementation?  Kleene’s star? It is easy to show that regular languages are closed under union and Kleene’s star, but what about the other cases? L 1 L 2 L1L2L1L2 If L 1 and L 2 are both regular then is L 1 L 2 regular?

Machines for Regular Languages?  Regular expressions Give a description of the language Do not necessarily give a direct algorithm to recognize a language … so what kinds of algorithms do we need to recognize regular languages?  Consider the following languages: Strings ending with 0 Strings whose second to last character is 0 Strings with an even number of 0s and 1s Strings ending in 1 and not containing 00  What algorithms work for them? How do we access the input? How much memory do we need?

Finite Automata  Finite automata The most restricted model of computation that we look at Input read once from left to right There is no memory, except for one register that contains the current state. There is a fixed, finite number of state for a given FA State: q Already read Remaining part Can an FA accept the language of strings with an even number of 0s and 1s?

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string , 1

Transition Diagrams  How to describe an FA computation? What’s inside an FA? States One state is designated as an initial state Some states are designated as accepting states For every state we know to what other state to move based on the symbol that we scan An FA accepts a given string x 1 x 2 …x n iff if you start in the initial state and follow the transitions from state to state then you end up in an accepting state after reading in the whole string , 1 Example: Accepts:001, 111, 01 Rejects: 00, 010

Finite Automata Examples  Give transition diagrams for the following languages L: L is a lanugage of strings that contain at least 3 a’s L is a language of strings that contain aaba as a substring L is a language of strings that do not contain aaba as a substring L is a language of strings with an even number of a’s and an even number of b’s

Formal Definition of Finite Automata  An FA is a quintuple M = (Q, Σ, q 0, A, δ) where Q is a finite set of states Σ is an alphabet of input symbols q 0 is the initial state (q 0  Q) A Q is a set of accepting states δ is a total function from Q  Σ  Q : the transition function (often specified as a table)  Exercise: Express the FA’s from the previous slide in terms of this formalism  Note: FAs are sometimes called DFAs. (D = deterministic)

Formal Definition of Finite Automata  Let M = (Q, Σ, q 0, A, δ) be an FA  Is the definition complete? It’s not enough to say what an FA is… … we have to define how it works!  The transition function δ(q, a) = q’ the transition function says to what state do we move if in state q we see symbol a  We extend δ as follows Let δ * (q, x) = q’ such that … q’ is the state to which the FA goes if it starts in state q and reads string x How can we define δ * formally? Definition. We say that a finite automaton M = (Q, Σ, q 0, A, δ) accepts a string x  Σ * iff δ*(q 0, x)  A. L(M) = set of strings accepted by M

Kleene’s Theorem  Why study finite automata? We have defined finite automata and their languages… But how does that help us in the study of regular languages?  Kleene’s theorem! A language L is regular if and only if there is a finite automaton that accepts L  Consequences of Kleene’s theorem: We can prove facts about regular languages via studying either regular expressions or finite automata In particular  Some closure properties of regular languages are easier to prove based on finite automata!  We can hope to write a grep program that matches text against regular expressions!

Closure Properties Revisited  Using Kleene’s theorem we can now show that regular languages are closed under Union Intersection Subtraction Complement  Proof technique: Given L 1 and L 2 Their corresponding FAs M 1 and M 2 run M 1 and M 2 in parallel and decide string membership based on their states  Focus on intersection M 1 = (Q 1, Σ, q 1, A 1, δ 1 ) M 2 = (Q 2, Σ, q 2, A 2, δ 2 ) We construct M such that: L(M) = L(M 1 )  L(M 2 ) M = (Q, Σ, q 0, A, δ), where Q = Q 1  Q 2 q 0 = (q 1, q 2 ) A = {(p,q) | p  A 1 and q  A 2 } For all p  Q 1, q  Q 2, a  Σ, set δ((p,q),a) = (δ 1 (p,a), δ 2 (q,a))

Proving Languages Not Regular  We can use Kleene’s theorem to show that certain languages are not regular So called pumping lemma … but we will here directly use properties of FAs to show a language is not regular  Consider L = {a i b i | i  N } We can show that L is not regular via showing that no FA can possibly accept L. A proof by contradiction.