Spring 2018
Summary So far: Today: Logic and proofs Divisibility, modular arithmetics Number Systems More logic definitions and proofs Reading: All of Chap. 1 + Chap 4.1, 4.2.
Divisibility P = 5 divides 30 Q = 8 divides 10 R = 4 divides 2 Questions: Propositions P,Q,R are (A) T,T,T; (B) T,F,F; (C) F,T,F; (D) F,F,F
Divisibility P = 5 divides 30 Q = 8 divides 10 R = 4 divides 2 Questions: Propositions P,Q,R are (A) T,T,T; (B) T,F,F; (C) F,T,F; (D) F,F,F Definition An integer a divides an integer b (written a b), if there is an integer c such that (A) a = b c; (B) a b = c; (C) b/a = c; (D) b = a c;
Divisibility P = 5 divides 30 Q = 8 divides 10 R = 4 divides 2 Questions: Propositions P,Q,R are (A) T,T,T; (B) T,F,F; (C) F,T,F; (D) F,F,F Definition An integer a divides an integer b (written a b), if there is an integer c such that (A) a = b c; (B) a b = c; (C) b/a = c; (D) b = a c; Answer (D): (a b) c.b = a c. We also say that b is a multiple of a.
Transitivity Definition A binary relation R(x, y) is transitive if x, y, z.r(x, y) R(y, z) R(x, z). Questions: Is relation D(a, b) = (a b) transitive? (A) Yes; (B) No; (C) I don t know
Transitivity Definition A binary relation R(x, y) is transitive if x, y, z.r(x, y) R(y, z) R(x, z). Questions: Is relation D(a, b) = (a b) transitive? (A) Yes; (B) No; (C) I don t know Yes, it is transitive. In English: If x divides y, and y divides z, then x divides z.
Proving Transitivity of Theorem The divisibility relation D(a, b) = (a b) is transitive.
Proving Transitivity of Theorem The divisibility relation D(a, b) = (a b) is transitive. Proof We want to prove that for all integers a, b, c, if (x y) and (y z), then (x z). Let x, y, z be arbitrary integers Assume that (x y) and (y z). By definition, there exist an integer c such that y = cx an integer d such that z = dy It follows that there exists an integer b = dc such that So, x z. z = dy = d(cx) = (dc)x = bx.
Congruence Definition Two integers a, b are congruent modulo an integer m (written a m b) if m divides (a b). (a m b) m (a b) q.q m = a b Question: For what values of m 1 is the relation m transitive? (A) all m > 1; (B) all m 1; (C) all even m; (D) only for m = 2
Transitivity of m Theorem: For any integers a, b, c and positive integer m, if a m b and b m c, then a m c. Proof:
Transitivity of m Theorem: For any integers a, b, c and positive integer m, if a m b and b m c, then a m c. Proof: 1. Let m, a, b, c be arbitrary integers, with m 1. 2. Assume a m b and b m c 3. By definition, there exist integers x, y such that mx = a b and my = b c 4. Adding up the last two equations gives mx + my = (a b) + (b c) = a c 5. Therefore, mz = a c for z = x + y. 6. This proves that a m c
Division Theorem Theorem (Division Theorem) For any integer a and positive integer b > 0 there exists a (unique) pair of integers (q, r) such that a = qb + r and 0 r < b. Vocabulary: a: dividend; b: divisor; q: quotient; r: reminder.
Division Theorem Theorem (Division Theorem) For any integer a and positive integer b > 0 there exists a (unique) pair of integers (q, r) such that a = qb + r and 0 r < b. Vocabulary: a: dividend; b: divisor; q: quotient; r: reminder. Question: What is the result (q, r) of division with remainder of a = 24 by b = 7? (A) q = 3, r = 5; (B) q = 4, r = 4; (C) q = 2, r = 3; (D) q = 3, r = 3
Uniqueness A new quantifier: There exists a unique x such that P(x) Think of P as an equation. A solution to P(x) is a value of x such that P(x) is true. What we are saying is that P(x) has precisely one solution Sometimes this is denoted!x.p(x) Can we express!x.p(x) using the standard quantifiers?
Uniqueness A new quantifier: There exists a unique x such that P(x) Think of P as an equation. A solution to P(x) is a value of x such that P(x) is true. What we are saying is that P(x) has precisely one solution Sometimes this is denoted!x.p(x) Can we express!x.p(x) using the standard quantifiers? x.(p(x) U(x)) where U(x) = P(x) has no other solution beside x U(x) = y.(p(y) (x = y))!x.p(x) x.(p(x) y.(p(y) (x = y))).
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b.
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b.
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b. We first prove that q = q.
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b. We first prove that q = q. Assume for contradiction that q q
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b. We first prove that q = q. Assume for contradiction that q q Then r r = q q b b, contradicting r r < b.
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b. We first prove that q = q. Assume for contradiction that q q Then r r = q q b b, contradicting r r < b. Since q = q, we also have r r = (q q )b = 0.
Proving Uniqueness Theorem The result (q, r) of division with remainder is unique Proof Let a, b be arbitrary integers, with b > 0, and let (q, r) be a solution of the division with remainder of a, b. Let (q, r ) be another solution. We need to prove that (q, r) = (q, r ). By definition, qb + r = q b + r = a and 0 r, r < b. Therefore (q q )b = r r, and r r < b. We first prove that q = q. Assume for contradiction that q q Then r r = q q b b, contradicting r r < b. Since q = q, we also have r r = (q q )b = 0. This proves that r = r and (q, r ) = (q, r) is unique.
Division Theorem (Application 1) Let (q, r) the result of the division with remainder of a by m. The uniqueness part of the theorem tell us that (q, r) are well defined We may think of divrem(a,b) = (q,r) as an algorithm In may applications we are interested only in r = a mod m. (a%m in some programming languages.) Theorem: For any integers a, b and positive integer m (modulus), a m b if and only if (a mod m) = (b mod m). Applications: Hashing, modular arithmetics, cryptography. 64-bit computer: Each 64-bit register stores a value between 0 and m = 2 64 1 All arithmetic operations are defined modulo m = 2 64
Division Theorem (Application 2) Every integer is either even or odd, but not both. Theorem: n.e(n) O(n). Proof: 1. Let n be an arbitrary integer 2. Divide n by 2. By the division theorem, there are integers (q, r) such that n = 2q + r and 0 r < 2 3. So, it must be r = 0 or r = 1. 4. If r = 0, then n = 2q, and n is even. 5. If r = 1, then n = 2q + 1, and n is odd. 6. n cannot be simultaneously even and odd because (q, r) is unique.
Modular Addition Theorem: If a 1 m b 1 and a 2 m b 2, then (a 1 + a 2 ) m (b 1 + b 2 ). Corollary: (a 1 + a 2 ) mod m = ((a 1 mod m) + (a 2 mod m)) mod m We can define a modular addition operation a + m b = (a + b) mod m, which operates on numbers a, b in Z m = {0,..., m 1}.
Modular Addition Theorem: If a 1 m b 1 and a 2 m b 2, then (a 1 + a 2 ) m (b 1 + b 2 ). Corollary: (a 1 + a 2 ) mod m = ((a 1 mod m) + (a 2 mod m)) mod m We can define a modular addition operation a + m b = (a + b) mod m, which operates on numbers a, b in Z m = {0,..., m 1}. Special case for m = 2: Z 2 = {0, 1} a mod 2 = 0 Even(a) a mod 2 = 1 Odd(a) Addition Table: a + 2 b b=0 b=1 a=0 0 1 a=1 1 0 Familiar rules: even +even = even even + odd = odd odd+odd = even
Modular Multiplication Theorem: If a 1 m b 1 and a 2 m b 2, then (a 1 a 2 ) m (b 1 b 2 ). Corollary: (a 1 a 2 ) mod m = ((a 1 mod m) (a 2 mod m)) mod m We can define a modular multiplication operation a m b = (a b) mod m, which operates on numbers a, b in Z m = {0,..., m 1}.
Modular Multiplication Theorem: If a 1 m b 1 and a 2 m b 2, then (a 1 a 2 ) m (b 1 b 2 ). Corollary: (a 1 a 2 ) mod m = ((a 1 mod m) (a 2 mod m)) mod m We can define a modular multiplication operation a m b = (a b) mod m, which operates on numbers a, b in Z m = {0,..., m 1}. Special case for m = 2: Z 2 = {0, 1} a mod 2 = 0 Even(a) a mod 2 = 1 Odd(a) Addition Table: a 2 b b=0 b=1 a=0 0 0 a=1 0 1 Familiar rules: even times even = even even times odd = even odd times odd = odd
Decimal notation Standard decimal notation: 1832 = 1 10 3 + 8 10 2 + 3 10 1 + 2 10 0 Every positive integer can be written (uniquely) as a sequence of digits n = c k c k 1... c 1 c 0 where each c i is one of 0, 1,..., 9. n = k i=0 10 i c i = c 0 + 10c 1 + 10 2 c 2 + 10 3 c 3 + 10 k c k where 0 c i < 10.
Decimal notation Standard decimal notation: 1832 = 1 10 3 + 8 10 2 + 3 10 1 + 2 10 0 Every positive integer can be written (uniquely) as a sequence of digits n = c k c k 1... c 1 c 0 where each c i is one of 0, 1,..., 9. n = k i=0 10 i c i = c 0 + 10c 1 + 10 2 c 2 + 10 3 c 3 + 10 k c k where 0 c i < 10. What is the last digit c 0 of n? (A) n mod 10 ; (B) n/10; (C) n 10; (D) I don t know.
Decimal notation Standard decimal notation: 1832 = 1 10 3 + 8 10 2 + 3 10 1 + 2 10 0 Every positive integer can be written (uniquely) as a sequence of digits n = c k c k 1... c 1 c 0 where each c i is one of 0, 1,..., 9. n = k i=0 10 i c i = c 0 + 10c 1 + 10 2 c 2 + 10 3 c 3 + 10 k c k where 0 c i < 10. What is the last digit c 0 of n? (A) n mod 10 ; (B) n/10; (C) n 10; (D) I don t know. For any integer n, the integer n (n mod 10) is always (A) positive; (B) a multiple of 10; (C) less than 10 (D) none.
Decimal notation If c k c k 1..., c 1, c 0 is the decimal representation of n. Then, the number represented by the digits c k c k 1..., c 2, c 1 equals (A) n (n mod 10); (B) n 10; (C) (n (n mod 10))/10; (D) n mod 10
Decimal notation If c k c k 1..., c 1, c 0 is the decimal representation of n. Then, the number represented by the digits c k c k 1..., c 2, c 1 equals (A) n (n mod 10); (B) n 10; (C) (n (n mod 10))/10; (D) n mod 10 So, the digits of a number n can be recovered as follows: 1. c 0 = (n mod 10) 2. c 1 = ((n c 0 )/10) mod 10 3. c 2 = ((n c 0 10c 1 )/100) mod 10
Number systems Everything applies to numbers written in other bases b > 1: n = i bi c i Binary numbers: b = 2. n = i 2i c i 1 10 11 100 101 110 111 Convert the number 134 to binary notation: (A) 10010110; (B) 10000110; (C) 11100110; (D) none
Other common bases Hexadecimal numbers: b = 16. Digits: 0,1,2,3,4,5,6,7,8,9,A= 10,B= 11,C= 12,D= 13,E= 14,F= 15 Octal: b = 8. Digits: 0,1,2,3,4,5,6,7 Convert between binary and hexadecimal. (Octal is similar.) Binary Hexadecimal Binary Hexadecimal 0000 0 1000 8 0001 1 1001 9 0010 2 1010 A 0011 3 1011 B 0100 4 1100 C 0101 5 1101 D 0110 6 1110 E 0111 7 1111 F
Addition with binary numbers Can you add 53 and 73? (A) 134; (B) 126; (C) Please, we are not in elementary school...
Addition with binary numbers Can you add 53 and 73? (A) 134; (B) 126; (C) Please, we are not in elementary school...... in binary? (53) 10 = (110101) 2 (73) 10 = (1001001) 2 110101 + 1001001 =???
Addition with binary numbers Can you add 53 and 73? (A) 134; (B) 126; (C) Please, we are not in elementary school...... in binary? (53) 10 = (110101) 2 (73) 10 = (1001001) 2 110101 + 1001001 =??? (11111110) 2 = (???) 10 (A) 135; (B) 126; (C) 118; (D) 134
Multiplication with binary numbers Can you multiply - (53) 10 = (110101) 2 - (73) 10 = (1001001) 2
Multiplication with binary numbers Can you multiply - (53) 10 = (110101) 2 - (73) 10 = (1001001) 2 110101 1001001 =??? 1001001 = 1000000 + 1000 + 1 110101 1000000 = 110101000000 110101 1000 = 110101000 110101 1 = 110101
Multiplication with binary numbers Can you multiply - (53) 10 = (110101) 2 - (73) 10 = (1001001) 2 110101 1001001 =??? 1001001 = 1000000 + 1000 + 1 110101 1000000 = 110101000000 110101 1000 = 110101000 110101 1 = 110101 110101 1001001 = 110101 (1000000 + 1000 + 1) = 110101000000 + 110101000 + 110101 =??? (A) 100101001001; (B) 111100011101; (C) 101100011101; (D) 111100011011