Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings

Similar documents
Theory of Computation - Module 3

Harvard CS 121 and CSCI E-207 Lecture 10: CFLs: PDAs, Closure Properties, and Non-CFLs

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

5.A Examples of Context-Free Grammars 3.1 and 3.2 of Du & Ko s book(pp )

Definition: A grammar G = (V, T, P,S) is a context free grammar (cfg) if all productions in P have the form A x where

Einführung in die Computerlinguistik

TAFL 1 (ECS-403) Unit- III. 3.1 Definition of CFG (Context Free Grammar) and problems. 3.2 Derivation. 3.3 Ambiguity in Grammar

Section 1 (closed-book) Total points 30

CFG Simplification. (simplify) 1. Eliminate useless symbols 2. Eliminate -productions 3. Eliminate unit productions

CS375: Logic and Theory of Computing

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Concordia University Department of Computer Science & Software Engineering

Homework 4. Chapter 7. CS A Term 2009: Foundations of Computer Science. By Li Feng, Shweta Srivastava, and Carolina Ruiz

AC68 FINITE AUTOMATA & FORMULA LANGUAGES DEC 2013

NPDA, CFG equivalence

Finite Automata and Formal Languages TMV026/DIT321 LP Useful, Useless, Generating and Reachable Symbols

Foundations of Informatics: a Bridging Course

60-354, Theory of Computation Fall Asish Mukhopadhyay School of Computer Science University of Windsor

CS 373: Theory of Computation. Fall 2010

EXAMPLE CFG. L = {a 2n : n 1 } L = {a 2n : n 0 } S asa aa. L = {a n b : n 0 } L = {a n b : n 1 } S asb ab S 1S00 S 1S00 100

Chapter 1. Formal Definition and View. Lecture Formal Pushdown Automata on the 28th April 2009

INSTITUTE OF AERONAUTICAL ENGINEERING

TAFL 1 (ECS-403) Unit- IV. 4.1 Push Down Automata. 4.2 The Formal Definition of Pushdown Automata. EXAMPLES for PDA. 4.3 The languages of PDA

cse303 ELEMENTS OF THE THEORY OF COMPUTATION Professor Anita Wasilewska

St.MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Parsing. Context-Free Grammars (CFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

CPS 220 Theory of Computation Pushdown Automata (PDA)

Automata Theory CS F-08 Context-Free Grammars

AC68 FINITE AUTOMATA & FORMULA LANGUAGES JUNE 2014

Computational Models - Lecture 5 1

CSE 355 Test 2, Fall 2016

Computational Models - Lecture 4 1

Properties of Context-Free Languages

Introduction to Formal Languages, Automata and Computability p.1/42

1. Draw a parse tree for the following derivation: S C A C C A b b b b A b b b b B b b b b a A a a b b b b a b a a b b 2. Show on your parse tree u,

Lecture 11 Context-Free Languages

NODIA AND COMPANY. GATE SOLVED PAPER Computer Science Engineering Theory of Computation. Copyright By NODIA & COMPANY

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Please give details of your answer. A direct answer without explanation is not counted.

Introduction to Theory of Computing

Talen en Compilers. Johan Jeuring , period 2. October 29, Department of Information and Computing Sciences Utrecht University

Pushdown Automata (Pre Lecture)

Ogden s Lemma for CFLs

Note: In any grammar here, the meaning and usage of P (productions) is equivalent to R (rules).

Notes for Comp 497 (Comp 454) Week 10 4/5/05

Fundamentele Informatica II

CS375: Logic and Theory of Computing

CSE 468, Fall 2006 Homework solutions 1

CS311 Computational Structures More about PDAs & Context-Free Languages. Lecture 9. Andrew P. Black Andrew Tolmach

Theory of Computation Turing Machine and Pushdown Automata

FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY

Theory of Computer Science

CSCI Compiler Construction

Context Free Languages and Grammars

Computational Models - Lecture 4 1

Non-context-Free Languages. CS215, Lecture 5 c

VTU QUESTION BANK. Unit 1. Introduction to Finite Automata. 1. Obtain DFAs to accept strings of a s and b s having exactly one a.

Context-Free Languages (Pre Lecture)

MA/CSSE 474 Theory of Computation

Properties of Context Free Languages

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Part 4 out of 5 DFA NFA REX. Automata & languages. A primer on the Theory of Computation. Last week, we showed the equivalence of DFA, NFA and REX

CPS 220 Theory of Computation

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Pushdown Automata. Reading: Chapter 6

Theory of Computation

Homework 4 Solutions. 2. Find context-free grammars for the language L = {a n b m c k : k n + m}. (with n 0,

Einführung in die Computerlinguistik

Pushdown automata. Twan van Laarhoven. Institute for Computing and Information Sciences Intelligent Systems Radboud University Nijmegen

CS500 Homework #2 Solutions

Context-Free and Noncontext-Free Languages

Homework 5 - Solution

Context-Free Grammars: Normal Forms

An automaton with a finite number of states is called a Finite Automaton (FA) or Finite State Machine (FSM).

Example. Addition, subtraction, and multiplication in Z are binary operations; division in Z is not ( Z).

Grammars and Context Free Languages

Grammars and Context Free Languages

Context Free Languages (CFL) Language Recognizer A device that accepts valid strings. The FA are formalized types of language recognizer.

This lecture covers Chapter 7 of HMU: Properties of CFLs

Theory of Computation

Intro to Theory of Computation

(b) If G=({S}, {a}, {S SS}, S) find the language generated by G. [8+8] 2. Convert the following grammar to Greibach Normal Form G = ({A1, A2, A3},

Properties of Context-free Languages. Reading: Chapter 7

Properties of Context-Free Languages. Closure Properties Decision Properties

C6.2 Push-Down Automata

C1.1 Introduction. Theory of Computer Science. Theory of Computer Science. C1.1 Introduction. C1.2 Alphabets and Formal Languages. C1.

Problem Session 5 (CFGs) Talk about the building blocks of CFGs: S 0S 1S ε - everything. S 0S0 1S1 A - waw R. S 0S0 0S1 1S0 1S1 A - xay, where x = y.

CS Pushdown Automata

MTH401A Theory of Computation. Lecture 17

Plan for 2 nd half. Just when you thought it was safe. Just when you thought it was safe. Theory Hall of Fame. Chomsky Normal Form

Context Free Languages. Automata Theory and Formal Grammars: Lecture 6. Languages That Are Not Regular. Non-Regular Languages

1. (a) Explain the procedure to convert Context Free Grammar to Push Down Automata.

CS20a: summary (Oct 24, 2002)

Automata Theory. CS F-10 Non-Context-Free Langauges Closure Properties of Context-Free Languages. David Galles

Context-Free Grammar

Computability and Complexity

Context Free Grammars

Automata Theory Final Exam Solution 08:10-10:00 am Friday, June 13, 2008

Transcription:

Recitation 4: Converting Grammars to Chomsky Normal Form, Simulation of Context Free Languages with Push-Down Automata, Semirings 11-711: Algorithms for NLP October 10, 2014

Conversion to CNF Example grammar G: S ba ab A baa as a B abb bs b Task: Convert G to Chomsky Normal Form (Perhaps we re using a CYK parser, more info in future lectures) CNF allows productions in the form: A BC A a

Conversion to CNF Requirements before converting: No unit productions: A B No epsilon productions: A ɛ Algorithms exist to factor out, usually straightforward process.

Conversion to CNF G S ba S ab A baa A as A a B abb B bs B b Leave unchanged: Productions: A a

Conversion to CNF G S ba S ab A baa A as A a B abb B bs B b Leave unchanged: Productions: A a

Conversion to CNF G S ba S ab A baa A as A a B abb B bs B b For productions: A X 1...X m, m 2, where X i is a terminal a Replace a with new variable C a and add production: C a a

Conversion to CNF G (modified) S C b A S C a B A C b AA A C a S A a B C a BB B C b S B b C a a C b b What modified rules now fit CNF?

G (modified) S C b A S C a B A C b AA A C a S A a B C a BB B C b S B b C a a C b b Conversion to CNF

G (modified) S C b A S C a B A C b AA A C a S A a B C a BB B C b S B b C a a C b b For productions: A B 1 B 2...B m, m 3 Replace with: Conversion to CNF A B 1 D 1 D 1 B 2 D 2... D m 2 B m 1 B m

G (modified) S C b A S C a B A C b D 1 D 1 AA A C a S A a B C a BB B C b S B b C a a C b b Conversion to CNF

G (modified) S C b A S C a B A C b D 1 D 1 AA A C a S A a B C a D 2 D 2 BB B C b S B b C a a C b b Conversion to CNF

G (CNF) S C b A S C a B A C b D 1 D 1 AA A C a S A a B C a D 2 D 2 BB B C b S B b C a a C b b Conversion to CNF

Equivalence of CFGs and PDAs Given a CFG G = (V, T, P, S), where the production rules in P are: S Ab ASb AbS ASbS A a 1. Construct a PDA M that accepts by empty stack such that L(M) = L(G). 2. Show the computation of M and the corresponding derivation in G for the string aabaabbb.

Constructing M

Constructing M M = { Q =

Constructing M M = { Q = {q} // States Σ =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 = S // Start stack symbol δ(q, ɛ, S) =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 = S // Start stack symbol δ(q, ɛ, S) = {(q, Ab), (q, ASb), (q, AbS), (q, ASbS)} δ(q, ɛ, A) =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 = S // Start stack symbol δ(q, ɛ, S) = {(q, Ab), (q, ASb), (q, AbS), (q, ASbS)} δ(q, ɛ, A) = {(q, a)} // Transitions for nonterminals δ(q, a, a) =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 = S // Start stack symbol δ(q, ɛ, S) = {(q, Ab), (q, ASb), (q, AbS), (q, ASbS)} δ(q, ɛ, A) = {(q, a)} // Transitions for nonterminals δ(q, a, a) = {(q, ɛ)} // Transitions for terminals δ(q, b, b) =

Constructing M M = { Q = {q} // States Σ = T = {a, b} // Input symbols Γ = V T = {S, A, a, b} // Stack symbols q 0 = q // Start state z 0 = S // Start stack symbol δ(q, ɛ, S) = {(q, Ab), (q, ASb), (q, AbS), (q, ASbS)} δ(q, ɛ, A) = {(q, a)} // Transitions for nonterminals δ(q, a, a) = {(q, ɛ)} // Transitions for terminals δ(q, b, b) = {(q, ɛ)} }

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ) aabsb (q, abaabbb, AbSb) δ(q, ɛ, S) (q, AbS)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ) aabsb (q, abaabbb, AbSb) δ(q, ɛ, S) (q, AbS) aabsb (q, abaabbb, absb) δ(q, ɛ, A) (q, a) (q, baabbb, bsb) δ(q, a, a) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ) aabsb (q, abaabbb, AbSb) δ(q, ɛ, S) (q, AbS) aabsb (q, abaabbb, absb) δ(q, ɛ, A) (q, a) (q, baabbb, bsb) δ(q, a, a) (q, ɛ) (q, aabbb, Sb) δ(q, b, b) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ) aabsb (q, abaabbb, AbSb) δ(q, ɛ, S) (q, AbS) aabsb (q, abaabbb, absb) δ(q, ɛ, A) (q, a) (q, baabbb, bsb) δ(q, a, a) (q, ɛ) (q, aabbb, Sb) δ(q, b, b) (q, ɛ) aabasbb (q, aabbb, ASbb) δ(q, ɛ, S) (q, ASb)

Computation / Derivation Grammar PDA δ Applied S (q, aabaabbb, S) ASb (q, aabaabbb, ASb) δ(q, ɛ, S) (q, ASb) asb (q, aabaabbb, asb) δ(q, ɛ, A) (q, a) (q, abaabbb, Sb) δ(q, a, a) (q, ɛ) aabsb (q, abaabbb, AbSb) δ(q, ɛ, S) (q, AbS) aabsb (q, abaabbb, absb) δ(q, ɛ, A) (q, a) (q, baabbb, bsb) δ(q, a, a) (q, ɛ) (q, aabbb, Sb) δ(q, b, b) (q, ɛ) aabasbb (q, aabbb, ASbb) δ(q, ɛ, S) (q, ASb) aabasbb (q, aabbb, asbb) δ(q, ɛ, A) (q, a)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ) aabaabbb (q, abbb, Abbb) δ(q, ɛ, S) (q, Ab)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ) aabaabbb (q, abbb, Abbb) δ(q, ɛ, S) (q, Ab) aabaabbb (q, abbb, abbb) δ(q, ɛ, A) (q, a) (q, bbb, bbb) δ(q, a, a) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ) aabaabbb (q, abbb, Abbb) δ(q, ɛ, S) (q, Ab) aabaabbb (q, abbb, abbb) δ(q, ɛ, A) (q, a) (q, bbb, bbb) δ(q, a, a) (q, ɛ) (q, bb, bb) δ(q, b, b) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ) aabaabbb (q, abbb, Abbb) δ(q, ɛ, S) (q, Ab) aabaabbb (q, abbb, abbb) δ(q, ɛ, A) (q, a) (q, bbb, bbb) δ(q, a, a) (q, ɛ) (q, bb, bb) δ(q, b, b) (q, ɛ) (q, b, b) δ(q, b, b) (q, ɛ)

