Category: Functions Level: 201
(f ∘ g)(x) = f(g(x)) = (x + 1)2, (g ∘ f)(x) = x2 + 1
Composition feeds the output of one function into another. The machine you reach first runs first, and swapping the order usually changes the answer.
Machine g adds one. Machine f squares. Put g first and f second, so the output of g drops straight into f.
g(x) = x + 1, f(x) = x2
Feed in 3. Machine g gives 4, and f turns 4 into 16. Read f(g(3)) from the inside out, the same order the machines run.
(f ∘ g)(3) = f(g(3)) = f(4) = 16
Feed in a plain x instead. Machine g hands over x + 1, and f squares the whole package.
(f ∘ g)(x) = (x + 1)2
Now f runs first. Three squared is 9, and 9 + 1 is 10, not 16. Same machines, different line, different result.
(g ∘ f)(3) = g(f(3)) = g(9) = 10
In general (x + 1)² and x² + 1 differ, so order matters. Putting on socks, then shoes, beats the reverse.
(x + 1)2 = x2 + 2x + 1 ≠ x2 + 1
cd svg-generator python3 -m svgmath render function-composition --out /tmp/function-composition
Source: svgmath/diagrams/function_operations.py