Monoid where every element has a one-sided inverse is a group.

abstract-algebraexamples-counterexamplesmonoid

Let $M$ be a monoid such that:
for all $x \in M$, there exists $y \in M$ such that $xy = 1$ or $yx = 1$.
Is it true that $M$ is a group?

In other words, if every element of $M$ has a one-sided inverse, then does it follow that every element of $M$ is invertible?


My thoughts
Suppose if I constrain every element to say, have a right inverse, then the statement does hold true.
Indeed, let $x \in M$ be arbitrary and $x'$ be a right inverse of $x$. We show that $x'x = 1$ as well.
First, let $x''$ denote the right inverse of $x'$. Then, we have
$$x'x = x'x(x'x'') = x'(xx')x'' = x'x'' = 1.$$

In fact, the above proof gives us a more refined result:

If $x, x', x'' \in M$ satisfy $xx' = x'x'' = 1$, then $x'$ is the inverse of $x$ (and thus, $x = x''$).
In words: If a right inverse of an element has a right inverse, then the element is invertible.

Thus, if we are looking for a counterexample, then there must necessarily be an element $x \in M$ which has a right inverse but not a left inverse. Moreover, any right inverse $x'$ of $x$ cannot have a right inverse.


Motivation/Context/Source
I didn't come across this in a textbook or anywhere else. I came up with this question because I was aware of the constrained example mentioned above and was wondering if this is true.
I don't have much background about monoids either. I am aware of some properties of finite semigroups/monoids (existence of idempotent powers, Green's relations) but those don't seem to be very fitting here. I haven't even been able to rule out that I can get a counterexample with a finite $M$.

Best Answer

Say we have $xy=1$. We need to prove $yx=1$. First, $g := yx$ is idempotent: $$g^2=(yx)(yx)=y(xy)x=yx=g.$$ If $g$ has a left inverse, we may multiply with it from the left and deduce $g=1$. Similarly, when $g$ has a right inverse, we may multiply with it from the right and deduce $g=1$. So we have $yx=g=1$ in either case.

Related Question