1 Module 30 EQUAL language –Designing a CFG –Proving the CFG is correct.

Slides:



Advertisements
Similar presentations
Mathematical Induction
Advertisements

1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
Recursive Definitions and Structural Induction
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
Induction and recursion
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 Lecture 22 Myhill-Nerode Theorem –distinguishability –equivalence classes of strings –designing FSA’s –proving a language L is not regular.
Induction Sections 41. and 4.2 of Rosen Fall 2008 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Lecture 31 EQUAL language –Designing a CFG –Proving the CFG is correct.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 CSC 3130: Automata theory and formal languages Tutorial 4 KN Hung Office: SHB 1026 Department of Computer Science & Engineering.
Module 28 Context Free Grammars Definition of a grammar G
Induction Sections 4.1 and 4.2 of Rosen Fall 2010
1 Intro to Induction Supplementary Notes Prepared by Raymond Wong Presented by Raymond Wong.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Languages and Finite Automata or how to talk to machines...
TR1413: INTRO TO DISCRETE MATHEMATICS LECTURE 2: MATHEMATICAL INDUCTION.
1 More Applications of the Pumping Lemma. 2 The Pumping Lemma: Given a infinite regular language there exists an integer for any string with length we.
1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.
Normal forms for Context-Free Grammars
EE1J2 - Slide 1 EE1J2 – Discrete Maths Lecture 12 Number theory Mathematical induction Proof by induction Examples.
1 Module 24 Myhill-Nerode Theorem –distinguishability –equivalence classes of strings –designing FSA’s –proving a language L is not regular.
Mathematical Induction
Induction and recursion
Algorithm Design and Analysis (ADA)
Chapter 4 Context-Free Languages Copyright © 2011 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1.
Induction and recursion
Reading and Writing Mathematical Proofs
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
Discrete Maths Objective to introduce mathematical induction through examples , Semester 2, Mathematical Induction 1.
CSE 3813 Introduction to Formal Languages and Automata Chapter 8 Properties of Context-free Languages These class notes are based on material from our.
Copyright © Peter Cappello Mathematical Induction Goals Explain & illustrate construction of proofs of a variety of theorems using mathematical induction.
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
1 Homework #7 (Models of Computation, Spring, 2001) Due: Section 1; April 16 (Monday) Section 2; April 17 (Tuesday) 2. Covert the following context-free.
9.4 Mathematical Induction
1 Module 31 Closure Properties for CFL’s –Kleene Closure –Union –Concatenation CFL’s versus regular languages –regular languages subset of CFL.
Chapter Mathematical Induction 4.2 Strong Induction and Well-Ordering 4.3 Recursive Definitions and Structural Induction 4.4 Recursive Algorithms.
Theory of Computation, Feodor F. Dragan, Kent State University 1 TheoryofComputation Spring, 2015 (Feodor F. Dragan) Department of Computer Science Kent.
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 3 The Foundations: Logic and Proof,
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.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
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.
Overview Mathematical Induction Derivations Recursive Inference Parse Trees Equivalence of Inference, Derivations, and Parse Trees.
CS 203: Introduction to Formal Languages and Automata
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Chapter 8 Properties of Context-free Languages These class notes are based on material from our textbook, An Introduction to Formal Languages and Automata,
INDUCTION Slides of Ken Birman, Cornell University.
CSE 311: Foundations of Computing Fall 2013 Lecture 8: Proofs and Set theory.
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
CSE 311: Foundations of Computing Fall 2013 Lecture 18: Structural induction, regular expressions.
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 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
CS 461 – Sept. 23 Context-free grammars Derivations Ambiguity Proving correctness.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Lecture 16 Cocke-Younger-Kasimi Parsing Topics: Closure Properties of Context Free Languages Cocke-Younger-Kasimi Parsing Algorithm June 23, 2015 CSCE.
Languages.
CSE 311 Foundations of Computing I
Induction and recursion
CSE 311: Foundations of Computing
Context-Free Languages
Discrete Structures for Computer Science
BaSIC Math Reviews.
CSE 311: Foundations of Computing
Applied Discrete Mathematics Week 2: Proofs
Mathematical Induction
Presentation transcript:

1 Module 30 EQUAL language –Designing a CFG –Proving the CFG is correct

2 EQUAL language Designing a CFG

