acfsfqe.red 9.8 KB

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