r/AskComputerScience • u/StudyNeat8656 • Sep 22 '25
Question: Is there a inverse function z to take functions' inverse?
For example, I have a function f
```scheme
(define (f input) (+ 1 input))
```
Its inverse is
```scheme
(define (f- input (- input 1))
```
I mean, is there a function z, have (z f)==f-
Of course this question has practical means: if I have a program zip, then I can directly have unzip program with z(zip). Non coding work need to be done.
1
Upvotes
8
u/nuclear_splines Ph.D Data Science Sep 22 '25
There are irreversible functions, so this is not possible in the general case
3
u/teraflop Sep 22 '25
If you are only concerned with the existence of such an "inverter" function z, and not its efficiency, this is straightforward to solve by "brute force" enumeration.
Just have
(z f)return a function such that((z f) x)iterates over all possible inputsy, and computes(f y)for each such input. When it finds a result that equalsx, it returns the corresponding value ofy. (Of course, if no such result exists, then the inverse function will run forever without halting.)You can use the standard "dovetailing" trick for Turing machines to guarantee that if there is an input such that
(f y)halts and returnsx, you will find it in finite time, even ifffails to halt on other inputs.In practice, this method is ludicrously inefficient, but from a theoretical perspective, it does show that the problem of function inversion is computable.