21
Fall 2002 CMSC 203 - Discrete Structures 1 and now for something and now for something completely different… completely different… Set Theory Set Theory Actually, you will see that Actually, you will see that logic and set theory are logic and set theory are very closely related. very closely related.

Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Embed Size (px)

Citation preview

Page 1: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 1

… … and now for something and now for something completely different…completely different…

Set TheorySet TheoryActually, you will see that logic Actually, you will see that logic and set theory are very closely and set theory are very closely

related.related.

Page 2: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 2

Set TheorySet Theory

• Set: Collection of objects (“elements”)Set: Collection of objects (“elements”)

• aaAA “a is an element of A” “a is an element of A” “a is a member of A” “a is a member of A”

• aaAA “a is not an element of A” “a is not an element of A”

• A = {aA = {a11, a, a22, …, a, …, ann} } “A contains…”“A contains…”

• Order of elements is meaninglessOrder of elements is meaningless

• It does not matter how often the same It does not matter how often the same element is listed.element is listed.

Page 3: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 3

Set EqualitySet Equality

Sets A and B are equal if and only if they Sets A and B are equal if and only if they contain exactly the same elements.contain exactly the same elements.

Examples:Examples:

• A = {9, 2, 7, -3}, B = {7, 9, -3, A = {9, 2, 7, -3}, B = {7, 9, -3, 2} :2} :

A = BA = B

• A = {dog, cat, horse}, A = {dog, cat, horse}, B = {cat, horse, squirrel, dog} B = {cat, horse, squirrel, dog} ::

A A B B

• A = {dog, cat, horse}, A = {dog, cat, horse}, B = {cat, horse, dog, dog} : B = {cat, horse, dog, dog} : A = BA = B

Page 4: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 4

Examples for SetsExamples for Sets

““Standard” Sets:Standard” Sets:

• Natural numbers Natural numbers NN = {0, 1, 2, 3, …} = {0, 1, 2, 3, …}

• Integers Integers ZZ = {…, -2, -1, 0, 1, 2, …} = {…, -2, -1, 0, 1, 2, …}

• Positive Integers Positive Integers ZZ++ = {1, 2, 3, 4, …} = {1, 2, 3, 4, …}

• Real Numbers Real Numbers RR = {47.3, -12, = {47.3, -12, , …}, …}

• Rational Numbers Rational Numbers QQ = {1.5, 2.6, -3.8, 15, = {1.5, 2.6, -3.8, 15, …}…}(correct definition will follow)(correct definition will follow)

Page 5: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 5

Examples for SetsExamples for Sets

• A = A = “empty set/null set”“empty set/null set”

• A = {z}A = {z} Note: zNote: zA, but z A, but z {z}{z}

• A = {{b, c}, {c, x, d}}A = {{b, c}, {c, x, d}}

• A = {{x, y}} A = {{x, y}} Note: {x, y} Note: {x, y} A, but {x, y} A, but {x, y} {{x, y}} {{x, y}}

• A = {x | P(x)}A = {x | P(x)}“set of all x such that P(x)”“set of all x such that P(x)”

• A = {x | xA = {x | xNN x > 7} = {8, 9, 10, …}x > 7} = {8, 9, 10, …}“set builder notation”“set builder notation”

Page 6: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 6

Examples for SetsExamples for Sets

We are now able to define the set of rational We are now able to define the set of rational numbers Q:numbers Q:

QQ = {a/b | a = {a/b | aZZ bbZZ++} }

or or

QQ = {a/b | a = {a/b | aZZ bbZ Z bb0} 0}

And how about the set of real numbers R?And how about the set of real numbers R?

RR = {r | r is a real number} = {r | r is a real number}

That is the best we can do.That is the best we can do.

Page 7: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 7

SubsetsSubsetsA A B B “A is a subset of B” “A is a subset of B”A A B if and only if every element of A is also B if and only if every element of A is also an element of B. an element of B.We can completely formalize this:We can completely formalize this:A A B B x (xx (xA A x xB)B)

Examples:Examples:

A = {3, 9}, B = {5, 9, 1, 3}, A A = {3, 9}, B = {5, 9, 1, 3}, A B ? B ?

