Context-free grammars and. Basics of string generation methods

Similar documents
Lecture 11: Pseudorandom functions

M A T H F A L L CORRECTION. Algebra I 1 4 / 1 0 / U N I V E R S I T Y O F T O R O N T O

Information Theory and Statistics Lecture 4: Lempel-Ziv code

Continued Fractions and Pell s Equation

The picture in figure 1.1 helps us to see that the area represents the distance traveled. Figure 1: Area represents distance travelled

Computability and computational complexity

The Boolean Ring of Intervals

CSE 1400 Applied Discrete Mathematics Number Theory and Proofs

Ma 530 Introduction to Power Series

Introduction to Automata Theory. Reading: Chapter 1

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

CS284A: Representations and Algorithms in Molecular Biology

Sequences. Notation. Convergence of a Sequence

Infinite Sequences and Series

Sequences, Mathematical Induction, and Recursion. CSE 2353 Discrete Computational Structures Spring 2018

Fortgeschrittene Datenstrukturen Vorlesung 11

Recursive Algorithm for Generating Partitions of an Integer. 1 Preliminary

If a subset E of R contains no open interval, is it of zero measure? For instance, is the set of irrationals in [0, 1] is of measure zero?

Axioms of Measure Theory

Lecture 9: Hierarchy Theorems

Properties of Regular Languages. Reading: Chapter 4

PRACTICE FINAL SOLUTIONS

Discrete-Time Systems, LTI Systems, and Discrete-Time Convolution

6.3 Testing Series With Positive Terms

Lecture 11: Hash Functions and Random Oracle Model

3 Gauss map and continued fractions

Chapter 6 Infinite Series

Learning random log-depth decision trees under the uniform distribution

Introduction to Probability. Ariel Yadin. Lecture 2

Recursive Algorithms. Recurrences. Recursive Algorithms Analysis

Alternating Series. 1 n 0 2 n n THEOREM 9.14 Alternating Series Test Let a n > 0. The alternating series. 1 n a n.

Solutions to Math 347 Practice Problems for the final

Ma 530 Infinite Series I

THE SOLUTION OF NONLINEAR EQUATIONS f( x ) = 0.

2.4 - Sequences and Series

Math 140A Elementary Analysis Homework Questions 3-1

Math 155 (Lecture 3)

Topics. Homework Problems. MATH 301 Introduction to Analysis Chapter Four Sequences. 1. Definition of convergence of sequences.

Math F215: Induction April 7, 2013

Frequentist Inference

Intro to Learning Theory

Sets and Probabilistic Models

5.1. The Rayleigh s quotient. Definition 49. Let A = A be a self-adjoint matrix. quotient is the function. R(x) = x,ax, for x = 0.

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

Linear chord diagrams with long chords

Lecture 16: Monotone Formula Lower Bounds via Graph Entropy. 2 Monotone Formula Lower Bounds via Graph Entropy

Lecture 2. The Lovász Local Lemma

6.003 Homework #3 Solutions

Hoggatt and King [lo] defined a complete sequence of natural numbers

Resolution Proofs of Generalized Pigeonhole Principles

# fixed points of g. Tree to string. Repeatedly select the leaf with the smallest label, write down the label of its neighbour and remove the leaf.

Exam 2 CMSC 203 Fall 2009 Name SOLUTION KEY Show All Work! 1. (16 points) Circle T if the corresponding statement is True or F if it is False.

Abstract Vector Spaces. Abstract Vector Spaces

Test One (Answer Key)

Lecture XVI - Lifting of paths and homotopies

SOME TRIBONACCI IDENTITIES

CS161: Algorithm Design and Analysis Handout #10 Stanford University Wednesday, 10 February 2016

Find a formula for the exponential function whose graph is given , 1 2,16 1, 6

4 Mathematical Induction

11. FINITE FIELDS. Example 1: The following tables define addition and multiplication for a field of order 4.

Metric Space Properties

DS 100: Principles and Techniques of Data Science Date: April 13, Discussion #10

