Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course objectives We will focus on two major goals:

Similar presentations


Presentation on theme: "Course objectives We will focus on two major goals:"— Presentation transcript:

1 Course objectives We will focus on two major goals:
Basic tools and techniques in discrete mathematics Propositional logic Set Theory Simple algorithms Induction, recursion Counting techniques (Combinatorics) Precise and rigorous mathematical reasoning Writing proofs 1

2 To do well you should: Study with pen and paper
Ask for help immediately Practice, practice, practice… Follow along in class rather than take notes Ask questions in class Keep up with the class Read the book, not just the slides 2

3 Reasoning about problems
….=1? There exists integers a,b,c that satisfy the equation a2+b2 = c2 The program below that I wrote works correctly for all possible inputs….. The program that I wrote never hangs (i.e. always terminates)… 3

4 Tools for reasoning: Logic
Ch. 1: Introduction to Propositional Logic Truth values, truth tables Boolean logic:    Implications:   4

5 Why study propositional logic?
A formal mathematical “language” for precise reasoning. Start with propositions. Add other constructs like negation, conjunction, disjunction, implication etc. All of these are based on ideas we use daily to reason about things. 5

6 Propositions Declarative sentence Must be either True or False.
York University is in Toronto York University is in downtown Toronto All students at York are Computer Sc. majors. Not propositions: Do you like this class? There are x students in this class. 6

7 Propositions - 2 Truth value: True or False Variables: p,q,r,s,…
Negation: p (“not p”) Truth tables p p T F 7

8 Caveat: negating propositions
p: “it is not the case that p is true” p: “it rained more than 20 inches in TO” p: “John has many iPads” Practice: Questions 1-7 page 12. Q10 (a) p: “the election is decided” 8

9 Conjunction, Disjunction
Conjunction: p  q [“and”] Disjunction: p  q [“or”] p q p  q p  q T F 9

10 Examples Q11, page 13 p: It is below freezing q: It is snowing
It is below freezing and snowing It is below freezing but now snowing (d) It is either snowing or below freezing (or both) 10

11 Exclusive OR (XOR) p  q – T if p and q have different truth values, F otherwise Colloquially, we often use OR ambiguously – “an entrée comes with soup or salad” implies XOR, but “students can take MATH XXXX if they have taken MATH 2320 or MATH 1019” usually means the normal OR (so a student who has taken both is still eligible for MATH XXXX). 11

12 Conditional p  q [“if p then q”] p: hypothesis, q: conclusion
E.g.: “If you turn in a homework late, it will not be graded”; “If you get 100% in this course, you will get an A+”. TRICKY: Is p  q TRUE if p is FALSE? YES!! Think of “If you get 100% in this course, you will get an A+” as a promise – is the promise violated if someone gets 50% and does not receive an A+? 12

13 Note the truth table of  p  q
Conditional - 2 p  q [“if p then q”] Truth table: p q p  q  p  q T F Note the truth table of  p  q 13

14 Logical Equivalence p  q and  p  q are logically equivalent
Truth tables are the simplest way to prove such facts. We will learn other ways later. 14

15 Contrapositive Contrapositive of p  q is q  p
Any conditional and its contrapositive are logically equivalent (have the same truth table) – Check by writing down the truth table. E.g. The contrapositive of “If you get 100% in this course, you will get an A+” is “If you do not get an A+ in this course, you did not get 100%”. 15

16 E.g.: Proof using contrapositive
Prove: If x2 is even, x is even Proof 1: x2 = 2a for some integer a. Since 2 is prime, 2 must divide x. Proof 2: if x is not even, x is odd. Therefore x2 is odd. This is the contrapositive of the original assertion. 16

17 Converse Converse of p  q is q  p
Not logically equivalent to conditional Ex 1: “If you get 100% in this course, you will get an A+” and “If you get an A+ in this course, you scored 100%” are not equivalent. Ex 2: If you won the lottery, you are rich. 17

18 Other conditionals Inverse: inverse of p  q is p  q
How is this related to the converse? Biconditional: “If and only if” True if p,q have same truth values, false otherwise. Q: How is this related to XOR? Can also be defined as (p  q)  (q  p) 18

19 Example Q16(c) 1+1=3 if and only if monkeys can fly. 19

20 Readings and notes Read pages 1-12.
Think about the notion of truth tables. Master the rationale behind the definition of conditionals. Practice translating English sentences to propositional logic statements. 20

21 Next Ch. 1.2, 1.3: Propositional Logic - contd
Compound propositions, precedence rules Tautologies and logical equivalences Read only the first section called “Translating English Sentences” in 1.2. 21

22 Compound Propositions
Example: p  q  r : Could be interpreted as (p  q)  r or p  (q  r) precedence order:      (IMP!) (Overruled by brackets) We use this order to compute truth values of compound propositions. 22

23 Tautology A compound proposition that is always TRUE, e.g. q  q
Logical equivalence redefined: p,q are logical equivalences if p  q is a tautology. Symbolically p  q. Intuition: p  q is true precisely when p,q have the same truth values. 23

24 Manipulating Propositions
Compound propositions can be simplified by using simple rules. Read page Some are obvious, e.g. Identity, Domination, Idempotence, double negation, commutativity, associativity Less obvious: Distributive, De Morgan’s laws, Absorption 24

25 Distributive Laws p  (q  r)  (p  q)  (p  r)
Intuition (not a proof!) – For the LHS to be true: p must be true and q or r must be true. This is the same as saying p and q must be true or p and r must be true. p  (q  r)  (p  q)  (p  r) Intuition (less obvious) – For the LHS to be true: p must be true or both q and r must be true. This is the same as saying p or q must be true and p or r must be true. Proof: use truth tables. 25

26 De Morgan’s Laws (q  r)  q  r (q  r)  q  r
Intuition – For the LHS to be true: neither q nor r can be true. This is the same as saying q and r must be false. (q  r)  q  r Intuition – For the LHS to be true: q  r must be false. This is the same as saying q or r must be false. Proof: use truth tables. 26

27 Using the laws Q: Is p  (p  q) a tautology? Can use truth tables
Can write a compound proposition and simplify 27

28 Limitations of Propositional Logic
What can we NOT express using predicates? Ex: How do you make a statement about all even integers? If x >2 then x2 >4 A more general language: Predicate logic (Sec 1.4) 28

29 Next: Predicate Logic Ch 1.4 Predicates and quantifiers
Rules of Inference 29

30 Predicate Logic A predicate is a proposition that is a function of one or more variables. E.g.: P(x): x is an even number. So P(1) is false, P(2) is true,…. Examples of predicates: Domain ASCII characters - IsAlpha(x) : TRUE iff x is an alphabetical character. Domain floating point numbers - IsInt(x): TRUE iff x is an integer. Domain integers: Prime(x) - TRUE if x is prime, FALSE otherwise. 30

31 Quantifiers describes the values of a variable that make the predicate true. E.g. x P(x) Domain or universe: range of values of a variable (sometimes implicit) 31

32 Two Popular Quantifiers
Universal: x P(x) – “P(x) for all x in the domain” Existential: x P(x) – “P(x) for some x in the domain” or “there exists x such that P(x) is TRUE”. Either is meaningless if the domain is not known/specified. Examples (domain real numbers) x (x2 >= 0) x (x >1) (x>1) (x2 > x) – quantifier with restricted domain 32

33 Aside: summation notation
Using Quantifiers Domain integers: Using implications: The cube of all negative integers is negative. x (x < 0) (x3 < 0) Expressing sums : n n ( i = n(n+1)/2) i=1 Aside: summation notation 33

34 Scope of Quantifiers   have higher precedence than operators from Propositional Logic; so x P(x)  Q(x) is not logically equivalent to x (P(x)  Q(x))  x (P(x)  Q(x))  x R(x) Say P(x): x is odd, Q(x): x is divisible by 3, R(x): (x=0) (2x >x) Logical Equivalence: P  Q iff they have same truth value no matter which domain is used and no matter which predicates are assigned to predicate variables. 34

35 Negation of Quantifiers
“There is no student who can …” “Not all professors are bad….” “There is no Toronto Raptor that can dunk like Vince …”  x P(x)   x P(x) why?   x P(x)   x P(x) Careful: The negation of “Every Canadian loves Hockey” is NOT “No Canadian loves Hockey”! Many, many students make this mistake! 35