3 EQUAL EQUAL is the set of strings over {a,b} with an equal number of a’s and b’s Strings in EQUAL include –aabbab –bbbaaa –abba Strings in {a,b}* not in EQUAL include –aaa –bbb –aab –ababa

4 Designing a CFG for EQUAL * Think recursively Base Case –What is the shortest possible string in EQUAL? –Production Rule:

5 Recursive Case * Recursive Case –Now consider a longer string x in EQUAL –Since x has length > 0, x must have a first character This must be a or b –Two possibilities for what x looks like x = ay –What must be true about relative number of a’s and b’s in y? x = bz –What must be true about relative number of a’s and b’s in z?

6 Case 1: x=ay * x = ay where y has one extra b –What must y look like? Some examples –b–b –babba –aabbbab –aaabbbb Is there a general pattern that applies to all of the above examples? More specifically, show how we can decompose all of the above strings y into 3 pieces, two of which belong to EQUAL. –Some of these pieces might be the empty string

7 Decomposing y y has one extra b –Possible examples b, babba, aabbbab, aaabbbb –Decomposition y = ubv where –u and v both have an equal number of a’s and b’s Decompose the 4 strings above into u, b, v – b, aabbbab, babba, aaabbbb

8 Implication * Case 1: x=ay –y has one extra b Case 1 refined: x=aubv –u, v belong to EQUAL Production rule for this case?

9 Case 2: x=bz * Case 2: x=bz –z has one extra a Case 2 refined: x=buav –u, v belong to EQUAL Production rule for this case?

10 Final Grammar * EG = (V, , S, P) –V = {S} –  = {a,b} –S = S –P:

11 EQUAL language Proving CFG is correct

12 Is our grammar correct? How do we prove our grammar is correct? –Informal Test some strings Review logic behind program (CFG) design –Formal First, show every string derived by EG belongs to EQUAL –That is, show L(EG) is a subset of EQUAL Second, show every string in EQUAL can be derived by EG –That is, show EQUAL is a subset of L(EG) Both proofs will be inductive proofs –Inductive proofs and recursive algorithms go well together

13 L(EG) subset of EQUAL Let x be an arbitrary string in L(EG) What does this mean? –S ==> * EG x Follows from definition of x in L(EG) –We will prove the following If S ==> 1 EG x, then x is in EQUAL If S ==> 2 EG x, then x is in EQUAL If S ==> 3 EG x, then x is in EQUAL If S ==> 4 EG x, then x is in EQUAL...

14 Base Case * Statement to be proven: –For all n >= 1, if S ==> n EG x, then x is in EQUAL –Prove this by induction on n Base Case: –n = 1 –What is the set of strings {x | S ==> 1 EG x}? –What do we need to prove about this set of strings?

15 Inductive Case Inductive Hypothesis: –For 1 j EG x, then x is in EQUAL Note, this is a “strong” induction hypothesis Traditional inductive hypothesis would take form: –For some n >= 1, if S ==> n EG x, then x is in EQUAL The difference is we assume the basic hypothesis for all integers between 1 and n, not just n Statement to be Proven in Inductive Case: –If S ==> n+1 EG x, then x is in EQUAL

16 Infinite Set of Facts –Fact 1 –Fact 2 –Fact 3 –Fact 4 –Fact 5 –Fact 6 –… Base Case –Prove fact 1 Regular inductive case –For n >= 1, Fact n --> Fact n+1 Strong inductive case –For n >= 1, Fact 1 to Fact n --> Fact n+1 “Regular” induction vs Strong induction

17 Visualization of Induction Regular Induction Fact 1 Fact 2 Fact 3 Fact 4 Fact 5 Fact 6 Fact 7 Fact 8 Fact 9 Strong Induction Fact 1 Fact 2 Fact 3 Fact 4 Fact 5 Fact 6 Fact 7 Fact 8 Fact 9 ……

18 Proving Inductive Case * If S ==> n+1 EG x, then x is in EQUAL –Let x be an arbitrary string such that S ==> n+1 EG x –Examining EG, what are the three possible first derivation steps Case 1: S ==>  ==> n EG x Case 2: S ==> ==> n EG x Case 3: S ==> ==> n EG x –One of the cases is impossible. Which one and why?

