dvfsf.red 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. % ----------------------------------------------------------------------
  2. % $Id: dvfsf.red,v 1.16 2002/05/28 13:21:56 sturm Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: dvfsf.red,v $
  7. % Revision 1.16 2002/05/28 13:21:56 sturm
  8. % Added black box rl_fbqe() and corresponding switch rlqefb.
  9. % That is, for ofsf, rlqe uses rlcad in case of failure now.
  10. %
  11. % Revision 1.15 1999/05/06 12:18:37 sturm
  12. % Updated comments for exported procedures.
  13. %
  14. % Revision 1.14 1999/03/23 15:10:45 dolzmann
  15. % Fixed a bug in dvfsf_enter.
  16. %
  17. % Revision 1.13 1999/03/23 08:44:16 dolzmann
  18. % Changed copyright information.
  19. % Added list of exported procedures.
  20. %
  21. % Revision 1.12 1999/03/22 12:37:51 dolzmann
  22. % Adapted procedure dvfsf_enter to the protocol required from the new rl_set.
  23. %
  24. % Revision 1.11 1999/03/21 13:35:40 dolzmann
  25. % Corrected comments.
  26. % Added black box implementation dvfsf_subsumption.
  27. % Use property number!-of!-args instead of num!-of!-args.
  28. % Use new procedure dvfsf_chsimpat instead of dvfsf_chsimpat. The AM
  29. % interface allows now the input of relation chains.
  30. % Fixed a bug in dvfsf_simpat: The AM interface now handles rationals
  31. % correct.
  32. % Added procedure dvfsf_opp.
  33. % Added package dvfsfsism.
  34. % Register dvfsf-code instead of cl-code for smart simplification.
  35. % Added switch rlsusi.
  36. %
  37. % Revision 1.10 1999/03/19 18:34:42 dolzmann
  38. % Added services rl_varl, rl_fvarl, and rl_bvarl.
  39. %
  40. % Revision 1.9 1999/03/19 15:50:31 dolzmann
  41. % Added service rlifacml.
  42. %
  43. % Revision 1.8 1999/03/19 15:20:51 dolzmann
  44. % Added service rl_subfof.
  45. %
  46. % Revision 1.7 1999/03/19 12:17:47 dolzmann
  47. % Added service rlmkcanonic.
  48. %
  49. % Revision 1.6 1999/01/17 16:21:42 dolzmann
  50. % Added services rl_explats, rl_termml, rl_terml, rl_struct, and
  51. % rl_ifstruct.
  52. % Added black boxes rl_termmlat, rl_structat, and rl_ifstructat.
  53. % Added procedure dvfsf_simpterm.
  54. % Removed unused properties simptermfn, mktermfn, and preptermfn from
  55. % context tag.
  56. % Added properties rl_prepterm, and rl_simpterm.
  57. % Added fluid binding for switches rlsiexpl, rlsiexpla, and rlsifac.
  58. % Changed copyright notice.
  59. %
  60. % Revision 1.5 1999/01/10 11:13:03 sturm
  61. % Added black box rl_specelim (cl_specelim).
  62. % Added service rlqea.
  63. %
  64. % Revision 1.4 1997/11/03 15:11:21 sturm
  65. % Added BB implementation dvfsf_a2cdl and services rl_tab, rlitab,
  66. % and rl_atab.
  67. % Turned on BFS for QE by default.
  68. %
  69. % Revision 1.3 1996/09/30 12:38:12 sturm
  70. % Fixed some comments for automatic processing.
  71. %
  72. % Revision 1.2 1996/07/13 11:51:34 dolzmann
  73. % Pakage dvfsf now uses context independent smart simplification facilities
  74. % of cl.
  75. % Removed control of switch rlsism.
  76. % Set servives rl_dnf and rl_cnf to dvfsf_dnf and dvfsf_cnf respectively.
  77. % Package dvfsf now uses cl black box implementations for black boxes
  78. % rl_sacatlp and rl_sacat.
  79. %
  80. % Revision 1.1 1996/07/08 12:15:19 sturm
  81. % Initial check-in.
  82. %
  83. % ----------------------------------------------------------------------
  84. lisp <<
  85. fluid '(dvfsf_rcsid!* dvfsf_copyright!*);
  86. dvfsf_rcsid!* := "$Id: dvfsf.red,v 1.16 2002/05/28 13:21:56 sturm Exp $";
  87. dvfsf_copyright!* := "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  88. >>;
  89. module dvfsf;
  90. % Discretely valued field standard form. Main module. Algorithms on
  91. % first-order formulas over the language of fields together with a
  92. % constant [p] and binary relations [equal], [neq], [div], [sdiv],
  93. % [assoc], and [nassoc]. The terms are SF's.
  94. create!-package('(dvfsf dvfsfsiat dvfsfsism dvfsfqe dvfsfmisc),nil);
  95. load!-package 'cl;
  96. load!-package 'rltools;
  97. exports dvfsf_enter,dvfsf_exit,dvfsf_simpterm,dvfsf_prepat,dvfsf_resimpat,
  98. dvfsf_lengthat,dvfsf_chsimpat,dvfsf_simpat,dvfsf_op,dvfsf_arg2l,dvfsf_arg2r,
  99. dvfsf_argn,dvfsf_mk2,dvfsf_0mk2,dvfsf_mkn,dvfsf_opp,dvfsf_simplat1,
  100. dvfsf_smupdknowl,dvfsf_smrmknowl,dvfsf_smcpknowl,dvfsf_smmkatl,
  101. dvfsf_susirmknowl,dvfsf_varsel,dvfsf_translat,dvfsf_elimset,dvfsf_qesubcq,
  102. dvfsf_qesubq,dvfsf_transform,dvfsf_trygauss,dvfsf_qemkans,
  103. dvfsf_ordatp,dvfsf_varlat,dvfsf_varsubstat,dvfsf_negateat,dvfsf_fctrat,
  104. dvfsf_dnf,dvfsf_cnf,dvfsf_subsumption,dvfsf_a2cdl,dvfsf_subat,dvfsf_subalchk,
  105. dvfsf_eqnrhskernels,dvfsf_structat,dvfsf_ifstructat,dvfsf_termmlat,
  106. dvfsf_explats,dvfsf_mkcanonic;
  107. imports rltools,cl;
  108. fluid '(!*rlverbose dvfsf_p!* !*rlsiexpl !*rlsiexpla !*rlsifac !*rlsusi);
  109. flag('(dvfsf),'rl_package);
  110. % Parameters
  111. put('dvfsf,'rl_params,'(
  112. (rl_smupdknowl!* . dvfsf_smupdknowl)
  113. (rl_smrmknowl!* . dvfsf_smrmknowl)
  114. (rl_smcpknowl!* . dvfsf_smcpknowl)
  115. (rl_smmkatl!* . dvfsf_smmkatl)
  116. (rl_smsimpl!-impl!* . cl_smsimpl!-impl)
  117. (rl_smsimpl!-equiv1!* . cl_smsimpl!-equiv1)
  118. (rl_sacatlp!* . cl_sacatlp)
  119. (rl_sacat!* . cl_sacat)
  120. (rl_ordatp!* . dvfsf_ordatp)
  121. (rl_tordp!* . ordp)
  122. (rl_simplat1!* . dvfsf_simplat1)
  123. (rl_negateat!* . dvfsf_negateat)
  124. (rl_varlat!* . dvfsf_varlat)
  125. (rl_varsubstat!* . dvfsf_varsubstat)
  126. (rl_translat!* . dvfsf_translat)
  127. (rl_transform!* . dvfsf_transform)
  128. (rl_elimset!*. dvfsf_elimset)
  129. (rl_trygauss!* . dvfsf_trygauss)
  130. (rl_subsumption!* . dvfsf_subsumption)
  131. (rl_bnfsimpl!* . cl_bnfsimpl)
  132. (rl_fctrat!* . dvfsf_fctrat)
  133. (rl_varsel!* . dvfsf_varsel)
  134. (rl_a2cdl!* . dvfsf_a2cdl)
  135. (rl_qemkans!* . dvfsf_qemkans)
  136. (rl_termmlat!* . dvfsf_termmlat)
  137. (rl_structat!* . dvfsf_structat)
  138. (rl_ifstructat!* . dvfsf_ifstructat)
  139. (rl_subat!* . dvfsf_subat)
  140. (rl_subalchk!* . dvfsf_subalchk)
  141. (rl_eqnrhskernels!* . dvfsf_eqnrhskernels)
  142. (rl_susipost!* . dvfsf_susipost)
  143. (rl_susitf!* . dvfsf_susitf)
  144. (rl_susibin!* . dvfsf_susibin)
  145. (rl_specelim!* . cl_specelim)
  146. (rl_fbqe!* . cl_fbqe)));
  147. % Switches
  148. put('dvfsf,'rl_cswitches,'(
  149. (rlqeheu . nil)
  150. (rlqedfs . nil)
  151. (rlsusi . T)
  152. ));
  153. % Services
  154. put('dvfsf,'rl_services,'(
  155. (rl_subfof!* . cl_subfof)
  156. (rl_identifyonoff!* . cl_identifyonoff)
  157. (rl_simpl!* . cl_simpl)
  158. (rl_nnf!* . cl_nnf)
  159. (rl_nnfnot!* . cl_nnfnot)
  160. (rl_pnf!* . cl_pnf)
  161. (rl_cnf!* . dvfsf_cnf)
  162. (rl_dnf!* . dvfsf_dnf)
  163. (rl_all!* . cl_all)
  164. (rl_ex!* . cl_ex)
  165. (rl_atnum!* . cl_atnum)
  166. (rl_ifacl!* . cl_ifacl)
  167. (rl_ifacml!* . cl_ifacml)
  168. (rl_matrix!* . cl_matrix)
  169. (rl_apnf!* . cl_apnf)
  170. (rl_atml!* . cl_atml)
  171. (rl_atl!* . cl_atl)
  172. (rl_qe!* . cl_qe)
  173. (rl_qeipo!* . cl_qeipo)
  174. (rl_qews!* . cl_qews)
  175. (rl_qea!* . cl_qea)
  176. (rl_tab!* . cl_tab)
  177. (rl_atab!* . cl_atab)
  178. (rl_termml!* . cl_termml)
  179. (rl_terml!* . cl_terml)
  180. (rl_varl!* . cl_varl)
  181. (rl_fvarl!* . cl_fvarl)
  182. (rl_bvarl!* . cl_bvarl)
  183. (rl_struct!* . cl_struct)
  184. (rl_ifstruct!* . cl_ifstruct)
  185. (rl_explats!* . dvfsf_explats)
  186. (rl_mkcanonic!* . dvfsf_mkcanonic)
  187. (rl_itab!* . cl_itab)));
  188. % Admin
  189. put('dvfsf,'rl_enter,'dvfsf_enter);
  190. put('dvfsf,'rl_exit,'dvfsf_exit);
  191. put('dvfsf,'simpfnname,'dvfsf_simpfn);
  192. put('dvfsf,'rl_prepat,'dvfsf_prepat);
  193. put('dvfsf,'rl_resimpat,'dvfsf_resimpat);
  194. put('dvfsf,'rl_lengthat,'dvfsf_lengthat);
  195. put('dvfsf,'rl_prepterm,'prepf);
  196. put('dvfsf,'rl_simpterm,'dvfsf_simpterm);
  197. algebraic infix equal;
  198. put('equal,'dvfsf_simpfn,'dvfsf_chsimpat);
  199. put('equal,'number!-of!-args,2);
  200. algebraic infix neq;
  201. put('neq,'dvfsf_simpfn,'dvfsf_chsimpat);
  202. put('neq,'number!-of!-args,2);
  203. put('neq,'rtypefn,'quotelog);
  204. newtok '((!< !>) neq);
  205. algebraic infix sdiv;
  206. put('sdiv,'dvfsf_simpfn,'dvfsf_chsimpat);
  207. put('sdiv,'number!-of!-args,2);
  208. put('sdiv,'rtypefn,'quotelog);
  209. precedence sdiv,neq;
  210. newtok '((| |) sdiv);
  211. algebraic infix div;
  212. put('div,'dvfsf_simpfn,'dvfsf_chsimpat);
  213. put('div,'number!-of!-args,2);
  214. put('div,'rtypefn,'quotelog);
  215. precedence div,sdiv;
  216. newtok '((|) div);
  217. algebraic infix assoc;
  218. put('assoc,'dvfsf_simpfn,'dvfsf_chsimpat);
  219. put('assoc,'number!-of!-args,2);
  220. put('assoc,'rtypefn,'quotelog);
  221. precedence assoc,div;
  222. newtok '((~) assoc);
  223. algebraic infix nassoc;
  224. put('nassoc,'dvfsf_simpfn,'dvfsf_chsimpat);
  225. put('nassoc,'number!-of!-args,2);
  226. put('nassoc,'rtypefn,'quotelog);
  227. precedence nassoc,assoc;
  228. newtok '((/ ~) nassoc);
  229. flag('(equal neq sdiv div assoc nassoc),'spaced);
  230. flag('(dvfsf_chsimpat),'full);
  231. procedure dvfsf_enter(argl);
  232. % Discretely valued field enter context. [argl] is either [nil] or
  233. % it evaluates to a list containing an integer $n$ such that $n=0$
  234. % or $|n|$ prime. Returns a pair $(f . l)$; if $f$ is [nil], then
  235. % $l$ contains an error message; if $f$ is non-[nil], then $l$ is
  236. % the new value for the fluid [rl_argl!*]. Modifies the algebraic
  237. % variable [p] and the fluid [dvfsf_p!*]. The argument $n$
  238. % describes the range of considered $p$-adic valuations for
  239. % elimination and simplification. With $n=0$ these functions are
  240. % uniformly correct for all $p$-adic valuations; with $n<0$ they
  241. % are correct for all $p$-adic valuations with $p \leq |n|$. For
  242. % $n>0$ the $n$-adic valuation is selected, and both the algebraic
  243. % variable [p] and the fluid [dvfsf_p!*] are set to $n$; then
  244. % simplification and quantifier elimination are correct only for
  245. % this $n$-adic valuation.
  246. begin scalar n;
  247. n := if argl then reval car argl else 0;
  248. if argl and cdr argl then <<
  249. lprim {"extra",ioto_cplu("argument",cddr argl),"ignored"};
  250. argl := {car argl}
  251. >>;
  252. if not (n=0 or primep n) then
  253. return nil . "dvfsf extra argument must be 0 or prime";
  254. if n <= 0 then <<
  255. lprim "p is being cleared";
  256. clear 'p;
  257. >> else <<
  258. lprim {"p is set to",n};
  259. algebraic(p := n);
  260. >>;
  261. flag('(p),'reserved);
  262. dvfsf_p!* := n;
  263. return T . argl
  264. end;
  265. procedure dvfsf_exit();
  266. % Discretely valued field exit context. No arguments. The return
  267. % value is unspecified. Modified the algebraic variable [p].
  268. <<
  269. remflag('(p),'share);
  270. remflag('(p),'reserved)
  271. >>;
  272. procedure dvfsf_simpterm(u);
  273. % Discretely valued field simp term. [u] is Lisp Prefix. Returns
  274. % the [u] as a DVFSF term.
  275. numr simp u;
  276. procedure dvfsf_prepat(f);
  277. % Discretely valued field prep atomic formula. [f] is a DVFSF
  278. % atomic formula. Returns [f] in Lisp prefix form.
  279. {dvfsf_op f,prepf dvfsf_arg2l f,prepf dvfsf_arg2r f};
  280. procedure dvfsf_resimpat(f);
  281. % Discretely valued field resimp atomic formula. [f] is an DVFSF
  282. % atomic formula. Returns the atomic formula [f] with resimplified
  283. % terms.
  284. dvfsf_mk2(dvfsf_op f,
  285. numr resimp !*f2q dvfsf_arg2l f,numr resimp !*f2q dvfsf_arg2r f);
  286. procedure dvfsf_lengthat(f);
  287. % Discretely valued field length of atomic formula. [f] is an
  288. % atomic formula. Returns a number, the length of [f].
  289. 2;
  290. procedure dvfsf_chsimpat(u);
  291. % Discretely valued field chain simp atomic formula. [u] is the
  292. % Lisp prefix representation of a chain of atomic formulas, i.e.,
  293. % the operators are nested right associatively. Returns a formula,
  294. % which is the corresponding conjunction.
  295. rl_smkn('and,for each x in dvfsf_chsimpat1 u collect dvfsf_simpat x);
  296. procedure dvfsf_chsimpat1(u);
  297. % Discretely valued field chain simp atomic formula subroutine. [u]
  298. % is the Lisp prefix representation of a chain of atomic formulas,
  299. % i.e., the operators are nested right associatively.
  300. begin scalar leftl,rightl,lhs,rhs;
  301. lhs := cadr u;
  302. if pairp lhs and dvfsf_opp car lhs then <<
  303. leftl := dvfsf_chsimpat1 lhs;
  304. lhs := caddr lastcar leftl
  305. >>;
  306. rhs := caddr u;
  307. if pairp rhs and dvfsf_opp car rhs then <<
  308. rightl := dvfsf_chsimpat1 rhs;
  309. rhs := cadr car rightl
  310. >>;
  311. return nconc(leftl,{car u,lhs,rhs} . rightl)
  312. end;
  313. procedure dvfsf_simpat(u);
  314. % Discretely valued field simp atomic formula. [u] is Lisp prefix.
  315. % Returns [u] as an atomic formula.
  316. begin scalar op,lhs,rhs,w;
  317. op := car u;
  318. lhs := simp cadr u;
  319. if not (numberp denr lhs) then
  320. typerr(u,"atomic formula");
  321. rhs := simp caddr u;
  322. if not (numberp denr rhs) then
  323. typerr(u,"atomic formula");
  324. if op memq '(equal neq) then
  325. return dvfsf_0mk2(op,numr subtrsq(lhs,rhs));
  326. w := lcm(denr lhs,denr rhs);
  327. return dvfsf_mk2(op,numr multsq(lhs,!*f2q w),numr multsq(rhs,!*f2q w))
  328. end;
  329. procedure dvfsf_op(atf);
  330. % Discretely valued field operator. [atf] is an atomic formula
  331. % $R(t_1,t_2)$. Returns $R$.
  332. car atf;
  333. procedure dvfsf_arg2l(atf);
  334. % Discretely valued field binary operator left hand side argument.
  335. % [atf] is an atomic formula $R(t_1,t_2)$. Returns $t_1$.
  336. cadr atf;
  337. procedure dvfsf_arg2r(atf);
  338. % Discretely valued field binary operator right hand side argument.
  339. % [atf] is an atomic formula $R(t_1,t_2)$. Returns $t_2$.
  340. caddr atf;
  341. procedure dvfsf_argn(atf);
  342. % Discretely valued field n-ary operator argument list. [atf] is an
  343. % atomic formula $R(t_1,...,t_n)$. Returns the list
  344. % $(t_1,...,t_n)$.
  345. {cadr atf,caddr atf};
  346. procedure dvfsf_mk2(op,lhs,rhs);
  347. % Discretely valued field make atomic formula for binary operator.
  348. % [op] is one of the operators [equal], [neq], [div], [sdiv],
  349. % [assoc], and [nassoc]; [lhs] and [rhs] are terms. Returns the
  350. % atomic formula $[op]([lhs],[rhs])$.
  351. {op,lhs,rhs};
  352. procedure dvfsf_0mk2(op,lhs);
  353. % Discretely valued field make zero right hand atomic formula for
  354. % binary operator. [op] is one of the operators [equal], [neq],
  355. % [div], [sdiv], [assoc], and [nassoc]; [lhs] is a term. Returns
  356. % the atomic formula $[op]([lhs],0)$.
  357. {op,lhs,nil};
  358. procedure dvfsf_mkn(op,argl);
  359. % Discretely valued field make atomic formula for n-ary operator.
  360. % [op] is one of the operators [equal], [neq], [div], [sdiv],
  361. % [assoc], and [nassoc]; [argl] is a list $(t_1,t_2)$ of terms.
  362. % Returns the atomic formula $[op](t_1,t_2)$.
  363. {op,car argl,cadr argl};
  364. procedure dvfsf_opp(op);
  365. % Discretely valued field operator predicate. [op] is an
  366. % S-expression. Returns non-[nil] iff op is a relation.
  367. op memq '(equal neq div sdiv assoc nassoc);
  368. endmodule; % [dvfsf]
  369. end; % of file