jim williams honp-112 week 3. set theory is a practical implementation of boolean logic that...

39
Set Theory Jim Williams HONP-112 Week 3

Upload: johnathan-wright

Post on 23-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Set TheoryJim Williams

HONP-112Week 3

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)

Set Theory

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.◦ {}

Definitions and Conventions

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 U to denote the universal set. Do not confuse this with the UNION symbol (later).

Universal Set

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}

Subsets

Venn Diagram

SET B

SETA

A Venn Diagram can be used to graphically illustrate the relationship between sets.

UNIVERSE

Union

SET B

SETA

SET A UNION SET B contains all the elements that are either in A or B. The shaded areas illustrate the union.

UNIVERSE

SETA

SETB

Intersection

SET B

SETA

SET A INTERSECT SET B contains only the elements that are in A and also in B. The shaded area illustrates the intersection.

UNIVERSE

Compliment

SET B

SETA

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

UNIVERSE

Union: ⋃◦Example: A ⋃ B

Intersection: ⋂◦Example: A ⋂ B

Compliment: '◦Example: A'

Symbols for Set Operators

Define Universal Set = All U.S. Coins

U={penny, nickel, dime, quarter, half-dollar, dollar}

Set A = {penny, nickel}Set B = {nickel, dime, dollar}

Set Example for next 3 slides

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!

Set Union - Example

U={penny, nickel, dime, quarter, half-dollar, dollar}

Set A = {penny, nickel}Set B = {nickel, dime, dollar}A ⋂ B = {nickel}

Set Intersection - Example

U={penny, nickel, dime, quarter, half-dollar, dollar}

Set A = {penny, nickel}Set B = {nickel, dime, dollar}A' = {dime, quarter, half-dollar, dollar}

Set Compliment - Example

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.

Work out some examples

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.

Set Theory Vis-à-vis Boolean logic

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…

The UNION operator as OR

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}

The UNION operator as OR

Penny Nickel Dime Quarter

Half D.

Dollar

Set A 1 1 0 0 0 0

Set B 0 1 1 0 0 1

Result Set

1 1 1 0 0 1

• Set A = {penny, nickel}• Set B = {nickel, dime, dollar}

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…

The INTERSECT operator as AND

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}

The INTERSECT operator as AND

Penny

Nickel Dime Quarter

Half D.

Dollar

Set A 1 1 0 0 0 0

Set B 0 1 1 0 0 1

Result Set

0 1 0 0 0 0

• Set A = {penny, nickel}• Set B = {nickel, dime, dollar}

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…

The COMPLIMENT as NOT

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}

The COMPLIMENT operator as NOT

Penny Nickel Dime

Quarter Half D.

Dollar

Set A 1 1 0 0 0 0

Result Set

0 0 1 1 1 1

• Set A = {penny, nickel}

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.

Alternate way of thinking about the Set Compliment (advanced)…

Penny Nickel

Dime

Quarter

Half D.

Dollar

Universe 1 1 1 1 1 1

Set A 1 1 0 0 0 0

Result Set

0 0 1 1 1 1

• Set A = {penny, nickel}

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.

Set theory and bit-wise mathematics

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.

The AND mask

Seq. 0 0 1 1 0 1 1 0

Mask 1 1 1 1 0 0 0 0

Result

0 0 1 1 0 0 0 0

• Given a BIT sequence 00110110, and a MASK of 11110000:

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.

The OR mask

Seq. 0 0 1 1 0 1 1 0

Mask 1 1 1 1 0 0 0 0

Result

1 1 1 1 0 1 1 0

• Given a BIT sequence 00110110, and a MASK of 11110000:

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?

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).

Set Theory applied to Databases

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.

Search Operators

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.

Search Operators and Set Theory

The OR search operator combines 2 or more subsets into a single larger subset.

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.

The OR (Union) 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.

The AND (Intersection) 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.

The NOT (Compliment) Database Search Operator: Example

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.

More practical examples: Library Searching

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.

Library search example - AND

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.

Library search example - OR

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

Library search example - NOT

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'

Library search example - complex

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.

Review