SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 1.1.1 What a function is: domain, range and notationConcept · 25 min
      2. 1.1.2 Transformations and piecewise functionsConcept · 30 min
      3. 1.1.3 Composition and inverse functionsConcept · 25 min
      4. 1.1.4 Practice set: functionsPractice set · 20 min
      5. 1.1.5 Case study: option payoff diagramsCase study · 30 min

Level 1, Precalculus 1.1 Functions and graphs Lesson 1 of 5

ConceptLesson 1.1.1 in Level 1, Precalculus. About 25 minutes.

What a function is: domain, range and notation

One input, one output

A function is a rule that takes an input and gives back exactly one output. Lesson 0.2.1 wrote this as f(x)f(x): the output of the rule ff at the input xx.

A table of values is the simplest way to see one. Here is f(x)=x2−2xf(x) = x^2 - 2x:

xx−1-10123
f(x)f(x)30−1-103

Two inputs may share an output: f(−1)=f(3)=3f(-1) = f(3) = 3. What a function may not do is give two outputs for one input. "The number whose square is xx" is not a function, because for x=4x = 4 it could be 2 or −2-2.

Rule: Function

x  ⟼  f(x)x \;\longmapsto\; f(x)

A function assigns to every allowed input exactly one output. Read the arrow as "goes to".

The output carries its own units, set by the rule. A car at a steady 60 km per hour has gone d(t)=60td(t) = 60t km after tt hours. The input is a time in hours and the output a distance in km, so d(2.5)=150d(2.5) = 150 km.

A function can be given by a formula, a table, a graph or a piece of code. All four answer the same question: which output goes with each input?

Try it

A Python function built from +, -, * and ** works on one number or on a whole NumPy array. One call on an array gives the whole table.

The two printed lines match the table above.

⌘/Ctrl + Enter runs the cell

The domain: which inputs are allowed

The domain is the set of inputs the function accepts. Unless told otherwise, it is every real number for which the formula makes sense.

Two things break a formula in this module: dividing by zero, and taking the square root of a negative number. Logarithms add a third in module 1.4.

Take g(x)=x−3g(x) = \sqrt{x - 3}. A table shows where it starts working:

xx234712
g(x)g(x)none0123

At x=2x = 2 the inside is −1-1, which has no square root. Algebra finds the edge exactly: the inside must be at least 0, so x−3≥0x - 3 \ge 0, which gives x≥3x \ge 3 (lesson 0.3.3).

The domain is the interval [3,∞)[3, \infty). The square bracket keeps 3 itself, because g(3)=0=0g(3) = \sqrt{0} = 0 is fine.

Now take h(x)=1x−2h(x) = \frac{1}{x - 2}. The bottom is zero at x=2x = 2, so the domain is every real number except 2. In set-builder notation (lesson 0.2.1) that is {x∈R:x≠2}\{x \in \mathbb{R} : x \neq 2\}.

Close to 2 the outputs grow very large, positive on one side and negative on the other: h(2.1)=10h(2.1) = 10, h(2.01)=100h(2.01) = 100 and h(1.9)=−10h(1.9) = -10.

Three more cases complete the picture.

  • Both rules at once. In 1x−3\frac{1}{\sqrt{x - 3}} the root needs x−3≥0x - 3 \ge 0 and the bottom needs x−3≠0\sqrt{x - 3} \neq 0. Together, x−3>0x - 3 > 0: the domain is (3,∞)(3, \infty), with 3 left out.
  • Nothing to break. x2−2xx^2 - 2x has no fraction and no root, so its domain is all of R\mathbb{R}.
  • Limits from the situation. A square of side ss cm has area A(s)=s2A(s) = s^2 cm². The formula accepts s=−2s = -2, but a side cannot be negative, so the domain is s≥0s \ge 0.

Rule: Finding the domain

topbottom: bottom≠0inside: inside≥0\begin{gathered} \frac{\text{top}}{\text{bottom}}: \ \text{bottom} \neq 0 \\ \sqrt{\text{inside}}: \ \text{inside} \ge 0 \end{gathered}

Find every bottom of a fraction and every square root, and remove the inputs where one fails. A root inside a bottom must be strictly positive. Then remove anything the situation rules out.

Try it

Python refuses inputs outside the domain. Each try block catches the error so the cell keeps going.

NumPy is more forgiving. It returns nan ("not a number") for a bad square root and inf (infinity) for a division by zero. The errstate line hides the warnings it would print.

The last line is 1x−3\frac{1}{\sqrt{x - 3}} at 3, 4 and 7: the edge 3 gives inf.

⌘/Ctrl + Enter runs the cell

The range: which outputs come out

The range is the set of outputs the function produces as the input runs over the whole domain. On a graph, the domain is the graph's shadow on the xx-axis and the range is its shadow on the yy-axis.

Domain and range as shadows of the graph. x−3\sqrt{x - 3} starts at (3,0)(3, 0), so its domain begins at 3 and its range at 0. x2−2xx^2 - 2x accepts every xx, and its lowest point (1,−1)(1, -1) sets the bottom of its range.

A graph suggests the range; algebra confirms it. A number yy is in the range when the equation f(x)=yf(x) = y has a solution in the domain. Rearrange it for xx, as in lesson 0.3.2.

  • x−3=y\sqrt{x - 3} = y. Squaring both sides gives x=y2+3x = y^2 + 3: the output 5, for example, comes from x=28x = 28. A square root is never negative, so this works for every y≥0y \ge 0 and no other. The range is [0,∞)[0, \infty).
  • 1x−2=y\frac{1}{x - 2} = y. Multiply by x−2x - 2 and divide by yy: x=2+1yx = 2 + \frac{1}{y}. That works for every yy except 0, so the range is every real number except 0. The graph never touches the xx-axis.
  • x2−2xx^2 - 2x. Multiplying out (x−1)2(x - 1)^2 gives x2−2x+1x^2 - 2x + 1, so x2−2x=(x−1)2−1x^2 - 2x = (x - 1)^2 - 1. A square is never below 0, so the output is never below −1-1, and it is −1-1 at x=1x = 1. The range is [−1,∞)[-1, \infty); lesson 1.2.2 turns this trick into a method.

A constant function such as c(x)=5c(x) = 5 has the smallest possible range: the single number 5.

Rule: Finding the range

y is in the range whenf(x)=y has a solution\begin{gathered} y \text{ is in the range when} \\ f(x) = y \text{ has a solution} \end{gathered}

Solve f(x)=yf(x) = y for xx. The outputs yy for which a solution exists, inside the domain, make up the range.

Lesson 0.2.1 wrote f:A→Bf: A \to B, read "ff takes inputs from AA to outputs in BB". The set AA is the domain.

The set BB only promises where outputs land; the range is the part of BB actually reached. For g:[3,∞)→Rg: [3, \infty) \to \mathbb{R} with g(x)=x−3g(x) = \sqrt{x - 3}, outputs land in R\mathbb{R}, but the range is only [0,∞)[0, \infty).

Try it

The first lines check the solving: feed in x=y2+3x = y^2 + 3 and gg gives back yy; feed in x=2+1yx = 2 + \frac{1}{y} and hh gives back yy.

Sampling many inputs estimates a range. On [−3,5][-3, 5], the lowest value of x2−2xx^2 - 2x is −1-1, at x=1x = 1. The highest, 15, is only the highest on this interval: the outputs keep growing beyond it.

⌘/Ctrl + Enter runs the cell

Graphs

The graph of ff is every point (x,f(x))(x, f(x)) drawn on a grid. Two places on it have names.

  • Where the graph meets the xx-axis, f(x)=0f(x) = 0. Those inputs are the zeros (or roots) of ff: for x2−2xx^2 - 2x, 0 and 2. A function can have no zeros: x2+4x^2 + 4 has range [4,∞)[4, \infty), so it never reaches 0.
  • Where the graph meets the yy-axis is the point (0,f(0))(0, f(0)), and f(0)f(0) is the yy-intercept. It exists only when 0 is in the domain, so x−3\sqrt{x - 3} has none.

A graph also shows at a glance whether a curve is a function at all. Two points straight above each other would mean two outputs for one input.

The vertical line test. The parabola meets every vertical line once. The curve y2=xy^2 = x pairs the input 4 with both 2 and −2-2, so it fails.

Rule: Vertical line test

each vertical line meetsthe graph at most once\begin{gathered} \text{each vertical line meets} \\ \text{the graph at most once} \end{gathered}

A curve is the graph of a function exactly when no vertical line crosses it twice. "At most" allows none: a vertical line outside the domain misses the graph.

Try it

A function written with NumPy operations works on a whole array at once, so one call gives every point to plot.

The dashed curve is a circle. A vertical line through its middle meets it twice, so it is not the graph of a function of xx. Change the formula in f and run the cell again to see another graph.

⌘/Ctrl + Enter runs the cell

These ideas carry the rest of the module. Lesson 1.1.2 moves and reshapes graphs, lesson 1.1.3 runs functions backwards, and case study 1.1.5 draws option payoffs as graphs.

Common mistakes

  1. Mixing up domain and range. The domain is about inputs; the range is about outputs.
  2. Getting the edge wrong. x−3\sqrt{x - 3} accepts 3, but 1x−3\frac{1}{\sqrt{x - 3}} does not: a root in a bottom must be strictly positive.
  3. Forgetting the situation. A length or a time cannot be negative, even if the formula accepts it.
  4. Trusting a sample as the whole range. Evaluating at many points shows the outputs on that interval only. Solve f(x)=yf(x) = y to be sure.
  5. Reading off a yy-intercept that is not there. f(0)f(0) exists only when 0 is in the domain.
  6. Using math on arrays. math.sqrt takes one number. For a NumPy array use np.sqrt.
  7. Accepting two outputs for one input. If a vertical line meets a curve twice, the curve is not a function of xx.
Check yourself
Which of these is not the graph of a function of xx?

Functions, domain and range

0 of 13 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
  12. 12.
  13. 13.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A function gives exactly one output for each input; its output has the units the rule produces. On a graph, every vertical line meets it at most once.
  • Domain: the inputs allowed. Remove inputs that divide by zero or take the square root of a negative number, and any the situation rules out.
  • Range: the outputs produced. yy is in the range when f(x)=yf(x) = y has a solution in the domain. On a graph, the range is the shadow on the yy-axis.
  • In f:A→Bf: A \to B, AA is the domain; the range is the part of BB actually reached.
  • Zeros are the inputs where f(x)=0f(x) = 0; the yy-intercept is f(0)f(0), when 0 is in the domain.
  • Write functions with NumPy operations (np.sqrt, not math.sqrt) and they work on whole arrays.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.