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∘g in solid blue — the composition f(g(x)) • g∘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 the quadraticf(x)=x2 and sineg(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.
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∘g — blue chip showing the composed expression f(g(x)). On by default. • g∘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:
• 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.
Composing with the Identity
The identity f(x)=x is composition's neutral element: whichever side it occupies, the other function passes through untouched.
Identity ∘ quadratic, frozen
Both compositions collapse onto the same parabola — the identity passes x² through untouched from either seat.
The algebra is one line each way: identity as outer gives f(g(x))=g(x); identity as inner gives g(f(x))=g(x) as well. Composition with the identity is the function-world analogue of multiplying by 1.
That neutrality is what makes the identity the reference point for inverse functions: a pair of functions are inverses precisely when their composition collapses to this do-nothing map.
In the picker, choosing identity for either role is the fastest sanity check that you have the outer/inner reading right — whichever curve survives unchanged is the other function.
Composing with the Quadratic
Squaring is the page's launch outer function, and the launch pair x2∘sin is the canonical order-matters demonstration.
x² and sin(x), both orders
Blue: (sin x)² folded positive at doubled frequency. Amber: sin(x²) accelerating outward. Same ingredients, different seats.
As outer, squaring acts on outputs: (sinx)2 oscillates between 0 and 1 — never negative, twice the frequency, all the wave's dips folded upward. As inner, it acts on inputs: sin(x2) keeps the full [−1,1] range but its oscillations accelerate as x2 races ahead — slow near the origin, frantic at the edges.
One function, two completely different jobs depending on which seat it takes. Output-side squaring reshapes values; input-side squaring reshapes pacing.
Squaring's even symmetry also transfers differently: sin(x2) is even (the input forgets sign), while (sinx)2 is even for its own reason — the output forgets sign. Compare with the cubic, which preserves sign in both roles.
Composing with the Cubic
Cubing looks like squaring's sibling, but it keeps the sign of whatever passes through — and that changes both compositions.
x³ and sin(x), both orders
Blue: (sin x)³ keeps its sign pattern, squashed toward the axis. Amber: sin(x³) oscillates ever faster. Both curves odd.
As outer, (sinx)3 still oscillates through negative values — the wave is squashed toward the axis at small amplitudes but keeps its sign pattern, unlike the always-positive (sinx)2. As inner, sin(x3) accelerates even more violently than sin(x2): the cubic's input-stretching grows with the cube of distance.
Cubing preserves oddness: sine is odd, cubing is odd, and both compositions are odd too — a composition of odd functions is always odd. The frozen scene shows it: both curves have point symmetry through the origin.
Put this section's picture next to the quadratic's and the even/odd contrast — the deepest difference between the two power functions — is visible at a glance.
Composing with the Reciprocal
The reciprocal 1/x injects singularities into any composition it joins — but where those singularities land depends entirely on its seat.
1/x and sin(x), both orders
Blue: 1/sin(x) — asymptotes at every multiple of π. Amber: sin(1/x) — infinitely fast oscillation packed against x = 0.
As outer, 1/sin(x) blows up wherever the inner function crosses zero: vertical asymptotes at every multiple of π, turning the gentle sine wave into the spiky cosecant. As inner, sin(1/x) has a single trouble spot at x=0 — but what a spot: as x→0, 1/x sweeps through infinitely many periods, and the curve oscillates infinitely fast, a classic pathological example.
The rule of thumb the pair teaches: an outer reciprocal converts the inner function's zeros into asymptotes; an inner reciprocal concentrates all the drama at its own singularity.
The exponential ex maps everything to positive territory — and as an outer function it lifts any bounded wave into a positive one.
eˣ and sin(x), both orders
Blue: e^(sin x) breathing between 1/e and e, always positive. Amber: sin(eˣ) flat on the left, frantic on the right.
As outer, esinx oscillates between e−1≈0.37 and e≈2.72: the sine's symmetric swing becomes an asymmetric breathing between reciprocal bounds, always positive. As inner, sin(ex) is flat and slow on the far left (where ex barely moves) and oscillates ever faster to the right as ex explodes.
The exponential's signature — turning addition into multiplication — shows in the outer role: equal ups and downs of sine become equal *ratios* above and below 1.
Its inverse partnership with the logarithm collapses both compositions to the identity — the special case given its own section in the inverse pair.
Composing with the Logarithm
The logarithm is the fussiest function in the picker — it demands positive input, so its compositions live or die by what the inner function delivers.
ln(x) and x², both orders
Blue: ln(x²) — two mirrored branches, the domain doubled by the inner square. Amber: (ln x)² — a valley bottoming at x = 1, half-line only.
As outer, ln(x2) survives everywhere except x=0: the squaring feeds it positive values on both sides, doubling the log's usual half-line domain into two mirrored branches. This is the domain-*expansion* trick — the composed domain is bigger than the log's own.
As inner, (lnx)2 keeps the log's restriction: nothing exists for x≤0. The squared output bends the log's slow climb into a valley bottoming at x=1, where ln1=0.
The general lesson: an outer function inherits its input supply from the inner one. Whether a composition's domain shrinks, survives, or grows is decided at that interface — the theme of Domain Restrictions in Composition.
Composing with Sine
Sine brings periodicity to whichever seat it takes — but only the outer seat lets it keep its own rhythm.
As outer, sin(x2) is sine forced to dance to the quadratic's tune: still bounded in [−1,1], but with wavelength shrinking as the input accelerates. As inner, (sinx)2 keeps sine's steady period; the squaring only reshapes the values.
The bound [−1,1] survives whenever sine is the last function applied — an outer sine caps any composition. An inner sine instead hands its bounded output to the outer function, which is why esinx and (sinx)2 are both bounded but sin(ex) merely oscillates.
Sine and cosine behave identically in composition up to a phase shift — swap them in any pair and the curves slide by a quarter period.
Composing with Cosine
Cosine composes exactly like sine — with one practical difference: it starts at its peak, and that changes where the composed features land.
cos(x) and x², both orders
Blue: cos(x²) ripples out symmetrically from its peak at the origin. Amber: (cos x)² traces the power-reduction identity.
As outer, cos(x2) begins at cos(0)=1 and ripples outward symmetrically — an even function of an even function. As inner, (cosx)2 oscillates between 0 and 1 with its maxima at multiples of π, tracing the power-reduction identity cos2x=21+cos2x in live geometry.
Because cosine is even, an inner cosine makes any composition even: f(cosx) always has mirror symmetry across the y-axis, whatever f is. That inheritance rule — symmetry flowing from the inner function outward — is one of composition's cleanest structural facts.
Everything else transfers from sine with a π/2 shift.
Composing with the Absolute Value
Absolute value is the fold: it reflects everything negative up into positive territory, and the two seats fold different things.
|x| and sin(x), both orders
Blue: |sin x| creased along the x-axis — the rectified wave. Amber: sin|x| creased along the y-axis — the mirrored wave.
As outer, ∣sinx∣ folds the output: every dip of the wave flips upward, producing the rectified sine — period halved to π, range [0,1]. As inner, sin∣x∣ folds the input: the right half of the sine wave is mirrored to the left, making the curve even but leaving each half unchanged.
The pair is the cleanest illustration of the outer/inner asymmetry because the fold is so easy to see: one graph is creased along the x-axis, the other along the y-axis.
Like the quadratic, an inner ∣x∣ forces evenness on any composition — both erase the input's sign before the outer function ever sees it.
Composing with the Square Root
The square root brings the sharpest domain scissors in the picker: whatever the inner function sends below zero is simply cut away.
√x and sin(x), both orders
Blue: √(sin x) survives only on the positive arches. Amber: sin(√x) lives on x ≥ 0 and slows as it goes.
As outer, sinx exists only where sinx≥0 — the positive arches survive as rounded humps and the negative dips vanish entirely, leaving a curve that lives on alternating intervals [2kπ,(2k+1)π]. As inner, sin(x) exists only for x≥0 and oscillates ever more *slowly*, since x feeds sine a decelerating input — the mirror image of the accelerating sin(x2).
An outer root censors the inner function's negative stretches; an inner root restricts the axis and stretches the pacing. Two different scissors from the same function.
Its algebraically famous pairing with the quadratic — x2 versus (x)2 — gets its own treatment in The Square and the Square Root.
The Inverse Pair: Exponential and Logarithm
Pick ex and lnx together, in either order, and composition performs its most elegant trick: both curves collapse onto the line y=x.
eˣ ∘ ln(x) and ln ∘ eˣ, frozen
Both compositions collapse onto y = x — blue on the positive half-line only, amber across the whole axis. Inverses, with their domains showing.
The collapse is the *definition* of inverse functions made visible: f and g are inverses exactly when f∘g and g∘f are the identity. The frozen scene shows the fine print too — elnx=x exists only for x>0 (blue half-line), while ln(ex)=x holds for every real x (amber full line).
That asymmetry between the two identity-copies is not a defect; it records the original domains. Undoing in one order can only recover what the first function accepted.
The identity target of this collapse is the subject of Composing with the Identity; the general theory lives on the inverse-functions tool, linked under Related Concepts.
The Square and the Square Root
The pair x2 and x looks like an inverse pair — and the frozen scene shows precisely why it only half-is.
√(x²) versus (√x)², frozen
Blue: √(x²) = |x| — the V, everywhere. Amber: (√x)² = x — the identity, but only for x ≥ 0. Half an inverse pair.
Order one: x2=∣x∣ — defined for every x, but V-shaped: squaring first destroys the sign, and the root cannot recover it. Order two: (x)2=x — a perfect identity, but only on x≥0, the root's own domain.
So one order gives the wrong function everywhere, and the other gives the right function on half the line. The failure is informative: x2 is not one-to-one, and only one-to-one functions have true inverses. Restrict the square to x≥0 and the pair becomes a genuine inverse pair — which is exactly how the square root is defined.
Choose the same function for both seats and the order question evaporates: f∘f is f∘f whichever way you read it.
x² ∘ x², frozen
Squaring twice gives x⁴: flatter valley, steeper walls — and the blue and amber curves coincide exactly, since order cannot matter.
The frozen example is squaring twice: (x2)2=x4 — a flatter valley near the origin and far steeper walls. Self-composition iterates a function, and iteration compounds its character: powers multiply (x2 twice is x4), growth stacks (eex grows absurdly), and contraction deepens.
Iterated maps are a field of their own — fixed points, cycles, chaos all live in the question "what happens when you compose a function with itself many times?" The visualizer shows iteration depth two; the interesting behavior at depth n starts here.
Note the coinciding curves in the scene: the blue and amber graphs are identical by construction, the degenerate case flagged in Special Cases.
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.