We now introduce a powerful method for proving claims about inductively-defined sets...

Similar documents
T (s, xa) = T (T (s, x), a). The language recognized by M, denoted L(M), is the set of strings accepted by M. That is,

CSCE 222 Discrete Structures for Computing. Review for Exam 2. Dr. Hyunyoung Lee !!!

Proof Techniques (Review of Math 271)

Algorithms and Data Structures 2016 Week 5 solutions (Tues 9th - Fri 12th February)

Theory of computation: initial remarks (Chapter 11)

CMSC 451: Lecture 7 Greedy Algorithms for Scheduling Tuesday, Sep 19, 2017

Logic I - Session 22. Meta-theory for predicate logic

Theory of computation: initial remarks (Chapter 11)

CS 151. Red Black Trees & Structural Induction. Thursday, November 1, 12

Nondeterministic finite automata

CS1800: Mathematical Induction. Professor Kevin Gold

Math 300: Final Exam Practice Solutions

Discrete Mathematics for CS Fall 2003 Wagner Lecture 3. Strong induction

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Intro to Learning Theory Date: 12/8/16

CS 173: Induction. Madhusudan Parthasarathy University of Illinois at Urbana-Champaign. February 7, 2016

Analysis of Algorithms I: Asymptotic Notation, Induction, and MergeSort

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

Lecture 7: More Arithmetic and Fun With Primes

Lecture 6: Finite Fields

Sum of Squares. Defining Functions. Closed-Form Expression for SQ(n)

Assignment 5: Solutions

1 Continuity and Limits of Functions

COE428 Notes Week 4 (Week of Jan 30, 2017)

Confidence Intervals and Hypothesis Tests

PROBLEM SET 3: PROOF TECHNIQUES

To factor an expression means to write it as a product of factors instead of a sum of terms. The expression 3x

CS1800: Strong Induction. Professor Kevin Gold

Lecture 8 : Structural Induction DRAFT

Lecture 4: Constructing the Integers, Rationals and Reals

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Dynamic Programming II Date: 10/12/17

Logic for Computer Science - Week 2 The Syntax of Propositional Logic

b + O(n d ) where a 1, b > 1, then O(n d log n) if a = b d d ) if a < b d O(n log b a ) if a > b d

E.g. The set RE of regular expressions is given by the following rules:

Discrete Mathematics for CS Spring 2008 David Wagner Note 4

CSC236H Lecture 2. Ilir Dema. September 19, 2018

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Asymptotic Analysis, recurrences Date: 9/7/17

Data Structures and Algorithms

Notes on induction proofs and recursive definitions

Introduction to Divide and Conquer

Theory Bridge Exam Example Questions

CS 577 Introduction to Algorithms: Strassen s Algorithm and the Master Theorem

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Preparing for the CS 173 (A) Fall 2018 Midterm 1

Lecture 10: Powers of Matrices, Difference Equations

The semantics of propositional logic

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

Dictionary: an abstract data type

Math 300: Foundations of Higher Mathematics Northwestern University, Lecture Notes

Bayesian Learning. Artificial Intelligence Programming. 15-0: Learning vs. Deduction

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 1

Asymptotic Analysis and Recurrences

Tutorial on Mathematical Induction

Lecture 11: Gödel s Second Incompleteness Theorem, and Tarski s Theorem

Writing proofs for MATH 51H Section 2: Set theory, proofs of existential statements, proofs of uniqueness statements, proof by cases

CS 220: Discrete Structures and their Applications. Mathematical Induction in zybooks

CS103 Handout 08 Spring 2012 April 20, 2012 Problem Set 3

Prompt. Commentary. Mathematical Foci

A Quick Introduction to Row Reduction

Greedy Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 10

An analogy from Calculus: limits

Analysis of Algorithms - Midterm (Solutions)

Lecture 10 September 27, 2016

6.841/18.405J: Advanced Complexity Wednesday, February 12, Lecture Lecture 3

This is logically equivalent to the conjunction of the positive assertion Minimal Arithmetic and Representability

Chapter 4: Computation tree logic

Algorithm Analysis Recurrence Relation. Chung-Ang University, Jaesung Lee

CVO103: Programming Languages. Lecture 2 Inductive Definitions (2)

Kant and Finitism. Crossing Worlds: Mathematical logisc, philosophy, art: For Juliette Kennedy. Bill Tait. 4 June 2016

