Reading and Writing Mathematical Proofs Spring 2016 Lecture 1: Basic Proving Techniques I.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science for Some.
Advertisements

Introduction to Proofs
Theory Of Automata By Dr. MM Alam
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Axiomatic systems and Incidence Geometry
Copyright © Cengage Learning. All rights reserved.
13.4 Map Coloring and the Four Color Theorem. We started this chapter by coloring the regions formed by a set of circles in the plane. But when do we.
ISBN Chapter 3 Describing Syntax and Semantics.
Last time: terminology reminder w Simple graph Vertex = node Edge Degree Weight Neighbours Complete Dual Bipartite Planar Cycle Tree Path Circuit Components.
Induction: One Step At A Time Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 4Jan 22, 2004Carnegie Mellon University.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
1 Introduction to Computability Theory Lecture12: Reductions Prof. Amos Israeli.
Proof Points Key ideas when proving mathematical ideas.
CS 536 Spring Global Optimizations Lecture 23.
CSE115/ENGR160 Discrete Mathematics 02/07/12
Logic: Connectives AND OR NOT P Q (P ^ Q) T F P Q (P v Q) T F P ~P T F
So far we have learned about:
Proofs, Recursion and Analysis of Algorithms Mathematical Structures for Computer Science Chapter 2.1 Copyright © 2006 W.H. Freeman & Co.MSCS SlidesProofs,
Describing Syntax and Semantics
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
TR1413: Discrete Mathematics For Computer Science Lecture 1: Mathematical System.
Prof. Bodik CS 164 Lecture 16, Fall Global Optimization Lecture 16.
Algorithm Design and Analysis (ADA)
Proof Methods.
C OURSE : D ISCRETE STRUCTURE CODE : ICS 252 Lecturer: Shamiel Hashim 1 lecturer:Shamiel Hashim second semester Prepared by: amani Omer.
Methods of Proof & Proof Strategies
Intro to Discrete Structures
Reading and Writing Mathematical Proofs Spring 2014 Lecture 1: Proofs in Textual Form.
The Forward-Backward Method The First Method To Prove If A, Then B.
7 Graph 7.1 Even and Odd Degrees.
Nattee Niparnan. Easy & Hard Problem What is “difficulty” of problem? Difficult for computer scientist to derive algorithm for the problem? Difficult.
Reading and Writing Mathematical Proofs Autumn 2015 Lecture 1: Proofs in Textual Form.
Introduction to Proofs
Reading and Writing Mathematical Proofs
MATH 224 – Discrete Mathematics
Mathematical Arguments and Triangle Geometry
1 Inference Rules and Proofs (Z); Program Specification and Verification Inference Rules and Proofs (Z); Program Specification and Verification.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 2: Basic Proving Techniques.
1 Put your name if you want your attendance credit. Please put your as well. CSC 320 is done at 11:30 so I did NOT fill in the box for 11:30 for.
Introduction to Problem Solving. Steps in Programming A Very Simplified Picture –Problem Definition & Analysis – High Level Strategy for a solution –Arriving.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Euclid and the “elements”. Euclid (300 BC, 265 BC (?) ) was a Greek mathematician, often referred to as the "Father of Geometry”. Of course this is not.
Theory of Computation, Feodor F. Dragan, Kent State University 1 TheoryofComputation Spring, 2015 (Feodor F. Dragan) Department of Computer Science Kent.
Copyright © Cengage Learning. All rights reserved.
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.
COMPSCI 102 Discrete Mathematics for Computer Science.
CSE373: Data Structures and Algorithms Lecture 2: Proof by Induction Linda Shapiro Winter 2015.
CS104:Discrete Structures Chapter 2: Proof Techniques.
Copyright © Cengage Learning. All rights reserved. Sequences and Series.
Great Theoretical Ideas in Computer Science for Some.
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.
COMPSCI 102 Introduction to Discrete Mathematics.
Section 1.7. Definitions A theorem is a statement that can be shown to be true using: definitions other theorems axioms (statements which are given as.
CSE 311 Foundations of Computing I Lecture 8 Proofs Autumn 2012 CSE
Reading and Writing Mathematical Proofs Spring 2016 Lecture 2: Basic Proving Techniques II.
COMPSCI 102 Introduction to Discrete Mathematics.
Analyze Conditional Statements Objectives: 1.To write a conditional statement in if-then form 2.To write the negation, converse, inverse, and contrapositive.
Section 1.7. Section Summary Mathematical Proofs Forms of Theorems Direct Proofs Indirect Proofs Proof of the Contrapositive Proof by Contradiction.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Proof And Strategies Chapter 2. Lecturer: Amani Mahajoub Omer Department of Computer Science and Software Engineering Discrete Structures Definition Discrete.
Chapter 1 Logic and Proof.
The Foundations: Logic and Proofs
Trigonometric Identities
Trigonometric Identities
The Foundations: Logic and Proofs
This Lecture Substitution model
Copyright © Cengage Learning. All rights reserved.
Foundations of Discrete Mathematics
Presentation transcript:

Reading and Writing Mathematical Proofs Spring 2016 Lecture 1: Basic Proving Techniques I

Organization The required stuff…

Organization Lecturer: Arthur van Goethem MSc, MF 4.144, Web page:Part of Data Structures Book:Daniel Solow. How to Read and Do Proofs (5th edition) not mandatory

Schedule Only 4 lectures

Prerequisites Not covered Logical inferences Logical derivations (flag proofs) In other words: Logic and Set Theory (2IT60) Covered Mathematical proofs in common English Common proof techniques (proof by contradiction, induction, etc.) Common errors Many proof examples

Reading and Writing Mathematical Proofs Today on:

Basic Proving Techniques I Today on: The proving cookbook…

Today: “How to properly slap your sidekick.” “Really poorly drawn circles!” “Proving my hamsters are strange.”

What is a proof? Why explanations are not proofs…

What is a proof? A method for establishing truth What establishes truth depends on context PhysicsSufficient experimental evidence CourtroomAdmissible evidence and witness testimony Mathematical proofNot a doubt possible!

What is a proof? A form of communication Proof must convince reader (not the writer!) of correctness Proofs must be:  Clearly written Should be easy to follow Very different from “proving process”  Very precise No ambiguities!  Leaving no doubts

What is a proof? Clearly written “We turn the solution into an array. We invert the graph and then it look like the array. Because the solution can be an inverted graph and the array is input, the solution exists.” Very precise “We use Depth-First-Search to find some nodes that are too deep and somehow form the solution.” Leaving no doubts “In most cases it is the case that this conversion works. As we only have the best cases we likely can always perform this conversion.”

Definition Mathematical proof A convincing argument for the reader to establish the correctness of a mathematical statement without any doubt.

= 9 Definition Mathematical proof A convincing argument for the reader to establish the correctness of a mathematical statement without any doubt. Statement must be true or false

Definition Mathematical proof A convincing argument for the reader to establish the correctness of a mathematical statement without any doubt. In what format should a proof be?

Logical derivation Good Very systematic Hard to make mistakes Bad Not convenient for statements not stated in logical formulas Emphasis on logical reasoning → detract from crux argument Hard to read Cumbersome

Common English Theorem If x is odd, then x 2 is odd Proof Since x is odd, there exists a k ℤ such that x = 2k + 1. Then, x 2 = (2k + 1) 2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1 = 2m+1. As there exists a m ℤ such that x 2 = 2m + 1, x 2 is odd. □ Good Short and to the point Easy to read Bad Logical reasoning somewhat hidden Natural language can be ambiguous This is the kind of proof we expect in Data Structures!

Two Proof Formats This is what you should write down This should be in the back of your mind Theorem If x is odd, then x 2 is odd Proof Since x is odd, there exists a k ℤ such that x = 2k + 1. Then, x 2 = (2k + 1) 2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1 = 2m+1. As there exists a m ℤ such that x 2 = 2m + 1, x 2 is odd. □

Two Proof Formats Must be able to translate: Logic ↔ English Theorem If x is odd, then x 2 is odd Proof Since x is odd, there exists a k ℤ such that x = 2k + 1. Then, x 2 = (2k + 1) 2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1 = 2m+1. As there exists a m ℤ such that x 2 = 2m + 1, x 2 is odd. □

Logic and Ambiguities The stuff that is kind of doing that thing…

Logic?

Logic vs. English LogicEnglish P ⋀ Q P and Q Both P and Q P ⋁ Q P or Q careful…. ¬P ¬( P ⋁ Q) not P doesn’t hold, cannot neither P nor Q

Logic vs. English LogicEnglish P ⇒ Q P implies Q If P, then Q P ⇔ Q P is equivalent to Q P if and only if Q P iff Q For P ⇒ Q: ¬Q ⇒ ¬ P (equivalent) Q ⇒ P (not equivalent!) contrapositive converse

Ambiguities Do you want beer or water? Do you want beer or water or both? (or) OR Do you want either beer or water? (exclusive-or) If you can solve any problem we pose, then you ace the course If you can solve some problem we pose, then you ace the course OR If you can solve all problems we pose, then you ace the course Always avoid ambiguities!

Detail What to describe and what not

Definition Mathematical proof A convincing argument for the reader to establish the correctness of a mathematical statement without any doubt. How detailed should a proof be?

A Simple Proof Theorem Two distinct circles can have at most two intersection points.

A Simple Proof Theorem Two distinct circles can have at most two intersection points. Proof For the sake of contradiction, assume that two distinct circles C 1 and C 2 have (at least) three intersection points p 1, p 2, and p 3. Note that p 1, p 2, and p 3 must lie on both C 1 and C 2. But, three points on a circle uniquely define the circle. Thus, C 1 = C 2. Contradiction! □

A Simple Proof Theorem Two distinct circles can have at most two intersection points. Proof For the sake of contradiction, assume that two distinct circles C 1 and C 2 have (at least) three intersection points p 1, p 2, and p 3. Note that p 1, p 2, and p 3 must lie on both C 1 and C 2. But, three points on a circle uniquely define the circle. Thus, C 1 = C 2. Contradiction! □

A Simple Proof Theorem Two distinct circles can have at most two intersection points. Proof For the sake of contradiction, assume that two distinct circles C 1 and C 2 have (at least) three intersection points p 1, p 2, and p 3. Note that p 1, p 2, and p 3 must lie on both C 1 and C 2. But then the center of C 1 (and C 2 ) must be at the intersection of the bisector of p 1 and p 2, and the bisector of p 2 and p 3. Since the bisectors are lines, and two lines intersect only once, this uniquely defines the center (and radius) of both C 1 and C 2.Thus, C 1 = C 2. Contradiction! □

A Simple Proof Theorem Two distinct circles can have at most two intersection points. Proof For the sake of contradiction, assume that two distinct circles C 1 and C 2 have (at least) three intersection points p 1, p 2, and p 3. Note that p 1, p 2, and p 3 must lie on both C 1 and C 2. But then the center of C 1 (and C 2 ) must be at the intersection of the bisector of p 1 and p 2, and the bisector of p 2 and p 3. Since the bisectors are lines, and two lines intersect only once, this uniquely defines the center (and radius) of both C 1 and C 2.Thus, C 1 = C 2. Contradiction! □

Proof Detail When is a proof detailed enough?  What will the reader accept as true statements  More detail results in “more obvious” statements…  … but is also much longer  A good proof must find the right balance

Axiomatic System Axiom A simple statement assumed to be true Which axioms are you allowed to use? ‘Anything’ from high school math (middelbare school) Anything covered in class If you are unsure, just ask! Exception: If you are asked to prove a statement, the statement itself can never be used as an axiom

Axioms in this Course Exception : If you are asked to prove a statement, the statement itself can never be used as an axiom

Practice What are the axioms? Theorem If x is odd, then x 2 is odd Proof Since x is odd, there exists a k ℤ such that x = 2k + 1. Then, x 2 = (2k + 1) 2 = 4k 2 + 4k + 1 = 2(2k 2 + 2k) + 1. Thus, x 2 is odd. □

Analogy Proving process

Analogy Written proof

Analogy The Maze Analogy entrance/premise exit/goal Proving process Find path between entrance and exit Erratic, creative Written proof Give instructions for others to find path Stick to essentials

Proving Tips Tips for writing proofs 1. State the proof techniques you’re using (see next lecture) 2. Keep a linear flow Proving process different from written proof 3. Describe every step clearly in words 4. Don’t use complicated notation 5. Make sure your axioms are actually “obvious” What is obvious to you may not be obvious to the reader 6. Finish your proof Connect everything with what you were trying to prove

Practice

Practice Proofs Theorem (handshaking lemma) For any graph G=(V, E) the number of vertices with odd degree is even.

Practice Proofs Theorem (handshaking lemma) Consider a group of people shaking hands with each other (but not necessarily with everyone). The number of people that shook hands with an odd number of people is even.

Practice Proofs Theorem (handshaking lemma) For any graph G=(V, E) the number of vertices with odd degree is even. Proof Consider the sum of the degrees of all vertices: Σ v d(v). This sum counts every edge exactly twice. Thus the sum is 2*|E|, which is even. Vertices with an even degree do not affect the parity of this sum. Hence, if V’ is the set of vertices with odd degree, then Σ v V’ d(v) must also be even. Since the sum of an odd number of odd numbers is odd, the sum Σ v V’ d(v) is even if and only if |V’| is even. □

Practice Proofs Theorem (Pythagoras) For a right triangle T with side lengths x, y, and z (x ≤ y ≤ z ), it holds that x 2 + y 2 = z 2.

Practice Proofs Theorem (Pythagoras) For a right triangle T with side lengths x, y, and z (x ≤ y ≤ z ), it holds that x 2 + y 2 = z 2. Proof Seems tricky… Let’s try to prove something simpler. What if x = y? Then the area of the triangle is x 2 /2. We need to prove that 2x 2 = z 2. So 4 triangles should together have area z 2. How about this configuration? z x y z zz z

Practice Proofs Theorem (Pythagoras) For a right triangle T with side lengths x, y, and z (x ≤ y ≤ z ), it holds that x 2 + y 2 = z 2. Proof Let’s return to the general case. What happens if we again try to form a square with side length z? We get a hole in the middle which seems to be a square. We may have enough for a proof here… z x y z z z z

Practice Proofs Theorem (Pythagoras) For a right triangle T with side lengths x, y, and z (x ≤ y ≤ z ), it holds that x 2 + y 2 = z 2. Proof Consider the configuration of four copies of T shown in the figure. Note that, for a right triangle, the sum of the non-right angles is 90 °, since the sum of all angles is 180°. Hence, the outer shape is a square with side length z and has area z 2. The area of a single triangle is xy/2. Because T is a right triangle, the middle hole is also a square with side length (y - x) and area (y - x) 2. We thus obtain: z 2 = 2xy + (y - x) 2 = x 2 + y 2. □ z z z z

Basic Proving Techniques Proving 101…

Overview Basic Proving Techniques

Overview Basic Proving Techniques 1. Forward-backward method 2. Mathematical induction 3. Case analysis 4. Proof by contradiction

Forward-Backward Method How to get from A to B and B to A…

Forward-Backward Method The most basic approach Logically combine axioms, definitions, and earlier theorems (forward) Simplify the goal (backward) This should always be your default approach FACTS GOAL

When to use? Generally used for statements of the form: If P then Q Reason forward from the premise Reason backward from the goal Usage PremiseGoal

Basic Example Theorem If my hamsters do excessive exercise, I will be tired in the morning. Proof My hamsters do excessive exercise They are running in their exercise wheel The exercise wheel is making noise Something is keeping me awake I do not get a good night’s sleep I am tired in the morning

Example

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof What does f(n) = O(g(n)) mean again? There exist positive constants c and n 0 such that f(n) ≤ c g(n) for all n ≥ n 0.

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. We must be very careful with variables! Use different names!

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0.

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. To establish this, we need to find suitable values for c and n 0.

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. To establish this, we need to find suitable values for c and n 0. We already are given constants c’, c’’, n 0 ’, and n 0 ’’.

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. To establish this, we need to find suitable values for c and n 0. We already are given constants c’, c’’, n 0 ’, and n 0 ’’. Note that f 1 (n)f 2 (n) ≤ c’g 1 (n) c’’g 2 (n) = c’ c’’ g 1 (n)g 2 (n),

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. To establish this, we need to find suitable values for c and n 0. We already are given constants c’, c’’, n 0 ’, and n 0 ’’. Note that f 1 (n)f 2 (n) ≤ c’g 1 (n) c’’g 2 (n) = c’ c’’ g 1 (n)g 2 (n), but only if n ≥ n 0 ’ and n ≥ n 0 ’’. So n ≥ n 0 should imply n ≥ n 0 ’ and n ≥ n 0 ’’.

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. Let n 0 = max(n 0 ’, n 0 ’’) and c = c’ c’’. Then, for all n ≥ n 0 (which implies n ≥ n 0 ’ and n ≥ n 0 ’’), f 1 (n)f 2 (n) ≤ c’ g 1 (n) c’’ g 2 (n) = c’ c’’ g 1 (n) g 2 (n) = c g 1 (n) g 2 (n). We have f 1 (n)f 2 (n) ≤ c g 1 (n) g 2 (n) for all n ≥ n 0. Thus, f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)). □