36 Nested Quantifiers Allows simultaneous quantification of many variables. E.g. – domain integers,  x  y  z x2 + y2 = z2 n  x  y  z xn + yn = zn (Fermat’s Last Theorem) Domain real numbers: x  y  z (x < z < y)  (y < z < x) Is this true? 36

37 Nested Quantifiers - 2 x y (x + y = 0) is true over the integers
Assume an arbitrary integer x. To show that there exists a y that satisfies the requirement of the predicate, choose y = -x. Clearly y is an integer, and thus is in the domain. So x + y = x + (-x) = x – x = 0. Since we assumed nothing about x (other than it is an integer), the argument holds for any integer x. Therefore, the predicate is TRUE. 37

38 Nested Quantifiers - 3 Caveat: In general, order matters! Consider the following propositions over the integer domain: x y (x < y) and y x (x < y) x y (x < y) : “there is no maximum integer” y x (x < y) : “there is a maximum integer” Not the same meaning at all!!! 38

39 Course page: http://www.cse.yorku.ca/course/1019
Math/CSE 1019C: Discrete Mathematics for Computer Science Fall 2011 Suprakash Datta Office: CSEB 3043 Phone: ext 77875 Course page: 39 39

40 Last class: quick recap
Sections Why logic? Why Propositional logic? What is a proposition? Tautology, contradiction Manipulating propositions –not, and, or, implication, biconditional Truth tables Propositional equivalences Table 6 (page 27) 40

41 Last class: quick recap – contd.
Sections : Predicate logic Why Predicate logic? What is a predicate? Translating English sentences to predicates Negation of quantifiers 41

42 Translation into predicates
“All students in this class are from FSE” “There are digital media majors in this class” “Every student has a smartphone or has a friend that owns a smartphone” “There are no students in this class that does not send text messages daily” 42

43 Scope of Quantifiers   have higher precedence than operators from Propositional Logic; so x P(x)  Q(x) x (P(x)  Q(x)) Use brackets E.g.  x (P(x)  Q(x))  x R(x) Say P(x): x is odd, Q(x): x is divisible by 3, R(x): (x=0) (2x >x) / 43

44 Negation of Quantifiers
Consider the statement Q: x P(x) where P(x) is a given predicate over a given domain. What does “Q is false” mean? Similarly what does “ x P(x) is false” mean? 44

45 Negation of Quantifiers - contd
 x P(x)   x P(x)   x P(x)   x P(x) E.g.: “There is no student who can …” “Not all professors are bad” “There is no Toronto Raptor that can dunk like Vince …” Caution: The negation of “Every Canadian loves Hockey” is NOT “No Canadian loves Hockey”! Many, many students make this mistake! 45

46 Allows simultaneous quantification of many variables.
Nested Quantifiers Allows simultaneous quantification of many variables. E.g. – domain positive integers,  x  y  z x2 + y2 = z2 n>2  x  y  z xn + yn = zn (Fermat’s Last Theorem) Domain real numbers: x y z (x < z < y)  (y < z < x) x y z (x=y) (x < z < y)  (y < z < x) x y z (xy) (x < z < y)  (y < z < x) Is it true? 46

47 x y (x + y = 0) is true over the integers
Nested Quantifiers - 2 x y (x + y = 0) is true over the integers Proof: Assume an arbitrary integer x. To show that there exists a y that satisfies the requirement of the predicate, choose y = -x. Clearly y is an integer, and thus is in the domain. So x + y = x + (-x) = x – x = 0. Since we assumed nothing about x (other than it is an integer), the argument holds for any integer x. Therefore, the predicate is TRUE. 47

48 p,j have different domains
Nested Quantifiers - 3 Analogy: quantifiers are like loops: An inner quantified variable can depend on the outer quantified variable. E.g. in x y (x + y = 0) we chose y=-x, so for different x we need different y to satisfy the statement. p j Accept (p,j) does NOT say that there is a j that will accept all p. p,j have different domains 48

49 x y (x < y) and y x (x < y)
Nested Quantifiers - 4 Caution: In general, order matters! Consider the following propositions over the integer domain: x y (x < y) and y x (x < y) x y (x < y) : “there is no maximum integer” y x (x < y) : “there is a maximum integer” Not the same meaning at all!!! 49

