# Is there a mathematical function which flips 1 and 2?

I'm looking for a function $f : \mathbb{Z} \rightarrow \mathbb{Z}$ such that $f(f(x)) = x$ and $f(1) = 2$. In particular, I don't want this function to be a piecewise function. Does such a function even exist?

For example, I can define the above function as follows:

\begin{equation} f(x) = \begin{cases} 2 & x = 1 \\ 1 & x = 2 \end{cases} \end{equation}

However, I was wondering whether there's a way to define this function without writing conditions.

• What exactly do you mean by "a piecewise function"? – Carl Schildkraut Sep 25 '16 at 6:56
• $3-x{}{}{}{}{}$ – Gerry Myerson Sep 25 '16 at 6:57
• @GerryMyerson Wow, that was simple. Why didn't that occur to me? – Aadit M Shah Sep 25 '16 at 7:01
• @GerryMyerson how about putting that into answer? :) – Sil Sep 25 '16 at 7:09
• @Sil, as you wish. – Gerry Myerson Sep 25 '16 at 13:36

## 2 Answers

$3-x$ (plus enough characters to qualify as an answer).

How about $f(x) = x-(-1)^x$? That works.

• O.P. also wants f(f(x))=x though. – SquirtleSquad Sep 25 '16 at 6:59
• @SquirtleSquad Sorry, I made a typo. This should work. – Carl Schildkraut Sep 25 '16 at 7:01