Is this a valid example for $f \circ g = id_M$, but $g \circ f \ne id_N$ The exercise is to give an example for two sets $M$ and $N$, and functions $f$ and $g$, for which $f \circ g = id_M$, but $g \circ f \ne id_N$.
My idea is a bit based on my computer programming background, where (x/2)*2 is 0 for integers. Here it is:
$$M=N=\mathbb{N_0}.$$
$$f: \mathbb{N_0} \rightarrow \mathbb{N_0}, g: \mathbb{N_0} \rightarrow \mathbb{N_0}.$$
$$f(x) = 2x, g(x) = x \div 2.$$
Thus,
$$(g\circ f)(x) = g(f(x)) = g(2x) = 2x\div 2 = x = id_\mathbb{N_0}$$
$$(f\circ g)(x) = f(g(x)) = f(x\div2) = (x\div2)\cdot2 \ne id_\mathbb{N_0}$$
Because if $f(g(1)) = f(0) = (0\div 2)\cdot2 = 0$, and $0\ne 1$, it follows that $(f\circ g) \ne id_\mathbb{N_0}$
Is my example valid?
 A: Yes, your example is valid, and your overall argument for it is good.  You have a few minor errors in details and notation, though.
$\newcommand{\id}{\mathit{id}} \newcommand{\N}{\mathbb{N}}$


*

*In your line “$(g \circ f)(x) = \cdots = x = \id_\mathbb{N}$”, the last item should be not $\id_\mathbb{N}$, but $\id_\mathbb{N}(x)$.  All the earlier terms in this sequence of equalities are values of the function; $\id_\N$ refers to the whole function, not just the individual value.

*In the line “$(f \circ g)(x) = \cdots \neq \id_\N$”, you again need to be more careful distinguishing between whole functions and individual values.  At the level of individual values, it’s not always true that $(f \circ g)(x) \neq \id_\N(x)$; there are some values of $x$, e.g. $x = 2$, that make them equal.  The key point is that there are some values, e.g. $x = 3$, that make them non-equal — $(f \cdot g)(3) = 2 \neq \id_\N 3$ — which implies that as functions, $(f \cdot g) \neq \id_\N$.

*As others have said, your function $x \div 2$ would usually be called $\lfloor \frac{x}{2} \rfloor$. Since you explicitly define what you mean by $x \div 2$, though, I wouldn’t really consider this an error, just an issue of style.
A: A simpler example might be $M=[0,\infty)$ and $N = \mathbb{R}$ with $f(x) = \sqrt{x}$ and $g(x)=x^2$. You can check the details.