Computation / Derivation Grammar PDA δ Applied aabasbb (q, aabbb, asbb) (q, abbb, Sbb) δ(q, a, a) (q, ɛ) aabaabbb (q, abbb, Abbb) δ(q, ɛ, S) (q, Ab) aabaabbb (q, abbb, abbb) δ(q, ɛ, A) (q, a) (q, bbb, bbb) δ(q, a, a) (q, ɛ) (q, bb, bb) δ(q, b, b) (q, ɛ) (q, b, b) δ(q, b, b) (q, ɛ) (q, ɛ, ɛ) δ(q, b, b) (q, ɛ)

Semirings S = (R,,, 0, 1) R is a set and are binary operations R R R, and 0, 1 R

Semiring Laws a, b, c R: (a b) c = a (b c) (associative ) (a b) c = a (b c) (associative ) a b = b a (commutative ) 0 a = a 0 = a ( 0 is id for ) 1 a = a 1 = a ( 1 is id for ) a (b c) = (a b) (a c) (left distributive) (a b) c = (a c) (b c) (right distributive) 0 a = a 0 = 0 ( 0 is annihilator for )

Semiring Examples (N, +,, 0, 1) (whole numbers)

Semiring Examples (N, +,, 0, 1) (whole numbers) ([0, 1], +,, 0, 1) (probabilities)

