$f \circ g =\operatorname{ id}$ and $g \circ f \neq \operatorname{id}$? Are there two functions $f$ and $g$ s.t.
$$f \circ g = \operatorname{id}$$
but
$$g \circ f \neq \operatorname{id}?$$
Could someone give an example or a proof that this is impossible?
This must be trivial, but I can't figure it out. :) Thanks!
 A: Let $A=\{0,1\}$ and $B=\{0\}$ and define the functions $f:A\to B$ and $g:B\to A$ so that $f(0)=f(1)=0$ and $g(0)=0$.
Then $f\circ g:B\to B$ is the identity but $g\circ f:A\to A$ maps everything to $0$.
A: Let $f:A\rightarrow B$ and $g:B\rightarrow A$. 
If $B$ is a singleton then $f\circ g=\operatorname{id}_B$. 
($\operatorname{id}_B$ is unique as function $B\rightarrow B$)
If $B$ is a singleton and $A$ is not a singleton then $g\circ f\neq \operatorname{id}_A$. 
($g\circ f$ is constant and $\operatorname{id}_A$ is not)

Nice to remember: 

$s\circ i=\operatorname{id}$

Here $s$ stands for surjective and $i$ for injective. So from $f\circ g=\operatorname{id}$ you are allowed to conclude that $f$ is surjective and $g$ is injective. A more general version (for later, if there is some familiarity with categories) is: 

$r\circ s=\operatorname{id}$

Here $r$ for retraction and $s$ for section.
These mnemonics are very valuable to me.
A: Hint: Consider the two functions on the integers:
$$
f(x)=\left\lfloor\frac x2\right\rfloor
$$
and
$$
g(x)=2x
$$
A: To treat this matter properly, one must consider the functions as having well-defined
domains and co-domains (or sources and targets, if preferred).  For the above compositions
to even make sense, we must have
$$
f: A \to B 
$$
and
$$
g: B \to A .
$$
Now the compositions are
$$
f\circ g: B \to B    
$$
and
$$
g\circ f: A \to A,
$$
so if $A$ and $B$ are different, the two compositions have no chance of being the same.
BUT, even if $f\circ g = id_B$, we still need not get $g\circ f = id_A$.
Example:   $A = \{ -1 , 1 \}$     and  $B = \{ 1 \}$ 
with $g(1) = 1$   and  $f(-1) = f(1) = 1$.
(This is just the square/squareroot example that was mentioned earlier.)
Bill Taylor
A: HINT: Consider $\sin$ and $\arcsin$ on their natural domains.
A: Take the space of polynomials, $f = $ differentiation and $g = $ integration.
Then $f \circ g = \operatorname{id}$ but $g \circ f \ne \operatorname{id}$ because $g(f(x^2+1))=g(2x)=x^2$.
A: To work out a pair of function $f$ and $g$ that satisfies these conditions the following  lemmas are helpful.
Lemma 1: 
If $$f \circ g = \operatorname{id} \tag{1}$$ then $f$ is surjective and $g$ is injective.
$\blacksquare$
I ommit the proof of this well known lemma. From lemma 1 follows the next lemma.
Lemma 2: 
If $$f \circ g = \operatorname{id}$$ and $g$ is surjective then $$g \circ f = \operatorname{id}$$
$\blacksquare$
Proof: 
$g$ is injective by lemma 1 and surjective, so it is bijective and $f$ is its inverse. 
$\blacksquare$
So let's assume that 
$$g:A \mapsto B$$
satisfies $(1)$.
So $g$ must be a injective but not surjective. We define
$$C:=g(B)$$
Then $$C \subsetneqq B$$ and $$g:A \mapsto C$$ is bijective.
We define $$f|_C: C \mapsto A$$ as  $$f|_C:=g^{-1}|_C$$ and define $$f|_{B\setminus C}: B\setminus C \mapsto A $$ arbitrary.
The $f$ and $g$ have the desired properties:
$$f \circ g = \operatorname{id} $$ because $$f|_C \circ g = \operatorname{id}$$
We have $$(g \circ f)|_C=\operatorname{id}|_C$$
But for $b \in B \setminus C$ we have $$(g \circ f) (b)=c \in C$$ and so $b \ne c$. But we have $$(g \circ f) (b) \ne c$$ and so $g \circ f$ is not injective.
Example 1
Choose an injective but not surjective function $g$, e.g. 
$$\exp: \to e^x$$
$$\exp: \mathbb{R} \mapsto \mathbb{R}$$
Then we have
$$A=\mathbb{R}$$
$$B=\mathbb{R}$$
$$C=\mathbb{R^+}$$
We have $$f|_\mathbb{R^+}=\log$$ and we define $$f: x \to x, \; \forall x \in \mathbb{R_0^\textbf{-}} $$
$\blacksquare$
Example 2
$M$ is an arbitrary set with $m \in M$ and $q \notin M$. We define 
$$A:=M$$
$$B:=M \cup \{q\}$$
and the functions $g$
$$g:M \mapsto M \cup \{q\}$$
$$g: x \to x$$
We have 
$$C=M$$
and 
$$f:M \cup \{q\} \mapsto M $$
$$f: x \to 
\begin{cases} x, \; \forall x \in M \\
m , \mbox{if } x=q
\end{cases}
$$
$\blacksquare$
A: It is possible to define the functions via matrices, in which case the product of the matrices is not commutative - I don't know if that is quite what you are looking for. You could also define the functions by $f(x) = x^2$, $g(x) = \sqrt{x}$, where $f:\mathbb{R} \to [0 , \infty)$ and $g: [0 , \infty) \to [0 , \infty)$. Here, $f(g(x)) = x $ but $g(f(x)) = |x|$. There are of course other examples of similar type.
