380 likes | 666 Views
Direct proof technique. The goal is to explain why some assertion is true. Formal proof: Sequence of statements Starts with some axiom (universally agreed-upon premise).
E N D
Direct proof technique • The goal is to explain why some assertion is true. • Formal proof: • Sequence of statements • Starts with some axiom (universally agreed-upon premise). • Remaining statements are further axioms, or derived statements based on earlier statements in the proof according to rules of valid argument/inference. (You may also use results of theorems proved elsewhere.) • Last statement is the theorem to be proved. • Our proofs will not be quite this formal. • Nevertheless: we need to begin by looking at relevant definitions, axioms and given information.
Technique • Follow advice in book • Steps: • Begin with given information • Apply definitions • Compare what you have with what you want. Experiment by manipulating this information, use related facts, with the goal in mind. • End with satisfying the desired property. • Let’s first look at some simple definitions • Odd and even numbers • Hint: if something looks hard to prove, maybe it’s false!
Example direct proof • “If the sum of 2 integers is even, then their difference is even.” • Incidentally, in symbols, the statement looks like this: x y (even(x + y) even(x – y)) • Here we go! Let x and y be integers such that x + y is even. By the definition of even, k such that x + y = 2k.Then, x – y = x + y – 2y = 2k – 2y = 2(k – y) and observe that k – y is an integer too. So, by definition, x – y is even because it’s 2 * (integer).
Divisibility • The symbol “|” means “divides”. We say that a | b if there exists some integer k such that ak = b. • Or we can say: b is a multiple of a. • Let’s use the direct proof technique for divisibility problems. It will sound like how we worked with even numbers, but more general. • Prove or disprove: • 3 divides the sum of any 3 consecutive integers • If a | b and b | c, then a | c. • If a | b and a | c, then a | (b + c). • If a | bc, then a | b or a | c. • If x and y are odd, then 6 | (3x + 3y).
Rational • A number is rational if it can be written of the form a / b, where • a and b are integers • a and b have no common factors • b is not 0 • Example: 7.5 is rational because we can let a = 15 and b = 2.
Rational opposite • Let’s show that: if x is rational, then –x is rational. • Since x is rational, x = a/b where a and b are integers with no common factors, and b is not 0. • By arithmetic, –x = –a/b. • We have to explain why –x satisfies the definition of rational. • Notice that both –a and b are integers. • If a and b have no common factors, then –a and b couldn’t have any common factors either. • b is still not zero. • We conclude that –x is rational.
Rational addition • If x and y are rational, then x+y is rational • According to the definition, let x = a/b and y = c/d. • x+y = (ad + bc) / bd • Since a, b, c and d are all integers, we can add and multiply integers to obtain more integers. Thus, (ad +bc) and bd are integers. • There is no common factor between (ad+bc) and bd. • Neither b nor d is zero. Thus, bd is not 0. • Conclusion: x+y satisfies the definition of rational number.
Proof practice • Floor and ceiling functions • Proof by contradiction • Iterative algorithms • What is the termination condition? • Application: Sequences and series
Floor and ceiling • Used to calculate phone bill, postage, and loop iterations • floor(x) = round down to the next lower integer • ceil(x) = round up to the next higher integer • Examples • floor() = 3, floor(–) = –4, floor(17) = 17 • ceil() = 4, ceil(–) = –3, ceil(17) = 17 • For which real numbers x is floor(x) equal to 2? • For which real numbers x is ceil(x) equal to 6?
Fractions • Often we need to take floor/ceil of a fraction. Can we derive formulas for floor(a/b) and ceil(a/b) ? Floor(a/b) = (a – a % b) / b Ceil(a/b) = (a + (b – a) % b) / b
Loop iteration formula • A for-loop (in C, C++ or Java) often has this general format: for (i = a; i <= b; i += s) • The number of loop iterations is floor((b – a)/s) + 1 • Example: for (i = 3; i <= 18; i += 5) // We execute when i = 3, 8, 13, 18.
Indirect proof • Common proof technique • Essentially, we show that the negation of the given statement is false. • Begin the proof by saying, “Suppose not.” The negation of the given statement gives us 1 extra piece of information. • During the proof, we arrive at a contradiction. Thus, we conclude that ~P is false; thus P must be true. • Example: • If I give 100 marbles to 23 people, then somebody must get at least 5.
Another example • “For all integers n, if n2 is even, then n is even.” • Proof by contradiction. • Assume the statement is false. Then there exists an integer n such that n2 is even and n is odd. Since n is odd, it may be written as n = (2k+1). Then n2 = (2k+1)2 = 4k2 + 4k + 1 = 2(2k2 + 2k) + 1. Since 2k2 + 2k is an integer, then n2 satisfies the definition of an odd number. We have reached a contradiction, since earlier we said n2 is even. Thus the original statement must be true. • Alternatively, can prove by contrapositive. The equivalent statement is: “… if n is odd, then n2 is odd.”
Irrational addition • If x is rational and y is irrational, then x+y is irrational. • Suppose not! • Then, we have that: x is rational, y is irrational, AND x+y is rational. • We already know that the sum of two rationals is rational, and that the opposite of a rational is rational. • Subtraction means adding the opposite. Thus, the difference of two rationals must be rational. • Notice that y = (x+y) – x. The two numbers (x+y) and x are rational. Therefore the difference, y, is rational. But this contradicts our earlier assumption that y is irrational! • Conclusion: The original statement must be correct.
Algorithm • Heart of any computer program • 2 kinds • Explicit formula: area of triangle, compute loan payment • Iterative computation: many examples! sorting an array listing prime numbers factorial GCF Square root Fibonacci
Closer look • Euclidean algorithm to compute GCF • Start with 2 numbers • Loop: Divide the smaller into the larger if remainder = 0, answer is the smaller else, continue with the smaller number and remainder • Square root of “a” • Start with an initial guess x0 • xn+1 = average of xn and a/xn • Stop when difference between 2 consecutive xi are sufficiently small.
Sequence and series • A sequence is essentially a list or array of values • A series is the sum of these values • Terms separated by “+” instead of “,” • Application: an operating system often needs to know the execution time of a computer program in order to best schedule that task. • A program’s execution time is largely dependent on loops! Especially nested loops. • We’ll use series formulas to calculate the number of iterations.
Notation • Sequence notation (like an array) • Can be explicit formula, as in: an = 4 + 3n • Or can be recursively defined, as in: a1 = 5 an+1 = 2an, n 1 • Series notation • a1 + a2 + a3 + a4 Too inefficient • Better to use Sigma notation
Applications • Sequence vs. series • Meaning of sigma notation • Common series formulas • Mathematical induction
Bernoulli formulas • Help us evaluate series, e.g. to count loop iterations • Nested loop can give rise to nested sigma expression
Example • Use Bernoulli formulas to determine the first hundred terms of (3)(7) + (5)(12) + (7)(17) + (9)(22) + … • First, write each term in terms of the term number, i Term formula = (2i + 1)(5i + 2) = 10i2 + 7i + 2 • Apply Bernoulli formulas.
How to check • If we say: sum(f(i)) = S(n), then we can check our sum answer this way: S(n) – S(n – 1) = f(n) • For example, consider f(i) = 6i. • The Bernoulli formula tells us that sum(f(i)) = 3n(n+1). • So, S(n) = 3n(n+1) • Work out S(n) – S(n – 1) = 3n(n+1) – 3(n – 1)n = 3n(n+1-(n – 1)) = 6n • The answer checks because f(n) = 6n equivalently means f(i) = 6i. • What would it look like if our summation formula is wrong? • The f(n) would not match the original term formula. • For example, we might have f(n) = 15n, but we originally wanted the summation of 6i, not 15i.
Inverse Bernoulli • Review: Bernoulli formulas are used to help us convert from a term formula to a summation formula for a series. • The way of checking summation formulas gives us an elegant way to calculate a term formula if we are given the summation formula. • Ex. Finding the sum of i32i is not easy. • Ex. But it is easy to find the term formula if we know if a series sum formula is n32n. Just plug in n and n – 1 and subtract! • In fact, doing S(n) – S(n – 1) can be used to guess an unknown summation formula.
Nested loop • Let’s count the operations in this nested loop. for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) // assume 3 stmts in body • Outer loop: • We do the i=1 once • We do the i<=n (n+1) times • We do the ++i n times. • Inner loop: • We enter the inner loop n times. Each time we have: (1 + (n+1) + n + 3n). • Total = 5n2 + 4n + 2 operations.
Nested loop #2 • Let’s change the inner loop bound to i for (i = 1; i <= n; ++i) for (j = 1; j <= i; ++j) // assume 3 stmts in body • Outer loop is still: 1 + (n+1) + n operations • Inner loop: • We enter the inner loop i times, where i could be 1 to n. For each i, we have: (1 + (i+1) + i + 3i). • So, we have to sum: 5i + 2. • Total = (5/2)n2 + (13/2)n + 2 operations.
Loop correctness • Eventually, we want to be able to show that our loops are correct • Powerful technique: Principle of Mathematical Induction • Useful for proving many assertions • Sum formulas • Linear-combination formulas • Divisibility questions • Inequalities • Correctness of loops
Induction • P(n) is a statement that should be true for all positive integers n, or more generally for integer values (some integer). • How to prove: • Show that P(1) is true. This is the “base case.” • Show that if P(k) is true for some k 1, then P(k+1) must also be true. This is the “inductive step.” • If you can do these two steps, then you can say: “Since P(1) is true and P(k) P(k+1) for an arbitrary k 1, then P(n) is true for all n 1.” • “domino effect”
Type I: Summations • Let’s first apply induction to verifying summation formulas. The key is to add the next term to both sides of the equation. • We’ll work out these examples: • n 1, 1 + 3 + 5 + 7 + … + (2n – 1) = n2 • n 1, 12 + 22 + 32 + … + n2 = n(n+1)(2n+1)/6 • n 1, 1(1!) + 2(2!) + 3(3!) + … n(n!) = (n+1)! – 1
Induction • Types of statements you’ll often see • Summations • Linear combination • Divisibility • Inequalities • Loop correctness
Type II: Linear formulas • n 24, x, y 0 such that n = 5x + 7y. • “Any integer n 24 can be expressed …” • Base case: if n = 24, then choose x = 2 and y = 2. • Next, assume P(k) is true. That is, k = 5x + 7y. • Now we need a similar formula for k+1. A table of values may help. • We see that if y 2, then k + 1 = 5(x + 3) + 7(y – 2) else k + 1 = 5(x – 4) + 7(y + 3) Two ways to add a penny: Trade away two 7’s for three 5’s, or Trade away four 5’s for three 7’s.
Try another • n 14, x, y 0 such that n = 3x + 8y. • “Any amount of postage 14 cents or higher can be achieved by using some combination of 3 and 8 cent stamps.” • The goal of the inductive step is to write alternate formulas for k+1: k + 1 = a(x + ___) + b(y – ___) k + 1 = a(x – ___) + b(y + ___) We have to give two formulas. Choose the appropriate formula to avoid a negative.
Type III: Divisibility • We want to show that: a | f(n) • Recall what our goal is: to go from P(k) to P(k+1) • One way to bridge the gap is to “subtract” P(k) from P(k+1) and verify that what results is true. Then add this residual to P(k) to conclude P(k+1). • For example, we may need to show that 5 | 6n – 1. The crux of the proof centers on f(n) = 6n – 1. Then: f(k) = 6k – 1 and f(k+1) = 6k+1 – 1, so that: f(k+1) – f(k) = (6k+1 – 1) – (6k – 1) = 6k+1 – 6k = 6k (6 – 1) = 5 * 6k. Note that this is divisible by 5. *** see handout
Alt approach • Alternative approach: write P(k+1) of the form: P(k+1) = x P(k) + y, where x and y are clearly multiples of a. • Often handy for multiple exponential terms. • Ex. For all positive integers, 4 | 3n + 7n – 2. In inductive step, we can write 3k+1 +7k+1 – 2 = 3*3k + (3+4)7k – 2 = 3*3k + 3*7k + 4*7k – 6 + 4 = 3(3k + 7k – 2) + 4(7k + 1)
Examples • For all positive integers n, 3n is odd. Sometimes we have a formula, and we want to be sure that it always evaluates to an integer. This turns out to be a divisibility problem in disguise. • For all positive integers n, (2/5)4n +(3/5)(–1)n is an integer.
Type IV: Inequalities • Purpose: Sometimes we want to know if one algorithm is more efficient than another. • The statement P(n) is of the form f(n) < g(n). • The “<“ could be some other relational operator, e.g. “”. • During the inductive step, to leap from P(k) to P(k+1), we need to verify either: • f(k+1) – f(k) < g(k+1) – g(k) or • f(k+1) / f(k) < g(k+1) / g(k) whichever is easier • Once you have established that inequality, then add or multiply to f(k) < g(k), as appropriate to conclude with f(k+1) < g(k+1). • Be careful to structure the proof so that you are not assuming what you are trying to prove.
Type V: loop correctness • Given a loop, and certain information about the loop: • Precondition • Invariant • Postcondition • For a loop to be correct, verify the following: • The precondition is true when the loop starts. • The invariant is true as we go from iter k to iter k+1. • The loop terminates. • The postcondition is true when the loop is done. • ***e.g. See handout (adding x 10 times yields 10x) • e.g. a loop that computes a summation of i2