truetrue

A = {3, 3, 3, 9}, B = {5, 9, 1, 3}, A A = {3, 3, 3, 9}, B = {5, 9, 1, 3}, A B ? B ?

falsefalse

truetrue

A = {1, 2, 3}, B = {2, 3, 4}, A A = {1, 2, 3}, B = {2, 3, 4}, A B ? B ?

Page 8: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 8

SubsetsSubsetsUseful rules:Useful rules:• A = B A = B (A (A B) B) (B (B A) A) • (A (A B) B) (B (B C) C) A A C C (see Venn Diagram)(see Venn Diagram)

UU

AABB

CC

Page 9: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 9

SubsetsSubsets

Useful rules:Useful rules: A for any set A A for any set A • AA A for any set A A for any set A

Proper subsets:Proper subsets:

A A B B “A is a proper subset of B”“A is a proper subset of B”

A A B B x (xx (xA A x xB) B) x (xx (xB B x xA)A)

oror

A A B B x (xx (xA A x xB) B) x (xx (xB B x xA) A)

Page 10: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 10

Cardinality of SetsCardinality of Sets

If a set S contains n distinct elements, nIf a set S contains n distinct elements, nNN,,we call S a we call S a finite setfinite set with with cardinality ncardinality n..

Examples:Examples:

A = {Mercedes, BMW, Porsche}, |A| = 3A = {Mercedes, BMW, Porsche}, |A| = 3

B = {1, {2, 3}, {4, 5}, 6}B = {1, {2, 3}, {4, 5}, 6} |B| = |B| = 44C = C = |C| = 0|C| = 0

D = { xD = { xN N | x | x 7000 } 7000 } |D| = 7001|D| = 7001

E = { xE = { xN N | x | x 7000 } 7000 } E is infinite!E is infinite!

Page 11: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 11

The Power SetThe Power Set

P(A) P(A) “power set of A”“power set of A”

P(A) = {B | B P(A) = {B | B A} A} (contains all subsets of A)(contains all subsets of A)

Examples:Examples:

A = {x, y, z}A = {x, y, z}

P(A)P(A) = {= {, {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, , {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, {x, y, z}}{x, y, z}}

A = A = P(A) = {P(A) = {}}

Note: |A| = 0, |P(A)| = 1Note: |A| = 0, |P(A)| = 1

Page 12: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 12

The Power SetThe Power SetCardinality of power sets:Cardinality of power sets:

| P(A) | = 2| P(A) | = 2|A||A|

• Imagine each element in A has an “Imagine each element in A has an “onon//offoff” switch” switch• Each possible switch configuration in A Each possible switch configuration in A

corresponds to one element in 2corresponds to one element in 2AA

zzzzzzzzzzzzzzzzzzyyyyyyyyyyyyyyyyyyxxxxxxxxxxxxxxxxxx8877665544332211AA

• For 3 elements in A, there are For 3 elements in A, there are 22222 = 8 elements in P(A)2 = 8 elements in P(A)

Page 13: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 13

Cartesian ProductCartesian ProductThe The ordered n-tupleordered n-tuple (a (a11, a, a22, a, a33, …, a, …, ann) is an ) is an

ordered collectionordered collection of objects. of objects.

Two ordered n-tuples (aTwo ordered n-tuples (a11, a, a22, a, a33, …, a, …, ann) and ) and

(b(b11, b, b22, b, b33, …, b, …, bnn) are equal if and only if they ) are equal if and only if they

contain exactly the same elements contain exactly the same elements in the same in the same orderorder, i.e. a, i.e. aii = b = bii for 1 for 1 i i n. n.

The The Cartesian productCartesian product of two sets is defined as: of two sets is defined as:

AAB = {(a, b) | aB = {(a, b) | aA A b bB}B}

Example:Example: A = {x, y}, B = {a, b, c} A = {x, y}, B = {a, b, c}AAB = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)}B = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)}

Page 14: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 14

Cartesian ProductCartesian Product

The The Cartesian productCartesian product of two sets is defined of two sets is defined as: Aas: AB = {(a, b) | aB = {(a, b) | aA A b bB}B}

