2.5 Operations Set Operations

You might also like

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1of 22

- Hello and welcome back.

In the last lecture we talked about set relations

and today we would like to discuss set operations

but before that we have a puzzle to resolve

so if you remember,

we asked whether

there are two sets A and B such that

A is both an element and a subset of B

namely A is an element of B

and A is subset of B

and the answer is yes.

One thing that helps is to note that

the empty set is a subset of any set

So if we take A to be the empty set

then half of this question will be solved for us

and we'll just need to find

so we take A to be the empty set

and so we already have that A will be contained

in anything else that we're going to choose for B

and we'll just need to choose a B such that

the empty set will be a member

will be an element of B

so we just need the element

the empty set to be an element of B

and that's very easy


we take B to consist of

just the empty set as an element

so B is the set that consists of just a single element

and that element is the empty set

and once we do that

then we see that...

The empty set belongs to B

belongs to the set that contains the empty set

Okay, and as always we have that the empty set

is a subset of the empty set

that's because this is always true

and so we found two sets

namely the empty set

and the set containing the empty set

such that the empty set is an element of that set

and the empty set is a subset of that set

So the answer is yes

and these are the two simple sets

that satisfy these two relations.

Now, you can find more complex relations

that do not imply...

that do not use the empty set,

but this is the simplest you can find.

What are we going to do?

Remember that...
For set relations we generalize numbers

namely we looked at equality,

less than equal,

and strictly less than,

and we defined similar relations for sets

equality, subset, and strict subset

and we would like to do the same here for operations

and what we'd like to generalize are

addition, subtraction, and multiplication.

Addition we'll denote by union

subtraction we'll denote again by subtraction

multiplication again

we'll use the same symbol, multiplication

and in this lecture we'll talk about

addition and subtraction, or union and difference

they're called for sets

and we'll actually also talk about intersection

and multiplication we'll discuss in the next lecture.

First let's start with the complement

recall that the universal set omega

contains all elements

and so the complement of a set A is

which is denoted by this notation

A complement is the set of all elements in omega

that are not in A


in logic terms a complement is a set of all

elements X in omega that are not in A

so that's set notation

Using a venn diagram here is our set A

here is omega

and a complement is all the elements

that are not in omega clearly,

but not in this as the complement.

Let's look at a couple of examples

Let's, omega, our universe, be zero one

then what is the complement

of the set containing zero

is the set of all elements

that are not zero in our universe

which it will just be one

and what is the complement of zero one?

That's a set of all elements of omega

of zero one, that are not in zero, one

there are no such elements

so this is the empty set

And what is the complement of the empty set?

That's going to be zero one

Notice that A complement depends both on A

and on the universal set omega

so if our universe is now zero one two


and we take the complement of zero

that will consist of the elements one and two

Alright

Now if we take our universe to be

Z, the set of all integers

then the complement of the negative numbers

minus one minus two and so on

is the natural numbers

the set of no negative numbers

and if we let, still the same universe Z

and we let our set E be the set of even numbers

which is, remember, we define it to be

the set of all numbers divisible by two

and we minus two, zero two, and so on

and then if we take the complement of that

it's going to be the set of all numbers

that are not divisble two

like minus three, minus one, one, three, and so on

and we denote this set by 'O' and call it

the set of odd numbers

Now, we can get a couple of identities

and identities are just relations that

hold for all sets

so for example if we take the complement of the empty set

it's going to be the universe


the complement of the universe is the empty set

if A and A complement are disjoint

not if...

If A and A complement are always disjoint

because A complement consists of all the elements

that are not in A

and if you take the complement of A

and the complement of that again

you get back A

and this is called...

the complement is called an involution

if you take this operation

and apply twice to a set you get the set itself

and if a set A is a subset of a set B

then the complement of A

will be superset of the complement of B

Now we want...

to move from complement to intersection

and intersection of two sets A and B

denoted by this notation

is the set of all elements

that are both in A and B

and again using set notation

intersection B is the set of all elements x

that are both in A and B


Here's using venn diagrams,

here are A and B

and the intersection of all elements

that are in this region where they overlap

and for example,

if we take zero one and one three

the intersection is one,

because it's the one element that contains both

and if you take set zero and set one

the intersection is empty

and if we take the two intervals

zero four and three six

and then the intersection is all the real numbers

between three and four inclusive of three

but exclusive of four

so it's three up to four

and zero two intersection to five

because this interval does not include two

this intersection is going to be empty

Alright, and finally if we take an intersection

of the following two sets,

the set where it rains cats

and the set where it rains dogs

we get the intersection

is the set where it rains cats and dogs.


