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)) • $g \circ f$ in solid amber — the composition 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 f∘g and g∘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)=x2 and g(x)=sin(x). You see f(g(x))=sin2(x) in blue and g(f(x))=sin(x2) 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 x before f sees it.
Ten functions are available on each side: identity, quadratic x2, cubic x3, reciprocal 1/x, exponential ex, logarithm ln(x), sine, cosine, absolute value ∣x∣, and square root x.
You can pick the same function for both sides, in which case f∘g=g∘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 f's equation. Off by default. • $g$ — teal chip showing g's equation. Off by default. • $f \circ g$ — blue chip showing the composed expression f(g(x)). On by default. • $g \circ f$ — amber chip showing 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 and inner = x2, the f∘g chip reads "(x)2" and the g∘f chip reads "(x)2" — visibly different expressions even though they look similar at a glance. Algebraically the first simplifies to ∣x∣ and the second to x (for x≥0), which the plot then confirms.
Toggling the underlying functions f and g on lets you see directly how each composed curve relates to its ingredients.
Why Order Matters
Function composition is not commutative — in general, f∘g=g∘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)=x2 and g(x)=x+1:
• f(g(x))=(x+1)2=x2+2x+1 — square first the shifted value • g(f(x))=x2+1 — add 1 to the squared value
Plotting both, f∘g is a parabola shifted left by 1, while g∘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 f and g 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 sides — f∘g=g∘f trivially. The blue and amber curves coincide exactly.
• Identity as outer — f(g(x))=g(x). The composition is just g unchanged. Useful to see that the identity function f(x)=x acts as the neutral element for composition.
• Identity as inner — g(f(x))=f(x). Symmetric to the above.
• Exponential and logarithm — these are inverse functions. The info panel flags this: elnx=x for x>0, and ln(ex)=x for all real x. Both compositions collapse to (a restricted) identity. The plot shows two straight lines along y=x — the visual signature of an inverse pair.
• Square root and quadratic — a classic asymmetric pair: x2=∣x∣ (defined for all x, V-shaped), while (x)2=x (defined only for x≥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)=x2−4 (always non-negative or negative for ∣x∣<2) and f(x)=ln(x) (needs positive input). The composition ln(x2−4) is defined only where x2−4>0, i.e., ∣x∣>2. The blue curve has a gap in the middle.
• Outer expands the visible domain via even powers — x2 is defined for all x because x2≥0 always, even though x alone needs x≥0. The composed domain is broader than the outer function's natural domain.
• Reciprocal in the inner — 1/x has a singularity at 0; any composition with 1/x as inner has a vertical asymptote at x=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)) — read "f of g of x". The outermost function is the last to act; you evaluate inside-out. • Circle notation: (f∘g)(x) — read "f composed with g of x" or "f ring g". Same meaning. The ∘ symbol is the composition operator.
The order in f∘g is read right-to-left as inputs flow left-to-right: g is applied first (it sits next to the x), then f wraps around. Many students initially read this backwards. The picker labels "Outer (f)" and "Inner (g)" reinforce the correct mental model: outer = applied second, inner = applied first.
In the chip strip, both forms appear: the chip label uses circle notation (f∘g) while the formula uses the equivalent function-of-function form built from the actual expressions.
What Is Function Composition?
Composition takes two functions f and g and builds a new function by chaining them: the output of one becomes the input of the other. Formally, (f∘g)(x)=f(g(x)) for every x in the domain of g for which g(x) lies in the domain of f.
Geometrically, composition is a two-step pipeline: 1. Feed x into g, producing the intermediate value g(x). 2. Feed that intermediate value into f, producing the final value f(g(x)).
The result is itself a function — call it 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) is sine composed with squaring; e−x2/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)), the chain rule gives h′(x)=f′(g(x))⋅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 f−1 is the inverse of f precisely when f∘f−1=f−1∘f=id, the identity. Composition is the operation that defines what "inverse" means.
• Function transformations — the standard transformation g(x)=a⋅f(b(x−h))+k is a composition of f with the affine function bx−bh, then composed with another affine function ay+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 f∘g=g∘f=id. The companion visualizer plots f and f−1 together with the y=x mirror line.
Function Transformations — visualizer for the affine composition pattern a⋅f(b(x−h))+k. Composition with bx−bh on the inside and ay+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, double-angle formulas involve compositions of trig with doubling.
Polynomial Functions — the closure of polynomials under composition is the foundation of polynomial algebra.