ofsfmisc.red 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. % ----------------------------------------------------------------------
  2. % $Id: ofsfmisc.red,v 1.13 1999/04/01 11:25:56 dolzmann Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: ofsfmisc.red,v $
  7. % Revision 1.13 1999/04/01 11:25:56 dolzmann
  8. % Added and corrected comments.
  9. %
  10. % Revision 1.12 1999/03/23 07:41:38 dolzmann
  11. % Changed copyright information.
  12. %
  13. % Revision 1.11 1997/08/24 16:18:51 sturm
  14. % Added service rl_surep with black box rl_multsurep.
  15. % Added service rl_siaddatl.
  16. %
  17. % Revision 1.10 1996/10/23 11:17:45 dolzmann
  18. % Corrected comments.
  19. %
  20. % Revision 1.9 1996/10/07 12:03:26 sturm
  21. % Added fluids for CVS and copyright information.
  22. %
  23. % Revision 1.8 1996/10/03 16:06:09 sturm
  24. % Fixed a bug in ofsf_structat.
  25. %
  26. % Revision 1.7 1996/10/01 10:25:08 reiske
  27. % Introduced new service rltnf and related code.
  28. %
  29. % Revision 1.6 1996/09/30 16:55:59 sturm
  30. % Cleaned up the use of several (conditional) negate-relation procedures.
  31. %
  32. % Revision 1.5 1996/09/05 11:15:19 dolzmann
  33. % Added implementation for black boxes rl_structat, rl_ifstructat, and
  34. % rl_termmlat.
  35. %
  36. % Revision 1.4 1996/08/01 11:45:48 reiske
  37. % Added implementation for black boxes rl_a2cdl and rl_getineq.
  38. %
  39. % Revision 1.3 1996/07/07 14:39:50 sturm
  40. % Added implementation for black box ofsf_eqnrhskernels.
  41. %
  42. % Revision 1.2 1996/05/21 17:14:19 sturm
  43. % Added procedures ofsf_subat and ofsf_subalchk.
  44. %
  45. % Revision 1.1 1996/03/22 12:14:11 sturm
  46. % Moved and split.
  47. %
  48. % ----------------------------------------------------------------------
  49. lisp <<
  50. fluid '(ofsf_misc_rcsid!* ofsf_misc_copyright!*);
  51. ofsf_misc_rcsid!* := "$Id: ofsfmisc.red,v 1.13 1999/04/01 11:25:56 dolzmann Exp $";
  52. ofsf_misc_copyright!* :=
  53. "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  54. >>;
  55. module ofsfmisc;
  56. % Ordered field standard form miscellaneous. Submodule of [ofsf].
  57. procedure ofsf_termprint(u);
  58. % Ordered field standard form term print term. [u] is a SF. The
  59. % return value is not specified. Prints [u] AM-like.
  60. <<
  61. sqprint !*f2q u where !*nat=nil;
  62. ioto_prin2 nil
  63. >>;
  64. procedure ofsf_canegrel(r,flg);
  65. % Ordered field standard form conditionally algberaically negate
  66. % relation. [r] is a relation. Returns a relation $R$. If [flg] is
  67. % non-[nil], then $[R]=[r]$. If [flg] is [nil], then [R] is a
  68. % relation, such that $R(-t,0)$ is equivalent to $[r](t,0)$ for
  69. % every term $t$.
  70. if flg then r else ofsf_anegrel r;
  71. procedure ofsf_anegrel(r);
  72. % Ordered field standard form algebraically negate relation. [r] is
  73. % a relation. Returns a relation $R$ such that $R(-t,0)$ is
  74. % equivalent to $[r](t,0)$ for a term $t$.
  75. cdr atsoc(r,'((equal . equal) (neq . neq) (leq . geq) (geq . leq)
  76. (lessp . greaterp) (greaterp . lessp)))
  77. or rederr {"ofsf_anegrel: unknown operator ",r};
  78. procedure ofsf_clnegrel(r,flg);
  79. % Ordered field standard form conditionally logically negate
  80. % relation. [r] is a relation; [flg] is bool. Return a relation
  81. % $R$. If [flg] is non-[nil] [r] is returned. Othewise a relation
  82. % $R$ is returned such that for terms $t_1$, $t_2$ we have
  83. % $R(t_1,t_2)$ equivalent to $\lnot [r](t_1,t_2)$.
  84. if flg then r else ofsf_lnegrel r;
  85. procedure ofsf_lnegrel(r);
  86. % Ordered field standard form logically negate relation. [r] is a
  87. % relation. Returns a relation $R$ such that for terms $t_1$, $t_2$
  88. % we have $R(t_1,t_2)$ equivalent to $\lnot [r](t_1,t_2)$.
  89. if r eq 'equal then 'neq
  90. else if r eq 'neq then 'equal
  91. else if r eq 'leq then 'greaterp
  92. else if r eq 'lessp then 'geq
  93. else if r eq 'geq then 'lessp
  94. else if r eq 'greaterp then 'leq
  95. else rederr {"ofsf_lnegrel: unknown operator ",r};
  96. procedure ofsf_fctrat(atf);
  97. % Ordered field standard form factorize atomic formula. [atf] is an
  98. % atomic formula $l \mathrel{\varrho} 0$. Returns a list $(...,(f_i
  99. % . d_i),...)$, where $f$ is an irreducible SF and $d$ is a
  100. % positive integer. We have $l=c \prod_i g_i^{d_i}$ for an integer
  101. % $c$.
  102. cdr fctrf ofsf_arg2l atf;
  103. procedure ofsf_negateat(f);
  104. % Ordered field standard form negate atomic formula. [f] is an
  105. % atomic formula. Returns an atomic formula equivalent to $\lnot
  106. % [f]$.
  107. ofsf_mkn(ofsf_lnegrel ofsf_op f,ofsf_argn f);
  108. procedure ofsf_varlat(atform);
  109. % Ordered field standard form atomic formula list of variables.
  110. % [atform] is an atomic formula. Returns the variables contained in
  111. % [atform] as a list.
  112. kernels ofsf_arg2l(atform);
  113. procedure ofsf_varsubstat(atf,new,old);
  114. % Ordered field standard form substitute variable for variable in
  115. % atomic formula. [atf] is an atomic formula; [new] and [old] are
  116. % variables. Returns an atomic formula equivalent to [atf] where
  117. % [old] is substituted with [new].
  118. ofsf_0mk2(ofsf_op atf,numr subf(ofsf_arg2l atf,{old . new}));
  119. procedure ofsf_ordatp(a1,a2);
  120. % Ordered field standard form atomic formula predicate. [a1] and
  121. % [a2] are atomic formulas. Returns [t] iff [a1] is less than [a2].
  122. begin scalar lhs1,lhs2;
  123. lhs1 := ofsf_arg2l a1;
  124. lhs2 := ofsf_arg2l a2;
  125. if lhs1 neq lhs2 then return ordp(lhs1,lhs2);
  126. return ofsf_ordrelp(ofsf_op a1,ofsf_op a2)
  127. end;
  128. procedure ofsf_ordrelp(r1,r2);
  129. % Ordered field standard form relation order predicate.
  130. % [r1] and [r2] are ofsf-relations. Returns a [T] iff $[r1] < [r2]$.
  131. not not (r2 memq (r1 memq '(equal neq leq lessp geq greaterp)));
  132. procedure ofsf_a2cdl(atml);
  133. % Ordered field standard form atomic to case distinction list.
  134. % [atml] is a list of atomic formulas with multiplicity, the right
  135. % hand side of which is always zero. Returns a list, each
  136. % containing a list of case distinction w.r.t. the term $t$, i.e.
  137. % ${t<0,t=0,t>0}$ resp. ${t=0,t neq 0}$.
  138. begin scalar atf,terml,flag;
  139. while atml do <<
  140. atf := caar atml;
  141. atml := cdr atml;
  142. terml := ofsf_arg2l atf . terml;
  143. if not(ofsf_op atf memq '(equal neq)) then flag := T
  144. >>;
  145. return for each x in terml collect
  146. if flag then
  147. {ofsf_0mk2('lessp,x),ofsf_0mk2('equal,x),ofsf_0mk2('greaterp,x)}
  148. else
  149. {ofsf_0mk2('equal,x),ofsf_0mk2('neq,x)}
  150. end;
  151. procedure ofsf_t2cdl(term);
  152. % Ordered field standard form term to case distinction list. [term]
  153. % is a term. Returns a list of full case distinctions w.r.t. the
  154. % term, i.e. ${[term]<0,[term]=0,[term]>0}$.
  155. {ofsf_0mk2('lessp,term),ofsf_0mk2('equal,term),ofsf_0mk2('greaterp,term)};
  156. procedure ofsf_subat(al,f);
  157. begin scalar nlhs;
  158. nlhs := subf(ofsf_arg2l f,al);
  159. if not domainp denr nlhs then
  160. rederr "parametric denominator after substitution";
  161. return ofsf_0mk2(ofsf_op f,numr nlhs)
  162. end;
  163. procedure ofsf_subalchk(al);
  164. for each x in al do
  165. if not domainp denr simp cdr x then
  166. rederr "parametric denominator in substituted term";
  167. procedure ofsf_eqnrhskernels(x);
  168. nconc(kernels numr w,kernels denr w) where w=simp cdr x;
  169. procedure ofsf_getineq(f,bvl);
  170. % Generate theory get inequalities. [f] is a formula, the right
  171. % hand side is always zero; [bvl] is a list of variables. Returns
  172. % the list of all inequalities occuring in [f] not containing any
  173. % variables from [bvl].
  174. begin scalar atml,atf,cdl;
  175. atml := cl_atml f;
  176. while atml do <<
  177. atf := caar atml;
  178. atml := cdr atml;
  179. if ofsf_op atf memq '(neq) and
  180. null intersection(bvl, kernels ofsf_arg2l atf) then
  181. cdl := atf . cdl
  182. >>;
  183. return cdl
  184. end;
  185. procedure ofsf_structat(at,al);
  186. % Orederd field standard form structure of an atomic formula. [at]
  187. % is an atomic formula $([op],l,0)$; [al] is an ALIST. Returns an
  188. % atomic formula. [al] is of the form $(...,(f_i . v_i),...)$ where
  189. % $f_i$ is an SF and $v_i$ is a variable. The left hand side of
  190. % [at] occurs as a key in [al]. Returns the atomic formula
  191. % $[op](v_i,0)$, provided $l=f_i$.
  192. begin scalar lhs;
  193. lhs := ofsf_arg2l at;
  194. if domainp lhs then
  195. return at;
  196. return ofsf_0mk2(ofsf_op at, numr simp cdr assoc(lhs,al))
  197. end;
  198. procedure ofsf_ifstructat(at,al);
  199. begin scalar w,r;
  200. w := fctrf ofsf_arg2l at;
  201. r := car w;
  202. for each x in cdr w do
  203. r := multf(r,expf(numr simp cdr assoc(car x,al),cdr x));
  204. return ofsf_0mk2(ofsf_op at,r)
  205. end;
  206. procedure ofsf_termmlat(at);
  207. % Ordered field standard form term multiplicity list of atomic
  208. % formula. [at] is an atomic formula. Returns the multiplicity list
  209. % off all non-zero terms in [at].
  210. if ofsf_arg2l at then
  211. {(ofsf_arg2l at . 1)};
  212. procedure ofsf_multsurep(at,atl);
  213. if ofsf_op at eq 'equal then
  214. ofsf_multsurep!-equal(at,atl)
  215. else
  216. ofsf_multsurep!-neq(at,atl);
  217. procedure ofsf_multsurep!-equal(at,atl);
  218. begin scalar c,a;
  219. c := ofsf_arg2l at;
  220. while atl do <<
  221. a := car atl;
  222. atl := cdr atl;
  223. if ofsf_op a eq 'equal and quotf(c,ofsf_arg2l a) then <<
  224. a := 'found;
  225. atl := nil
  226. >>
  227. >>;
  228. return a eq 'found
  229. end;
  230. procedure ofsf_multsurep!-neq(at,atl);
  231. begin scalar c,a;
  232. c := ofsf_arg2l at;
  233. while atl do <<
  234. a := car atl;
  235. atl := cdr atl;
  236. if ofsf_op a eq 'neq and quotf(ofsf_arg2l a,c) then <<
  237. a := 'found;
  238. atl := nil
  239. >>
  240. >>;
  241. return a eq 'found
  242. end;
  243. endmodule; % [ofsfmisc]
  244. end; % of file