BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS

Slides:



Advertisements
Similar presentations
Modeling Computation Chapter 13.
Advertisements

Grammar types There are 4 types of grammars according to the types of rules: – General grammars – Context Sensitive grammars – Context Free grammars –
Finite State Machines Finite state machines with output
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
Grammars, Languages and Parse Trees. Language Let V be an alphabet or vocabulary V* is set of all strings over V A language L is a subset of V*, i.e.,
COGN1001: Introduction to Cognitive Science Topics in Computer Science Formal Languages and Models of Computation Qiang HUO Department of Computer.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
79 Regular Expression Regular expressions over an alphabet  are defined recursively as follows. (1) Ø, which denotes the empty set, is a regular expression.
Chapter 3: Formal Translation Models
Topics Automata Theory Grammars and Languages Complexities
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
Syntactic Pattern Recognition Statistical PR:Find a feature vector x Train a system using a set of labeled patterns Classify unknown patterns Ignores relational.
Languages and Grammars MSU CSE 260. Outline Introduction: E xample Phrase-Structure Grammars: Terminology, Definition, Derivation, Language of a Grammar,
1 INFO 2950 Prof. Carla Gomes Module Modeling Computation: Languages and Grammars Rosen, Chapter 12.1.
Formal Grammars Denning, Sections 3.3 to 3.6. Formal Grammar, Defined A formal grammar G is a four-tuple G = (N,T,P,  ), where N is a finite nonempty.
Languages & Strings String Operations Language Definitions.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Grammars CPSC 5135.
1 Introduction to Regular Expressions EELS Meeting, Dec Tom Horton Dept. of Computer Science Univ. of Virginia
Copyright © Curt Hill Languages and Grammars This is not English Class. But there is a resemblance.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Regular Grammars Chapter 7 1. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
Mathematical Notions and Terminology Lecture 2 Section 0.2 Fri, Aug 24, 2007.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Finite State Machines 1.Finite state machines with output 2.Finite state machines with no output 3.DFA 4.NDFA.
Three Basic Concepts Languages Grammars Automata.
September1999 CMSC 203 / 0201 Fall 2002 Week #14 – 25/27 November 2002 Prof. Marie desJardins clip art courtesy of
Formal Languages and Grammars
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Chapter 4: Syntax analysis Syntax analysis is done by the parser. –Detects whether the program is written following the grammar rules and reports syntax.
Conceptual Foundations © 2008 Pearson Education Australia Lecture slides for this course are based on teaching materials provided/referred by: (1) Statistics.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Lecture #2 Advanced Theory of Computation. Languages & Grammar Before discussing languages & grammar let us deal with some related issues. Alphabet: is.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesAlgebraic.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
PROGRAMMING LANGUAGES
CONTEXT-FREE LANGUAGES
Finite State Machines Dr K R Bond 2009
Introduction to Formal Languages
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
David Rodriguez-Velazquez CS – 6800 Summer I
Formal Language & Automata Theory
CS 404 Introduction to Compiler Design
L-systems L-systems are grammatical systems introduced by Lyndenmayer to describe biological developments such as the growth of plants and cellular organisms.
Natural Language Processing - Formal Language -
CS314 – Section 5 Recitation 3
A HIERARCHY OF FORMAL LANGUAGES AND AUTOMATA
Chapter 7 Regular Grammars
Discrete Mathematics and its Applications Rosen 6th ed., Ch. 12.1
Models of Computation by Dr. Michael P
Finite Automata and Formal Languages
Midterm (Models of Computation, Fall, 2000)
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Derivations and Languages
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Models of Computation by Dr. Michael P
Discrete Mathematics and its Applications Rosen 8th ed., Ch. 13.1
Discrete Maths 13. Grammars Objectives
Finite Automaton with output
Models of Computation by Dr. Michael P
COMPILER CONSTRUCTION
Languages and Grammer In TCS
Presentation transcript:

BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS BCT2083 DISCRETE STRUCTURE & APPLICATIONS CHAPTER 5 MODELLING COMPUTATION BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS SITI ZANARIAH SATARI FIST/FSKKP UMP I0910 CHAPTER 5

CHAPTER 5 MODELLING COMPUTATION BCT2083 DISCRETE STRUCTURE & APPLICATIONS CONTENT CHAPTER 5 MODELLING COMPUTATION 5.1 Languages and Grammars 5.2 Finite-State Machines with Output 5.3 Finite-State Machines with No Output 5.4 Language Recognition (not cover) 5.5 Turing Machines (not cover) CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Introduction CHAPTER 5 MODELLING COMPUTATION Models of computation help us to answer the following questions: Can a task be carried out using computer? If YES, How can the task be carried out? Three types of structures used in models computation: Grammars Used to generate words of a language and determine whether a word is in a language. Finite-state Machines Used in modeling a problem. Turing Machines Used to classify problems as tractable/intractable and solvable/unsolvable. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS 5.1 LANGUAGE AND GRAMMARS CHAPTER 5 MODELLING COMPUTATION Understand language and grammars in models of computation Construct derivation tree CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Natural Language & Formal Language 5.1 LANGUAGE AND GRAMMARS Natural Language is spoken language. It is not possible to specify all the rules of syntax (form) in Natural language One of the rules is English grammars. Formal Language which are generated by grammars, provide models for both natural languages and programming languages. Formal Language specified by a well defined set of rules/syntax. Grammars help us answer the following questions: How can we determine whether a combination of words is a valid sentence in a formal language? How can we generate the valid sentences of a formal language? CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Basic Terminologies 5.1 LANGUAGE AND GRAMMARS A vocabulary/alphabet, V is a finite nonempty set of elements called symbols. Example: V = {a, b, c, A, B, C, S} A word/sentence over V is a string of finite length of elements of V. Example: Aba The empty/null string, λ is the string with no symbols. V* is the set of all words over V. Example: V* = {Aba, BBa, bAA, cab …} A language over V is a subset of V*. We can give some criteria to a word to be in a language. Example: cab is a subset in V* and is a language. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Phrase-Structure Grammars 5.1 LANGUAGE AND GRAMMARS A Phrase-Structure Grammars G = (V, T, S, P) consists of: a vocabulary V, a subset T of V consisting of terminal elements a start symbol S from V a finite set of productions P Elements of N = V – T are called nonterminal symbols. Every production in P must contain at least one nonterminal on its left side. EXAMPLE: Let G = (V, T, S, P), where V = {a, b, A, B, S}, T = {a, b}, S is a start symbol and P = {S → ABa, A → BB, B → ab, A → Bb}. Then, G is a Phrase-Structure Grammar. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Language L(G) of a Grammar G 5.1 LANGUAGE AND GRAMMARS Suppose w and w’ are words over the vocabulary set V of a grammar G. Then: We write w ⇒ w’ if w’ can be obtained from w by using one of the productions We write w ⇒ ⇒ w’ if w’ can be obtained from w by using a finite number of productions The language of G consists of all words in terminal set T that can be obtained from the start symbol S by the above process: L (G) = { w Є T*: S ⇒ ⇒ w} EXAMPLE: Let G = (V, T, S, P), where V = {a, b, A, S}, T = {a, b}, S is a start symbol and P = {S → aA, S → b, A → aa}. The language of this grammar is given by L (G) = {b, aaa}; since we can derive aA from using S → aA, and then derive aaa using A → aa. We can also derive b using S → b. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.1 5.1 LANGUAGE AND GRAMMARS Let G = (V, T, S, P), where V = {a, b, A, B, S}, T = {a, b}, S is a start symbol and P = {S →AB, A →Aa, B →Bb, A →a, B →b}. What is L(G), the language of this grammar? Find the language L(G) over {a, b, c} generated by the grammar G with the productions P = {S →aSb, aS →Aa, Aab →c}. Let V = {a, b, A, B, S}, and T = {a, b}. Find the language L(G) generated by the grammar G = (V, T, S, P), with S is a start symbol and a set of productions P = {S →AA, S →B, A →aaA, A →aa, B →bB, B →b}. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Types of Grammars 5.1 LANGUAGE AND GRAMMARS TYPE RESTRICTIONS ON PRODUCTION w ⇒ w’ No restrictions 1 Context- sensitive Every production is of the form α → β where |α|≤ β or of the form α → λ 2 Context- free Every production is of the form A → β where the left side is a nonterminal 3 regular Every production is of the form A → a or A → aB where the left side is a single nonterminal and the right side is a single terminal or a terminal followed by a terminal or, of the form S → λ Every Type 3 grammar is a Type 2 grammar. Every Type 2 grammar is a Type 1 grammar. Every Type 1 grammar is a Type 0 grammar. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Derivation Tree of Context-Free Grammar 5.1 LANGUAGE AND GRAMMARS Represents the language using an ordered rooted tree. Root represents the starting symbol. Internal vertices represent the nonterminal symbol that arise in the production. Leaves represent the terminal symbols. If the production A → w arise in the derivation, where w is a word, the vertex that represents A has as children vertices that represent each symbol in w, in order from left to right. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS Example: Derivation Tree 5.1 LANGUAGE AND GRAMMARS Let G be a context-free grammar with the productions P = {S →aAB, A →Bba, B →bB, B →c}. The word w = acbabc can be derived from S as follows: S ⇒ aAB →a(Bba)B ⇒ acbaB ⇒ acba(bB) ⇒ acbabc Thus, the derivation tree is given as follows: S a A B B b b a B c c CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.1 5.1 LANGUAGE AND GRAMMARS The word w = cbab belongs to the language generated by the grammar G = (V, T, S, P), where V = {a, b, c, A, B, C, S}, T = {a, b, c}, S is the start symbol and P = {S →AB, A →Ca, B →Ba, B →Cb, B →b , C →cb, C →b}. Construct the derivation tree for w. The production rules of a grammar for simple arithmetic expression are: ‹ expression › ::= ‹ digit ›| (‹ expression ›) | + (‹ expression ›) | − (‹ expression ›) | ‹ expression › ‹ operator › ‹ expression › ‹ digit › ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ‹ operator › ::= + | − | * | / | ↑ Construct a derivation tree for arithmetic expression (2 ↑ 5 ) − 8 and (3 * 7) / (9 + 1). CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.1 : EXTRA 5.1 LANGUAGE AND GRAMMARS PAGE : 793, 794, 795 and 796 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. CHAPTER 5

