# Any good way to inverse a function? [closed]

I'm guessing that the answer to this is "no," but I'm curious if there is any way to save writing some code by specifying a function to do the opposite of whatever another function does. For example the inverse of:

``````int FW (int in)
{
int out=2+in;
Return out
}
``````

would be

``````int RV (int in)
{
int out=in-2;
Return out
}
``````

However, would there be any way to call the inverse of `FW()` if it was a more complicated function that still had one and only one input for each output?

## closed as off-topic by gre_gor, Code Gorilla, Enric Blanco, jfpoilpret, KIIVMay 19 '17 at 19:42

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not appear to be about Arduino, within the scope defined in the help center." – gre_gor, Code Gorilla, Enric Blanco, jfpoilpret, KIIV
If this question can be reworded to fit the rules in the help center, please edit the question.

• Ask this question on stackoverflow and use `c` tag .You will get much better answers there – Sniper May 16 '17 at 15:32
• You could crate a more general function like; MOVE(int in, int direction){} – Gerben May 16 '17 at 15:41
• @Sniper, this is hardly a C question. More of a theory question. Per Halting Problem on wikipedia, “Alan Turing proved in 1936 that a general algorithm to solve the halting problem for all possible program-input pairs cannot exist”, providing an easy answer of No to the question in its general form, and with more effort probably to the “one and only one input for each output” subquestion as well. ¶ ATE-ENGE, of course there are lots of ways to get function inverses for particular functions, but from Turing's result not in general – James Waldby - jwpat7 May 16 '17 at 17:02
• lol! Well if Turing said I can't do it, I suppose I shouldn't try XD – ATE-ENGE May 16 '17 at 17:11
• Now if it could be used to figure out the original two factors multiplied together to produce a big number, then you would be on to something. – SDsolar May 17 '17 at 8:39