Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Composition of Functions


QuadraticSinef(x) = · g(x) = sin(x)
×
880 × 600
Show







Getting Started with the Visualizer

Open the page and three panels appear. On the left, the picker is split into two halves: Outer ($f$) at the top and Inner ($g$) below. Each lists ten base functions. In the center, the plot panel shows up to four curves:

$f \circ g$ in solid blue — the composition f(g(x))f(g(x))
$g \circ f$ in solid amber — the composition g(f(x))g(f(x))
$f$ in dashed gray (off by default) — outer alone, for reference
$g$ in dashed teal (off by default) — inner alone, for reference

A legend chip strip below the plot lets you toggle any curve. By default only the two compositions are shown, so the asymmetry between fgf \circ g and gfg \circ f is the visual focus. On the right, the info panel shows the symbolic forms of both compositions and explains why the order matters for this specific pair.

The page launches with f(x)=x2f(x) = x^2 and g(x)=sin(x)g(x) = \sin(x). You see f(g(x))=sin2(x)f(g(x)) = \sin^2(x) in blue and g(f(x))=sin(x2)g(f(x)) = \sin(x^2) in amber — clearly two different curves built from the same two ingredients.

Picking Outer and Inner Functions

Two independent pickers control the composition:

Outer ($f$) — the function applied second. Highlighted in gray when active. This is the function you eventually feed the result into.
Inner ($g$) — the function applied first. Highlighted in teal when active. This is what processes xx before ff sees it.

Ten functions are available on each side: identity, quadratic x2x^2, cubic x3x^3, reciprocal 1/x1/x, exponential exe^x, logarithm ln(x)\ln(x), sine, cosine, absolute value x|x|, and square root x\sqrt{x}.

You can pick the same function for both sides, in which case fg=gff \circ g = g \circ f trivially and you see one curve doubled. Most pairs produce two distinctly different curves — that's the point. The picker uses color to signal which side you're choosing for: gray dot = outer, teal dot = inner.

The Legend Chips

Below the plot, four colored chips correspond to the four available curves:

$f$ — gray chip showing ff's equation. Off by default.
$g$ — teal chip showing gg's equation. Off by default.
$f \circ g$ — blue chip showing the composed expression f(g(x))f(g(x)). On by default.
$g \circ f$ — amber chip showing g(f(x))g(f(x)). On by default.

Click any chip to toggle that curve's visibility. The chip dims and the curve disappears.

The chip text updates live with the symbolic expression. With outer = x\sqrt{x} and inner = x2x^2, the fgf \circ g chip reads "(x)2\sqrt{(x)^2}" and the gfg \circ f chip reads "(x)2(\sqrt{x})^2" — visibly different expressions even though they look similar at a glance. Algebraically the first simplifies to x|x| and the second to xx (for x0x \geq 0), which the plot then confirms.

Toggling the underlying functions ff and gg on lets you see directly how each composed curve relates to its ingredients.

Why Order Matters

Function composition is not commutative — in general, fggff \circ g \ne g \circ f. The two compositions evaluate the same two functions but in opposite orders, and the resulting outputs are usually completely different.

Concrete example with f(x)=x2f(x) = x^2 and g(x)=x+1g(x) = x + 1:

f(g(x))=(x+1)2=x2+2x+1f(g(x)) = (x + 1)^2 = x^2 + 2x + 1 — square first the shifted value
g(f(x))=x2+1g(f(x)) = x^2 + 1 — add 1 to the squared value

Plotting both, fgf \circ g is a parabola shifted left by 1, while gfg \circ f is a parabola shifted up by 1. Same two functions, two very different graphs.

The plot makes this asymmetry the main visual story: by hiding ff and gg by default and showing the two compositions side-by-side, the page foregrounds exactly how much the order changes the result. Swap which function you pick for outer vs inner — the blue and amber curves swap roles.

Special Cases the Tool Highlights

The info panel watches the current pair and surfaces noteworthy combinations:

Same function on both sidesfg=gff \circ g = g \circ f trivially. The blue and amber curves coincide exactly.

Identity as outerf(g(x))=g(x)f(g(x)) = g(x). The composition is just gg unchanged. Useful to see that the identity function f(x)=xf(x) = x acts as the neutral element for composition.

Identity as innerg(f(x))=f(x)g(f(x)) = f(x). Symmetric to the above.

Exponential and logarithm — these are inverse functions. The info panel flags this: elnx=xe^{\ln x} = x for x>0x > 0, and ln(ex)=x\ln(e^x) = x for all real xx. Both compositions collapse to (a restricted) identity. The plot shows two straight lines along y=xy = x — the visual signature of an inverse pair.

Square root and quadratic — a classic asymmetric pair: x2=x\sqrt{x^2} = |x| (defined for all xx, V-shaped), while (x)2=x(\sqrt{x})^2 = x (defined only for x0x \geq 0). The two compositions are different graphs, illustrating that even when one composition simplifies cleanly, the reverse may not.

Domain Restrictions in Composition

