Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

3.2 Function Operations

A function operation is a procedure we can apply to transform or combine functions. Function operations are the essential tools that make mathematical modeling expressive. They are also the key to breaking complicated functions down into bite-sized pieces. The better you get at recognizing functions, and the richer your album of mental images, the more efficiently you will be able to break down formula into their pieces, visualize each piece, then visualize their combinations.

Linear Transformations...

  1. to the Input: These transforms are used to generalize almost every distribution family. They need to be instinctive.

    • Horizontal Translation: Replace f(x)f(x) with f(xs)f(x - s) to translate the function horizontally by a shift ss. For example, f(x3)f(x - 3) looks like f(x)f(x) shifted horizontally to the right by 3 units.

    Horizontal Translation
    • Dilation: Replace f(x)f(x) with f(x/a)f(x/a) for some a>0a > 0 to dilate the function. You can think of aa as controlling a zoom factor on the horizontal axis.

      • Using aa less than 1 compresses the function by making it narrower.

      • Using aa greater than 1 expands the function by making it wider. For example, setting a=3a = 3 makes the function three times wider.

      Horizontal Dilation
      • If a<0a < 0 then the result also reflects ff about x=0x = 0.

    • Generic: Replace f(x)f(x) with f((xs)/a)f((x - s)/a).

  2. to the Output: We can apply the same operations to the outputs of functions.

    • Vertical Translation: Replace f(x)f(x) with f(x)+hf(x) + h to translate the function vertically by a height hh. For example, f(x)+2f(x) + 2 looks like f(x)f(x) shifted vertically by 2 units.

    Vertical Translation
    • Vertical Scaling: Replace f(x)f(x) with cf(x)c f(x) to scale the function. You can think of cc as controlling a zoom factor on the vertical axis.

      • Using c<1c < 1 shrinks the function by making it shorter. For example, replacing f(x)f(x) with 13f(x)\frac{1}{3} f(x) compresses ff vertically by a factor of 3.

      Vertical Scaling
      • Using c>1c > 1 expands the function by making it taller.

      • If c<0c < 0 then the function reflects about the horizontal axis.

    • Generic: Replace f(x)f(x) with cf(x)+hc f(x) + h.

Run the code cell below to visualize linear transformations of the inputs and outputs of a function. You’ve used this tool to check function properties. This time, experiment with the four sliders that perform horizontal translation, dilation, vertical translation, and scaling. Watch the grid lines in the background. These will translate, squash, and stretch, as you translate, dilate and scale. They represent the linear transformation of the original coordinate system.

from utils_week3_functions import show_function_properties
properties = show_function_properties()

Function Combinations:

  1. Algebraic Combination:

    • Function Addition and Multiplication: As they sound, f(x)+g(x)f(x) + g(x) or f(x)×g(x)f(x) \times g(x).

      • Visualize the function sums like a stacked plot where the two functions sit on top of one another.

      • Visualizing function products takes practice, and is often best left to the tools from Sections 3.1 and Section 3.3. When given a product, always check the roots and sign of each term separately. Unfortunately, many distributions are expressed as products of functions.

    • Linear Combination: This is a special version of function addition. It looks like af(x)+bg(x)a f(x) + b g(x) for some coefficient aa and bb that scale each term in the combination.

      • You can visualize a linear combination either by drawing its two component functions, af(x)a f(x) and bg(x)b g(x) separately, then adding them together to produce the combo. The green and blue bumps are the component functions. The red curve is their linear combination. Varying aa or bb makes the associated bumps taller or shorter.

      Linear Combination
      • Alternately, you can use a stacked plot convention where you first draw af(x)a f(x), then you draw af(x)+bg(x)a f(x) + b g(x) where the difference between your first curve and your second curve is bg(x)b g(x). Here’s the same combination, using a stacked convention. In this example we drew the blue bump first, then added the green bump on top of it.

      Linear Combination Stacked
      • Important examples in probability are mixture distributions.

Run the code cell below to visualize function addition and multiplication.

from utils_week3_functions import show_function_combination
combination = show_function_combination()
  1. Function Composition: The composition of hh and gg is hg(x)=h(g(x))h \circ g(x) = h(g(x)). Many distributions are expressed as compositions.

    • To visualize an arbitrary function composition, proceed as follows:

    • This process is a bit involved at first, but it’s a nice visual procedure. Once you get the hang of it, you can use it to very quickly evaluate compositions of arbitrary hh and gg. Just repeat the process for a bunch of different xx values. It is good practice to try this by hand at least once.

Run the code cell below to visualize the composition of two functions.

from utils_week3_functions import show_function_composition
composition = show_function_composition()

The dashed orange lines represent the procedure provided above. Try building up an example composition. A good place to start is f(x)=e12x2+1f(x) = e^{-\frac{1}{2} x^2 + 1} where the inner function gg is a negated quadratic and the outer function is an exponential. You’ll practice with this example in discussion.

Here’s a different example with f(x)=h(g(x))f(x) = h(g(x)) with g(x)=0.2×(1+x2)g(x) = 0.2 \times(1 + x^2) and h(x)=1/xh(x) = 1/x.

Composite

We can also use three-dimensional plots to visualize function compositions. Set the first axis to the input, xx, the second to the inner function, g(x)g(x), and the third axis to the composition h(g(x))h(g(x)). If we plot gg as a function of xx, and hh as a function of gg, then we can recover h(g(x))h(g(x)) as a function of xx.

As an example, run the code cell below. Set the inner function to g(x)=12(x2+1)g(x) = \frac{1}{2} (x^2 + 1). Set the outer function to h(x)=0.5xh(x) = 0.5^x.

Click “Show Inner” to show the quadratic function. Then click “Show Outer” to show the exponential function.

Then click “Compose” to reveal the composite (dark red). Move the cursor to vary the input xx.

from utils_week_4 import show_composite_3d
composition_3d = show_composite_3d()

Inverses:

If ff is monotonic, then it is invertible. Its inverse, f1f^{-1} is the function that accepts outputs of ff and returns the matching input.

  • In other words, given f(x)=yf(x) = y, f1(y)=xf^{-1}(y) = x.

  • It can help to think, whatever ff does, f1f^{-1} undoes.

  • Inverse are constructed by reflecting ff about the x=yx = y line (exchange inputs and outputs).

    • To reflect, do the following:

    • The image below shows an example. The blue function if ff, the dashed grey line is the y=xy = x line that matches inputs and outputs, and the red curve is the inverse produced by reflecting across y=xy = x. The orange filled square is the square used to build the reflection.

Inverse Example

The most important examples in probability are the exponential and logarithm functions. Remember elog(x)=xe^{\log(x)} = x and log(ex)=x\log(e^{x}) = x.

Run the code cell below to visualize function inverses. Start with a linear function, and see how the inverse varies as we vary the initial function. The square you see represents the graphical construction outlined above. It is good practice to try this by hand at least once.

from utils_week3_functions import show_function_inverse
inverse = show_function_inverse()

Once you’ve run the code below, go back to the composition demo provided above, and pick inner and outer functions that are related by an inverse. For example, exe^x and log(x)\log(x). Then, the graphical construction used to create the composite will trace the boundary of the reflecting square, always returning the (x,x)(x,x) corner. In other words, f1(f(x))=xf^{-1}(f(x)) = x.