COMP 1002 Logic for Computer Scientists Lecture 16 5 2 J
dmin stuff 2 due Feb 17 th. Midterm March 2 nd. Semester break next week!
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 = xx xx xx } The green part of the picture above = {2,3} nion = xx xx xx } The coloured part in the top picture. = 1,2,3,4 Difference = xx xx xx } The yellow part in the top picture. = 1 - Symmetric difference Δ = ( ) The yellow and blue parts of the top picture. Δ = 1,4 Δ Complement = xx xx } The blue part on the bottom Venn diagram If universe = N, = xx N xx 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) CC = + + CC CC CC + CC 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 nn 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 = xx, yy xx, yy } ={1,2,3}, ={a,b} = { 1, aa, 1, bb, 2, aa, 2, bb, 3, aa, 3, bb } ={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 kk = xx 1, xx 2, xx kk ) xx 1 1 xx kk kk = 1,2,3, ={a,b}, C={3,4} CC = { 1, aa, 3, 1, aa, 4, 1, bb, 3, 1, bb, 4, 2, aa, 3, 2, aa, 4, 2, bb, 3, 2, bb, 4, 3, aa, 3, 3, aa, 4, 3, bb, 3, 3, bb, 4 }
Proofs with sets Two ways to describe the purple area, xx when xx This happens when xx xx. So xx. Since we picked an arbitrary x, then Not quite done yet Now let xx Then xx xx. So xx xx. xx xx xx xx. So xx. Thus xx. 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?... pp q pp qq DeMorgan s law works in set theory! What about other equivalences from logic?
More useful equivalences For any formulas,, C: TTTTTTTT FFFFFFFFFF TTTTTTTT TTTTTTTT. TTTTTTTT FFFFFFFFFF. FFFFFFFFFF FFFFFFFFFF lso, like in arithmetic (with as +, as *) aaaaaa CC CC Same holds for. lso, CC CC CC nd unlike arithmetic CC CC ( CC)
Propositions vs. sets Propositional logic Set theory Negation pp Complement pp qq Intersection OR pp qq nion FLSE TRE Empty set niverse
More useful equivalences For any formulas,, C: TTTTTTTT FFFFFFFFFF TTTTTTTT TTTTTTTT. TTTTTTTT FFFFFFFFFF. FFFFFFFFFF FFFFFFFFFF lso, like in arithmetic (with as +, as *) aaaaaa CC CC Same holds for. lso, CC CC CC nd unlike arithmetic CC CC ( CC)
Laws of set theory For any sets,, C: = = =. = =. = = = lso, like in arithmetic (with as +, as *) = aaaaaa CC = CC Same holds for. lso, CC = CC CC nd unlike arithmetic - CC CC ( CC)
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 pp Complement aa pp qq Intersection aa bb OR pp qq nion aa + bb FLSE Empty set 0 TRE niverse 1
xioms of oolean algebra 1. aa + bb = bb + aa, aa bb = bb aa 2. (a+b)+c=a+(b+c) a bb cc = aa bb cc 3. aa + bb cc = aa + bb aa + cc aa bb + cc = aa bb + (aa cc ) 4. There exist distinct elements 0 and 1 (among underlying set of elements of the algebra) such that for all aa, aa + 0 = aa aa 1 = aa 5. For each aa there exists an element aa such that aa + aa = 1 aa aa = 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?