Composition can create domain restrictions that neither original function had. The visualizer surfaces these naturally — wherever the composed value is undefined, the curve simply disappears from the plot.

Patterns to watch for:

Inner produces values outside outer's domain — pick g(x)=x24g(x) = x^2 - 4 (always non-negative or negative for x<2|x| < 2) and f(x)=ln(x)f(x) = \ln(x) (needs positive input). The composition ln(x24)\ln(x^2 - 4) is defined only where x24>0x^2 - 4 > 0, i.e., x>2|x| > 2. The blue curve has a gap in the middle.

Outer expands the visible domain via even powersx2\sqrt{x^2} is defined for all xx because x20x^2 \geq 0 always, even though x\sqrt{x} alone needs x0x \geq 0. The composed domain is broader than the outer function's natural domain.

Reciprocal in the inner1/x1/x has a singularity at 00; any composition with 1/x1/x as inner has a vertical asymptote at x=0x = 0, no matter what the outer function is.

These domain effects often determine whether the two composition orders look anywhere near each other.

Composition Notation

Two equivalent notations appear throughout the visualizer:

Function-of-function: f(g(x))f(g(x)) — read "ff of gg of xx". The outermost function is the last to act; you evaluate inside-out.
Circle notation: (fg)(x)(f \circ g)(x) — read "ff composed with gg of xx" or "ff ring gg". Same meaning. The \circ symbol is the composition operator.

The order in fgf \circ g is read right-to-left as inputs flow left-to-right: gg is applied first (it sits next to the xx), then ff wraps around. Many students initially read this backwards. The picker labels "Outer (ff)" and "Inner (gg)" reinforce the correct mental model: outer = applied second, inner = applied first.

In the chip strip, both forms appear: the chip label uses circle notation (fgf \circ g) while the formula uses the equivalent function-of-function form built from the actual expressions.

What Is Function Composition?

Composition takes two functions ff and gg and builds a new function by chaining them: the output of one becomes the input of the other. Formally, (fg)(x)=f(g(x))(f \circ g)(x) = f(g(x)) for every xx in the domain of gg for which g(x)g(x) lies in the domain of ff.

Geometrically, composition is a two-step pipeline:
1. Feed xx into gg, producing the intermediate value g(x)g(x).
2. Feed that intermediate value into ff, producing the final value f(g(x))f(g(x)).

The result is itself a function — call it h(x)=f(g(x))h(x) = f(g(x)) — that you can graph, differentiate, integrate, or further compose. Most "complicated" functions you meet in calculus are compositions of simpler ones: sin(x2)\sin(x^2) is sine composed with squaring; ex2/2e^{-x^2/2} is exponential composed with negative-half-square.

Composition is the natural way to build up functions from a small library of primitives, which is why it appears in nearly every later topic: chain rule, inverse functions, change of variables, transformations, and more.

Why Composition Matters

Composition is the operation by which simple functions combine into complex ones. Three big places it shows up:

Chain rule in calculus — to differentiate h(x)=f(g(x))h(x) = f(g(x)), the chain rule gives h(x)=f(g(x))g(x)h'(x) = f'(g(x)) \cdot g'(x). Every nested derivative computation is a composition unpacking. Without understanding composition, the chain rule looks arbitrary; with it, the rule is just "apply the derivative-of-pipeline rule."

Inverse functions — a function f1f^{-1} is the inverse of ff precisely when ff1=f1f=idf \circ f^{-1} = f^{-1} \circ f = \text{id}, the identity. Composition is the operation that defines what "inverse" means.

Function transformations — the standard transformation g(x)=af(b(xh))+kg(x) = a \cdot f(b(x - h)) + k is a composition of ff with the affine function bxbhbx - bh, then composed with another affine function ay+kay + k. Every transformation visualizer is implicitly working with composition.

Beyond these, composition is the algebraic backbone of category theory, group theory, and most of abstract mathematics. Mastering it visually here pays off broadly.

Related Concepts and Tools

Inverse Functions — the special case of composition where fg=gf=idf \circ g = g \circ f = \text{id}. The companion visualizer plots ff and f1f^{-1} together with the y=xy = x mirror line.

Function Transformations — visualizer for the affine composition pattern af(b(xh))+ka \cdot f(b(x-h)) + k. Composition with bxbhbx - bh on the inside and ay+kay + k on the outside.

Chain Rule — calculus theory for differentiating compositions. Reads directly from the inner-outer structure the picker exposes.

Function Types — the catalog of base function families used as building blocks. Every entry in the picker comes from this catalog.

Domain of a Function — composed functions often have restricted domains that neither original function had. The Domain visualizer helps reason about these restrictions.

Function Symmetry — composing two even functions stays even; composing two odd functions stays odd; mixed compositions may break both. A nice cross-cutting exercise.

Trigonometric Identities — many trig identities are statements about specific compositions: sin2+cos2=1\sin^2 + \cos^2 = 1, double-angle formulas involve compositions of trig with doubling.

Polynomial Functions — the closure of polynomials under composition is the foundation of polynomial algebra.