acfsfqe.red 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. % ----------------------------------------------------------------------
  2. % $Id: acfsfqe.red,v 1.10 1999/04/12 09:25:59 sturm Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: acfsfqe.red,v $
  7. % Revision 1.10 1999/04/12 09:25:59 sturm
  8. % Updated comments for exported procedures.
  9. %
  10. % Revision 1.9 1999/04/11 11:35:30 dolzmann
  11. % Use the new standard form interface cgb_cgbf which provides also a
  12. % wrapper to the gb package.
  13. %
  14. % Revision 1.8 1999/04/11 09:53:24 dolzmann
  15. % Adapted the procedure acfsf_qeblk2 to the new SF interface of the cgb
  16. % package.
  17. % Procedure acfsf_qefl uses dip's instead of vdp's.
  18. %
  19. % Revision 1.7 1999/04/04 19:03:23 sturm
  20. % Removed acfsf_cgbf and use new interface cgb_cgbf provided by cgb.
  21. % Encapsulated sfto_groebnerf call into torder local setting.
  22. %
  23. % Revision 1.6 1999/03/23 08:21:01 dolzmann
  24. % Changed copyright information.
  25. % Corrected comments for extracting with exc.
  26. %
  27. % Revision 1.5 1999/03/21 13:33:45 dolzmann
  28. % Added implementation of the service rlthsimpl.
  29. % Corrected comments.
  30. %
  31. % Revision 1.4 1997/11/14 05:37:25 dolzmann
  32. % Fixed a bug acfsf_qe1.
  33. %
  34. % Revision 1.3 1997/10/02 13:49:51 dolzmann
  35. % In procedure acfsf_qe1: Remove atomic formulas containing bound variables
  36. % from the theory.
  37. %
  38. % Revision 1.2 1997/10/02 13:14:41 sturm
  39. % The CGB switches have been renamed from gcgb... to cgb...
  40. %
  41. % Revision 1.1 1997/10/01 11:13:06 dolzmann
  42. % Initial check-in.
  43. %
  44. % ----------------------------------------------------------------------
  45. lisp <<
  46. fluid '(acfsf_qe_rcsid!* acfsf_qe_copyright!*);
  47. acfsf_qe_rcsid!* :=
  48. "$Id: acfsfqe.red,v 1.10 1999/04/12 09:25:59 sturm Exp $";
  49. acfsf_qe_copyright!* := "Copyright (c) 1995-1999 A. Dolzmann and T. Sturm"
  50. >>;
  51. module acfsfqe;
  52. % Algebraically closed field standard form quantifier elimination.
  53. % Submodule of [acfsf].
  54. procedure acfsf_gqe(f,theo,xbvl);
  55. % Algebraically closed field generic quantifier elimination. [f] is
  56. % a formula; [theo] is a theory; [xbvl] is a list of variables.
  57. begin scalar !*cgbgen,!*cgbreal;
  58. !*cgbgen := T;
  59. return acfsf_qe1(f,theo,xbvl)
  60. end;
  61. procedure acfsf_qe(f,theo);
  62. % Algebraically closed field quantifier elimination. [f] is a
  63. % formula; [theo] is a theory. Returns a quantifier-free formula
  64. % equivalent to [f] wrt. [theo].
  65. begin scalar !*cgbgen,!*cgbreal;
  66. !*cgbgen := nil;
  67. return acfsf_qe1(f,theo,nil)
  68. end;
  69. procedure acfsf_qe1(f,theo,xbvl);
  70. % Algebraically closed field standard form quantifier elimination.
  71. % [f] is a formula; [theo] is a theory; [xbvl] is a list of
  72. % variables. Returns a formula equivalent to [f].
  73. begin scalar w,qblkl,qff,bvl;
  74. f := rl_simpl(rl_pnf f,theo,-1);
  75. w := cl_splt f;
  76. qblkl := car w;
  77. if null qblkl then
  78. return f;
  79. qff := cadr w;
  80. bvl := caddr w;
  81. theo := for each atf in theo join
  82. if null intersection(rl_varlat atf,bvl) then {atf};
  83. xbvl := nconc(bvl,xbvl);
  84. if !*rlqegen then
  85. if cdr qblkl then
  86. rederr "acfsf_qe: gqe supported only for one block of quantifiers"
  87. else if xbvl then
  88. rederr "acfsf_qe: does not accept a xbvl";
  89. for each qblk in qblkl do
  90. qff := acfsf_qeblk(qblk,qff,theo,xbvl);
  91. return qff
  92. end;
  93. procedure acfsf_qeblk(qblk,f,theo,bvl);
  94. % Algebraically closed field standard form quantifier elimination.
  95. % [qblk] is a QBLK; [f] is a quantifier-free formula; [theo] is a
  96. % theory; [bvl] is a list of variables. Returns a formula
  97. % equivalent to [f].
  98. if car qblk eq 'ex then
  99. acfsf_qeblk1(cdr qblk,f,theo,bvl)
  100. else
  101. cl_nnfnot acfsf_qeblk1(cdr qblk,cl_nnfnot f,theo,bvl);
  102. procedure acfsf_qeblk1(vl,f,theo,bvl);
  103. % Algebraically closed field standard form quantifier elimination.
  104. % [vl] is a list of variables; [f] is a conjunction of atomic
  105. % formulas, an atomic formula or a truth value; [theo] is a theory;
  106. % [bvl] is a list of variables. Returns a formula.
  107. begin scalar w,fl;
  108. f := rl_dnf f;
  109. fl := if rl_op f eq 'or then rl_argn f else {f};
  110. w := for each c in fl collect
  111. acfsf_qeblk2(vl,c,theo,bvl);
  112. return rl_simpl(rl_smkn('or,reversip w),theo,-1)
  113. end;
  114. procedure acfsf_qeblk2(vl,f,theo,bvl);
  115. % Algebraically closed field standard form quantifier elimination.
  116. % [qblkl] is a list of QBLK's; [f] is a conjunction of atomic
  117. % formulas, an atomic formula, or a truth value; [theo] is a
  118. % theory; [bvl] is a list of variables. Returns a formula which is
  119. % equivalent to ex(vl,f) wrt. [theo].
  120. begin scalar w,atl,eqtl,itheo,cgb;
  121. if rl_tvalp f then
  122. return f;
  123. atl := cl_atl1 f;
  124. w := acfsf_spltcj(atl,vl);
  125. atl := car w;
  126. itheo := cdr w;
  127. w := acfsf_eqtl atl;
  128. eqtl := car w;
  129. vl := nconc(cdr w,vl);
  130. cgb := cgb_cgbf(eqtl,vl,'revgradlex,nil) where !*gbverbose=nil;
  131. return rl_smkn('and,acfsf_qefl(cgb,vl) . itheo)
  132. end;
  133. procedure acfsf_spltcj(atl,vl);
  134. % Algebraically closed field standard form quantifier elimination
  135. % split conjunction. [atl] is a list of atomic formulas considered
  136. % conjunctive; [vl] is a list of variables. Returns a pair $(\alpha
  137. % . \beta)$, where $\alpha$ and $\beta$ are list of atomic
  138. % formulas. The union of $\alpha$ and $beta$ is equal to [atl]. No
  139. % variables from [vl] occurs in the atomic formulas in $\beta$.
  140. begin scalar natl,itheo;
  141. for each x in atl do
  142. if intersection(acfsf_varlat x,vl) then
  143. natl := x . natl
  144. else
  145. itheo := x . itheo;
  146. return natl . itheo
  147. end;
  148. procedure acfsf_eqtl(atl);
  149. % Algebraically closed field standard form equation term list.
  150. % [atl] is a list of atomic formulas. Returns a pair $(\lambda .
  151. % \tau)$, where $\lambda$ is a list of terms considered as
  152. % equations and $\tau$ is a list of variables. $\bigwedge([atl])$
  153. % is equivalent to $\exists(\tau,\lambda)$.
  154. begin scalar eqtl,neqtl,w;
  155. for each at in atl do
  156. if acfsf_op at eq 'equal then
  157. eqtl := acfsf_arg2l at . eqtl
  158. else
  159. neqtl := acfsf_arg2l at . neqtl;
  160. w := acfsf_rmneqtl neqtl;
  161. eqtl := nconc(car w,eqtl);
  162. return eqtl . cdr w
  163. end;
  164. procedure acfsf_rmneqtl(neqtl);
  165. % Algebraically closed field standard form remove neq term list.
  166. % [neqtl] is a list of terms considered as inequalities. Returns a
  167. % pair $(\lambda . \tau)$, where $\lambda$ is a list of terms
  168. % considered as equations and $\tau$ is a list of variables.
  169. % $\bigwedge([neqtl])$ is equivalent to $\exists(\tau,\lambda)$.
  170. begin scalar p,v;
  171. if null neqtl then
  172. return nil . nil;
  173. p := 1;
  174. for each u in neqtl do
  175. p := multf(p,u);
  176. v := acfsf_tagvar();
  177. p := addf(multf(p,numr simp v),negf 1);
  178. return {p} . {v}
  179. end;
  180. procedure acfsf_tagvar();
  181. % Algebraically closed field standard form tag variable. Returns a
  182. % tag variable.
  183. intern gensym();
  184. procedure acfsf_qefl(ul,vl);
  185. % Algebraically closed field standard form quantifier elimination
  186. % formula from form-list. [ul] is a list of SF's; [vl] is a list of
  187. % variables. Returns a quantifier-free formula.
  188. begin scalar fl,oenv;
  189. if null ul then return 'true;
  190. oenv := dip_init(vl,'revgradlex,nil);
  191. fl := for each u in ul collect
  192. acfsf_qefl1 dip_f2dip u;
  193. dip_cleanup(oenv);
  194. return rl_smkn('and,fl)
  195. end;
  196. procedure acfsf_qefl1(p);
  197. % Algebraically closed field standard form quantifier elimination
  198. % formula from form subroutine. [p] is a DIP. Returns a
  199. % quantifier-free formula.
  200. begin scalar p,fl,cl,lev,lc;
  201. while p do <<
  202. cl := dip_lbc p . cl;
  203. lev := dip_evlmon p;
  204. p := dip_mred p;
  205. >>;
  206. if ev_zero!? lev then <<
  207. lc := car cl;
  208. cl := cdr cl
  209. >> else
  210. lc := simp 0;
  211. fl := for each c in cl collect
  212. acfsf_0mk2('neq,acfsf_bc2f c);
  213. fl := acfsf_0mk2('equal,acfsf_bc2f lc) . fl;
  214. return rl_smkn('or,fl)
  215. end;
  216. procedure acfsf_bc2f(c);
  217. % Algebraically closed field standard form base coefficient to
  218. % form. [c] is a base coefficient as defined in dipoly. Returns a
  219. % SF.
  220. numr bc_2sq c;
  221. procedure acfsf_thsimpl(atl);
  222. % Algebraically closed field theory simplification. [atl] is a
  223. % theory. Returns an equivalent theory. The returned theory is
  224. % simpler than the original one.
  225. begin scalar !*rlsiexpla,!*rlsipo;
  226. !*rlsiexpla := T;
  227. return sort(acfsf_thregen cl_simpl(rl_smkn('and,atl),nil,-1),'rl_ordatp)
  228. end;
  229. procedure acfsf_thregen(f);
  230. % Algebraically closed field standard form re-generate theory. [f]
  231. % is a formula. Returns a possibly empty list of atomic formulas
  232. % equivalent to [f] or the list [{'false}] if [f] is recognized as
  233. % a contradiction.
  234. begin scalar op;
  235. op := rl_op f;
  236. if op = 'and then
  237. return for each x in rl_argn f collect acfsf_thregen!-or x;
  238. if op = 'or then
  239. return {acfsf_thregen!-or f};
  240. if op = 'true then
  241. return nil;
  242. if op = 'false then
  243. {'false};
  244. % [f] is atomic.
  245. return {f}
  246. end;
  247. procedure acfsf_thregen!-or(f);
  248. % Algebraically closed field standard form re-generate theory
  249. % disjunction case. [f] is a disjunction of equations. Returns an
  250. % equation equivalent to [f].
  251. begin scalar w;
  252. if cl_atfp f then
  253. return f;
  254. w := numr simp 1;
  255. for each equ in rl_argn f do <<
  256. if rl_op equ neq 'equal then
  257. rederr "Bug in acfsf_thregen!-or";
  258. w := multf(w,rl_arg2l equ)
  259. >>;
  260. return acfsf_0mk2('equal,w)
  261. end;
  262. endmodule; % [acfsfqe]
  263. end; % of file