Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.

Slides:



Advertisements
Similar presentations
Deterministic Finite Automata (DFA)
Advertisements

YES-NO machines Finite State Automata as language recognizers.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
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.
CS5371 Theory of Computation
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Languages and Finite Automata or how to talk to machines...
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 4: Automata Theory II (DFA = NFA, Regular Language)
Topics Automata Theory Grammars and Languages Complexities
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Languages and Machines Unit two: Regular languages and Finite State Automata.
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.
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,
1 Introduction to Automata Theory Reading: Chapter 1.
Finite-State Machines with No Output Longin Jan Latecki Temple University Based on Slides by Elsa L Gunter, NJIT, and by Costas Busch Costas Busch.
Finite-State Machines with No Output
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
AUTOMATA THEORY Reference Introduction to Automata Theory Languages and Computation Hopcraft, Ullman and Motwani.
Theory of Computation, Feodor F. Dragan, Kent State University 1 Regular expressions: definition An algebraic equivalent to finite automata. We can build.
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
1 Chapter 1 Introduction to the Theory of Computation.
Grammars CPSC 5135.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2006.
Great Theoretical Ideas in Computer Science.
Languages Given an alphabet , we can make a word or string by concatenating the letters of . Concatenation of “x” and “y” is “xy” Typical example: 
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
CHAPTER 1 Regular Languages
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions Finite Automata.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
CS 203: Introduction to Formal Languages and Automata
Recursive Definations Regular Expressions Ch # 4 by Cohen
Deterministic Finite Automata COMPSCI 102 Lecture 2.
Modeling Computation: Finite State Machines without Output
UNIT - I Formal Language and Regular Expressions: Languages Definition regular expressions Regular sets identity rules. Finite Automata: DFA NFA NFA with.
Theory of computation Introduction theory of computation: It comprises the fundamental mathematical properties of computer hardware, software,
Transparency No. 2-1 Formal Language and Automata Theory Homework 2.
Great Theoretical Ideas in Computer Science for Some.
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.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Finite Automata A simple model of computation. 2 Finite Automata2 Outline Deterministic finite automata (DFA) –How a DFA works.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
COMP3190: Principle of Programming Languages DFA and its equivalent, scanner.
Theory of Languages and Automata By: Mojtaba Khezrian.
Lecture 2 Compiler Design Lexical Analysis By lecturer Noor Dhia
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Theory of Languages and Automata By: Mojtaba Khezrian.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Languages.
Lecture 1 Theory of Automata
CIS Automata and Formal Languages – Pei Wang
Deterministic FA/ PDA Sequential Machine Theory Prof. K. J. Hintz
Deterministic Finite Automata
Finite Automata & Regular Languages
Jaya Krishna, M.Tech, Assistant Professor
Deterministic Finite Automata
COSC 3340: Introduction to Theory of Computation
Chapter 1 Introduction to the Theory of Computation
Chapter 1 Regular Language
Presentation transcript:

Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata. Equivalence between DFA and NFA. 2

*notes:- In a set we do not distinguish repetitions of the elements. Thus the set{red, blue, red} is the same as set{red, blue}. Similarly, the order of the elements is immaterial; for example, {3, 1, 9}, {9, 3,1}, and {1, 3, 9} are the same set. 4 To summarize: Two sets are equal (that is, the same) if and only if they have the same elements.

*The elements of a set need not be related in any way for example, {3, red, {d, blue}} is a set with three elements, one of which is itself a set. 5 So far we have specified sets by simply listing all their elements, separated by commas and included in braces. HW:- F={ yes, no }. write in other ways

