Problem: For which pairs of integers $(a, b)$ do there exist functions
$f\colon \ZZ \to \ZZ$ and $g \colon \ZZ \to \ZZ$ obeying
\[ f(g(x)) = x + a \quad \text{and} \quad g(f(x)) = x + b \]
for all integers $x$?

Solution: The answer is if $a=b$ or $a=-b$.
In the former case, one can take $f(x) \equiv x+a$ and $g(x) \equiv x$.
In the latter case, one can take $f(x) \equiv -x+a$ and $g(x) = -x$.

Now we prove these are the only possibilities.
First:
\begin{claim*}
  The functions $f$ and $g$ are bijections.
\end{claim*}
\begin{proof}
  Surjectivity is obvious.
  To see injective, note that if $f(u) = f(v)$
  then $g(f(u)) = g(f(v)) \implies u+b = v+b \implies u=v$,
  and similarly for $g$.
\end{proof}

Note also that for any $x$, we have
\begin{align*}
  f(x+b) &= f(g(f(x))) = f(x) + a \\
  g(x+a) &= g(f(g(x))) = g(x) + b.
\end{align*}
If either $a$ is zero or $b$ is zero,
we immediately get the other is zero, and hence done.
So assume $ab \neq 0$.

If $|b| > |a|$, then two of
\[ \{ f(0), f(1), \dots, f(b-1) \} \pmod{|a|} \]
coincide, which together with repeatedly applying the first equation
above will then give a contradiction to injectivity of $f$.
Similarly, if $|a| > |b|$ swapping the roles of $f$ and $g$
(and $a$ and $b$) will give a contradiction to injectivity of $g$.
This completes the proof.

\begin{remark*}
  Here is a way to visualize the argument,
  so one can see pictorially what is going on.
  We draw two parallel number lines indexed by $\ZZ$.
  Starting from $0$, we draw red arrow from $0$ to $f(0)$,
  and then a blue arrow from $f(0)$ to $g(f(0)) = b$,
  and then a red arrow from $b$ to $g(b) = f(0)+a$, and so on.
  These arrows can be extended both directions,
  leading to an infinite ``squaretooth'' wave.
  The following is a picture of an example with $a,b > 0$.
  \begin{center}
  \begin{asy}
  size(11cm);
  usepackage("amsmath");
  usepackage("amssymb");
  draw( (-3,2)--(13,2), Arrows(TeXHead) );
  draw( (-3,-2)--(13,-2), Arrows(TeXHead) );
  label("$\mathbb Z$", (13, 2), dir(0));
  label("$\mathbb Z$", (13, -2), dir(0));

  pair bm1 = (-5,2);
  pair b0 = (0,2);
  pair b1 = (5,2);
  pair b2 = (10,2);
  pair b3 = (15,2);
  pair am1 = (-1,-2);
  pair a0 = (2.5,-2);
  pair a1 = (6,-2);
  pair a2 = (9.5,-2);
  pair a3 = (13,-2);

  dot("$0$", b0, dir(90));
  dot("$b$", b1, dir(90));
  dot("$2b$", b2, dir(90));
  dot("$f(0)-a$", am1, dir(-90));
  dot("$f(0)$", a0, dir(-90));
  dot("$f(0)+a$", a1, dir(-90));
  dot("$f(0)+2a$", a2, dir(-90));

  draw(midpoint(bm1--am1)--am1, red, EndArrow, Margins);
  label("$f$", midpoint(bm1--am1)--am1, dir(50), red);
  draw(b0--a0, red, EndArrow, Margins);
  label("$f$", b0--a0, dir(50), red);
  draw(b1--a1, red, EndArrow, Margins);
  label("$f$", b1--a1, dir(50), red);
  draw(b2--a2, red, EndArrow, Margins);
  label("$f$", b2--a2, dir(50), red);

  draw(am1--b0, blue, EndArrow, Margins);
  label("$g$", midpoint(am1--b0)--b0, dir(-50), blue);
  draw(a0--b1, blue, EndArrow, Margins);
  label("$g$", a0--b1, dir(-50), blue);
  draw(a1--b2, blue, EndArrow, Margins);
  label("$g$", a1--b2, dir(-50), blue);
  draw(a2--midpoint(a2--b3), blue, EndArrow, Margins);
  label("$g$", a2--midpoint(a2--b3), dir(-50), blue);
  \end{asy}
  \end{center}
  The problem is essentially trying to decompose
  our two copies of $\ZZ$ into multiple squaretooth waves.
  For this to be possible, we expect the ``width'' of the waves
  on the top and bottom must be the same --- i.e., that $|a| = |b|$.
\end{remark*}

\begin{remark*}
  This also suggests how to classify all functions $f$ and $g$
  satisfying the condition.
  If $a = b = 0$ then any pair of functions $f$ and $g$
  which are inverses to each other is okay.
  There are thus uncountably many pairs of functions $(f,g)$ here.

  If $a = b > 0$, then one sets $f(0)$, $f(1)$, \dots, $f(a-1)$
  as any values which are distinct modulo $b$,
  at which point $f$ and $g$ are uniquely determined.
  An example for $a = b = 3$ is
  \[ f(x) = \begin{cases}
      x + 42 & x \equiv 0 \pmod 3 \\
      x + 13 & x \equiv 1 \pmod 3 \\
      x - 37 & x \equiv 2 \pmod 3,
    \end{cases}
    \qquad
    g(x) = \begin{cases}
      x - 39 & x \equiv 0 \pmod 3 \\
      x + 40 & x \equiv 1 \pmod 3 \\
      x - 10 & x \equiv 2 \pmod 3.
    \end{cases} \]
  The analysis for $a = b < 0$ and $a = -b$ are similar,
  but we don't include the details here.
\end{remark*}