Functions

Level FundamentalDifficulty ★★★★★Concept⌖ Open in the map

What is it?

A rule ff that assigns to each input xx of a set AA exactly one output f(x)f(x) in a set BB. 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 xx in, get f(x)f(x) out, always the same output for the same input. Its graph {(x,f(x))}\{(x, f(x))\} 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 f:A→Bf : A \to B is a subset G⊂A×BG \subset A \times B such that for each x∈Ax \in A there is exactly one y∈By \in B with (x,y)∈G(x, y) \in G; we write y=f(x)y = f(x). AA is the domain, BB the codomain, and f(A)={f(x):x∈A}f(A) = \{f(x) : x \in A\} the range (image).

Formulas

f:A→B,x↦f(x)f : A \to B, \qquad x \mapsto f(x)
graph⁡(f)={(x,f(x)):x∈A}\operatorname{graph}(f) = \{(x, f(x)) : x \in A\}

Example

f(x)=x−1f(x) = \sqrt{x - 1} has domain [1,∞)[1, \infty) and range [0,∞)[0, \infty). The softmax function of machine learning, softmax⁡(z)i=ezi/∑jezj\operatorname{softmax}(z)_i = e^{z_i} / \sum_j e^{z_j}, is a function ℝn→ℝn\R^n \to \R^n 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 f:ℝn→ℝmf : \R^n \to \R^m. 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

  • Symbolic computation (CAS)★★★★★frequentScientific computing and algorithms

    A CAS represents functions as expression trees that can be simplified, differentiated and integrated.

Where it shows up in AI

  • Neural networks★★★★★fundamentalAI and machine learning

    A network is a parametrized function fθ:ℝn→ℝmf_\theta : \R^n \to \R^m; training chooses θ\theta.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

Exercises

1Computation

Find the domain and range of f(x)=ln⁡(4−x2)f(x) = \ln(4 - x^2).

Solution

Domain: 4−x2>0  ⟺  x∈(−2,2)4 - x^2 > 0 \iff x \in (-2, 2). On it 4−x2∈(0,4]4 - x^2 \in (0, 4], so the range is (−∞,ln⁡4](-\infty, \ln 4].

2Computing

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, f(t)f(t) — which is exactly what makes code testable.

↑ ↓ to navigate · ↵ · Esc