Inverse Factorial Function (Prolog)

Posted by user2796815 on Stack Overflow See other posts from Stack Overflow or by user2796815
Published on 2013-11-12T21:50:46Z Indexed on 2013/11/12 21:53 UTC
Read the original article Hit count: 263

Filed under:
|

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 is 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?

© Stack Overflow or respective owner

Related posts about prolog

Related posts about swi-prolog