BCT2083 DISCRETE STRUCTURE & APPLICATIONS CHAPTER 5 MODELLING COMPUTATION 5.2 FINITE-STATE MACHINE WITH OUTPUT Understand finite state machines with output. Draw state diagrams for finite state machines with output. Construct state table for finite state machines with output. CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS Finite State Machines 5.2 FINITE-STATE MACHINES WITH OUTPUT A Finite State Machine are used to model many kinds of machine (computer components, vending machine) as the basis for programs for spell checking, grammar checking, indexing or searching large bodies of text, recognizing speech, transforming text and network protocol. A Finite State Machine include a finite set of states, with a designated starting state, an input alphabet a transition function that assigns a next state to every state and input pair. A Finite State Machine can produce output or no output. CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS Finite State Machines with Output 5.2 FINITE-STATE MACHINES WITH OUTPUT A Finite State Machine, M = (S, I, O, f, g, s0) consists of: A finite set S of states A finite input alphabet I A finite output alphabet O A transition function f that assigns to each state and input pair a new state An output functions g that assigns to each state and input pair an output An initial state s0 A Finite State Machine can be represented by State TABLE State DIAGRAM (a directed graph with labeled edge, state represented by a circle) CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS State Table and State Diagram 5.2 FINITE-STATE MACHINES WITH OUTPUT State TABLE represents the values of the transaction function f and the output function g for all pairs of states and input. State DIAGRAM is a directed graph with labeled edge. Each state represented by a circle. Arrows labeled with the input and output pair are shown for each transition State f g Input 0 1 s0 s1 s0 1 0 s1 s3 s0 1 1 s2 s1 s2 s3 s2 s1 0 0 S = {s0, s1, s2, s3}, I = {0, 1}, O = {0, 1} 0,1 0,1 1,0 s1 1,0 s0 s3 1,1 0,0 0,0 s2 1,1 CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.2 5.2 FINITE-STATE MACHINES WITH OUTPUT Draw the state diagrams for the finite state machines with the following tables. State f g Input 0 1 s0 s1 s0 1 1 s1 s2 s0 0 0 s2 s0 s3 1 0 s3 s1 s2 0 1 State f g Input 0 1 s0 s1 s0 0 0 s1 s0 s2 s2 s1 s1 1 0 TABLE 1 TABLE 2 CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.2 5.2 FINITE-STATE MACHINES WITH OUTPUT Construct the state tables for the finite state machines with the following state diagrams. 0,0 0,0 1,0 s0 0,0 s1 0,1 s0 s1 s2 1,1 0,1 1,0 1,0 1,0 0,1 0,0 s2 s3 1,0 1,1 FIGURE 1 FIGURE 2 CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS Input and Output String 5.2 FINITE-STATE MACHINES WITH OUTPUT Given the following finite state machine; State f g Input 0 1 s0 s1 s0 1 0 s1 s3 s0 1 1 s2 s1 s2 s3 s2 s1 0 0 S = {s0, s1, s2, s3}, I = {0, 1}, O = {0, 1} 0,1 0,1 1,0 s1 1,0 s0 s3 1,1 0,0 0,0 s2 1,1 If the input string is 0111 then the output string is 1100. If the input string is 11011011 then the output string is 00110110. CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.2 5.2 FINITE-STATE MACHINES WITH OUTPUT Given the finite state machines with the following state table and state diagrams. Determine the output for each of the following input strings. 0,0 State f g Input a b s0 s0 s2 3 2 s1 s0 s2 2 1 s2 s1 s2 1 3 s0 s1 0,1 1,1 0,1 1,0 1,0 0,0 s2 s3 1,1 TABLE 1 FIGURE 1 w = abaabbababaa 1010 b) 11011011 c) 1010001001 CHAPTER 5

5.2 FINITE-STATE MACHINES WITH OUTPUT BCT2083 DISCRETE STRUCTURE & APPLICATIONS EXERCISE 5.2 : EXTRA 5.2 FINITE-STATE MACHINES WITH OUTPUT PAGE : 802 and 803 Rosen K.H., Discrete Mathematics & Its Applications, (Seventh Edition), McGraw-Hill, 2007. CHAPTER 5

CHAPTER 5 MODELLING COMPUTATION BCT2083 DISCRETE STRUCTURE & APPLICATIONS CHAPTER 5 MODELLING COMPUTATION Grammars, finite state machine and Turing machines are three structures used in models of computation SUMMARY What NEXT? FINAL EXAMINATION THAT’S ALL ; THANK YOU CHAPTER 5