Let $f: \mathbb{Z} \to \mathbb{Z}, \; z \mapsto 3z$ be a map on the integers. I am trying to find a left inverse function, $g: \mathbb{Z} \to \mathbb{Z}$ such that $g \circ f = \text{id}$.
My attempt didn't quite seem to work: \begin{align*} (g \circ f)(x) & = g(f(x) = g(3x). \end{align*} Setting $g(3x) = x$, taking $g$ to be the function $g(t) = \frac{1}{3} t$ allows $g(3x) = \frac{3x}{x} = x$. However, $x \mapsto \frac{1}{3}x$ is not a map from $\mathbb{Z}$ to $\mathbb{Z}$ because taking $x = 1$ returns $\frac{1}{3}$, which is not an integer.
This choice of $g$, certainly, does not work unless we extend the codomain to $\mathbb{R}$. The question I have is, is there a better, more systematic approach of finding such a $g$?
Your map $g$ can be
$g(x)=\frac{x}{3}$ if $x\equiv 0$ mod $3$ while $g(x)=x$ otherwise.
Clearly there are other maps $g$ such that $g\circ f=id$. For example you can define
$g(x)=\frac{x}{3}$ if $x\equiv 0$ mod $3$ and $g(x)=2x$ otherwise.
A systematic approach of find a left inverse function is to find the image of $f$ and to define a function $h: Im(f)\to \mathbb{Z}$ such that $h\circ f=id$. Then you can built
$g(x)=h(x)$ if $x\in Im(f)$ and $g(x)=x$ otherwise.
If $f$ is injective, i.e a monomorphism in the set category, then there always exists a left inverse function. In fact you can define $h=f^{-1}: Im(f)\to \mathbb{Z}$.
So a necessary and sufficient condition for which $f$ has a left inverse function is the injectivity. Clearly, there is not a unique left inverse function.