I need a predicate which plus of a list of lists in prolog using pure logic and natural number notation. For example for the predicate :
?-totalPlus([ [s(0)],[s(0),s(0)],[s(s(0))] ], Res).
The result must be:
Res= s(s(s(s(s(0))))).
This is my implementation but it only returns the plus of the first list:
plusNat(0,X,X).
plusNat(s(X),Y,s(Z)):-plusNat(X,Y,Z).
plusList([],0).
plusList([X|Xs], S) :- plusList(Xs,SXs), plusNat(X,SXs,S).
totalPlus([],_).
totalPlus([X|Xs],Y):-totalPlus(Xs,_), plusList(X,Y).
------------------
?-totalPlus([ [s(0)],[s(0),s(0)],[s(s(0))] ], Res).
Res= s(0).
Thanks in advance!
plusList
a second time. – Willem Van Onsem