Example:Example:

A = {good, bad}, B = {student, prof}A = {good, bad}, B = {student, prof}

AAB = {B = {(good, student),(good, student), (good, prof),(good, prof), (bad, student),(bad, student), (bad, prof)(bad, prof)}}

(student, good),(student, good), (prof, good),(prof, good), (student, bad),(student, bad), (prof, bad)(prof, bad)}} BBA = A = {{

Page 15: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 15

Cartesian ProductCartesian Product

Note that:Note that:

• AA = = • A = A = • For non-empty sets A and B: AFor non-empty sets A and B: AB B A AB B B BAA

• |A|AB| = |A|B| = |A||B||B|

The Cartesian product of The Cartesian product of two or more setstwo or more sets is is defined as:defined as:

AA11AA22……AAnn = {(a = {(a11, a, a22, …, a, …, ann) | a) | aiiA for 1 A for 1 i i

n}n}

Page 16: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 16

Set OperationsSet Operations

Union: AUnion: AB = {x | xB = {x | xA A x xB}B}

Example:Example: A = {a, b}, B = {b, c, d} A = {a, b}, B = {b, c, d}

AAB = {a, b, c, d} B = {a, b, c, d}

Intersection: AIntersection: AB = {x | xB = {x | xA A x xB}B}

Example:Example: A = {a, b}, B = {b, c, d} A = {a, b}, B = {b, c, d}

AAB = {b}B = {b}

Page 17: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 17

Set OperationsSet Operations

Two sets are called Two sets are called disjointdisjoint if their intersection if their intersection is empty, that is, they share no elements:is empty, that is, they share no elements:

AAB = B =

The The differencedifference between two sets A and B between two sets A and B contains exactly those elements of A that are contains exactly those elements of A that are not in B:not in B:

A-B = {x | xA-B = {x | xA A x xB}B}Example: Example: A = {a, b}, B = {b, c, d}, A-B = {a}A = {a, b}, B = {b, c, d}, A-B = {a}

Page 18: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 18

Set OperationsSet Operations

The The complementcomplement of a set A contains exactly of a set A contains exactly those elements under consideration that are those elements under consideration that are not in A: not in A: AAcc = U-A = U-A

Example: Example: U = U = NN, B = {250, 251, 252, …}, B = {250, 251, 252, …} BBcc = {0, 1, 2, …, 248, 249} = {0, 1, 2, …, 248, 249}

Page 19: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 19

Set OperationsSet OperationsTable 1 in Section 1.5 shows many useful Table 1 in Section 1.5 shows many useful

equations.equations. How can we prove AHow can we prove A(B(BC) = (AC) = (AB)B)(A(AC)?C)?

Method I:Method I: xxAA(B(BC)C) xxA A x x(B(BC)C) xxA A (x (xB B x xC)C) (x(xA A x xB) B) (x (xA A x xC)C)

(distributive law for logical expressions)(distributive law for logical expressions) xx(A(AB) B) x x(A(AC)C) xx(A(AB)B)(A(AC)C)

Page 20: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 20

Set OperationsSet OperationsMethod II: Method II: Membership tableMembership table

1 means “x is an element of this set”1 means “x is an element of this set”0 means “x is not an element of this set” 0 means “x is not an element of this set”

11111111111 1 11 1 1

11111111001 1 01 1 0

11111111001 0 11 0 1

11111111001 0 01 0 0

11111111110 1 10 1 1

00001100000 1 00 1 0

00110000000 0 10 0 1

00000000000 0 00 0 0

(A(AB) B) (A(AC)C)AACCAABBAA(B(BC)C)BBCCA B CA B C

Page 21: Fall 2002CMSC 203 - Discrete Structures1 … and now for something completely different… Set Theory Actually, you will see that logic and set theory are

Fall 2002 CMSC 203 - Discrete Structures 21

Set OperationsSet Operations

Every logical expression can be transformed Every logical expression can be transformed into an equivalent expression in set theory and into an equivalent expression in set theory and vice versa.vice versa.

You could work on Exercises 9 and 19 in You could work on Exercises 9 and 19 in Section 1.5 to get some practice. Section 1.5 to get some practice.