Moving from intersections to unions

the union of two sets A and B

denoted using this symbol here

is the collection of all elements in A, B, or both.

Using set notation, A union B

is the set of all x's

that are in A or in B or in both

and venn diagrams, this is A and this is B

and we're looking at the set of all elements

that are in one of them or both of them

that's going to be the whole shaded region here

that's A union B.

Okay some example,

if we take zero one union with one two

we get the set of all elements that are in

at least one of those two sets

that's zero, one and two

and notice that we can get zero, one, two

from a union of other sets

for example zero, one and just two

that'll give us the same union

zero, one, two

because the element two now is just here

where as beforehand it was...

I'm sorry, the element one...


is here just in this set

whereas here it was in both sets

and it's not really necessary to have it twice.

If we take...

the union of these two real intervals

zero, two union one, three,

what do we get?

We get the interval from zero to three

inclusive of both

and if we take the union of zero, one

with the single to one, what do we get?

We get the interval from zero to one

but now it includes the element one

and if we take the union of the evens and the odd

we get all the integers.

Alright.

So we can generalize of course to multiple sets

and A union B union C therefore

will be the collection of all elements x

such that x is in A or in B or in C

and using a venn diagram

here's A, B, and C

Um...

The union is just a collection

of all elements that are in any of those sets.


So it's the whole shaded area,

and if we take zero, one

union one, two

union two, three

we get zero, one, two, three

and generally if you have more than three sets

if three sets the union of A 'i'

'i' going from one up to 't'

is the set of all x such that

x belongs to A'i' for sum 'i' between 1 and t.

Alright.

And the union, for example, of all integers

the set of all integers, the set of containing 'i'

and we take the union of all these sets

from 'i' going from minus infinity to infinity

is just the set of all integers.

Similarly, we can define intersections,

so if this is A, B, and C,

the intersection is just this region here

which is the set of all elements

that are all in A, B, and C.

Okay. So...

Let's mention a few identities.

First for one set,

and identities are also called laws


they are relations that hold for all sets

so the first set identity is actually called identity

it says that if you take any set A

and intersect it with the universe

you get the set A itself

if you take any set A and take the union with the universe

you get the universe.

Second identity, called universal bond

it says that if you take any set A

and intersect it with the empty set

you'll get the empty set

and if you take any set A and take the union

with the empty set you get the set A himself.

Then, we have the idempotent identity

that says that if you take set A

to intersect with itself you get the set A

and if you take the set A and take union with itself

you get A

and complement,

that is if you take A intersect it with a complement

as we know there's the joint

so the intersection is going to be empty

and if you take the set A and take union

with its complement you get the whole space omega.

Again these are just very basic and I think,


kind of intuitive identities,

so we won't give proofs we'll just

mention them and you can verify them.

Alright.

And then if we move to laws with two or three sets,

we get the commutative law

that says that A intersection B is the

same as B intersection A

because these are just the set of elements both A and B.

And A union B is equal to B union A.

We've got the associative law

that says that A intersection B intersection C

if you first intersect A and B

and then intersect it with C

it's the same as taking A intersecting it

with the first intersecting B and C.

And similarly for the union

the order in which you perform the operations

does not matter.

And the distributive law that says if you take

A and intersect it with the union of B and C

it's the same as taking A intersection B

and taking the union of that with A intersection C.

And same for...

union and intersection.


And finally, one that we'll use a little more often

De Morgan's Law that says that

if you take any two sets and take the intersection

and take the complement that's the same

as taking the union of the two complements.

Basically, the complement of the intersection

is the union of the complements.

And you can have symmetric law

for if you take the union and take the complement

that's going to be

the complement of A intersection of the complement of B

or in other words, the complement of the union

is the intersection of the complement.

And this one maybe we're going to show why it's true,

and we're going to use venn diagrams for that.

So, De Morgan's Law, we'll prove,

or show that,

the complement of the intersection

is the union of the complement

so we're going to show, first,

draw this, a venn diagram for this region

and then for this one

and we'll show that they're the same.

So here's the set A

and here is a set B


they could be any sets

then A intersection B, we're doing this one first,

is this set here.

This is A intersection B.

And if we take the complement of that,

which we need to here

then that's going to be this whole shaded region here

that's A intersection B complement.

On the other hand,

if we do the right hand side,

then again this is A and this is B

this is A complement, and this is B complement,

and now if we take the union of these two sets

we get the whole shaded region here.

Okay, and we can see that these two areas

are exactly the same, and therefore,

the complement of A intersection B

is the same as the union of A complement and B complement.

Alright.

And then we also would like to discuss

set difference.

So the difference A minus B between two sets

