home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / prolog / library / prolo_c / exampl05.pro < prev    next >
Text File  |  1986-10-06  |  3KB  |  88 lines

  1. /* Program 5 */
  2. /*
  3.   We have commented out the goal. Note: to
  4.   compile to a stand alone program (.EXE) the
  5.   goal must be included within the program. Read
  6.   the comments in this program.
  7.  
  8.   An internal goal will return nothing if it
  9.   fails and will only return the first answer.
  10.  
  11.   Try the following goals as outlined on Page 28
  12.   of the Manual:
  13.  
  14.   brother(ivan,alan). Is false, hence, returns nothing
  15.   grandfather(marilyn,Gf),write(Gf). Returns charles.
  16.          An external goal would return bob also.
  17.   sister(fay,Sis),write(Sis). Returns nothing
  18.   sister(marilyn,beverly) and write("marilyn is
  19.   beverly's sister") or mother(marilyn,beverly)
  20.   and write("marilyn is beverly's mother").
  21.         Returns: "marilyn is beverly's mother"
  22.  
  23. */
  24.  
  25. domains
  26.     person = symbol
  27.  
  28. predicates
  29.     male(person)
  30.     female(person)
  31.     father(person,person)
  32.     mother(person,person)
  33.     sister(person,person)
  34.     parent(person,person)
  35.     brother(person,person)
  36.     uncle(person,person)
  37.     grandfather(person,person)
  38.  
  39.  
  40. clauses
  41.     male(alan).
  42.     male(charles).
  43.     male(bob).
  44.     male(ivan).
  45.  
  46.     female(beverly).
  47.     female(fay).
  48.     female(marilyn).
  49.     female(sally).
  50.  
  51.     mother(marilyn,beverly).
  52.     mother(alan,sally).
  53.  
  54.     father(alan,bob).
  55.     father(beverly,charles).
  56.     father(fay,bob).
  57.     father(marilyn,alan).
  58.  
  59.     parent(X,Y) if mother(X,Y).
  60.     parent(X,Y) if father(X,Y).
  61.  
  62.     brother(X,Y) if       /*The brother of X is Y if  */
  63.         male(Y) and       /*Y is a male and           */
  64.         parent(X,P) and   /*the parent of X is P and  */
  65.         parent(Y,P) and   /*the parent of Y is P and  */
  66.         X <> Y.           /* X and Y are not the same */
  67.  
  68.     sister(X,Y) if        /*The sister of X is Y if   */
  69.         female(Y) and     /*Y is female and           */
  70.         parent(X,P) and   /*the parent of X is P and  */
  71.         parent(Y,P) and   /*the parent of Y is P and  */
  72.         X <> Y.           /*X and Y are not the same  */
  73.  
  74.     uncle(X,U) if         /*The uncle of X is U if    */
  75.         mother(X,P) and   /*the mother of X is P and  */
  76.         brother(P,U).     /*the brother of P is U.    */
  77.  
  78.     uncle(X,U) if         /*The uncle of X is U if    */
  79.         father(X,P) and   /*the father of X is P and  */
  80.         brother(P,U).     /*the brother of P is U     */
  81.  
  82.     grandfather(X,G) if   /*The grandfather of X is G */
  83.         father(P,G) and   /*if the father of P is G   */
  84.         mother(X,P).      /*and the mother of X is P. */
  85.     grandfather(X,G) if   /*The grandfather of X is G */
  86.         father(X,P) and   /*if the father of X is P   */
  87.         father(P,G).      /*the father of P is G      */
  88.