On this page
If your textbook asks you to find fog and gof, the whole question is the order of the letters. Swap the order and you usually get a different function. Below we work one pair out line by line, then list the special pairs where the order really does not matter.
What do fog and gof mean?
The NCERT Class 12 Mathematics textbook defines the composition of f: A → B and g: B → C as the function gof: A → C given by gof(x) = g(f(x)) (NCERT Class 12 Mathematics, Chapter 1, Section 1.4).
Read it from right to left: in gof, f acts first; in fog, g acts first. You may also see them written g∘f and f∘g.
Is fog equal to gof for f(x) = x² and g(x) = x + 1?
Take f(x) = x² (square it) and g(x) = x + 1 (add one). Work each composition from the inside out.
fog(x) = f(g(x)) = f(x + 1) = (x + 1)² = x² + 2x + 1.
gof(x) = g(f(x)) = g(x²) = x² + 1.
Subtract: fog(x) − gof(x) = 2x, which is zero only at x = 0.
Test x = 2: fog(2) = 3² = 9, but gof(2) = 2² + 1 = 5.
So fog ≠ gof: ‘add one, then square’ is not ‘square, then add one’. NCERT's Example 16 reaches the same verdict for f(x) = cos x and g(x) = 3x², where gof(x) = 3cos²x but fog(x) = cos(3x²) (NCERT, Chapter 1).
Since the difference is 2x, the graphs meet only at x = 0, where both equal 1. See our post on why f(g(x)) and g(f(x)) differ, visualised.
When is fog equal to gof?
Functions that give the same result in either order are said to commute, and the Wikipedia article on function composition notes that this is a special property only particular functions have. These are the pairs you will meet most often.
A function and its inverse. NCERT's Definition 9 calls f invertible if there is a g with gof = I_X and fog = I_Y, where I is the identity function (NCERT, Section 1.4). For f(x) = 2x + 3 and f⁻¹(x) = (x − 3)/2, both orders give x.
The identity function with anything. I(x) = x leaves every function unchanged, in either order.
Two shifts. x + a and x + b both compose to x + a + b.
Two whole-number powers. x^m and x^n both compose to x^(mn), since (x^m)^n = (x^n)^m.
A function with itself. fof is trivially the same in either order.
One caution: in Definition 9, I_X and I_Y are identities on different sets, X and Y, so check where each one acts.
How do you test two linear functions quickly?
For f(x) = ax + b and g(x) = cx + d:
fog(x) = a(cx + d) + b = acx + ad + b
gof(x) = c(ax + b) + d = acx + cb + d
The x terms always match, so fog = gof exactly when ad + b = cb + d. Try f(x) = 2x + 1 and g(x) = 3x + 2: ad + b = 5 and cb + d = 5, so both orders give 6x + 5, even though neither function is the inverse of the other.
Why do √x and x² not always cancel?
This is the trap that costs marks. (√x)² = x, but only for x ≥ 0, because √x is not a real number when x is negative. Going the other way, √(x²) = |x| for every real x, so √((−3)²) = 3, not −3.
So x² and √x are inverses only once you restrict x² to x ≥ 0. Our guide to making a function one-one by restricting its domain shows how to choose that restriction.
How do you check any fog vs gof question?
Write both compositions in full, inner function first: f(g(x)) and g(f(x)).
Simplify each one separately, without cancelling across them.
Subtract. If the difference is not zero for every x, name one x where they differ and write both outputs.
State the domain of each, using the range-inside-domain check for when fog is defined.
If your working goes wrong at step 2 and you cannot see where, the Fermi Problem Library has worked problems with a step-by-step solver that explains the reasoning rather than printing an answer. If the gap is the idea of composition itself, the Fermi Concept Library gives each concept in mathematics its own lesson and its place in the map.
Try steps 1 to 3 on x² and x + 1 from memory. If you get 9 and 5 at x = 2, you have it.



