R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 10 Automata, Grammars and Languages.

Slides:



Advertisements
Similar presentations
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Advertisements

Finite-State Machines with No Output Ying Lu
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
COGN1001: Introduction to Cognitive Science Topics in Computer Science Formal Languages and Models of Computation Qiang HUO Department of Computer.
Chapter Section Section Summary Set of Strings Finite-State Automata Language Recognition by Finite-State Machines Designing Finite-State.
COMMONWEALTH OF AUSTRALIA Copyright Regulations 1969 WARNING This material has been reproduced and communicated to you by or on behalf of Monash University.
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
Finite Automata Finite-state machine with no output. FA consists of States, Transitions between states FA is a 5-tuple Example! A string x is recognized.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Normal forms for Context-Free Grammars
1 Non-Deterministic Automata Regular Expressions.
Grammars, Languages and Finite-state automata Languages are described by grammars We need an algorithm that takes as input grammar sentence And gives a.
1 Pushdown Automata PDAs. 2 Pushdown Automaton -- PDA Input String Stack States.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
Languages and Machines Unit two: Regular languages and Finite State Automata.
Rosen 5th ed., ch. 11 Ref: Wikipedia
Zvi Kohavi and Niraj K. Jha 1 Capabilities, Minimization, and Transformation of Sequential Machines.
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
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 8 Mälardalen University 2010.
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
REGULAR LANGUAGES.
Theory of Languages and Automata
PZ02B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02B - Regular grammars Programming Language Design.
Pushdown Automata (PDAs)
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Language Recognition Rosen, Chapter 12.4.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
Week 14 - Wednesday.  What did we talk about last time?  Regular expressions  Introduction to finite state automata.
Dr. Eng. Farag Elnagahy Office Phone: King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222.
2. Regular Expressions and Automata 2007 년 3 월 31 일 인공지능 연구실 이경택 Text: Speech and Language Processing Page.33 ~ 56.
Complexity and Computability Theory I Lecture #11 Instructor: Rina Zviel-Girshin Lea Epstein.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
September1999 CMSC 203 / 0201 Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of
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.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
BİL711 Natural Language Processing1 Regular Expressions & FSAs Any regular expression can be realized as a finite state automaton (FSA) There are two kinds.
Conceptual Foundations © 2008 Pearson Education Australia Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
1 Chapter Pushdown Automata. 2 Section 12.2 Pushdown Automata A pushdown automaton (PDA) is a finite automaton with a stack that has stack operations.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Mealy and Moore Machines Lecture 8 Overview Moore Machines Mealy Machines Sequential Circuits.
1 Advanced Theory of Computation Finite Automata with output Pumping Lemma Theorem.
Finite Automata (FA) with Output FA discussed so far, is just associated with R.Es or language. Is there exist an FA which generates an output string corresponding.
1 Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Deterministic Finite-State Machine (or Deterministic Finite Automaton) A DFA is a 5-tuple, (S, Σ, T, s, A), consisting of: S: a finite set of states Σ:
Non Deterministic Automata
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
Non Deterministic Automata
Finite Automata.
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Chapter 1 Regular Language
Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
PZ02B - Regular grammars Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section PZ02B.
Presentation transcript:

R. Johnsonbaugh Discrete Mathematics 5 th edition, 2001 Chapter 10 Automata, Grammars and Languages

10.1 Sequential circuits and finite-state machines Unit-time delay A unit time delay accepts as input a bit x t at time t and outputs x t -1, the bit received as input at time t -1. It is used in the serial adder.

Serial adder  A serial adder accepts as input two binary numbers x and y and outputs the sum z = x + y x = 0x N x N-1 …x 1 x 0 y = 0y N y N-1 …y 1 y 0 z = z N+1 z N z N-1 …z 1 z 0  x and y are input sequentially in pairs x 0,y 0 ; x 1,y 1 ; …; 0,0  The sum is the output z 0, z 1,…, z N, z N+1

Example of a serial adder A serial adder circuit performs addition in the binary system Example: add x + y, where x = 010 and y = 011  x 0 = 0, y 0 = 1.  Adding these two, obtain z 0 = 1 and i = 0  x 1 = 1, y 1 = 1.  Adding these two, obtain z 1 = 0 and i = 1  x 2 = 0, y 2 = 0.  Add these two plus the last i =1 and obtain z 2 = 1  Final answer is z = 101

Serial adder circuit

Finite-state machines A finite-state machine M = (I, O, S, f, g,  ), where: a) I is a finite set of input symbols b) O is finite set of output symbols c) S is a finite set of states d) f: S x I  S is a next-state function e) g: S x I  O is an output function f)  is an initial state

Example of a finite-state machine  I = {a, b}  O = {0, 1}  S = {  0,  1 }  f and g are defined by the table and the transition diagram Input symbols  fg abab States 00 00 11 01 11 11 11 10

Input and output strings  Given a finite state machine M = (I, O, S, f, g,  ), an input string for M is a finite sequence  = x 1 x 2 …x n over I, i.e. x j  I for 1 < j < n.  Given an input string  = x 1 x 2 …x n, then  = y 1 y 2 …y n is an output string for M if  there exist states  0 = ,  i = f(  i-1,x i ) for i = 1,…, n  and y i = g(  i-1,x i ) for i = 1,…, n.

A serial adder finite-state machine  A serial adder accepts pairs of bits, thus its input set is {00, 01, 10, 11}  And the output set is the set {0, 1}  Two states: NC (no carry) and C (carry)  Initial state NC

SR flip-flop (1) Set-reset flip-flop Sequential circuit implementation of the SR flip-flop SRQ 11 Not allowed if S was last 1 0 if R was last 1

SR flip-flop (2)

10.2 Finite state automata A finite-state automaton is a special kind of finite state machine.  A = (I, O, S, f, g,  ) with output set O = {0, 1} and the current state determines the next state.  States for which the last output is 1 are called accepting states. Input symbols  fg abab States 00 11 00 10 11 22 00 10 22 22 11 10 Example of a FSA

Alternative definition of a FSA  A finite-state automaton A is  I = set of input symbols  S = set of states  f :S x I  S, next-state function  A  S, a set of accepting states   = initial state Write A = (I, S, f, A,  )

Accepted strings  = x 1 x 2 …x n is an accepted string over I if there are states  0,  1,…,  n satisfying a)  0 =  b) f(  i-1,x i ) =  i, for i = 1,…, n c)  n  A

Examples of accepted strings  Some of the strings accepted by the FSA in the diagram are: a, a n (n >1), aba k (k > 1), (ab) m a k (k >1), etc.  Let Ac(A) = {accepted strings of A}  Strings ending in b are not accepted

Equivalent finite-state automata Two FSA's A and A' are equivalent if they accept exactly the same strings i.e. Ac(A) = Ac(A' )

Languages and Grammars  Let A be a finite set.  Define A* = { all strings over A }  A grammar G consists of: a) a finite set N of nonterminal symbols b) a finite set T of terminal symbols c) a finite set P of productions, where P  [(N  T)* - T*] x (N  T)* d) a starting symbol 

Formal languages A (formal) language over A is a subset L  A* Example: A = {a, b} A* = { all strings using letters a and b} L = {  |  is a string ending in b}  A*

Productions  A production (A,B)  P can be written A  B where A  (N  T)* - T* and B  (N  T)*  If    is a production and x  y  (N  T)* then we say that x  y is directly derivable from x  y and we write x  y  x  y

Language generated by a grammar The language L(G) generated by G consists of all strings over T derivable from .  If grammars G and G' generate the same languages, i.e. L(G) = L(G'), then G and G' are equivalent.

Backus-Naur (BNF) form  Nonterminal symbols are written  Production S  T is written S:: =T  Productions of the form S:: = T 1, S:: = T 2,…, S:: = T n can be written S:: = T 1 | T 2 |…| T n

