How does prolog run through recursive queries using succ?
Can someone explain to me why this prolog query works the way it does. The definition is: add(0,Y,Y). add(succ(X),Y,succ(Z)):- add(X,Y,Z). Given this: ?- add(succ(succ(succ(0))), succ(succ(0)), R). Heres the trace of the query: Call: (6) add(succ(succ(succ(0))), succ(succ(0)), R) Call: (7) add(succ(succ(0)), succ(succ(0)), _G648) Call: (8) add(succ(0), succ(succ(0)), _G650) Call: (9) add(0, succ(succ(0)), _G652) Exit: (9) add(0, succ(succ(0)), succ(succ(0))) Exit: (8) add(succ(0), succ(succ(0)), succ(succ(succ(0)))) Exit: (7) add(succ(succ(0)), succ(succ(0)), succ(succ(succ(succ(0))))) Exit: