Question regarding Addition in Prolog

Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.

Question regarding Addition in Prolog
Hey altogether,

I have trouble understanding how ProLog(“I”) can finish additions and wanted to ask if somebody could help me in / explain the following case:

Knowledge-Base:
add(X,Y,Z). [1.]
add(X,zero,X). [2.]
add(X, s(Y), s(Z)) :- add (X,Y,Z). [3.]

Query:
?- add(s(zero), s(zero), W).
Is correct in case add (X, s(Y),s(Z)) when X = s(zero), Y = zero, and W=s(Z) [3.]; Therefore use Tail of the clause
?- add(s(zero), zero, s(Z)).
According to video: Correct in case add (X, zero, X), when X=s(zero) and Z = X [2.]: Therefore this leaves me with the following:
?- add(s(zero), zero, s(s(zero)).

So in my oppinion the Addition would be solved at this moment - I guess it would state “True” now? I also have the Result that W = s(s(zero), but how does that resolve? What happens to the first part of the equitation? I’m sorry if that would be obvious, but I’m just a little confused right now…

Thanks and kind regards.


This is probably not what you are asking for, but are you sure you want to have the face 1. in your knowledge base? Unless I’m mistaken, it’s basically a fall-through case that let’s true be derived from any add/3 predicate.