← Module 00 / Math starter kit

Lesson 00.2 · Prerequisite bridge

Functions are machines

Follow an input through simple rules, then connect the rules together.

In this lesson 5 ideas
  1. A rule with one output
  2. Connect two simple rules
  3. Ask where a function makes sense
  4. Reversing a rule
  5. An ML connection

A rule with one output

A function assigns exactly one output to every input in its domain. With g(x)=2xg(x)=2x, the input 3 produces 6; the input −2-2 produces −4-4. Different inputs can share an output: f(x)=x2f(x)=x^2 sends both 2 and −2-2 to 4. That still counts as a function.

Write g:R→Rg:\mathbb R\to\mathbb R to say that gg accepts real inputs and returns real outputs. The set after the arrow is the codomain. The outputs actually reached form the range. For f(x)=x2f(x)=x^2 with real inputs, the range is [0,∞)[0,\infty) even if we choose R\mathbb R as the codomain.

Connect two simple rules

Let gg double a number and let ff square a number. Connect the output of gg to the input of ff:

x→g2x→f(2x)2.x\xrightarrow{g}2x\xrightarrow{f}(2x)^2.
Explore it yourself

Follow the input

First double the input. Then square the result. Does changing the order matter?

Preparing interactive controls…

Input x2
g: multiply by 2…
f: square it…

Start with the input. No operation has happened yet.

The composite function is written f∘gf\circ g. Read it as “f after g.” Evaluate the inside first:

(f∘g)(x)=f(g(x))=4x2.(f\circ g)(x)=f(g(x))=4x^2.

Changing the order usually changes the answer:

(g∘f)(x)=g(x2)=2x2.(g\circ f)(x)=g(x^2)=2x^2.

For x=2x=2, those outputs are 16 and 8. Composition is an instruction sequence, not ordinary multiplication of function names.

Ask where a function makes sense

A formula comes with a domain. The real-valued square root r(x)=xr(x)=\sqrt{x} needs x≥0x\ge0. A reciprocal h(x)=1/xh(x)=1/x excludes zero. The natural logarithm needs x>0x>0. Composing functions means checking the intermediate output too: ln⁡(x−2)\ln(x-2) requires x>2x>2.

A function may accept several numbers. For example,

c(x,y)=2x+3yc(x,y)=2x+3y

could be the cost of xx notebooks and yy pens, at 2 dollars and 3 dollars each. This function has a pair as its input and one number as its output.

Reversing a rule

An inverse recovers the input from the output. The inverse of g(x)=2xg(x)=2x is g−1(u)=u/2g^{-1}(u)=u/2. The superscript −1-1 here means inverse function, not reciprocal.

Squaring on all of R\mathbb R has no inverse function: from the output 4, you cannot tell whether the input was 2 or −2-2. Restrict the input to [0,∞)[0,\infty) and the principal square root becomes an inverse.

Make a prediction

Let g(x) = x + 1 and f(x) = x². What is f(g(3))?

An ML connection

A prediction pipeline is a sequence of transformations. You might first rescale an input, then compute a score, then map that score to a prediction. Understanding the order now will make the chain rule easier later.