Class 12 Maths, Worked in Full Past papersGet updates
Chapter 1 · Relations and Functions

Example 16: g∘f≠f∘gg\circ f \ne f\circ g for cos⁡x\cos x and 3x23x^2

ExamplesComposition of functions · Section 1.4
The question

Find gofgof and fogfog⁠, if f:R→Rf : \R \to \R and g:R→Rg : \R \to \R are given by f(x)=cos⁡xf(x) = \cos x and g(x)=3x2g(x) = 3x^2⁠. Show that gof≠foggof \ne fog⁠.

Exam answer

For x∈Rx \in \R⁠,

gof(x)=g(f(x))=g(cos⁡x)=3cos⁡2x\begin{aligned} gof(x) &= g(f(x)) = g(\cos x) \\ &= 3\cos^2 x \end{aligned} fog(x)=f(g(x))=f(3x2)=cos⁡(3x2)\begin{aligned} fog(x) &= f(g(x)) = f(3x^2) \\ &= \cos(3x^2) \end{aligned}

At x=0x = 0⁠: gof(0)=3cos⁡20=3gof(0) = 3\cos^2 0 = 3 and fog(0)=cos⁡0=1fog(0) = \cos 0 = 1⁠.

∴ gof(0)≠fog(0)\therefore\ gof(0) \ne fog(0)⁠, so gof≠foggof \ne fog⁠.

Want the reason behind every step, the basics and the checks?

The one idea this problem is built on

The order of composition matters. gofgof means "do ff first, then gg", and fogfog means "do gg first, then ff". Here that is the difference between cosine then square-and-triple, giving 3cos⁡2x3\cos^2 x⁠, and square-and-triple then cosine, giving cos⁡(3x2)\cos(3x^2)⁠. Two functions are equal only if they agree at every input, so to show they are different we need just one input where they disagree. x=0x = 0 does it: 33 against 11⁠.

Given, to find and show, and the plan
Given
f(x)=cos⁡xf(x) = \cos x and g(x)=3x2g(x) = 3x^2⁠, both from R\R to R\R⁠.
To find and show
Formulas for gof(x)gof(x) and fog(x)fog(x)⁠; then that gofgof and fogfog are not the same function.
Plan
(1) Check both composites are defined. (2) Substitute to get gof(x)=g(cos⁡x)gof(x) = g(\cos x)⁠. (3) Substitute to get fog(x)=f(3x2)fog(x) = f(3x^2)⁠. (4) Recall what "equal functions" means, and find one xx where the two values differ.

Basics you need

1Composition

For f:A→Bf : A\to B and g:B→Cg : B \to C⁠, gof(x)=g(f(x))gof(x) = g(f(x))⁠. The function nearer to xx acts first. Basics: what a function is

2Substituting into a formula

g(x)=3x2g(x) = 3x^2 means "whatever goes in, square it and multiply by 3". So g(anything)=3(anything)2g(\text{anything}) = 3(\text{anything})^2⁠. The letter xx is only a placeholder.

3The notation cos⁡2x\cos^2 x

cos⁡2x\cos^2 x means (cos⁡x)2(\cos x)^2⁠, the square of the cosine. It is not cos⁡(x2)\cos(x^2)⁠, the cosine of the square. For example cos⁡20=12=1\cos^2 0 = 1^2 = 1⁠.

4When are two functions equal?

h=kh = k means they have the same domain, the same codomain, and h(x)=k(x)h(x) = k(x) for every xx in the domain. So h≠kh \ne k as soon as h(x0)≠k(x0)h(x_0) \ne k(x_0) for a single x0x_0⁠. Basics: proving and disproving

5A few values of cosine

cos⁡0=1\cos 0 = 1⁠, cos⁡π2=0\cos\frac{\pi}{2} = 0⁠, cos⁡π=−1\cos \pi = -1⁠, and −1≤cos⁡t≤1-1 \le \cos t \le 1 for every real tt⁠.

Solution

  1. Both composites are defined

    ff and gg both go from R\R to R\R⁠. The codomain of ff is R\R⁠, which is the domain of gg⁠, so gof:R→Rgof : \R \to \R is defined. In the same way the codomain of gg is the domain of ff⁠, so fog:R→Rfog : \R \to \R is defined too.

    Definition 8 needs the first function's outputs to be legal inputs for the second. Here every real number is a legal input to both cos⁡\cos and 3x23x^2⁠, so both orders work. (In Example 15 only one order was possible; here both are, which is what lets us compare them.)
    Definition 8: for f:A→Bf : A \to B and g:B→Cg : B \to C⁠, gof:A→Cgof : A \to C⁠, gof(x)=g(f(x))gof(x) = g(f(x))⁠. Lesson: composition of functions
  2. Find gofgof⁠: cosine first, then gg

    gof(x)=g(f(x))=g(cos⁡x)=3(cos⁡x)2=3cos⁡2x.gof(x) = g(f(x)) = g(\cos x) = 3(\cos x)^2 = 3\cos^2 x.
    We first replace f(x)f(x) by what it equals, cos⁡x\cos x⁠. That leaves g(cos⁡x)g(\cos x)⁠: the rule gg applied to the number cos⁡x\cos x⁠. The rule says square the input and multiply by 3, so the input cos⁡x\cos x becomes 3(cos⁡x)23(\cos x)^2⁠. The last equality is only the standard shorthand (cos⁡x)2=cos⁡2x(\cos x)^2 = \cos^2 x⁠.
    g(□)=3□2g(\square) = 3\square^2 whatever is put in the box (Basic 2). Writing the input in brackets, 3(cos⁡x)23(\cos x)^2⁠, avoids confusion with 3cos⁡(x2)3\cos(x^2) (Basic 3).
  3. Find fogfog⁠: gg first, then cosine

    fog(x)=f(g(x))=f(3x2)=cos⁡(3x2).fog(x) = f(g(x)) = f(3x^2) = \cos(3x^2).
    Now the inner function is gg⁠, so g(x)=3x2g(x) = 3x^2 is computed first. Then ff⁠, the cosine, is applied to that number. The square sits inside the cosine this time. The two answers contain the same ingredients (a cosine, a square, a factor 3), but in a different order, and that is exactly the point of the example.
    f(□)=cos⁡□f(\square) = \cos\square⁠. With □=3x2\square = 3x^2⁠, the result is cos⁡(3x2)\cos(3x^2)⁠, not 3cos⁡2x3\cos^2 x and not 3cos⁡(x2)3\cos(x^2)⁠.
  4. Show gof≠foggof \ne fog with one value of xx

    Both functions have domain R\R and codomain R\R⁠, so they are equal only if 3cos⁡2x=cos⁡(3x2)3\cos^2 x = \cos(3x^2) for every real xx⁠. Try x=0x = 0⁠:

    gof(0)=3cos⁡20=3⋅12=3,fog(0)=cos⁡(3⋅02)=cos⁡0=1.\begin{aligned} gof(0) &= 3\cos^2 0 = 3\cdot 1^2 = 3,\\ fog(0) &= \cos(3\cdot 0^2) = \cos 0 = 1. \end{aligned}

    Since 3≠13 \ne 1⁠, the two functions disagree at x=0x = 0⁠. Hence gof≠foggof \ne fog.

    −11230−1.5−1−0.50.511.5gof(0) = 3fog(0) = 1gof(x) = 3cos²xfog(x) = cos(3x²)
    Blue: gof(x)=3cos⁡2xgof(x) = 3\cos^2 x⁠. Gold: fog(x)=cos⁡(3x2)fog(x) = \cos(3x^2)⁠. At x=0x = 0 the blue curve is at 3 and the gold one at 1. The curves do cross at two points in this window (circled, near x≈±1.285x \approx \pm 1.285⁠), so some inputs happen to give equal values, but a single input with different values is enough to make the functions different.
    "gof=foggof = fog" is a claim about every real number, so one real number where it fails disproves it. That is why the textbook says only "for x=0x = 0": a single counterexample is a complete proof that the functions are not equal. We chose x=0x = 0 because both cosines are easy there (cos⁡0=1\cos 0 = 1⁠). The graph also shows why we must not test at a crossing point: there the two values agree, and that tells us nothing.
    Two functions are equal when they agree at every point of a common domain (Basic 4). One counterexample disproves a "for all" statement. Basics: proving and disproving
  5. A second way to see the difference

    Since −1≤cos⁡t≤1-1 \le \cos t \le 1 for every real tt⁠, the function fog(x)=cos⁡(3x2)fog(x) = \cos(3x^2) never takes a value larger than 1. But gof(0)=3>1gof(0) = 3 > 1⁠. So the value 3 is in the range of gofgof and not in the range of fogfog⁠. Functions with different ranges cannot be equal.

    This argument does not even need to compare the two functions at the same input. It looks at the set of values each one produces. Their ranges are [0,3][0,3] for gofgof (because 0≤cos⁡2x≤10 \le \cos^2 x \le 1⁠) and [−1,1][-1,1] for fogfog⁠. Different ranges force different functions.
    If h=kh = k⁠, they produce exactly the same outputs, so their ranges are equal. Contrapositive: different ranges mean h≠kh \ne k⁠.
Result

gof(x)=3cos⁡2x,fog(x)=cos⁡(3x2),x∈R.gof(x) = 3\cos^2 x, \qquad fog(x) = \cos(3x^2), \qquad x \in \R. At x=0x = 0⁠, gof(0)=3gof(0) = 3 but fog(0)=1fog(0) = 1⁠, so gof≠foggof \ne fog⁠. This agrees with the textbook's solution. Composition of functions is not commutative in general.

Check it with numbers

Another input: x=πx = \pi⁠. Then gof(π)=3cos⁡2π=3(−1)2=3gof(\pi) = 3\cos^2\pi = 3(-1)^2 = 3⁠, while fog(π)=cos⁡(3π2)fog(\pi) = \cos(3\pi^2)⁠, and 3π2≈29.613\pi^2 \approx 29.61⁠, so fog(π)≈−0.234fog(\pi) \approx -0.234⁠. Again different. And at x=1x = 1⁠: gof(1)=3cos⁡21≈0.876gof(1) = 3\cos^2 1 \approx 0.876⁠, fog(1)=cos⁡3≈−0.990fog(1) = \cos 3 \approx -0.990⁠. The verification script checks these values and also confirms that the two curves really do meet near x≈1.285x \approx 1.285⁠, where both equal about 0.23850.2385⁠.

Common mistakes
  1. Reading cos⁡2x\cos^2 x as cos⁡(x2)\cos(x^2)⁠. cos⁡2x=(cos⁡x)2\cos^2 x = (\cos x)^2⁠. At x=0x = 0 both happen to be 1, but at x=πx = \pi⁠, cos⁡2π=1\cos^2\pi = 1 while cos⁡(π2)≈−0.903\cos(\pi^2) \approx -0.903⁠.
  2. Swapping the meaning of gofgof and fogfog⁠. In gofgof the function ff (written on the right, next to xx⁠) acts first.
  3. Writing fog(x)=3cos⁡(x2)fog(x) = 3\cos(x^2)⁠. The factor 3 belongs to gg⁠, which acts first, so it ends up inside the cosine: cos⁡(3x2)\cos(3x^2)⁠.
  4. Trying to "prove" ≠\ne with algebra. No general manipulation is needed. A single value of xx where the outputs differ is a complete proof.
  5. Thinking one equal value means equal functions. The curves cross near x≈±1.285x \approx \pm 1.285⁠. Equality at some points does not give equality as functions.
What to take away
  1. To compose, substitute the inner function into the outer one: gof(x)=g(f(x))gof(x) = g(f(x))⁠.
  2. In general gof≠foggof \ne fog⁠: composition is not commutative. Always keep track of which function acts first.
  3. To show two functions are different, find one input where they differ. To show they are equal, you must argue for every input.

Every fact used, and where it comes from

FactUsed inSource
Definition of compositionSteps 1–3Definition 8, Section 1.4 (Lesson: composition)
cos⁡2x\cos^2 x means (cos⁡x)2(\cos x)^2Step 2Standard notation for powers of trigonometric functions
Equal functions agree at every pointStep 4Meaning of equality of functions (Basics: what a function is)
cos⁡0=1\cos 0 = 1⁠; −1≤cos⁡t≤1-1 \le \cos t \le 1Steps 4, 5Values and range of cosine (Class 11)
One counterexample disproves a "for all"Step 4Logic of quantifiers (Basics: proving and disproving)
Numerical values, crossing point, graph coordinatesCheck, figureRecomputed in the site's verification script
Found an error, or want more?

Tell us if something on this page is wrong or unclear, or if you would like a fuller explanation, another method or a new feature. Send feedback on this problem →