Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities
COMPSCI 220 Math Background: Rounding, Logarithms, Proofs, . . .
Lecturer: Miika Hannula
1 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities
1 Rounding: d...e; b...c
2 Logarithms
3 Math proofs
4 Inequalities
2 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Rounding Real Numbers: Notation
Replacing a real number x with the closest integer: 1 Ceil notation: dxe rounds up to the nearest integer larger than or equal to x:
x + 1 > i = dxe ≥ x
• Examples: d3.2e = 4; d10.01e = 11; d10.99e = 11 2 Floor notation: bxc rounds down to the nearest integer smaller than or equal to x:
x − 1 < i = bxc ≤ x
• Examples: b3.2c = 3; b10.01c = 10; b10.99c = 10
3 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Exponential functions: ax
Exponential functions ax with the base a and the exponent x: • For an integer i and any real number a, ai is equal to a multiplied i times: ai ≡ a × a × ... × a. | {z } i factors a • However, i may be and, in fact, often is a real number. • Simple rules for exponential functions: 1 ax a−x = ; ax+y = ax · ay; ax−y = ;(ax)y = ax·y ax ay • Special case: ex where e is Euler’s (pronounced “Oil-ah”) constant (e ≈ 2.718 ...). • x d x x The function e is its own derivative: dx e = e . • Using the natural logarithm (see Slide 5), ln, all functions aκ are mapped into ex by setting x = κ ln a, because eln a = a.
4 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Logarithms: log y
x The inverse of exponential functions: if a = y, then loga y = x.
• loga y = x reads “x is the logarithm to base a of y”.
Logarithm to other base differs by a factor: loga y = loga b · logb y
y = aloga y = blogb y = ((aloga b)logb y = aloga b·logb y
Thus, the base is often neglected by writing log y instead of loga y.
Commonly used logarithms: • “logarithm to base 2” (in computing; lg in this course) • “logarithm to base 10” (in engineering) • “logarithm to base e ≈ 2.718 ...” (the “natural logarithm”): ln x always means loge x.
5 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Logarithms: log y
Simple rules for logarithms (from those for exponential functions):
loga(x · y) = loga x + loga y ⇒ log2(4 · 32) = log2 4 + log2 32 | {z } | {z } | {z } log 128 = 7 2 5 2 x 128 loga y = loga x − loga y ⇒ log2 = log2 128 − log2 4 4 | {z } | {z } | {z } 7 2 log2 32 = 5 y 10 loga(x ) = y · loga x ⇒ log2(32 ) = 10 log2 32 = 50 log y = 1 ⇒ log 2 = 1 = 0.2 a logy a 32 log2 32 log z log z = y ⇒ log 128 = log2 128 = 7 = 1.4 x logy x 32 log2 32 5 zlogx y = ylogx z ⇒ 128log2 32 = 32log2 128 = 235
6 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Systematic Analysis of Algorithms
Some COMPSCI 220 contexts use systematically, step-by-step, the established mathematical tools: definitions, lemmas, and theorems.
• A definition is used to make it clear what a certain term means, what we are going to call something, or how we will be using a certain notation. • A theorem is a statement we claim to be true, and it always requires a proof. • A lemma is like a small theorem that we prove to lead us up to the proof of a more extensive theorem. • As a general rule, we do not claim that something is true unless we can also prove it. • To find a statement is true, it should be either deduced (a direct proof), or proved by math induction or by contradiction.
7 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Mathematical Induction
Proves that some statement is true for all integers, such that n ≥ n0, where n0 is mostly a non-negative constant.
• If the proof should be for all non-negative integers, n0 = 0.
• If the proof should be for all positive integers, n0 = 1.
Proof by mathematical induction (or simply induction):
1 Basis: Prove that the statement is true for n0. 2 Induction hypothesis: Assume that the statement is true for some n. 3 Inductive step from n to n + 1: If the induction hypothesis holds, prove that the statement is also true for n + 1.
The inductive step completes the proof.
8 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Pn n(n+1) Example 1: The Gauss Formula i=1 i = 2 Prove by math induction that for all n ≥ 1, n X n(n + 1) S = 1 + 2 + ... + n ≡ i = n 2 i=1
1·2 1 Basis: For n0 = 1, the statement is correct: S1 = 1 = 2 . n(n+1) 2 Induction hypothesis: Let Sn = 2 hold for n, i.e., n(n + 1) 1 + ... + n = 2 3 Inductive step: Then n(n + 1) (n + 1)(n + 2) S = S + (n + 1) = + (n + 1) = n+1 n 2 2 Hence, the same formula holds for n + 1, so that the Gauss formula is valid for all n ≥ 1. 9 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Mathematical Induction: Example 2
2 2 2 n(n+1)(2n+1) Prove that Sn = 1 + 2 + ... + n = 6 for n ≥ 1. 1·2·3 1 Basis: For n0 = 1, the statement is correct: S1 = 1 = 6 . n(n+1)(2n+1) 2 Induction hypothesis: Let Sn = 6 hold for n, i.e., n(n + 1)(2n + 1) 12 + ... + n2 = 6
2 3 Inductive step: Then Sn+1 = Sn + (n + 1) =
n(n+1)(2n+1) 2 (n+1)[n(2n+1)+6(n+1)] 6 + (n + 1) = 6 =
(n+1)[2n2+7n+6] (n+1)(n+2)(2n+3) 6 = 6 i.e., the same formula holds for n + 1.
10 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Mathematical Induction: Example 3
2 n an+1−1 Prove that Sn = 1 + a + a + ... + a = a−1 for n ≥ 0 and a 6= 1 (partial sums for the geometric series with ratio a). a−1 1 Basis: For n0 = 0, the statement is correct: S1 = 1 = a−1 . an+1 2 Induction hypothesis: Let Sn = a−1 hold for n, i.e.,
an+1 − 1 1 + ... + an = a − 1
n+1 an+1−1 n+1 3 Inductive step: Then Sn+1 = Sn + a = a−1 + a
an+1 − 1 + an+2 − an+1 an+2 − 1 = = a − 1 a − 1 i.e., the same formula holds for n + 1.
11 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Proving a Statement by Contradiction
• A simple, but quite rare way: Find a counterexample. • More general framework: 1 Assume the statement is false. 2 Derive a logical contradiction from this assumption. 3 Conclude the assumption is wrong and the statement is true.
Example: Proof of the statement “There is no largest integer”.
• Assume there exists the largest integer itop. • Consider the number inext = itop + 1. • inext is integer as the sum of two integers. • Obviously, inext > itop, that contradicts the assumption. • Thus, the assumption is wrong, and the statement is true.
12 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Are all cars of the same colour?
K + 1 K
K “Proof” by a hidden error in using the math induction. • Base case: I have one car (K = 1) and it is green. • Inductive hypothesis. Let any subset of K cars; K ≥ 1, are of the same colour. • Inductive step. Park K cars in line and add my car to the end as the (K + 1)-th car. • Remove the first car: then the remaining intermediate cars and my car (K in total) are of the same colour, i.e., green. • Return the first car, but take away my car: once again these K cars are of the same colour as the intermediate cars. • Return my car to get K + 1 cars of the same colour. What is wrong? (hint: check the inductive step for K = 2)
13 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Inequalities, A Rel B, and their properties
Exactly one of three relationships: x < y (less than); x = y (equal to), or x > y (greater than) holds for any two real numbers x and y.
Rel Meaning Example x > y “x is greater than y” 5X + 15 > −25 x ≥ y “x is greater than or equal to y” −7X ≥ 28 x < y “x is less than y” 5X − 1 < 0 x ≤ y “x is less than or equal to y” 20X ≤ 1
• Transitivity: If x < y and y < z, then x < z. • Bias: if x < y and c is a real number, then x + c < y + c. • Positive scaling: If x < y and c > 0, then cx < cy. • Negative scaling: If x < y and c < 0, then cx > cy. The same properties hold for x ≤ y, x > y, and x ≥ y.
14 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Inequalities, A Rel B, and their properties
• Reversal: if x < y, then y > x. • Inverse: When x and y be both positive or both negative, it 1 1 1 1 holds that if x < y then x > y and if x > y then x < y . • Non-negative squares: x2 ≥ 0.
Solution of inequalities – getting numerical bound(s) for the unknown(s) on the left of the inequality symbol:
5X + 15 > −25 ⇒ X + 3 > −5 ⇒ X > −5 − 3 ⇒ X > −8 −7X ≥ 28 ⇒ X ≤ −4 5X − 1 < 0 ⇒ 5X < 1 ⇒ X < 0.2 20X ≤ 1 ⇒ X ≤ 0.05
In accord with this system of four inequalities: −4 ≥ X > −8.
15 / 16 Outline Rounding: d...e; b...c Logarithms Math proofs Inequalities Inequalities, A Rel B, and their properties
Solution steps that do not affect direction of inequality: • Adding a number to both sides: 5X + 15 > −25 ⇒ 5X > −25 − 15 ⇒ 5X > −40. • Scaling with a positive factor: 5X > −40 ⇒ X > −8 Solution steps that reverse direction of inequality: • Scaling with a negative factor: −7X ≥ 28 ⇒ X ≤ −4. • Swapping left- and right-hand sides: X ≤ −4 ⇒− 4 ≥ X.
Scaling could be done if the sign of the factor is known (thus - do not scale by an unknown variable): • Example: 5xy ≥ 15y cannot be solved if y is unknown. Systems of inequalities may have no solution: 5X > 10 and X < 0.
16 / 16