Hashing and Amortization

NICK DUFRESNE. 1 1 p(x). To determine some formulas for the generating function of the Schröder numbers, r(x) = a(x) =

Math 25 Solutions to practice problems

The Borel hierarchy classifies subsets of the reals by their topological complexity. Another approach is to classify them by size.

SEQUENCE AND SERIES NCERT

On forward improvement iteration for stopping problems

4.3 Growth Rates of Solutions to Recurrences

Recurrence Relations

The Discrete Fourier Transform

Math Solutions to homework 6

Chapter 7: The z-transform. Chih-Wei Liu

Product measures, Tonelli s and Fubini s theorems For use in MAT3400/4400, autumn 2014 Nadia S. Larsen. Version of 13 October 2014.

Once we have a sequence of numbers, the next thing to do is to sum them up. Given a sequence (a n ) n=1

Math 299 Supplement: Real Analysis Nov 2013

SEQUENCES AND SERIES

t distribution [34] : used to test a mean against an hypothesized value (H 0 : µ = µ 0 ) or the difference

11 Hidden Markov Models

1. By using truth tables prove that, for all statements P and Q, the statement

Worksheet on Generating Functions

Read carefully the instructions on the answer book and make sure that the particulars required are entered on each answer book.

EE / EEE SAMPLE STUDY MATERIAL. GATE, IES & PSUs Signal System. Electrical Engineering. Postal Correspondence Course

2 High-level Complexity vs. Concrete Complexity

Lecture 11: Decision Trees

ACCESSIBLE INDEPENDENCE RESULTS FOR PEANO ARITHMETIC

1 Statement of the Game

Real Variables II Homework Set #5

The standard deviation of the mean

A CAT Algorithm for Generating Permutations with a Fixed Number of Inversions

Data Structures Lecture 9

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

ÉCOLE POLYTECHNIQUE FÉDÉRALE DE LAUSANNE

Davenport-Schinzel Sequences and their Geometric Applications

MAT1026 Calculus II Basic Convergence Tests for Series

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Pb ( a ) = measure of the plausibility of proposition b conditional on the information stated in proposition a. & then using P2

CANTOR SETS WHICH ARE MINIMAL FOR QUASISYMMETRIC MAPS

15.083J/6.859J Integer Optimization. Lecture 3: Methods to enhance formulations

FIR Filter Design: Part II

Transcription:

Cotext-free grammars ad laguages Basics of strig geeratio methods

What s so great about regular expressios? A regular expressio is a strig represetatio of a regular laguage This allows the storig a whole (evetually ifiite) laguage as a (sigle) strig 2

Example Let L = { w : w {0,}* w eds with } The regular expresssio (0 + )* o describes completely this laguage. Therefore L, which is a ifiite laguage, ca be "stored" by storig R (a strig of legth 8). 3

A laguage that is ot regular Theorem 8.: The laguage over the alphabet {0, } L = { w:( N) w = 0 } is ot regular. Proof: By cotradictio. Assume that L is regular.ice L is ifiite, its regular expressio R must cotai the star closure of a o - empty, o - ull regular expressio.ice the basic ( i.e. alphabet) symbolsare 0 ad, such expressio must be either : 0*,*, (0 + )*, or (0o)*. Now, sice L((0 + )*) = {0,}*, (0 + )* produces more strig tha those i L, ad therefore (0 + )*. 4

Proof (cot.) ice L((0o)*) = { λ,0,00,000,...}, (0o)* produces strigs that are ot i L. Therefore, (0o)*. Assume that = 0*. The, the laguage : M = { w : ( x, y {0,}*) ( N) w = must be a sub - laguage of L. But this is ot the case, as well. imilarly,if = *, the laguage : Q = { w : ( x, y {0,}*) ( N) w = must be a sub - laguage of L. This is also false. Therefore, there is o regular expressio for L. This cotradicts the assumptio that L is regular. x0 x y} y} 5

