home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l210 / 1.ddi / EXAMPLES.ARC / CH05EX12.PRO < prev    next >
Encoding:
Text File  |  1988-06-21  |  2.9 KB  |  111 lines

  1. /*
  2.    Turbo Prolog 2.0 Chapter 5, Example Program 12
  3.    
  4.    Copyright (c) 1986, 88 by Borland International, Inc
  5.    
  6. */
  7.    
  8. trace
  9. domains
  10.    name, sex, occupation, object, vice, substance = symbol
  11.    age=integer
  12.  
  13. predicates
  14.    person(name, age, sex, occupation)
  15.    had_affair(name, name)
  16.    killed_with(name, object)
  17.    killed(name)
  18.    killer(name)
  19.    motive(vice)
  20.    smeared_in(name, substance)
  21.    owns(name, object)
  22.    operates_identically(object, object)
  23.    owns_probably(name, object)
  24.    suspect(name)
  25.  
  26. /* * * Facts about the murder * * */
  27. clauses
  28.    person(bert, 55, m, carpenter).
  29.    person(allan, 25, m, football_player).
  30.    person(allan, 25, m, butcher).
  31.    person(john, 25, m, pickpocket).
  32.  
  33.    had_affair(barbara, john).
  34.    had_affair(barbara, bert).
  35.    had_affair(susan, john).
  36.  
  37.    killed_with(susan, club).
  38.    killed(susan).
  39.  
  40.    motive(money).
  41.    motive(jealousy).
  42.    motive(righteousness).
  43.  
  44.    smeared_in(bert, blood).
  45.    smeared_in(susan, blood).
  46.    smeared_in(allan, mud).
  47.    smeared_in(john, chocolate).
  48.    smeared_in(barbara, chocolate).
  49.  
  50.    owns(bert, wooden_leg).
  51.    owns(john, pistol).
  52.  
  53. /* * * Background knowledge * * */
  54.  
  55.    operates_identically(wooden_leg, club).
  56.    operates_identically(bar, club).
  57.    operates_identically(pair_of_scissors, knife).
  58.    operates_identically(football_boot, club).
  59.  
  60.    owns_probably(X, football_boot) :-
  61.       person(X, _, _, football_player).
  62.    owns_probably(X, pair_of_scissors) :-
  63.       person(X, _, _, hairdresser).
  64.    owns_probably(X, Object) :-
  65.       owns(X, Object).
  66.  
  67. /* * * * * * * * * * * * * * * * * * * * * * *
  68.  * Suspect all those who own a weapon with   *
  69.  * which Susan could have been killed.       *
  70.  * * * * * * * * * * * * * * * * * * * * * * */
  71.  
  72.    suspect(X) :-
  73.       killed_with(susan, Weapon) ,
  74.       operates_identically(Object, Weapon) ,
  75.       owns_probably(X, Object).
  76.  
  77. /* * * * * * * * * * * * * * * * * * * * * * * * * *
  78.  * Suspect men who have had an affair with Susan.  *
  79.  * * * * * * * * * * * * * * * * * * * * * * * * * */
  80.  
  81.    suspect(X) :-
  82.       motive(jealousy) ,
  83.       person(X, _, m, _) ,
  84.       had_affair(susan, X).
  85.  
  86. /* * * * * * * * * * * * * * * * * * * * *
  87.  * Suspect females who have had an       *
  88.  * affair with someone that Susan knew.  *
  89.  * * * * * * * * * * * * * * * * * * * * */
  90.  
  91.    suspect(X) :-
  92.       motive(jealousy) ,
  93.       person(X, _, f, _) ,
  94.       had_affair(X, Man) ,
  95.       had_affair(susan, Man).
  96.  
  97. /* * * * * * * * * * * * * * * * * * * * * * * * * * *
  98.  * Suspect pickpockets whose motive could be money.  *
  99.  * * * * * * * * * * * * * * * * * * * * * * * * * * */
  100.  
  101.    suspect(X) :-
  102.       motive(money) , person(X, _, _, pickpocket).
  103.  
  104.    killer(Killer) :-
  105.       person(Killer, _, _, _) ,
  106.       killed(Killed) ,
  107.       Killed <> Killer , /* It is not a suicide */
  108.       suspect(Killer) ,
  109.       smeared_in(Killer, Goo) ,
  110.       smeared_in(Killed, Goo).
  111.