E = hν light = hc λ = ( J s)( m/s) m = ev J = ev

n n P} is a bounded subset Proof. Let A be a nonempty subset of Z, bounded above. Define the set

Lecture 12 : Recurrences DRAFT

CS411 Notes 3 Induction and Recursion

Models of Computation,

CS173 Strong Induction and Functions. Tandy Warnow

Recitation 7. Treaps and Combining BSTs. 7.1 Announcements. FingerLab is due Friday afternoon. It s worth 125 points.

Design and Analysis of Algorithms

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

CSE 311: Foundations of Computing I Autumn 2014 Practice Final: Section X. Closed book, closed notes, no cell phones, no calculators.

Strong Induction (Second Principle) Example: There are two piles of cards, players take turn: each turn: one player removes any number of cards from

The predicate calculus is complete

Solution to Proof Questions from September 1st

Theory of Computation

Notes from Yesterday s Discussion. Big Picture. CIS 500 Software Foundations Fall November 1. Some lessons.

Lecture 15 - NP Completeness 1

Extensions to the Logic of All x are y: Verbs, Relative Clauses, and Only

Languages, regular languages, finite automata

Computational Logic for Computer Science

MAC-CPTM Situations Project

Lecture 2: Proof of Switching Lemma

1 Randomized Computation

CSC236 Week 3. Larry Zhang

CS 360, Winter Morphology of Proof: An introduction to rigorous proof techniques

Another Proof By Contradiction: 2 is Irrational

University of Toronto Department of Electrical and Computer Engineering. Final Examination. ECE 345 Algorithms and Data Structures Fall 2016

CHAPTER 6 - THINKING ABOUT AND PRACTICING PROPOSITIONAL LOGIC

Basics of Proofs. 1 The Basics. 2 Proof Strategies. 2.1 Understand What s Going On

!t + U " #Q. Solving Physical Problems: Pitfalls, Guidelines, and Advice

Midterm 1. Your Exam Room: Name of Person Sitting on Your Left: Name of Person Sitting on Your Right: Name of Person Sitting in Front of You:

Dynamic Programming. Data Structures and Algorithms Andrei Bulatov

Transcription:

Structural induction We now introduce a powerful method for proving claims about inductively-defined sets... In structural induction, the structure of the inductive proof (that every element of a set S has some property) follows the structure of the inductive definition (of S). For instance, to prove that every binary tree T (over A) has a property P, we would simply argue that P( ), and for all binary trees L and R (and all x A), if P(L) and P(R), then P( L, x, R ). (Compare the structure of this argument to the structure of the inductive defn of the set of binary trees over A.)

Soundness of structural induction Let S be an inductively-defined set. Let P(x) be a property of x. Claim. To show that, for all x S, P(x), it suffices to show that: Basis: For all initial elements x of S, P(x). Induction: For each construction rule using elements x 1,..., x k of S to construct an element x, show that if P(x 1, ),..., P(x k ), then P(x). Let s verify the soundness of this claim... So assume that we can meet the obligations of the proof by structural induction described above. What we ll show is that the set S P = { x x S, P(x) } satisfies both the basis and induction parts of the inductive definition of S. It follows that S P is a superset of S (WHY?), and so that, for every x S, P(x).

Let S be an inductively-defined set. To prove P(x) for all x S, it suffices to show that: Basis: For all initial elements x of S, P(x). Induction: For each construction rule using elements x 1,..., x k of S to construct an element x, show that if P(x 1, ),..., P(x k ), then P(x). Assuming that we can meet the proof obligations given above, we can show that it follows that the set S P = { x x S, P(x) } satisfies both the basis and induction parts of the inductive definition of S. [Hence, S S p. Thus, for all x S, P(x).] Notice first that the basis part of the structural induction proof establishes that S P satisfies the basis part of the inductive definition of S. (That is, all initial elements of S have property P, and so belong to S p.) The inductive part of the structural induction proof establishes that, for any x 1,..., x n S p, if x can be constructed from x 1,..., x n (according to the inductive definition of S), then x S P. (So S P also satisfies the induction part of the defn of S.)

Structural induction example 1 Let BT be the set of binary trees over A, and consider the function f : BT N defined recursively as follows. f ( ) = 0 j 1, if L = R = f ( L, x, R ) = f (L) + f (R), otherwise Prove: For all T BT, f (T ) is the number of leaves in T. By structural induction on T. Basis: f ( ) = 0, which is the number of leaves in. Induction: L, R BT, x A. IH: f (L) is the number of leaves in L and f (R) is the number of leaves in R. NTS: f ( L, x, R ) is the number of leaves in L, x, R. Subcase 1: L = R = In this subcase, the number of leaves in L, x, R is 1 = f ( L, x, R ). Subcase 2: Otherwise. Here, the number of leaves in L, x, R is the number of leaves in L plus the number of leaves in R, which, by IH, is exactly f (L) + f (R) = f ( L, x, R ).

Structural induction example 2 Claim: For every binary tree T over A, 2 depth(t )+1 nodes(t ) + 1. Proof by structural induction (on the inductive definition of BT over A). Basis: 2 depth( )+1 = 1 = nodes( ) + 1. Induction: L, R BT, and x A. IH: 2 depth(l)+1 nodes(l) + 1 and 2 depth(r)+1 nodes(r) + 1. NTS: 2 depth( L,x,R )+1 nodes( L, x, R ) + 1. 2 depth( L,x,R )+1 = 2 2 depth( L,x,R ) = 2 2 max(depth(l),depth(r))+1 (defn depth) = 2 2 max(depth(l)+1,depth(r)+1) = 2 max(2 depth(l)+1, 2 depth(r)+1 ) 2 max(nodes(l) + 1, nodes(r) + 1) (IH) = (2 max(nodes(l), nodes(r))) + 2 (nodes(l) + nodes(r)) + 2 = (nodes(l) + nodes(r) + 1) + 1 = nodes( L, x, R ) + 1 (defn nodes)

Another structural induction example Recall: For any alphabet A, A can be defined inductively as follows: Basis: Λ A. Induction: If x A and a A, then ax A. And here s a recursively defined function we ve discussed before: Take r : A A s.t. r(λ) = Λ r(ax) = r(x)a (x A, a A) Claim: For all x, y A, r(xy) = r(y)r(x). Hmmm, should we induct on x or on y? You can try it both ways. One way is much nicer...

For any alphabet A, A is defined inductively as follows: Basis: Λ A. Induction: If x A and a A, then ax A. Take r : A A s.t. r(λ) = Λ r(ax) = r(x)a (x A, a A) Claim: For all x, y A, r(xy) = r(y)r(x). Take an arbitrary y A. We ll prove, by structural induction on the inductive defn of A, that for all x A, Basis: Induction: x A, a A IH: r(xy) = r(y)r(x) NTS: r(axy) = r(y)r(ax) r(xy) = r(y)r(x). r(λy) = r(y) = r(y)λ = r(y)r(λ) (defn r) r(axy) = r(xy)a (defn r) = r(y)r(x)a (IH) = r(y)r(ax) (defn r)

Format for structural induction proof In this class, please use the format of the previous example for proofs by structural induction. Essential elements: Identify the claim you are proving by structural induction. It should be a claim about all elements of some inductively-defined set. Say it is proof by structural induction, and clearly indicate the inductive definition on which the proof is based. Clearly label basis and induction cases as such. In the induction case, state IH and NTS. Clearly indicate where and how the IH is used.

Proving correctness of the insert function Recall the inductive definition of lists(a): Basis: Induction: lists(a). If x A and L lists(a), then x :: L lists(a). Recall also the following recursive definition of a function from N lists(n ) to lists(n ): insert(x, ) = x j x :: y :: L, if x y insert(x, y :: L) = y :: insert(x, L), otherwise Claim: For all L lists(n ), for all x N, if L is sorted, then insert(x, L) is a sorted permutation of x :: L. We previously discussed the idea for an argument proving this claim. The idea of that argument can be made precise using structural induction on L. Consider any x N. We ll show that, for all L lists(n ), if L is sorted, then insert(x, L) is a sorted permutation of x :: L.

insert(x, ) = x j x :: y :: L insert(x, y :: L) = y :: insert(x, L), if x y, otherwise We ll show that, for all L lists(n ), if L is sorted, then insert(x, L) is a sorted permutation of x :: L. Proof by structural induction on L. Basis: insert(x, ) = x, which is a sorted permutation of x :: = x. Induction: L lists(n ), y N. IH: If L is sorted, then insert(x, L) is a sorted permutation of x :: L. NTS: If y :: L is sorted, then insert(x, y :: L) is a sorted permutation of x :: y :: L. Assume y :: L is sorted. Consider two cases: Case 1: x y. Then insert(x, y :: L) = x :: y :: L. Since y :: L is sorted and x y, x :: y :: L is also sorted. And of course x :: y :: L is a permutation of x :: y :: L.

insert(x, ) = x j x :: y :: L insert(x, y :: L) = y :: insert(x, L), if x y, otherwise Case 2: x > y. So insert(x, y :: L) = y :: insert(x, L). Since y :: L is sorted (by assumption), so is L. So by IH we can conclude that insert(x, L) is a sorted permutation of x :: L. It follows easily that y :: insert(x, L) is a permutation of x :: y :: L. And to see that y :: insert(x, L) is sorted, it is enough to check that every element of insert(x, L) is at least y, since we already know that insert(x, L) is sorted. This is easy to check... Notice first that since y :: L is sorted, every element of L is at least y. We also know that x is at least y. So every element of x :: L is at least y, and since insert(x, L) is a permutation of x :: L, we can conclude that every element of insert(x, L) is at least y.

Proving correctness of the sort function Recall the following recursively-defined function, from lists(n ) to lists(n ): sort( ) = sort(x :: L) = insert(x, sort(l)) Given the previous result for insert, we can prove that for all L lists(n ), sort(l) is a sorted permutation of L. By structural induction on (the inductive definition of) L. Basis: sort( ) =, which is a sorted permutation of itself. Induction: L lists(n ), x N. IH: sort(l) is a sorted permutation of L. NTS: sort(x :: L) is a sorted permutation of x :: L. Notice that sort(x :: L) = insert(x, sort(l)), and it remains only to show that insert(x, sort(l)) is a sorted permutation of x :: L. By IH, sort(l) is a sorted permutation of L. Since sort(l) is sorted, we know by the result from the previous problem that insert(x, sort(l)) is a sorted permutation of x :: sort(l), and it remains only to observe that x :: sort(l) is in turn a permutation of x :: L, which is true since sort(l) is a permutation of L.

Remarks on these last two correctness proofs The previous two problems are similar to Problem 12, Section 4.4 in the textbook. But the textbook s version of these problems does not give an adequate account of correctness of the sort and insert functions. Let me elaborate... About insert, the textbook asks you to prove that insert(x, L) is sorted if L is. If you try to do that in a straightforward fashion by structural induction on L, you will likely fail. (Or at least you should!) Why? Because at a key point in the proof, you will need to conclude from the assumption (via IH) that insert(x, L) is sorted that y :: insert(x, L) is also sorted. But it doesn t follow that easily. As it turns out, you need to know more about insert(x, L) in particular, you need to know that every element of insert(x, L) is at least y, and although this is indeed the case, it does not follow from the IH. This is one reason why we needed to talk about permutations...

Interestingly, the insert function does have the correctness property that the textbook mentions: if L is sorted, then insert(x, L) is sorted. Indeed, this is an immediate consequence of the result we proved above. There we considered the stronger claim that if L is sorted, then insert(x, L) is a sorted permutation of x :: L. This stronger property is better for proof by induction because we get to make use of the correspondingly stronger IH. But the textbook s version of correctness for the insert function is inappropriate for another reason. It is intuitively wrong, because it provides an inadequate characterization of correctness for an insert function. Can you see why?

To see the difficulty more starkly, suppose that we define a much simpler version of the function: for all x N and L lists(n ), insert(x, L) =. This constant function is intuitively wrong; nonetheless, it has the property that the textbook uses to characterize correctness. That is, it satisfies the claim of problem 12b, that if L is sorted, then so is insert(x, L). By the way, you can see that similarly it would not be sufficient to say that what we require of sort(l) is that it be sorted, for every L lists(n ). And yet that is all that is proved in the textbook s solution to 12a!

A general conclusion to draw from this discussion is that it is difficult to give adequate specifications concerning correctness of functions (or, say, software). It is generally hard to make our requirements sufficiently explicit. (That is not to say that it isn t worth doing!) Another, more technical conclusion is that in proofs by induction, it is often the case that stronger claims are easier to prove (because you get a stronger induction hypothesis).