Discrete Mathematics and its Applications Rosen 6th ed., Ch. 12.1

Slides:



Advertisements
Similar presentations
Natural Language Processing - Formal Language - (formal) Language (formal) Grammar.
Advertisements

C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
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.
Normal forms for Context-Free Grammars
Syntactic Pattern Recognition Statistical PR:Find a feature vector x Train a system using a set of labeled patterns Classify unknown patterns Ignores relational.
Finite State Machines Data Structures and Algorithms for Information Processing 1.
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.
Modeling Computation Rosen, ch. 12.
Introduction Syntax: form of a sentence (is it valid) Semantics: meaning of a sentence Valid: the frog writes neatly Invalid: swims quickly mathematics.
::ICS 804:: Theory of Computation - Ibrahim Otieno SCI/ICT Building Rm. G15.
CS/IT 138 THEORY OF COMPUTATION Chapter 1 Introduction to the Theory of Computation.
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
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.
Introduction to Language Theory
Parsing Introduction Syntactic Analysis I. Parsing Introduction 2 The Role of the Parser The Syntactic Analyzer, or Parser, is the heart of the front.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
Lecture 16: Modeling Computation Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output.
Formal Languages and Grammars
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
Models of Computation by Dr. Michael P. Frank, University of Florida Modified and extended by Longin Jan Latecki, Temple University Rosen 7 th ed., Ch.
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Formal Languages and Automata FORMAL LANGUAGES FINITE STATE AUTOMATA.
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.
Topic 3: Automata Theory 1. OutlineOutline Finite state machine, Regular expressions, DFA, NDFA, and their equivalence, Grammars and Chomsky hierarchy.
Modeling Arithmetic, Computation, and Languages Mathematical Structures for Computer Science Chapter 8 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesAlgebraic.
PROGRAMMING LANGUAGES
Language Recognition MSU CSE 260.
PROGRAMMING LANGUAGES
Theory of Computation Lecture #
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Introduction to the Theory of Computation
Introduction to Formal Languages
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Lecture 1 Theory of Automata
Syntax Specification and Analysis
Classification of Languages
Complexity and Computability Theory I
Automata and Languages What do these have in common?
Natural Language Processing - Formal Language -
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Discrete Mathematics and its Applications
Jaya Krishna, M.Tech, Assistant Professor
Context-Free Languages
Context-Free Grammars and Languages
A HIERARCHY OF FORMAL LANGUAGES AND AUTOMATA
Models of Computation by Dr. Michael P
Intro to Data Structures
Finite Automata and Formal Languages
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Discrete Mathematics and its Applications Rosen 7th ed., Ch. 13.1
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Models of Computation by Dr. Michael P
Discrete Mathematics and its Applications Rosen 8th ed., Ch. 13.1
Formal Languages Context free languages provide a convenient notation for recursive description of languages. The original goal of formalizing the structure.
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Models of Computation by Dr. Michael P
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Language translation Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
COMPILER CONSTRUCTION
Languages and Grammer In TCS
Presentation transcript:

Discrete Mathematics and its Applications Rosen 6th ed., Ch. 12.1 12/2/2018 Models of Computation by Dr. Michael P. Frank, University of Florida Modified and extended by Longin Jan Latecki, Temple University Rosen 6th ed., Ch. 12.1 (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Modeling Computation An algorithm: A description of a computational procedure. Now, how can we model the computer itself, and what it is doing when it carries out an algorithm? For this, we want to model the abstract process of computation itself. (c)2001-2002, Michael P. Frank

Early Models of Computation Discrete Mathematics and its Applications 12/2/2018 Early Models of Computation Recursive Function Theory Kleene, Church, Turing, Post, 1930’s Turing Machines – Turing, 1940’s RAM Machines – von Neumann, 1940’s Cellular Automata – von Neumann, 1950’s Finite-state machines, pushdown automata various people, 1950’s VLSI models – 1970s Parallel RAMs, etc. – 1980’s (c)2001-2002, Michael P. Frank

§11.1 – Languages & Grammars Discrete Mathematics and its Applications 12/2/2018 §11.1 – Languages & Grammars Phrase-Structure Grammars Types of Phrase-Structure Grammars Derivation Trees Backus-Naur Form (c)2001-2002, Michael P. Frank

Computers as Transition Functions Discrete Mathematics and its Applications Computers as Transition Functions 12/2/2018 A computer (or really any physical system) can be modeled as having, at any given time, a specific state sS from some (finite or infinite) state space S. Also, at any time, the computer receives an input symbol iI and produces an output symbol oO. Where I and O are sets of symbols. Each “symbol” can encode an arbitrary amount of data. A computer can then be modeled as simply being a transition function T:S×I → S×O. Given the old state, and the input, this tells us what the computer’s new state and its output will be a moment later. Every model of computing we’ll discuss can be viewed as just being some special case of this general picture. (c)2001-2002, Michael P. Frank

Language Recognition Problem Discrete Mathematics and its Applications 12/2/2018 Language Recognition Problem Let a language L be any set of some arbitrary objects s which will be dubbed “sentences.” That is, the “legal” or “grammatically correct” sentences of the language. Let the language recognition problem for L be: Given a sentence s, is it a legal sentence of the language L? That is, is sL? Surprisingly, this simple problem is as general as our very notion of computation itself! (c)2001-2002, Michael P. Frank

Vocabularies and Sentences Discrete Mathematics and its Applications 12/2/2018 Vocabularies and Sentences Remember the concept of strings w of symbols s chosen from an alphabet Σ? An alternative terminology for this concept: Sentences σ of words υ chosen from a vocabulary V. No essential difference in concept or notation! Empty sentence (or string): λ (length 0) Set of all sentences over V: Denoted V*. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Grammars A formal grammar G is any compact, precise mathematical definition of a language L. As opposed to just a raw listing of all of the language’s legal sentences, or just examples of them. A grammar implies an algorithm that would generate all legal sentences of the language. Often, it takes the form of a set of recursive definitions. A popular way to specify a grammar recursively is to specify it as a phrase-structure grammar. (c)2001-2002, Michael P. Frank

PSG Example – English Fragment Discrete Mathematics and its Applications 12/2/2018 PSG Example – English Fragment We have G = (V, T, S, P), where: V = {(sentence), (noun phrase), (verb phrase), (article), (adjective), (noun), (verb), (adverb), a, the, large, hungry, rabbit, mathematician, eats, hops, quickly, wildly} T = {a, the, large, hungry, rabbit, mathematician, eats, hops, quickly, wildly} S = (sentence) P = (see next slide) (c)2001-2002, Michael P. Frank

Productions for our Language Discrete Mathematics and its Applications 12/2/2018 Productions for our Language P = { (sentence) → (noun phrase) (verb phrase), (noun phrase) → (article) (adjective) (noun), (noun phrase) → (article) (noun), (verb phrase) → (verb) (adverb), (verb phrase) → (verb), (article) → a, (article) → the, (adjective) → large, (adjective) → hungry, (noun) → rabbit, (noun) → mathematician, (verb) → eats, (verb) → hops, (adverb) → quickly, (adverb) → wildly } (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Backus-Naur Form sentence ::= noun phrase verb phrase noun phrase ::= article [adjective] noun verb phrase ::= verb [adverb] article ::= a | the adjective ::= large | hungry noun ::= rabbit | mathematician verb ::= eats | hops adverb ::= quickly | wildly Square brackets [] mean “optional” Vertical bars mean “alternatives” (c)2001-2002, Michael P. Frank

A Sample Sentence Derivation Discrete Mathematics and its Applications 12/2/2018 A Sample Sentence Derivation (sentence) (noun phrase) (verb phrase) (article) (adj.) (noun) (verb phrase) (art.) (adj.) (noun) (verb) (adverb) the (adj.) (noun) (verb) (adverb) the large (noun) (verb) (adverb) the large rabbit (verb) (adverb) the large rabbit hops (adverb) the large rabbit hops quickly On each step, we apply a production to a fragment of the previous sentence template to get a new sentence template. Finally, we end up with a sequence of terminals (real words), that is, a sentence of our language L. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Derivation Tree 12/2/2018 (c)2001-2002, Michael P. Frank

Phrase-Structure Grammars Discrete Mathematics and its Applications 12/2/2018 Phrase-Structure Grammars A phrase-structure grammar (abbr. PSG) G = (V,T,S,P) is a 4-tuple, in which: V is a vocabulary (set of words) The “template vocabulary” of the language. T  V is a set of words called terminals Actual words of the language. Also, N :≡ V − T is a set of special “words” called nonterminals. (Representing concepts like “noun”) SN is a special nonterminal, the start symbol. P is a set of productions (to be defined). Rules for substituting one sentence fragment for another. A phrase-structure grammar is a special case of the more general concept of a string-rewriting system, due to Post. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Productions A production pP is a pair p=(b,a) of sentence fragments l, r (not necessarily in L), which may generally contain a mix of both terminals and nonterminals. We often denote the production as b → a. Read “b goes to a” (like a directed graph edge) Call b the “before” string, a the “after” string. It is a kind of recursive definition meaning that If lbr  LT, then lar  LT. (LT = sentence “templates”) That is, if lbr is a legal sentence template, then so is lar. That is, we can substitute a in place of b in any sentence template. A phrase-structure grammar imposes the constraint that each l must contain a nonterminal symbol. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Languages from PSGs The recursive definition of the language L defined by the PSG: G = (V, T, S, P): Rule 1: S  LT (LT is L’s template language) The start symbol is a sentence template (member of LT). Rule 2: (b→a)P: l,rV*: lbr  LT → lar  LT Any production, after substituting in any fragment of any sentence template, yields another sentence template. Rule 3: (σ  LT: ¬nN: nσ) → σL All sentence templates that contain no nonterminal symbols are sentences in L. Abbreviate this using lbr  lar. (read, “lar is directly derivable from lbr”). (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Example V T Let G = ({a, b, A, B, S}, {a, b}, S, {S → ABa, A → BB, B → ab, AB → b}). One possible derivation in this grammar is: S  ABa  Aaba  BBaba  Bababa  abababa. P (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Derivability Recall that the notation w0  w1 means that (b→a)P: l,rV*: w0 = lbr  w1 = lar. The template w1 is directly derivable from w0. If w2,…wn-1: w0  w1  w2  …  wn, then we write w0 * wn, and say that wn is derivable from w0. The sequence of steps wi  wi+1 is called a derivation of wn from w0. Note that the relation * is just the transitive closure of the relation . (c)2001-2002, Michael P. Frank

A Simple Definition of L(G) Discrete Mathematics and its Applications 12/2/2018 A Simple Definition of L(G) The language L(G) (or just L) that is generated by a given phrase-structure grammar G=(V,T,S,P) can be defined by: L(G) = {w  T* | S * w} That is, L is simply the set of strings of terminals that are derivable from the start symbol. (c)2001-2002, Michael P. Frank

Language Generated by a Grammar Discrete Mathematics and its Applications 12/2/2018 Language Generated by a Grammar Example: Let G = ({S,A,a,b},{a,b}, S, {S → aA, S → b, A → aa}). What is L(G)? Easy: We can just draw a tree of all possible derivations. We have: S  aA  aaa. and S  b. Answer: L = {aaa, b}. S aA b Example of a sentence diagram. aaa (c)2001-2002, Michael P. Frank

Generating Infinite Languages Discrete Mathematics and its Applications 12/2/2018 Generating Infinite Languages A simple PSG can easily generate an infinite language. Example: S → 11S, S → 0 (T = {0,1}). The derivations are: S  0 S  11S  110 S  11S  1111S  11110 and so on… L = {(11)*0} – the set of all strings consisting of some number of concaten- ations of 11 with itself, followed by 0. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Another example Construct a PSG that generates the language L = {0n1n | nN}. 0 and 1 here represent symbols being concatenated n times, not integers being raised to the nth power. Solution strategy: Each step of the derivation should preserve the invariant that the number of 0’s = the number of 1’s in the template so far, and all 0’s come before all 1’s. Solution: S → 0S1, S → λ. (c)2001-2002, Michael P. Frank

Types of Grammars - Chomsky hierarchy of languages Discrete Mathematics and its Applications 12/2/2018 Types of Grammars - Chomsky hierarchy of languages Venn Diagram of Grammar Types: Type 0 – Phrase-structure Grammars Type 1 – Context-Sensitive Type 2 – Context-Free Type 3 – Regular (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Defining the PSG Types Type 1: Context-Sensitive PSG: All after fragments are either longer or empty: if b → a, then |b| ≤ |a| or a=λ Type 2: Context-Free PSG: All before fragments have length 1: if b → a, then |b| = 1 and b  N Type 3: Regular PSGs: All after fragments are either single terminals, or a pair of a terminal followed by a nonterminal. if b → a, then a  T or a  TN. (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Classifying grammars Given a grammar, we need to be able to find the smallest class in which it belongs. This can be determined by answering three questions: Are the left hand sides of all of the productions single non-terminals? If yes, does each of the productions create at most one non-terminal and is it on the right? Yes – regular No – context-free If not, can any of the rules reduce the length of a string of terminals and non-terminals? Yes – unrestricted No – context-sensitive (c)2001-2002, Michael P. Frank

Regular grammars (Type 3) Discrete Mathematics and its Applications 12/2/2018 Regular grammars (Type 3) A regular grammar is one where each production takes one of the following forms: A → a, A → aB. The grammar G: S → 1<First1>, <First1> → 1<Second1>, <Second1> → 1<First1>, <Second1> → 0 is regular. What is L(G)? (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications The grammar: S → 0S1, S → λ is not regular, it is context-free Only one nonterminal can appear on the right side and it must be at the right end of the right side. Therefore, the productions A → aBc and S → TU are not part of a regular grammar, but the production A → bA is. Discrete Mathematics and its Applications 12/2/2018 12/2/2018 (c)2001-2002, Michael P. Frank

Context-Free Grammars (Type 2) Discrete Mathematics and its Applications Context-Free Grammars (Type 2) 12/2/2018 Grammar Variables Terminal symbols Start variable Productions of the form: Variable String of variables and terminals (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Example The grammar: S → 0S1, S → λ is context-free. Another example of a context free language is { anbmcn+m | n,m  0} . This is not a regular language, but it is context free as it can be generated by the following CFG (Context Free Grammar): S → aSc | B B → bBc | λ The language { anbncn | n  1} is context-sensitive but not context free. A grammar for this language is given by: S → aSBC | aBC CB → BC aB → ab bB → bb bC → bc cC → cc (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 A example derivation in this grammar is: S  aSBC  aaBCBC (using S → aBC)  aabCBC (using aB → ab)  aabBCC (using CB → BC)  aabbCC (using bB → bb)  aabbcC (using bC → bc)  aabbcc (using cC → cc)  which derives a2b2c2. (c)2001-2002, Michael P. Frank

Context-Sensitive Grammar (Type 1) Discrete Mathematics and its Applications 12/2/2018 Context-Sensitive Grammar (Type 1) A context-sensitive grammar is a formal grammar G = (V, T, S, P) such that all rules in P are of the form αAβ → αγβ with A in N=V-T (i.e., A is single nonterminal) and α and β in V (i.e., α and β strings of nonterminals and terminals) and γ is in V+ (i.e., γ a nonempty string of nonterminals and terminals), plus a rule of the form S → λ with λ the empty string, is allowed if S does not appear on the right side of any rule. 12/2/2018 (c)2001-2002, Michael P. Frank

Discrete Mathematics and its Applications 12/2/2018 Every context-sensitive grammar which does not generate the empty string can be transformed into an equivalent one in Kuroda normal form: AB → CD or A → BC or A → B or A → α where A, B, C and D are nonterminal symbols and α is a terminal symbol. 12/2/2018 (c)2001-2002, Michael P. Frank