Is there a mathematical function which flips 1 and 2?

124 Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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

2
On

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