So I'm having a hard time trying with Peano and I need some help. I want to know if a Peano number is even and if yes then add:
0 + s(s(0)) = s(s(0))
0 + s(0) = No because one of the numbers odd
The code I have so far:
s(0).
s(X):-
X.
add(0,Y,Y).
add(s(X), Y, s(Z)):-
add(X,Y,Z).
Do not think about Peano numbers as numbers but as symbols.
Realize that the even Paeno numbers are
0
and a repeat of the patterns(s(X))
whereX
can be0
or the patterns(s(X))
Also I look at
0
ands(0)
etc. as data, and you are usings
as a predicate name. I am not saying it will not work this way, but that is not how I think about this.The name of the predicate is
paeno_even
and it takes one argument.The base case is
next for recursive case
and the processing on P just removes
s(s(X))
so do that in the head asand then just do the recursive call
A few test to demonstrate:
The entire code as one snippet: