Function composition \circ

If you have two functions f(x)\operatorname{f}(x) and g(x)\operatorname{g}(x), then you can define a third function:

h(x)=(gf)(x)=g(f(x))\begin{align*} \operatorname{h}(x) &= (\operatorname{g} \circ \operatorname{f}) (x) \\ &= g(f(x)) \end{align*}

It basically means: First apply the function on the right. Then use that result and apply the left function. Of course, you can use more than two and repeat that process.

In code, you can either explicitly call the first function and then the second or you can create a new function using something like lambda expressions.

Code:

This version applies the argument directly. In languages, that don't support passing functions as parameters, you might need to explicitly write functions for all combinations or use some other mechanism

Here we create a new function h=(gf)\operatorname{h} = (\operatorname{g} \circ \operatorname{f}) that is the composition of f\operatorname{f} and f\operatorname{f} and can be called as h(x)\operatorname{h}(x).