Functions
Introduction
Math on the Computer
In the context of working on a computer, a function that behaves like a mathematical function is called a "pure function"
A function is a mapping that takes a value as an input and returns a value as an output.
This has more detail than I will normally provide when I write down a function in lecture but it's helpful to see the distinct components:
- \(\mathcal{X}\), \(\mathcal{Y}\) are sets1 called the domain and codomain respectively
- \(x\) is an element of \(\mathcal{X}\) and is the input to the function
- \(f(x)\) is the output, also referred to as the image of \(x\) under \(f\)
- \(f\) is the function which maps all of the elements of \(\mathcal{X}\) into \(\mathcal{Y}\) such that for each \(x\) there is only one \(y\). We can partially define a function as follows. This tells us the domain and codomain of the function.
Composition
Perhaps you will recall that as with numbers, we can add functions. For example, let's say that we are given two function: \(f(x) = 2x\), \(g(x) = x^2\), then we can construct a new function by adding \(g\) with \(f\) as follows.
Question
Does the order of composition matter? It doesn't when we multiply numbers!
As you see above, we add functions (as done in the first line), pointwise.2
If we can add functions, it's natural to consider whether we can multiply them. We can multiply numbers, so why not functions? And indeed we can! We refer to this multiplication as composition. That is, we can construct a new function by composing two other functions as follows (note the symbol \(\circ\) denotes composition.)
Implicit Functions
Implicit functions are functions where a solver is called during the evaluation of the function.
Vectors as Functions
- Reference: Thinking with Types