# Function composition where two functions are not equal

Can you find two functions $f$ and $g$ such that they are not equal and $$f \circ g= f,\qquad\text{and}\qquad g \circ f= f$$ where $\circ$ denotes composition of the two functions.

• If we work with only $f$ and $g$ which are invertible, then $g$ would be forced to be the identity map by some basic group theory.
– Tai
Jul 24 '17 at 16:39
• Can you give an example? Jul 24 '17 at 16:44
• You can let $f$ be anything, and it will work if you set $g(x) = x$ (the identity map) since $f(g(x)) = f(x) = g(f(x))$. In fact, if you restrict $f$ and $g$ to be invertible, then $g(x) = x$ will be the only function that will satisfy this.
– Tai
Jul 24 '17 at 16:45
• What is the domain of the two functions? Reals? Integers? Finite sets? Jul 24 '17 at 17:58
• what about $f$ and $f^{-1}$ for an invertible function? Then you have $f\circ f^{-1}=f^{-1}\circ f=\operatorname{id}$. By example $e^{\ln x}=\ln(e^x)=x$ for $x\in[1,\infty)$. Jul 24 '17 at 18:30

Yes, you can. To satisfy these conditions, $g$ has to be the identity map on the range of $f$, but you can play with other elements (in the complement of the range of $f$) to define $g$ that is different from both $f$ and the identity map.
Here's an example. Let $X=\{1,2,3\}$ and define the two maps $f,g : X\to X$ as follows: $$f(1)=1,f(2)=1,f(3)=1 \quad \text{and} \quad g(1)=1,g(2)=3,g(3)=2.$$ (It looks much better as a diagram, but I don't know how to create one quickly.)