
> 
> **Possible Duplicate:**  
> 
> [solving f(f(x))=g(x)](https://mathoverflow.net/questions/17614/solving-ffxgx) 
> 
> 
> 


Here is a nice interview question for computer science people:


Write a unary function `f` such that


`f(f(x)) = -x`


Constraints:


1. The function should be pure (i.e. it should have no state and every time its called it should output the same value for the "same" input.).
2. Complex number arithmetic is not allowed. So `f(x) = ix` is not allowed.
3. You can use plain mathematics or use a program. Choice is yours.


Although I am a student of computer science but I am unable to figure out it's mathematical aspect.


Any help ?



Interview Question
Divide the domain into separate sets of four, each set having the form {x,y,-x,-y}. Now, let f simply rotate within these sets one step. That is, map x to y, and y to -x, and -x to -y, and -y to x. Thus, doing it twice maps every x to -x, as desired. (Also let f(0)=0.)


