Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Topic Sets (5.1, 5.2, 5.3). 2 Original author of the slides: Vadim Bulitko University of Alberta Modified by.

Similar presentations


Presentation on theme: "1 Topic Sets (5.1, 5.2, 5.3). 2 Original author of the slides: Vadim Bulitko University of Alberta Modified by."— Presentation transcript:

1 1 Topic Sets (5.1, 5.2, 5.3)

2 2 Original author of the slides: Vadim Bulitko University of Alberta http://www.cs.ualberta.ca/~bulitko/W04 Modified by T. Andrew Yang (yang@uhcl.edu)yang@uhcl.edu

3 3 Sneak-preview : Sets What is a set? A collection of elements: –Order is irrelevant –No repetitions –Can be infinite –Can be empty Examples: {A, B, C} {0,1,2,3,…} N, Z, Q, R

4 4 Operations on sets S is a set Membership: x  S x is an element of S Subset: S 1  S Set S 1 is a subset of set S All elements of S 1 are elements of S S  S Proper subset S 1  S

5 5 Operations on sets S, S 1 are sets Equality: S = S 1 iff they have the same elements Difference: S - S 1 is a set of all elements that belong to S but NOT to S 1 {A,B,C} - {A,B,X,Y} = {C} {A,B,X,Y} – {A,B,C} = {X,Y}

6 6 Operations on sets S, S 1 are sets Intersection: S  S 1 is a set of all elements that belong to both S and S 1 {A,B,C}  {A,B,X,Y} = {A,B} Union: S  S 1 is a set of all elements that belong to either S or S 1 {A,B,C}  {A,B,X,Y} = {A,B,C,X,Y}

7 7 Interesting Properties of Sets S, S 1 are sets Then S – S 1 = S – (S  S 1 ) S = S 1  S – S 1 = Φ (S  S 1 ) – S 1 = S – S 1 Use a Venn diagram to see more properties S 1  S  S 1 - S = ? S 1  S  S 1  S = ? S 1  S  S 1  S = ? (S 1 – S)  (S - S 1 ) = ? Is S – (S 1  S) = (S –S 1 )  S ? Is (S  S 1 ) – S 1 = S  (S 1 – S 1 ) ?

8 8 More notation In mathematics, sets are often specified with a predicate and an enveloping set as follows: S={x  A | P(x)} S is the set of all elements of A that satisfy predicate P Example: Q={x  R |  a,b  Z b  0 & x=a/b}

9 9 Set Equality Two sets are equal iff they have the same elements Theorem: for any sets A and B, A=B iff A  B & B  A Proof

10 10 Subset and Membership Book example 5.1.5 2  {1,2,3} ? {2}  {1,2,3} ? 2  {1,2,3}? {2}  {1,2,3}? {2}  {{1},{2}}? {2}  {{1},{2}}? Given a set A, the power set of A, P (A), is the set of all subsets of A.

11 11 Universal Set If we are dealing with sets S 1, S 2, …, S n which are all subsets of a larger set U, then U is called the universal set of S 1, S 2, …, S n. All of S 1, S 2, …, S n are subsets of U When does such a U exist? Always, for we can set U to be the union of all sets involved e.g., Given sets A, B, and C: U = A  B  C ... e.g., A = all students taking math3331 in summer 2008, B = all students taking csci3134 in summer 2008, C = all students taking cinf3132 in summer 2008: What could be the universal set (or the universe of discourse)? Another example?

12 12 Complement So if I am dealing with set A which is a subset of the universal set U then: I can define complement of A as: A C = U - A That is the set of all elements (of U) that are not in A Often “of U” is dropped and people say that A C is the set of everything that is not in A

13 13 Quick questions What is the complement of U? U C = Ø What set has U as its complement? Ø C = U

14 14 Sets & Predicate Logic All of the set operations and relations above can be defined in terms of Boolean connectives: A  B={x | x  A v x  B} A  B={x | x  A & x  B} A-B={x | x  A & not x  B} A C ={x | not x  A} A=B iff  x x  A  x  B A  B iff  x x  A  x  B A  B iff (  x x  A  x  B) & not A=B

