Function composition on a commutative diagram: basic question I'm trying to work through Categories for the Working Mathematician and immediately ran into a point of confusion.

A composition of functions is commutative iff $f\circ g = g\circ f$. But if in this diagram  $f:\mathbf{R}^2 \to \mathbf{R}$, $g:\mathbf{R}\to\mathbf{R}$, and $h:\mathbf{R}^2\to\mathbf{R}$, the diagram could commute without the composition $f\circ g$ commuting. Is the idea of a diagram commuting completely unrelated to whether composition of its functions (or morphisms, I think) commutes?
 A: Commutativity of a diagram is different commutativity of composition. Stating that the triangle in your picture commutes is another way of saying $h=g\circ f$.
To be more elaborate, a diagram is said to commute if compositions along any path from the same start to the same end must be equal. In your triangle, there are two paths to go from $X$ to $Z$: either you directly follow $X\xrightarrow hZ$, or you follow the composite $X\xrightarrow fY\xrightarrow gZ$. Commutativity asserts that these are the same thing, and thus $h=f\circ g$.
I'm not sure if this is the reasoning for calling this commutativity of a diagram, but two morphisms $p,q:A\to A$ commute with each other iff the square
$\require{AMScd}$
\begin{CD}
A @>p>> A \\
@VqVV @VVqV \\
A @>>p> A
\end{CD}
commutes as a diagram (indeed, this is just another way of saying $p\circ q=q\circ p$).
Commutative diagrams are practically useful because they can succinctly and visually display several equalities of morphisms simultaneously. For example, the slightly bigger diagram
\begin{CD}
A @>t>> B @>u>> C \\
@VvVV @VVwV @VVxV \\
D @>>y> E @>>z> F
\end{CD}
being commutative expresses all of the equations

*

*$x\circ u\circ t=z\circ w\circ t=z\circ y\circ v$

*$x\circ u=z\circ w$

*$w\circ t=y\circ v$
Note that there is some redundancy since the first chain of equations can be deduced from the latter two, but this reflects the ease of demonstrating commutativity of the entire diagram here by observing that its component squares both commute. Techniques like this come in handy when the diagrams get more involved.
