Next: Constructing Recursive Data Structures:
Up: Adding Computation Domains: CLP
Previous: Constructing Recursive Data Structures
-
- Adding Peano numbers:
-
- add(z, X, X):- natural(X).
add(s(N), X, s(Y)):- add(N, X, Y).
-
- Some queries
-
- ?- add(s(s(z)), s(z), R).
R = s(s(s(z)))
?- add(s(s(s(z))), T, s(s(s(s(s(z))))).
T = s(z)
?- add(s(s(s(s(z)))), T, s(s(s(z)))).
no
?- add(X, Y, s(s(z))).
X = z, Y = s(s(z)) ;
X = s(z), Y = s(z) ;
X = s(s(z)), Y = z
Last modification: Thu Oct 7 12:04:03 MEST 1999 <webmaster@clip.dia.fi.upm.es>