@reiver

Function Composition

In math, function composition is a way of combining 2 functions into one by "plugging" the output of one function into the input of another function.

Example

Let's first look at an example of this. Let's say we have two functions: f and g defined as follows:

f ( x ) := 2 x g ( x ) := x + 5

Then we can combine them using function composition as follows:

( f g ) ( x ) := f ( g ( x ) ) = 2 ( g ( x ) ) = 2 ( x + 5 ) = 2 x + 10

Function Composition Operator

Note that we have introduced this new operator that combines functions in this manner:

f g

Speaking, we'd say this as: "f circle g" or alternatively "f of g".

Not Commutative

Note that the order that you write that matters. In other words...

f g

... is NOT the same as...

g f

To illustrate this, if we use the same f and g from our previous example, then we can see that:

( g f ) ( x ) := g ( f ( x ) ) = ( f ( x ) ) + 5 = ( 2 x ) + 5 = 2 x + 5

Thus we can clearly see that, in general:

f g g f

(Although there will be some special cases where they will actually be equal.)

Another Example

Let's look at another example. Let's says we have two (new) functions (that have absolutely nothing to do with the functions in our previous example): f and g defined as follows:

f ( x ) := 8 x + 4 x 2 g ( x ) := x - 2

Then our function composition looks like:

( f g ) ( x ) := f ( g ( x ) ) = 8 ( g ( x ) ) + 4 ( g ( x ) ) 2 = 8 ( x - 2 ) + 4 ( x - 2 ) 2 = 4 x 2 - 8 x

Associative

We can combine more than two functions at a time. For example, if we had 3 functions, f, g and h, we could write:

f g h

The astute reader may have noticed that I have written this in a way that implies that function composition is associative. And in fact it is. In other words:

f ( g h ) = ( f g ) h

And when we have this property, we tend to just drop the brackets and write:

f g h

Or, in other words:

f ( g h ) = ( f g ) h = f g h

Example With 3 Functions

Here's an example with 3 functions. Let's say we have 3 functions, f, g and h, defined as follows:

f ( x ) := 1 + x g ( x ) := 5 + 20 x h ( x ) := 7 x

Then we can combine the 3 functions we with following function composition and get:

( f g h ) ( x ) := f ( g ( h ( x ) ) ) = 1 + ( g ( h ( x ) ) ) = 1 + ( 5 + 20 ( h ( x ) ) ) = 1 + ( 5 + 20 ( 7 x ) ) = 6 + 140 x

Inputs and Outputs

So far, I've picked the example very carefully. I wanted to keep thigs simple so we could focus on learning the topic. But now that we've learned it, we need to look at some things we need to be careful and mindful of. Let's look at this function composition:

f g

To actually be able to do this, we need the input of f to match the output of g.

To illustate why this is important, let's pick two functions which we cannot compose, because their inputs and outputs are incompatible.

f ( x , y ) := 3 x + y g ( x ) := x + 5

In this case, f g does not make any sense since the input of f is 2 dimensional and the output of g is one dimensional.

-- Mirza Charles Iliya Krempeaux
See Other Topics