David Rodriguez-Velazquez CS – 6800 Summer I

Slides:



Advertisements
Similar presentations
CSCI 3130: Formal Languages and Automata Theory Tutorial 5
Advertisements

Theorem 7.16: Every CFL is a member of P Proof: Let G be a Chomsky normal form grammar for language L. The following O(n 3 ) algorithm decides whether.
Theory of Computation CS3102 – Spring 2014 A tale of computers, math, problem solving, life, love and tragic death Nathan Brunelle Department of Computer.
Closure Properties of CFL's
CYK Parser Von Carla und Cornelia Kempa. Overview Top-downBottom-up Non-directional methods Unger ParserCYK Parser.
101 The Cocke-Kasami-Younger Algorithm An example of bottom-up parsing, for CFG in Chomsky normal form G :S  AB | BB A  CC | AB | a B  BB | CA | b C.
Simplifying CFGs There are several ways in which context-free grammars can be simplified. One natural way is to eliminate useless symbols those that cannot.
Dept. of Computer Science & IT, FUUAST Automata Theory 2 Automata Theory VII.
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Western Michigan University CS6800 Advanced Theory of Computation Spring 2014 By Abduljaleel Alhasnawi & Rihab Almalki.
The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I
Post's Correspondence Problem Word Problem in semi-Thue Systems
CS5371 Theory of Computation
CS 310 – Fall 2006 Pacific University CS310 Pushdown Automata Sections: 2.2 page 109 October 11, 2006.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
CS Master – Introduction to the Theory of Computation Jan Maluszynski - HT Lecture 4 Context-free grammars Jan Maluszynski, IDA, 2007
Fall 2005 CSE 467/567 1 Formal languages regular expressions regular languages finite state machines.
Normal forms for Context-Free Grammars
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.
نظریه زبان ها و ماشین ها فصل دوم Context-Free Languages دانشگاه صنعتی شریف بهار 88.
CONVERTING TO CHOMSKY NORMAL FORM
Context-Free Grammars – Chomsky Normal Form Lecture 16 Section 2.1 Wed, Sep 26, 2007.
CSCI 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Ambiguity.
The CYK Algorithm Presented by Aalapee Patel Tyler Ondracek CS6800 Spring 2014.
Membership problem CYK Algorithm Project presentation CS 5800 Spring 2013 Professor : Dr. Elise de Doncker Presented by : Savitha parur venkitachalam.
Phrase-structure grammar A phrase-structure grammar is a quadruple G = (V, T, P, S) where V is a finite set of symbols called nonterminals, T is a set.
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.
CS 44 – Jan. 29 Expression grammars –Associativity √ –Precedence CFG for entire language (handout) CYK algorithm –General technique for testing for acceptance.
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.
1 Simplification of Context-Free Grammars Some useful substitution rules. Removing useless productions. Removing -productions. Removing unit-productions.
Closure Properties Lemma: Let A 1 and A 2 be two CF languages, then the union A 1  A 2 is context free as well. Proof: Assume that the two grammars are.
1 Chapter 6 Simplification of CFGs and Normal Forms.
Introduction Finite Automata accept all regular languages and only regular languages Even very simple languages are non regular (  = {a,b}): - {a n b.
Discrete Structures ICS252 Chapter 5 Lecture 2. Languages and Grammars prepared By sabiha begum.
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Normal forms.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
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.
1 Context Free Grammars Xiaoyin Wang CS 5363 Spring 2016.
CS6800 Advance Theory of Computation Spring 2016 Nasser Alsaedi
Chapter 2. Formal Languages Dept. of Computer Engineering, Hansung University, Sung-Dong Kim.
Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.
BCT 2083 DISCRETE STRUCTURE AND APPLICATIONS
Context-Free Grammars: an overview
Properties of Context-Free Languages
Chomsky Normal Form CYK Algorithm
Lecture 1 Theory of Automata
Ambiguity Parsing algorithms
Theory of Languages and Automata
Complexity and Computability Theory I
Natural Language Processing - Formal Language -
7. Properties of Context-Free Languages
Simplifications of Context-Free Grammars
Chapter 7 PUSHDOWN AUTOMATA.
Context Free Languages
Jaya Krishna, M.Tech, Assistant Professor
REGULAR LANGUAGES AND REGULAR GRAMMARS
A HIERARCHY OF FORMAL LANGUAGES AND AUTOMATA
Context-free Languages
Chapter 7 Regular Grammars
NORMAL FORMS FDP ON THEORY OF COMPUTING
7. Properties of Context-Free Languages
CHAPTER 2 Context-Free Languages
The Pumping Lemma for CFL’s
Subject Name: FORMAL LANGUAGES AND AUTOMATA THEORY
The Cocke-Kasami-Younger Algorithm
Normal forms and parsing
Normal Forms for Context-free Grammars
Context-Free Languages
Presentation transcript:

David Rodriguez-Velazquez CS – 6800 Summer I - 2009 The CYK Algorithm David Rodriguez-Velazquez CS – 6800 Summer I - 2009

The CYK Algorithm The membership problem: Problem: Question: Given a context-free grammar G and a string w G = (V, ∑ ,P , S) where V finite set of variables ∑ (the alphabet) finite set of terminal symbols P finite set of rules S start symbol (distinguished element of V) V and ∑ are assumed to be disjoint G is used to generate the string of a language Question: Is w in L(G)?

The CYK Algorithm J. Cocke D. Younger, T. Kasami Independently developed an algorithm to answer this question.

The CYK Algorithm Basics The Structure of the rules in a Chomsky Normal Form grammar Uses a “dynamic programming” or “table-filling algorithm”

Chomsky Normal Form Normal Form is described by a set of conditions that each rule in the grammar must satisfy Context-free grammar is in CNF if each rule has one of the following forms: A  BC at most 2 symbols on right side A  a, or terminal symbol S  λ null string where B, C Є V – {S}

Construct a Triangular Table Each row corresponds to one length of substrings Bottom Row – Strings of length 1 Second from Bottom Row – Strings of length 2 . Top Row – string ‘w’

Construct a Triangular Table Xi, i is the set of variables A such that A  wi is a production of G Compare at most n pairs of previously computed sets: (Xi, i , Xi+1, j ), (Xi, i+1 , Xi+2, j ) … (Xi, j-1 , Xj, j )

Construct a Triangular Table X1, 5 X1, 4 X2, 5 X1, 3 X2, 4 X3, 5 X1, 2 X2, 3 X3, 4 X4, 5 X1, 1 X2, 2 X3, 3 X4, 4 X5, 5 w1 w2 w3 w4 w5 Table for string ‘w’ that has length 5

Construct a Triangular Table X1, 5 X1, 4 X2, 5 X1, 3 X2, 4 X3, 5 X1, 2 X2, 3 X3, 4 X4, 5 X1, 1 X2, 2 X3, 3 X4, 4 X5, 5 w1 w2 w3 w4 w5 Looking for pairs to compare

Example CYK Algorithm Show the CYK Algorithm with the following example: CNF grammar G S  AB | BC A  BA | a B  CC | b C  AB | a w is baaba Question Is baaba in L(G)?

Constructing The Triangular Table S  AB | BC A  BA | a B  CC | b C  AB | a {B} {A, C} b a Calculating the Bottom ROW

Constructing The Triangular Table X1 , 2 = (Xi , i ,Xi+1 , j) = (X1 , 1 , X2 , 2)  {B}{A,C} = {BA, BC} Steps: Look for production rules to generate BA or BC There are two: S and A X1 , 2 = {S, A} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table {S, A} {B} {A, C} b a

Constructing The Triangular Table X2 , 3 = (Xi , i ,Xi+1 , j) = (X2 , 2 , X3 , 3)  {A, C}{A,C} = {AA, AC, CA, CC} = Y Steps: Look for production rules to generate Y There is one: B X2 , 3 = {B} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table {S, A} {B} {A, C} b a

Constructing The Triangular Table X3 , 4 = (Xi , i ,Xi+1 , j) = (X3 , 3 , X4 , 4)  {A, C}{B} = {AB, CB} = Y Steps: Look for production rules to generate Y There are two: S and C X3 , 4 = {S, C} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table {S, A} {B} {S, C} {A, C} b a

Constructing The Triangular Table X4 , 5 = (Xi , i ,Xi+1 , j) = (X4 , 4 , X5 , 5)  {B}{A, C} = {BA, BC} = Y Steps: Look for production rules to generate Y There are two: S and A X4 , 5 = {S, A} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table {S, A} {B} {S, C} {A, C} b a

Constructing The Triangular Table X1 , 3 = (Xi , i ,Xi+1 , j) (Xi , i+1 ,Xi+2 , j) = (X1 , 1 , X2 , 3) , (X1 , 2 , X3 , 3)  {B}{B} U {S, A}{A, C}= {BB, SA, SC, AA, AC} = Y Steps: Look for production rules to generate Y There are NONE: S and A X1 , 3 = Ø no elements in this set (empty set) S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table Ø {S, A} {B} {S, C} {A, C} b a

Constructing The Triangular Table X2 , 4 = (Xi , i ,Xi+1 , j) (Xi , i+1 ,Xi+2 , j) = (X2 , 2 , X3 , 4) , (X2 , 3 , X4 , 4)  {A, C}{S, C} U {B}{B}= {AS, AC, CS, CC, BB} = Y Steps: Look for production rules to generate Y There is one: B X2 , 4 = {B} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table Ø {B} {S, A} {S, C} {A, C} b a

Constructing The Triangular Table X3 , 5 = (Xi , i ,Xi+1 , j) (Xi , i+1 ,Xi+2 , j) = (X3 , 3 , X4 , 5) , (X3 , 4 , X5 , 5)  {A,C}{S,A} U {S,C}{A,C} = {AS, AA, CS, CA, SA, SC, CA, CC} = Y Steps: Look for production rules to generate Y There is one: B X3 , 5 = {B} S  AB | BC A  BA | a B  CC | b C  AB | a

Constructing The Triangular Table Ø {B} {S, A} {S, C} {A, C} b a

Final Triangular Table {S, A, C}  X1, 5 Ø {B} {S, A} {S, C} {A, C} b a - Table for string ‘w’ that has length 5 - The algorithm populates the triangular table

Example (Result) Is baaba in L(G)? Yes We can see the S in the set X1n where ‘n’ = 5 We can see the table the cell X15 = (S, A, C) then if S Є X15 then baaba Є L(G)

Theorem The CYK Algorithm correctly computes X i j for all i and j; thus w is in L(G) if and only if S is in X1n. The running time of the algorithm is O(n3).

References J. E. Hopcroft, R. Motwani, J. D. Ullman, Introduction to Automata Theory, Languages and Computation, Second Edition, Addison Wesley, 2001 T.A. Sudkamp, An Introduction to the Theory of Computer Science Languages and Machines, Third Edition, Addison Wesley, 2006

Question Show the CYK Algorithm with the following example: CNF grammar G S  AB | BC A  BA | a B  CC | b C  AB | a w is ababa Question Is ababa in L(G)? Basics of CYK Algorithm The Structure of the rules in a Chomsky Normal Form grammar Uses a “dynamic programming” or “table-filling algorithm” Complexity O(n3)