15 15 Symmetric Difference C=A  B Set C is the symmetric difference of sets A and B iff every element of C belongs to A or B but not both  A  B  C [C=A  B   a (a  C  (a  A xor a  B))]

16 16 Examples A={1,2}, B={2,3} A  B={1,3} A={Clinton,Reagan}, B={Gorbachov,Bregnev} A  B={Clinton,Reagan,Gorbachov,Bregnev} A={CMPUT272 students}, B={CMPUT272 students} A  B = {} A  A = {}

17 17 Exercise 2 Intersection of two sets is contained in their union:  A  B [ (A  B)  (A  B) ] Proof:

18 18 Exercise 3 Union is commutative  A  B [ A  B = B  A ]

19 19 Exercise 4 Intersection is commutative  A  B [ A  B = B  A ] Proof: very similar to the one we just did. Try it yourself.

20 20 Exercise 5 Intersection distributes over union:  A  B  C [ A  (B  C) =(A  B)  (A  C) ] Note: There is an analogy between logical operations v and & and arithmetic operations: v feels like + & feels like * So A & (B v C) = A & B v A & C [just like A*(B+C) = A*B + A*C] How about A+(B*C) --- is it (A+B)*(A+C)? NO So what about A v (B & C) = (A v B) & (A v C)?

21 21 The Analogy The analogy is incomplete: –Arithmetic: A+(B*C)  (A+B)*(A+C) –Logic: A v B&C = (A v B) & (A v C) Proof of the latter:

22 22 Exercise 6 In Exercise #5 we proved:  A  B  C [ A  (B  C) =(A  B)  (A  C) ] using the fact that A&(B v C)=A&B v A&C Given the statement just proved A v B&C = (A v B) & (A v C) What can we now prove in terms of sets? Union distributes over intersection:  A  B  C [ A  (B  C) =(A  B)  (A  C) ]

23 23 Proof of Exercise 6

24 24 More Identities See Theorem 5.2.2 (set identities) in the book, p.272 –An identity is an equation that is universally true for all elements in some set. The proofs can often be done using: –the logical definitions of set operations –logical identities we have proven before Do some of them as an exercise

25 25 Boolean Algebra Are the similarities between set identities and logical identities incidental? It turns out that both systems are examples of a more general construct called Boolean algebra

26 26 Boolean Algebra Boolean algebra is given by a set S and two operations: + and * defined over it such that the following identities hold (here a and b are arbitrary elements of S): a+b = b+a a*b = b*a (a+b)+c = a+(b+c) (a*b)*c = a*(b*c) a*(b+c) = a*b+a*c a+(b*c) = (a+b)*(a+c) There exist distinct 0,1 in S: a+0 = a a*1 = a For each a from S there exists a complement a’ such that: a+a’ = 1 a*a’ = 0

27 27 Boolean Algebra Logic Sets S{true,false}P(U) (i.e., all sets) +v  *&  a+b=b+aavb=bvaa  b=b  a a*b=b*aa&b=b&aa  b=b  a (a+b)+c=a+(b+c)(avb)vc=av(bvc)(a  b)  c=a  (b  c) (a*b)*c=a*(b*c)(a&b)&c=a&(b&c)(a  b)  c=a  (b  c) a*(b+c)=(a*b)+(a*c)a&(bvc)=(a&b)v(a&c)a  (b  c)=(a  b)  (a  c) a+(b*c)=(a+b)*(a+c)av(b&c)=(avb) & (avc)a  (b  c)=(a  b)  (a  c) 0 falseØ 1 trueU a+0=aa v false = aa  Ø = a a*1=aa & true = aa  U = a complement (a’)~aa C a+a’=1a v ~a = truea  a C = U a*a’=0a & ~a = falsea  a C = Ø

28 28 Questions?


Download ppt "1 Topic Sets (5.1, 5.2, 5.3). 2 Original author of the slides: Vadim Bulitko University of Alberta Modified by."

Similar presentations


Ads by Google