For examplethe set N of natural numbers is infinite; we may suggest its elements by writing N = {0, 1, 2,... }, using the three dots and your intuition in place of an infinitely long list. For example :- the set N of natural numbers is infinite; we may suggest its elements by writing N = {0, 1, 2,... }, using the three dots and your intuition in place of an infinitely long list. *Some sets cannot be written in this way,because *Some sets cannot be written in this way, because they are infinite *Another way to specify a set is by referring to other sets and to properties that elements may or may not have. For example I= {l, 3, 9} and G = {3,9} G may be described as the set of elements of I that are greater than 2. the set of odd natural numbers is Set with even number S= {2, 4, 6, …} S = {i :i>0 and even 6

7

If we have two sets A,B then the there is some operations that performed on them as follow 8 For example 1. {1,3,9}  {3,5,7} = {1,3,5,7} 1. {1,3,9}  {3,5,7} = {1,3,5,7} {1,3,9}  {3,5,7} ={3} {1,3,9}  {3,5,7} ={3} 2. {1,3,9}  {a,b,c,d} = Ø 2. {1,3,9}  {a,b,c,d} = Ø 3. {1,3,9}  {a,b,c,d}=? 3. {1,3,9}  {a,b,c,d}=?

9 It is possible to form intersections and unions of more than two sets.If S is any collection of sets, we write  S for the set whose elements are the elements of all the sets in S. And  S for the set whose elements are the elements of each sets in S. For example, if S = {{a, b}, {b, c},{c, d, b}} It is possible to form intersections and unions of more than two sets. If S is any collection of sets, we write  S for the set whose elements are the elements of all the sets in S. And  S for the set whose elements are the elements of each sets in S. For example, if S = {{a, b}, {b, c},{c, d, b}}  S = {a, b, c,d }  S = {b} A - B = {x: x  A and x  B}. For example, { I, 3, 9} - {3, 5, 7} = {I, 9}.

HW:- what are these sets? (a) ({1,3,5}  {3,1})  {3,5,7} (b)  { {3}, {3, 5},  { {5, 7}, {7, 9}}} (c) ({1,2,5} - {5, 7,9})  ({5, 7,9} - {l,2,5}) (d) 2 {7,8,9} - 2 {7,9} (e) 2 Ø HW:- what are these sets? (a) ({1,3,5}  {3,1})  {3,5,7} (b)  { {3}, {3, 5},  { {5, 7}, {7, 9}}} (c) ({1,2,5} - {5, 7,9})  ({5, 7,9} - {l,2,5}) (d) 2 {7,8,9} - 2 {7,9} (e) 2 Ø 10

Alphabet:- An alphabet is a finite and not empty set of symbols.We use Σ(sigma) to denote this alphabet. Alphabet:- An alphabet is a finite and not empty set of symbols. We use Σ(sigma) to denote this alphabet. English alphabet ∑ = { A, B, …, Z, a, b, …, z,0,…,9 } For example: Binary alphabet ∑ = { 0,1} For example: 0, 1, 11, 00, and are strings over {0, 1 }. Cat, CAT, watermelon and compute are strings over the English alphabet. Lower case letters ∑= {a, b, c,... z} 11

For example: 1. |automata|= 8 2. |computation| = |ε |= 0 4. |101|=3 5. |ab |=3 6. |01  0  1  00  | = ? 12

13

Example: = = beach. boy = beachboy beach. boy = beachboy if n = 0, w0 = ε if n > 0, w1 = w w2 = w1. w1 w2 = w1. w1 w3 = w2. w1 w3 = w2. w1... wn = wn-1. w1 wn = wn-1. w1 Example: (do) 2 = dodo 14

- ε is a substring of every string. - for every string x, x is a substring of x itself. - ε is a substring of every string. - for every string x, x is a substring of x itself. Example: ε, compu and computation are substrings of computation. The string ”spelled backwards” Example: 1. (reverse) R = esrever 2. (automata) R = atamotua 15

Σ*: denotes the set of all sequences of strings that are composed of zero or more symbols of Σ The symbol * is called the Kleene star. Σ*: denotes the set of all sequences of strings that are composed of zero or more symbols of Σ.The symbol * is called the Kleene star. ∑* = ∑ 0 U ∑ 1 U ∑ 2 U … 1.  = {0, 1}. 1.  = {0, 1}.  * = { , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… }  * = { , 0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… } Σ + : denotes the set of all sequences of strings composed of one or more symbols of Σ. ∑ + = ∑1 U ∑2 U ∑3 U … ∑ + = ∑1 U ∑2 U ∑3 U … 1.  + = {0, 1, 00, 01, 10, 11, 000, 001, 010, 011,… } 2.  + = { a,b,aa,ab,ba,bb,aaa,aab,…} Σ + = Σ* − {ε}  = {a,b}  * = { , a,b,aa,ab,ba,bb,aaa,aab,…}  * = { , a,b,aa,ab,ba,bb,aaa,aab,…}

17 A language is a set of strings over an alphabet Σ. 1.Let L be the language of all strings consisting of n 0’s followed by n 1’s: L = { ,01,0011,000111,…} 2.Let L be the language of all strings with equal number of 0’s and 1’s: L = { ,01,10,0011,1100,0101,1010,1001,…} 3. Let L be the language of all strings contain two consecutive 0’s L = { ,001,100,0011,1100, ,…} L = { ,001,100,0011,1100, ,…} 4. L = {(10) n : n ≥0} L = { ,10,1010,101010,101010,…} L = { ,10,1010,101010,101010,…} 5. L = {a 2n + 1 : n >= 0} L = {a, aaa, aaaaa,...} L = {a, aaa, aaaaa,...}

18

Union: Let L 1 and L 2 be languages over an alphabet Σ. The union of L 1 and L 2, denoted by L 1  L 2, is {x | x is in L 1 or L 2 }. Examples: 1. L 1 ={ 0, 11, 01, 011 },L 2 ={ 1, 01, 110 } L1  L 2 = { 0, 11, 01, 011, 1, 110, 111 } L1  L 2 = { 0, 11, 01, 011, 1, 110, 111 } 2. {x  {0,1}*|x begins with 0}  {x  {0,1}*|x ends with 0} = {x  {0,1}*| x begins or ends with 0} = {x  {0,1}*| x begins or ends with 0} 19

Intersection: Let L 1 and L 2 be languages over an alphabet Σ.The intersection of L 1 and L 2, denoted by L 1  L 2, is { x | x is in L 1 and L 2 }. Examples 1. L 1 ={ 0, 11, 01, 011 },L 2 ={ 1, 01, 110 } L1  L 2 ={01} L1  L 2 ={01} 2. { x  {0,1}*| x begins with 0}  { x  {0,1}*| x ends with 0} = { x  {0,1}*| x begins and ends with 0} 20

Let L 1 and L 2 be languages over an alphabet Σ. The concatenation of L 1 and L 2, denoted by L 1  L 2, is {w 1  w 2 | w 1 is in L 1 and w 2 is in L 2 }. is {w 1  w 2 | w 1 is in L 1 and w 2 is in L 2 }.Examples: 1. L1 = {00, 01}. 1. L1 = {00, 01}. L2 = {a, aa, aaa }. Then, L2 = {a, aa, aaa }. Then, L1.L2 = {00a, 01a, 00aa, 01aa, 00aaa, 01aaa}. L1.L2 = {00a, 01a, 00aa, 01aa, 00aaa, 01aaa}. 2. L1 = { a, ab } L2 = { b, ba } = L2 = { b, ba } = L1.L2 = { ab, aba, abb, abba }. L1.L2 = { ab, aba, abb, abba }. 21

Expansion: The concatenation of a language L with itself n times is denoted L n In particular, if n = 0, L 0 = {ε}. if n = 0, L 0 = {ε}. if n > 0, L 1 = L if n > 0, L 1 = L L 2 = L 1. L 1 L 2 = L 1. L 1 L 3 = L 2. L 1 L 3 = L 2. L 1... L n = L n-1. L 1 L n = L n-1. L 1 Example: If L = {01, 001}, then L 0 = {ε}. L 0 = {ε}. L 1 ={01, 001}. L 1 ={01, 001}. L 2 = {0101, , 01001, 00101}. L 2 = {0101, , 01001, 00101}. L 3 = {010101, , , , L 3 = {010101, , , , , , , } , , , }. 22 Hw:- Let L = { 1, 00} compute L 3

23

Closure: Let L be a language over an alphabet Σ.The closure of L, denoted by L +, is { x | for an integer n  1, x = x 1 x 2 …x n and x 1, x 2, …, x n are in L} Or it all strings derivable by one or more concatenations of strings in L. Example : Let L = { a, ab }. Then we have, L* = {ε}  {a, ab}  {aa, aab, aba, abab} … L+ = {a, ab}  {aa, aab, aba, abab} … 24

26  Software for designing and checking the behavior of digital circuits.  Lexical analyzer of a typical compiler.  Software for scanning large bodies of text (e.g., web pages) for pattern finding  Software for verifying systems of all types that have a finite number of states (e.g., stock market transaction, communication/network protocol)

27 machine that automatically recognizes if a particular string belongs to the language or not, by checking the grammar or rules of the string. Example 1:-represents a finite state machine that recognize (accept) string {ab}. Start state Final state Transition Intermediate state Example 2:- Modeling recognition of the string {then}

29 Deterministic Finite Automata (DFA) The machine can exist in only one state at any given time q0q0 start q1q1 0 0,1 Non-deterministic Finite Automata (NFA) The machine can exist in multiple states at the same time q0q0 start q1q {q 0 } 1 0 {q 1 } 1 {q 2 } Find the DFA and NFA for the following diagrams One Two

30 A deterministic finite automaton (DFA) isA deterministic finite automaton (DFA) is a 5-tuple (Q, , , q0, F) where a 5-tuple (Q, , , q0, F) where – Q is a finite set of states –  is an alphabet –  : Q ×  → Q is a transition function – q 0  Q is the initial state – F  Q is a set of accepting states (or final states). q0q0q0q0 q1q1q1q1 q2q2q2q2 1000,11 alphabet = {0, 1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state= q0 accepting states F = {q0, q1} alphabet = {0, 1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state= q0 accepting states F = {q0, q1} states input symbols 0 1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q0q0q0q0 q1q1q1q1 q2q2q2q2 q2q2q2q2 q2q2q2q2 q1q1q1q1 transition function  : Example 1:

31 q0q0q0q0 q1q1q1q1 q2q2q2q ,11 HW:- find the 5-tuple parts for the following diagram alphabet = {a, b} states Q = {0, 1, 2} states Q = {0, 1, 2} initial state= 0 accepting states F = {1} alphabet = {a, b} states Q = {0, 1, 2} states Q = {0, 1, 2} initial state= 0 accepting states F = {1} Example 2: states input symbols a b transition function  :

32 Input: a word or string w in ∑*Input: a word or string w in ∑* Question: Is w acceptable by the DFA?Question: Is w acceptable by the DFA? Steps:Steps: –Start at the “start state” q 0 –For every input symbol in the sequence w do Compute the next state from the current state by given the current input symbol in w and the transition functionCompute the next state from the current state by given the current input symbol in w and the transition function –If after all symbols in w are consumed, the current state is one of the final states (F) then accept w; –Otherwise, reject w. What does a DFA do on reading an input string?

33 So String is accepted by a FA if and only if the FA starting at the initial state and ends in an accepting state after reading the string. M=(Q, , , q 0, F) alphabet = {0,1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state = q0 accepting states F = {q1} transition function  : M=(Q, , , q 0, F) alphabet = {0,1} states Q = {q0, q1, q2} states Q = {q0, q1, q2} initial state = q0 accepting states F = {q1} transition function  : For Example: states input symbols 0 1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q0q0q0q0 q1q1q1q1 q0q0q0q0 q1q1q1q1 q2q2q2q2 q2q2q2q2 we see that the automation will accept the strings 01,101,0111 and 11001, but reject the strings 00,100 or 1100 Note: extended transition function  Note: extended transition function  *    Q ×   → Q the second argument of  * is a string rather than a single symbol. for example:  q0,a)=q1  q0,a)=q1And  (q1,b)=q2 Then    q0,ab)=q2 for example:  q0,a)=q1  q0,a)=q1And  (q1,b)=q2 Then    q0,ab)=q2

34 Languages and DFA language accepted by a DFA M=(Q, , , q 0, F) is the set of all strings on  accepted by M, and the languages called regular languages. In formal notation. While, Nonaccepted means that the DFA stops in a nonfinal state. In formal notation Example 1: Answer :

35 Example 2: find a diagram of DFA for language L = {a 2n + 1 | n >= 0} L = {a 2n + 1 | n >= 0} Answer : L = {a, aaa, aaaaa,...} Example 3: L(M) = {w in {a,b}* | w contains even no. of a's} Answer :  * = {a,b}* = {b,aa, bb,aab,baba,babba…}

36 HW in class:-Build a DFA for the following language: L = { w in {a,b}* | w has odd number of b's}. HW :-DFA of A = {w | w contains at least one 1 and an even number of 0s follow the last 1}

37