I have to write a Prolog program to computer the inverse of factorial function without using division. I was also given the note: "the inverse of a function is not necessarily a function". I have this as a normal factorial predicate..
fact(0,1).
fact(N,F) :- N>0, N1 is N-1, fact(N1,F1), F is N * F1.
I've read on some other posts that you should be able to just switch around the arguments, but that doesn't seem to be the case with this version. Could anyone help me out with figuring out why?
N>0demandsNbe a ground arithmetic value. and so doesN1 is N-1bit. - Will Nessinvfact(X,1)should succeed twice. Right? - Will Nessfactchanged into a generative predicate - such that generates a list of factorials up to a given value - as pairs is better, (N, F) where F is N! - and then search that list back from end for my index. - Will Ness