How to Use Composite Functions in Julia
Code
julia> f(x) = 2x + 1
f (generic function with 1 method)
julia> g(x) = x^2
g (generic function with 1 method)
julia> (g ∘ f)(3)
49
Description
In Julia, function composition is similar to the pipe operator in programming. The main advantage of this composition is that it makes it easier for mathematicians to express formulas as code. The example above is simply a translation of the following formula into code.
$$ f(x) := 2x + 1 \\ g(x) := x^2 \\ (g \circ f) (3) $$
Like many languages these days, treating functions as first-class citizens is the same, but dealing with function spaces as in pure mathematics might be considered a more extreme philosophy that has even influenced the syntax. Note that the function composition operator can be used by entering \circ
in tex syntax.