50 Negation of Nested Quantifiers
Use the same rule as before carefully. Ex 1:  x y (x + y = 0) This is equivalent to x y (x + y = 0) This is equivalent to x  y (x + y = 0) This is equivalent to x  y (x + y  0) Ex 2: x y (x < y) This is equivalent to x y (x < y) This is equivalent to x y (x < y) This is equivalent to x y (x  y) 50

51 Logical Equivalence of statements
Page 45: P  Q if and only if they have same truth value no matter which domain is used and no matter which predicates are assigned to predicate variables. 51

52 Truth tables may not help Domain may be infinite (e.g. integers)
How to prove  Truth tables may not help Domain may be infinite (e.g. integers) Prove each direction separately Use intuitive ideas (example 19 on page 45). 52

53 Proof and counterexamples
To prove a statement of the form x P(x) it is not enough to show that P(a) is true for one or some a’s. To show that a statement of the form x P(x) is FALSE, it is enough to show that P(a) is false for one a (“counterexample”). To prove a statement of the form  x P(x) it is enough to show that P(a) is true for one a. 53

54 Exercises Check that: x y (x + y = 0) is not true over the positive integers. x y (x + y = 0) is not true over the integers. x  0 y (y = 1/x) is true over the real numbers. 54

55 Readings and problems Read 1.4-1.5. Practice: Q2,8,16,30 (pg 65-67)
Next: Rules of inference (1.6). 55

56 Inference rules Recall: the reason for studying logic was to formalize derivations and proofs. How can we infer facts using logic? Let’s start with Propositional logic. 56

57 Inference rules - 2 Simple inference rule (Modus Ponens) :
From (a) p  q and (b) p is TRUE, we can infer that q is TRUE. Example: (a) if these lecture slides (ppt) are online then you can print them out (b) these lecture slides are online Similarly, From p  q, q  r and p is TRUE, we can infer that r is TRUE. 57

58 Inference rules - 3 ((p  q)  p )  q is a TAUTOLOGY.
Modus Tollens, Hypothetical syllogism and disjunctive syllogism can be seen as alternative forms of Modus Ponens Other rules like “From p is true we can infer p  q” are very intuitive 58

59 Inference rules - 4 q  r ((p  q)  ( p  r))  (q  r)
Resolution: From (a) p  q and (b)  p  r, we can infer that q  r Exercise: check that ((p  q)  ( p  r))  (q  r) is a TAUTOLOGY. Very useful in computer generated proofs. 59

60 Inference rules - 5 Read rules on page 72.
Understanding the rules is crucial, memorizing is not. You should be able to see that the rules make sense and correspond to our intuition about formal reasoning. 60

61 Inference rules for quantified statements
Very intuitive, e.g. Universal instantiation – If x P(x) is true, we infer that P(a) is true for any given a E.g.: Universal Modus Ponens: x P(x)  Q(x) and P(a) imply Q(a) If x is odd then x2 is odd, a is odd. So a2 is odd. 61

62 Inference rules for quantified statements-2
Read rules on page 76 Again, understanding is required, memorization is not. 62

63 Aside: Inference and Planning
The steps in an inference are useful for planning an action. Example: your professor has assigned reading from an out-of-print book. How do you do it? Example 2: you are participating in the television show “Amazing race”. How do you play? 63

64 Aside 2: Inference and Automatic Theorem-Proving
The steps in an inference are useful for proving assertions from axioms and facts. Why is it important for computers to prove theorems? Proving program-correctness Hardware design Data mining ….. 64

65 Aside 2: Inference and Automatic Theorem-Proving – contd.
Sometimes the steps of an inference (proof) are useful. E.g. on Amazon book recommendations are made. You can ask why they recommended a certain book to you (reasoning). 65

66 Next Introduction to Proofs (Sec 1.7) What is a (valid) proof?
Why are proofs necessary? 66

67 Introduction to Proof techniques
Why are proofs necessary? What is a (valid) proof? What details do you include/skip? “Obviously”, “clearly”… 67

68 Assertions Axioms Proposition, Lemma, Theorem Corollary Conjecture 68

69 Logic-based proof Every step should follow from axioms or previous step(s) using an inference rule. Problems: Axiomatization is hard and often long (see Appendix 1) Proofs are often very long and tedious Intuitive proofs : 69

