irewrite.sl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. % {DSK}IREWRITE.PSL;2 6-JAN-83 10:08:06
  2. (DE ADD-LEMMA (TERM)
  3. (COND ((AND (NOT (ATOM TERM))
  4. (EQ (CAR TERM)
  5. 'EQUAL)
  6. (NOT (ATOM (CADR TERM))))
  7. (PUT (CAR (CADR TERM))
  8. 'LEMMAS
  9. (CONS TERM (GET (CAR (CADR TERM))
  10. 'LEMMAS))))
  11. (T (ERROR 0 (LIST 'ADD-LEMMA-DID-NOT-LIKE-TERM
  12. TERM)))))
  13. (DE ADD-LEMMA-LST (LST)
  14. (COND ((NULL LST)
  15. T)
  16. (T (ADD-LEMMA (CAR LST))
  17. (ADD-LEMMA-LST (CDR LST)))))
  18. % lmm 7-JUN-81 10:07
  19. (DE APPLY-SUBST (ALIST TERM)
  20. (COND ((NOT (PAIRP TERM))
  21. ((LAMBDA (TEM)
  22. (COND
  23. (TEM (CDR TEM))
  24. (T TERM)))
  25. (ASSOC TERM ALIST)))
  26. (T (CONS (CAR TERM)
  27. (MAPCAR (CDR TERM)
  28. (FUNCTION (LAMBDA (X)
  29. (APPLY-SUBST ALIST X))))))))
  30. (DE APPLY-SUBST-LST (ALIST LST)
  31. (COND ((NULL LST)
  32. NIL)
  33. (T (CONS (APPLY-SUBST ALIST (CAR LST))
  34. (APPLY-SUBST-LST ALIST (CDR LST))))))
  35. (DE FALSEP (X LST)
  36. (OR (EQUAL X '(F))
  37. (MEMBER X LST)))
  38. (DE ONE-WAY-UNIFY (TERM1 TERM2)
  39. (PROGN (SETQ UNIFY-SUBST NIL)
  40. (ONE-WAY-UNIFY1 TERM1 TERM2)))
  41. % lmm 7-JUN-81 09:47
  42. (DE ONE-WAY-UNIFY1 (TERM1 TERM2)
  43. (COND ((NOT (PAIRP TERM2))
  44. ((LAMBDA (TEM)
  45. (COND
  46. (TEM (EQUAL TERM1 (CDR TEM)))
  47. (T (SETQ UNIFY-SUBST (CONS (CONS TERM2 TERM1)
  48. UNIFY-SUBST))
  49. T)))
  50. (ASSOC TERM2 UNIFY-SUBST)))
  51. ((NOT (PAIRP TERM1))
  52. NIL)
  53. ((EQ (CAR TERM1)
  54. (CAR TERM2))
  55. (ONE-WAY-UNIFY1-LST (CDR TERM1)
  56. (CDR TERM2)))
  57. (T NIL)))
  58. (DE ONE-WAY-UNIFY1-LST (LST1 LST2)
  59. (COND ((NULL LST1)
  60. T)
  61. ((ONE-WAY-UNIFY1 (CAR LST1)
  62. (CAR LST2))
  63. (ONE-WAY-UNIFY1-LST (CDR LST1)
  64. (CDR LST2)))
  65. (T NIL)))
  66. (DE PTIME NIL
  67. (PROG (GCTM)
  68. (SETQ GCTM 0)
  69. (RETURN (CONS (time)
  70. GCTM))))
  71. % lmm 7-JUN-81 10:04
  72. (DE REWRITE (TERM)
  73. (COND ((NOT (PAIRP TERM))
  74. TERM)
  75. (T (REWRITE-WITH-LEMMAS (CONS (CAR TERM)
  76. (MAPCAR (CDR TERM)
  77. (FUNCTION REWRITE)))
  78. (GET (CAR TERM)
  79. 'LEMMAS)))))
  80. (DE REWRITE-WITH-LEMMAS (TERM LST)
  81. (COND ((NULL LST)
  82. TERM)
  83. ((ONE-WAY-UNIFY TERM (CADR (CAR LST)))
  84. (REWRITE (APPLY-SUBST UNIFY-SUBST (CADDR (CAR LST)))))
  85. (T (REWRITE-WITH-LEMMAS TERM (CDR LST)))))
  86. (DE SETUP NIL
  87. (ADD-LEMMA-LST
  88. '((EQUAL (COMPILE FORM)
  89. (REVERSE (CODEGEN (OPTIMIZE FORM)
  90. (NIL))))
  91. (EQUAL (EQP X Y)
  92. (EQUAL (FIX X)
  93. (FIX Y)))
  94. (EQUAL (GREATERP X Y)
  95. (LESSP Y X))
  96. (EQUAL (LESSEQP X Y)
  97. (NOT (LESSP Y X)))
  98. (EQUAL (GREATEREQP X Y)
  99. (NOT (LESSP X Y)))
  100. (EQUAL (BOOLEAN X)
  101. (OR (EQUAL X (T))
  102. (EQUAL X (F))))
  103. (EQUAL (IFF X Y)
  104. (AND (IMPLIES X Y)
  105. (IMPLIES Y X)))
  106. (EQUAL (EVEN1 X)
  107. (IF (ZEROP X)
  108. (T)
  109. (ODD (SUB1 X))))
  110. (EQUAL (COUNTPS- L PRED)
  111. (COUNTPS-LOOP L PRED (ZERO)))
  112. (EQUAL (FACT- I)
  113. (FACT-LOOP I 1))
  114. (EQUAL (REVERSE- X)
  115. (REVERSE-LOOP X (NIL)))
  116. (EQUAL (DIVIDES X Y)
  117. (ZEROP (REMAINDER Y X)))
  118. (EQUAL (ASSUME-TRUE VAR ALIST)
  119. (CONS (CONS VAR (T))
  120. ALIST))
  121. (EQUAL (ASSUME-FALSE VAR ALIST)
  122. (CONS (CONS VAR (F))
  123. ALIST))
  124. (EQUAL (TAUTOLOGY-CHECKER X)
  125. (TAUTOLOGYP (NORMALIZE X)
  126. (NIL)))
  127. (EQUAL (FALSIFY X)
  128. (FALSIFY1 (NORMALIZE X)
  129. (NIL)))
  130. (EQUAL (PRIME X)
  131. (AND (NOT (ZEROP X))
  132. (NOT (EQUAL X (ADD1 (ZERO))))
  133. (PRIME1 X (SUB1 X))))
  134. (EQUAL (AND P Q)
  135. (IF P (IF Q (T)
  136. (F))
  137. (F)))
  138. (EQUAL (OR P Q)
  139. (IF P (T)
  140. (IF Q (T)
  141. (F))
  142. (F)))
  143. (EQUAL (NOT P)
  144. (IF P (F)
  145. (T)))
  146. (EQUAL (IMPLIES P Q)
  147. (IF P (IF Q (T)
  148. (F))
  149. (T)))
  150. (EQUAL (FIX X)
  151. (IF (NUMBERP X)
  152. X
  153. (ZERO)))
  154. (EQUAL (IF (IF A B C)
  155. D E)
  156. (IF A (IF B D E)
  157. (IF C D E)))
  158. (EQUAL (ZEROP X)
  159. (OR (EQUAL X (ZERO))
  160. (NOT (NUMBERP X))))
  161. (EQUAL (PLUS (PLUS X Y)
  162. Z)
  163. (PLUS X (PLUS Y Z)))
  164. (EQUAL (EQUAL (PLUS A B)
  165. (ZERO))
  166. (AND (ZEROP A)
  167. (ZEROP B)))
  168. (EQUAL (DIFFERENCE X X)
  169. (ZERO))
  170. (EQUAL (EQUAL (PLUS A B)
  171. (PLUS A C))
  172. (EQUAL (FIX B)
  173. (FIX C)))
  174. (EQUAL (EQUAL (ZERO)
  175. (DIFFERENCE X Y))
  176. (NOT (LESSP Y X)))
  177. (EQUAL (EQUAL X (DIFFERENCE X Y))
  178. (AND (NUMBERP X)
  179. (OR (EQUAL X (ZERO))
  180. (ZEROP Y))))
  181. (EQUAL (MEANING (PLUS-TREE (APPEND X Y))
  182. A)
  183. (PLUS (MEANING (PLUS-TREE X)
  184. A)
  185. (MEANING (PLUS-TREE Y)
  186. A)))
  187. (EQUAL (MEANING (PLUS-TREE (PLUS-FRINGE X))
  188. A)
  189. (FIX (MEANING X A)))
  190. (EQUAL (APPEND (APPEND X Y)
  191. Z)
  192. (APPEND X (APPEND Y Z)))
  193. (EQUAL (REVERSE (APPEND A B))
  194. (APPEND (REVERSE B)
  195. (REVERSE A)))
  196. (EQUAL (TIMES X (PLUS Y Z))
  197. (PLUS (TIMES X Y)
  198. (TIMES X Z)))
  199. (EQUAL (TIMES (TIMES X Y)
  200. Z)
  201. (TIMES X (TIMES Y Z)))
  202. (EQUAL (EQUAL (TIMES X Y)
  203. (ZERO))
  204. (OR (ZEROP X)
  205. (ZEROP Y)))
  206. (EQUAL (EXEC (APPEND X Y)
  207. PDS ENVRN)
  208. (EXEC Y (EXEC X PDS ENVRN)
  209. ENVRN))
  210. (EQUAL (MC-FLATTEN X Y)
  211. (APPEND (FLATTEN X)
  212. Y))
  213. (EQUAL (MEMBER X (APPEND A B))
  214. (OR (MEMBER X A)
  215. (MEMBER X B)))
  216. (EQUAL (MEMBER X (REVERSE Y))
  217. (MEMBER X Y))
  218. (EQUAL (LENGTH (REVERSE X))
  219. (LENGTH X))
  220. (EQUAL (MEMBER A (INTERSECT B C))
  221. (AND (MEMBER A B)
  222. (MEMBER A C)))
  223. (EQUAL (NTH (ZERO)
  224. I)
  225. (ZERO))
  226. (EQUAL (EXP I (PLUS J K))
  227. (TIMES (EXP I J)
  228. (EXP I K)))
  229. (EQUAL (EXP I (TIMES J K))
  230. (EXP (EXP I J)
  231. K))
  232. (EQUAL (REVERSE-LOOP X Y)
  233. (APPEND (REVERSE X)
  234. Y))
  235. (EQUAL (REVERSE-LOOP X (NIL))
  236. (REVERSE X))
  237. (EQUAL (COUNT-LIST Z (SORT-LP X Y))
  238. (PLUS (COUNT-LIST Z X)
  239. (COUNT-LIST Z Y)))
  240. (EQUAL (EQUAL (APPEND A B)
  241. (APPEND A C))
  242. (EQUAL B C))
  243. (EQUAL (PLUS (REMAINDER X Y)
  244. (TIMES Y (QUOTIENT X Y)))
  245. (FIX X))
  246. (EQUAL (POWER-EVAL (BIG-PLUS1 L I BASE)
  247. BASE)
  248. (PLUS (POWER-EVAL L BASE)
  249. I))
  250. (EQUAL (POWER-EVAL (BIG-PLUS X Y I BASE)
  251. BASE)
  252. (PLUS I (PLUS (POWER-EVAL X BASE)
  253. (POWER-EVAL Y BASE))))
  254. (EQUAL (REMAINDER Y 1)
  255. (ZERO))
  256. (EQUAL (LESSP (REMAINDER X Y)
  257. Y)
  258. (NOT (ZEROP Y)))
  259. (EQUAL (REMAINDER X X)
  260. (ZERO))
  261. (EQUAL (LESSP (QUOTIENT I J)
  262. I)
  263. (AND (NOT (ZEROP I))
  264. (OR (ZEROP J)
  265. (NOT (EQUAL J 1)))))
  266. (EQUAL (LESSP (REMAINDER X Y)
  267. X)
  268. (AND (NOT (ZEROP Y))
  269. (NOT (ZEROP X))
  270. (NOT (LESSP X Y))))
  271. (EQUAL (POWER-EVAL (POWER-REP I BASE)
  272. BASE)
  273. (FIX I))
  274. (EQUAL (POWER-EVAL (BIG-PLUS (POWER-REP I BASE)
  275. (POWER-REP J BASE)
  276. (ZERO)
  277. BASE)
  278. BASE)
  279. (PLUS I J))
  280. (EQUAL (GCD X Y)
  281. (GCD Y X))
  282. (EQUAL (NTH (APPEND A B)
  283. I)
  284. (APPEND (NTH A I)
  285. (NTH B (DIFFERENCE I (LENGTH A)))))
  286. (EQUAL (DIFFERENCE (PLUS X Y)
  287. X)
  288. (FIX Y))
  289. (EQUAL (DIFFERENCE (PLUS Y X)
  290. X)
  291. (FIX Y))
  292. (EQUAL (DIFFERENCE (PLUS X Y)
  293. (PLUS X Z))
  294. (DIFFERENCE Y Z))
  295. (EQUAL (TIMES X (DIFFERENCE C W))
  296. (DIFFERENCE (TIMES C X)
  297. (TIMES W X)))
  298. (EQUAL (REMAINDER (TIMES X Z)
  299. Z)
  300. (ZERO))
  301. (EQUAL (DIFFERENCE (PLUS B (PLUS A C))
  302. A)
  303. (PLUS B C))
  304. (EQUAL (DIFFERENCE (ADD1 (PLUS Y Z))
  305. Z)
  306. (ADD1 Y))
  307. (EQUAL (LESSP (PLUS X Y)
  308. (PLUS X Z))
  309. (LESSP Y Z))
  310. (EQUAL (LESSP (TIMES X Z)
  311. (TIMES Y Z))
  312. (AND (NOT (ZEROP Z))
  313. (LESSP X Y)))
  314. (EQUAL (LESSP Y (PLUS X Y))
  315. (NOT (ZEROP X)))
  316. (EQUAL (GCD (TIMES X Z)
  317. (TIMES Y Z))
  318. (TIMES Z (GCD X Y)))
  319. (EQUAL (VALUE (NORMALIZE X)
  320. A)
  321. (VALUE X A))
  322. (EQUAL (EQUAL (FLATTEN X)
  323. (CONS Y (NIL)))
  324. (AND (NLISTP X)
  325. (EQUAL X Y)))
  326. (EQUAL (LISTP (GOPHER X))
  327. (LISTP X))
  328. (EQUAL (SAMEFRINGE X Y)
  329. (EQUAL (FLATTEN X)
  330. (FLATTEN Y)))
  331. (EQUAL (EQUAL (GREATEST-FACTOR X Y)
  332. (ZERO))
  333. (AND (OR (ZEROP Y)
  334. (EQUAL Y 1))
  335. (EQUAL X (ZERO))))
  336. (EQUAL (EQUAL (GREATEST-FACTOR X Y)
  337. 1)
  338. (EQUAL X 1))
  339. (EQUAL (NUMBERP (GREATEST-FACTOR X Y))
  340. (NOT (AND (OR (ZEROP Y)
  341. (EQUAL Y 1))
  342. (NOT (NUMBERP X)))))
  343. (EQUAL (TIMES-LIST (APPEND X Y))
  344. (TIMES (TIMES-LIST X)
  345. (TIMES-LIST Y)))
  346. (EQUAL (PRIME-LIST (APPEND X Y))
  347. (AND (PRIME-LIST X)
  348. (PRIME-LIST Y)))
  349. (EQUAL (EQUAL Z (TIMES W Z))
  350. (AND (NUMBERP Z)
  351. (OR (EQUAL Z (ZERO))
  352. (EQUAL W 1))))
  353. (EQUAL (GREATEREQPR X Y)
  354. (NOT (LESSP X Y)))
  355. (EQUAL (EQUAL X (TIMES X Y))
  356. (OR (EQUAL X (ZERO))
  357. (AND (NUMBERP X)
  358. (EQUAL Y 1))))
  359. (EQUAL (REMAINDER (TIMES Y X)
  360. Y)
  361. (ZERO))
  362. (EQUAL (EQUAL (TIMES A B)
  363. 1)
  364. (AND (NOT (EQUAL A (ZERO)))
  365. (NOT (EQUAL B (ZERO)))
  366. (NUMBERP A)
  367. (NUMBERP B)
  368. (EQUAL (SUB1 A)
  369. (ZERO))
  370. (EQUAL (SUB1 B)
  371. (ZERO))))
  372. (EQUAL (LESSP (LENGTH (DELETE X L))
  373. (LENGTH L))
  374. (MEMBER X L))
  375. (EQUAL (SORT2 (DELETE X L))
  376. (DELETE X (SORT2 L)))
  377. (EQUAL (DSORT X)
  378. (SORT2 X))
  379. (EQUAL (LENGTH (CONS X1 (CONS X2 (CONS X3 (CONS X4
  380. (CONS X5 (CONS X6 X7)))))))
  381. (PLUS 6 (LENGTH X7)))
  382. (EQUAL (DIFFERENCE (ADD1 (ADD1 X))
  383. 2)
  384. (FIX X))
  385. (EQUAL (QUOTIENT (PLUS X (PLUS X Y))
  386. 2)
  387. (PLUS X (QUOTIENT Y 2)))
  388. (EQUAL (SIGMA (ZERO)
  389. I)
  390. (QUOTIENT (TIMES I (ADD1 I))
  391. 2))
  392. (EQUAL (PLUS X (ADD1 Y))
  393. (IF (NUMBERP Y)
  394. (ADD1 (PLUS X Y))
  395. (ADD1 X)))
  396. (EQUAL (EQUAL (DIFFERENCE X Y)
  397. (DIFFERENCE Z Y))
  398. (IF (LESSP X Y)
  399. (NOT (LESSP Y Z))
  400. (IF (LESSP Z Y)
  401. (NOT (LESSP Y X))
  402. (EQUAL (FIX X)
  403. (FIX Z)))))
  404. (EQUAL (MEANING (PLUS-TREE (DELETE X Y))
  405. A)
  406. (IF (MEMBER X Y)
  407. (DIFFERENCE (MEANING (PLUS-TREE Y)
  408. A)
  409. (MEANING X A))
  410. (MEANING (PLUS-TREE Y)
  411. A)))
  412. (EQUAL (TIMES X (ADD1 Y))
  413. (IF (NUMBERP Y)
  414. (PLUS X (TIMES X Y))
  415. (FIX X)))
  416. (EQUAL (NTH (NIL)
  417. I)
  418. (IF (ZEROP I)
  419. (NIL)
  420. (ZERO)))
  421. (EQUAL (LAST (APPEND A B))
  422. (IF (LISTP B)
  423. (LAST B)
  424. (IF (LISTP A)
  425. (CONS (CAR (LAST A))
  426. B)
  427. B)))
  428. (EQUAL (EQUAL (LESSP X Y)
  429. Z)
  430. (IF (LESSP X Y)
  431. (EQUAL T Z)
  432. (EQUAL F Z)))
  433. (EQUAL (ASSIGNMENT X (APPEND A B))
  434. (IF (ASSIGNEDP X A)
  435. (ASSIGNMENT X A)
  436. (ASSIGNMENT X B)))
  437. (EQUAL (CAR (GOPHER X))
  438. (IF (LISTP X)
  439. (CAR (FLATTEN X))
  440. (ZERO)))
  441. (EQUAL (FLATTEN (CDR (GOPHER X)))
  442. (IF (LISTP X)
  443. (CDR (FLATTEN X))
  444. (CONS (ZERO)
  445. (NIL))))
  446. (EQUAL (QUOTIENT (TIMES Y X)
  447. Y)
  448. (IF (ZEROP Y)
  449. (ZERO)
  450. (FIX X)))
  451. (EQUAL (GET J (SET I VAL MEM))
  452. (IF (EQP J I)
  453. VAL
  454. (GET J MEM))))))
  455. % lmm 7-JUN-81 09:44
  456. (DE TAUTOLOGYP (X TRUE-LST FALSE-LST)
  457. (COND ((TRUEP X TRUE-LST)
  458. T)
  459. ((FALSEP X FALSE-LST)
  460. NIL)
  461. ((NOT (PAIRP X))
  462. NIL)
  463. ((EQ (CAR X)
  464. 'IF)
  465. (COND ((TRUEP (CADR X)
  466. TRUE-LST)
  467. (TAUTOLOGYP (CADDR X)
  468. TRUE-LST FALSE-LST))
  469. ((FALSEP (CADR X)
  470. FALSE-LST)
  471. (TAUTOLOGYP (CADDDR X)
  472. TRUE-LST FALSE-LST))
  473. (T (AND (TAUTOLOGYP (CADDR X)
  474. (CONS (CADR X)
  475. TRUE-LST)
  476. FALSE-LST)
  477. (TAUTOLOGYP (CADDDR X)
  478. TRUE-LST
  479. (CONS (CADR X)
  480. FALSE-LST))))))
  481. (T NIL)))
  482. (DE TAUTP (X)
  483. (TAUTOLOGYP (REWRITE X)
  484. NIL NIL))
  485. (DE TEST NIL
  486. (PROG (TM1 TM2 ANS TERM)
  487. (SETQ TM1 (PTIME))
  488. (SETQ TERM (APPLY-SUBST '((X F (PLUS (PLUS A B)
  489. (PLUS C (ZERO))))
  490. (Y F (TIMES (TIMES A B)
  491. (PLUS C D)))
  492. (Z F (REVERSE (APPEND (APPEND A B)
  493. (NIL))))
  494. (U EQUAL (PLUS A B)
  495. (DIFFERENCE X Y))
  496. (W LESSP (REMAINDER A B)
  497. (MEMBER A (LENGTH B))))
  498. '(IMPLIES (AND (IMPLIES X Y)
  499. (AND (IMPLIES Y Z)
  500. (AND (IMPLIES Z U)
  501. (IMPLIES U W))))
  502. (IMPLIES X W))))
  503. (SETQ ANS (TAUTP TERM))
  504. (SETQ TM2 (PTIME))
  505. (RETURN (LIST ANS (DIFFERENCE (CAR TM2)
  506. (CAR TM1))
  507. (DIFFERENCE (CDR TM2)
  508. (CDR TM1))))))
  509. (DE TRANS-OF-IMPLIES (N)
  510. (LIST 'IMPLIES
  511. (TRANS-OF-IMPLIES1 N)
  512. (LIST 'IMPLIES
  513. 0 N)))
  514. (DE TRANS-OF-IMPLIES1 (N)
  515. (COND ((EQUAL N 1)
  516. (LIST 'IMPLIES
  517. 0 1))
  518. (T (LIST 'AND
  519. (LIST 'IMPLIES
  520. (SUB1 N)
  521. N)
  522. (TRANS-OF-IMPLIES1 (SUB1 N))))))
  523. (DE TRUEP (X LST)
  524. (OR (EQUAL X '(T))
  525. (MEMBER X LST)))