cltab.red 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. % ----------------------------------------------------------------------
  2. % $Id: cltab.red,v 1.9 1999/04/13 13:11:03 sturm Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: cltab.red,v $
  7. % Revision 1.9 1999/04/13 13:11:03 sturm
  8. % Updated comments for exported procedures.
  9. %
  10. % Revision 1.8 1999/04/11 10:20:12 sturm
  11. % Added call to rl_nnf in cl_gentheo1 such that non-positive formulas
  12. % are treated as intended by rlgentheo now.
  13. %
  14. % Revision 1.7 1999/03/22 17:08:08 dolzmann
  15. % Changed copyright information.
  16. %
  17. % Revision 1.6 1996/10/07 11:45:58 sturm
  18. % Added fluids for CVS and copyright information.
  19. %
  20. % Revision 1.5 1996/10/01 10:17:26 reiske
  21. % Added verbosity output in cl_atab.
  22. %
  23. % Revision 1.4 1996/09/30 16:57:28 sturm
  24. % Switched to new tableau code.
  25. %
  26. % Revision 1.3 1996/08/01 11:44:59 reiske
  27. % Major changes:
  28. % New implementation of tableau method.
  29. % Added procedure cl_gentheo.
  30. %
  31. % Revision 1.2 1996/07/07 14:34:21 sturm
  32. % Turned some cl calls into service calls.
  33. %
  34. % Revision 1.1 1996/03/22 10:31:34 sturm
  35. % Moved and split.
  36. %
  37. % ----------------------------------------------------------------------
  38. lisp <<
  39. fluid '(cl_tab_rcsid!* cl_tab_copyright!*);
  40. cl_tab_rcsid!* := "$Id: cltab.red,v 1.9 1999/04/13 13:11:03 sturm Exp $";
  41. cl_tab_copyright!* := "(c) 1995-1999 by A. Dolzmann and T. Sturm"
  42. >>;
  43. module cltab;
  44. % Common logic tableau method. Submodule of [cl].
  45. procedure cl_tab(f,cdl);
  46. % Common logic tableau; simplification. [f] is a formula; [cdl] is
  47. % a list of atomic formulas. Returns a formula. The result is a
  48. % case distiction on the atomic formulas in [cdl] in conjunction
  49. % with corresponding specializations of [f].
  50. cl_mktf cl_tab1(f,cdl);
  51. procedure cl_tab1(f,cdl);
  52. % Common logic tableau subroutine. [f] is a formula; [cdl] is a
  53. % list of atomic formulas. Returns a list of consed pairs of $(...,
  54. % (\phi_i . c_i), ...)$, where $c_i$ is in [cdl] and $\phi_i$ is a
  55. % specialization of [f] wrt. $c_i$.
  56. begin scalar w,ff,resl;
  57. for each atf in cdl do <<
  58. ff := rl_simpl(f,{atf},-1);
  59. if ff neq 'inctheo and ff neq 'false then
  60. if (w := assoc(ff,resl)) then
  61. cdr w := rl_simpl(rl_mkn('or,{atf,cdr w}),nil,-1)
  62. else
  63. resl := (ff . atf) . resl
  64. >>;
  65. return resl
  66. end;
  67. procedure cl_mktf(resl);
  68. % Common logic make tableau formula. [resl] is a list of consed
  69. % pairs. Returns a formula. Uses a heuristic approach whether to
  70. % use the simplifier or not. Depends on the facilities of
  71. % [rl_simpl].
  72. begin scalar w,flg;
  73. w := resl;
  74. while w do
  75. if (rl_tvalp caar w) or (cl_atfp caar w) then <<
  76. w := nil;
  77. flg := T
  78. >> else
  79. w := cdr w;
  80. return
  81. if flg then
  82. rl_simpl(rl_mkn('or,for each x in resl collect
  83. rl_mkn('and,{cdr x,car x})),nil,-1)
  84. else
  85. rl_mkn('or,for each x in resl collect
  86. rl_mkn('and,{cdr x,car x}));
  87. end;
  88. procedure cl_atab(f);
  89. % Common logic automatic tableau; simplification. [f] is a formula.
  90. % Returns a simplified equivalent of [f] or [f] itself. The result
  91. % is obtained by trying [cl_tab] with case distictions on the signs
  92. % of terms in [f] as [cdl].
  93. begin scalar w;
  94. w := cl_atab1 f;
  95. return if w then
  96. cl_mktf w
  97. else
  98. f
  99. end;
  100. procedure cl_atab1(f);
  101. % Common logic new automatic tableau subroutine. [f] is a formula.
  102. % Returns [nil] or a resl.
  103. begin scalar cdl,cdll,atnum,atnumold,atnumnf,nresl,resl,dpth;
  104. atnum := cl_atnum f;
  105. atnumold := atnum;
  106. cdll:= rl_a2cdl cl_atml f;
  107. if !*rlverbose then <<
  108. ioto_tprin2t {atnum," = 100%"};
  109. dpth := length cdll
  110. >>;
  111. while cdll do <<
  112. cdl := car cdll;
  113. cdll := cdr cdll;
  114. nresl := cl_tab1(f,cdl);
  115. atnumnf := cl_atnum cl_mktf nresl;
  116. if !*rlverbose then <<
  117. ioto_prin2 {"[",dpth,": ",atnumnf,"] "};
  118. dpth := dpth - 1
  119. >>;
  120. if atnumnf < atnum then <<
  121. resl := nresl;
  122. atnum := atnumnf
  123. >>
  124. >>;
  125. if !*rlverbose then
  126. if atnum < atnumold then
  127. ioto_tprin2t {"Success: ",atnumold," -> ",atnum}
  128. else
  129. ioto_tprin2t {"No success, returning the original formula"};
  130. return resl
  131. end;
  132. procedure cl_itab(f);
  133. % Common logic iterative tableau; simplification. [f] is a formula.
  134. % Returns a simplified equivalent of [f] or [f] itself. The result
  135. % is obtained by iterative application of [cl_atab]. Depends on the
  136. % switch [rltabib]. With [rltabib] on, the iteration is not
  137. % performed on the entire formula but on the single sepcialization
  138. % branches.
  139. if !*rltabib then cl_itab2 f else cl_itab1 f;
  140. procedure cl_itab1(f);
  141. % Common logic iterative tableau subroutine. [f] is a formula.
  142. % The switch [rltabib] is off. Returns a formula.
  143. begin scalar w,res;
  144. w := cl_atab1 f;
  145. while w do <<
  146. res := cl_mktf w;
  147. if !*rlverbose then
  148. ioto_tprin2t {"Recomputing tableau."};
  149. w:= cl_atab1 res
  150. >>;
  151. return res or f
  152. end;
  153. procedure cl_itab2(f);
  154. % Common logic iterative tableau subroutine. [f] is a formula.
  155. % Iterate branchwise. Returns a formula.
  156. begin scalar w;
  157. w := cl_atab1 f;
  158. return if w then
  159. cl_mktf for each res in w collect (cl_itab2 car res) . cdr res
  160. else
  161. f
  162. end;
  163. procedure cl_gentheo(theo,f,bvl);
  164. % Common logic generate theory. [theo] is THEORY; [f] is a
  165. % quantifier-free formula; [bvl] is a list of variables. Returns a
  166. % pair $(\Theta . \phi)$, where $\Theta$ is a THEORY extending
  167. % [theo] by inequalities, and $\phi$ is a formula such that $\Theta
  168. % \models \phi \longleftrightarrow [f]$. The additional assumptions
  169. % in $\Theta$ do not involve variables in [bvl].
  170. begin scalar w;
  171. w := cl_gentheo0(f,bvl);
  172. return rl_thsimpl(union(theo,car w)) . cdr w
  173. end;
  174. procedure cl_gentheo0(f,bvl);
  175. % Generate theory. [f] is a quantifier-free formula; [bvl] is a
  176. % list of variables. Returns a pair $\theta . \phi$ where $\theta$
  177. % is a list of inequations not containing variables from [bvl], and
  178. % $\phi$ is a quantifier-free formula such that $\bigwedge \theta
  179. % \longrightarrow ([f] \longleftrightarrow \phi)$.
  180. begin scalar w,res,theo;
  181. while car (w:=cl_gentheo1(f,bvl)) do <<
  182. res := cdr w;
  183. theo := cdr res . theo;
  184. f := car res
  185. >>;
  186. return theo . f
  187. end;
  188. procedure cl_gentheo1(f,bvl);
  189. % Generate theory subroutine. [f] is a formula; [bvl] is a list of
  190. % variables. Returns a consed pair (flag . res).
  191. begin scalar cdl,result,nres,flag,theo;
  192. result := f;
  193. cdl := rl_getineq(rl_nnf f,bvl);
  194. for each ineq in cdl do <<
  195. nres := rl_simpl(f,{ineq},-1) . ineq;
  196. if not cl_cmpfp(result,car nres) then <<
  197. result := car nres;
  198. theo := cdr nres;
  199. flag := T
  200. >>
  201. >>;
  202. return flag . (result . theo)
  203. end;
  204. procedure cl_cmpfp(f,nf);
  205. % Generate theory compare formulas predicate. [f] and [nf] are
  206. % quantifier-free formulas. Returns a Boolean.
  207. cl_atnum f < cl_atnum nf;
  208. endmodule; % [cltab]
  209. end; % of file