TExcelTAD
Home › Calculus in Depth › Four Ways to Represent a Function

Four Ways to Represent a Function

A function can be given in words, as a table of values, as a graph or as a formula, and each form answers different questions. This lesson states the precise definition, shows how to move between the four representations, and covers piecewise functions, symmetry and monotonicity, which later chapters use constantly.

For a first look at domain and range, see Functions, Domain and Range.

The definition

A function ff from a set DD to a set EE is a rule that assigns to each element xx of DD exactly one element f(x)f(x) of EE.

  • DD is the domain. When a formula is given without a domain, the convention is the largest set of real numbers for which the formula makes sense.
  • The range is the set of values ff actually takes: {f(x):x∈D}\{ f(x) : x \in D \}. It can be smaller than EE.
  • The graph of ff is the set of pairs {(x,f(x)):x∈D}\{ (x, f(x)) : x \in D \}.

"Exactly one" is the whole point. A curve in the plane is the graph of a function of xx if and only if every vertical line meets it at most once (the vertical line test). The circle x2+y2=4x^2 + y^2 = 4 fails it: the line x=1x = 1 meets it at (1,3)(1, \sqrt{3}) and (1,−3)(1, -\sqrt{3}). It is the union of two function graphs, y=4−x2y = \sqrt{4 - x^2} and y=−4−x2y = -\sqrt{4 - x^2}.

The four representations

Form Example Good for Weak at
verbal "the monthly bill is a $5 base fee plus $0.12 per GB above 20 GB" modelling, requirements computing
numeric a table of sensor readings every 10 minutes measured data values between the samples
visual a plotted temperature curve trends, extremes, symmetry exact values
algebraic B(g)=5+0.12⋅max⁡(0,g−20)B(g) = 5 + 0.12 \cdot \max(0, g - 20) exact computation, calculus messy real data

Moving between them is a core skill. The verbal billing rule becomes a piecewise formula:

B(g)=5if 0≤g≤20B(g)=5+0.12(g−20)if g>20\begin{aligned} B(g) &= 5 && \text{if } 0 \le g \le 20 \\ B(g) &= 5 + 0.12(g - 20) && \text{if } g > 20 \end{aligned}

Code is just another algebraic representation:

python · try it yourself
def bill(gb):
    """Monthly bill in dollars for gb gigabytes of traffic."""
    if gb < 0:
        raise ValueError("domain is gb >= 0")
    return 5 + 0.12 * max(0, gb - 20)

for g in [0, 12.5, 20, 21, 50, 200]:
    print(f"{g:>6} GB -> ${bill(g):.2f}")
     0 GB -> $5.00
  12.5 GB -> $5.00
    20 GB -> $5.00
    21 GB -> $5.12
    50 GB -> $8.60
   200 GB -> $26.60

The raise makes the domain explicit, something a formula on paper only states in words. The range is [5,∞)[5, \infty).

Piecewise functions and absolute value

The absolute value is the most important piecewise function:

∣x∣=xif x≥0∣x∣=−xif x<0\begin{aligned} \lvert x \rvert &= x && \text{if } x \ge 0 \\ \lvert x \rvert &= -x && \text{if } x < 0 \end{aligned}

so ∣x∣≥0\lvert x \rvert \ge 0 always, and ∣x−a∣\lvert x - a \rvert is the distance between xx and aa on the number line. Sums of absolute values are piecewise linear: to rewrite one, split the line at the points where each expression inside changes sign.

Data to function

A table defines a function only at its sample points. Between them we must choose a model. The simplest is linear interpolation, which draws straight segments between neighbouring points:

python · try it yourself
import numpy as np

t = np.array([0, 10, 20, 30, 40])            # minutes
temp = np.array([18.0, 21.5, 23.0, 23.4, 23.5])  # °C

for q in [5, 15, 37]:
    print(f"T({q}) ≈ {float(np.interp(q, t, temp)):.2f} °C")

coeffs = np.polyfit(t, temp, 2)
print("quadratic fit:", [round(float(c), 5) for c in coeffs])
for q in [37, 60]:
    print(f"t = {q}: interp {float(np.interp(q, t, temp)):.2f}, fit {float(np.polyval(coeffs, q)):.2f}")
T(5) ≈ 19.75 °C
T(15) ≈ 22.25 °C
T(37) ≈ 23.47 °C
quadratic fit: [-0.00564, 0.35471, 18.17143]
t = 37: interp 23.47, fit 23.57
t = 60: interp 23.50, fit 19.14

Inside the data range the two models agree closely (about 0.1 °C apart at t=37t = 37). Outside it they part ways: asked about t=60t = 60, np.interp simply repeats the last value, while the quadratic, which has its peak near t=31t = 31, predicts the room cooling back down by four degrees. Neither is "right"; extrapolation depends entirely on the model you chose, and choosing it is a modelling decision, not a calculation. The next lesson's catalogue of functions is the menu to choose from.

Symmetry

  • ff is even if f(−x)=f(x)f(-x) = f(x) for every xx in the domain. Its graph is symmetric about the yy-axis (x2x^2, cos⁡x\cos x, ∣x∣\lvert x \rvert).
  • ff is odd if f(−x)=−f(x)f(-x) = -f(x). Its graph is symmetric about the origin (x3x^3, sin⁡x\sin x, 1/x1/x).

Products follow sign rules: even⋅even\text{even} \cdot \text{even} and odd⋅odd\text{odd} \cdot \text{odd} are even, even⋅odd\text{even} \cdot \text{odd} is odd. Symmetry saves real work later: the integral of an odd function over [−a,a][-a, a] is 0.

python · try it yourself
import sympy as sp

