Int 3 for Programmers

Functions, transformations, composition and inverses

13 / 396
Contents

Contents

Int 3 for Programmers

0 of 396 complete

8 min read

Adding, multiplying and dividing functions

New functions built from old ones, and what happens to the domain when you do.

A shop tracks the money coming in and the money going out, each as a function of the day. The profit is one minus the other, and it is a function of the day too. Combining functions is that everyday operation, done carefully enough to keep the domain straight.

Run this and check any one row by hand before reading on.

Try CodePython

Swap the order in the subtraction column to g(x) - f(x) and run it again. Every entry changes sign, which is why the order in a difference is part of the question.

Nothing surprising happened, and that is the point: combining functions means combining their outputs, one input at a time. The notation gives the combination a name.

(f+g)(x)=f(x)+g(x)(fg)(x)=f(x) g(x)(fg)(x)=f(x)g(x)(f + g)(x) = f(x) + g(x) \qquad (fg)(x) = f(x)\,g(x) \qquad \left(\frac{f}{g}\right)(x) = \frac{f(x)}{g(x)}
Subtraction works the same way, with (f - g)(x) = f(x) - g(x).

The brackets on the left are doing something worth noticing. (f+g)(f+g) is the name of a new function, and (f+g)(x)(f+g)(x) is that new function evaluated at xx. With f(x)=2x+1f(x) = 2x+1 and g(x)=x−3g(x) = x - 3, the new rule is (f+g)(x)=(2x+1)+(x−3)=3x−2(f+g)(x) = (2x+1) + (x-3) = 3x - 2.

Multiplying means expanding: (fg)(x)=(2x+1)(x−3)=2x2−6x+x−3=2x2−5x−3(fg)(x) = (2x+1)(x-3) = 2x^2 - 6x + x - 3 = 2x^2 - 5x - 3. Check it at x=2x = 2: the rule gives 8−10−3=−58 - 10 - 3 = -5, and the table gives f(2)×g(2)=5×(−1)=−5f(2) \times g(2) = 5 \times (-1) = -5.

Subtraction needs one extra piece of care, because the minus sign applies to the whole of the second rule and not merely to its first term. With the same two functions, (f−g)(x)=(2x+1)−(x−3)(f - g)(x) = (2x + 1) - (x - 3), and removing the bracket gives 2x+1−x+3=x+42x + 1 - x + 3 = x + 4. Writing 2x+1−x−32x + 1 - x - 3 instead is the standard error, and it is out by 6 at every input.

What happens to the domain

Adding two functions cannot invent an input that either one refuses. Run this and watch where the combination gives up.

Try CodePython

Change the rule in g to 1 / (x - 9) and change the test x == 4 to x == 9. A different input drops out of the combined domain.

An input has to be acceptable to both functions before the combination can say anything about it. So the domain of f+gf + g, f−gf - g and fgfg is the overlap of the two domains, and nothing else. Here that is [0,4)∪(4,∞)[0, 4) \cup (4, \infty).

Division adds one more restriction of its own, and it has nothing to do with either original domain.

Try CodePython

Change g to return x * x - 4 and run it again. Now two inputs have to be thrown out rather than one.

So the domain of fg\frac{f}{g} is the overlap of the two domains with every input where g(x)=0g(x) = 0 removed as well. Both functions accept 2 quite happily; it is the division that fails there.

CombinationDomain
f+gf + g, f−gf - g, fgfgEverything in both D(f)D(f) and D(g)D(g)
fg\frac{f}{g}Everything in both, except inputs where g(x)=0g(x) = 0
The domain of a combination, with f and g having domains D(f) and D(g).

One worked example in full. With f(x)=x+5f(x) = x + 5 and g(x)=x2−9g(x) = x^2 - 9, find (fg)(x)\left(\frac{f}{g}\right)(x) and its domain.

  1. The rule is x+5x2−9\frac{x+5}{x^2-9}.
  2. Both ff and gg accept every real number, so the overlap is all of them.
  3. Ask where the bottom is zero: x2−9=0x^2 - 9 = 0 when x2=9x^2 = 9, so at x=3x = 3 and at x=−3x = -3.
  4. Remove both: the domain is (−∞,−3)∪(−3,3)∪(3,∞)(-\infty, -3) \cup (-3, 3) \cup (3, \infty).
ff has domain [2,∞)[2, \infty) and gg has domain (−∞,6](-\infty, 6]. What is the domain of fgfg?

[2,6][2, 6]. An input must be acceptable to both, so it must be at least 2 and at most 6. Both endpoints survive, because 2 is in ff's domain and also at most 6, and 6 is in gg's domain and also at least 2.

Check yourself

With f(x)=3xf(x) = 3x and g(x)=x−7g(x) = x - 7, which input is missing from the domain of fg\frac{f}{g}?

All lessons in Int 3 for Programmers