TExcelTAD
Home › Calculus Essentials › Types of Functions

Types of Functions

Most functions you meet in calculus belong to a handful of families: polynomials, rational functions, roots, exponentials, logarithms, trig functions and piecewise rules. Knowing the family tells you the graph's shape, the domain and how the function will behave under differentiation before you compute anything.

The main families

Family General form Example Domain Shape
Constant f(x)=cf(x) = c f(x)=4f(x) = 4 all reals horizontal line
Linear f(x)=mx+bf(x) = mx + b 2x−12x - 1 all reals straight line, slope mm
Quadratic ax2+bx+cax^2 + bx + c x2−4x+3x^2 - 4x + 3 all reals parabola
Polynomial anxn+⋯+a1x+a0a_n x^n + \cdots + a_1 x + a_0 x3−xx^3 - x all reals smooth, at most n−1n - 1 turns
Rational P(x)/Q(x)P(x)/Q(x) 1/(x−2)1/(x - 2) where Q(x)≠0Q(x) \ne 0 can have asymptotes
Power / root xpx^p x=x1/2\sqrt{x} = x^{1/2} depends on pp
Exponential axa^x (a>0a > 0, a≠1a \ne 1) 2x2^x, exe^x all reals always positive
Logarithmic log⁡ax\log_a x ln⁡x\ln x x>0x > 0 slow growth
Trigonometric sin⁡x\sin x, cos⁡x\cos x, tan⁡x\tan x sin⁡x\sin x depends periodic
Piecewise different rules on different intervals ∣x∣\lvert x \rvert, ReLU may have corners or jumps

Algebraic functions are built from xx with ++, −-, ×\times, ÷\div and roots (polynomials, rational functions, x\sqrt{x}). Transcendental functions are everything else: exponentials, logs and trig functions. The split matters later because derivatives and integrals of transcendental functions follow their own rules.

Properties that describe a function

Property Test Example
Even f(−x)=f(x)f(-x) = f(x); graph symmetric about the yy-axis x2x^2, cos⁡x\cos x, ∣x∣\lvert x \rvert
Odd f(−x)=−f(x)f(-x) = -f(x); symmetric about the origin x3x^3, sin⁡x\sin x, tanh⁡x\tanh x
Increasing on an interval a<b⇒f(a)<f(b)a < b \Rightarrow f(a) < f(b) exe^x everywhere
Decreasing on an interval a<b⇒f(a)>f(b)a < b \Rightarrow f(a) > f(b) 1/x1/x on (0,∞)(0, \infty)
One-to-one different inputs give different outputs x3x^3 yes, x2x^2 no
Periodic f(x+p)=f(x)f(x + p) = f(x) for some p>0p > 0 sin⁡x\sin x with p=2πp = 2\pi
Bounded outputs stay between two numbers sin⁡x\sin x stays in [−1,1][-1, 1]

Most functions are neither even nor odd, for example x2+xx^2 + x. A quick symbolic check:

python · try it yourself
import sympy as sp

x = sp.symbols('x')
candidates = [x**2, x**3, sp.cos(x), sp.sin(x), x**2 + x, sp.tanh(x), sp.Abs(x)]

for f in candidates:
    g = f.subs(x, -x)
    if sp.simplify(g - f) == 0:
        kind = "even"
    elif sp.simplify(g + f) == 0:
        kind = "odd"
    else:
        kind = "neither"
    print(f"{str(f):10} {kind}")
x**2       even
x**3       odd
cos(x)     even
sin(x)     odd
x**2 + x   neither
tanh(x)    odd
Abs(x)     even

Piecewise functions

A piecewise function uses different formulas on different parts of its domain. The absolute value is the classic example:

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

In code a piecewise function is simply an if, or np.where for arrays:

python · try it yourself
import numpy as np

def shipping_cost(kg):
    if kg <= 1:
        return 4.0
    elif kg <= 5:
        return 4.0 + 1.5 * (kg - 1)
    else:
        return 10.0 + 1.0 * (kg - 5)

for kg in [0.5, 1, 3, 5, 8]:
    print(f"{kg:>4} kg -> {shipping_cost(kg):.2f}")

xs = np.array([-2.0, -0.5, 0.0, 1.5])
print("|x| via np.where:", np.where(xs >= 0, xs, -xs))
 0.5 kg -> 4.00
   1 kg -> 4.00
   3 kg -> 7.00
   5 kg -> 10.00
   8 kg -> 13.00
|x| via np.where: [2.  0.5 0.  1.5]

The pieces of shipping_cost meet without a jump at 1 kg and 5 kg. Whether pieces join up (continuity) and whether they join without a corner (differentiability) are exactly the questions of the next chapter.

In software: activation functions

Every artificial neuron computes a weighted sum z=wx+bz = wx + b and then passes it through an activation function. The three classics come from three different families:

Activation Formula Family Range Property
Sigmoid σ\sigma 1/(1+e−z)1/(1 + e^{-z}) exponential (rational in eze^z) (0,1)(0, 1) increasing, bounded
tanh (ez−e−z)/(ez+e−z)(e^z - e^{-z})/(e^z + e^{-z}) hyperbolic (−1,1)(-1, 1) increasing, odd, bounded
ReLU max⁡(0,z)\max(0, z) piecewise linear [0,∞)[0, \infty) increasing (not strictly), corner at 0
python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

z = np.linspace(-4, 4, 401)
sigmoid = 1 / (1 + np.exp(-z))
tanh = np.tanh(z)
relu = np.maximum(0, z)

plt.figure(figsize=(6, 4))
plt.plot(z, sigmoid, label="sigmoid")
plt.plot(z, tanh, label="tanh")
plt.plot(z, relu, label="ReLU")
plt.ylim(-1.5, 3); plt.grid(alpha=0.3); plt.legend()
plt.title("Three activation functions")

for v in [-2, 0, 2]:
    s = 1 / (1 + np.exp(-v))
    print(f"z = {v:2}: sigmoid {s:.4f}  tanh {np.tanh(v):+.4f}  relu {max(0, v)}")
z = -2: sigmoid 0.1192  tanh -0.9640  relu 0
z =  0: sigmoid 0.5000  tanh +0.0000  relu 0
z =  2: sigmoid 0.8808  tanh +0.9640  relu 2

Notice sigmoid(−2)+sigmoid(2)=1\text{sigmoid}(-2) + \text{sigmoid}(2) = 1: the sigmoid is not odd, but it is symmetric about the point (0,0.5)(0, 0.5). The tanh values at ±2\pm 2 are negatives of each other because tanh is odd. ReLU is cheap to compute and does not flatten out for large zz, one reason it became the default in deep networks. See Neural Networks for how they are used.

Exercises

Exercise 1: Name the family

Classify each function: (a) f(x)=3x4−xf(x) = 3x^4 - x, (b) g(x)=(x+1)/(x2+1)g(x) = (x + 1)/(x^2 + 1), (c) h(x)=5⋅(0.8)xh(x) = 5 \cdot (0.8)^x, (d) k(x)=log⁡2(x)k(x) = \log_2(x).

Answer

(a) polynomial of degree 4, (b) rational, (c) exponential (decay), (d) logarithmic.

Solution
  • (a) Only whole-number powers of xx with constant coefficients: a polynomial; the highest power is 4.
  • (b) A polynomial divided by a polynomial: rational. Since x2+1x^2 + 1 is never 0, its domain is all reals.
  • (c) The variable is in the exponent and the base 0.8 is between 0 and 1, so it decays.
  • (d) Logarithm with base 2; domain x>0x > 0.

Exercise 2: Even, odd or neither

Decide for f(x)=x5−2x3f(x) = x^5 - 2x^3, g(x)=x4+cos⁡xg(x) = x^4 + \cos x and h(x)=x2+x3h(x) = x^2 + x^3.

Answer

ff is odd, gg is even, hh is neither.

Solution
f(−x)=(−x)5−2(−x)3=−x5+2x3=−f(x)oddg(−x)=(−x)4+cos⁡(−x)=x4+cos⁡x=g(x)evenh(−x)=x2−x3, which is neither h(x) nor −h(x)neither\begin{aligned} f(-x) &= (-x)^5 - 2(-x)^3 = -x^5 + 2x^3 = -f(x) && \text{odd} \\ g(-x) &= (-x)^4 + \cos(-x) = x^4 + \cos x = g(x) && \text{even} \\ h(-x) &= x^2 - x^3, \text{ which is neither } h(x) \text{ nor } -h(x) && \text{neither} \end{aligned}

A sum of only odd powers is odd, a sum of only even powers is even, and mixing them gives neither.

Exercise 3: Leaky ReLU

A "leaky ReLU" is zz for z≥0z \ge 0 and 0.1⋅z0.1 \cdot z for z<0z < 0. Write it with np.where and evaluate it at [-3, -1, 0, 2]. Is it one-to-one?

Answer

[-0.3, -0.1, 0.0, 2.0]; yes, it is one-to-one (strictly increasing), unlike ReLU.

Solution
python · try it yourself
import numpy as np

z = np.array([-3.0, -1.0, 0.0, 2.0])
leaky = np.where(z >= 0, z, 0.1 * z)
print(leaky)
[-0.3 -0.1  0.   2. ]

Both pieces have positive slope (1 and 0.1) and they meet at 0, so the function is strictly increasing and never repeats an output. Plain ReLU sends every negative zz to 0, so it is not one-to-one.

Exercise 4: Sigmoid symmetry

Show by algebra that σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z) for σ(z)=1/(1+e−z)\sigma(z) = 1/(1 + e^{-z}).

Answer

Both sides simplify to e−z/(1+e−z)e^{-z}/(1 + e^{-z}), so σ(−z)=1−σ(z)\sigma(-z) = 1 - \sigma(z).

Solution
σ(−z)=11+ez=e−ze−z+1multiply top and bottom by e−z1−σ(z)=1+e−z−11+e−z=e−z1+e−z\begin{aligned} \sigma(-z) &= \frac{1}{1 + e^z} \\ &= \frac{e^{-z}}{e^{-z} + 1} && \text{multiply top and bottom by } e^{-z} \\ 1 - \sigma(z) &= \frac{1 + e^{-z} - 1}{1 + e^{-z}} = \frac{e^{-z}}{1 + e^{-z}} \end{aligned}

The two expressions are equal. This is why a classifier's probability for "class 0" is just 1 minus its probability for "class 1".

Test yourself

Which function is odd?

  1. cos⁡x\cos x
  2. x2+1x^2 + 1
  3. x3−4xx^3 - 4x
  4. exe^x

What is the range of the sigmoid function 1/(1+e−z)1/(1 + e^{-z})?

  1. (−1,1)(-1, 1)
  2. [0,∞)[0, \infty)
  3. all reals
  4. (0,1)(0, 1)

ReLU(z)=max⁡(0,z)\text{ReLU}(z) = \max(0, z) belongs to which family?

  1. Piecewise linear
  2. Polynomial of degree 2
  3. Exponential
  4. Periodic