19 Case 2: S ==> ==> n EG x * This means x has the form aubv where –What can we conclude about u (don’t apply IH)? –What can we conclude about v (don’t apply IH)? Apply the inductive hypothesis –u and v belong to EQUAL –Why do we need the strong inductive hypothesis? Conclude x belongs to EQUAL –x = aubv where u and v belong to EQUAL Clearly the number of a’s in x equals the number of b’s in x

20 Case 3: S ==> ==> n EG x This means x has the form buav where –What can we conclude about u (no IH)? –What can we conclude about v (no IH) Apply the inductive hypothesis –u and v belong to EQUAL –Why do we need the strong inductive hypothesis? Conclude x belongs to EQUAL –x = buav where u and v belong to EQUAL Clearly the number of a’s in x equals the number of b’s in x

21 L(EG) subset of EQUAL Wrapping up inductive case –In all possible derivations of x, we have shown that x belongs to EQUAL –Thus, we have proven the inductive case Conclusion –By the principle of mathematical induction, we have shown that L(EG) is a subset of EQUAL

22 EQUAL subset of L(EG) * Let x be an arbitrary string in EQUAL What does this mean? We will prove the following If |x| = 0 and x is in EQUAL, then x is in L(G) If |x| = 1 and x is in EQUAL, then x is in L(G) If |x| = 2 and x is in EQUAL, then x is in L(G) If |x| = 3 and x is in EQUAL, then x is in L(G)...

23 Statement to be proven: –For all n >= 0, if |x| = n and x is in EQUAL, then x is in L(EG) –Prove this by induction on n Base Case: –n = 0 –What is the only string x such that |x|=0 and x is in EQUAL? –Prove this string belongs to L(EG) EQUAL subset of L(EG) *

24 Inductive Case Inductive Hypothesis: –For 0 <= j <= n, if |x| =j and x is in EQUAL, then x is in L(EG) Again, this is a “strong” induction hypothesis Statement to be Proven in Inductive Case: –For n >= 0, –if |x| = n+1 and x is in EQUAL, then x is in L(EG)

25 Proving Inductive Case * If |x|=n+1 and x is in EQUAL, then x is in L(EG) –Let x be an arbitrary string such that |x|=n+1 and x is in L(EG) –Examining S, what are the two possibilities for the first character in x? Case 1: first character in x is Case 2: first character in x is –In each case, what can we say about the remainder of x? Case 1: the remainder of x Case 2: the remainder of x

26 Case 1: x = ay * What can we say about y in this case? This means x has the form aubv where –u is in EQUAL and has length <= n –v is in EQUAL and has length <= n –Proving this statement true Consider all the prefixes of string y –length 0: –length 1: y 1 –length 2: y 1 y 2 –…–… –length n: y 1 y 2 … y n = y

27 Case 1: x = ay Consider all the prefixes of string y –length 0: –length 1: y 1 –length 2: y 1 y 2 –…–… –length n: y 1 y 2 … y n = y The first prefix has the same number of a’s as b’s The last prefix y has one extra b The relative number of a’s and b’s changes in the length i prefix differs by only one from the length i-1 prefix Thus, there must be a first prefix t of y where t has one extra b Furthermore, the last character of t must be b –Otherwise, t would not be the FIRST prefix of y with one extra b Break t into u and b and let the remainder of y be v The statement follows

28 Case 1: x = aubv * x = aubv –u is in EQUAL and has length <= n –v is in EQUAL and has length <= n Apply the induction hypothesis –What can we conclude from applying the IH? –Why did we need a strong inductive hypothesis? Conclude x is in L(EG) by constructing a derivation –S ==> aSbS ==> * EG aubS ==> * EG aubv Justify each of the derivation steps in this derivation

29 Case 2: x = buav x = buav –u is in EQUAL and has length <= n –v is in EQUAL and has length <= n Apply the induction hypothesis –What can we conclude about u and v? Conclude x is in L(EG) by constructing a derivation –S ==> bSaS ==> * EG buaS ==> * EG buav Justify each of the steps in this derivation

30 EQUAL subset of L(EG) Wrapping up inductive case –For all possible first characters of x, we have shown that x belongs to L(EG) –Thus, we have proven the inductive case Conclusion –By the principle of mathematical induction, we have shown that EQUAL is a subset of L(EG)