COMP 1002 Logic for Computer Scientists Lecture 17 5 2 J
Puzzle: the barber In a certain village, there is a (male) barber who shaves all and only those men of the village who do not shave themselves. Question: who shaves the barber?
Operations on sets Let and be two sets. Such as ={1,2,3} and ={ 2,3,4} Intersection = x x x } The green part of the picture above = {2,3} nion = x x x } The coloured part in the top picture. = 1,2,3,4 Difference = x x x } The yellow part in the top picture. = 1 - Symmetric difference Δ = ( ) The yellow and blue parts of the top picture. Δ = 1,4 Δ Complement = x x } The blue part on the bottom Venn diagram If universe = N, = x N x 1,2,3 }
Subsets and operations If then Intersection = nion = Difference = Difference =
Size (cardinality) If a set has n elements, for a natural number n, then is a finite set and its cardinality is =n. 1,2,3 = 3 = 0 Sets that are not finite are infinite. More on cardinality of infinite sets in a couple of lectures N, Z, Q R, C 0,1 : set of all finite-length binary strings.
Rule of inclusion-exclusion Let and be two sets. Then = + Proof idea: notice that elements in are counted twice in +, so need to subtract one copy. If and are disjoint, then = + If there are 112 students in COMP 1001, 70 in COMP 1002, and 12 of them are in both, then the total number of students in 1001 or 1002 is 112+70-12=170. For three sets (and generalizes) C = + + C C C + C C
Power sets power set of a set, P, is a set of all subsets of. Think of sets as boxes of elements. subset of a set is a box with elements of (maybe all, maybe none, maybe some). Then P is a box containing boxes with elements of. When you open the box P, you don t see chocolates (elements of ), you see boxes. Subsets of : ={1,2}, P =, 1, 2, 1,2 =, P =. They are not the same! There is nothing in, and there is one element, an empty box, in P If has n elements, then P has 2 n elements. Power set P
Cartesian products Cartesian product of and is a set of all pairs of elements with the first from, and the second from : x = x, y x, y } ={1,2,3}, ={a,b} = { 1, a, 1, b, 2, a, 2, b, 3, a, 3, b } ={1,2}, = { 1,1., 1,2, 2,1, 2,2 } Order of pairs does not matter, order within pairs does:. Number of elements in is = a b 1 (1,a) (1,b) 2 (2,a) (2,b) 3 (3,a) (3,b) x Can define the Cartesian product for any number of sets: 1 2 k = x 1, x 2, x k ) x 1 1 x k k = 1,2,3, ={a,b}, C={3,4} C = { 1, a, 3, 1, a, 4, 1, b, 3, 1, b, 4, 2, a, 3, 2, a, 4, 2, b, 3, 2, b, 4, 3, a, 3, 3, a, 4, 3, b, 3, 3, b, 4 }
Proofs with sets Two ways to describe the purple area, x when x This happens when x x. So x. Since we picked an arbitrary x, then Not quite done yet Now let x Then x x. So x x. x x x x. So x. Thus x. Since x was an arbitrary element of, then. Therefore =
Laws of set theory Two ways to describe the purple area = y similar reasoning, = Does this remind you of something?... p q p q DeMorgan s law works in set theory! What about other equivalences from logic?
More useful equivalences For any formulas,, C: TTTT FFFFF TTTT TTTT. TTTT FFFFF. FFFFF FFFFF lso, like in arithmetic (with as +, as *) aaa C C Same holds for. lso, C C C nd unlike arithmetic C C ( C)
Propositions vs. sets Propositional logic Set theory Negation p Complement p q Intersection OR p q nion FLSE TRE Empty set niverse
More useful equivalences For any formulas,, C: TTTT FFFFF TTTT TTTT. TTTT FFFFF. FFFFF FFFFF lso, like in arithmetic (with as +, as *) aaa C C Same holds for. lso, C C C nd unlike arithmetic C C ( C)
Laws of set theory For any sets,, C: = = =. = =. = = = lso, like in arithmetic (with as +, as *) = aaa C = C Same holds for. lso, C = C C nd unlike arithmetic - C C ( C)
oolean algebra The algebra of both propositional logic and set theory is called oolean algebra (as opposed to algebra on numbers). Propositional logic Set theory oolean algebra Negation p Complement a p q Intersection a b OR p q nion a + b FLSE Empty set 0 TRE niverse 1
xioms of oolean algebra 1. a + b = b + a, a b = b a 2. (a+b)+c=a+(b+c) a b c = a b c 3. a + b c = a + b a + c a b + c = a b + (a c ) 4. There exist distinct elements 0 and 1 (among underlying set of elements of the algebra) such that for all a, a + 0 = a a 1 = a 5. For each a there exists an element a such that a + a = 1 a a = 0 How about DeMorgan, etc? They can be derived from the axioms!
Puzzle: the barber club In a certain barber s club, Every member has shaved at least one other member No member shaved himself No member has been shaved by more than one member There is a member who has never been shaved. Question: how many barbers are in this club?