70 Types of Proofs Direct proofs (including Proof by cases)
Proof by contraposition Proof by contradiction Proof by construction Proof by Induction Other techniques 70

71 Direct Proofs The average of any two primes greater than 2 is an integer. Every prime number greater than 2 can be written as the difference of two squares, i.e. a2 – b2. 71

72 Proof by cases If n is an integer, then n(n+1)/2 is an integer
Case 1: n is even. or n = 2a, for some integer a So n(n+1)/2 = 2a*(n+1)/2 = a*(n+1), which is an integer. Case 2: n is odd. n+1 is even, or n+1 = 2a, for an integer a So n(n+1)/2 = n*2a/2 = n*a, 72

73 Proof by contraposition
If (pq)  (p+q)/2, then p  q Direct proof left as exercise Contrapositive: If p = q, then (pq) = (p+q)/2 Easy: (pq) = (pp) = (p2) = p = (p+p)/2 = (p+q)/2. 73

74 Proof by contraposition- 2
Prove: If x2 is even, x is even Proof: if x is not even, x is odd. Therefore x2 is odd. This is the contrapositive of the original assertion. Note that the problem is to prove an implication. Universal generalization 74

75 Proof by Contradiction
2 is irrational Suppose 2 is rational. Then 2 = p/q, such that p, q have no common factors. Squaring and transposing, p2 = 2q2 (even number) So, p is even (previous slide) Or p = 2x for some integer x So 4x2 = 2q2 or q2 = 2x2 So, q is even (previous slide) So, p,q are both even – they have a common factor of 2. CONTRADICTION. So 2 is NOT rational Q.E.D. 75

76 Proof by Contradiction - 2
In general, start with an assumption that statement A is true. Then, using standard inference procedures infer that A is false. This is the contradiction. Recall: for any proposition p, p  p must be false 76

77 Existence Proofs There exists integers x,y,z satisfying x2+y2 = z2
Proof: x = 3, y = 4, z = 5. This is a constructive proof (produce an example). 77

78 Existence Proofs - 2 There exists irrational b,c, such that bc is rational (page 97) Nonconstructive proof: Consider 22. Two cases are possible: Case 1: 22 is rational – DONE (b = c = 2). Case 2: 22 is irrational – Let b = 22, c = 2. Then bc = (22)2 = (2)2*2 = (2)2 = 2 78

79 Uniqueness proofs E.g. the equation ax+b=0, a,b real, a0 has a unique solution. 79

80 The Use of Counterexamples
All prime numbers are odd Every prime number can be written as the difference of two squares, i.e. a2 – b2. 80

81 Examples Show that if n is an odd integer, there is a unique integer k such that n is the sum of k-2 and k+3. Prove that there are no solutions in positive integers x and y to the equation 2x2 + 5y2 = 14. If x3 is irrational then x is irrational Prove or disprove – if x, y are irrational, x + y is irrational. 81

82 Alternative problem statements
“show A is true if and only if B is true” “show that the statements A,B,C are equivalent” 82

83 Exercises Q8, 10, 26, 28 on page 91 83

84 What can we prove? The statement must be true
We must construct a valid proof 84

85 The role of conjectures
3x+1 conjecture Game: Start from a given integer n. If n is even, replace n by n/2. If n is odd, replace n with 3n+1. Keep doing this until you hit 1. e.g. n=5  16  8  4  2  1 Q: Does this game terminate for all n? 85

86 Elegance in proofs Q: Prove that the only pair of positive integers satisfying a+b=ab is (2,2). Many different proofs exist. What is the simplest one you can think of? 86

87 Next Ch. 2: Introduction to Set Theory Set operations Functions
Cardinality 87

88 Course page: http://www.cse.yorku.ca/course/1019
Math/CSE 1019: Discrete Mathematics for Computer Science Fall 2011 Suprakash Datta Office: CSEB 3043 Phone: ext 77875 Course page: 88 88

89 Last class: proofs Different techniques
Proofs vs counterexamples (connections with quantifiers) 89

90 Uniqueness proofs E.g. the equation ax+b=0, a,b real, a0 has a unique solution. 90