x = sp.symbols('x')
def parity(f):
    g = f.subs(x, -x)
    if sp.simplify(g - f) == 0:
        return "even"
    if sp.simplify(g + f) == 0:
        return "odd"
    return "neither"

for f in [x**4 - 3*x**2, x**3 * sp.cos(x), x / (x**2 + 1), sp.exp(x), sp.Abs(x) + x**2]:
    print(f, "->", parity(f))
x**4 - 3*x**2 -> even
x**3*cos(x) -> odd
x/(x**2 + 1) -> odd
exp(x) -> neither
x**2 + Abs(x) -> even

Increasing and decreasing

ff is increasing on an interval II if x1<x2x_1 < x_2 in II implies f(x1)<f(x2)f(x_1) < f(x_2), and decreasing if it implies f(x1)>f(x2)f(x_1) > f(x_2). The definition compares outputs for every pair of inputs, which is hard to check directly; in chapter 4 the derivative gives a practical test (How Derivatives Affect the Shape of a Graph).

In software

Every pure function in a program is a mathematical function: one output per input. A lookup table (dict, array) is the numeric representation, np.interp turns it into a continuous function, and a pricing rule, a tax bracket or a game's damage falloff is a piecewise function. Domain checks are input validation. Functions that are not functions in the mathematical sense, because they read a clock or a random generator, are exactly the ones that make tests flaky.

Exercises

Exercise 1: Domain from a formula

Find the domain of f(x)=1x2−5x+6f(x) = \dfrac{1}{\sqrt{x^2 - 5x + 6}}.

Answer

(−∞,2)∪(3,∞)(-\infty, 2) \cup (3, \infty)

Solution

The square root needs x2−5x+6≥0x^2 - 5x + 6 \ge 0 and the division needs it≠0\text{it} \ne 0, so we need x2−5x+6>0x^2 - 5x + 6 > 0.

x2−5x+6=(x−2)(x−3)>0both factors positive: x>3both factors negative: x<2\begin{aligned} &x^2 - 5x + 6 = (x - 2)(x - 3) > 0 \\ &\text{both factors positive: } x > 3 \\ &\text{both factors negative: } x < 2 \end{aligned}

Exercise 2: Remove the absolute values

Write g(x)=∣x−1∣+∣x+1∣g(x) = \lvert x - 1 \rvert + \lvert x + 1 \rvert as a piecewise function without absolute values, and give its range.

Answer

g(x)=−2xg(x) = -2x for x<−1x < -1, 22 for −1≤x≤1-1 \le x \le 1, 2x2x for x>1x > 1. Range [2,∞)[2, \infty).

Solution

The inside expressions change sign at x=−1x = -1 and x=1x = 1.

x<−1:(1−x)+(−x−1)=−2x−1≤x≤1:(1−x)+(x+1)=2x>1:(x−1)+(x+1)=2x\begin{aligned} x < -1{:} &\quad (1 - x) + (-x - 1) = -2x \\ -1 \le x \le 1{:} &\quad (1 - x) + (x + 1) = 2 \\ x > 1{:} &\quad (x - 1) + (x + 1) = 2x \end{aligned}

The outer pieces grow without bound and the middle piece is the smallest value, so the range is [2,∞)[2, \infty). Geometrically, g(x)g(x) is the total distance from xx to −1-1 and to 1, which is at least 2.

Exercise 3: A box as a function

An open box is made from a 20 cm×12 cm20\ \text{cm} \times 12\ \text{cm} sheet by cutting a square of side xx from each corner and folding up the sides. Write the volume V(x)V(x) with its domain, then estimate the largest volume numerically on a fine grid.

Answer

V(x)=x(20−2x)(12−2x)V(x) = x(20 - 2x)(12 - 2x) on 0<x<60 < x < 6. The maximum is about 262.7 cm3262.7\ \text{cm}^3 at x≈2.427x \approx 2.427.

Solution

After folding, the base is (20−2x)(20 - 2x) by (12−2x)(12 - 2x) and the height is xx. All three must be positive, so 0<x<60 < x < 6.

python · try it yourself
import numpy as np

x = np.linspace(0, 6, 600001)
V = x * (20 - 2*x) * (12 - 2*x)
i = int(np.argmax(V))
print(f"x ≈ {float(x[i]):.3f}, V ≈ {float(V[i]):.1f}")
x ≈ 2.427, V ≈ 262.7

Chapter 4 finds the exact maximiser x=(16−219)/3x = (16 - 2\sqrt{19})/3 with a derivative.

Exercise 4: Parity by the rules

Without computing, decide whether h(x)=x⋅cos⁡x+x3⋅∣x∣h(x) = x \cdot \cos x + x^3 \cdot \lvert x \rvert is even, odd or neither, then confirm with the parity function above.

Answer

Odd.

Solution

xx is odd and cos⁡x\cos x is even, so x⋅cos⁡xx \cdot \cos x is odd. x3x^3 is odd and ∣x∣\lvert x \rvert is even, so x3∣x∣x^3\lvert x \rvert is odd. A sum of odd functions is odd: h(−x)=−h(x)h(-x) = -h(x).

Test yourself

Which curve is NOT the graph of a function of xx?

  1. y=x3−xy = x^3 - x
  2. x2+y2=9x^2 + y^2 = 9
  3. y=∣x−2∣y = \lvert x - 2 \rvert
  4. y=1x2+1y = \frac{1}{x^2 + 1}

ff is even and gg is odd. What is f⋅gf \cdot g?

  1. Even
  2. Neither, always
  3. Odd
  4. It depends on ff and gg

What is the natural domain of f(x)=x−3x−5f(x) = \frac{\sqrt{x - 3}}{x - 5}?

  1. x>3x > 3
  2. x≥3x \ge 3 and x≠5x \ne 5
  3. x≠5x \ne 5
  4. x≥5x \ge 5