0:03

Welcome back everyone.

We're going to continue with our module on functions.

And here, we're gonna talk about two important things to do with functions.

But first, we're gonna talk about what it means to compose two functions.

Then I'll just give you a basic idea of what that means with several examples.

In one of those examples we'll walk you into a warning,

the warning to say what we write at the front is that

you can't necessarily compose functions in any order you want,

and we'll show you why that's true.

Then we'll talk about a very specific type of

composing functions which will be able

to tell you that one function is an inverse of another.

In a nutshell, two functions are inverse,

if when you compose them,

they undo what they did before.

To give you a basic idea,

we'll show you a neat geometric picture and

then a warning – the warning is that not every function has an inverse,

and we'll see a geometric reason why.

OK, fine, let's get to it.

So let me give you the basic picture of what it means to compose functions.

Suppose we have f(x) = x^2 and g(x) = x+5.

Now I'm not gonna graph these for a second.

Let's remember that functions are actually machines that map sets to sets.

So here's a copy of the real line.

Here's a copy of the real line,

and here's the function f that goes from here to here.

So remember this machine takes any point x and maps it to x^2.

Here's another copy of the real line, here is an arrow,

and here's g. So this machine takes anything here and maps it to that thing plus five.

Okay, I'm now going to draw,

connect the triangle here with a dotted line.

And I'm going to do this funny symbol g circle f. We read this,

g composed with f,

g following f, sometimes you say.

What does that mean? By definition,

g composed with f,

of an input thing x is equal to, first,

you take x and feed it to f,

you let the machine go whir, chunk,

it spits out an output f(x).

Now you feed that output to g as an input, so g(f(x)).

So, it looks mysterious.

It's not that hard at all. Let's figure it out here.

Suppose I have a typical input x,

and let's compute what g of f(x) actually is in this example.

So that's supposed to be g of f(x).

Okay, fine. Great, buddy.

What's f(x)? f(x) is x^2, so this is g of x^2.

Now here's the hard part.

x^2 is now the input to the machine g. The machine takes anything and adds five to it.

Don't be deceived by the fact that you have an x here – that just stands for any input.

The input in this case is x^2,

so what do we do to x^2?

We add five to it.

So at the end of the day,

we get x^2 + 5.

For example, g of f of two will be g(f(2)),

g(f(2)) is 2^2, so that's g of two squared, which is g(4).

And then I take four and I add five to it,

and so I get nine.

That's what it means to compose functions.

Here's the warning.

Suppose let's do it in the reverse order: f of g of x.

By definition, that would be f(g(x)),

which in this case would be f(x+5).

Okay, now I take x+5 and I stick it in here, and there.

So f says take whatever input you have and, buddy, square it.

So, f(x+5) is (x+5), quantity squared,

which unfortunately is not the same as x^2 + 5 as we all know.

And so the punchline is that you can't

necessarily compose things in whatever order you want.

Often you can, but you don't get the same answer.

Okay, that's what it means to compose functions. It's pretty simple.

There's a special type of function that when you compose them, you undo what you did.

Let me just give you an example and then tell you the general term.

So suppose we start with f(x) = 2x.

Suppose someone magically hands us g(x) = 1/2 x.

Let's see what happens when we compose these.

So note, g of f of x is equal to g(f(x)).

f(x) is 2x, so now we have g(2x).

Great, so here's 2x.

Let's plug 2x in for x into the g machine and see what happens.

If I do that, I get 1/2 times the input,

which is 2x, and now you see the punchline – one half times two is one,

and this is back to x.

Notice that's true for every single x.

In other words, g of f of three,

if I follow through all this madness,

I'm gonna get three;

g of f of negative pi,

if I follow through all this madness,

I'm gonna get negative pi.

In this case, we say that,

f and g are inverses of each other.

That is, g undoes what f does.

And we write often this: g is equal to f to the -1.

Notice that doesn't mean one over f, right?

That's a very, very unfortunate notation.

Often when we say two to the -1,

we mean one half.

That's not really what we mean here.

We mean it's thing that undoes,

the machine that undoes the original machine.

If you liked your x and some idiot

came along and multiplied it by two and you weren't happy with that,

you didn't put a work order in for that,

g is a function which undoes what that idiot does and put it right,

sort of a way of getting rid of the stupid action.

That's the point. Okay, cool.

So, let's understand an interesting geometric relationship between inverses on the graph,

which is this picture we have right here.

So what I've just drawn here is the graph of y = 2x in green.

And, of course, someone told you that y = 1/2x is the inverse of that.

But, suppose you didn't know that, here's an interesting picture.

So suppose we have this graph here,

and let's think about a function as the input-output machine.

So we have f(x) = 2x.

We want to know how to undo that.

Suppose for example we know that f(x) = 4,

and what we want to know is what is this particular value of x, right?

That's sort of how you would undo it.

Someone took an x and turned it into four,

we didn't like that, we want x back.

How do we get our x back?

If this is our picture of y = 2x; here's four.

We can take this horizontal line at y=4 and dash it over until we hit the graph.

Remember the horizontal line test.

Spoiler, that's coming up in the next slide.

So here's this horizontal line,

it hits y = 2x,

and now let's just see what that x value is.

That x value is in fact two, right?

If we just drop it down here, we see two.

And that's true for any of these, right?

If I take any dotted line here and drop it,

whatever that x value is here is whatever input we needed to make that output.

So in essence what you're doing to find

the inverse is you're just swapping the roles of x and y.

One way to really do that is literally swap the y and x axes, swap their role.

And what that means to do is to reflect the entire picture in this blue dotted line,

y=x, in that 45 degree line.

If you do that to the green graph,

you get this red graph here which is y = 1/2 x.

No point really dwelling on that.

That doesn't really give you an algorithm for finding inverses,

but that's really the picture,

that's what's happening when you're finding

inverses of functions from the real line to the real line.

That picture leads us to the following very interesting warning.

So first let me just write this: warning,

not every function f from R to R has an inverse.

In fact, in some vaguely defined sense, most don't.

By the way, if you'd like a non-vague definition of most,

take lots and lots of probability courses –

that gets to be some really interesting abstract math,

which we're not gonna talk about here.

But let me just give you an example.

Let's take for example f(x) = x^2.

Let's draw the graph.

There is no inverse function here.

And let's think about pulling the same trick I did before.

Let's stretch this all the way up.

And here's a particular value here.

And let's figure out which x led to that value if I plugged in f(x),

so if someone told me, for example,

that f(x) = 4.

Well, I could drop the horizontal line this way and say,

"Aha! That's my x."

Unfortunately, that same horizontal line hits the graph in

another point – remember the horizontal line test

– and drop that down here and hits it somewhere else.

You actually know what these values are, right?

This is 2 and -2. That's the whole problem, right?

If I take the square root of four,

I actually have to take plus or minus,

the square root of four plus or minus,

that is, I have plus or minus two.

Those are two values which give when I square them, give me four.

That's the whole problem.

Remember that functions are machines which take one input and give you one output.

So I can't define a machine which takes four and sends it to 2,

-2, so there's no uniquely defined inverse.

The punch line here,

so the warning, say it negatively,

is if the graph of f fails the horizontal line test,

which we remember from the previous video,

then f has no inverse.

And if we remember what the horizontal line test tells us,

it means that the only invertible functions are

ones that are either strictly increasing or strictly decreasing.