set operations - york university · set operations two sets can be combined in many different ways....

28
Set Operations Niloufar Shafiei

Upload: others

Post on 01-Jun-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

Set Operations

Niloufar Shafiei

Page 2: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

1

Set operations

Two sets can be combined in many

different ways.

Set operations can be used to combine

sets.

Page 3: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

2

Union

Let A and B be sets.

The union of A and B, denoted by A B, is

the set containing those elements that are

either in A or in B, or in both.

A B = {x | x A x B}

UB A

Page 4: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

3

Union (example)

{1,2,3} {2,4,6,8} =

{1,2,3,4,6,8}

{x| x Z x is even} {x|x Z x is odd} =

Z

Page 5: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

4

Intersection

Let A and B be sets.

The intersection of A and B, denoted by A

B, is the set containing those elements in

both A and B.

A B = {x | x A x B}

UB A

Page 6: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

5

Intersection (example)

{1,2,3} {2,4,6,8} =

{2}

Z {x|x Z x is odd} =

{x|x Z x is odd}

{x|x Z x is even} {x|x Z x is odd} =

Ø

Two sets are called disjoint if their intersection is empty.

Page 7: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

6

The cardinality of the union of sets

|A B|=?

Solution:

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

|A|=3 |B|=3 A B|=4

|A B| = |A| + |B| - |A B|

Principle of inclusion-exclusion

Page 8: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

7

Difference

Let A and B be sets.

The difference of A and B, denoted by A-B,

is the set containing those elements that

are in A but not in B. (also called complement

of B with respect to A)

A-B = {x | x A x B}

UA B

Page 9: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

8

Difference (example)

{1,2,3} - {2,4} =

{1,3}

Z - {x|x Z x is odd} =

{x|x Z x is even}

Page 10: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

9

Complement

Let U be the universal set and A be a set.

The complement of A, denoted by , is the

complement of A with respect to U (which

is U-A).

= {x | x A}

UA

Page 11: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

10

Complement (example)

A={a,b,c,d} and U is the set of English

alphabet

= {e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}

A = {x|x Z x is odd} and U is Z

= {x|x Z x is even}

Page 12: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

11

Set identities

A = A

A U = A

A U = U

A =

A A = A

A A = A

( ) = A

A = U

A =

UA

Identity laws

Domination laws

Idempotent laws

Complementation law

Complement laws

Page 13: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

12

Set identities

A B = B A

A B = B A

Commutative laws

A (B C) = (A B) C

A (B C) = (A B) C

Associative laws

A (A B) = A

A (A B) = A

Absorption laws

UA B C

Page 14: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

13

Set identities (example)

Show A B = A B.

Solution:

A B = {x | x A B }

= {x | ¬(x A B) }

= {x | ¬((x A) (x B)) }

= {x | ¬(x A) ¬(x B) }

= {x | (x A) (x B) }

= {x | (x A) (x B) }

= {x | (x A B)}

= A B

Page 15: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

14

Set identities

A B = A B

A B = A B

De Morgan’s laws

There is the similarity between set identities andlogical equivalences.

¬(A B) ¬A ¬B

¬(A B) ¬A ¬B

Page 16: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

15

Set identities (example)

Show A (B C) = (A B) (A C).

Solution:

Part 1: A (B C) (A B) (A C)

Assume x A (B C).

(x A) (x (B C))

(x A) (x B r x C)

(x A x B) (x A x C)

(x (A B)) (x (A C))

x (A B) (A C)

So, A (B C) (A B) (A C).

Page 17: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

16

Set identities (example)

Show A (B C) = (A B) (A C).

Solution:

Part 2: (A B) (A C) A (B C)

Assume x (A B) (A C).

x (A B) r x (A C)

(x A x B) (x A x C)

x A (x B x C)

x A (x (B C))

x A (B C)

So, (A B) (A C) A (B C) .

Thus, A (B C) = (A B) (A C).

Page 18: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

17

Set identities

A (B C) = (A B) (A C)

A (B C) = (A B) (A C)

Distributive laws

There is the similarity between set identities

and logical equivalences.

A (B C) (A B) (A C)

A (B C) (A B) (A C)

Page 19: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

18

Set identities

A (B C) = (A B) (A C)

A (B C) = (A B) (A C)

Distributive laws

000000 0 0

010000 0 1

001000 1 0

111110 1 1

111101 0 0

111101 0 1

111101 1 0

111111 1 1

(A B) (A C)A CA BA (B C)B CA B C

Membership table

Page 20: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

19

Set identities (example)

Show A (B C) = (C B) A.

Solution:

A (B C) =

A (B C) = (by De Morgan’s law)

A (B C) = (by De Morgan’s law)

(C B) A (by commutative law)

Page 21: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

20

Database query

The query that returns students that their GPA

is more than B and they are either

computer science or mathematics major.

A: students that their GPA is more than B

B: students that are computer science major.

C: students that are Mathematics major.

A (B C)

Page 22: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

21

Generalized union

Assume A1, A2, … and An are sets

The union of A1, A2, … and An is the set that

contains those elements that are members

of at least one set.

A1 A2 … An = Ai

n

i=1

Page 23: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

22

Generalized union (example)

Assume Ai is {i, i+1, i+2, …}. What is Ai?

Solution:

A1 = {1,2,3,…}

A2 = {2,3,4,…}

A3 = {3,4,5,…}

: Ai = {1,2,3,…}

n

i=1

n

i=1

Page 24: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

23

Generalized intersection

Assume A1, A2, … and An are sets

The intersection of A1, A2, … and An is theset that contains those elements that aremembers of all sets.

A1 A2 … An = Ai

n

i=1

Page 25: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

24

Generalized intersection (example)

Assume Ai is {i, i+1, i+2, …}. What is Ai?

Solution:

A1 = {1,2,3,…}

A2 = {2,3,4,…}

:

An = {n,n+1,n+2,…}

Ai = {n,n+1,n+2,…}

n

i=1

n

i=1

Page 26: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

25

Generalized union and intersection

A1 A2 … An … = Ai

A1 A2 … An … = Ai

i=1

i=1

Page 27: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

26

Example

Assume Ai = {1,2,3,…,i}. What is Ai and Ai?

Solution:

A1 = {1}

A2 = {1,2}

A3 = {1,2,3}

: Ai = Z+

Ai = {1}

i=1i=1

i=1

i=1

Page 28: Set Operations - York University · Set operations Two sets can be combined in many different ways. Set operations can be used to combine ... computer science or mathematics major

27

Recommended exercises

3,5,7,9,11,13,17,19,24,27,29,45,49