is the set of elements that are in A but not in B

that generalizes minus four numbers

so A minus B is the set of x such that


x is in A but not in B.

And pictorially this is A, this is B

this is going to be the set A minus B

if all elements are in A but not in B

for example, zero, one minus one

is the set containing just zero.

And zero, one minus zero, one, two

looking at all the elements

that are in this set A but not here and are none,

this is going to be the empty set

and if we take the interval one to three

minus the interval two to four

is all the elements in the interval one to three

two to four it's going to be

the interval from one all the way up to two

but not including two because we're removing two.

And if we take one, three minus one, three

and then we'll just be left with

the numbers one and the number three.

Okay.

And one observation, again denoted here

in (mumbles) for a result, it's always true

A minus B, you can express it as

A intersection B complement.

And a note on notation, that...


Set difference which we denote by minus,

is also sometimes denoted by this slash,

backslash, sorry.

And once we have difference we can also define

symmetric difference.

The symmetric difference of two sets

is the set of all elements that are exactly in one set.

A delta B is the set of all elements

that are in A,

so the set of all elements x such that x is in A

and not in B,

or x is in B but not in A.

So they're in exactly one set.

Pictorally this is A and this is B

the symmetric difference

is just the elements that are in A not B

or B and not A,

in other words they're in just exactly one set.

If we take zero, one

symmetric difference with one, two

we're looking at all elements that are

in exactly one set,

and that is going to be zero and two.

If we look at the interval zero, two

symmetric difference with one, four


that's all the elements that are in exactly

one of those two intervals

and that's going to be zero up to one,

or two up to four,

and we're not including one because

one is here

so it cannot be included

we want it to be included in just one element

so here one is in both of them

so it's not in this set

and likewise two is in both of them,

so it's not included.

Alright.

And you can observe that

the symmetric difference of A and B

can be expressed as A minus B

union with B minus A.

Because this is A minus B here

and this is B minus A

you take the union you get

A symmetric difference with B.

And again from two set to three sets

if you have three sets

then you can define similar operations

just you can find recursively so this is going to be


these are A, B, C

this is A intersection B intersection C

this is all the intersection of all three of them

and this is A intersection B

that's what we have here minus C

so we're excluding this region here

we're just talking about

this region and this region here is

A minus the union of these two regions

so it's A minus B union C

and um...

If we take the union of these three region

this one and this one and this one

that's going to be B union C minus A and so on.

Okay.

So hopefully we've talked about

many different operations.

So to test I would like to do

the Venn Master Chart Quiz.

And this quiz actually comes with real rewards

that you can use.

So I'll give you two sets and I'll share

some regions and ask you what the regions are.

So first let's introduce the set,

this is our set A and this is our set B,


and if you ask what is this whole region

where we have points either in A or in B

what is this whole region?

That is A union B.

Very good.

And now let's say we eliminate this set

so we're left with just this region here.

What is this region?

It's A minus B.

And if we reverse things?

And we now look at just this region,

what is it?

It's B minus A.

And if we look at both this region

the red region here and the orange region here

what are they?

That's A symmetric difference with B.

Very good.

And then last one,

if we look at the intersection here,

what do we get?

Mastercard.

And if you got all of them correct,

then you can go and max the card.

So hopefully we all understand what


the different regions are

for intersection and union and difference,

and now we're just going to express them in Python.

So, set operations,

first union and intersection

again define two sets A and B,

like that.

and the union...

is expressed using either the bar,

again used,

or union.

So we can write A union B

we get 1, 2, 3

and we can write C equals A union dot union of B

we get this (mumbles) and then print C.

We get the same thing

and intersection you can write as 'and'

which kind of like borrows from the logical notation.

Or intersection

and you can write A intersection B you'll get two

or C equals A dot intersection B and print C

and you'll get two again which is the intersection.

And set difference and symmetric difference

so again A and B are the same

set difference we write as either minus


or difference

and can write A minus B and we'll get one

so this an element which is in A but not in B

it's just one

or we can write B dot difference with A

and we'll get three because this is B

and we subtract A

(mumbles) to make three.

And symmetric difference you can write using

this carrot notation or symmetric_difference.

So write A carrot B,

you get three, one

the elements that are in A or B,

but not both

or can B dot symmetric difference A

and again you get three, one.

So to summarize we talked about set operations,

we discussed complement,

which is denoted by A with superscript c

for complement of set A

intersection denoted like so

union

that

difference denoted by minus

and symmetric difference denoted by delta


and what are we going to do next time?

We're going to discuss Cartesian products.

See you then.

End of transcript. Skip to the start.

Discussion

You might also like