PROFESSOR: We've seen a lot of functions
in introductory calculus-- trig functions, rational functions,
exponentials, logs and so on.
I don't know whether your calculus course
has included a general discussion of functions.
The old fashioned ones didn't, and we will go into that
now in this segment.
And we're going to be interpreting functions
as a special case of binary relations.
So let's just say what a binary relation is.
A binary relation is a mathematical object
that associates elements of one set
called the domain with elements of another set
called the codomain.
And I'm going to give you a bunch of examples
of binary relations in a short moment,
but let's just talk about what they're for
and what their role is.
So they may be familiar to you as computer scientists
if you've worked with any relational databases like SQL
or MySQL.
MySQL.
And we'll see an example that indicates
where the original ideas behind those relational databases
came from.
But even more fundamental, relations
are one of the most basic mathematical abstractions right
after sets, and they play a role everywhere.
We're going to be looking in later lectures
at special kinds of binary relations
like equivalence relations and partial orders
and numerical congruences.
But today, we're going to set up the machinery
to be using binary relations for counting,
which will be another important application in this class.
So let's look at an example.
And I'm going to take one that's close to home-- the registered
for relation, which is a relation between students--
that's going to be the domain, in this case, four
students, Jason, Joan, Yihui, and Adam-- and four subjects.
As a coincidence, 6.042, 003, 012, and 004.
And the relation R is going to be indicated
by arrows which show just which students are associated
with which subjects, meaning that they're
registered for that subject.
So if we look at Jason, we can see
that there's a particular arrow connecting Jason and 6.042.
And what that tells us is that Jason is registered for 6.042.
Now, there's a bunch of notations
that are used with respect to binary relations.
So let's look at some.
One way to write it is if you think
of the relation R as an equality sign
or a less than sign, where it's normally
written in the middle of the two things
that it's connecting, as in this example-- Jason R 6.042.
That would be called infix notation.
Sometimes it's written as a binary predicate-- R
of Jason comma 6.042.
That would be kind of prefix notation
where the relation or operator comes first.
And then if you start being a little closer
to the formal definition of what a binary relation is,
you could say that the ordered pair Jason 6.042
is a member of the relation.
If you wanted to be really precise,
you would say that it was a member
of the graph of the relation.
And I'll come back and elaborate further
on what the graph of a relation is
and what this ordered pairs businesses.
But for now, just let's continue with this example.
And a basic concept with relations
is the idea of the image of a bunch of domain
elements under the relation.
So you can think of the relation as an operator
that applies to domain elements or even sets
of domain elements.
So if I write R of Jason, that defines the subjects
that Jason is registered for.
So looking at the picture, R is not a function.
So that there may be more than one subject, as is
you'd expect for a student to be registered for multiple courses
at MIT.
So Jason in this diagram is registered for 6.042 and 6.012
as indicated by the highlighted two connection
arrows, which we've made red.
Which means that R of Jason is that set
of two courses that he's associated with
or that are associated with him-- that he's
registered 6.042 and 6.012.
So at this point, we've applied R
to one domain element-- one student Jason.
But the interesting case is when you apply R
to a bunch of students.
So the general setup is that if x
is a set of students-- a subset of the domain, which we've
been showing in green-- then if I apply R to X,
it gives me all the subjects that they're
taking among them-- all the subjects that any one of them
is taking.
Let's take a look at an example.
Well, another way to say it I guess is that R of X
is everything in R that relates to things in X.
So if I look at Jason and Yihui and I
want to know what do they connect to under R--
these are the subjects that Jason or Yihui
is registered for.
The way I'd find that is by looking at the arrow diagram,
and I'd find that Jason is taking 042 and 012.
And Yihui is taking 012 and 004.
So between them, they're taking three courses.
So R of Jason, Yihui is in fact 042, 012, and 004.
So another way to understand this idea of the image of a set
R of X is that X is a set of points in the set
that you're starting with called the domain.
And R of X is going to be all of the endpoints in the other set,
the codomain, that start at X.
If I said that as a statement in formal logic or in set theory
with logical notation, I would say that R of X
is the set of j in subjects such that there
is a d in X such that dRj.
So what that's exactly saying that dRj
says that d is the starting point in the domain.
d is a student.
j is a subject.
dRj means there's an arrow that goes from student
d to subject j.
And we're collecting the set of those j's that started some d.
So an arrow from X goes to j is what
exists at d an X. dRj means-- written in logic notation--
it's really talking about the endpoints of arrows,
and that's a nice way to think about it.
But you ought to be able also to retreat
to give a nice, crisp set theoretic definition
without reference to pictures if need be.
So that's an official definition of the image under R.
Let's turn now to an operation on relations which
converts one relation into another relation
called the inverse of R. And the inverse of R
is what you get by turning the arrows around.
So let's look at the relation R, which
is the registered for relation going from d students
to j subjects.
And then if I look at R inverse, R inverse
I could think of as the registers relation-- 6.042
registers Jason, and 6.012 registers Jason and Yihui.
It's a funny usage of the word, but I needed something short
that would fit on the slide.
So registers is basically turning the arrows backwards of
is registered for.
And now I can apply the definition of image
to R inverse in a useful way.
But just to be crisp about what we're doing here
is formally our inverse is gotten
by flipping the role of the domain and the codomain.
So we have that dRj if and only if jR inverse d.
So let's look at R inverse of 6.012.
What that's going to mean is all the students
that are taking 6.012.
So we start off at 6.012, and we go back to all the students
that are registered for it.
It's Jason and Yihui again.
And so our inverse of 6.012 is Jason and Yihui.
Our inverse of 6.012 and 6.003?
Well, it's same deal.
Let's look at 6.003 and 6.012 and look at all the students
that are registered for either one of them.
Now its Jason, Joan, and Yihui shown by those red arrows--
all the arrows coming out of those two courses, 003 and 012.
And so our inverse of 003 and 012 is that set of three
students-- Jason, Joan, and Yihui.
And in general, when you start off
with a bunch of subjects-- a bunch of elements--
of the codomain and you apply R inverse to it,
it's called the inverse image of the Y under R.
Well, let's look at the set J of all the subjects
and think about what is R inverse of J. What
does it mean?
Well, R inverse of J is all the students
that are registered for some subject
at all, which is a good thing to have.
So now, I can start using these sets to make assertions
about my database that can be useful to know.
So for example, if I want to say that every student is
registered for some subject-- which, of course,
they are-- what I would say is that D,
the set of all students, is a subset of R inverse of J.
So this concise set theoretic containment statement--
d is a subset of R inverse of J--
is a slick way of writing the precise statement that
says that all the students are registered for some subject.
Now, happens not to be true by the way.
Because if you look back at that example,
Adam was not registered for a subject.
So we're not claiming that this is true,
but simply that there's a nice way
to express it using images and containment.
Let's look at a different relation
that we could call the advises relation.
So the advises relation's going to have codomain
the same set of students d, but it's going to have as a domain
the set of professors.
And I've written down the initials of five
prominent professors minus at the top--
and you may recognize some of the others.
But it doesn't really matter if you don't.
And the advises relation V is going
to be indicated by those arrows.
So in particular, it shows that ARM
is the adviser of Jason, Joan, Yihui, and Adam,
which he happens to be.
FTL is an adviser of Joan and Yihui.
So Joan has two advisers because she's a double major.
Yihui does as well.
And Adam does as well now that I look at this example.
So if I look at in particular now the advisees of FTL or TLP,
I'm looking at V of the set consisting of FTL and TLP.
And it's going to be Joan, Yihui, and Adam.
So taking the image of FTL and TLP--
that's the set of advisees of either of those two professors,
I get this set of three students--
Joan, Yihui, and Adam.
Well, that's a set of students, and the registered relation
applies to a set of students.
So let's do that.
If I now apply R to Joan and Yihui
and Adam, what I'm getting is the subjects
that they're registered for.
So this is called composing R and V. I've applied V and them
I'm applying R to the result.
In this case, R of V of FTL and TLP
is the same as R of Joan, Yihui, and Adam.
It's the courses that any of them are taking, and it's 003,
012, and 004.
So the way to understand this R of V in general
is you start off with any set X of professors in the domain.
You take V of W-- are the advisees that they have have--
and then you take R of the advisees,
and you get the subjects that the advisees are taking.
So R of V of X is the subjects that advisees of X are taking,
are registered for.
Well, we can abstract that out and call
this the composition of R and V. It's defined the same way
that functional composition is.
So R of V is the relation and the images of that relation.
The images of a set of professors under R of V
is defined to be apply V to X and then apply R to V of X.
And it's again, called the composition of R and V.
What it means now is that two things are related by R of V.
It relates professors and subjects.
And it says that a professor in a subject
are related if the professor has an advisee-- some advisee--
in that subject.
p for a professor.
Composition of R with V. j for a subject
holds if and only if professor p has an advisee
registered in subject j.
Let's see how you figure that kind of thing out.
So I'm going to draw the V relation which
goes from p professors to D students
and then the R relation that goes from D students
to J subjects.
And by showing them in this way, I
can understand the composition of R and V
as following two arrows.
You start off, say, at ARM, and you follow a V arrow from ARM
to his advisee, Yihui.
Then you follow another arrow from Yihui to 6.012,
and you discover, hey, ARM has an advisee in--
So now we can say that professor ARM is in the relation
R composed with V with 6.012 because of this path
ARM has Yihui as an advisee, and Yihui is registered for 6.012.
And this relation R o V, we figured out,
is the relation that the professor
has an advisee in the subject.
So in general, what we can say is
that a professor p is in the R o V relation
to j if and only if-- and here we're
going to state it in formal logical notation, which
really applies in general, not just
to this particular example.
So the definition of R composed with V
is the p R composed with Vj means
there's a D that connects p and j through V and D,
in particular that there's a D such that pVd,
which means there's a V arrow from p to to d.
And dRJ-- there's an R arrow from d to j.
For some, d.
By the way, there's a technicality here
that when you write the formula pVd and dRj, following
the diagram where you start with V on the left
and follow a V arrow and then and R arrow,
it's natural to think of them as written
in left to right order of which you apply first V R.
But of course, that's not the way composition works.
When you apply, one function-- R to V to something,
you're applying V first.
And you write it on the right.
So R o V is written like function composition
where V applies first, but the logical statement,
the natural way to write it, is to follow
the way the picture works.
And D, Vs, and Rs get reversed.
So watch out for that confusion.
Well, I want to introduce one more relation to flesh
out this example, and that'll be the teaches relation.
So the teaches relation is going to have--
as domain professors, again-- and it's codomain, subjects.
And it's simply going to tell us who's teaching what.
So here we're going to see that ARM is teaching 6.042,
as you well know.
And FTL is teaching 6.042, two which he does frequently
but not this term.
And now I can again use my relational operators
to start making assertions about these people
and relations involving teaching and advisees.
And a useful way to do that is by applying set operations
to the relations because I can think of the relations
as being that set of arrows.
So suppose I wanted to make some statement that a professor
should not teach their own advisee because it's
too much power for one person to have over a student.
This is not true, by the way.
It's common for professors to teach advisees,
but there are other kinds of rules
about dual relationships between supervisory relationships
and personal relationships.
But anyway, let's say if we can say
that profs should not teach anyone one that they're
advising.
Well, if we were saying that in logical notation, what we would
say is that for every professor and subject,
it's not the case that the professor has
an advisee in subject j and the professor
is teaching subject j.
So that's how you would say it in logic,
but there's a very slick way to say it
without all the formulas and the quantifiers.
I could just say that T, the relationship of his teaching,
intersected with the relationship
of has an advisee in the subject is empty.
There is no pair of professor and subject that is in both T
and in R of V.
And this bottom expression here gives you
a sense of the concise way that you
can express queries and assertions about the database
using a combination of relational operators
and set operators.
Another way to say it by the way-- there's
a general set theoretic fact-- is the way
to say that T and R of V intersected is empty
is to say that the set T and the set R of V, whatever they are,
have no points in common.
An equivalent way to say that is that one set
is contained in the complement of the other set.
So I could equally well have said this as R composed with V
is a subset of not T.
Well, let's step back now and summarize
what we've done by example and say a little bit
about how it works in general.
So as I said, a binary relation-- and we'll
start to be slightly more formal now-- a binary relation
R from a set A to a set B associates elements of A
with elements of B.
And there's a picture of a general set
A called the domain and a general set B
called the codomain.
And R is given by those arrows.
Well, what exactly are arrows?
Well, if you're going to formalize arrows,
the set of them is what's called the graph of R.
So technically, a relation really has three parts.
It's not to be identified with just its arrows.
A relation has a domain and codomain
and some bunch of arrows going from the domain
to the codomain.
The arrows can be formalized by saying all
that matters about an arrow is where it begins where it ends
because it's just designed to reflect
an association between an element of the domain
and an element of the codomain.
So technically, the arrows are just ordered pairs.
And in this case, there are three arrows-- one from A
to b 2.
And so you see at the bottom of the slide an ordered pair a 1,
b 2.
Another arrow goes for a 1 to b 4.
So you see the ordered pair a 1, b 4.
And the final arrow is a 3, b 4.
And you see that pair.
So all the language about arrows is really
talking about ordered pairs.
It's just that the geometric image
of these diagrams and their arrows
makes a lot of properties much clearer.
So the range of R is an important concept
that comes up regularly and tends to be
a little confusing for people.
The range of R is simply the elements
with arrows coming in from R. It's
all of the elements that are hit by an arrow that
starts in the domain.
So it's really R of the domain is the range of R.
Now, notice that this is typically not
equal to the whole codomain.
Let's look at this example.
Here, the range of R-- the points
that are hit by elements of A under R, namely just b 2
and b 4.
The codomain has elements b 1 and b 3 that are missing
and that are not in the range.
Well, as I said, functions are a special case of relations.
So let's just look at that.
A function, F, from a set A to a set B
is a relation which associates with each element
in the domain-- each element little a and the domain capital
A-- with at most one element of the codomain B.
So this one element, if it exists, is called F of a.
It's the image of the element a under the relation F,
but what's special about it is that F of a contains at most
one element.
So let's just look at an example again.
A way to say that a relation is a function
is to look at all of the points on the left in the domain
and make sure that none of them have more than one arrow coming
out.
Well, in this picture, there are a couple of violations of that.
There are a couple points on the left in A
that have more than one arrow coming out.
[? There's ?] our two bad edges.
But if I erase those, now I'm left with a function.
And sure enough, there's at most one arrow coming out
of each of the points on the left in A. Some of the points
have no arrows coming out.
That's fine.
And so for those green points with an arrow out,
there's a unique F of the green point equal to a magenta
point in B that's uniquely determined by the functional
relation F, which may not be defined for all
of the green points if they don't have any arrow coming out
of them.
So function means less than or equal to 1 arrow coming out.
So if we set this formally without talking
about the arrows, one way is simply
to say that a relation is a function
if the size of F of little a is less than or equal to 1 for all
of the domain elements A.
And a more elementary way to say it
using just the language of relations and equality
and Boolean connectives is to say
that if a is connected to two things
by F-- if aFb AND aFb prime-- then in fact
b is equal to b prime.
And that wraps up functions.