What is wrong with my power function?
pow(_,0,1).
pow(X,Y,Z) :-
pow(X,Y-1,X*Z).
?- pow(2,3,Z).
ERROR: Out of global stack
What is wrong with my power function?
pow(_,0,1).
pow(X,Y,Z) :-
pow(X,Y-1,X*Z).
?- pow(2,3,Z).
ERROR: Out of global stack
Your Y does not get decremented, you can not use predicates like functions. You also have to unify Z with the result of the multiplication.
There is also a builtin power function which will be much faster:
Also note that pow is not a last call and can not be optimized to use only one stack frame. You should reformulate it to: