Ambiguity, closure properties, Overview of ambiguity, and Chomsky s standard form


 Kelly Reynolds
 1 years ago
 Views:
Transcription
1 Ambiguity, closure properties, and Chomsky s normal form Overview of ambiguity, and Chomsky s standard form
2 The notion of ambiguity Convention: we assume that in every substitution, the leftmost remaining variable is the one that is replaced. When this convention is applied to all substitutions in a derivation, we talk about leftmost derivations Definition: A CGF is said to be ambiguous if a string in its language has two different leftmost derivations. In such a case, the string has necessarily two different parsing trees
3 Equivalence and ambiguity Definition: Two contextfree grammars are declared to be equivalent if and only if they produce the same contextfree language. Remark: An ambiguous contextfree grammar may have an equivalent unambiguous contextfree grammar. Definition: Given an ambiguous grammar, the process of identifying an equivalent grammar that is not ambiguous is called disambiguation. If not such grammar exists, the language is called inherently ambiguous 3
4 Example of an ambiguous contextfree grammar Let G = ({, A}, {,}, R, } R = { A λ, A A A } w = L( G) Then, the string has the following two leftmost derivations:.. A A A A A A 4
5 The grammar is not inherently ambiguous The ambiguity stems from the fact that the rule A A can be use in the first or in the second substitution indistinctively. In either case the same string is derived. w = L( G) L(G) However, is not inherently ambiguous. Following is a context free grammar that eliminates the above ambiguity. 5
6 Disambiguation Let G R = ({, A, B},{,}, R, ) = { A λ, A A B, B B } Claim: L ( G ) = L ( G ) and under G each string is derived by a unique sequence of leftmost substitutions. This is, the new grammar derives the language unambiguously Proof: exercise! 6
7 Closure properties Theorem 9.: Contextfree languages are closed under regular operations L L cketch of the proof: Let and be contextfree languages. Let G = ( V, A, R, and G = ( V, A, R, ) be contextfree grammars such that L = L( G ) and L ( ) = L G respectively. We may assume without loss of generality that V I = φ. V ) 7
8 Proof (cont.) Define the contextfree grammars:. U = ({ } UV UV, A, R U R U{ },. C = ({ } UV UV, A, R U R U{ }, 3. T = ({ } U V, A, R U { λ }, ) Here we assume V UV Claim: L ( U ) = L U L L( C) = L L L( T) = L The rest of the proof (i.e. verification of the claim) is left as an exercise. ) ) * 8
9 Applications n. The language { n n n M = : n, n } is contextfree, since it is the concatenation n n of L = { : n } with itself. The language = i n n nk nk { : k N ( i =,..., k) n is also contextfree, since it is the starclosure of L } 9
10 Chomsky normal form Theorem 9.: (Chomsky normal form) Any contextfree grammar is equivalent to a grammar G = ( V, A, R, ) whose productions are either of the form: Z UT Z a λ where Z, U, T V U T ; or where a A ; or
11 Method 9. Transforming a contextfree grammar into a grammar in Chomsky normal form Given a contextfree grammar G=(V,A,R,). Add a new start variable and add the rule. Remove all rules of the form u λ, u V adding the rules that are necessary to preserve the grammar s productions 3. Eliminate unit rules. These are rules of the form of u v, u, v V and their elimination requires adding the rules u w wherever v w appears, unless was already eliminated 4. Convert rules of the form k to a set of rules of the form u a u, u au,..., uk ak ak where the u i ' s are new variables. 5. Convert rules of the form k to rules of the form of u w u a... a a3 a, k 3 u a... a, k ui ai, wherever ai is a terminal.here, ui is a new variable.
12 Example The context free grammar: G R = ({ },{,}, R, ) = { λ} is not in Chomsky normal form. We will find an equivalent contextfree grammar N, which is in Chomsky normal form, using the previous procedure (Method 9.)
13 Example (cont.). Define a new start variable Old productions λ
14 Example (cont.). Eliminate unitary productions. In our case we have: λ Recall that the removal is performed by eliminating them and adding all rules necessary to preserve the original grammar s derivations
15 Example (cont.) The derivations that involve these unitary productions (and have to be preserved) are: Thus, the new set of rules is: λ
16 Example (cont.) The latter set of rules define an equivalent grammar which is not yet in Chomsky normal form. Indeed no rule, except the one that associate the starting variable with the null string, is in Chomsky normal form. We ll fix this in the next step: 3. Decomposing all remaining productions that are not in Chomsky normal form into sets of productions with two variables or a terminal on the right hand side.
17 Example (cont.) This applies to the current productions:,, We transform each of them into a set of productions in Chomsky normal form as follows
18 Example (cont.) Consider first: This production is clearly equivalent to the combined action of the following productions:
19 Example (cont.) As for we have: ) ( 3 3 ince there are here productions that were already defined, we replace the variables: ) ( ) ( : : = =
20 Example (cont.) After replacing we get: 3 3
21 Example (cont.) And similarly, using the already defined productions, we transform and 3 3
22 Example (cont.) In summary, we get:, { ), },{,},,,,, ({ 3 3 R R N = = λ },,,, { R = λ
23 Does it work? Let s derive a few strings: λ 3 3
24 What s so important about Chomsky s normal form? Theorem 9.3: A contextfree grammar in Chomsky normal form derives a string of length n in exactly n substitutions Proof: Let G w = w of rules of of be a context  free grammar in Chomsky normal form and let w such rules. L ( G ).ince each w n i produced by substituting a the form of v But, the formation of the form u v n. Thus, rule of zv, u, z, v such rules involved in the generation of is a terminal, it could only be the form v the derivation of v v n w involves n applications of can only be done by applying variables.there are exactly n applications v i v w n. i in a string of variables
25 A note on contextsensitive grammars Definition: A contextsensitive grammar is a quadruple G = ( V, A, R, ) wherev, A and are just as in a context  free grammar, but the set of rules R includes rules of the form aub cvd, whereu andv are variables, and a, b, c, and d are strings of variables and literals. 5
26 Example Let G=({,R,T,U,V,W},{a, b, c}, R, ) R= { arc, R art b, btc bbcc, btt bbut, UT UU, UUc VUc Vcc, UV VV, bvc bbcc, bvv bbwv, WV WW, WWc TWc Tcc, WT TT } This grammar generates the canonical noncontextfree n n n language: {a b c : n } 6
27 A derivation The derivation of the string is: aaabbbccc arc aartc aaarttc aaabttc aaabbutc aaabbuuc aaabbvuc aaabbvcc aaabbbccc 7
28 Note on normal forms Principle: Every contextsensitive grammar which does not generate the empty string can be transformed into an equivalent grammar in Kuroda normal form Remark: The normal form will not in general be a contextsensitive grammar, but will be a noncontracting grammar 8
Switching Algebra and Logic Gates
Chapter 2 Switching Algebra and Logic Gates The word algebra in the title of this chapter should alert you that more mathematics is coming. No doubt, some of you are itching to get on with digital design
More informationMEP Y9 Practice Book A
1 Base Arithmetic 1.1 Binary Numbers We normally work with numbers in base 10. In this section we consider numbers in base 2, often called binary numbers. In base 10 we use the digits 0, 1, 2, 3, 4, 5,
More informationTwodimensional Languages
Charles University Faculty of Mathematics and Physics Mgr. Daniel Průša Twodimensional Languages Doctoral Thesis Supervisor: Martin Plátek, CSc. Prague, 2004 Acknowledgements The results presented in
More informationMonads for functional programming
Monads for functional programming Philip Wadler, University of Glasgow Department of Computing Science, University of Glasgow, G12 8QQ, Scotland (wadler@dcs.glasgow.ac.uk) Abstract. The use of monads to
More informationOrthogonal Bases and the QR Algorithm
Orthogonal Bases and the QR Algorithm Orthogonal Bases by Peter J Olver University of Minnesota Throughout, we work in the Euclidean vector space V = R n, the space of column vectors with n real entries
More information12. FiniteState Machines
2. FiniteState Machines 2. Introduction This chapter introduces finitestate machines, a primitive, but useful computational model for both hardware and certain types of software. We also discuss regular
More informationNotes on Richard Dedekind s Was sind und was sollen die Zahlen?
Notes on Richard Dedekind s Was sind und was sollen die Zahlen? David E. Joyce, Clark University December 2005 Contents Introduction 2 I. Sets and their elements. 2 II. Functions on a set. 5 III. Onetoone
More informationAdaptive LL(*) Parsing: The Power of Dynamic Analysis
Adaptive LL(*) Parsing: The Power of Dynamic Analysis Terence Parr University of San Francisco parrt@cs.usfca.edu Sam Harwell University of Texas at Austin samharwell@utexas.edu Kathleen Fisher Tufts University
More informationWHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT?
WHAT ARE MATHEMATICAL PROOFS AND WHY THEY ARE IMPORTANT? introduction Many students seem to have trouble with the notion of a mathematical proof. People that come to a course like Math 216, who certainly
More informationTwoSided Matching Theory
TwoSided Matching Theory M. Utku Ünver Boston College Introduction to the Theory of TwoSided Matching To see which results are robust, we will look at some increasingly general models. Even before we
More informationRevised Version of Chapter 23. We learned long ago how to solve linear congruences. ax c (mod m)
Chapter 23 Squares Modulo p Revised Version of Chapter 23 We learned long ago how to solve linear congruences ax c (mod m) (see Chapter 8). It s now time to take the plunge and move on to quadratic equations.
More informationWHICH SCORING RULE MAXIMIZES CONDORCET EFFICIENCY? 1. Introduction
WHICH SCORING RULE MAXIMIZES CONDORCET EFFICIENCY? DAVIDE P. CERVONE, WILLIAM V. GEHRLEIN, AND WILLIAM S. ZWICKER Abstract. Consider an election in which each of the n voters casts a vote consisting of
More informationBase year recalculation methodologies for structural changes
Base year recalculation methodologies for structural changes Appendix E to the GHG Protocol Corporate Accounting and Reporting Standard Revised Edition Version January 2005 Introduction Making meaningful
More informationYou know from calculus that functions play a fundamental role in mathematics.
CHPTER 12 Functions You know from calculus that functions play a fundamental role in mathematics. You likely view a function as a kind of formula that describes a relationship between two (or more) quantities.
More informationRegular Languages are Testable with a Constant Number of Queries
Regular Languages are Testable with a Constant Number of Queries Noga Alon Michael Krivelevich Ilan Newman Mario Szegedy Abstract We continue the study of combinatorial property testing, initiated by Goldreich,
More informationHow many numbers there are?
How many numbers there are? RADEK HONZIK Radek Honzik: Charles University, Department of Logic, Celetná 20, Praha 1, 116 42, Czech Republic radek.honzik@ff.cuni.cz Contents 1 What are numbers 2 1.1 Natural
More informationRandom matchings which induce Hamilton cycles, and hamiltonian decompositions of random regular graphs
Random matchings which induce Hamilton cycles, and hamiltonian decompositions of random regular graphs Jeong Han Kim Microsoft Research One Microsoft Way Redmond, WA 9805 USA jehkim@microsoft.com Nicholas
More informationOn the Translation of Languages from Left to Right
INFORMATION AND CONTROL 8, 607639 (1965) On the Translation of Languages from Left to Right DONALD E. KNUTtt Mathematics Department, California Institute of Technology, Pasadena, California There has
More informationWhich Semantics for Neighbourhood Semantics?
Which Semantics for Neighbourhood Semantics? Carlos Areces INRIA Nancy, Grand Est, France Diego Figueira INRIA, LSV, ENS Cachan, France Abstract In this article we discuss two alternative proposals for
More informationCommunication Theory of Secrecy Systems
Communication Theory of Secrecy Systems By C. E. SHANNON 1 INTRODUCTION AND SUMMARY The problems of cryptography and secrecy systems furnish an interesting application of communication theory 1. In this
More informationA brief overview of developing a conceptual data model as the first step in creating a relational database.
Data Modeling Windows Enterprise Support Database Services provides the following documentation about relational database design, the relational database model, and relational database software. Introduction
More informationA prettier printer Philip Wadler
A prettier printer Philip Wadler Joyce Kilmer and most computer scientists agree: there is no poem as lovely as a tree. In our love affair with the tree it is parsed, pattern matched, pruned and printed.
More informationRecursive Path Orderings can also be Incremental
Recursive Path Orderings can also be Incremental MirthaLina Fernández 1, Guillem Godoy 2, and Albert Rubio 2 1 Universidad de Oriente, Santiago de Cuba, Cuba Email: mirtha@csd.uo.edu.cu 2 Universitat
More informationCritical points of once continuously differentiable functions are important because they are the only points that can be local maxima or minima.
Lecture 0: Convexity and Optimization We say that if f is a once continuously differentiable function on an interval I, and x is a point in the interior of I that x is a critical point of f if f (x) =
More informationDependent Types at Work
Dependent Types at Work Ana Bove and Peter Dybjer Chalmers University of Technology, Göteborg, Sweden {bove,peterd}@chalmers.se Abstract. In these lecture notes we give an introduction to functional programming
More informationThe Backpropagation Algorithm
7 The Backpropagation Algorithm 7. Learning as gradient descent We saw in the last chapter that multilayered networks are capable of computing a wider range of Boolean functions than networks with a single
More information(LMCS, p. 317) V.1. First Order Logic. This is the most powerful, most expressive logic that we will examine.
(LMCS, p. 317) V.1 First Order Logic This is the most powerful, most expressive logic that we will examine. Our version of firstorder logic will use the following symbols: variables connectives (,,,,
More informationMath 2001 Homework #10 Solutions
Math 00 Homework #0 Solutions. Section.: ab. For each map below, determine the number of southerly paths from point to point. Solution: We just have to use the same process as we did in building Pascal
More informationONEDIMENSIONAL RANDOM WALKS 1. SIMPLE RANDOM WALK
ONEDIMENSIONAL RANDOM WALKS 1. SIMPLE RANDOM WALK Definition 1. A random walk on the integers with step distribution F and initial state x is a sequence S n of random variables whose increments are independent,
More informationA GRAPHTHEORETIC DEFINITION OF A SOCIOMETRIC CLIQUE *
Journal of Mathematical Sociology Gordon and Breach Science Publishers 1973 Vol. 3, pp 113126 Printed in Birkenhead, England A GRAPHTHEORETIC DEFINITION OF A SOCIOMETRIC CLIQUE * RICHARD D. ALBA Columbia
More information