home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / library / prolo_c / exampl61.pro < prev    next >
Text File  |  1986-10-06  |  648b  |  26 lines

  1. /* program 61 */
  2. /*
  3.   Try the goal
  4.       plus(A,1,5),plus(1,B,10),plus(B,A,C).
  5. */
  6.  
  7. predicates
  8.     plus(integer,integer,integer)
  9.     numb(integer)
  10.  
  11. clauses
  12.     plus(X,Y,Z):- bound(X),bound(Y),Z=X+Y.
  13.     plus(X,Y,Z):- bound(X),bound(Z),Y=Z-X.
  14.     plus(X,Y,Z):- bound(Z),bound(Y),X=Z-Y.
  15.     plus(X,Y,Z):- free(X),free(Y),bound(Z),numb(X), Y=Z-X.
  16.     plus(X,Y,Z):- free(X),free(Z),bound(Y),numb(X), Z=X+Y.
  17.     plus(X,Y,Z):- free(Y),free(Z),bound(X),numb(Y), Z=X+Y.
  18.     plus(X,Y,Z):-
  19.         free(X),free(Y),free(Z),numb(X),numb(Y),Z=X+Y.
  20.  
  21. /*
  22.   Generator of numbers starting at 0
  23. */
  24.  
  25.     numb(0).
  26.     numb(X) :- numb(A), X=A+1.