Composite Function Calculator

Both orders composed symbolically, f(g(x)) and g(f(x)), with two-stage numeric evaluation.

Composite Function Calculator

What Is Function Composition?

Composition chains functions: (f ∘ g)(x) = f(g(x)) feeds x into g, then feeds g's output into f. It is the assembly line of mathematics, machine g processes the raw input, machine f processes the result, and the order matters enormously: f(g(x)) and g(f(x)) are different products from the same two machines.

Composition is also the single most important structure to see inside a formula before calculus begins. sin(3x) is sin ∘ (multiply by 3); √(x² + 4) is √ ∘ (x² + 4); e^(−x²) is exp ∘ negate ∘ square. The chain rule the workhorse of differentiation, is precisely the rule for differentiating compositions, and students who can decompose fluently find it almost mechanical, while those who can't find it mysterious. This page trains the decomposition eye in both directions.

How to Use This Calculator

Enter the outer function f and inner function g. The calculator substitutes symbolically, every x in f replaced by g's whole formula, and simplifies, producing both orders: f(g(x)) and g(f(x)). Add a point to see the two-stage evaluation numerically (first g(x), then f of that), which is the order-of-operations story told with actual numbers. The plot draws both compositions (solid indigo for f∘g, dashed teal for g∘f) so the non-commutativity is visible, not just asserted.

Worked Example

With f(x) = x² + 1 and g(x) = 2x − 3:

(f ∘ g)(x) = f(2x − 3) = (2x − 3)² + 1 = 4x² − 12x + 10
(g ∘ f)(x) = g(x² + 1) = 2(x² + 1) − 3 = 2x² − 1

Two genuinely different parabolas from the same ingredients. At x = 2: g(2) = 1, then f(1) = 2, so (f∘g)(2) = 2, while (g∘f)(2) = g(5) = 7. The numeric check is more than verification; the two-stage arithmetic is the definition, and running it by hand once per problem keeps the substitution honest.

Domains of Compositions: the Two-Gate Rule

The domain of f ∘ g is not simply g's domain: x must pass two gates, x in the domain of g, and g(x) in the domain of f. The second chip illustrates the pleasant case: √(x² + 4) is defined for all x because x² + 4 ≥ 4 never violates √'s requirement. Swap the roles, though, and (g ∘ f)(x) = (√x)² + 4 is defined only for x ≥ 0, even though the simplified formula "x + 4" looks global. The simplification hid the gate. This is a recurring trap: simplify after recording the domain, not before because algebra performed on a formula can silently enlarge where it seems to be defined. The domain calculator handles each gate's inequality when the pieces get complicated.

Common Mistakes to Avoid

  • Multiplying instead of composing. f(g(x)) is substitution, not the product f(x)·g(x). The notation f ∘ g's little circle is not a multiplication dot, a classic misreading under exam pressure.
  • Substituting into only some x's. Every occurrence of x in f gets replaced by the entire expression g(x), parentheses and all. With f(x) = x² − x, f(2x−3) = (2x−3)² − (2x−3); dropping the second replacement (or its parentheses) is the most common algebra slip.
  • Assuming f ∘ g = g ∘ f. Almost never true, the worked example gives 4x² − 12x + 10 versus 2x² − 1. Equality happens only in special families (inverse pairs compose to x; power functions commute with each other).
  • Losing domain restrictions during simplification. (√x)² simplifies to x but its domain stays x ≥ 0. Record the two-gate domain from the unsimplified composition first.

Real-World Applications

Composition is how multi-stage processes become single formulas. Retail pricing: a discount function then a tax function, and the order (tax-then-discount vs discount-then-tax) changes the receipt, a daily-life proof of non-commutativity. Currency conversion followed by fees, temperature conversion chains (Celsius → Fahrenheit → "feels like"), unit pipelines in engineering, all compositions, all order-sensitive.

In computing, composition is the organizing principle itself: Unix pipes, spreadsheet formulas referencing formulas, neural networks (each layer a function, the network a deep composition, trained by the chain rule under the name "backpropagation"), and functional programming's compose operator. In calculus applications, related-rates problems are compositions with time (radius depends on t, volume on radius, so volume on t), and every u-substitution in integration is composition recognized in reverse. Fluency here is fluency everywhere downstream.

Frequently Asked Questions

How do I decompose a function into f ∘ g?

Find the "inside", the expression a substitution u could stand for, and let g be it, f the outer shell. For √(x² + 4): g = x² + 4, f = √u. Useful test: if you'd compute it on a calculator in two keystrokes, the first keystroke is g, the second is f. Decompositions aren't unique; pick the one that makes the outer function elementary.

Can I compose a function with itself?

Yes, (f ∘ f)(x) = f(f(x)) is iteration, written f². With f(x) = 2x − 3: f(f(x)) = 4x − 9. Repeated self-composition is the mathematics of recurrence: population year over year, interest month over month, and the iteration inside Newton's method.

What undoes a composition?

Inverses in reverse order: (f ∘ g)⁻¹ = g⁻¹ ∘ f⁻¹, socks on then shoes on is undone shoes off then socks off. The inverse function calculator finds the individual inverses this rule chains together.

Is composition associative?

Yes: f ∘ (g ∘ h) = (f ∘ g) ∘ h, a triple chain needs no parentheses, and long pipelines are unambiguous. Order still matters (no commutativity), but grouping doesn't: the assembly line runs the same regardless of how you bracket the stations.

How does the chain rule use composition?

It differentiates the chain link by link: (f(g(x)))′ = f′(g(x))·g′(x), outer derivative evaluated at the inner function, times inner derivative. Identifying f and g correctly (this page's skill) is 90% of every chain rule problem; the remaining 10% is multiplication.

Why does my simplified composition seem to have a bigger domain?

Because algebraic simplification can cancel the very piece that carried the restriction, (√x)² → x loses the x ≥ 0 gate. The composition's true domain is computed from the unsimplified two-gate rule; the simplified formula is an alias valid only there.