Motivatig grammars The laguage L = { w : w {0,}* ( N) w = hows the existece of o-regular laguages. Ca they be described i a sigle strig? The aswer comes with the itroductio of grammars. Grammars are desiged for: 0 } describig, aalyzig ad geeratig laguages 6

Defiitio of cotext-free grammar Defiitio 8.: A cotext-free grammar (CFG) is a four-tuple G = (, A, R, ) where. is a fiite set of symbols called variables; 2. A is a alphabet 3. I A = φ 4. R ( U A ) * is the set of rules ( v, w ) R is usually deoted v w ad called a productio 5. is the startig or iitial variable. 7

Example Let G = where ({ },{0,}, R, ) R = { 0 Here meas or. Thus, Ad thus, 0} 0 0 0 R = { 0, 0} 0 8

The strig derivatio process The geeratio of a strig with CFGs is called derivatio trigs are derived as follows:. elect a productio whose left had side is the start variable. Ex: 0 2. elect a variable i the rightmost side of this productio. Ex: i the previous CFG we have o choice but, as is the oly variable. 9

trig derivatio process (cot.) 3. elect a productio iitiated with the chose variable. Ex: Assume that we choose: 0 4. Replace the selected variable with the rightmost side of the selected productio. Ex: Choice 3. yields 0 00 5. Cotiue util o variables are left. I the example, o variables are left. The derivatio eds with 00 0

Deotig derivatios Let G = (, A, R, ) be a cotext-free grammar. Assume that w ( A)* is a strig derived from G through a sequece of productios. The, we write w G, w G or, if the umber of productios is ot importat,

Example With the CFG of the previous example: 0 00 (after replacig with 0) 000(after replacig These derivatios are deoted: 0, G, 00, G,2 000; G,3 ad respectively. with 0) 2

The laguage of a cotext-free grammar Defiitio 8.:The laguage of a cotext-free grammar G =(,A,R,), deoted L(G), is the set of all strigs i A* that are geerated (this is, derived with) by G. Thus, L( G) = { w : w A* ( N) w} G, Defiitio 8.2: If a laguage over a alphabet A ca be geerated by a cotext-free grammar, the the laguage is said to be a cotext-free laguage 3

Represetig cotext-free laguages ice a CFG is a four-tuple of fiite mathematical objects, it has strig represetatios. Thus, cotext-free laguages ca be stored (without loss of iformatio) as a strig represetig its cotext-free grammar Ulike regular laguages whose regular expressios are easy to fid, either fidig a cotext-free grammar for a laguage or idetifyig the laguage of a cotext-free grammar, may be much more complex 4

A simple example of laguage idetificatio Theorem 8.2: The laguage of G = is W = { w: ( N) ( ) w = 0 Proof: ({ },{0,},{ 0, 0}, ) } Recall that L( G) = { w : w A* ( N), w} G, To show : (a) W L( G) (b) L( G) W Proof of (a) : We eed to demostrate the predicate :( N) Q( ), where Q( ) :" ( a derivatio) Assume first that =. The, sice the productio 0 R, There is ideed a derivatio 0 0. G, G, " 5

Proof (cot.) Assume 2. We show Q( ) by iductio o the auxiliary predicate : Let P( ) :" Base case : = 0 G, ice 0 R, there exists the derivatio Iductive hypothesis: ( Iductive thesis : P ( ) ( N)( 2 ) Thus, ( N)( " > ) P( ) P ( + ) Proof : By hypothesis, there exists the derivatio ice 0 R, there exists the derivatio + + 0, as well. G, + Now, by applyig 0 R we get 0 G, 0 ) Q( ) is a true predicate. 0 G, 0 G,. 6

