 In this video, we're gonna change pace a little bit. We're gonna still talk about combining functions together, but this time we're not gonna use the four arithmetic operations. We're gonna use a new type of combination that's unique just to functions. And this is called function composition. If we have two functions f and g, we can talk about the composite of f and g, which is denoted like this, f circle g. Sometimes we read this as f composed with g, f of g or something of that manner. Now, f composed with g is itself a function. So there has to be some rule that if I give you any x in the domain of f composed with g, then we can compute what the corresponding output is, what's the corresponding y-coordinate. So if x is in the domain of f composed with g, we then define f composed with g to be f evaluated at g of x. So g of x is itself a number. And so we're gonna put that number inside of f. So we're gonna evaluate f at the number of that g evaluates x at. And so to make that a little bit more clear, I want you to think of sort of the following analogy here. Functions are often thought of as machines. And so without drawing too much detail here, I'm gonna pretend my machine looks like this little bubblegum wrapper, right? This is the machine g. And so this is a machine and you can think of it as part of an assembly line. Some products come into the machine, it processes it, bam, bam, bam, bam, bam, bam, bam, computes it, no, no, no, no, no, no, no, changes it. It's gonna spit something out. So when the number x comes inside of this machine, it processes it, processes it, processes it, and then it's gonna spit out the number g of x. And so this is gonna change based upon what is the function g? And so an example we can use is, let's imagine we had like a soda factory, in which case we make a special type of soda and we put it into glass bottles and sell it. So the first machine you see right here, g, what it's gonna do is it has a timer built into it so that when you put in some type of container, it'll fill it up with say eight fluid ounces of our soda. That's the type we're making right now. And this machine can accept lots of different things, right? It can accept anything that can hold eight fluid ounces of soda, right? Now typically speaking, we're gonna be inserting our glass bottles into this machine, but you could also put an empty soda can in here. You could put an empty bowl or an empty bucket so long as it can hold eight fluid ounces. That's all that's required and that's what our first machine does. Now, suppose we have a second machine. The second machine we're gonna call it f, right? And with our soda analogy, we're gonna say f is a machine which seals bottles, caps onto bottles. So if you stick a bottle inside of f, it'll put a bottle cap on it as long as it's an open bottle. Now, if that bottle is filled with soda, it'll seal it. If that bottle is empty, it'll seal it, doesn't matter. It's just accepts as it's input empty bottles. And so when you put these two machines together, g, if you put g and f together are what we would call f composed with g. So as we put the two machines together, what this means is we're gonna put something inside of g. G will process it, b, b, b, b, b, b, b, b, b. It computes it and then it spits out g of x. Then g of x then becomes the input of f, in which case f computes it, b, b, b, b, b, b. And then it spits out the object f of g of x. And so when you put the two machines together, this creates a new function which we call the composite function and that's what we mean by f of g of x. So f of g of x, what it does is it computes g at x and then you compute f at g of x. You do the two things together. And so with our soda analogy, when you put your empty bottle inside of g, it fills the bottle with soda. Then you put that filled bottle inside of f, it seals it. And so the composition of the two functions is that you filled your soda and sealed it. And so now our bottle is ready to ship it to the grocery store and sell it. Now, when you start sticking two functions together via composition, we have to be concerned about the domain of these things. What is allowed to go inside of f of g? Well, since x first goes inside of g, if x is incompatible to fit inside of g here, what if like x is just too big, right? It doesn't fit, it doesn't fit, it doesn't fit. If x doesn't fit inside of g, then that will not fit inside of f composed with g. With our soda analogy, right, we can only accept things which can hold eight fluid ounces of soda. So bottles, bowls, buckets, or things we could shove inside there. If we shove a cat inside of g, it'll be very upset cat, it will not fill up with soda, it will not function correctly, right? So cat is not inside the domain of g. So anything that goes inside of f of g has to first fit inside of g. That part's pretty clear. But then the second part we have to be cautious about, the stuff coming out of g has to fit inside of f. So we have sort of the restriction here that the domain of f of g is gonna be everything that fits inside of the domain of g, right? But then we have to also restrict ourselves to those, those things in the range of g which are inside the domain of f. The thing coming out of g has to fit inside of f. So sure, if we stick an empty bottle inside of g, it'll process, it'll put out a filled bottle which can go inside of f, that's fine. So that empty bottle will be inside the domain of f of g. But if we were to stick some bowl, like some empty bucket into g, it would fill up with soda, no problem. But then we put that bucket of soda through f, f can't put a bottle cap on a bucket and therefore that would be incompatible. And so numerically we're looking for those type of things. We have to have numbers which fit inside of g such that the things coming out of g will fit inside of f. So let's look at some examples of such a thing here. We'll focus more on the domain in the subsequent videos. So take a look at that. Let's just make sure we have the basic mechanics here because the domain is a much more subtle creature there. Consider we have the function f of x equals 2x squared minus three and g of x equals 4x. How does one compute f of g of one? Well, f of g of one by definition is f of g at one. You say the same thing because the two things are equal. We have to first compute what is g of one. Now g of one would be four times one using the formula right here, which is equal to four. And then so then f of g of one would then equal f of four for which case we would take two times four squared minus three. Four squared is a 16 times that by two, you get 32 minus three should end up with 29. And so f of g of one is 29. What that means is we have like our machine g, we start off with one, it then transformed that into four, and then that gets transformed into 29 via the function f when we put these things together. That's what we're doing here. We just do one operation after the other. In the other direction, what if we did g of f of one? What if we switch the order of the machines? If we do f first, f of one is gonna equal two times one squared minus three. One squared is one times that by two, you get two, two minus three is negative one. And so then when we do g of f of one, that's g of f of one here, we end up with g of negative one. And then g of negative one is four times negative one, which is equal to negative four, right? And when you compare those two things together there, right, 29 and negative four are not the same number. That's a really long equal sign with a slash third in case you were wondering. 29 and negative four are not the same thing. If we switch the order of the functions, if we switch the order of the machines, we're gonna get a different result. And if you're not convinced about this, what I want you to do is try the following exercise. As you get ready to leave your house, put your socks on, then your shoes. And then the next time you get, you prepare to leave your house, put your shoes on, then your socks, right? If we switch the order in the sequence, it could have a dramatically different effect on the outcome here. And as another example, we can take f of f of one. What this would mean is f of f of one, right? And so we get f of two times one squared minus three, like so. And we saw a moment ago that f of one is negative one. And so this becomes f of negative one, like so. And then when you plug negative one into f, you'll get two times negative one squared minus three, which again gives you negative one squared, of course, is going to be just one in that case. You get two minus three, which is negative one again, like so. And then if you did that for g of g of one, g of g of one, gg here, you're gonna do g of one, which we did that earlier, we got a four. And then you're gonna get g of four, which is four times four, which is 16. So do pay attention to the order of operations here. We can compose these functions together and get things of the following nature. Let's do one more example before we finish this video right here. So this time let's take the new functions, f of x equals x squared plus one, which you see right here, g of x, which equals x minus three. And we're gonna compose them together, but this time take f of g of x, let's not evaluate it. Let's just kinda do it generically. Can we find a formula for f composed with g here as opposed to just individual evaluations like we were doing in the previous exercise? Well, f composed with g means you're gonna put g inside of f. And so g can be, you can substitute with g of x the formula x minus three. And so then you plug into that f of x minus three. Now in this situation, we now have to evaluate the function f at some algebraic expression other than x, which is actually something we've done previously. We were just practicing it, wax on, wax off. And now we actually see why one might do so. These calculations come up naturally when one does function composition. So what we're gonna do is in the formula of f everywhere we see an x, we're gonna replace with an x minus three, which is gonna give us an x minus three. Make sure you put a parentheses around all of g of x there. You're gonna get x minus three squared plus one, which that perfectly gives us the composition of the function. We potentially could stop right here and be like, yep, this is it. There are some benefits of doing that, right? As we study quadratic functions later on, we're gonna see that we're presently in the vertex form, which is pretty nice. But if we wanna expand it out, we take x minus three times x minus three plus one, foil out the x minus three times x minus three. You'll get x squared minus three x minus three x plus nine plus one, combining like terms, you get x squared minus six x plus 10, like so. And I should mention that the domain of this function, the composition of f of g, well, the domain of f and the domain of g are all real numbers. When you compose them together, we also get all real numbers. There's no restriction on the polynomial x squared minus six x plus 10. On the other hand, if we wanna compute g of f of x, we're gonna put f inside of g. Now, in the first example, we evaluated the inside function first, but you can also evaluate the outside function first, if you want. Because if you look at something like g of f of x, what that means is in the formula of g, you're gonna plug in f of x every time you see an x. So this would look like f of x minus three. And students often ask, which one do you do first? Do you evaluate the inside function or the outside function first? It really doesn't matter. It's always gonna be a two-step process. And so the first example, I evaluate the inside function first, then the outside function. And this one I evaluate the outside function first, and then we're gonna do the inside function. f of x is x squared plus one. We subtract three from that. We end up with x squared minus two. And so when you look at these things right here, you can see very clearly that although they're both quadratic functions, their domains are all real numbers, these two functions are not the same function. If you switch the order of the composition, it changes the outcome. Putting your shoes on, then your socks is not the same thing as putting your socks on, then your shoes. Order matters when it comes to function composition. And so as you switch up the order, you'll see that things do fundamentally change.