Semiring Examples (N, +,, 0, 1) (whole numbers) ([0, 1], +,, 0, 1) (probabilities) (Reg Σ, +,,, ɛ) (Regular expressions)

Semiring Examples (N, +,, 0, 1) (whole numbers) ([0, 1], +,, 0, 1) (probabilities) (Reg Σ, +,,, ɛ) (Regular expressions) (Z p, + (mod p), (mod p), 0, 1) (integers modulo some prime p)

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S)

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S) (S[X ], +,, 0, 1) (polynomials over S)

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S) (S[X ], +,, 0, 1) (polynomials over S) (WFST Σ Σ (S),,,, ) (WFSTs with weights from S)

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S) (S[X ], +,, 0, 1) (polynomials over S) (WFST Σ Σ (S),,,, ) (WFSTs with weights from S) (S T,?,?,?, 1 S 1 T ) (pairs of S and T )

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S) (S[X ], +,, 0, 1) (polynomials over S) (WFST Σ Σ (S),,,, ) (WFSTs with weights from S) (S T,?,?,?, 1 S 1 T ) (pairs of S and T ) (Option[S],?,?, None, Some( 1)) (optional Ss)

Semirings Built from Other Semirings If S and T are semirings, then so are: (S n n, +,, 0, I ) (n by n matrices over S) (S[X ], +,, 0, 1) (polynomials over S) (WFST Σ Σ (S),,,, ) (WFSTs with weights from S) (S T,?,?,?, 1 S 1 T ) (pairs of S and T ) (Option[S],?,?, None, Some( 1)) (optional Ss) (GL(S), +,, 0, id) (linear functions S S)