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 | all reals | horizontal line | ||
| Linear | all reals | straight line, slope | ||
| Quadratic | all reals | parabola | ||
| Polynomial | all reals | smooth, at most turns | ||
| Rational | where | can have asymptotes | ||
| Power / root | depends on | |||
| Exponential | (, ) | , | all reals | always positive |
| Logarithmic | slow growth | |||
| Trigonometric | , , | depends | periodic | |
| Piecewise | different rules on different intervals | , ReLU | may have corners or jumps |
Algebraic functions are built from with , , , and roots (polynomials, rational functions, ). 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 | ; graph symmetric about the -axis | , , |
| Odd | ; symmetric about the origin | , , |
| Increasing on an interval | everywhere | |
| Decreasing on an interval | on | |
| One-to-one | different inputs give different outputs | yes, no |
| Periodic | for some | with |
| Bounded | outputs stay between two numbers | stays in |
Most functions are neither even nor odd, for example . A quick symbolic check:
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:
In code a piecewise function is simply an if, or np.where for arrays:
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 and then passes it through an activation function. The three classics come from three different families:
| Activation | Formula | Family | Range | Property |
|---|---|---|---|---|
| Sigmoid | exponential (rational in ) | increasing, bounded | ||
| tanh | hyperbolic | increasing, odd, bounded | ||
| ReLU | piecewise linear | increasing (not strictly), corner at 0 |
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 : the sigmoid is not odd, but it is symmetric about the point . The tanh values at are negatives of each other because tanh is odd. ReLU is cheap to compute and does not flatten out for large , 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) , (b) , (c) , (d) .
Answer
(a) polynomial of degree 4, (b) rational, (c) exponential (decay), (d) logarithmic.
Solution
- (a) Only whole-number powers of with constant coefficients: a polynomial; the highest power is 4.
- (b) A polynomial divided by a polynomial: rational. Since 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 .
Exercise 2: Even, odd or neither
Decide for , and .
Answer
is odd, is even, is neither.
Solution
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 for and for . 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
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 to 0, so it is not one-to-one.
Exercise 4: Sigmoid symmetry
Show by algebra that for .
Answer
Both sides simplify to , so .
Solution
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?
What is the range of the sigmoid function ?
- all reals
belongs to which family?
- Piecewise linear
- Polynomial of degree 2
- Exponential
- Periodic