Functions
- high school edition: a function takes in a real number and outputs a real number
- except when there are vertical asymptotes or other discontinuities
- in programming, functions
- might take in inputs
- might return values
- might have side effects
- might never return anything
- might crash
- might return different values when called multiple times
- high level intuition: a function $f$ takes in one thing $x$ and produces exactly one output $f(x)$.
- in mathematics, functions are deterministic. just a simplifying assumption to make functions easier to work with.
Domains and Codomains
- a function $f$ can only be applied to elements of its domain
- for any $x$ in the domain, $f(x)$ belongs to the codomain.
- asymmetry
- the function must be defined for every element of the domain
- however, the output of the function. must always be in the codomain, but not all elements of the codomain must be produced as outputs.
- example: $f(x) = |x|$
- domain is $\mathbb R$, codomain is also $\mathbb R$. Everything produced is a real number, but not all real numbers can be produced.
- notation for a function whose domain is $A$ and whose codomain is $B$, we write $f:A\to B$.
- think of this like a “function prototype” in C++.
- the term range is ambiguous: it could mean codomain or image (set of things that can be produced by $f$.) therefore, this term will NOT be used in this class.
Official Rules for Functions
- Formally speaking, we say that $f:A\to B$ if the following two rules hold:
- $f$ must obey its domain/codomain rules:
$$
\forall a \in A.~\exists b \in B.~ f(a) = b
$$
- $f$ must be deterministic:
$$
\forall a_1 \in A.~\forall a_2 \in A.~(a_1=a_2 \to f(a_1)=f(a_2))
$$
- can a function have an empty domain (yes!), can a function have an empty codomain (no!)
defining functions
- specify the domain, specify the codomain, and give a rule used to evaluate the function.
- e.g. $f: \mathbb Z \to \mathbb Z$, where $f(x) = x^2 +3x-15$