Another Example Theorem If f 1 (n) = O(g 1 (n)) and f 2 (n) = O(g 2 (n)), then f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)) Proof By definition there exist positive constants c’ and n 0 ’ such that f 1 (n) ≤ c’ g 1 (n) for all n ≥ n 0 ’. Similarly, there exist positive constants c’’ and n 0 ’’ such that f 2 (n) ≤ c’’ g 2 (n) for all n ≥ n 0 ’’. We need to show that there exist positive constants c and n 0 such that f 1 (n)f 2 (n) ≤ c g 1 (n)g 2 (n) for all n ≥ n 0. Let n 0 = max(n 0 ’, n 0 ’’) and c = c’ c’’. Then, for all n ≥ n 0 (which implies n ≥ n 0 ’ and n ≥ n 0 ’’), f 1 (n)f 2 (n) ≤ c’ g 1 (n) c’’ g 2 (n) = c’ c’’ g 1 (n) g 2 (n) = c g 1 (n) g 2 (n). We have f 1 (n)f 2 (n) ≤ c g 1 (n) g 2 (n) for all n ≥ n 0. Thus, f 1 (n)f 2 (n) = O(g 1 (n)g 2 (n)). □

Mathematical Induction An introduction to induction…

Recurring structures Many algorithms and (data)structures have recurrences  Loop  List  Tree sum = 0 for i = 1 to A.length do sum = sum + A[i]

