General Announcements Project Due Friday, 1/30 Labs start Wednesday & Thursday – Java review – Weiss 1.19, 1.20 – You may show up & hand in Workshops.

Slides:



Advertisements
Similar presentations
1.1The Principle of Mathematical Induction 1.2Divisibility Chapter Summary Case Study Mathematical Induction 1.
Advertisements

Reasoning About Code; Hoare Logic, continued
Self-Reference - Induction Cmput Lecture 7 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this lecture is.
DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2004.
Lecture 12 Oct 13, 2008 Some simple recursive programs recursive problem solving, connection to induction Some examples involving recursion Announcements.
ITERATION CSC 171 FALL 2004 LECTURE 10. Simple Branching If (test){ A;} start end A; test.
DATA STRUCTURES INTRODUCTION CSC 172 SPRING 2002.
TR1413: INTRO TO DISCRETE MATHEMATICS LECTURE 2: MATHEMATICAL INDUCTION.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
analysis, plug ‘n’ chug, & induction
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Algorithm Design and Analysis (ADA)
Great Theoretical Ideas in Computer Science for Some.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Murali Sitaraman
MATH 224 – Discrete Mathematics
Reading and Writing Mathematical Proofs
CSNB143 – Discrete Structure Topic 5 – Induction Part I.
Discrete Maths Objective to introduce mathematical induction through examples , Semester 2, Mathematical Induction 1.
1 CE 221 Data Structures & Algorithms Chapter 1 Introduction Text: Read Weiss, §1.1 – 1.3 Izmir University of Economics.
MATH 224 – Discrete Mathematics
CSE 311: Foundations of Computing Fall 2013 Lecture 8: More Proofs.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 19 : Recursion King Fahd University of Petroleum & Minerals College of Computer.
CSC201 Analysis and Design of Algorithms Asst.Proof.Dr.Surasak Mungsing Oct-151 Lecture 2: Definition of algorithm and Mathematical.
Introduction to Programming (in C++) Algorithms on sequences. Reasoning about loops: Invariants. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept.
10/14/ Algorithms1 Algorithms - Ch2 - Sorting.
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
CSC 172 DATA STRUCTURES. THEORETICAL BOUND  Many good sorting algorithms run in O(nlogn) time.  Can we do better?  Can we reason about algorithms not.
Computer Science School of Computing Clemson University Discrete Math and Reasoning about Software Correctness Joseph E. Hollingsworth
Discrete Maths: Induction/1 1 Discrete Maths Objective – –to introduce mathematical induction through examples , Semester
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.
Recursion. What is recursion? Rules of recursion Mathematical induction The Fibonacci sequence Summary Outline.
Introduction to Data Structures and Algorithms CS 110: Data Structures and Algorithms First Semester,
# ACS 168 Structured Programming Using the Computer Chapter 2 Spring 2002 Prepared by Shirley White.
CS101 Computer Programming I Chapter 4 Extra Examples.
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
Looping and Counting Lecture 3 Hartmut Kaiser
Recursive Algorithms &
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.
COMPSCI 102 Discrete Mathematics for Computer Science.
Inductive Reasoning Great Theoretical Ideas In Computer Science Victor AdamchikCS Spring 2010 Lecture 2Jan 14, 2010Carnegie Mellon University.
October 3, 2001CSE 373, Autumn Mathematical Background Exponents X A X B = X A+B X A / X B = X A-B (X A ) B = X AB X N +X N = 2X N 2 N +2 N = 2 N+1.
1/32 This Lecture Substitution model An example using the substitution model Designing recursive procedures Designing iterative procedures Proving that.
INDUCTION Slides of Ken Birman, Cornell University.
Copyright © Zeph Grunschlag, Induction Zeph Grunschlag.
COMPSCI 102 Introduction to Discrete Mathematics.
Section 8.4 Mathematical Induction. Mathematical Induction In this section we are going to perform a type of mathematical proof called mathematical induction.
Section 2.3 Mathematical Induction. First Example Investigate the sum of the first n positive odd integers. 1= ____ 1 + 3= ____ = ____
INDUCTION Lecture 22 CS2110 – Fall 2009 A well-known scientist (some say it was Bertrand Russell) once gave a public lecture on astronomy. He described.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Mathematical Induction I Lecture 19 Section 4.2 Mon, Feb 14, 2005.
Proof by Induction CSC 172 SPRING 2002 LECTURE 7.
Mathematical Induction. The Principle of Mathematical Induction Let S n be a statement involving the positive integer n. If 1.S 1 is true, and 2.the truth.
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
MSc/ICY Software Workshop , Semester 2
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2012
CSC 172 DATA STRUCTURES.
CSE 311: Foundations of Computing
CSE 20: Discrete Mathematics for Computer Science Prof. Shachar Lovett
Great Theoretical Ideas in Computer Science
This Lecture Substitution model
Mathematical Reasoning
Mathematical Induction
This Lecture Substitution model
Copyright © Cengage Learning. All rights reserved.
This Lecture Substitution model
Induction: One Step At A Time
Loop Invariants CSC 171 FALL 2001 LECTURE 6.
Useful GCD Fact If a and b are positive integers, then gcd(a,b) = gcd(b, a mod b) Proof: By definition of mod, a = qb+ (a mod b) for.
11.4 Mathematical Induction
Presentation transcript:

