ofsfsiat.red 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. % ----------------------------------------------------------------------
  2. % $Id: ofsfsiat.red,v 1.8 1999/03/23 12:26:33 sturm Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: ofsfsiat.red,v $
  7. % Revision 1.8 1999/03/23 12:26:33 sturm
  8. % Renamed switch rlsisqf to rlsiatadv.
  9. %
  10. % Revision 1.7 1999/03/23 07:41:39 dolzmann
  11. % Changed copyright information.
  12. %
  13. % Revision 1.6 1996/10/08 13:54:37 dolzmann
  14. % Renamed "degree parity decomposition" to "parity decomposition".
  15. % Adapted names of procedures and switches accordingly.
  16. %
  17. % Revision 1.5 1996/10/07 12:03:32 sturm
  18. % Added fluids for CVS and copyright information.
  19. %
  20. % Revision 1.4 1996/09/30 16:56:02 sturm
  21. % Cleaned up the use of several (conditional) negate-relation procedures.
  22. %
  23. % Revision 1.3 1996/09/05 11:16:08 dolzmann
  24. % Fixed a bug in ofsf_simplleq and ofsf_simplgreaterp.
  25. %
  26. % Revision 1.2 1996/05/12 08:27:49 sturm
  27. % Introduced code for splitting of trivial square sums.
  28. %
  29. % Revision 1.1 1996/03/22 12:14:16 sturm
  30. % Moved and split.
  31. %
  32. % ----------------------------------------------------------------------
  33. lisp <<
  34. fluid '(ofsf_siat_rcsid!* ofsf_siat_copyright!*);
  35. ofsf_siat_rcsid!* := "$Id: ofsfsiat.red,v 1.8 1999/03/23 12:26:33 sturm Exp $";
  36. ofsf_siat_copyright!* :=
  37. "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  38. >>;
  39. module ofsfsiat;
  40. % Ordered field standard form simplification. Submodule of [ofsf].
  41. procedure ofsf_simplat1(f,sop);
  42. % Ordered field standard form simplify atomic formula. [f] is an
  43. % atomic formula; [sop] is the boolean operator [f] occurs with or
  44. % [nil]. Accesses switches [rlsiatadv], [rlsipd], [rlsiexpl], and
  45. % [rlsiexpla]. Returns a quantifier-free formula that is a
  46. % simplified equivalent of [f].
  47. begin scalar rel,lhs;
  48. rel := ofsf_op f;
  49. if not (rel memq '(equal neq leq geq lessp greaterp)) then
  50. return nil;
  51. lhs := ofsf_arg2l f;
  52. if domainp lhs then
  53. return if ofsf_evalatp(rel,lhs) then 'true else 'false;
  54. lhs := quotf(lhs,sfto_dcontentf lhs);
  55. if minusf lhs then <<
  56. lhs := negf lhs;
  57. rel := ofsf_anegrel rel
  58. >>;
  59. if null !*rlsiatadv then return ofsf_0mk2(rel,lhs);
  60. if rel eq 'equal then return ofsf_simplequal(lhs,sop);
  61. if rel eq 'neq then return ofsf_simplneq(lhs,sop);
  62. if rel eq 'leq then return ofsf_simplleq(lhs,sop);
  63. if rel eq 'geq then return ofsf_simplgeq(lhs,sop);
  64. if rel eq 'lessp then return ofsf_simpllessp(lhs,sop);
  65. if rel eq 'greaterp then return ofsf_simplgreaterp(lhs,sop)
  66. end;
  67. procedure ofsf_simplequal(lhs,sop);
  68. % Ordered field standard form simplify [equal]-atomic formula.
  69. % [lhs] is a term. Returns a quantifier-free formula.
  70. begin scalar w,ff,ww;
  71. w := sfto_tsqsumf lhs;
  72. if w eq 'stsq then return 'false;
  73. ff := sfto_sqfpartf lhs;
  74. ww := sfto_tsqsumf ff;
  75. if ww eq 'stsq then return 'false;
  76. if !*rlsitsqspl and (!*rlsiexpla or !*rlsiexpl and sop = 'and) then <<
  77. if ww eq 'tsq then return ofsf_tsqsplequal ff;
  78. if w eq 'tsq then return ofsf_tsqsplequal lhs
  79. >>;
  80. if !*rlsifac and (!*rlsiexpla or !*rlsiexpl and sop = 'or) then
  81. return ofsf_facequal ff;
  82. return ofsf_0mk2('equal,ff)
  83. end;
  84. procedure ofsf_tsqsplequal(f);
  85. % Trivial square sum split [equal] case.
  86. begin scalar w;
  87. w := ofsf_getsqsummons(f);
  88. if !*rlsifac and (!*rlsiexpla or !*rlsiexpl and null cdr w) then
  89. return rl_smkn('and,for each m in w collect
  90. rl_smkn('or,for each v in m collect ofsf_0mk2('equal,v)));
  91. return rl_smkn('and,for each m in w collect
  92. ofsf_0mk2('equal,ofsf_lmultf m))
  93. end;
  94. procedure ofsf_facequal(f);
  95. % Left hand side factorization [equal] case.
  96. rl_smkn('or,for each x in cdr fctrf f collect ofsf_0mk2('equal,car x));
  97. procedure ofsf_simplneq(lhs,sop);
  98. % Ordered field standard form simplify [neq]-atomic formula.
  99. % [lhs] is a term. Returns a quantifier-free formula.
  100. begin scalar w,ff,ww;
  101. w := sfto_tsqsumf lhs;
  102. if w eq 'stsq then return 'true;
  103. ff := sfto_sqfpartf lhs;
  104. ww := sfto_tsqsumf ff;
  105. if ww eq 'stsq then return 'true;
  106. if !*rlsitsqspl and (!*rlsiexpla or !*rlsiexpl and sop = 'or) then <<
  107. if ww eq 'tsq then return ofsf_tsqsplneq ff;
  108. if w eq 'tsq then return ofsf_tsqsplneq lhs
  109. >>;
  110. if !*rlsifac and (!*rlsiexpla or !*rlsiexpl and sop = 'and) then
  111. return ofsf_facneq ff;
  112. return ofsf_0mk2('neq,ff)
  113. end;
  114. procedure ofsf_tsqsplneq(f);
  115. % Trivial square sum split [neq] case.
  116. begin scalar w;
  117. w := ofsf_getsqsummons(f);
  118. if !*rlsifac and (!*rlsiexpla or !*rlsiexpl and null cdr w) then
  119. return rl_smkn('or,for each m in w collect
  120. rl_smkn('and,for each v in m collect ofsf_0mk2('neq,v)));
  121. return rl_smkn('or,for each m in w collect
  122. ofsf_0mk2('neq,ofsf_lmultf m))
  123. end;
  124. procedure ofsf_facneq(f);
  125. % Left hand side factorization [neq] case.
  126. rl_smkn('and,for each x in cdr fctrf f collect ofsf_0mk2('neq,car x));
  127. procedure ofsf_lmultf fl;
  128. if null fl then
  129. 1
  130. else if null cdr fl then
  131. car fl
  132. else
  133. multf(car fl,ofsf_lmultf cdr fl);
  134. procedure ofsf_getsqsummons(f);
  135. begin scalar v,w;
  136. if null f then return nil;
  137. if domainp f then return {nil}; % i.e. {1}
  138. w := ofsf_getsqsummons(red f);
  139. v := !*k2f mvar f;
  140. for each x in ofsf_getsqsummons lc f do
  141. w := (v . x) . w;
  142. return w
  143. end;
  144. procedure ofsf_simplleq(lhs,sop);
  145. % Ordered field standard form simplify [leq]-atomic formula. [lhs]
  146. % is a term, [sop] is a boolean operator or [nil]. Accesses
  147. % switches [rlsipd], [rlexpl], and [rlexpla]. Returns a
  148. % quantifier-free formula.
  149. begin scalar s1,s2,w,x;
  150. if (s1 := sfto_tsqsumf lhs) eq 'stsq then % necessary?
  151. return 'false;
  152. w := sfto_sqfpartf lhs;
  153. if (s2 := sfto_tsqsumf w) eq 'stsq then
  154. return 'false;
  155. if !*rlsitsqspl and (!*rlsiexpla or !*rlsiexpl and sop = 'and) then <<
  156. if s2 then return ofsf_tsqsplequal w;
  157. if s1 then return ofsf_tsqsplequal lhs
  158. >>;
  159. if s1 or s2 then
  160. return ofsf_0mk2('equal,w);
  161. if null !*rlsipd then
  162. return ofsf_0mk2('leq,lhs);
  163. x := sfto_pdecf lhs;
  164. if sfto_tsqsumf car x then % in particular, 1 is an stsq.
  165. return ofsf_0mk2('equal,w);
  166. if cdr x = 1 then
  167. return ofsf_0mk2('leq,car x);
  168. if !*rlsiexpla or (!*rlsiexpl and (sop eq 'or)) then
  169. return rl_mkn('or,{
  170. ofsf_0mk2('leq,car x),ofsf_0mk2('equal,cdr x)});
  171. return ofsf_0mk2('leq,multf(car x,exptf(cdr x,2)))
  172. end;
  173. procedure ofsf_simplgeq(lhs,sop);
  174. % Ordered field standard form simplify [geq]-atomic formula. [lhs]
  175. % is a term, [sop] is a boolean operator or [nil]. Accesses
  176. % switches [rlsipd], [rlexpl], and [rlexpla]. Returns a
  177. % quantifier-free formula.
  178. begin scalar w;
  179. if sfto_tsqsumf lhs or sfto_tsqsumf sfto_sqfpartf lhs then
  180. return 'true;
  181. if null !*rlsipd then
  182. return ofsf_0mk2('geq,lhs);
  183. w := sfto_pdecf lhs;
  184. if sfto_tsqsumf car w then
  185. return 'true;
  186. if cdr w = 1 then
  187. return ofsf_0mk2('geq,car w);
  188. if !*rlsiexpla or (!*rlsiexpl and (sop eq 'or)) then
  189. return rl_mkn('or,{
  190. ofsf_0mk2('geq,car w),ofsf_0mk2('equal,cdr w)});
  191. return ofsf_0mk2('geq,multf(car w,exptf(cdr w,2)))
  192. end;
  193. procedure ofsf_simpllessp(lhs,sop);
  194. % Ordered field standard form simplify [lessp]-atomic formula.
  195. % [lhs] is a term, [sop] is a boolean operator or [nil]. Accesses
  196. % switches [rlsipd], [rlexpl], and [rlexpla]. Returns a
  197. % quantifier-free formula.
  198. begin scalar w;
  199. if sfto_tsqsumf lhs or sfto_tsqsumf sfto_sqfpartf lhs then
  200. return 'false;
  201. if null !*rlsipd then
  202. return ofsf_0mk2('lessp,lhs);
  203. w := sfto_pdecf lhs;
  204. if sfto_tsqsumf car w then
  205. return 'false;
  206. if cdr w = 1 then
  207. return ofsf_0mk2('lessp,car w);
  208. if !*rlsiexpla or (!*rlsiexpl and (sop eq 'and)) then
  209. return rl_mkn('and,{
  210. ofsf_0mk2('lessp,car w),ofsf_0mk2('neq,cdr w)});
  211. return ofsf_0mk2('lessp,multf(car w,exptf(cdr w,2)))
  212. end;
  213. procedure ofsf_simplgreaterp(lhs,sop);
  214. % Ordered field standard form simplify [greaterp]-atomic formula.
  215. % [lhs] is a term, [sop] is a boolean operator or [nil]. Accesses
  216. % switches [rlsipd], [rlexpl], and [rlexpla]. Returns a
  217. % quantifier-free formula.
  218. begin scalar s1,s2,w,x;
  219. if (s1 := sfto_tsqsumf lhs) eq 'stsq then % necessary?
  220. return 'true;
  221. w := sfto_sqfpartf lhs;
  222. if (s2 := sfto_tsqsumf w) eq 'stsq then
  223. return 'true;
  224. if !*rlsitsqspl and (!*rlsiexpla or !*rlsiexpl and sop = 'or) then <<
  225. if s2 then return ofsf_tsqsplneq w;
  226. if s1 then return ofsf_tsqsplneq lhs
  227. >>;
  228. if s1 or s2 then return
  229. ofsf_0mk2('neq,w);
  230. if null !*rlsipd then
  231. return ofsf_0mk2('greaterp,lhs);
  232. x := sfto_pdecf lhs;
  233. if sfto_tsqsumf car x then
  234. return ofsf_0mk2('neq,w);
  235. if cdr x = 1 then
  236. return ofsf_0mk2('greaterp,car x);
  237. if !*rlsiexpla or (!*rlsiexpl and (sop eq 'and)) then
  238. return rl_mkn('and,{
  239. ofsf_0mk2('greaterp,car x),ofsf_0mk2('neq,cdr x)});
  240. return ofsf_0mk2('greaterp,multf(car x,exptf(cdr x,2)))
  241. end;
  242. procedure ofsf_evalatp(rel,lhs);
  243. % Ordered field standard form evaluate atomic formula. [rel] is a
  244. % relation; [lhs] is a domain element. Returns a truth value
  245. % equivalent to $[rel]([lhs],0)$.
  246. if rel eq 'equal then null lhs
  247. else if rel eq 'neq then not null lhs
  248. else if rel eq 'leq then minusf lhs or null lhs
  249. else if rel eq 'geq then not minusf lhs
  250. else if rel eq 'lessp then minusf lhs
  251. else if rel eq 'greaterp then not (minusf lhs or null lhs)
  252. else rederr {"ofsf_evalatp: unknown operator ",rel};
  253. endmodule; % [ofsfsiat]
  254. end; % of file