dvfsf.red 12 KB

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