home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l217 / 2.ddi / EXAMPLES / CH21EX01.PRO < prev    next >
Encoding:
Prolog Source  |  1990-03-26  |  735 b   |  22 lines

  1. /*
  2.    Copyright (c) 1986, 90 by Prolog Development Center
  3. */
  4.  
  5. predicates
  6.    plus(integer, integer, integer)
  7.    num(integer)
  8.  
  9. clauses
  10.    plus(X,Y,Z) :- bound(X), bound(Y), Z=X+Y. /* (i,i,o) */
  11.    plus(X,Y,Z) :- bound(Y), bound(Z), X=Z-Y. /* (o,i,i) */
  12.    plus(X,Y,Z) :- bound(X), bound(Z), Y=Z-X. /* (i,o,i) */
  13.    plus(X,Y,Z) :- free(X), free(Y), bound(Z), num(X), Y=Z-X. /* (o,o,i) */
  14.    plus(X,Y,Z) :- free(X), free(Z), bound(Y), num(X), Z=X+Y. /* (o,i,o) */
  15.    plus(X,Y,Z) :- free(Y), free(Z), bound(X), num(Y), Z=X+Y. /* (i,o,o) */
  16.    plus(X,Y,Z) :- free(X), free(Y), free(Z), num(X), num(Y), Z=X+Y.
  17.                                 /* (o,o,o) */
  18.  
  19.    /* Generator of numbers starting from 0 */
  20.    num(0).
  21.    num(X) :- num(A), X = A+1.
  22.