 Hello, and welcome to a screencast on composition of functions. Composition of functions is a concept that allows us to take two functions that are compatible in a certain way and make a new third function out of them. Let's see how this works with a couple of examples. So there are many processes that we use every day that consist of a number of simple steps that are done in sequence. For example, when I make eggs for breakfast, this is a two-step process. First I have to break the eggs and stir them up. That's a change process if you think about it. I'm changing the eggs from an in-the-shell state to a mixed-up-in-the-bowl state. Then I have to take those stirred-up eggs and cook them in the frying pan. This is a change process, too. I'm changing the eggs from a liquid form to a solid form by applying heat. For the most part, we think of this whole process as a single process called making eggs, but really it's a combination of two processes that are compatible in the sense that the second process, the cooking in the pan, begins where the first process, the stirring up, ends. And this is done in a particular order. That order matters, of course. It wouldn't be a good idea to drop the eggs into the pan before I get them out of the shell. Likewise, computer programs are also processes that usually involve multiple simple processes that are chained together in a certain order. For example, let's suppose I wanted to write a program that takes a student's student ID number and returns their initials. This would really involve two processes joined together and done in sequence. First I'd have to write a process that changes an ID number into the student's name. That could be a program that goes out to the university database and looks up the person's ID number and returns their full name to me. Then I would have another process that picks up where the first process left off. I'd take the student's name and then convert the name into initials. In one sense, we think of this as one large process, but really it's broken down into two processes that are simple, that are compatible, again, in the sense that the second process starts where the first one ends, and they're done in order. Now, mathematically, processes like these are modeled by functions. And so what we're seeing here is that it's quite common to take two functions that are compatible, again, in the sense that one function starts where the other ends, and connect them together to make a more complex but more useful third function. That notion is the basic concept behind what we will call function composition. Here's our formal definition. Let A, B, and C be non-empty sets, and let there be two functions, F from A to B, and G from B to C. Note that the domain of G is the co-domain of F, so G begins where F ends. Then the composition of F and G is denoted by G circle F, and it's the function that goes from A to C defined by G circle F of X is equal to G of F of X for all X and A. Now, what does this mean? Well, this is just a formal way of defining this connecting of processes that we saw earlier with making eggs or converting an ID number to initials. We're taking two simple processes that are compatible in the sense that the second one, which we're calling G in the definition, begins where the first one, which we called F, ends. We ensure the compatibility of these two functions by making the co-domain of F equal to the domain of G. And then we just do these processes in order, F first and then G. Notice that we include all five main ingredients that we need for a function here. We've specified the domain and co-domain. We have defined the rule for the function. Given an X in the domain, we evaluate F at that point, and then we take the output from F and evaluate G there. Since both F and G are functions themselves, we know that every point in the domain will be evaluated, and we also know there will be no splitting. So let's take a look at an example of composite functions and see how they might work, and then we'll end with a concept check. First, let's take F to be the function from the real numbers to the integers, defined to be the round function we've seen before that rounds real numbers up to the next higher integer. Then let's define G to be the mapping from the integers to Z3, the set consisting of 0, 1, and 2. And let's let that be the function G of n equals n mod 3, to simply returning the least non-negative residue mod 3. Notice that the co-domain of F, which is the integers, is the domain of G, and so G begins where F ends. And this means we can form the composite function G circle F. This would be a function that goes from the real numbers all the way over to Z3. The definition of G circle F says that the function operates as follows. Given a real number X, G circle F is defined to be G of F of X. That means if I'm given an X as an input, remember X is a real number here, I'm first going to run X through F and get some output. And then I'm going to run that output through G to get a second output. That's my final answer. For example, if I start with square root of 11, that's about 3.31, then G circle F of square root of 11 is defined to be G of F of square root of 11. So first I would calculate F of square root of 11. That would be the round of square root of 11, which is 4. Then I'm going to take that output 4 and evaluate it into G. And G of 4 is equal to 4 mod 3, which is 1. So G circle F of square root of 11 eventually equals 1. Likewise, and you should check this on your own, G circle F of 2 pi is equal to 1. And G circle F of negative 3.2 is equal to 0. Notice that if we tried to reverse the order here and form F circle G, this wouldn't make mathematical sense. Because I would have to perform G first given an input. G is a function from the integers to Z3. And then I would have to take that output and load it into F. But the domain of F is the real number, it's not Z3. So in this case, I really can't reverse the order of composition because the co-domain of the first function is not equal to the domain of the second one. So let's have a concept check here to see how well you're acquiring this idea. Let F be the function from the real numbers to the real numbers defined by F of X equals 2X minus 5. And let G also be a function from the real numbers to the real numbers, defined by G of X equals 1 minus X square. So the question here is, what is the value of F circle G of 2? Take a look at the possibilities below and pause the video and vote. So the answer here is negative 11. Let's see why. Well, by definition, F circle G of 2 is defined to be F of G of 2. That means I'm going to take 2, run it through G, and then take the output of that process and run it through F. So running 2 through the function G gives me G of 2 is 1 minus 2 squared equals negative 3. Now let's take that output negative 3 and run it through F. That will give us F of negative 3 equals 2 times negative 3 minus 5, which is negative 6 minus 5, which is negative 11. Now the other options in this list, except for the very last one, does not exist, do arise through compositions, just not F circle G. The first option, 0, is the result of G circle F of 2, the same two functions, but composed in the opposite order. Now this time, the opposite order composition makes mathematical sense because the domains and the co-domains of F and G are all the same. So G circle F of 2, we would get by evaluating F of 2 first. That would give me 2 times 2 minus 5, which is negative 1. And then I take that result and run it through G, and that would give me G of negative 1 is 1 minus negative 1 squared, which is 1 minus 1, which is 0. Now negative 7 is obtained by composing F with itself. That is, it's F of F of 2, or F circle F of 2. The domain and co-domain of F are both a set of real numbers, so it makes sense to take a number and run it through F, and then re-run the output through F again. Here we'd get F of F of 2 by performing F first. So F of 2 is 2 times 2 minus 5, which is negative 1. And then take that negative 1 and run it back through F to get F of negative 1 is 2 times negative 1 minus 5, which is negative 7. The option down here of negative 8 is G circle G of 2. We get that by calculating G of 2 first to get 1 minus 2 squared, which is negative 3. Then running the result through G again, which would give me G of negative 3 is 1 minus negative 3 squared, which is 1 minus 9, which is minus 8. The last option does not exist here, isn't valid since the domain of the second function is always equal to the domain of the first. So that's a brief rundown of composition of functions. Thanks for watching.