91 The Use of Counterexamples
All prime numbers are odd Every prime number can be written as the difference of two squares, i.e. a2 – b2. 91

92 The role of conjectures
3x+1 conjecture Game: Start from a given integer n. If n is even, replace n by n/2. If n is odd, replace n with 3n+1. Keep doing this until you hit 1. e.g. n=5  16  8  4  2  1 Q: Does this game terminate for all n? 92

93 Elegance in proofs Q: Prove that the only pair of positive integers satisfying a+b=ab is (2,2). Many different proofs exist. What is the simplest one you can think of? 93

94 More proof exercises If n+1 balls are distributed among n bins prove that at least one bin has more than 1 ball A game 94

95 Meaningful diagrams Pythagoras 95

96 Meaningful diagrams - 2 Sum of an arithmetic series (from geometry/sum-of-number-series/SumOfOdd.jpg) 96

97 Meaningful diagrams - 3 Sum of a geometric series (from if) 97

98 Meaningful diagrams - 4 1/4 + 1/16 + 1/64 + 1/ = 1/3 (from visual-proofs_25.html) 98

99 Next Ch. 2: Introduction to Set Theory Set operations Functions
Cardinality 99

100 Sets Unordered collection of elements, e.g., Equality of sets
Single digit integers Nonnegative integers faces of a die sides of a coin students enrolled in 1019N, W 2007. Equality of sets Note: Connection with data types 100

101 Describing sets English description Set builder notation Note:
The elements of a set can be sets, pairs of elements, pairs of pairs, triples, …!! Cartesian product: A x B = {(a,b)| a  A and b  B} 101

102 Sets of numbers Natural numbers Whole numbers Integers
Rational numbers Real numbers Complex numbers Co-ordinates on the plane 102

103 Sets - continued Cardinality – number of (distinct) elements
Finite set – cardinality some finite integer n Infinite set - a set that is not finite Special sets Universal set Empty set  (cardinality = ?) 103

104 Sets vs Sets of sets {1,2} vs {{1,},{2}} {} vs {{}} = {} 104

105 Similarly, P({}) = {, {}}
Subsets A  B: x ( x  A  x  B) Theorem: For any set S,   S and S  S. Proper subset: A  B: x ( x  A  x  B)   x ( x  B  x  A) Power set P(S) : set of all subsets of S. P(S) includes S, . Tricky question – What is P() ? P() = {} Similarly, P({}) = {, {}} 105

106 Set operations Union – A  B = { x | (x  A)  (x  B)}
Intersection - A  B = { x | (x  A)  (x  B)} Disjoint sets - A, B are disjoint iff A  B =  Difference – A – B = {x | (x  A)  (x  B)} Symmetric difference Complement – Ac or Ā = {x | x A} = U - A Venn diagrams 106

107 Laws of set operations Page 130 – notice the similarities with the laws for Boolean operators Remember De Morgan’s Laws and distributive laws. Proofs can be done with Venn diagrams. E.g.: (A  B) c = Ac  Bc Proofs via membership tables (page 131) 107

108 Cartesian products A x B 108

109 Introduction to functions
A function from A to B is an assignment of exactly one element of B to each element of A. E.g.: Let A = B = integers, f(x) = x+10 Let A = B = integers, f(x) = x2 Not a function A = B = real numbers f(x) = x A = B = real numbers, f(x) = 1/x 109

110 Terminology A = Domain, B = Co-domain f: A  B (not “implies”)
range(f) = {y|  x  A f(x) = y}  B int floor (float real){ … } f1 + f2, f1f2 One-to-one INJECTIVE Onto SURJECTIVE One-to-one correspondence BIJECTIVE 110

111 Operations with functions
Inverse f-1(x)  1/f(x) f -1(y) = x iff f(x) = y Composition: If f: A  B, g: C  A, then f ° g: C  B, f°g(x) = f(g(x)) 111

112 Graphs of functions 112

113 Special functions All domains: identity (x)
Note: f ° f –1 = f -1 ° f =  Integers: floor, ceiling, DecimalToBinary, BinaryToDecimal Reals: exponential, log 113