General Announcements Project Due Friday, 1/30 Labs start Wednesday & Thursday – Java review – Weiss 1.19, 1.20 – You may show up & hand in Workshops start Sunday – Why do we do workshops

WORKSHOPS “Analysts say tech employers today seek workers who are well educated in math and science but they also want them to have intangible skills, such as the ability to work well in teams.” -”New Tech Products Mean New Tech Jobs” -Brian Deagon, IBD, 1/20/04

PROOF IN COMPUTER SCIENCE CSC 172 SPRING 2004 LECTURE 2

Example Write a method to compute a n public static double power(int a, int n) You have 5 minutes

Possible solution public static double power(int a, int n) { double r = 1; double b = a; int i = n ; while (i>0){ if (i%2 == 0) { b = b * b; i = i / 2;} else { r = r * b; i--; } return r; }

Does it work? SURE! TRUST ME! Well, look at a 100 if you don’t believe me! – Note, less loops! Can you “prove” that it works? bir a1001 a2a2 50 a4a a4a4 a8a8 12 a 16 6 a a 36 a a 100

Loop invariants In order to verify loops we often establish an assertion (boolean expression) that is true each time we reach a specific point in the loop. We call this assertion, a loop invariant

Assertions When ever the program reaches the top of the while loop, the assertion is true INIT BODY TEST INVARIANT

What is the loop invariant? At the top of the while loop, it is true that r*b i = a n It is? – Well, at the top of the first loop r==1 b==a i==n

So, if it’s true at the start Even case r new = r old b new == (b old ) 2 i new ==(i old )/2 Therefore, – r new * (b new ) inew == r old * ((b old ) 2 ) iold/2 – == r old * ((b old ) 2 ) iold – == a n

So, if it’s true at the start II Odd case r new = r old *b old b new == b old i new ==i old -1 Therefore, – r new * (b new ) inew == r old *b old * (b old ) iold-1 – == r old * (b old ) iold – == a n

So, If it’s true at the start And every time in the loop, it remains true Then, it is true at the end r*b i = a n And, i == 0 ( the loop ended) What do we know?

Correctness Proofs Proof are more valuable than testing – Tests demonstrate limited correctness – Proofs demonstrate correctness for all inputs For some time, people hoped that all formal logic would replace programming The naïve idea that “programming is a form of math” proved to be an oversimplification

Correctness Proofs Unfortunately, in practice, these methods never worked very well. – Instead of buggy programs, – people wrote buggy logic Nonetheless, the approach is useful for program analysis

The take away message? In the end, engineering and (process) management are at least as important as mathematics and logic for the successful completion of large software projects

Example One dimensional pattern recognition Input: a vector x of n floating point numbers Output: the maximum sum found in any contiguous subvector of the input. X[2..6] or 187 How would you solve this?

Obvious solution Check all pairs int sum; int maxsofar = 0; for (int i = 0; i<x.length;i++) for (int j = i; j<x.length;j++){ sum = 0; for (int k = i;k<=j;k++) sum += x[k]; maxsofar = max(sum,maxsofar); }

An improved solution int maxSum = 0 ; for (int i = 0; i<a.length;i++) { int thisSum = 0; for (int j = i; j<a.length;j++){ thisSum += a[j]; if (thisSum > maxSum) maxSum = thisSum; } return maxSum;

How many loops ? int maxSum = 0 ; for (int i = 0; i<a.length;i++) { int thisSum = 0; for (int j = i; j<a.length;j++){ thisSum += a[j]; if (thisSum > maxSum) maxSum = thisSum; } return maxSum;

Total number of comparisons N + (N-1) + (N-2) Reversing N =

Prove In order to calculate work

Simple Induction Three Pieces 1. A statement S(n) to be proved The statement must be about an integer parameter n 2. A basis for the proof The statement S(b) for some specific integer b Often b==0 or b==1 3. An inductive step for the proof Show that “If S(n) is true, then S(n+1) must also be true” Prove the statement “S(n) implies S(n+1)” for any n. For this part, you get to “suppose” S(n) is true –“For the sake of argument” –Aka the inductive hypothesis

Prove: 1. Statement: S(n) : For any n>=1

Prove: 2. Basis Select n == 1

Prove: 2. Alternate Basis Select n == 2

Prove: 2. Alternate Basis Select n == 3

Prove: 3. Inductive Step Assume: To show:

Inductive Step We know, by definition: Rewrite it:

Inductive Step “By the Induction hypothesis” (we can make the following substitution)

Inductive Step The rest is just algebra

Which, of course, is what we set out to prove!

So, what did we do We showed that it worked for 1 And that if it worked for n, it must work for n+1 So, is it true for n==7? Why? Is it true for n== ?

Template for Simple Induction 1. State what S(n) is. 2. Explain what n represents. “any positive integer” or “length of the string” 3. Tell what the value of n is for the basis case n==b 4. Prove S(b) 5. State that you are assuming n>=b and S(n) 6. Prove S(n+1) using the assumptions (say: “B.T.I.H.”) 7. State that due to (4) and (6) you conclude S(n) for all n>=b

Interesting Aside: Visual Proof Proof is “convincing prose” Not all proof is “mathematical”

Visual Proof 123..n n

1..n/2..n n

Visual Proof 1..n/ n

Visual Proof 1..n/ n

Visual Proof 1..n/ n

Visual Proof 1..n/ n n+1

Visual Proof 1..(n+1)/2..n n