CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.

Slides:



Advertisements
Similar presentations
Automata Theory Part 1: Introduction & NFA November 2002.
Advertisements

4b Lexical analysis Finite Automata
Lecture 16 Deterministic Turing Machine (DTM) Finite Control tape head.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 3 School of Innovation, Design and Engineering Mälardalen University 2012.
Introduction to Computability Theory
1 Introduction to Computability Theory Lecture7: PushDown Automata (Part 1) Prof. Amos Israeli.
Intro to DFAs Readings: Sipser 1.1 (pages 31-44) With basic background from Sipser 0.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
Fall 2006Costas Busch - RPI1 Deterministic Finite Automata And Regular Languages.
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 490: Automata and Language Theory Daniel Firpo Spring 2003.
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
CSC 361Finite Automata1. CSC 361Finite Automata2 Formal Specification of Languages Generators Grammars Context-free Regular Regular Expressions Recognizers.
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.
Finite Automata Costas Busch - RPI.
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
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,
Pushdown Automata.
Lecture 2UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 2.
Theory of Languages and Automata
Pushdown Automata (PDAs)
4b 4b Lexical analysis Finite Automata. Finite Automata (FA) FA also called Finite State Machine (FSM) –Abstract model of a computing entity. –Decides.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2010.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CS 3813: Introduction to Formal Languages and Automata Chapter 2 Deterministic finite automata These class notes are based on material from our textbook,
Deterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.2)
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PushDown Automata. What is a stack? A stack is a Last In First Out data structure where I only have access to the last element inserted in the stack.
Three Basic Concepts Languages Grammars Automata.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2007.
1.2 Three Basic Concepts Languages start variables Grammars Let us see a grammar for English. Typically, we are told “a sentence can Consist.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
using Deterministic Finite Automata & Nondeterministic Finite Automata
CS 154 Formal Languages and Computability February 9 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
CS 154 Formal Languages and Computability February 11 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 3 Mälardalen University 2006.
CS 154 Formal Languages and Computability March 8 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 17 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
CS 154 Formal Languages and Computability March 10 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability March 15 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
1 Finite Automata. 2 Introductory Example An automaton that accepts all legal Pascal identifiers: Letter Digit Letter or Digit "yes" "no" 2.
CS 154 Formal Languages and Computability May 12 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 28 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 5 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
CS 154 Formal Languages and Computability April 7 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
Lecture 11  2004 SDU Lecture7 Pushdown Automaton.
Costas Busch - LSU1 Deterministic Finite Automata And Regular Languages.
Fall 2004COMP 3351 Finite Automata. Fall 2004COMP 3352 Finite Automaton Input String Output String Finite Automaton.
Finite Automata.
Formal Languages, Automata and Models of Computation
Lecture2 Regular Language
Non Deterministic Automata
Chapter 7 PUSHDOWN AUTOMATA.
Chapter 9 TURING MACHINES.
Chapter 2 FINITE AUTOMATA.
COSC 3340: Introduction to Theory of Computation
Deterministic Finite Automata And Regular Languages Prof. Busch - LSU.
Non-Deterministic Finite Automata
Non-Deterministic Finite Automata
Non Deterministic Automata
4b Lexical analysis Finite Automata
4b Lexical analysis Finite Automata
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

