ofsfsism.red 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. % ----------------------------------------------------------------------
  2. % $Id: ofsfsism.red,v 1.6 1999/03/23 07:41:39 dolzmann Exp $
  3. % ----------------------------------------------------------------------
  4. % Copyright (c) 1995-1999 Andreas Dolzmann and Thomas Sturm
  5. % ----------------------------------------------------------------------
  6. % $Log: ofsfsism.red,v $
  7. % Revision 1.6 1999/03/23 07:41:39 dolzmann
  8. % Changed copyright information.
  9. %
  10. % Revision 1.5 1996/10/07 12:03:33 sturm
  11. % Added fluids for CVS and copyright information.
  12. %
  13. % Revision 1.4 1996/09/30 16:56:12 sturm
  14. % Cleaned up the use of several (conditional) negate-relation procedures.
  15. %
  16. % Revision 1.3 1996/07/15 13:29:10 sturm
  17. % Modified data structure descriptions for automatic processing.
  18. %
  19. % Revision 1.2 1996/07/13 11:20:35 dolzmann
  20. % Added black box implementation ofsf_smcpknowl.
  21. % Removed black box implementations ofsf_smsimpl!-impl and
  22. % ofsf_smsimpl!-equiv1.
  23. %
  24. % Revision 1.1 1996/03/22 12:14:17 sturm
  25. % Moved and split.
  26. %
  27. % ----------------------------------------------------------------------
  28. lisp <<
  29. fluid '(ofsf_sism_rcsid!* ofsf_sism_copyright!*);
  30. ofsf_sism_rcsid!* := "$Id: ofsfsism.red,v 1.6 1999/03/23 07:41:39 dolzmann Exp $";
  31. ofsf_sism_copyright!* :=
  32. "Copyright (c) 1995-1999 by A. Dolzmann and T. Sturm"
  33. >>;
  34. module ofsfsism;
  35. % Ordered field standard form smart simplification. Submodule of [ofsf].
  36. %DS
  37. % <irl> ::= (<ir>,...)
  38. % <ir> ::= <para> . <db>
  39. % <db> ::= (<le>,...)
  40. % <le> ::= <label> . <entry>
  41. % <label> ::= <integer>
  42. % <entry> ::= <of relation> . <standard quotient>
  43. procedure ofsf_smrmknowl(knowl,v);
  44. % Ordered field standard form remove from knowledge. [knowl] is an
  45. % IRL; [v] is a variable. Returns an IRL. Destructively removes any
  46. % information about [v] from [knowl].
  47. if null knowl then
  48. nil
  49. else if v member kernels caar knowl then
  50. ofsf_smrmknowl(cdr knowl,v)
  51. else <<
  52. cdr knowl := ofsf_smrmknowl(cdr knowl,v);
  53. knowl
  54. >>;
  55. procedure ofsf_smcpknowl(knowl);
  56. for each ir in knowl collect
  57. car ir . append(cdr ir,nil);
  58. procedure ofsf_smupdknowl(op,atl,knowl,n);
  59. % Ordered field standard form update knowledge. [op] is one of
  60. % [and], [or]; [atl] is a list of (simplified) atomic formulas;
  61. % [knowl] is a conjunctive IRL; [n] is the current level. Returns
  62. % an IRL. Destructively updates [knowl] wrt. the [atl] information.
  63. begin scalar w,ir,a;
  64. while atl do <<
  65. a := if op eq 'and then car atl else ofsf_negateat car atl;
  66. atl := cdr atl;
  67. ir := ofsf_at2ir(a,n);
  68. if w := assoc(car ir,knowl) then <<
  69. cdr w := ofsf_sminsert(cadr ir,cdr w);
  70. if cdr w eq 'false then <<
  71. atl := nil;
  72. knowl := 'false
  73. >> % else [ofsf_sminsert] has updated [cdr w] destructively.
  74. >> else
  75. knowl := ir . knowl
  76. >>;
  77. return knowl
  78. end;
  79. procedure ofsf_smmkatl(op,oldknowl,newknowl,n);
  80. % Ordered field standard form make atomic formula list. [op] is one
  81. % of [and], [or]; [oldknowl] and [newknowl] are IRL's; [n] is an
  82. % integer. Returns a list of atomic formulas. Depends on switch
  83. % [rlsipw].
  84. if op eq 'and then
  85. ofsf_smmkatl!-and(oldknowl,newknowl,n)
  86. else % [op eq 'or]
  87. ofsf_smmkatl!-or(oldknowl,newknowl,n);
  88. procedure ofsf_smmkatl!-and(oldknowl,newknowl,n);
  89. begin scalar w;
  90. if not !*rlsipw and !*rlsipo then
  91. return ofsf_irl2atl('and,newknowl,n);
  92. return for each ir in newknowl join <<
  93. w := atsoc(car ir,oldknowl);
  94. if null w then ofsf_ir2atl('and,ir,n) else ofsf_smmkatl!-and1(w,ir,n)
  95. >>;
  96. end;
  97. procedure ofsf_smmkatl!-and1(oir,nir,n);
  98. begin scalar w,parasq;
  99. parasq := !*f2q car nir;
  100. return for each le in cdr nir join
  101. if car le = n then <<
  102. if cadr le memq '(lessp greaterp) and
  103. (w := ofsf_smmkat!-and2(cdr oir,cdr le,parasq))
  104. then
  105. {w}
  106. else
  107. {ofsf_entry2at('and,cdr le,parasq)}
  108. >>
  109. end;
  110. procedure ofsf_smmkat!-and2(odb,ne,parasq);
  111. % Ordered field standard form smart simplify make atomic formula.
  112. % [odb] is a DB; [ne] is an entry with its relation being one of
  113. % [lessp], [greaterp]; [parasq] is a numerical SQ. Returns an
  114. % atomic formula.
  115. begin scalar w;
  116. w := ofsf_smdbgetrel(cdr ne,odb);
  117. if w eq 'neq then
  118. (if !*rlsipw then <<
  119. if car ne eq 'lessp then
  120. return ofsf_entry2at('and,'leq . cdr ne,parasq);
  121. % We know [car ne eq 'greaterp].
  122. return ofsf_entry2at('and,'geq . cdr ne,parasq)
  123. >>)
  124. else if w memq '(leq geq) then
  125. if not !*rlsipo then
  126. return ofsf_entry2at('and,'neq . cdr ne,parasq)
  127. end;
  128. procedure ofsf_smmkatl!-or(oldknowl,newknowl,n);
  129. begin scalar w;
  130. return for each ir in newknowl join <<
  131. w := atsoc(car ir,oldknowl);
  132. if null w then ofsf_ir2atl('or,ir,n) else ofsf_smmkatl!-or1(w,ir,n)
  133. >>;
  134. end;
  135. procedure ofsf_smmkatl!-or1(oir,nir,n);
  136. begin scalar w,parasq;
  137. parasq := !*f2q car nir;
  138. return for each le in cdr nir join
  139. if car le = n then <<
  140. if cadr le memq '(lessp greaterp equal) and
  141. (w := ofsf_smmkat!-or2(cdr oir,cdr le,parasq))
  142. then
  143. {w}
  144. else
  145. {ofsf_entry2at('or,cdr le,parasq)}
  146. >>
  147. end;
  148. procedure ofsf_smmkat!-or2(odb,ne,parasq);
  149. begin scalar w;
  150. w := ofsf_smdbgetrel(cdr ne,odb);
  151. if w eq 'neq then
  152. (if not !*rlsipw then <<
  153. if car ne eq 'lessp then
  154. return ofsf_entry2at('or,'leq . cdr ne,parasq);
  155. % We know [car ne eq 'greaterp]!
  156. return ofsf_entry2at('or,'geq . cdr ne,parasq)
  157. >>)
  158. else if w memq '(leq geq) then <<
  159. if car ne memq '(lessp greaterp) then
  160. return ofsf_entry2at('or,'neq . cdr ne,parasq);
  161. % We know [car ne eq 'equal].
  162. if !*rlsipo then
  163. return ofsf_entry2at('or,ofsf_anegrel w . cdr ne,parasq)
  164. >>
  165. end;
  166. procedure ofsf_smdbgetrel(abssq,db);
  167. if abssq = cddar db then
  168. cadar db
  169. else if cdr db then
  170. ofsf_smdbgetrel(abssq,cdr db);
  171. procedure ofsf_at2ir(atf,n);
  172. % Ordered field standard form atomic formula to IR. [atf] is an
  173. % atomic formula; [n] is an integer. Returns the IR representing
  174. % [atf] on level [n].
  175. begin scalar op,par,abs,c;
  176. op := ofsf_op atf;
  177. abs := par := ofsf_arg2l atf;
  178. while not domainp abs do abs := red abs;
  179. par := addf(par,negf abs);
  180. c := sfto_dcontentf(par);
  181. par := quotf(par,c);
  182. abs := quotsq(!*f2q abs,!*f2q c);
  183. return par . {n . (op . abs)}
  184. end;
  185. procedure ofsf_irl2atl(op,irl,n);
  186. % Ordered field standard form IRL to atomic formula list. [irl] is
  187. % an IRL; [n] is an integer. Returns a list of atomic formulas
  188. % containing the level-[n] atforms encoded in IRL.
  189. for each ir in irl join ofsf_ir2atl(op,ir,n);
  190. procedure ofsf_ir2atl(op,ir,n);
  191. (for each le in cdr ir join
  192. if car le = n then {ofsf_entry2at(op,cdr le,a)}) where a=!*f2q car ir;
  193. procedure ofsf_entry2at(op,entry,parasq);
  194. if !*rlidentify then
  195. cl_identifyat ofsf_entry2at1(op,entry,parasq)
  196. else
  197. ofsf_entry2at1(op,entry,parasq);
  198. procedure ofsf_entry2at1(op,entry,parasq);
  199. ofsf_0mk2(ofsf_clnegrel(car entry,op eq 'and),numr addsq(parasq,cdr entry));
  200. procedure ofsf_sminsert(le,db);
  201. % Ordered field standard form smart simplify insert. [le] is a
  202. % marked entry; [db] is a database. Returns a database.
  203. % Destructively inserts [le] into [db].
  204. begin scalar a,w,scdb,oscdb;
  205. repeat <<
  206. w := ofsf_sminsert1(cadr car db,cddr car db,cadr le,cddr le,car le);
  207. if w and not idp w then << % identifiers [false] and [true] possible.
  208. db := cdr db;
  209. le := w
  210. >>
  211. >> until null w or idp w or null db;
  212. if w eq 'false then return 'false;
  213. if w eq 'true then return db;
  214. if null db then return {le};
  215. oscdb := db;
  216. scdb := cdr db;
  217. while scdb do <<
  218. a := car scdb;
  219. scdb := cdr scdb;
  220. w := ofsf_sminsert1(cadr a,cddr a,cadr le,cddr le,car le);
  221. if w eq 'true then <<
  222. scdb := nil;
  223. a := 'true
  224. >> else if w eq 'false then <<
  225. scdb := nil;
  226. a := 'false
  227. >> else if w then <<
  228. cdr oscdb := scdb;
  229. le := w
  230. >> else
  231. oscdb := cdr oscdb
  232. >>;
  233. if a eq 'false then return 'false;
  234. if a eq 'true then return db;
  235. return le . db
  236. end;
  237. procedure ofsf_sminsert1(r1,a,r2,b,n);
  238. % Ordered field standard form smart simplify insert. [r1], [r2] are
  239. % relations, [a], [b] are absolute summands in SQ representation;
  240. % [n] is the current level. Returns [nil], [false], [true], or a
  241. % marked entry. Simplification of $\alpha=[r2](f+b,0)$ under the
  242. % condition $\gamma=[r1](f+a,0)$ is considered: [nil] means there
  243. % is no simplification posssible; [true] means that $\gamma$
  244. % implies $\alpha$; [false] means that $\alpha$ contradicts
  245. % $\gamma$; the atomic formula encoded by a resulting marked entry
  246. % wrt. $f$ is equivalent to $\alpha$ under $\gamma$.
  247. begin scalar w,diff,n;
  248. diff := numr subtrsq(a,b);
  249. if null diff then <<
  250. w := ofsf_smeqtable(r1,r2);
  251. if w eq 'false then return 'false;
  252. if r1 eq w then return 'true;
  253. return n . (w . a)
  254. >>;
  255. if minusf diff then <<
  256. w := ofsf_smordtable(r1,r2);
  257. if atom w then return w;
  258. if eqcar(w,r1) and cdr w then return 'true;
  259. return n . (car w . if cdr w then a else b)
  260. >>;
  261. w := ofsf_smordtable(r2,r1);
  262. if atom w then return w;
  263. if eqcar(w,r1) and null cdr w then return 'true;
  264. return n . (car w . if cdr w then b else a)
  265. end;
  266. procedure ofsf_smeqtable(r1,r2);
  267. % Ordered field standard form smart simplify equal absolute
  268. % summands table. [r1], [r2] are relations. Returns [false] or a
  269. % relation $R$ such that $R(f+a,0)$ is equivalent to $[r1](f+a,0)
  270. % \land [r2](f+a,0)$.
  271. begin scalar al;
  272. al := '((equal . ((equal . equal) (neq . false) (geq . equal)
  273. (leq . equal) (greaterp . false) (lessp . false)))
  274. (neq . ((neq . neq) (geq . greaterp) (leq . lessp)
  275. (greaterp . greaterp) (lessp . lessp)))
  276. (geq . ((geq . geq) (leq . equal) (greaterp . greaterp)
  277. (lessp . false)))
  278. (leq . ((leq . leq) (greaterp . false) (lessp . lessp)))
  279. (greaterp . ((greaterp . greaterp) (lessp . false)))
  280. (lessp . ((lessp . lessp))));
  281. return cdr (atsoc(r2,atsoc(r1,al)) or atsoc(r1,atsoc(r2,al)))
  282. end;
  283. procedure ofsf_smordtable(r1,r2);
  284. % Ordered field standard form smart simplify ordered absolute
  285. % summands table. [r1], [r2] are relations. Returns [nil], which
  286. % means that no simplification is possible, [false] or a pair $R .
  287. % s$ where $R$ is a relation and $s$ is one of [T], [nil]. For
  288. % absolute summands $a<b$ we have $[r1](f+a,0) \land [r2](f+b,0)$
  289. % equivalent to $R(f+a,0)$ in case $[s]=[T]$ or to $R(f+b,0)$ in
  290. % case $[s]=[nil]$.
  291. begin scalar al;
  292. al := '((equal . ((equal . false) (neq . (equal . T)) (geq . (equal .T))
  293. (leq . false) (greaterp . (equal . T)) (lessp . false)))
  294. (neq . ((equal . (equal . nil)) (neq . nil) (geq . nil)
  295. (leq . (leq . nil)) (greaterp . nil) (lessp . (lessp . nil))))
  296. (geq . ((equal . false) (neq . (geq . T)) (geq . (geq . T))
  297. (leq . false) (greaterp . (geq . T)) (lessp . false)))
  298. (leq . ((equal . (equal . nil)) (neq . nil) (geq . nil)
  299. (leq . (leq . nil)) (greaterp . nil) (lessp . (lessp . nil))))
  300. (greaterp . ((equal . false) (neq . (greaterp . T))
  301. (geq . (greaterp . T)) (leq . false) (greaterp . (greaterp . T))
  302. (lessp . false)))
  303. (lessp . ((equal . (equal . nil)) (neq . nil) (geq . nil)
  304. (leq . (leq . nil)) (greaterp . nil) (lessp . (lessp . nil)))));
  305. return cdr atsoc(r2,atsoc(r1,al))
  306. end;
  307. endmodule; % [ofsfsism]
  308. end; % of file