114 Special functions DecimalToBinary, BinaryToDecimal
E.g. 7 = 1112 , = 9 BinaryToDecimal – n = : n = 1*23 + 0*22 +0*21 + 1*20 = 9 DecimalToBinary – n = 7: b1 = n rem 2 = 1, n = n div 2 = 3 b2 = n rem 2 = 1, n = n div 2 = 1 b3 = n rem 2 = 1, n = n div 2 = 0. STOP 114

115 Special functions – contd.
Changing bases: In general need to go through the decimal representation E.g: 1017 = ?9 1017 = 1*72 +0*71 + 1*70 = 50 Decimal to Base 9: d1 = n rem 9 = 5, n = n div 9 = 5 b2 = n rem 9 = 5, n = n div 9 = 0. STOP So 1017 = 559 115

116 Special functions – tricks
Changing bases that are powers of 2: Can often use shortcuts. Binary to Octal: = 2758 Binary to Hexadecimal: = BD16 Hexadecimal to Octal: Go through binary, not decimal. 116

117 Sequences Finite or infinite
Calculus – limits of infinite sequences (proving existence, evaluation…) E.g. Arithmetic progression (series) 1, 4, 7, 10, … Geometric progression (series) 3, 6, 12, 24, 48 … 117

118 Similarity with series
S = a1 + a2 + a3 + a4 + ….. (n terms) Consider the sequence S1, S2, S3, … Sn, where Si = a1 + a2 + … + ai In general we would like to evaluate sums of series – useful in algorithm analysis. e.g. what is the total time spent in a nested loop? 118

119 Sums of common series Arithmetic series
e.g … + n (occurs in the analysis of running time of simple for loops) general form iti, ti= a + ib Geometric series e.g … + 2n general form iti, ti= ari More general series (not either of the above) … + n2 119

120 Sums of common series - 2 Technique for summing arithmetic series
Technique for summing geometric series More general series – more difficult 120

121 Caveats Need to be very careful with infinite series
In general, tools from calculus are needed to know whether an infinite series sum exists. There are instances where the infinite series sum is much easier to compute and manipulate, e.g. geometric series with r < 1. 121

122 Cardinality revisited
A set is finite (has finite cardinality) if its cardinality is some (finite) integer n. Two sets A,B have the same cardinality iff there is a one-to-one correspondence from A to B E.g. alphabet (lower case) a b c ….. 1 2 3 ….. 122

123 Infinite sets Why do we care? Cardinality of infinite sets
Do all infinite sets have the same cardinality? 123

124 Countable sets Defn: Is finite OR has the same cardinality as the positive integers. Why do we care? E.g. The algorithm works for “any n” Induction! 124

125 Countable sets – contd. Proving this involves (usually) constructing an explicit bijection with positive integers. Fact (Will not prove): Any subset of a countable set is countable. Will prove that The rationals are countable! The reals are not countable 125

126 The integers are countable
Write them as 0, 1, -1, 2, -2, 3, -3, 4, -4, …… Find a bijection between this sequence and 1,2,3,4,….. Notice the pattern: 1   So f(n) = n/2 if n even 3   (n-1)/2 o.w. 5   3 126

127 Other simple bijections
Odd positive integers 1     7 …. Union of two countable sets A, B is countable: Say f: N  A, g:N  B are bijections New bijection h: N  A  B h(n) = f(n/2) if n is even = g((n-1)/2) if n is odd. 127

128 The rationals are countable
Show that Z+ x Z+ is countable. Trivial injection between Q+, Z+ x Z+. To go from Q+ to Q, use the trick used to construct a bijection from Z to Z+. Details on the board. 128

129 The reals are not countable
Wrong proof strategy: Suppose it is countable Write them down in increasing order Prove that there is a real number between any two successive reals. WHY is this incorrect? (Note that the above “proof” would show that the rationals are not countable!!) 129

130 The reals are not countable - 2
Cantor diagonalization argument (1879) VERY powerful, important technique. Proof by contradiction. Sketch (details done on the board) - Assume countable - look at all numbers in the interval [0,1) - list them in ANY order - show that there is some number not listed 130

131 Notes The cardinality of neither the reals nor the integers are finite, yet one set is countable, the other is not. Q: Is there a set whose cardinality is “in-between”? Q: Is the cardinality of R the same as that of [0,1) ? 131


Download ppt "Course objectives We will focus on two major goals:"

Similar presentations


Ads by Google