ofsfbnf.red 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. % ----------------------------------------------------------------------
  2. % $Id: ofsfbnf.red,v 1.9 2003/06/11 08:46:55 dolzmann Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-2003 A. Dolzmann, A. Seidl, and T. Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: ofsfbnf.red,v $
  7. % Revision 1.9 2003/06/11 08:46:55 dolzmann
  8. % Implemented black boxes rl_qssimpl and rl_qssiadd.
  9. %
  10. % Revision 1.8 2003/06/04 06:10:22 dolzmann
  11. % Added black box implementation ofsf_qssusuat.
  12. %
  13. % Revision 1.7 2003/06/03 16:10:39 dolzmann
  14. % Added blackbox implementations for rl_qssubsumep, rl_qstrycons, and
  15. % rl_qssubat.
  16. %
  17. % Revision 1.6 2003/05/27 08:19:19 dolzmann
  18. % Changed wrong log messages.
  19. %
  20. % Revision 1.5 2003/05/27 08:17:42 dolzmann
  21. % Added pseudo implementation of black box cl_qscsa.
  22. %
  23. % Revision 1.4 1999/03/23 07:41:37 dolzmann
  24. % Changed copyright information.
  25. %
  26. % Revision 1.3 1999/03/21 13:38:04 dolzmann
  27. % Removed procedure acfsf_bnfsimpl which was identical to cl_bnfsimpl.
  28. %
  29. % Revision 1.2 1996/10/07 12:03:22 sturm
  30. % Added fluids for CVS and copyright information.
  31. %
  32. % Revision 1.1 1996/03/22 12:14:02 sturm
  33. % Moved and split.
  34. %
  35. % ----------------------------------------------------------------------
  36. lisp <<
  37. fluid '(ofsf_bnf_rcsid!* ofsf_bnf_copyright!*);
  38. ofsf_bnf_rcsid!* := "$Id: ofsfbnf.red,v 1.9 2003/06/11 08:46:55 dolzmann Exp $";
  39. ofsf_bnf_copyright!* :=
  40. "Copyright (c) 1995-2003 by A. Dolzmann, A. Seidl, and T. Sturm"
  41. >>;
  42. module ofsfbnf;
  43. % Ordered field standard form boolean normal forms. Submodule of [ofsf].
  44. procedure ofsf_dnf(f);
  45. % Ordered field standard form conjunctive normal form. [f] is a
  46. % formula. Returns a DNF of [f].
  47. if !*rlbnfsac then
  48. (cl_dnf f) where !*rlsiso=T
  49. else
  50. cl_dnf f;
  51. procedure ofsf_cnf(f);
  52. % Ordered field standard form conjunctive normal form. [f] is a
  53. % formula. Returns a CNF of [f].
  54. if !*rlbnfsac then
  55. (cl_cnf f) where !*rlsiso=T
  56. else
  57. cl_cnf f;
  58. procedure ofsf_subsumption(l1,l2,gor);
  59. % Ordered field standard form subsume. [l1] and [l2] are lists of
  60. % atomic formulas. Returns one of [imp], [rep], [nil].
  61. if gor eq 'or then (
  62. if ofsf_subsumep!-and(l1,l2) then
  63. 'keep2
  64. else if ofsf_subsumep!-and(l2,l1) then
  65. 'keep1
  66. ) else % [gor eq 'and]
  67. if ofsf_subsumep!-or(l1,l2) then
  68. 'keep1
  69. else if ofsf_subsumep!-or(l2,l1) then
  70. 'keep2;
  71. procedure ofsf_subsumep!-and(l1,l2);
  72. % Ordered field standard form subsume [and] case. [l1] and [l2] are
  73. % lists of atomic formulas.
  74. begin scalar a;
  75. while l2 do <<
  76. a := car l2;
  77. l2 := cdr l2;
  78. if cl_simpl(a,l1,-1) neq 'true then a := l2 := nil
  79. >>;
  80. return a
  81. end;
  82. procedure ofsf_subsumep!-or(l1,l2);
  83. % Ordered field standard form subsume [or] case. [l1] and [l2] are
  84. % lists of atomic formulas.
  85. begin scalar a;
  86. while l1 do <<
  87. a := car l1;
  88. l1 := cdr l1;
  89. if cl_simpl(rl_smkn('or,l2),{a},-1) neq 'true then a := l1 := nil
  90. >>;
  91. return a
  92. end;
  93. procedure ofsf_sacatlp(a,l);
  94. % Ordered field standard form subsume and cut atomic formula list
  95. % predicate. [a] is an atomic formula; [l] is a list of atomic
  96. % formulas. [T] is returned if a subsumption or cut beween [a] and
  97. % an element of [l] is possible.
  98. not ((ofsf_arg2l a neq ofsf_arg2l w) and ordp(ofsf_arg2l a,ofsf_arg2l w))
  99. where w=car l;
  100. procedure ofsf_sacat(a1,a2,gor);
  101. % Ordered field standard form subsume and cut atomic formula. [a1]
  102. % and [a2] are atomic formulas; [gor] is one of [or], [and].
  103. % Returns [nil], ['keep], ['keep2], ['keep1], ['drop], or an atomic
  104. % formula. If [nil] is returned then neither a cut nor a
  105. % subsumption can be applied, if [keep] is returned then the atomic
  106. % formuas are identical, in the case of [keep1] or [keep2] the
  107. % respective atomic formula must be kept but the other can be
  108. % dropped. If an atomic formula $a$ is returned then it is the
  109. % result of the cut beween [a1] and [a2], if ['drop] is returned, a
  110. % cut with result ['true] or ['false] can be performed.
  111. begin scalar w;
  112. if ofsf_arg2l a1 neq ofsf_arg2l a2 then return nil;
  113. w := ofsf_sacrel(ofsf_op a1, ofsf_op a2,gor);
  114. if w memq '(drop keep keep1 keep2) then return w;
  115. return ofsf_0mk2(w,ofsf_arg2l a1)
  116. end;
  117. procedure ofsf_sacrel(r1,r2,gor);
  118. % Ordered field standard form subsume and cut relation. [r1] and
  119. % [r2] are relations; [gor] is one of [or], [and]. Returns ['keep],
  120. % ['keep2], ['keep1], ['drop], or a relation. [r1] and [r2] are
  121. % considered as relations of atomic formulas $[r1](t,0)$ and
  122. % $[r2](t,0)$. If [keep] is returned then the atomic formulas are
  123. % identical, in the case of [keep1] or [keep2] the respective
  124. % atomic formula must be kept but the other can be dropped, if a
  125. % relation $\rho$ is returned a cut with result $t\rho 0$ can be
  126. % performed, where $t$ is the left hand side of [a1] and [a2], if
  127. % ['drop] is returned, a cut with result ['true] or ['false] can be
  128. % performed.
  129. if gor eq 'or then
  130. ofsf_sacrel!-or(r1,r2)
  131. else
  132. ofsf_sacrel!-and(r1,r2);
  133. procedure ofsf_sacrel!-or(r1,r2);
  134. % Ordered field standard form subsume and cut relation or. [r1] and
  135. % [r2] are relations. ['keep], ['keep2], ['keep1], ['drop], or a
  136. % relation is returned. [r1] and [r2] are considered as relations
  137. % of atomic formulas $[r1](t,0)$ and $[r2](t,0)$. If [keep] is
  138. % returned then the atomic formulas are identical, in the case of
  139. % [keep1] or [keep2] the respective atomic formula must be kept but
  140. % the other can be dropped, if a relation $\rho$ is returned a cut
  141. % with result $t\rho 0$ can be performed, where $t$ is the left
  142. % hand side of [a1] and [a2], if ['drop] is returned a cut with
  143. % result ['true] can be performed.
  144. begin scalar w;
  145. w:= '( (lessp . ( (lessp . keep) (leq . keep1) (equal . leq)
  146. (neq . keep1) (geq . drop) (greaterp . neq)))
  147. (leq . ( (lessp . keep2) (leq . keep) (equal . keep2)
  148. (neq . drop) (geq . drop) (greaterp . drop)))
  149. (equal . ( (lessp . leq) (leq . keep1) (equal . keep)
  150. (neq . drop) (geq . keep1) (greaterp . geq)))
  151. (neq . ( (lessp . keep2) (leq . drop) (equal . drop)
  152. (neq . keep) (geq . drop) (greaterp . keep2)))
  153. (geq . ( (lessp . drop) (leq . drop) (equal . keep2)
  154. (neq . drop) (geq . keep) (greaterp . keep2)))
  155. (greaterp . ( (lessp . neq) (leq . drop) (equal . geq)
  156. (neq . keep1) (geq . keep1) (greaterp . keep))));
  157. return cdr atsoc(r1,cdr atsoc(r2,w));
  158. end;
  159. procedure ofsf_sacrel!-and(r1,r2);
  160. % Ordered field standard form subsume and cut relation and. [r1] and
  161. % [r2] are relations. ['keep], ['keep2], ['keep1], ['drop], or a
  162. % relation is returned. [r1] and [r2] are considered as relations
  163. % of atomic formulas $[r1](t,0)$ and $[r2](t,0)$. If [keep] is
  164. % returned then the atomic formulas are identical, in the case of
  165. % [keep1] or [keep2] the respective atomic formula must be kept but
  166. % the other can be dropped, if a relation $\rho$ is returned a cut
  167. % with result $t\rho 0$ can be performed, where $t$ is the left
  168. % hand side of [a1] and [a2], if ['drop] is returned a cut with
  169. % result ['false] can be performed.
  170. begin scalar w;
  171. w:= '( (lessp . ( (lessp . keep) (leq . keep2) (equal . drop)
  172. (neq . keep2) (geq . drop) (greaterp . drop)))
  173. (leq . ( (lessp . keep1) (leq . keep) (equal . keep1)
  174. (neq . lessp) (geq . equal) (greaterp . drop)))
  175. (equal . ( (lessp . drop) (leq . keep2) (equal . keep)
  176. (neq . drop) (geq . keep2) (greaterp . drop)))
  177. (neq . ( (lessp . keep1) (leq . lessp) (equal . drop)
  178. (neq . keep) (geq . greaterp) (greaterp . keep1)))
  179. (geq . ( (lessp . drop) (leq . equal) (equal . keep1)
  180. (neq . greaterp) (geq . keep) (greaterp . keep1)))
  181. (greaterp . ( (lessp . drop) (leq . drop) (equal . drop)
  182. (neq . keep2) (geq . keep2) (greaterp . keep))));
  183. return cdr atsoc(r1,cdr atsoc(r2,w))
  184. end;
  185. % ----------------------------------------------------------------------
  186. % Simplification of Boolean normal forms in the style of W. V. Quine.
  187. % ----------------------------------------------------------------------
  188. procedure ofsf_qssubat(pl,a);
  189. begin scalar w,r;
  190. w := ofsf_qssubatfind(pl,a);
  191. if not w then
  192. return a;
  193. r := ofsf_qssubatrel(ofsf_op w,ofsf_op a);
  194. return if rl_tvalp r then
  195. r
  196. else
  197. ofsf_0mk2(r,ofsf_arg2l a)
  198. end;
  199. procedure ofsf_qssubatfind(pl,a);
  200. begin scalar r,la;
  201. la := ofsf_arg2l a;
  202. while pl do <<
  203. if ofsf_arg2l car pl = la then <<
  204. r := car pl;
  205. pl := nil
  206. >> else
  207. pl := cdr pl
  208. >>;
  209. return r
  210. end;
  211. % TODO: Reuse tables of ofsfsism
  212. procedure ofsf_qssubatrel(r1,r2);
  213. begin scalar w;
  214. % Printen mit: for each x in w do << for each y in cdr x do <<
  215. % prin2 cdr y; prin2 " " >>; prin2t ""; >>;
  216. w:= '( (lessp . ( (lessp . true) (leq . true) (equal . false)
  217. (neq . true) (geq . false) (greaterp . false)))
  218. (leq . ( (lessp . neq) (leq . true) (equal . geq)
  219. (neq . neq) (geq . geq) (greaterp . false)))
  220. (equal . ( (lessp . false) (leq . true) (equal . true)
  221. (neq . false) (geq . true) (greaterp . false)))
  222. (neq . ( (lessp . leq) (leq . leq) (equal . false)
  223. (neq . true) (geq . geq) (greaterp . geq)))
  224. (geq . ( (lessp . false) (leq . leq) (equal . leq)
  225. (neq . neq) (geq . true) (greaterp . neq)))
  226. (greaterp . ( (lessp . false) (leq . false) (equal . false)
  227. (neq . true) (geq . true) (greaterp . true))));
  228. return cdr atsoc(r2,cdr atsoc(r1,w))
  229. end;
  230. procedure ofsf_qstrycons(a,c1,c2,op);
  231. % quine simplification try consensus. [a] is an atomic formula,
  232. % [c1] and [c2] are clauses, op is one of ['and], ['or]. Returns
  233. % [T], [nil] or [break]. [c1] contains [a].
  234. begin scalar r,cc1,cc2,w;
  235. w := ofsf_qstrycons!-find(a,c2);
  236. if null w then
  237. return nil;
  238. r := ofsf_qstrycons!-or(ofsf_op a,ofsf_op w);
  239. if null r or r eq 'false then
  240. return nil;
  241. cc1 := delete(a,c1); % Copy... % TODO: delq or delete?
  242. cc2 := delete(w,c2); % Copy... % TODO: delq or delete?
  243. w := append(cc1,cc2); % TODO: nconc
  244. if r neq 'true then
  245. w := ofsf_0mk2(r,ofsf_arg2l a) . w;
  246. w := cl_qssimplc(w,nil,op); % TODO: CNF
  247. if w eq 'false then
  248. return nil;
  249. if w eq 'true then
  250. return 'break;
  251. %% prin2t "Konsens von";
  252. %% mathprint rl_prepfof rl_smkn('and,c1);
  253. %% prin2t "Mit";
  254. %% mathprint rl_prepfof rl_smkn('and,c2);
  255. %% prin2t "Ueber";
  256. %% mathprint rl_prepfof a;
  257. %% prin2t "Ergibt";
  258. %% mathprint rl_prepfof rl_smkn('and,w);
  259. return w
  260. end;
  261. procedure ofsf_qstrycons!-or(r1,r2);
  262. begin scalar w;
  263. w := ofsf_qsflip ofsf_smeqtable(ofsf_qsflip r1,ofsf_qsflip r2);
  264. return if w eq r1 or w eq r2 then nil else w
  265. end;
  266. procedure ofsf_qsflip(r);
  267. if rl_tvalp r then
  268. cl_flip r
  269. else
  270. ofsf_lnegrel r;
  271. % (TODO) REMARK: Letters occurs only once.
  272. procedure ofsf_qstrycons!-find(a,c2);
  273. begin scalar r,la;
  274. la := ofsf_arg2l a;
  275. while c2 do <<
  276. if ofsf_arg2l car c2 = la then <<
  277. r := car c2;
  278. c2 := nil
  279. >> else
  280. c2 := cdr c2;
  281. >>;
  282. return r
  283. end;
  284. procedure ofsf_qssusuat(a1,a2,op);
  285. ofsf_arg2l a1 = ofsf_arg2l a2 and ofsf_qssusutab(ofsf_op a1,ofsf_op a2);
  286. % TODO: Abbrechen bei offensichtlichem widerspruch
  287. procedure ofsf_qssusutab(r1,r2);
  288. begin scalar w;
  289. % Printen mit: for each x in w do << for each y in cdr x do <<
  290. % prin2 cdr y; prin2 " " >>; prin2t ""; >>;
  291. w:= '( (lessp . ( (lessp . T) (leq . T) (equal . nil)
  292. (neq . T) (geq . nil) (greaterp . nil)))
  293. (leq . ( (lessp . nil) (leq . T) (equal . nil)
  294. (neq . nil) (geq . nil) (greaterp . nil)))
  295. (equal . ( (lessp . nil) (leq . T) (equal . T)
  296. (neq . nil) (geq . T) (greaterp . nil)))
  297. (neq . ( (lessp . nil) (leq . nil) (equal . nil)
  298. (neq . T) (geq . nil) (greaterp . nil)))
  299. (geq . ( (lessp . nil) (leq . nil) (equal . nil)
  300. (neq . nil) (geq . T) (greaterp . nil)))
  301. (greaterp . ( (lessp . nil) (leq . nil) (equal . nil)
  302. (neq . T) (geq . T) (greaterp . T))));
  303. return cdr atsoc(r2,cdr atsoc(r1,w))
  304. end;
  305. procedure ofsf_qssiadd(a,c,theo);
  306. begin scalar w;
  307. w := ofsf_qssifind(a,c);
  308. if null w then
  309. return a . c;
  310. c := delq(w,c);
  311. w := ofsf_qssibin(a,w);
  312. return if rl_tvalp w then
  313. w
  314. else
  315. w . c
  316. end;
  317. procedure ofsf_qssibin(a1,a2);
  318. begin scalar w;
  319. w := ofsf_qssirel(ofsf_op a1,ofsf_op a2);
  320. if rl_tvalp w then
  321. return w;
  322. return ofsf_0mk2(w,ofsf_arg2l a1);
  323. end;
  324. procedure ofsf_qssifind(a,c);
  325. begin scalar r,la;
  326. la := ofsf_arg2l a;
  327. while c do <<
  328. if ofsf_arg2l car c = la then <<
  329. r := car c;
  330. c := nil
  331. >> else
  332. c := cdr c
  333. >>;
  334. return r
  335. end;
  336. procedure ofsf_qssirel(r1,r2);
  337. begin scalar w;
  338. % Printen mit: for each x in w do << for each y in cdr x do <<
  339. % prin2 cdr y; prin2 " " >>; prin2t ""; >>;
  340. w:= '( (lessp . ( (lessp . lessp) (leq . lessp) (equal . false)
  341. (neq . lessp) (geq . false) (greaterp . false)))
  342. (leq . ( (lessp . lessp) (leq . leq) (equal . equal)
  343. (neq . lessp) (geq . equal) (greaterp . false)))
  344. (equal . ( (lessp . false) (leq . equal) (equal . equal)
  345. (neq . false) (geq . equal) (greaterp . false)))
  346. (neq . ( (lessp . lessp) (leq . lessp) (equal . false)
  347. (neq . neq) (geq . greaterp) (greaterp . greaterp)))
  348. (geq . ( (lessp . false) (leq . equal) (equal . equal)
  349. (neq . greaterp) (geq . geq) (greaterp . greaterp)))
  350. (greaterp . ( (lessp . false) (leq . false) (equal . false)
  351. (neq . greaterp) (geq . greaterp) (greaterp . greaterp)
  352. )));
  353. return cdr atsoc(r2,cdr atsoc(r1,w))
  354. end;
  355. endmodule; % [ofsfbnf]
  356. end; % of file