Iterating to negative one

I’ve been looking into reducing the volume of my paper files by scanning some of what’s there, or just downloading stuff that’s available online. I found this, though, which I wrote up ages ago, and rather than scanning it, I thought I’d write it up here. And then I can download it…

Hofstadter [I think this must have been in one of his Metamagical Themas columns] poses  the problem: Find a real-valued function $f(x)$ operating on the real numbers such that $f(f(x))=-x$. (If $f(x)$ could be complex, this would be trivial: $f(x)=ix$ (or $-ix$).)

We stalk $f(x)$ by learning some of its properties…

(i) Suppose $f(x)=f(y)$. Then $-x=f(f(x))=f(f(y))=-y$ and so $x=y$:

$f(x)=f(y)\Leftrightarrow x=y$

(ii) $f(-x)=f(f(f(x)))=-f(x)$:

$f(-x)=-f(x)$ — $f(x)$ is an odd function.

(i) and (ii) together imply:

$f(0)=0$ and $f(x\ne 0)\ne 0$

(iii) Suppose $f(x)>0$ for all $x>0$. Then $f(f(x))>0$. But $f(f(x))=-x$ — contradiction. So for some $x>0$$f(x)<0$. Similarly, for some $f>0$$f(x)>0$:

$f(x)$ has positive and negative values for positive x.

But since $f(x\ne 0)\ne 0$,

$f(x)$ has at least one discontinuity for positive $x$.

(iv) Split the positive reals $\mathbb{R}^+$ into two sets, $\mathbb{P}$ and $\mathbb{N}$, such that

$f(x\in\mathbb{P})>0\\f(x\in\mathbb{N})<0$

By (ii),

$f(x) < 0$ if $-x\in\mathbb{P}$
$f(x) > 0$ if $-x\in\mathbb{N}$

If  $x\in\mathbb{P}$, $f(x)>0$; $f(f(x))=-x<0\Rightarrow f(x)\in\mathbb{N}$. Similarly, $x\in\mathbb{N}\Rightarrow -f(x)\in\mathbb{P}$:

$x\in\mathbb{P}\Rightarrow f(x)\in\mathbb{N}\\x\in\mathbb{N}\Rightarrow -f(x)\in\mathbb{P}$

So $f(x)$ (sort of) maps half the real numbers into the other half, and the other half back into the first half. (Sort of because of that minus sign. Zero is the exception; it maps to itself.)

The task is to find a $\mathbb{P}$ and an $\mathbb{N}$ such that one can be mapped onto the other.

One solution is:

$\mathbb{P}=(0,1]\cup(2,3]\cup(4,5]\cup...\\\mathbb{N}=(1,2]\cup(3,4]\cup(5,6]\cup...=\mathbb{R}^+-\mathbb{P}$

$f(x\in\mathbb{P})=x+1$ and so $f(x)\in\mathbb{N}$
$f(x\in\mathbb{N})=-(x-1)$ and so $-f(x)\in\mathbb{P}$

The function fully specified is

$f(x) = \begin{cases} x+1& \mbox{if } x\in\mathbb{P}\\ -x+1& \mbox{if } x\in\mathbb{N}\\ 0& \mbox{if }x=0\\x-1& \mbox{if } -x\in\mathbb{P}\\ -x-1& \mbox{if } -x\in\mathbb{N}\end{cases}$

And here’s a plot: