I want to write a proof to show that the composition of two functions is a function. To do that, I need to define the composition of two functions, but I haven't been able to verify my attempt. Here it is.
Let $f : X \rightarrow Y$ and $g : Y \rightarrow Z$ be well-defined functions, and let $f \circ g : X \rightarrow Z$ be the composition of $g$ to $f$. The composition $f \circ g$ is defined as
$$f \circ g := \{(x, z) : \exists y \ni (x, y) \in f \, \mathrm{and} \, (y, z) \in g\}$$
Please I'd like to know it this definition is correct, and if not, the correct definition. Thanks.