Composition of Functions

Composing two functions means feeding the output of one as the input of the other. This operation, denoted f g , is fundamental to calculus (especially the Chain Rule) and to computer science, where it models the chaining of procedures.

Quick Reference

Concept Formula / Rule
Composite function ( f g ) ( x ) = f ( g ( x ) )
Domain of f g { x Dom ( g ) g ( x ) Dom ( f ) }
Order matters f g g f in general
Associativity f g h = ( f g ) h = f ( g h )

What Is Composition?

If f ( x ) = x + 1 and g ( x ) = x 2 , we can define a new function h by substituting g ( x ) into f :

h ( x ) = f ( g ( x ) ) = f ( x 2 ) = x 2 + 1 .

In general, to form the composite f g , we start with x in the domain of g , apply g to get g ( x ) , and then apply f to that result, obtaining f ( g ( x ) ) . This requires g ( x ) to lie in the domain of f .

Machine diagram showing input x through g then f to produce f(g(x)).
(a) Machine diagram: x g g ( x ) f f ( g ( x ) ) .
Arrow diagram showing the mapping from x to g(x) to f(g(x)).
(b) Arrow diagram for f g .

Let f and g be two functions. The composite function f g is defined by

( f g ) ( x ) = f ( g ( x ) ) ,

for all x in the domain of g for which g ( x ) lies in the domain of f .

The domain of f g is:

Dom ( f g ) = { x x Dom ( g )  and  g ( x ) Dom ( f ) } .

Order matters: ( f g ) ( x ) = f ( g ( x ) ) and ( g f ) ( x ) = g ( f ( x ) ) are generally different functions.

Examples

Let f ( x ) = x and g ( x ) = 1 + x 2 . Find f g and g f with their domains.

Solution Dom ( f ) = [ 0 , ) , Dom ( g ) = . f g : ( f g ) ( x ) = f ( g ( x ) ) = f ( 1 + x 2 ) = 1 + x 2 . Since 1 + x 2 1 > 0 for all real x , g ( x ) always lies in Dom ( f ) . So Dom ( f g ) = . g f : ( g f ) ( x ) = g ( f ( x ) ) = g ( x ) = 1 + ( x ) 2 = 1 + x ( x 0 ) . f is defined only for x 0 , and f ( x ) = x 0 always lies in Dom ( g ) = . So Dom ( g f ) = [ 0 , ) .

If f ( x ) = x + 1 x 1 , find f f and its domain.

Solution ( f f ) ( x ) = f ( f ( x ) ) = f ( x + 1 x 1 ) = x + 1 x 1 + 1 x + 1 x 1 1 = 2 x x 1 2 x 1 = 2 x 2 = x . The formula simplifies to x , but the domain is not all of . We need:
  1. x Dom ( f ) : x 1 .
  2. f ( x ) Dom ( f ) : x + 1 x 1 1 , i.e., x + 1 x 1 , i.e., 1 1 (always true).
So the second condition imposes no additional restriction, and Dom ( f f ) = { 1 } .

Decomposing a Function

Any complex function can often be written as a composition of simpler ones. This skill is essential for the Chain Rule in calculus.

Find f and g such that h = f g where h ( x ) = cos ( x 2 ) .

Solution To compute h ( x ) , we first square x , then take the cosine. So: g ( x ) = x 2 (square the input) , f ( x ) = cos x (take cosine) . Check: ( f g ) ( x ) = f ( x 2 ) = cos ( x 2 ) = h ( x ) . ✓

Find f , g , h such that F = f g h where F ( x ) = | x | + 3 .

Solution To compute F ( x ) : first take the absolute value, then add 3, then take the square root. h ( x ) = | x | , g ( x ) = x + 3 , f ( x ) = x . Check: ( f g h ) ( x ) = f ( g ( | x | ) ) = f ( | x | + 3 ) = | x | + 3 = F ( x ) . ✓

Composing Three or More Functions

Composition is associative: f g h = ( f g ) h = f ( g h ) . You can group them in any order when composing more than two functions.

For example, F ( x ) = 1 2 + x 2 can be written as F = f g h where h ( x ) = x 2 , g ( x ) = x + 2 , f ( x ) = 1 x .

Frequently Asked Questions

Is composition commutative? Generally no. f g and g f are usually different functions. For example, with f ( x ) = x + 1 and g ( x ) = x 2 : ( f g ) ( x ) = x 2 + 1 but ( g f ) ( x ) = ( x + 1 ) 2 . These are not equal.

How do I find the domain of a composite function? First, find Dom ( g ) . Then, from those x -values, keep only those where g ( x ) falls inside Dom ( f ) . The intersection of these two restrictions is Dom ( f g ) .

Why is composition important in calculus? The Chain Rule in differential calculus says: if h = f g , then . To apply the Chain Rule, you need to recognize a function as a composition and identify its inner and outer parts.

Can a function be composed with itself? Yes. f f is called the iterate of f . For example, if f ( x ) = x 2 , then ( f f ) ( x ) = ( x 2 ) 2 = x 4 . Iterates appear in dynamical systems and the study of fractals.