Composition of partial functions (source code)

= Composition of partial functions

For <partial functions> $h:X\rightharpoonup Y$ and $g:Y\rightharpoonup Z$, their <function composition> is defined precisely on
$$
\operatorname{dom}(g\circ h)=\{x\in\operatorname{dom}h:h(x)\in\operatorname{dom}g\}.
$$
For example, composing $h(x)=1/x$ with $g(y)=\sqrt y$, as real <partial functions>, gives $1/\sqrt x$ only on $x>0$.

More generally, strict <composition of partial functions> makes $g(h_1(x),\ldots,h_r(x))$ defined only if every $h_i(x)$ is defined and $g$ is defined on the resulting <tuple>. An argument discarded by the outer <function> must still be defined: the expression $g(1/x)$ with the everywhere-zero <constant function> $g$ remains undefined at zero. A representation in a programming language using <lazy evaluation> therefore needs an explicit check of the intermediate definedness conditions.