0w Proof (cot.) Proof of (b) : It will be show that G caot geerate strigs that are ot i W. Observe first that G has two rulesstartig with thestart variable,amely 0 ad 0. Therefore, G has oly twosubstitutios.thus, ( w) w = w w w w w i ( A )* ( i)( i i+ w w =,..., ) w 0w We will demostrate by iductio that there is at most oe variable P( ) :" Iductive thesis: 0. w Iductivehypothesis:( ) i Base case: =. I this case, clearly, G, i+ w w w has oe symbol or oe". i = per strig derived by G.This is, we'll demostrate : G, 0 G, w w has oe symbol w w has oe symbol or oe. G, + G,. or oe. 7

Proof (cot.) Proof of the iductio : Assume that G, + w = Therefore, w =. w m ( i)( < i < variablei w. Therefore, w has oly oe start variable. m) w i =. The, there exists w ( A )*, such that w w usig 0 to substitute its ow. This is so, because the oly other possible productio ( i. e. 0) does ot preserves. But the, because of the form of the productio, w i w = = 0 w w w i+ i 2 w i+ 2 w m w is the oly start G, 8

Parsig regular expressios Is the same as aalyzig a regular laguage: a recursive process for idetifyig the expressio s basic regular compoets. The recursio decomposes first the lowest hierarchy operatio Ex: The aalysis of a + b* c is represeted i the tree a + b* c a + b* c b* c b * 9

Method 8.: Cotext-free grammar geeratig the laguage of a regular expressio. Write the parsig tree of the regular expressio 2. Replace the root ad each iteral ode that is ot a operatio, with a variable 3. Keep the termials as the leaves, except for termials uder a subtree rooted by a variable havig the operatio * as child. I these cases, replace the termial a, with the strig au, where U is a variable 4. Write the rules as follows: 4. The root is the startig variable, ad each paret-childre edge correspod to a rule. For buildig these rules: 4.2 Assig to each triple of siblig odes,, U the strig U 4.3 Assig to each triple of siblig odes, +, U the strig U 4.4 For each ode havig U ad * as childre, create λ U 4.5 For each leaf au i a sub-tree rooted by a variable havig * as child, create U ad the rule U λ 20

Example : Cosider R = 0+* 0+ Parsig tree after replacemets Correspodig set of rules: +, 0, 0, { 3 2 2 R = 2 * 0 0 4 3 2 o + }, 3 4 4 3 λ λ

Two productios with the previous grammar The resultig grammar is: G=(,,..., },{0,}, R, ) { 7 Where R is the set of rules defied i slide 2 The strigs w=0 ad w =, which are i L(0+* 0+), are produced by G as follows: 0 The strig w= 0, which is also i L(0+* 0+), is produced by G as follows: 4 2 0 3 3 0 4 0 0 4 3 0 0 0 22

trig parsig Defiitio: The parsig of a give strig is the geeratio of a tree represetatio of the derivatio of the strig by a grammar. The tree represetig the strig geeratio is called parse tree. Example: Parse tree for w=0 uder the previous grammar 3 2 4 3 4 3 4 λ 0 23

Grammars vs. regular expressios Oe ca (easily) be coviced that the laguage of the grammar G i the previous costructio is the laguage of the regular expressio. This is, L(G)=L(0+* 0+) Q: Does this double represetatio costitutes a redudacy? A: NO!. Ulike a regular expressio whose role is merely descriptive, the grammar built by Method 8., (as ay other grammar) costitutes (the basis of) a computatioal method (ot ecessarily the most efficiet) for geeratig the strigs of a laguage described by a regular expressio INDEED, uderlyig grammars is the idea of storig a laguage ot as a (static) mathematical descriptio but as a computatioal method BE FULLY AWARE OF THI CONCEPTUAL FACT!!!! 24

A fudametal theorem Theorem: Every regular laguage is a cotext-free laguage cheme of the proof: Let L be a regular laguage ad L is completely described by a regular expressio R. Let G w L.ice L is regular, be the grammar built from the parsig of Build the parsig tree of tree to show that If, o the other had, L The, there is o parse tree for w i terms of This implies that w is ot described by R. But this is a cotradictio with the assumptio that w L. R. w uder R. Use this parsig w.this shows that G L L( G), the ( w L) ( L( G). w). G the grammar G. 25