r/AskComputerScience • • 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

15 comments sorted by

View all comments

Show parent comment

1

u/tavianator Sep 23 '25

Okay sure, but you can use that to define g(x) = teraflop_invert(f, x) which satisfies f(g(x)) = x

1

u/nuclear_splines Ph.D Data Science Sep 23 '25

Yes, with the caveat that this will only work for enumerable inputs. For example, if f takes a 32-bit integer as an input then you can brute force your way through all possible 32-bit ints. However, if f takes a linked list of ints as an input then there's a countably infinite input domain, and if f takes a bignum arbitrary-precision float then there's an uncountably infinite search space.

3

u/tavianator Sep 23 '25

There's no uncountable inputs in CS :)

You can use that dovetailing trick to make it work in an output-sensitive way. So if there is a solution of length n, it will find it in exponential time in n

2

u/nuclear_splines Ph.D Data Science Sep 23 '25

Of course there are. There are no uncountable inputs on a finite-storage deterministic computer, but there are plenty of uncountable inputs in computer science. But yes, to your dovetail point, if we add extra constraints like a solution of length n then we can reduce the problem to a solvable one.

1

u/tavianator Sep 23 '25

Well the solution must have some length n because inputs are finite, for Turing machines anyway. So a solution of length n is not really a constraint if n is not fixed ahead of time. That's what I mean by output sensitive