The Idea P(1)P(2)P(3)P(2)P(n) …

Usage

Basic Example

Example

Practice 1

Practice 2

Loop Invariant An introduction to proving loops…

Loop Invariant What do we want? How do we prove something is true at the end? What do we really know? sum = 0 for i = 1 to A.length do sum = sum + A[i]

Loop Invariant What do we really know? sum = 0 for i = 1 to A.length do sum = sum + A[i]

Loop Invariant What do we really know? sum = 0 for i = 1 to A.length do sum = sum + A[i]

Loop Invariant What do we really know? sum = 0 for i = 1 to A.length do sum = sum + A[i] Not an Axiom!!

Loop Invariant What do we really know? sum = 0 for i = 1 to A.length do sum = sum + A[i]

Loop Invariant

Loop Invariants replicate the chain of logical derivations To prove a statement is true at the end, we need..  Invariant(What remains true)  Initialization (Starting conditions)  Maintenance (Making sure it remains true)  Termination (Ending conditions)

Basic Example sum = 0 for i = 1 to A.length do sum = sum + A[i]

Basic Example sum = 0 for i = 1 to A.length do sum = sum + A[i]

Basic Example sum = 0 for i = 1 to A.length do sum = sum + A[i]

Basic Example sum = 0 for i = 1 to A.length do sum = sum + A[i]

Reading and Writing Mathematical Proofs Next time on:

Next time! “Proving Teletubbies are unlikable!” “How to prove you are cool (and own a Ferrari).” “How to store way too many pigeons.”