I am trying to write a higher-order Racket function that takes a first-order function of one variable and returns its inverse. I know that it has to start off something like this:
(let [(inverse (lambda (f)
(lambda (y)
... )))])
I figured this because inverse must take a function which returns a function which takes a y and returns x such that (= (f x) y). In other words, the contract for inverse is something like:
; inverse : (number? -> number?) -> (number? -> number?)
I’m just stumped trying to figure out what goes where the elipses are?
EDIT:
In response to people saying this is impossible, I am willing to accept an inverse function that when given y returns a possible x. In response to comments about the function not having an inverse, please note the contract that I have for f. It is a (number? -> number?) mapping, and therefore has an inverse.
For the general case, given an arbitrary function
fyou can’t tell what’s its inverse function. Even worse, a given function might not have an inverse at all – for example: the input function could perform an MD5 hash, which has no inverse. Sorry, your question has no answer.