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.