let $f,g: \mathbb{N} \to \mathbb{N}$ be the following functions: $$ f(x)=\left\{\begin{array}{cc} x+1 & \text{ if $x$ is even} \\ x-1 & \text{ if $x$ is odd} \end{array} \right. $$ $$ g(x)=\left\{\begin{array}{cc} x/2 & \text{ if $x$ is even} \\ (x-1)/2 & \text{ if $x$ is odd} \end{array} \right. $$
Match the following composition with their definitions. $$ h(x) = g(x) $$ Is this composition $g \circ g$?
The answer is $h= g \circ f$. To see this, take first $x \in \mathbb{N}$ such that $x$ is an even number, thus there exist $n \in \mathbb{N}$ such that $x=2n$, then $$ (g \circ f)(x) = (g \circ f)(2n) = g(f(2n))=g(2n+1) = (2n+1-1)/2 = n =g(2n)=g(x) $$ If we now take $x \in \mathbb{N}$ to be an odd natural number then $x=2n+1$, and hence $$ (g \circ f)(x) = (g \circ f)(2n+1) = g(f(2n+1))=g(2n) = n= g(2n+1)=g(x) $$ Since for all $x \in \mathbb{N}$ we just proved that $(g \circ f)(x) = g(x)$, then indeed $g \circ f = g $.