1 / 30

CS1022 Computer Programming & Principles

CS1022 Computer Programming & Principles. Lecture 3.2 Set Theory (2). Plan of lecture. Algebra of sets Laws of the algebra of sets Proofs with algebra of sets Cardinality of sets Principle of inclusion and exclusion Ordered pairs and Cartesian product.

cher
Download Presentation

CS1022 Computer Programming & Principles

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS1022Computer Programming & Principles Lecture 3.2 Set Theory (2)

  2. Plan of lecture • Algebra of sets • Laws of the algebra of sets • Proofs with algebra of sets • Cardinality of sets • Principle of inclusion and exclusion • Ordered pairs and Cartesian product CS1022

  3. Algebra of sets (aka Mathematic Structure) • Various properties of sets can be derived using the operations such as union, intersection, etc. • Some are obvious, some aren’t • They all need proofs, though! • Proofs exploit correspondence between logic/sets CS1022

  4. Example • Prove that for any sets A and B, (A  B) = A  B CS1022

  5. Example (2) • Since the predicates defining (A  B) and A  B are equivalent, we have (A  B) = A  B • This property is one of “De Morgan’s Laws” • Fundamental properties of sets • Principles of the algebra of sets • In the tables, notice left- and right-hand sidesfor union and intersection. Augustus De Morgan CS1022

  6. Laws of the algebra of sets (1) CS1022

  7. Laws of the algebra of sets (2) Universe of Discourse. Universe of Discourse. CS1022

  8. Proofs with laws of algebra (1) • We can use the laws to prove further results • Prove that for any sets A and B, A  B = (A  B)  (A  B) CS1022

  9. Proofs with laws of algebra (2) CS1022

  10. Proofs with laws of algebra (2) CS1022

  11. Proofs with laws of algebra (2) CS1022

  12. Proofs with laws of algebra (2) CS1022

  13. Proofs with laws of algebra (2) CS1022

  14. Proofs with laws of algebra (2) CS1022

  15. Proofs with laws of algebra (2) CS1022

  16. Proofs with laws of algebra (2) CS1022

  17. Proofs with laws of algebra (2) CS1022

  18. Proofs with laws of algebra (2) CS1022

  19. Proofs with laws of algebra (2) CS1022

  20. Proofs with laws of algebra (2) CS1022

  21. Proofs with laws of algebra (3) • We started from the claim, and obtained definition • We can start from definition, and work towards claim • We can start from both ends, and meet “in the middle” • Whichever way, we must use the laws at each step • Notice that A, B in the laws may be set operations, not necessarily a set: • ((A  B)  (C  D))   = E   =  • (A  (B – C))  (A  (B – C)) = D  D =D =(A  (B – C)) CS1022

  22. Cardinality of sets • We sometimes need to count elements of sets • For instance, we might need to make provisions for their implementation, so we need to consider how much space needed... • The cardinality of a finite set S is the number of elements in S, represented as |S| • Examples: • A = {1, 2, 34, 3}; |A| = 4 • B = {bob, sue, 3, sue} = {bob, sue, 3}; |B| = 3 • || = 0: the cardinality of the empty set is zero CS1022

  23. Principle of inclusion & exclusion (1) • Counting rule for the union of two sets: |A  B| = |A| + |B| – |A  B| • Venn diagram: A  B = (A – B)  (A  B)  (B – A) • Proof: suppose that • |A – B|= m • |A  B| = n • |B – A|= p Then, |A  B| = |A – B| + |A  B| + |B – A| = m + n + p = (m + n) + (n + p) – n = |A| + |B| – |A  B| To avoid double counting. A B A–B AB B–A CS1022

  24. Principle of inclusion & exclusion (2) Example: • 63 first-year students choose optional courses • 16 chose Accounting • 37 chose Business • 5 chose both Accounting and Business How many took neither Accounting or Business? • Solution: • A = {students who took Accounting} • B = {students who took Business} Then |A| = 16, |B| = 37 and |A B| = 5 So |A B| = |A| + |B| – |A  B| = 16 + 37 – 5 = 48 Hence, 63 – 48 = 15 students took neither A B A–B AB B–A CS1022

  25. Ordered pairs & Cartesian product (1) • An ordered pair is (a, b), where • ais an element of a set A (aA) • bis an element of a set B (bB) • The set of all ordered pairs of sets A and B is called the Cartesian product of A and B, denoted by A  B • Formally: A  B = {(a, b) : (aA) and (bB)} • Important operation for • Functions & relations (very important for computing) • Information modelling CS1022

  26. Ordered pairs & Cartesian product (2) Let A = {coffee, tea} and B = {cake, muffin, donut} • A  B = {(coffee,cake),(coffee,muffin),(coffee,donut), (tea,cake),(tea,muffin),(tea,donut)} • B  A = {(cake,coffee),(muffin,coffee),(donut,coffee), (cake,tea),(muffin,tea),(donut,tea)} • B B = {(cake,cake),(cake,muffin),(cake,donut), (muffin,cake),(muffin,muffin),(muffin,donut), (donut,cake),(donut,muffin),(donut,donut)} CS1022

  27. Ordered pairs & Cartesian product (3) • if A  B, thenA  B  B  A • If |A| m and |B| n, then|A B| mn • Let R be the set of real numbers • The set R R or R2 are all pairs of real numbers (x, y) • The elements of R2 can be displayed as coordinates of a two-dimensional space • R2 is called the Cartesian plane y (3,2) x CS1022

  28. Ordered pairs & Cartesian product (4) • Given a collection of setsA1, A2,..., An • We can define its Cartesian product as A1  A2  ...  An ={(a1, a2, ..., an) : ai  Ai, i = 1, 2, ..., n} • If A1 = A2 = ... = An(the same set) then we write An for the Cartesian product of n copies of A • Example: Let B = {0,1}; describe the set Bn • Solution: the elements of Bn are lists of zeros and ones of length n • There are also called bit strings of size n CS1022

  29. Summary You should now know: • Laws of the algebra of sets • How to use the laws when proving claims • Cardinality of sets • Principle of inclusion and exclusion • Cartesian product • Cartesian plane • Bit strings CS1022

  30. Further reading • R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 3) • Wikipedia’s entry • Wikibooks entry CS1022

More Related