dvfsfmisc.red 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. % ----------------------------------------------------------------------
  2. % $Id: dvfsfmisc.red,v 1.14 1999/04/05 11:23:43 dolzmann Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: dvfsfmisc.red,v $
  7. % Revision 1.14 1999/04/05 11:23:43 dolzmann
  8. % Fixed a bug in dvfsf_mkcanonic.
  9. %
  10. % Revision 1.13 1999/04/01 11:24:59 dolzmann
  11. % Changed comments.
  12. % Fixed a bug in dvfsf_varsubstat.
  13. %
  14. % Revision 1.12 1999/03/24 12:41:51 dolzmann
  15. % Added and reformatted comments.
  16. % Fixed a bug in dvfsf_fctrat: The alist of the left and right hand sides
  17. % are merged instead of concatenated.
  18. %
  19. % Revision 1.11 1999/03/23 08:52:17 dolzmann
  20. % Changed copyright information.
  21. %
  22. % Revision 1.10 1999/03/21 13:35:23 dolzmann
  23. % Added black box implementation dvfsf_subsumption.
  24. %
  25. % Revision 1.9 1999/03/19 18:35:32 dolzmann
  26. % Changed procedure dvfsf_varlat: p is not longer treated as a variable.
  27. %
  28. % Revision 1.8 1999/03/19 15:20:37 dolzmann
  29. % Added procedures dvfsf_subat, dvfsf_subalchk, and dvfsf_eqnrhskernels
  30. % for the CL implementation of the service rl_subfof.
  31. %
  32. % Revision 1.7 1999/03/19 12:17:47 dolzmann
  33. % Added service rlmkcanonic.
  34. %
  35. % Revision 1.6 1999/01/17 16:24:01 dolzmann
  36. % Changed copyright notice.
  37. % Changed semantics of dvfsf_fctrat: Polynomials in p does not belong to
  38. % the content.
  39. % Added black boxes rl_termmlat, rl_structat, and rl_ifstructat.
  40. % Added services rl_explats.
  41. %
  42. % Revision 1.5 1997/11/03 15:11:51 sturm
  43. % Added BB implementation dvfsf_a2cdl.
  44. %
  45. % Revision 1.4 1996/10/07 11:32:06 sturm
  46. % Added fluids for CVS and copyright information.
  47. %
  48. % Revision 1.3 1996/07/15 14:08:09 sturm
  49. % Fixed a bug in dvfsf_negateat.
  50. %
  51. % Revision 1.2 1996/07/13 11:40:36 dolzmann
  52. % Added procedures dvfsf_dnf and dvfsf_cnf for Boolean normal form
  53. % computation with subsumption.
  54. % Removed procedure dvfsf_bnfsimpl.
  55. %
  56. % Revision 1.1 1996/07/08 12:15:22 sturm
  57. % Initial check-in.
  58. %
  59. % ----------------------------------------------------------------------
  60. lisp <<
  61. fluid '(dvfsf_misc_rcsid!* dvfsf_misc_copyright!*);
  62. dvfsf_misc_rcsid!* :=
  63. "$Id: dvfsfmisc.red,v 1.14 1999/04/05 11:23:43 dolzmann Exp $";
  64. dvfsf_misc_copyright!* :=
  65. "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  66. >>;
  67. module dvfsfmisc;
  68. % Discretely valued field standard form miscellaneous. Submodule of [dvfsf].
  69. procedure dvfsf_ordatp(a1,a2);
  70. % Discretely valued field standard form ordering of atomic formulas
  71. % predicate. [a1] and [a2] are atomic formulas. Returns [T] iff
  72. % [a1] is less than or equal to [a2].
  73. begin scalar w1,w2;
  74. w1 := dvfsf_arg2l a1;
  75. w2 := dvfsf_arg2l a2;
  76. if w1 neq w2 then return ordp(w1,w2);
  77. w1 := dvfsf_arg2r a1;
  78. w2 := dvfsf_arg2r a2;
  79. if w1 neq w2 then return ordp(w1,w2);
  80. return dvfsf_ordrelp(dvfsf_op a1,dvfsf_op a2)
  81. end;
  82. procedure dvfsf_ordrelp(r1,r2);
  83. % Discretely valued field standard form ordering of atomic formulas
  84. % predicate. [a1] and [a2] are relations. Returns [T] iff [r1] is
  85. % less than or equal to [r2].
  86. not not (r2 memq (r1 memq '(equal neq div sdiv assoc)));
  87. procedure dvfsf_varlat(atf);
  88. % Discretely valued field standard form atomic formula list of
  89. % variables. [atf] is an atomic formula. Returns the variables
  90. % contained in [atf] as a list. The constant ['p] of our language
  91. % is not considered as an variable.
  92. delqip('p,union(kernels dvfsf_arg2l atf,kernels dvfsf_arg2r atf));
  93. procedure dvfsf_varsubstat(atf,new,old);
  94. % Discretely valued field standard form substitute variable for
  95. % variable in atomic formula. [atf] is an atomic formula; [new] and
  96. % [old] are variables. Returns an atomic formula equivalent to
  97. % [atf] where [old] is substituted with [new].
  98. dvfsf_mk2(dvfsf_op atf,numr subf(dvfsf_arg2l atf,{old . new}),
  99. numr subf(dvfsf_arg2r atf,{old . new}));
  100. procedure dvfsf_negateat(atf);
  101. % Discretely valued field standard form negate atomic formula.
  102. % [atf] is an atomic formula. Returns a quantifier-free positive
  103. % formula that is equivalent to $\lnot [atf]$.
  104. begin scalar op;
  105. op := dvfsf_op atf;
  106. if op eq 'equal then
  107. return dvfsf_mkn('neq,dvfsf_argn atf);
  108. if op eq 'neq then
  109. return dvfsf_mkn('equal,dvfsf_argn atf);
  110. if op eq 'div then
  111. return dvfsf_mk2('sdiv,dvfsf_arg2r atf,dvfsf_arg2l atf);
  112. if op eq 'sdiv then
  113. return dvfsf_mk2('div,dvfsf_arg2r atf,dvfsf_arg2l atf);
  114. if op eq 'assoc then
  115. return dvfsf_mk2('nassoc,dvfsf_arg2l atf,dvfsf_arg2r atf);
  116. if op eq 'nassoc then
  117. return dvfsf_mk2('assoc,dvfsf_arg2l atf,dvfsf_arg2r atf);
  118. end;
  119. procedure dvfsf_fctrat(at);
  120. % Discretely valued field standard form factorize atomic formula.
  121. % [at] is an atomic formula $l \mathrel{\varrho} r$. Returns a list
  122. % $(...,(f_i . d_i),...)$, where $f$ is an irreducible SF and $d$
  123. % is a positive integer. We have $l r=c \prod_i g_i^{d_i}$ for an
  124. % integer $c$.
  125. begin scalar w1,w2;
  126. w1 := cdr fctrf dvfsf_arg2l at;
  127. w2 := cdr fctrf dvfsf_arg2r at;
  128. return lto_almerge({w1,w2},'plus2)
  129. end;
  130. procedure dvfsf_v(z);
  131. % Discretely valued field standard form valuation function. [z] is
  132. % a non-zero integer. The fluid [dvfsf_p!*] must be fixed to a
  133. % positive prime integer $p$. Returns the $p$-adic value of [z].
  134. (if null cdr qrm then 1 + dvfsf_v car qrm else 0)
  135. where qrm=qremf(z,dvfsf_p!*);
  136. procedure dvfsf_dnf(f);
  137. % Discretely valued field standard form conjunctive normal form.
  138. % [f] is a formula. Returns a DNF of [f].
  139. if !*rlbnfsac then
  140. (cl_dnf f) where !*rlsiso=T
  141. else
  142. cl_dnf f;
  143. procedure dvfsf_cnf(f);
  144. % Discretely valued field standard form conjunctive normal form.
  145. % [f] is a formula. Returns a CNF of [f].
  146. if !*rlbnfsac then
  147. (cl_cnf f) where !*rlsiso=T
  148. else
  149. cl_cnf f;
  150. procedure dvfsf_subsumption(l1,l2,gor);
  151. % Discretely valued field standard form subsume. [l1] and [l2] are
  152. % lists of atomic formulas. Returns one of [keep1], [keep2], [nil].
  153. if gor eq 'or then (
  154. if dvfsf_subsumep!-and(l1,l2) then
  155. 'keep2
  156. else if dvfsf_subsumep!-and(l2,l1) then
  157. 'keep1
  158. ) else % [gor eq 'and]
  159. if dvfsf_subsumep!-or(l1,l2) then
  160. 'keep1
  161. else if dvfsf_subsumep!-or(l2,l1) then
  162. 'keep2
  163. else
  164. nil;
  165. procedure dvfsf_subsumep!-and(l1,l2);
  166. % Discretely valued field standard form subsume [and] case. [l1]
  167. % and [l2] are lists of atomic formulas.
  168. begin scalar a;
  169. while l2 do <<
  170. a := car l2;
  171. l2 := cdr l2;
  172. if cl_simpl(a,l1,-1) neq 'true then a := l2 := nil
  173. >>;
  174. return a
  175. end;
  176. procedure dvfsf_subsumep!-or(l1,l2);
  177. % Discretely valued field standard form subsume [or] case. [l1] and
  178. % [l2] are lists of atomic formulas.
  179. begin scalar a;
  180. while l1 do <<
  181. a := car l1;
  182. l1 := cdr l1;
  183. if cl_simpl(rl_smkn('or,l2),{a},-1) neq 'true then a := l1 := nil
  184. >>;
  185. return a
  186. end;
  187. procedure dvfsf_a2cdl(atml);
  188. % Discretely valued field standard form atomic formula multiplicity
  189. % list to case distinction list. [atml] is a list of atomic
  190. % formulas with multiplicity. Returns a list, each containing a
  191. % list of complete case distinctions.
  192. begin scalar atf,termll,flag;
  193. while atml do <<
  194. atf := caar atml;
  195. atml := cdr atml;
  196. termll := dvfsf_argn atf . termll;
  197. if not(dvfsf_op atf memq '(equal neq)) then flag := T
  198. >>;
  199. return if flag then
  200. for each x in termll collect
  201. {dvfsf_mk2('sdiv,car x,cadr x),
  202. dvfsf_mk2('assoc,car x,cadr x),
  203. dvfsf_mk2('sdiv,cadr x,car x)}
  204. else
  205. for each x in termll collect
  206. {dvfsf_0mk2('equal,x),dvfsf_0mk2('neq,x)}
  207. end;
  208. procedure dvfsf_subat(al,f);
  209. % Discretely valued field standard form substitute in atomic
  210. % formula. [al] is ALIST for [subf()]; [f] is an atomic formula.
  211. % Returns an atomic formula.
  212. begin scalar nlhs,nrhs,w;
  213. nlhs := subf(dvfsf_arg2l f,al);
  214. nrhs := subf(dvfsf_arg2r f,al);
  215. if (not domainp denr nlhs) or (not domainp denr nrhs) then
  216. rederr "parametric denominator after substitution";
  217. w := lcm(denr nlhs,denr nrhs);
  218. return dvfsf_mk2(dvfsf_op f,
  219. numr multsq(nlhs,!*f2q w),numr multsq(nrhs,!*f2q w))
  220. end;
  221. procedure dvfsf_subalchk(al);
  222. % Discretely valued field standard form substitution alist check.
  223. % [al] is an ALIST for [subf()]. Return value undefined. Raises an
  224. % error if an illegal substituion is contained in [al].
  225. for each x in al do
  226. if not domainp denr simp cdr x then
  227. rederr "parametric denominator in substituted term";
  228. procedure dvfsf_eqnrhskernels(x);
  229. % Discretely valued field standard form equation right hand side
  230. % kernels. [x] is an equation. Returns a list of all kernels
  231. % contained in the right hand side of [x].
  232. nconc(kernels numr w,kernels denr w) where w=simp cdr x;
  233. procedure dvfsf_structat(at,al);
  234. % Discretely valued field standard form structure of an atomic
  235. % formula. [at] is an atomic formula $([op],l,r)$; [al] is an
  236. % ALIST. Returns an atomic formula. [al] is of the form $(...,(f_i
  237. % . v_i),...)$ where $f_i$ is an SF and $v_i$ is a variable. Both
  238. % the left hand side of [at] and the right hand side of [at] occurs
  239. % as keys in [al]. Returns the atomic formula $[op](v_i,v_j)$,
  240. % provided $l=f_i$ and $r=f_j$.
  241. begin scalar lhs,rhs;
  242. lhs := dvfsf_arg2l at;
  243. rhs := dvfsf_arg2r at;
  244. if not(domainp lhs) then
  245. lhs := numr simp cdr assoc(lhs,al);
  246. if not(domainp rhs) then
  247. rhs := numr simp cdr assoc(rhs,al);
  248. return dvfsf_mk2(dvfsf_op at,lhs,rhs)
  249. end;
  250. procedure dvfsf_ifstructat(at,al);
  251. % Discretely valued field standard form irreducible factor
  252. % structure of atomic formula. [at] is an atomic formula $(f\rho
  253. % g)$, [al] is an A-LIST of the form $(...,( f_i . v_i ),...)$.
  254. % Returns an atomic formula of the form $(z u_1 \cdots u_m \rho z'
  255. % w_1 \cdots w_m)$. Each $u_i$ and each $w_i$ occur as a value in
  256. % [al] with the keys $f'_i$ and $g'_i$, respectively, and we have
  257. % $f=z f'_1 \cdots f'_m$ and $g'=z' w_1 \cdots w_m$ for integers
  258. % $z$ and $z'$.
  259. begin scalar lhs,rhs,rl,rr;
  260. lhs := fctrf dvfsf_arg2l at;
  261. rhs := fctrf dvfsf_arg2r at;
  262. rl := car lhs;
  263. for each x in cdr lhs do
  264. rl := multf(rl,expf(numr simp cdr assoc(car x,al),cdr x));
  265. rr := car rhs;
  266. for each x in cdr rhs do
  267. rr := multf(rr,expf(numr simp cdr assoc(car x,al),cdr x));
  268. return dvfsf_mk2(dvfsf_op at,rl,rr)
  269. end;
  270. procedure dvfsf_termmlat(at);
  271. % Discretely valued field standard form term multiplicity list of
  272. % atomic formula. [at] is an atomic formula. Returns the
  273. % multiplicity list off all non-zero terms in [at].
  274. begin scalar r,w;
  275. w := dvfsf_arg2l at;
  276. if w then
  277. r := (w . 1) . r;
  278. w := dvfsf_arg2r at;
  279. if w then
  280. r := (w . 1) . r;
  281. return r
  282. end;
  283. procedure dvfsf_explats(f);
  284. % Discretely valued fields standard form explode z atomic formulas.
  285. % [f] is a formula. Returns a formula equivalent to [at]. Explodes
  286. % atomic formula contained in [f] in dependency of [!*rlsiexpl],
  287. % [!*rlsiexpla] and the operator of the respective boolean level.
  288. % Only atomic formulas of the form $z \mathrel{\varrho} 1$, where
  289. % $z$ is an integer and $\varrho$ is one of ['assoc], ['nassoc]
  290. % will be exploded.
  291. cl_simpl(cl_apply2ats2(f,'dvfsf_explodezat,nil,nil),nil,-1);
  292. procedure dvfsf_explodezat(at,sop);
  293. % Discretely valued fields standard form explode z atomic formulas
  294. % for atomic formulas. [at] is an atomic formula; [sop] is a
  295. % boolean operator. Returns a formula equivalent to [at]. Explodes
  296. % [at] in dependency of [!*rlsiexpl], [!*rlsiexpla], and [sop].
  297. % Only atomic formulas of the form $z \mathrel{\varrho} 1$, where
  298. % $z$ is an integer and $\varrho$ is one of ['assoc], ['nassoc]
  299. % will be exploded.
  300. begin scalar op,lhs,rhs;
  301. lhs := dvfsf_arg2l at;
  302. rhs := dvfsf_arg2r at;
  303. if not(domainp lhs and rhs = 1) then
  304. return at;
  305. op := dvfsf_op at;
  306. if not (op eq 'assoc or op eq 'nassoc) then
  307. return at;
  308. if !*rlsiexpla then
  309. return dvfsf_explodezat1(op,lhs);
  310. if !*rlsiexpl then <<
  311. if op eq 'assoc and (sop eq 'and or null sop) then
  312. return dvfsf_explodezat1(op,lhs);
  313. if op eq 'nassoc and (sop eq 'or or null sop) then
  314. return dvfsf_explodezat1(op,lhs);
  315. >>;
  316. return at
  317. end;
  318. procedure dvfsf_explodezat1(op,lhs);
  319. % Discretely valued fields standard form explode z atomic formulas
  320. % subroutine. [op] id one of ['assoc], ['nassoc]; [lhs] is an
  321. % integer.
  322. rl_smkn(if op eq 'assoc then 'and else 'or,
  323. for each x in zfactor lhs collect dvfsf_mk2(op,car x,numr simp 1));
  324. procedure dvfsf_mkcanonic(f);
  325. % Discretely valued fields standard form make canonic. [f] is an
  326. % variable free and quantifier free formula. Returns the unique and
  327. % canonic representation of [f].
  328. begin scalar facl,u,fu,xl,op,pr;
  329. if rl_tvalp f then
  330. return f;
  331. facl := dvfsf_coeffacl(f);
  332. if null facl then
  333. return cl_simpl(f,nil,-1);
  334. pr := nextprime lto_max facl;
  335. u := cl_simpl(dvfsf_subp(f,pr),nil,-1)
  336. where dvfsf_p!*=pr;
  337. fu := cl_flip u;
  338. xl := for each fac in facl join
  339. if ((cl_simpl(dvfsf_subp(f,fac),nil,-1))
  340. where dvfsf_p!*=fac) eq fu
  341. then
  342. {fac};
  343. op := if u eq 'false then 'nassoc else 'assoc;
  344. xl := sort(xl,'lessp);
  345. return rl_smkn(if u eq 'false then 'or else 'and,
  346. for each x in xl collect dvfsf_mk2(op,x,numr simp 1))
  347. end;
  348. procedure dvfsf_coeffacl(f);
  349. % Discretely valued fields standard form coefficients factor list.
  350. % [f] is a formula. Returns the list of all ireducicble factors of
  351. % all integer coefficients.
  352. begin scalar cfml;
  353. cfml := cl_f2ml(f,'dvfsf_coeffaclat);
  354. return for each x in cfml collect car x
  355. end;
  356. procedure dvfsf_coeffaclat(at);
  357. % Discretely valued fields standard form coefficients factor list
  358. % for atomic formulas. [f] is an atomic formula. Returns the list
  359. % of all ireducicble factors of all integer coefficients.
  360. lto_almerge({dvfsf_coeffaclf dvfsf_arg2l at,dvfsf_coeffaclf dvfsf_arg2r at},
  361. 'plus2);
  362. procedure dvfsf_coeffaclf(f);
  363. % Discretely valued fields standard form coefficients factor list
  364. % for standard forms. [f] is an SF. Returns the list of all
  365. % ireducicble factors of all integer coefficients.
  366. if null f then
  367. {}
  368. else if domainp f then
  369. dvfsf_coeffaclz f
  370. else if mvar f eq ' p then
  371. lto_almerge({dvfsf_coeffaclz lc f,dvfsf_coeffaclf red f},'plus2)
  372. else
  373. rederr "dvfsf_coeffaclf: unknown mvar";
  374. procedure dvfsf_coeffaclz(z);
  375. % Discretely valued fields standard form coefficients factor list
  376. % for integers. [f] is an integer. Returns the list of all
  377. % positive ireducicble factors upto 1 and -1.
  378. if z=1 or z=-1 or z=0 then
  379. {}
  380. else if z < 0 then
  381. zfactor (-z)
  382. else
  383. zfactor z;
  384. procedure dvfsf_subp(f,p);
  385. % Discretely valued fields standard form substitute for p. [f] is a
  386. % formula, [p] is a prime integer. Returns a formula in which all
  387. % occurences of ['p] are replaced by [p].
  388. cl_apply2ats1(f,'cl_subpat,{{'p . p}});
  389. procedure cl_subpat(at,al);
  390. % Discretely valued fields standard form substitute for p for
  391. % atomic formulas. [at] is an atomic formula, al is an ALIST
  392. % describing the substitution of ['p] with an prime integer $p$.
  393. % Returns a formula in which all occurences of ['p] are replaced by
  394. % $p$.
  395. dvfsf_mk2(dvfsf_op at,
  396. numr subf(dvfsf_arg2l at,al),numr subf(dvfsf_arg2r at,al));
  397. endmodule; % [dvfsfmisc]
  398. end; % of file