0
fac(0,1).
fac(X,Y):-
        X>0,
        X1 is X-1,
        fac(X1,N),
        Y is N*X.

I understand how recursion works in java but now im just starting with prolog and I have trouble understanding how N changes for each time fac is called?

Ahmed Mahmoud
  • 23
  • 1
  • 6
  • See https://stackoverflow.com/questions/9576494/prolog-factorial-recursion and https://stackoverflow.com/questions/32042043/prolog-code-calculating-factorial and https://stackoverflow.com/questions/67972830/prolog-finding-the-nth-fibonacci-number-using-accumulators and https://www.cpp.edu/~jrfisher/www/prolog_tutorial/2_2.html , and http://kti.ms.mff.cuni.cz/~bartak/prolog/bottomup.html has a faster method. – brebs Mar 02 '22 at 08:34

0 Answers0