home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1986 / 04 / brownlst.apr < prev    next >
Text File  |  1986-04-30  |  30KB  |  961 lines

  1. .paè.fo                            Listing 1
  2.                             Listing 1
  3.  
  4. elijah-brown father-of robert-brown-sr
  5. robert-brown-sr father-of robert-brown-jr
  6. john-mccollister father-of lavenia-mccollister
  7. isam-mccollister father-of john-mccollister
  8. mr-holt father-of bettie-holt
  9. elias-presley father-of margret-presley
  10. robert-brown-jr father-of robert-brown-iii
  11. paul-h-sewall father-of virginia-sewall
  12. paul-h-sewall father-of paul-sewall-jr
  13. paul-sewall-jr father-of peter-sewall
  14. paul-sewall-jr father-of dee-dee-sewall
  15. paul-sewall-jr father-of mark-sewall
  16. paul-sewall-jr father-of paul-sewall-iii
  17. robert-brown-jr father-of kenneth-brown
  18. robert-brown-sr father-of amos-trice-brown
  19. robert-brown-sr father-of james-elro-brown
  20. clarence-bailey-compton father-of elanor-compon
  21. george-washington-compton father-of clarence-bailey-compton
  22. samuel-compton father-of george-washington-compton
  23. henry-sewall father-of paul-h-sewall
  24. dr-james-d-nelson father-of rachel-nelson
  25. robert-sewall father-of henry-sewall
  26. paul-hebert father-of evelina-hebert
  27. harry-breeden father-of X if
  28.          dorothy-wallace mother-of X
  29. berke-breeden father-of harry-breeden
  30. john-wallace father-of dorothy-wallace
  31. robert-brown-iii father-of krystl-raquelle-brown
  32. paul-sewall-jr father-of robert-sewall-ii
  33. danny-crider father-of amy-crider
  34. bill-skirvin father-of marty-skirvin
  35. bill-skirvin father-of rodney-skirvin
  36. tommy-breeden father-of thomas-andrew-breeden
  37. tommy-breeden father-of suzanne-breeden
  38. john-alsop father-of joy-alsop
  39. lester-stevens father-of geneva-stevens
  40. strawder-breeden father-of daren-breeden
  41. daren-breeden father-of shaun-breeden
  42. strawder-breeden father-of deidra-breeden
  43. robert-bishop father-of krystal-bishop
  44. robert-bishop father-of tiffany-bishop
  45. robert-brown-sr father-of opal-brown
  46. strawder-breeden father-of deva-breeden
  47. strawder-breeden father-of stephanie-breeden
  48. johnny-wilson father-of jonathan-wilson
  49. lester-stevens father-of geneva-stevens
  50. bettie-holt mother-of lavenia-mccollister
  51. miss-hornsby mother-of robert-brown-sr
  52. elizabeth-arthur mother-of john-mccollister
  53. margret-e-presley mother-of betty-holt
  54. virginia-sewall mother-of robert-brown-iii
  55. elanor-compton mother-of virginia-sewall
  56. .paèlilian-givens mother-of X if
  57.          paul-sewall-jr father-of X
  58. virginia-sewall mother-of kenneth-brown
  59. lavenia-mccollister mother-of amos-trice-brown
  60. lavenia-mccollister mother-of james-elro-brown
  61. sarah-virginia-sanford mother-of elanor-compton
  62. mary-eliza-sanford mother-of clarence-bailey-compton
  63. rachel-nelson mother-of paul-h-sewall
  64. jane-kirk mother-of rachel-nelson
  65. evelina-hebert mother-of henry-sewall
  66. eugina-hamilton mother-of evelina-hebert
  67. dorothy-wallace mother-of darlene-breeden
  68. dorothy-wallace mother-of willena-breeden
  69. dorothy-wallace mother-of karen-breeden
  70. dorothy-wallace mother-of bonnie-breeden
  71. dorothy-wallace mother-of tommy-breeden
  72. dorothy-wallace mother-of dorothy-breeden
  73. dorothy-wallace mother-of brenda-breeden
  74. dorothy-wallace mother-of betty-breeden
  75. dorothy-wallace mother-of strawder-breeden
  76. flo-marsh mother-of harry-breeden
  77. christine-xxx mother-of dorothy-wallace
  78. darlene-breeden mother-of krystl-raquelle-brown
  79. dorothy-breeden mother-of amy-crider
  80. brenda-breeden mother-of X if
  81.          bill-skirvin father-of X
  82. joy-alsop mother-of suzanne-breeden
  83. joy-alsop mother-of thomas-andrew-breeden
  84. pauline-davis mother-of joy-alsop
  85. myrtle-jackson mother-of geneva-stevens
  86. tammy-xxx mother-of shaun-breeden
  87. deidra-breeden mother-of krystal-bishop
  88. deidra-breeden mother-of tiffany-bishop
  89. lavenia-mccollister mother-of opal-brown
  90. lavenia-mccollister mother-of robert-brown-jr
  91. elanor-compton mother-of paul-sewall-jr
  92. karen-breeden mother-of jonathan-wilson
  93. geneva-stevens mother-of X if
  94.          strawder-breeden father-of X
  95. myrtle-jackson mother-of geneva-stevens
  96. male (X) if
  97.          X father-of Y
  98. male (john-viscar)
  99. male (shaun-breeden)
  100. female (X) if
  101.          X mother-of Y
  102. female (willena-breeden)
  103. female (bonnie-breeden)
  104. female (karen-breeden)
  105. female (betty-breeden)
  106. female (judy-tracey)
  107. X wife Y if
  108.          X mother-of Z and
  109.          Y father-of Z
  110. èX husband Y if
  111.          Y wife X
  112. X parent-of Y if
  113.          X father-of Y
  114. X parent-of Y if
  115.          X mother-of Y
  116. X wife-of Y if
  117.          X wife Y
  118. judy-tracy wife-of tommy-breeden
  119. X husband-of Y if
  120.          X husband Y
  121. john-viscar husband-of pauline-davis
  122. X child-of Y if
  123.          Y parent-of X
  124. X descendant-of Y if
  125.          X child-of Y
  126. X descendant-of Y if
  127.          Z child-of Y and
  128.          X descendant-of Z
  129. X ancestor-of Y if
  130.          X parent-of Y
  131. X ancestor-of Y if
  132.          Z parent-of Y and
  133.          X ancestor-of Z
  134. lavenia-mccollister moher-of robert-brown-jr
  135. X sibling-of Y if
  136.          Z mother-of X and
  137.          Z mother-of Y and
  138.          x father-of X and
  139.          x father-of Y and
  140.          Not (X EQ Y)
  141. X half-sibling-of Y if
  142.          Z mother-of X and
  143.          Z mother-of Y and
  144.          Not (X sibling-of Y) and
  145.          Not (X EQ Y)
  146. X half-sibling-of Y if
  147.          Z father-of X and
  148.          Z father-of Y and
  149.          Not (X sibling-of Y) and
  150.          Not (X EQ Y)
  151. X aunt-or-uncle-of Y if
  152.          Z parent-of Y and
  153.          X sibling-of Z
  154. X cousin-of Y if
  155.          Z aunt-or-uncle-of X and
  156.          Y child-of Z
  157. .paè
  158.                            Figure 1
  159. .fo                           Figure 1
  160.  
  161. which (X X father-of robert-brown-iii)
  162. Answer is robert-brown-jr
  163. No (more) answers
  164.  
  165. which (X robert-brown-iii father-of X)
  166. Answer is krystl-raquelle-brown
  167. No (more) answers
  168.  
  169. which (X X parent-of krystl-raquelle-brown)
  170. Answer is robert-brown-iii
  171. Answer is darlene-breeden
  172. No (more) answers
  173.  
  174. which (X X descendant-of robert-brown-sr)
  175. Answer is robert-brown-jr
  176. Answer is amos-trice-brown
  177. Answer is james-elro-brown
  178. Answer is opal-brown
  179. Answer is robert-brown-iii
  180. Answer is kenneth-brown
  181. Answer is krystl-raquelle-brown
  182. No (more) answers
  183.  
  184. which (X X aunt-or-uncle-of robert-brown-iii)
  185. Answer is amos-trice-brown
  186. Answer is james-elro-brown
  187. Answer is opal-brown
  188. Answer is paul-sewall-jr
  189. No (more) answers
  190.  
  191. which (X X aunt-or-uncle-of krystl-raquelle-brown)
  192. Answer is kenneth-brown
  193. Answer is willena-breeden
  194. Answer is karen-breeden
  195. Answer is bonnie-breeden
  196. Answer is tommy-breeden
  197. Answer is dorothy-breeden
  198. Answer is brenda-breeden
  199. Answer is betty-breeden
  200. Answer is strawder-breeden
  201. No (more) answers
  202.  
  203. which (X robert-brown-iii cousin-of X)
  204. Answer is peter-sewall
  205. Answer is dee-dee-sewall
  206. Answer is mark-sewall
  207. Answer is paul-sewall-iii
  208. Answer is robert-sewall-ii
  209. No (more) answers
  210. .paèwhich (X krystl-raquelle-brown cousin-of X)
  211. Answer is jonathan-wilson
  212. Answer is thomas-andrew-breeden
  213. Answer is suzanne-breeden
  214. Answer is amy-crider
  215. Answer is marty-skirvin
  216. Answer is rodney-skirvin
  217. Answer is daren-breeden
  218. Answer is deidra-breeden
  219. Answer is deva-breeden
  220. Answer is stephanie-breeden
  221. No (more) answers
  222. .paè                            Listing 2
  223. .fo                             Listing 2
  224.  
  225. ((cousin-of X Y)
  226.   (aunt-or-uncle-of Z X)
  227.   (child-of Y Z))
  228. ((aunt-or-uncle-of X Y)
  229.   (parent-of Z Y)
  230.   (sibling-of X Z))
  231. ((half-sibling-of X Y)
  232.   (mother-of Z X)
  233.   (mother-of Z Y)
  234.   (NOT ? ((sibling-of X Y)))
  235.   (NOT ? ((EQ X Y))))
  236. ((half-sibling-of X Y)
  237.   (father-of Z X)
  238.   (father-of Z Y)
  239.   (NOT ? ((sibling-of X Y)))
  240.   (NOT ? ((EQ X Y))))
  241. ((male X)
  242.   (father-of X Y))
  243. ((male john-viscar))
  244. ((male shaun-breeden))
  245. ((female X)
  246.   (mother-of X Y))
  247. ((female willena-breeden))
  248. ((female bonnie-breeden))
  249. ((female karen-breeden))
  250. ((female betty-breeden))
  251. ((female judy-tracey))
  252. ((wife-of X Y)
  253.   (wife X Y))
  254. ((wife-of judy-tracy tommy-breeden))
  255. ((wife X Y)
  256.   (mother-of X Z)
  257.   (father-of Y Z))
  258. ((husband X Y)
  259.   (wife Y X))
  260. ((husband-of X Y)
  261.   (husband X Y))
  262. ((husband-of john-viscar pauline-davis))
  263. ((descendant-of X Y)
  264.   (child-of X Y))
  265. ((descendant-of X Y)
  266.   (child-of Z Y)
  267.   (descendant-of X Z))
  268. ((child-of X Y)
  269.   (parent-of Y X))
  270. ((parent-of X Y)
  271.   (father-of X Y))
  272. ((parent-of X Y)
  273.   (mother-of X Y))
  274. .paè((ancestor-of X Y)
  275.   (parent-of X Y))
  276. ((ancestor-of X Y)
  277.   (parent-of Z Y)
  278.   (ancestor-of X Z))
  279. ((moher-of lavenia-mccollister robert-brown-jr))
  280. ((father-of elijah-brown robert-brown-sr))
  281. ((father-of robert-brown-sr robert-brown-jr))
  282. ((father-of john-mccollister lavenia-mccollister))
  283. ((father-of isam-mccollister john-mccollister))
  284. ((father-of mr-holt bettie-holt))
  285. ((father-of elias-presley margret-presley))
  286. ((father-of robert-brown-jr robert-brown-iii))
  287. ((father-of paul-h-sewall virginia-sewall))
  288. ((father-of paul-h-sewall paul-sewall-jr))
  289. ((father-of paul-sewall-jr peter-sewall))
  290. ((father-of paul-sewall-jr dee-dee-sewall))
  291. ((father-of paul-sewall-jr mark-sewall))
  292. ((father-of paul-sewall-jr paul-sewall-iii))
  293. ((father-of robert-brown-jr kenneth-brown))
  294. ((father-of robert-brown-sr amos-trice-brown))
  295. ((father-of robert-brown-sr james-elro-brown))
  296. ((father-of clarence-bailey-compton elanor-compon))
  297. ((father-of george-washington-compton clarence-bailey-compton))
  298. ((father-of samuel-compton george-washington-compton))
  299. ((father-of henry-sewall paul-h-sewall))
  300. ((father-of dr-james-d-nelson rachel-nelson))
  301. ((father-of robert-sewall henry-sewall))
  302. ((father-of paul-hebert evelina-hebert))
  303. ((father-of harry-breeden X)
  304.   (mother-of dorothy-wallace X))
  305. ((father-of berke-breeden harry-breeden))
  306. ((father-of john-wallace dorothy-wallace))
  307. ((father-of robert-brown-iii krystl-raquelle-brown))
  308. ((father-of paul-sewall-jr robert-sewall-ii))
  309. ((father-of danny-crider amy-crider))
  310. ((father-of bill-skirvin marty-skirvin))
  311. ((father-of bill-skirvin rodney-skirvin))
  312. ((father-of tommy-breeden thomas-andrew-breeden))
  313. ((father-of tommy-breeden suzanne-breeden))
  314. ((father-of john-alsop joy-alsop))
  315. ((father-of lester-stevens geneva-stevens))
  316. ((father-of strawder-breeden daren-breeden))
  317. ((father-of daren-breeden shaun-breeden))
  318. ((father-of strawder-breeden deidra-breeden))
  319. ((father-of robert-bishop krystal-bishop))
  320. ((father-of robert-bishop tiffany-bishop))
  321. ((father-of robert-brown-sr opal-brown))
  322. ((father-of strawder-breeden deva-breeden))
  323. ((father-of strawder-breeden stephanie-breeden))
  324. ((father-of johnny-wilson jonathan-wilson))
  325. ((father-of lester-stevens geneva-stevens))
  326. ((mother-of bettie-holt lavenia-mccollister))
  327. ((mother-of miss-hornsby robert-brown-sr))
  328. ((mother-of elizabeth-arthur john-mccollister))è((mother-of margret-e-presley betty-holt))
  329. ((mother-of virginia-sewall robert-brown-iii))
  330. ((mother-of elanor-compton virginia-sewall))
  331. ((mother-of lilian-givens X)
  332.   (father-of paul-sewall-jr X))
  333. ((mother-of virginia-sewall kenneth-brown))
  334. ((mother-of lavenia-mccollister amos-trice-brown))
  335. ((mother-of lavenia-mccollister james-elro-brown))
  336. ((mother-of sarah-virginia-sanford elanor-compton))
  337. ((mother-of mary-eliza-sanford clarence-bailey-compton))
  338. ((mother-of rachel-nelson paul-h-sewall))
  339. ((mother-of jane-kirk rachel-nelson))
  340. ((mother-of evelina-hebert henry-sewall))
  341. ((mother-of eugina-hamilton evelina-hebert))
  342. ((mother-of dorothy-wallace darlene-breeden))
  343. ((mother-of dorothy-wallace willena-breeden))
  344. ((mother-of dorothy-wallace karen-breeden))
  345. ((mother-of dorothy-wallace bonnie-breeden))
  346. ((mother-of dorothy-wallace tommy-breeden))
  347. ((mother-of dorothy-wallace dorothy-breeden))
  348. ((mother-of dorothy-wallace brenda-breeden))
  349. ((mother-of dorothy-wallace betty-breeden))
  350. ((mother-of dorothy-wallace strawder-breeden))
  351. ((mother-of flo-marsh harry-breeden))
  352. ((mother-of christine-xxx dorothy-wallace))
  353. ((mother-of darlene-breeden krystl-raquelle-brown))
  354. ((mother-of dorothy-breeden amy-crider))
  355. ((mother-of brenda-breeden X)
  356.   (father-of bill-skirvin X))
  357. ((mother-of joy-alsop suzanne-breeden))
  358. ((mother-of joy-alsop thomas-andrew-breeden))
  359. ((mother-of pauline-davis joy-alsop))
  360. ((mother-of myrtle-jackson geneva-stevens))
  361. ((mother-of tammy-xxx shaun-breeden))
  362. ((mother-of deidra-breeden krystal-bishop))
  363. ((mother-of deidra-breeden tiffany-bishop))
  364. ((mother-of lavenia-mccollister opal-brown))
  365. ((mother-of lavenia-mccollister robert-brown-jr))
  366. ((mother-of elanor-compton paul-sewall-jr))
  367. ((mother-of karen-breeden jonathan-wilson))
  368. ((mother-of geneva-stevens X)
  369.   (father-of strawder-breeden X))
  370. ((mother-of myrtle-jackson geneva-stevens))
  371. ((sibling-of X Y)
  372.   (mother-of Z X)
  373.   (mother-of Z Y)
  374.   (father-of x X)
  375.   (father-of x Y)
  376.   (NOT ? ((EQ X Y))))
  377. .paè                            Listing 3
  378. .fo                             Listing 3
  379.  
  380. (DEFUN * (NLAMBDA X
  381.   NIL ))
  382.  
  383. (¬ Thσ functioε (CAA╥ X⌐ mean≤ (CA╥ (CA╥ X))«  Thi≤ conventioε i≤ ì
  384. extendeΣ t∩ (CDA╥ X⌐ mean≤ (CD╥ (CA╥ X))¼ etc« *)
  385.  
  386. (DEFUN CONCAT (LAMBDA (P Q)
  387.   (* concatenate 2 lists *)
  388.   ((NULL P) Q)
  389.   (CONS (CAR P) (CONCAT (CDR P) Q)) ))
  390.  
  391. (DEFUN PURGE (LAMBDA (L)
  392.   (* purge a list of duplicate members *)
  393.   ((NULL L) NIL)
  394.   ((MEMBER (CAR L) (CDR L))
  395.     (PURGE (CDR L)) )
  396.   (CONS (CAR L) (PURGE (CDR L))) ))
  397.  
  398. (DEFUN JOIN (LAMBDA (L M)
  399.   (* form the set union of 2 lists *)
  400.   (PURGE (CONCAT L M)) ))
  401.  
  402. (DEFUN MEET (LAMBDA (L M)
  403.   (* form the set intersection of 2 lists *)
  404.   (PURGE (COMMON L M)) ))
  405.  
  406. (DEFUN COMMON (LAMBDA (L M)
  407.   (* form the set intersection of 2 lists with possible
  408.       duplicate entries *)
  409.   ((NULL L) NIL)
  410.   ((MEMBER (CAR L) M)
  411.     (CONS (CAR L) (COMMON (CDR L) M)) )
  412.   (COMMON (CDR L) M) ))
  413.  
  414. (DEFUN DEF (LAMBDA (V E)
  415.   (* determine whether the variable V is defined in the
  416.       environment E *)
  417.   ((NULL E) NIL)
  418.   ((EQUAL V (CAAR E)) T)
  419.   (DEF V (CDR E)) ))
  420.  
  421. (DEFUN IMM (LAMBDA (V E)
  422.   (* return the immediate successor of the variable V in the
  423.       environment E *)
  424.   ((NULL E) NIL)
  425.   ((EQUAL V (CAAR E))
  426.     (CDAR E) )
  427.   (IMM V (CDR E)) ))
  428. .paè(DEFUN ULT (LAMBDA (V E)
  429.   (* return the ultimate successor of the variable V in the
  430.       environment E *)
  431.   ((DEF V E)
  432.     (ULT (IMM V E) E) )
  433.   V ))
  434.  
  435. (DEFUN PAIRP (LAMBDA (P)
  436.   (* determine if P is a pair (not an atom) *)
  437.   ((ATOM P) NIL)
  438.   T ))
  439.  
  440. (DEFUN VARIABLEP (LAMBDA (V)
  441.   (* determine if V is a variable *)
  442.   (EQ (CAR (UNPACK V)) '*) ))
  443.  
  444. (DEFUN RECREAL (LAMBDA (F E)
  445.   (* return the recursive realization of a formula F in the
  446.       environment E which amounts to instantiating all variables
  447.       from the environment *)
  448.   ((PAIRP F)
  449.     (CONS (RECREAL (CAR F) E) (RECREAL (CDR F) E)) )
  450.   ((DEF F E)
  451.     (RECREAL (ULT F E) E) )
  452.   F ))
  453.  
  454. (DEFUN OCCURS (LAMBDA (V X E)
  455.   (* see if the variable V occurs in the term X under the
  456.       environment E *)
  457.   ((VARIABLEP X)
  458.     ((DEF X E)
  459.       (OCCURS V (IMM X E) E) )
  460.     ((EQ V X) T) )
  461.   ((ATOM X) NIL)
  462.   ((OCCURS V (CAR X) E) T)
  463.   (OCCURS V (CDR X) E) ))
  464.  
  465. (DEFUN UNIFY (LAMBDA (A B E)
  466.   (* unify 2 expressions (A and B) in the environment E by
  467.       extending E to the most general unifier of A and B and
  468.       returning that environment *)
  469.   ((EQ E 'IMPOSSIBLE)
  470.     'IMPOSSIBLE )
  471.   (EQUATE (ULT A E) (ULT B E) E) ))
  472. .paè(DEFUN EQUATE (LAMBDA (A B E)
  473.   (* auxilliary routine to UNIFY so that the flow of control
  474.       ping-pongs recursivly between UNIFY and EQUATE to
  475.       construct the most general unifier of A and B *)
  476.   ((EQUAL A B) E)
  477.   ((VARIABLEP A)
  478.     ((OCCURS A B E)
  479.       'IMPOSSIBLE )
  480.     (CONS (CONS A B) E) )
  481.   ((VARIABLEP B)
  482.     ((OCCURS B A E)
  483.       'IMPOSSIBLE )
  484.     (CONS (CONS B A) E) )
  485.   ((ATOM A)
  486.     'IMPOSSIBLE )
  487.   ((ATOM B)
  488.     'IMPOSSIBLE )
  489.   (UNIFY (CDR A) (CDR B) (UNIFY (CAR A) (CAR B) E)) ))
  490.  
  491. (DEFUN VARS (LAMBDA (X)
  492.   (* return a list of all the variables found in the expression
  493.       X *)
  494.   ((NULL X) NIL)
  495.   ((VARIABLEP X) X)
  496.   ((ATOM X) NIL)
  497.   (CONCAT (VARS (CAR X)) (VARS (CDR X))) ))
  498.  
  499. (DEFUN VARIANT (LAMBDA (Q E D)
  500.   (* returns a variant of D such that all variables are distinct
  501.       from those of Q in the environment E *)
  502.   (RECREAL D (MAKENV (VARS Q) (VARS E) (VARS D))) ))
  503.  
  504. (DEFUN MAKENV (LAMBDA (Q E D)
  505.   (* make an environment such that the instantiation of D in
  506.       this environment will have no variables in common with the
  507.       instantiation of Q in E *)
  508.   (MAKENV1 (MEET D (JOIN Q E)) (JOIN (JOIN Q E) D)) ))
  509.  
  510. (DEFUN MAKENV1 (LAMBDA (P Q V)
  511.   (* does the dirty work for MAKENV and VARIANT by generating an
  512.       environment that sticks asterisks onto the front of all
  513.       variable names in Q that also occur in P (V is a local
  514.       temporary variable) *)
  515.   ((NULL P) NIL)
  516.   ((ATOM P)
  517.     (SETQ V P)
  518.     (LOOP
  519.       ((NOT (MEMBER V Q)))
  520.       (SETQ V (PACK (CONS '* (UNPACK V)))) )
  521.     (CONS P V) )
  522.   (CONS (MAKENV1 (CAR P) Q) (MAKENV1 (CDR P) Q)) ))
  523. .paè(DEFUN GETLIT (LAMBDA (CL N)
  524.   (* get the Nth litteral in the clause CL and return it both as
  525.       the functions value and in the free variable LITG along
  526.       with its sign in the free variable SIGNG *)
  527.   (SETQ LITG (CAR (NTH CL N)))
  528.   (SETQ SIGNG (NOT (EQ (CAR LITG) '~)))
  529.   ((NOT (NULL SIGNG)) LITG)
  530.   (CADR LITG) ))
  531.  
  532. (DEFUN FRONT (LAMBDA (C N)
  533.   (* return all elements in the clause C in front of element N
  534.       *)
  535.   ((NULL C) NIL)
  536.   ((ZEROP N) NIL)
  537.   ((EQ N 1) NIL)
  538.   (CONS (CAR C) (FRONT (CDR C) (SUB1 N))) ))
  539.  
  540. (DEFUN BACK (LAMBDA (C N)
  541.   (* return all elements in clause C in back of element N *)
  542.   (NTH C (ADD1 N)) ))
  543.  
  544. (DEFUN FACTOR (LAMBDA (C P1 N1 S1 P2 N2 S2 ENV)
  545.   (* returns a factored version of the clause C *)
  546.   (SETQ ENV 'IMPOSSIBLE)
  547.   (SETQ N1 0)
  548.   (LOOP
  549.     (SETQ N1 (ADD1 N1))
  550.     ((GREATERP N1 (LENGTH C))
  551.       'IMPOSSIBLE )
  552.     (GETLIT C N1)
  553.     (SETQ P1 LITG)
  554.     (SETQ S1 SIGNG)
  555.     (SETQ N2 N1)
  556.     ( ((LOOP
  557.           (SETQ N2 (ADD1 N2))
  558.           ((GREATERP N2 (LENGTH C)))
  559.           (GETLIT C N2)
  560.           (SETQ P2 LITG)
  561.           (SETQ S2 SIGNG)
  562.           ( ((EQ S1 S2)
  563.               (SETQ ENV (UNIFY P1 P2)) ) )
  564.           ((NOT (EQ ENV 'IMPOSSIBLE))
  565.             (SETQ C (RECREAL C ENV))
  566.             (SETQ C (APPEND (FRONT C N1) (BACK C N1))) ) )) )
  567.     ((NOT (EQ ENV 'IMPOSSIBLE))) )
  568.   ((NOT (EQ ENV 'IMPOSSIBLE)) C)
  569.   'IMPOSSIBLE ))
  570. .paè(DEFUN BINRES (LAMBDA (CL1 N1 CL2 N2 ENV LIT1 SGN1 LIT2 SGN2 L1
  571.     L2 LITG SIGNG)
  572.   (* compute the binary resolvent of clause CL1 litteral number
  573.       N1 with clause CL2 litteral number N2 and return the
  574.       instantiated resolvent *)
  575.   (SETQ CL2 (VARIANT CL1 ENV CL2))
  576.   (SETQ LIT1 (GETLIT CL1 N1))
  577.   (SETQ L1 LITG)
  578.   (SETQ SGN1 SIGNG)
  579.   (SETQ LIT2 (GETLIT CL2 N2))
  580.   (SETQ L2 LITG)
  581.   (SETQ SGN2 SIGNG)
  582.   ((EQ SGN1 SGN2) NIL)
  583.   (SETQ ENV (UNIFY LIT1 LIT2 ENV))
  584.   ((EQ ENV 'IMPOSSIBLE)
  585.     'IMPOSSIBLE )
  586.   (RECREAL (APPEND (FRONT CL1 N1) (BACK CL1 N1) (FRONT CL2 N2)
  587.       (BACK CL2 N2)) ENV) ))
  588.  
  589. (DEFUN PARAMOD (LAMBDA (FROM INTO PF F PI I SEL SUB ENV SWAP PM)
  590.   (* return the paramodulant of the FROM clause into the INTO
  591.       clause *)
  592.   (SETQ INTO (VARIANT FROM NIL INTO))
  593.   (SETQ PM 'IMPOSSIBLE)
  594.   (SETQ PF 0)
  595.   (LOOP
  596.     (SETQ PF (ADD1 PF))
  597.     (SETQ F (CAR (NTH FROM PF)))
  598.     ((NULL F))
  599.     ((EQ (CAR F) '=)
  600.       (SETQ SEL (CADR F))
  601.       (SETQ SUB (CADDR F))
  602.       (SETQ PI 0)
  603.       (LOOP
  604.         (SETQ PI (ADD1 PI))
  605.         (SETQ I (CAR (NTH INTO PI)))
  606.         ((NULL I))
  607.         (SETQ ENV (UNIFY SEL I))
  608.         ( ((EQ ENV 'IMPOSSIBLE)
  609.             (SETQ ENV (UNIFY SUB I))
  610.             (SETQ SUB SEL) ) )
  611.         ((NOT (EQ ENV 'IMPOSSIBLE))
  612.           (SETQ FROM (RECREAL FROM ENV))
  613.           (SETQ INTO (RECREAL INTO ENV))
  614.           ( ((NOT (NULL SWAP))
  615.               (SETQ SUB SEL) ) )
  616.           (SETQ INTO (APPEND (FRONT INTO PI) (LIST SUB) (BACK
  617.               INTO PI)))
  618.           (SETQ FROM (APPEND (FRONT FROM PF) (BACK FROM PF)))
  619.           (SETQ PM (APPEND FROM INTO)) ) ) )
  620.     ((NOT (EQ PM 'IMPOSSIBLE))) )
  621.   PM ))
  622. .paè                           Figure 2
  623. .fo                            Figure 2
  624.  
  625. (SETQ C1 '((F *X)))
  626. ((F *X))
  627. (SETQ C2 '((G *X)))
  628. ((G *X))
  629. (SETQ E (UNIFY C1 C2))
  630. IMPOSSIBLE
  631. (RECREAL C1 E)
  632. ((F *X))
  633. (RECREAL C2 E)
  634. ((G *X))
  635.  
  636. (SETQ C2 '((F A)))
  637. ((F A))
  638. (SETQ E (UNIFY C1 C2))
  639. ((*X . A))
  640. (RECREAL C1 E)
  641. ((F A))
  642. (RECREAL C2 E)
  643. ((F A))
  644.  
  645. (SETQ C2 '((F (G *Y))))
  646. ((F (G *Y)))
  647. (SETQ E (UNIFY C1 C2))
  648. ((*X G *Y))
  649. (RECREAL C1 E)
  650. ((F (G *Y)))
  651. (RECREAL C2 E)
  652. ((F (G *Y)))
  653.  
  654. (SETQ C2 '((F (F *X))))
  655. ((F (F *X)))
  656. (SETQ E (UNIFY C1 C2))
  657. IMPOSSIBLE
  658. (RECREAL C1 E)
  659. ((F *X))
  660. (RECREAL C2 E)
  661. ((F (F *X)))
  662.  
  663. (SETQ C1 '((F *X A) (G B *Y)))
  664. ((F *X A) (G B *Y))
  665. (SETQ C2 '((F B *Y) (G *X *Z)))
  666. ((F B *Y) (G *X *Z))
  667. (SETQ E (UNIFY C1 C2))
  668. ((*Z . A) (*Y . A) (*X . B))
  669. (RECREAL C1 E)
  670. ((F B A) (G B A))
  671. (RECREAL C2 E)
  672. ((F B A) (G B A))
  673. .paè                           Figure 3
  674. .fo                            Figure 3
  675.  
  676. (SETQ CL1 '((F *X) (~ (G *Y A)) (F B)))
  677. ((F *X) (~ (G *Y A)) (F B))
  678.  
  679. (FACTOR CL1)
  680. ((~ (G *Y A)) (F B))
  681.  
  682. (SETQ CL2 '((G B *X) (F *Y)))
  683. ((G B *X) (F *Y))
  684.  
  685. (BINRES CL1 2 CL2 1)
  686. ((F *X) (F B) (F **Y))
  687.  
  688. (SETQ FROM '((F *X) (= (G *Y A) (F *Y)) (F B)))
  689. ((F *X) (= (G *Y A) (F *Y)) (F B))
  690.  
  691. (SETQ INTO CL2)
  692. ((G B *X) (F *Y))
  693.  
  694. (PARAMOD FROM INTO)
  695. ((F *X) (F B) (F *Y) (F **Y))
  696. .paè                            Listing 4
  697. .fo                             Listing 4
  698.  
  699. (DEFUN VARIABLEP (LAMBDA (V)
  700.   (* determine if V is a variable: if it starts with lower-case
  701.       it is *)
  702.   ((ATOM V)
  703.     (GREATERP (ASCII (CAR (UNPACK V))) (ASCII `)) )
  704.   NIL ))
  705.  
  706. (DEFUN LPAR (LAMBDA (R)
  707.   (* return left parent *)
  708.   (CAR R) ))
  709.  
  710. (DEFUN LLIT# (LAMBDA (R)
  711.   (* return left litteral number *)
  712.   (CADR R) ))
  713.  
  714. (DEFUN RPAR (LAMBDA (R)
  715.   (* return right parent *)
  716.   (CADDR R) ))
  717.  
  718. (DEFUN RLIT# (LAMBDA (R)
  719.   (* return right litteral number *)
  720.   (CAR (CDDDR R)) ))
  721.  
  722. (DEFUN NLITS (LAMBDA (R)
  723.   (* return number of litterals *)
  724.   (CADR (CDDDR R)) ))
  725.  
  726. (DEFUN MAXNDX (LAMBDA (R)
  727.   (* return maximum index *)
  728.   (CADDR (CDDDR R)) ))
  729.  
  730. (DEFUN BINDINGS (LAMBDA (R)
  731.   (* return the bindings *)
  732.   (CAR (CDDDR (CDDDR R))) ))
  733.  
  734. (DEFUN SETLPAR (LAMBDA (R V)
  735.   (* set left parent *)
  736.   (RPLACA R V) ))
  737.  
  738. (DEFUN SETLLIT# (LAMBDA (R V)
  739.   (* set left litteral number *)
  740.   (RPLACA (CDR R) V) ))
  741.  
  742. (DEFUN SETRPAR (LAMBDA (R V)
  743.   (* set right parent *)
  744.   (RPLACA (CDDR R) V) ))
  745.  
  746. (DEFUN SETRLIT# (LAMBDA (R V)
  747.   (* set right litteral number *)
  748.   (RPLACA (CDDDR R) V) ))
  749. .paè(DEFUN SETNUMLITS (LAMBDA (R V)
  750.   (* set number of litterals *)
  751.   (RPLACA (CDR (CDDDR R)) V) ))
  752.  
  753. (DEFUN SETMAXNDX (LAMBDA (R V)
  754.   (* set maximum index *)
  755.   (RPLACA (CDDR (CDDDR R)) V) ))
  756.  
  757. (DEFUN SETBINDINGS (LAMBDA (R V)
  758.   (* set bindings *)
  759.   (RPLACA (CDDDR (CDDDR R)) V) ))
  760.  
  761. (DEFUN INRECP (LAMBDA (R)
  762.   (* is R an input record? *)
  763.   (NULL (RPAR R)) ))
  764.  
  765. (DEFUN LEQP (LAMBDA (X Y)
  766.   (* is X less than or equal to Y ? *)
  767.   (NOT (GREATERP X Y)) ))
  768.  
  769. (DEFUN NMEMS (LAMBDA (L)
  770.   (* return the number of members in the list L *)
  771.   ((NULL L) 0)
  772.   (ADD1 (NMEMS (CDR L))) ))
  773.  
  774. (DEFUN EXTRACT (LAMBDA (K L TMP)
  775.   (* return the Kth member of L *)
  776.   (* TMP is a local variable *)
  777.   (LOOP
  778.     ((ZEROP K) TMP)
  779.     (SETQ K (SUB1 K))
  780.     (SETQ TMP (POP L)) ) ))
  781.  
  782. (DEFUN RESOLVE (LAMBDA (CL1 I CL2 J LLIT RLIT LNDX RNDX BNDEV
  783.     LSIGN RSIGN)
  784.   (* resolve clause CL1 litteral I with clause CL2 litteral J
  785.       returning a new clause record representing the resolvent:
  786.       UNIFY will extend the binding environment: returns NIL if
  787.       impossible *)
  788.   (GETLIT CL1 I)
  789.   (SETQ LLIT LITG)
  790.   (SETQ LNDX INDEXG)
  791.   (SETQ LSIGN SIGNG)
  792.   (GETLIT CL2 J)
  793.   (SETQ RLIT LITG)
  794.   (SETQ RNDX (PLUS INDEXG (MAXNDX CL1)))
  795.   (SETQ RSIGN SIGNG)
  796.   (* create the new clause record *)
  797.   (SETQ BNDEV (LIST CL1 I CL2 J (DIFFERENCE (PLUS (NLITS CL1)
  798.       (NLITS CL2)) 2) (PLUS (MAXNDX CL1) (MAXNDX CL2)) NIL))
  799.   (* test for opposite signs *)
  800.   ((EQ LSIGN RSIGN) NIL)
  801.   (* extend the environment by the unification algorithm *)
  802.   ((UNIFY LLIT LNDX RLIT RNDX) BNDEV)
  803.   NIL ))è
  804. (DEFUN GETLIT (LAMBDA (CL K)
  805.   (* get the Kth litteral in clause CL: return the litteral
  806.       gotten in LITG: and the associated index in INDEXG *)
  807.   (* if CL is an input clause then extract the Kth litteral and
  808.       set the index to 1 *)
  809.   ((INRECP CL)
  810.     (SETQ LITG (EXTRACT K (LPAR CL)))
  811.     (SETQ SIGNG (EQ K 1))
  812.     (SETQ INDEXG 1) )
  813.   (* if it is in the left parent of the clause then get the
  814.       litteral from the left parent *)
  815.   (* this is true if K is less than the litteral last resolved
  816.       upon in the left parent of the current clause *)
  817.   ((LESSP K (LLIT# CL))
  818.     (GETLIT (LPAR CL) K) )
  819.   (* this is also true if K is less than the number of litterals
  820.       in the left parent but in this case we must adjust K by 1
  821.       *)
  822.   ((LESSP K (NUMLITS (LPAR CL)))
  823.     (GETLIT (LPAR CL) (ADD1 K)) )
  824.   (* if the selected litteral is in the right parent but left of
  825.       the litteral last resolved upon then get the litteral from
  826.       the right parent with the appropriate adjustment to K *)
  827.   ((LESSP K (PLUS (SUB1 (NUMLITS (LPAR CL))) (RLIT# CL)))
  828.     (GETLIT (RPAR CL) (ADD1 (DIFFERENCE K (NUMLITS (LPAR CL)))))
  829.     (* in this case adjust the index got *)
  830.     (SETQ INDEXG (PLUS INDEXG (MAXNDX (LPAR CL)))) )
  831.   (* otherwise the selected litteral is in the right parent to
  832.       the right of last litteral resolved upon so adjust K
  833.       accordingly and get the litteral *)
  834.   (GETLIT (RPAR CL) (PLUS (DIFFERENCE K (NUMLITS (LPAR CL))) 2))
  835.   (* and adjust the index gotten *)
  836.   (SETQ INDEXG (PLUS INDEXG (MAXNDX (LPAR CL)))) ))
  837. .paè(DEFUN UNIFY (LAMBDA (TERM1 INDEX1 TERM2 INDEX2)
  838.   (* attempt to unify TERM1 under INDEX1 with TERM2 under INDEX2
  839.       and extend the binding environment represented in the
  840.       global variable BNDEV: return T if successful or NIL if the
  841.       unification is impossible *)
  842.   (* if both terms and indices are equal then return T: no
  843.       extension to BNDEV is needed *)
  844.   ((EQUAL TERM1 TERM2)
  845.     (EQ INDEX1 INDEX2)
  846.     T )
  847.   (* if TERM1 is a variable *)
  848.   ((VARIABLEP TERM1)
  849.     (* then if it is bound in the current environment *)
  850.     ((ISBOUND TERM1 INDEX1 BNDEV)
  851.       (* then substitute that binding and attempt to unify again
  852.           *)
  853.       (UNIFY TERMB INDEXB TERM2 INDEX2) )
  854.     (* else if the variable of TERM1 occurs in TERM2 then we
  855.         have a recursive """black" "hole""" situation so return 
  856.         NIL *)
  857.     ((OCCUR TERM1 INDEX1 TERM2 INDEX2) NIL)
  858.     (* else force a unification by adding the necessary binding
  859.         and return T for success *)
  860.     (BIND TERM1 INDEX1 TERM2 INDEX2 BNDEV)
  861.     T )
  862.   (* if TERM2 is a variable then swap the 2 terms and UNIFY the
  863.       other way *)
  864.   ((VARIABLEP TERM2)
  865.     (UNIFY TERM2 INDEX2 TERM1 INDEX1) )
  866.   (* otherwise if the heads of the terms unify then return the
  867.       result of unifying the tails of the terms: the environment
  868.       is extended as needed *)
  869.   ((UNIFY (CAR TERM1) INDEX1 (CAR TERM2) INDEX2)
  870.     (UNIFY (CDR TERM1) INDEX1 (CDR TERM2) INDEX2) ) ))
  871. .paè(DEFUN ISBOUND (LAMBDA (VAR INDEX BNDEV)
  872.   (* determine if the variable VAR under the index INDEX is
  873.       bound in the binding environment BNDEV: if it is then
  874.       return T and set the free variables TERMB and INDEXB to
  875.       the term and index respectively to which it is bound: *)
  876.   (* otherwise return NIL and do not alter the values of TERMB and
  877.       INDEXB *)
  878.   (* if BNDEV is an input record then it cannot be bound so
  879.       return NIL *)
  880.   ((INRECP BNDEV) NIL)
  881.   (* if VAR under INDEX is equal to the head of the binding
  882.       environment at this level then return T and set TERMB and
  883.       INDEXB accordingly *)
  884.   ((EQUAL (CONS VAR INDEX) (CAR (BINDINGS BNDEV)))
  885.     (SETQ TERMB (CADAR (BINDINGS BNDEV)))
  886.     (SETQ INDEXB (CAR (CDDAR (BINDINGS BNDEV))))
  887.     T )
  888.   (* else see if it is bound in the tail of the binding
  889.       environment at this level *)
  890.   ((ISBOUND VAR INDEX (CDR (BINDINGS BNDEV))) T)
  891.   (* if not then check INDEX to see whether to search the left
  892.       or right parent binding environment *)
  893.   ((LEQP INDEX (MAXNDX (LPAR BNDEV)))
  894.     (* search left parent *)
  895.     (ISBOUND VAR INDEX (LPAR BNDEV)) )
  896.   (* search right parent *)
  897.   ((ISBOUND VAR (DIFFERENCE INDEX (MAXNDX (LPAR BNDEV))) (RPAR
  898.       BNDEV))
  899.     (* adjust INDEXB accordingly *)
  900.     (SETQ INDEXB (PLUS INDEXB (MAXNDX (LPAR BNDEV))))
  901.     (* and return success *)
  902.     T )
  903.   (* all possible approaches failed so return NIL for not bound *)
  904.   NIL ))
  905. .paè(DEFUN OCCUR (LAMBDA (V I TERM J)
  906.   (* see if the variable V under the index I occurs in the term
  907.       TERM under the index J and return T or NIL *)
  908.   (* if TERM is a variable *)
  909.   ((VARIABLEP TERM)
  910.     (* then if it is bound *)
  911.     ((ISBOUND TERM J BNDEV)
  912.       (* then make the substitution and test for occurance *)
  913.       (OCCUR V I TERMB INDEXB) )
  914.     (* if V equals TERM *)
  915.     ((EQ V TERM)
  916.       (* then return T if I=J else NIL *)
  917.       (EQ I J) ) )
  918.   (* if TERM is atomic and not a variable *)
  919.   (* then it is a constant so return NIL *)
  920.   ((ATOM TERM) NIL)
  921.   (* otherwise if V under I occurs in the head of TERM under J
  922.       then return T *)
  923.   ((OCCUR V I (CAR TERM) J) T)
  924.   (* otherwise return T if V under I occurs in the tail of TERM
  925.       under J and NIL otherwise *)
  926.   (OCCUR V I (CDR TERM) J) ))
  927.  
  928. (DEFUN BIND (LAMBDA (V I TERM J BNDEV)
  929.   (* bind V under I to TERM under J in BNDEV *)
  930.   (SETBINDINGS BNDEV (CONS (CONS (CONS V I) (CONS TERM J))
  931.       (BINDINGS BNDEV))) ))
  932.  
  933. (DEFUN * (LAMBDA COMMENTS
  934.   NIL ))
  935.  
  936. (DEFUN MAKECL (LAMBDA (CL)
  937.   (* make a clause record out of the expression CL *)
  938.   (LIST CL 0 NIL 0 (NMEMS CL) 1 NIL) ))
  939. .paè                           Figure 4
  940. .fo                            Figure 4
  941.  
  942. (SETQ CLAUSE-1 '((F x y) (G x) (P A y x) ))
  943. ((F x y) (G x) (P A y x))
  944.  
  945. (SETQ CLAUSE-2 '((P A B C)))
  946. ((P A B C))
  947.  
  948. (SETQ CLAUSE-3 '((G C)))
  949. ((G C))
  950.  
  951. (SETQ TEST (RESOLVE (MAKECL CLAUSE-1) 2 (MAKECL CLAUSE-3) 1))
  952.       ( ((F x y) (G x) (P A y x)) 0 NIL 0 3 1 NIL )
  953.       2
  954.       ( ((G C)) 0 NIL 0 1 1 NIL )
  955.       1
  956.       2
  957.       2
  958.       ( ((x . 1) C . 2))
  959. )
  960.