What is it?
A rule that assigns to each input of a set exactly one output in a set . Calculus studies how outputs change when inputs change; computing is, quite literally, evaluating functions.
Why does it exist?
To talk about dependence: the position of a planet depends on time, the cost of an algorithm on the input size, the error of a neural network on its weights. A function packages that dependence as a single object we can add, compose, differentiate and integrate.
Intuition
Think of a machine: put in, get out, always the same output for the same input. Its graph is a curve in the plane that every vertical line crosses at most once. Most of calculus is reading geometric properties of that curve — slope, area, curvature — from the formula.
Formal definition
A function is a subset such that for each there is exactly one with ; we write . is the domain, the codomain, and the range (image).
Formulas
Example
has domain and range . The softmax function of machine learning, , is a function whose range is the set of probability vectors with positive entries.
Why does it matter?
A trained neural network is a function — millions of parameters fixing one particular . Pure functions (same input, same output, no side effects) are also the unit of reasoning in functional programming, and the reason caching and parallelism are safe.
Where it shows up in computing
A CAS represents functions as expression trees that can be simplified, differentiated and integrated.
Where it shows up in AI
A network is a parametrized function ; training chooses .
Where is it used?
Computing topics reachable from here, through the chain of ideas that leads to them:
λ Scientific computing and algorithms
- Exponential functions→Logarithmic functions→Algorithm analysis and complexity★★★★★
- Riemann sums→Numerical integration (quadrature)→Scientific computing★★★★★
- Riemann sums→Definite integral→Monte Carlo methods★★★★★
- Limit of a function→Derivative→Differentiation rules→Symbolic computation (CAS)★★★★★
- Exponential functions→Logarithmic functions→Floating point (IEEE 754)★★★★★
3D Computer graphics
- Polynomial functions→Bézier curves and splines★★★★★
- Trigonometric functions→Dot product→Lighting and shading★★★★★
- Functions of several variables→Surfaces and level sets→Signed distance fields and ray marching★★★★★
- Riemann sums→Definite integral→The rendering equation★★★★★
- Functions of several variables→Partial derivatives→Gradient→Surface normals★★★★★
- Trigonometric functions→Dot product→Lighting and shading→Ray tracing★★★★★
- +2
⚙ Robotics and control
- Ordinary differential equations→Control theory★★★★★
- Limit of a function→Derivative→Kinematics: position, velocity, acceleration★★★★★
- Exponential functions→Continuous distributions→Kalman filter★★★★★
- Maxima and minima→Constrained optimization→Trajectory optimization and MPC★★★★★
- Limit of a function→Derivative→Kinematics: position, velocity, acceleration→Robot Jacobian (velocity kinematics)★★★★★
- Limit of a function→Derivative→Kinematics: position, velocity, acceleration→Robot dynamics★★★★★
- +2
⚛ Physics and simulation
- Ordinary differential equations→Classical mechanics★★★★★
- Ordinary differential equations→Physics engines★★★★★
- Exponential functions→Population and epidemic models★★★★★
- Ordinary differential equations→Physics engines→N-body gravitational simulation★★★★★
- Functions of several variables→Partial derivatives→Heat equation and diffusion★★★★★
- Ordinary differential equations→Partial differential equations→Wave equation★★★★★
- +4
∿ Signals, media and vision
- Trigonometric functions→Signal processing★★★★★
- Polynomial functions→Interpolation→Image processing and computer vision★★★★★
- Trigonometric functions→Signal processing→Sampling theorem (Nyquist–Shannon)★★★★★
- Trigonometric functions→Complex numbers→Fast Fourier transform (FFT)★★★★★
- Trigonometric functions→Signal processing→Digital filters★★★★★
- Trigonometric functions→Signal processing→Media compression (JPEG, MP3, video)★★★★★
- +1
What depends on it
Exercises
Find the domain and range of .
Solution
Domain: . On it , so the range is .
Is a function that reads the system clock a function in the mathematical sense? What is missing?
Solution
No: the same (empty) input gives different outputs. It becomes a mathematical function if the time is made an explicit input, — which is exactly what makes code testable.