Backus-Naur (BNF) form Example: A grammar for integers. Productions: :: = 0|1|2|3|4|5|6|7|8|9 :: = | :: = + | :: = | Starting symbol is

Types of grammars  Context-sensitive (type 1) Every production is of the form  M    Q , where ,  (N  T)*, M  N, Q  (N  T)* - { }, where is the null string.  Context-free (type 2) Every production is of the form A  K, where A  N, K  (N  T)*  Regular (type 3) Every production is of the type A  a or A  aB or A , where A, B  N, a  T.

Lindenmayer grammar A Lindenmayer context-free (LCF) grammar consists of: a) a finite set N of nonterminal symbols b) a finite set T of terminal symbols, with N  T =  c) A finite set P of productions A  B, where A  N  T, B  (N  T)* d) a starting symbol  Notice that in this LCF grammar A can be terminal or nonterminal.

Von Koch Snowflake (1)  This is a LCF grammar G with  N = {D}  T = {d, +, -}  P has four productions: D  D – D + + D - D D  d +  + -  -  A derivation is D  D – D + + D – D  d – d + + d – d Therefore d – d + + d – d  L(G)

Von Koch Snowflake (2) This grammar produces Von Koch snowflakes, which are an example of fractal curves.

10.4 Nondeterministic FSA  A finite-state automaton may be converted to a regular grammar in the following way:  Example: Let A = (I, S, f, A, E) be a FSA with I = {a, b}, S = {E, O}, A = {O} and f defined by the following table and transition diagram

A grammar defined by a FSA  Let N = S = {E, O}, T = I = {a, b}  Let  = E (starting symbol)  Productions P = the directed edges  For every edge x between S and S', define a production S  xS'. In this case we have the productions E  bE, E  aO, O  aE and O  bO  Add the production S  whenever S is an accepting state. In our case, we add O 

Accepted strings and language Theorem : Let A be a finite-state automaton given as a transition diagram with initial state , N = {states} and T = {input symbols}.  Let P = set of productions S  xS' whenever there is a directed edge x = (S, S'), and S .  Let G = (N, T, P,  ) be a regular grammar.  Then the set Ac(A) of strings accepted by A is equal to L(G).

Nondeterministic FSA  A nondeterministic finite-state automaton is characterized for having more than one label x in some of its vertices and, therefore, given input x, there is room for choice of next state.

Table of a nondeterministic FSA  Start with I = {a, b}, S = { , C, D}, Accepting states = {C, D} Next state function ff Statesab  { , C} {D} C  {C} D{C, D} 

10.5 Languages and automata  Given a finite-state automaton A there exists a grammar G such that L(G) = Ac(A).  Conversely, if G is a regular grammar, there exists a nondeterministic finite-state automaton A such that L(G) = Ac(A).

Regular grammars and FSA  Also, given a nondeterministic FSA A there exists a deterministic FSA A' equivalent to A.  Therefore, if G is a regular grammar, there exists a deterministic finite state automaton A with L(G) = Ac(A).

Transition diagram of a nondeterministic FSA

Unreachable states  When unreachable states are deleted, the previous diagram is simplified:

A deterministic FSA equivalent to a nondeterministic FSA  Theorem : Let A = (I, S, f, A,  ) be a nondeterministic finite-state automaton. Let S' = P(S) I' = I  ' =  A' = { X  S | X  A  } f '(X,x) =  if X =  OR  f(S,x) if X  S  X Then the finite-state automaton A' = (I', S', f', A',  ') is equivalent to A.

Regular grammars and languages  Theorem : A language L is regular if and only if there exists a finite-state automaton that accepts precisely the strings in L.  Example: a language L that is not regular: L = {a n b n | n = 1, 2, 3,…}

Reverse of a language The reverse L R of a language L is defined as the set L R = {x n x n-1 …x 2 x 1 | x 1 x 2 …x n  L} Example: if ab 2 ab  L, then bab 2 a  L R.

Example of L and L R