CS 154 Formal Languages and Computability February 4 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Did We Understand …  The proof that |uv| = |u| + |v| ?  The fact that L** = L* ? 2

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Grammars  A grammar G is defined as the quadruple where: V is a finite set of objects called variables T is a finite set of objects called terminal symbols S in V is a special symbol called the start variable P is a finite set of production rules 3 G = (V, T, S, P)

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Grammar Examples  Let grammar with P given by  Then so we can write  Therefore, the string aabb is in the language 4 * sentential forms L(G) = {a n b n : n ≥ 0}

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Grammar Examples, cont’d  Find a grammar that generates the language  The language is similar to the previous example but with an extra b. We add the production rule  Therefore, G = ({S, A}, {a, b}, S, P) with the production rules 5 S  Ab A  aAb A  λ S  Ab L = {a n b n+1 : n ≥ 0} Or: S  Ab A  aAb|λ

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Equivalent Grammars  Two grammars are equivalent if they both generate the same language:  It is not always easy to discover whether or not two grammars are equivalent. 6 L(G 1 ) = L(G 2 )

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Automata  An automaton is an abstract model of a digital computer. Plural: automata  It can read symbols from an input “file”. A string of symbols from an alphabet. It can read the file only from left to right, one symbol at a time.  It can produce output. 7

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Automata, cont’d  It has a limited amount of temporary storage. Each storage cell can hold one symbol. The automaton can read and change the contents of the storage cells.  It has a control unit. 8 Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Control Unit  The control unit can be in any one of a finite number of internal states.  At any given moment: The control unit is in some internal state. The input mechanism is scanning a particular symbol from the input.  The automaton operates in discrete time steps.  The control unit’s next internal state is determined by the transition function. 9

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Transition Function  The transition function determines the next state of the control unit based on: the current state the current input symbol information currently in the temporary storage  From one time step to another: output may be produced temporary storage contents may be changed 10

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Automaton Configuration  A configuration refers to a particular state of: the control unit the input the temporary storage  The transition of the automaton from one configuration to the next is a move. 11

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Acceptors and Transducers  An automaton whose output is limited to “yes” or “no” for any given input is an acceptor. It either accepts the input string or not.  An automaton that can produce any string of symbols as output is a transducer. 12

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Deterministic vs. Nondeterministic  Deterministic automaton Each move is uniquely determined by the current configuration. If we know the internal state, the input, and the contents of internal storage  we can exactly predict the future behavior of the automaton.  Nondeterministic automaton At each point, the automaton can have several possible moves  we can only predict a set of possible actions. 13 The relationship between deterministic and nondeterministic automata will play a significant role in our study of formal languages and computation.

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Deterministic Acceptors  A deterministic finite acceptor (DFA) is the quintuple where: Q is the finite set of internal states Σ is the input alphabet, a finite set of symbols is a total transition function is the initial state is a set of final states 14 M = (Q, Σ, δ, q 0, F) Total function: A function that is defined for all inputs of the right type (i.e., for all inputs from a given domain).

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak DFA Operation  At the initial time: In internal state q 0 Input mechanism on the leftmost input symbol  During each move: Consume one input symbol by advancing the input one symbol to the right. 15

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak DFA Operation, cont’d  The transition from one internal state to another is governed by the transition function  Example: If the automaton is at the initial state q 0, and If the input symbol is a, and If Then the DFA will go to state q 1.  We can visualize and represent a finite automaton with a transition graph. 16 δ(q 0, a) = q 1

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Transition Graph Example  The DFA where δ is given by 17 δ(q 0, 0) = q 0 δ(q 0, 1) = q 1 δ(q 1, 0) = q 0 δ(q 1, 1) = q 2 δ(q 2, 0) = q 2 δ(q 2, 1) = q 1 M = ({q 0, q 1, q 2 }, {0, 1}, δ, q 0, {q 1 }) initial vertexfinal vertex Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak DFA Operation, cont’d  The automaton accepts its input string if: The automaton reaches the end of the input string. And it’s in one of its final states.  Otherwise, the automaton rejects the string. 18

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Transition Graph Example, cont’d  Will this automaton accept or reject: JFLAP demo Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Extended Transition Function  Transition on a string rather than a single symbol. Do a regular transition on each symbol of the string.  Give the state after reading the entire string. 20

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak State Transition Matrix  We can implement a state transition matrix with a state transition matrix. 21 ab q0q0 q0q0 q1q1 q1q1 q2q2 q2q2 q2q2 q2q2 q2q2 trap state Formal Languages and Automata, 5 th ed. Peter Linz Jones & Bartlett, 2012

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application  You are given the text of the novel War and Peace as a plain text file.  Write a program to search the text for these names: Boris Drubetskoy Joseph Bazdeev Makar Alexeevich  For each name found, print the line number and the position within the line. Line and position numbers start with 1 22

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application, cont’d  A name can span two lines. First name at the end of one line. Last name at the beginning of the next line.  How efficiently can this program run? Run and time the program 10 times and time each run. Print the minimum, maximum, and median times (in milliseconds). To compare among different machines, also calculate the “performance number”: run time in ms X processor speed in GHz (lower performance numbers are better) 23

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application, cont’d  State transition diagram to recognize “Boris” and “Makar”: Boris M akar Recognize “Boris” Recognize “Makar”

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application, cont’d 25 BMaikors The state transition matrix

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application, cont’d 26 private static final int MATRIX[][] =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 */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0}, /* 15 */ {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,BD,0,0,0}, … };

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak A Practical Application, cont’d 27 private int index(char ch) { switch (ch) { case 'A' : return 1; case 'B' : return 2; case 'D' : return 3; case 'J' : return 4; case 'M' : return 5; case 'a' : return 6; case 'b' : return 7; case 'c' : return 8; case 'd' : return 9; case 'e' : return 10; case 'h' : return 11; case 'i' : return 12; case 'k' : return 13; case 'l' : return 14; case 'o' : return 15; case 'p' : return 16; case 'r' : return 17; case 's' : return 18; case 't' : return 19; case 'u' : return 20; case 'v' : return 21; case 'x' : return 22; case 'y' : return 23; case 'z' : return 24; case ' ' : return 25; case '\n' : return 26; default : return 0; }

Computer Science Dept. Spring 2016: February 4 CS 154: Formal Languages and Computability © R. Mak Languages and DFAs  Recall that an acceptor is an automaton that either accepts or rejects input strings.  The set of all strings that the DFA accepts constitutes the language  The DFA represents the language’s rules. 28