1 / 39

Set Theory

Set Theory. Jim Williams HONP-112 Week 3. Set Theory. Set Theory is a practical implementation of Boolean logic that examines the relationships between groups of objects .

lawsonr
Download Presentation

Set Theory

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. Set Theory Jim Williams HONP-112 Week 3

  2. Set Theory • Set Theory is a practical implementation of Boolean logic that examines the relationships between groups of objects. • Set theory has numerous real-life applications in computer systems design, as well as database searching (we will learn more about databases later, but will touch on search concepts today)

  3. Definitions and Conventions • A set consists of individual elements. • A set is denoted by curly brackets and elements are separated by commas: • {A,E,I,O,U} • A set that has no elements is called the empty set, AKA the null set. • {}

  4. Universal Set • The Universal Set (or “Universe”) contains all possible values of whatever type of objects we are studying. • Sets can be infinite (i.e. {all real numbers}), or finite (i.e. {all letters of the alphabet}). • We will only be studying finite (AKA "discrete") sets. • We will use Uto denote the universal set. Do not confuse this with the UNION symbol (later).

  5. Subsets • Lets assume we have 2 sets A and B. • B is a subset of A if and only if all the elements in B are also in A. • Every set is a subset of the Universal Set. • Example: {1,2,6} is a subset of {1,2,3,4,5,6}

  6. Venn Diagram UNIVERSE SET A SET B A Venn Diagram can be used to graphically illustrate the relationship between sets.

  7. Union UNIVERSE SET A SET A SET B SET B SET A UNIONSET B contains all the elements that are either in A or B. The shaded areas illustrate the union.

  8. Intersection UNIVERSE SET A SET B SET A INTERSECTSET B contains only the elements that are in A and also in B. The shaded area illustrates the intersection.

  9. Compliment UNIVERSE SET A SET B SET A COMPLIMENT contains only the elements that are not in a given set. The shaded areas illustrate the compliment of A.

  10. Symbols for Set Operators • Union: ⋃ • Example: A ⋃ B • Intersection: ⋂ • Example: A ⋂ B • Compliment: ' • Example: A'

  11. Set Example for next 3 slides • Define Universal Set = All U.S. Coins • U={penny, nickel, dime, quarter, half-dollar, dollar} • Set A = {penny, nickel} • Set B = {nickel, dime, dollar}

  12. Set Union - Example • U={penny, nickel, dime, quarter, half-dollar, dollar} • Set A = {penny, nickel} • Set B = {nickel, dime, dollar} • A ⋃ B = {penny, nickel, dime, dollar} • IMPORTANT: Notice that the set elements never repeat within a single set of any kind (see there is only one “nickel” element in the result set!) Do not forget this!

  13. Set Intersection - Example • U={penny, nickel, dime, quarter, half-dollar, dollar} • Set A = {penny, nickel} • Set B = {nickel, dime, dollar} • A ⋂ B = {nickel}

  14. Set Compliment - Example • U={penny, nickel, dime, quarter, half-dollar, dollar} • Set A = {penny, nickel} • Set B = {nickel, dime, dollar} • A' = {dime, quarter, half-dollar, dollar}

  15. Work out some examples • U={penny, nickel, dime, quarter, half-dollar, dollar} • Set A = {all denominations over 10 cents.} • Set B = {all coins not silver in color} • What is A ⋃ B? A ⋂ B? • Try some more examples.

  16. Set Theory Vis-à-vis Boolean logic • The UNION set operator functions in a similar manner to the Boolean OR logical operator. • The INTERSECTION set operator functions in a similar manner to the Boolean AND logical operator. • The COMPLIMENT set operator functions in a similar manner to the Boolean NOT logical operator.

  17. The UNION operator as OR • Given Set A , Set B • The UNION applies a boolean OR to each element of each set. • A result of True (1) for any of these cases qualifies the element to be included in the result set. • Let’s Look at an example…

  18. The UNION operator as OR • Set A = {penny, nickel} • Set B = {nickel, dime, dollar} • The OR is applied to each element in set A and the corresponding element in set B • Results with 1 are included in the result set. • A ⋃ B = {penny, nickel, dime, dollar}

  19. The INTERSECT operator as AND • Given Set A , Set B • The INTERSECT applies a boolean AND to each element of each set. • A result of True (1) for any of these cases qualifies the element to be included in the result set. • Let’s Look at an example…

  20. The INTERSECT operator as AND • Set A = {penny, nickel} • Set B = {nickel, dime, dollar} • The AND is applied to each element in set A and the corresponding element in set B • Results with 1 are included in the result set. • A ⋂ B = {nickel}

  21. The COMPLIMENT as NOT • Given Set A • The COMPLIMENT applies a boolean NOT to each element of the set. • But, remember, that we also have to consider the entire universal set. • This is because a NOT is a unary operator. In this context, it only operates on the elements of a single set. But there are elements in the universal set that are still NOT in A. • (This type of compliment is the “absolute compliment” - which is the only type we are concerned with here). • Let’s look at an example…

  22. The COMPLIMENT operator as NOT • Set A = {penny, nickel} • The NOT is applied to each element in the set we are taking the compliment of. Remember we are still doing this in relation to the universal set! • Results with 1 are included in the result set. • A' = {dime, quarter, half-dollar, dollar}

  23. Alternate way of thinking about the Set Compliment (advanced)… • The COMPLIMENT applies a NAND against each element of the universal set and the corresponding elements of the set we are taking the compliment of. • Set A = {penny, nickel}

  24. Set theory and bit-wise mathematics • The concept we have illustrated in our previous tables is also used in various other computer circuits, and is called BIT-MASKING. • Given a sequence of bits, and a mask (also made up of some chosen sequence of bits), we can apply an AND mask, an OR mask, etc. • We need not worry about what bit-masking is used for right now – or why certain bit sequences may be chosen as a mask. • But we should know HOW to apply a mask to a bit sequence.

  25. The AND mask • The resulting bit sequence results from applying an AND against each bit in the sequence, and the corresponding bit in the mask. Result is 00110000. • Given a BIT sequence 00110110, and a MASK of 11110000:

  26. The OR mask • The resulting bit sequence results from applying an OR against each bit in the sequence, and the corresponding bit in the mask. Result is 11110110. • Given a BIT sequence 00110110, and a MASK of 11110000:

  27. Bitwise Masks: Observation • Given a BIT sequence 00110110, and a MASK of 11110000: • The AND mask results in 00110000 • The OR mask results in 11110110 • So, which type of MASK results in having more 1s in the resulting sequence?

  28. Set Theory applied to Databases • We can better understand the relationship between Boolean Logic and Set Theory by using a database example. • We will study databases in more depth later – but just keep the concept in mind. • Boolean searches are done against large databases in many situations (think of some).

  29. Search Operators • Databases usually use search operators that correspond with the standard Boolean operators of AND, OR, and NOT. • BUT – in the case of searches, they are applied to whether an item being searched for meets certain criteria.

  30. Search Operators and Set Theory • To understand this better, we need to think of search criteria in a different way. • Keep in mind that each search criterion will really be creating a separate SUBSET that meets the criterion. • When we search, we can apply boolean operators to connect criteria together in different ways. • So what we are really doing is creating different subsets and applying set operators to them.

  31. The OR (Union) Database Search Operator: Example • The OR search operator combines 2 or more subsetsinto a single largersubset. • Example: Criterion 1: Customers from the 07463 zipcode. Criterion 2: Customers who have made a purchase within the past month. • (Criterion 1) OR (Criterion 2) will create a single subset containing all customers from 07463, along with all the customers who have made a purchase within the past month, regardless of their zip code.

  32. The AND (Intersection) Database Search Operator: Example • The AND search operator selects the records that 2 or more subsets have in common into a single smaller subset. • Example: Criterion 1: Customers from the 07463 zipcode. Criterion 2: Customers who have made a purchase within the past month. • (Criterion 1) AND (Criterion 2) will create a single subset containing the customers from 07463, who also have made a purchase within the past month.

  33. The NOT (Compliment) Database Search Operator: Example • The NOT search operator gives us all the records in a set that do not belong to a particular subset. • Example: Criteria 1: Customers from the 07463 zip code. • NOT (Criteria 1) will create a single subset containing the customers who are NOT from 07463.

  34. More practical examples: Library Searching • In your college studies you will frequently need to look up books and articles in the library catalog, based on certain criteria (conditions). • The following slides will illustrate some examples of this and hopefully clarify the relationship between boolean search operators and their corresponding “behind the scenes” set operations. • Remember that in these examples the Universal Set is the entire library collection.

  35. Library search example - AND • Consider this: we want to find all books written by Stephen King within the past 5 years. • What we are really doing: Set A: Books written by Stephen King. Set B: All books written within the past 5 years. • If we want books that meet BOTH criteria, what we are looking for is the INTERSECTION between sets A and B. • A library system may allow us to say something like: Author=Stephen King AND date >= 2007.

  36. Library search example - OR • But what if we wanted any book written by Stephen King, or any book (regardless of author) written within the past 5 years. • What we are really doing: Set A: Books written by Stephen King. Set B: All books written within the past 5 years. • If we want books that meet EITHER criteria, what we am looking for is the UNION of sets A and B. • A library system may allow us to say something like: Author=Stephen King OR date >= 2007.

  37. Library search example - NOT • But what if we didn’t care for Stephen King’s writing? So, we wanted to find any book NOT written by him. • What we are really doing: Set A: Books written by Stephen King. • If we want books that are NOT in set A, what we are looking for is the COMPLIMENT of set A. • A library system may allow us to say something like: Author IS NOT Stephen King

  38. Library search example - complex • In real life most library searches are more complex. • Example: Mystery books written in the past 5 years, but not by Stephen King. • Set A: All Mystery Books. Set B: All Books written during the past 5 years. Set C: All Books written by Stephen King. • A library system might let us do something like this: Category=Mystery AND Date >= 2007 AND Author IS NOT Stephen King. • In set theory terms, this means: (A ⋂ B) ⋂ C'

  39. Review • Know the three set operators • Know how these are related to the three basic boolean operators. • Use these concepts to solve set theory problems. • Use these concepts to apply a given mask to a given bit sequence. • Understand how these concepts are applied to boolean searching of databases.

More Related