1 (* Title: tests for ProgLang/rewrite.sml
2 TODO.WN0509 collect typical tests from systest here !!!!!
3 Author: Walther Neuper 050908
4 (c) copyright due to lincense terms.
6 12345678901234567890123456789012345678901234567890123456789012345678901234567890
7 10 20 30 40 50 60 70 80
10 "--------------------------------------------------------";
11 "table of contents --------------------------------------";
12 "--------------------------------------------------------";
13 "----------- assemble rewrite ---------------------------";
14 "----------- test rewriting without Isac's thys ---------";
15 "----------- conditional rewriting without Isac's thys --";
16 "----------- step through 'and rew_sub': ----------------";
17 "----------- step through 'fun rewrite_terms_' ---------";
18 "----------- rewrite_inst_ bdvs -------------------------";
19 "----------- check diff 2002--2009-3 --------------------";
20 "----------- compare all prepat's existing 2010 ---------";
21 "----------- fun app_rev, Rrls, -------------------------";
22 "----------- 2011 thms with axclasses -------------------";
23 "----------- repair NO asms from rls RatEq_eliminate ----";
24 "----------- fun assoc_thm' -----------------------------";
25 "--------------------------------------------------------";
26 "--------------------------------------------------------";
27 "--------------------------------------------------------";
30 "----------- assemble rewrite ---------------------------";
31 "----------- assemble rewrite ---------------------------";
32 "----------- assemble rewrite ---------------------------";
33 "===== rewriting by thm with 'a";
34 (*show_types := true;*)
36 val thy = @{theory Complex_Main};
37 val ctxt = @{context};
38 val thm = @{thm add_commute};
39 val t = (term_of o the) (parse thy "((r + u) + t) + s");
40 "----- from old: fun rewrite__";
42 val r = (((inst_bdv bdv) o norm o #prop o rep_thm) thm);
43 "----- from old: and rew_sub";
44 val (LHS,RHS) = (dest_equals' o strip_trueprop
45 o Logic.strip_imp_concl) r;
47 val insts = Pattern.match thy (LHS,t) (Vartab.empty, Vartab.empty);*)
48 "----- fun match_rew in Pure/pattern.ML";
49 val rtm = the_default RHS (Term.rename_abs LHS t RHS);
51 writeln(Syntax.string_of_term ctxt rtm);
52 writeln(Syntax.string_of_term ctxt LHS);
53 writeln(Syntax.string_of_term ctxt t);
55 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty));
56 val (rew, RHS) = (Envir.subst_term
57 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty)) rtm, rtm);
58 (*lookup in isabelle?trace?response...*)
59 writeln(Syntax.string_of_term ctxt rew);
60 writeln(Syntax.string_of_term ctxt RHS);
61 "===== rewriting: prep insertion into rew_sub";
62 val thy = @{theory Complex_Main};
63 val ctxt = @{context};
64 val thm = @{thm nonzero_mult_divide_cancel_right};
65 val r = Thm.prop_of thm;
66 val tm = @{term "x*2 / 2::real"};
68 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
69 o Logic.strip_imp_concl) r;
70 val r' = Envir.subst_term (Pattern.match thy (LHS, tm)
71 (Vartab.empty, Vartab.empty)) r;
72 val p' = (fst o Logic.strip_prems) (Logic.count_prems r', [], r');
73 val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
74 o Logic.strip_imp_concl) r';
76 (*is displayed on top of <response> buffer...*)
77 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r');
78 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} t');
81 "----------- test rewriting without Isac's thys ---------";
82 "----------- test rewriting without Isac's thys ---------";
83 "----------- test rewriting without Isac's thys ---------";
85 "===== rewriting with Isabelle2009-1 only, i.e without isac-hacks";
86 val thy = @{theory Complex_Main};
87 val ctxt = @{context};
88 val thm = @{thm add_commute};
89 val tm = @{term "x + y*z::real"};
91 val SOME (r,_) = (rewrite_ thy dummy_ord e_rls false thm tm)
92 handle _ => error "rewrite.sml diff.behav. in rewriting";
93 (*is displayed on _TOP_ of <response> buffer...*)
94 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
95 if r = @{term "y*z + x::real"}
96 then () else error "rewrite.sml diff.result in rewriting";
98 "----- rewriting a subterm";
99 val tm = @{term "w*(x + y*z)::real"};
101 val SOME (r,_) = (rewrite_ thy dummy_ord e_rls false thm tm)
102 handle _ => error "rewrite.sml diff.behav. in rew_sub";
104 "----- ordered rewriting";
105 fun tord (_:subst) pp = Term_Ord.termless pp;
106 if tord [] (@{term "x + y*z::real"}, @{term "y*z + x::real"}) then ()
107 else error "rewrite.sml diff.behav. in ord.rewr.";
109 val NONE = (rewrite_ thy tord e_rls false thm tm)
110 handle _ => error "rewrite.sml diff.behav. in rewriting";
111 (*is displayed on _TOP_ of <response> buffer...*)
112 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
114 val tm = @{term "x*y + z::real"};
115 val SOME (r,_) = (rewrite_ thy tord e_rls false thm tm)
116 handle _ => error "rewrite.sml diff.behav. in rewriting";
119 "----------- conditional rewriting without Isac's thys --";
120 "----------- conditional rewriting without Isac's thys --";
121 "----------- conditional rewriting without Isac's thys --";
123 "===== prepr cond.rew. with Pattern.match";
124 val thy = @{theory Complex_Main};
125 val ctxt = @{context};
126 val thm = @{thm nonzero_mult_divide_cancel_right};
127 val rule = Thm.prop_of thm;
128 val tm = @{term "x*2 / 2::real"};
130 val prem = Logic.strip_imp_prems rule;
131 val nps = Logic.count_prems rule;
132 val prems = Logic.strip_prems (nps, [], rule);
134 val eq = Logic.strip_imp_concl rule;
135 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop) eq;
137 val mtcs = Pattern.match thy (LHS, tm) (Vartab.empty, Vartab.empty);
138 val rule' = Envir.subst_term mtcs rule;
140 val prems' = (fst o Logic.strip_prems)
141 (Logic.count_prems rule', [], rule');
142 val RHS' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
143 o Logic.strip_imp_concl) rule';
145 "----- conditional rewriting creating an assumption";
146 "----- conditional rewriting creating an assumption";
147 val tm = @{term "x*y / y::real"};
148 val SOME (rew, asm) = (rewrite_ thy dummy_ord e_rls false thm tm)
149 handle _ => error "rewrite.sml diff.behav. in cond.rew.";
151 if rew = @{term "x::real"} then () (* the rewrite is _NO_ Trueprop *)
152 else error "rewrite.sml diff.result in cond.rew.";
154 if hd asm = @{term "~ y = (0::real)"} (* dropped Trueprop $ ...*)
155 then () else error "rewrite.sml diff.asm in cond.rew.";
156 "----- conditional rewriting immediately: can only be done with ";
157 "------Isabelle numerals, because erls cannot handle them yet.";
160 "----------- step through 'and rew_sub': ----------------";
161 "----------- step through 'and rew_sub': ----------------";
162 "----------- step through 'and rew_sub': ----------------";
163 (*and make asms without Trueprop, beginning with the result:*)
164 val tm = @{term "x*y / y::real"};
165 val (t', asm, _, _) = rew_sub thy 0 [] dummy_ord e_rls true [] (prop_of thm) tm;
166 (*show_types := false;*)
167 "----- evaluate arguments";
168 val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) =
169 (thy, 0, [], dummy_ord, e_rls, true, [], (prop_of thm), tm);
170 "----- step 1: LHS, RHS of rule";
171 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
172 o Logic.strip_imp_concl) r;
173 term2str r = "?b ~= (0::?'a) ==> ?a * ?b / ?b = ?a";
174 term2str LHS = "?a * ?b / ?b"; term2str RHS = "?a";
175 "----- step 2: the rule instantiated";
176 val r' = Envir.subst_term
177 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty)) r;
178 term2str r' = "y ~= 0 ==> x * y / y = x";
179 "----- step 3: get the (instantiated) assumption(s)";
180 val p' = (fst o Logic.strip_prems) (Logic.count_prems r', [], r');
181 term2str (hd p') = "y ~= 0";
182 "=====vvv make asms without Trueprop ---vvv";
183 val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems)
184 (Logic.count_prems r', [], r'));
186 [Const ("HOL.Not", _) $ (Const ("HOL.eq", _) $ Free ("y", _) $
187 Const ("Groups.zero_class.zero", _))] => ()
188 | _ => error "rewrite.sml assumption changed";
189 "=====^^^ make asms without Trueprop ---^^^";
190 "----- step 4: get the (instantiated) RHS";
191 val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
192 o Logic.strip_imp_concl) r';
195 "----------- step through 'fun rewrite_terms_' ---------";
196 "----------- step through 'fun rewrite_terms_' ---------";
197 "----------- step through 'fun rewrite_terms_' ---------";
198 "----- step 0: args for rewrite_terms_, local fun";
199 val (thy, ord, erls, equs, t) =
200 (@{theory "Biegelinie"}, dummy_ord, Erls, [str2term "x = 0"],
201 str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2");
202 "----- step 1: args for rew_";
203 val ((t', asm'), (rules as r::rs), t) = ((e_term, []), equs, t);
204 "----- step 2: rew_sub";
205 rew_sub thy 1 [] ord erls false [] (Trueprop $ r) t;
206 "----- step 3: step through rew_sub -- inefficient: goes into subterms";
209 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
210 writeln "----------- rewrite_terms_ 1---------------------------";
211 if term2str t' = "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
212 else error "rewrite.sml rewrite_terms_ [x = 0]";
214 val equs = [str2term "M_b 0 = 0"];
215 val t = str2term "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2";
216 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
217 writeln "----------- rewrite_terms_ 2---------------------------";
218 if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
219 else error "rewrite.sml rewrite_terms_ [M_b 0 = 0]";
221 val equs = [str2term "x = 0", str2term"M_b 0 = 0"];
222 val t = str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2";
223 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
224 writeln "----------- rewrite_terms_ 3---------------------------";
225 if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
226 else error "rewrite.sml rewrite_terms_ [x = 0, M_b 0 = 0]";
229 "----------- rewrite_inst_ bdvs -------------------------";
230 "----------- rewrite_inst_ bdvs -------------------------";
231 "----------- rewrite_inst_ bdvs -------------------------";
232 (*see smltest/Scripts/term_G.sml: inst_bdv 2*)
233 val t = str2term"-1 * (q_0 * L ^^^ 2) / 2 + (L * c_3 + c_4) = 0";
234 val bdvs = [(str2term"bdv_1",str2term"c"),
235 (str2term"bdv_2",str2term"c_2"),
236 (str2term"bdv_3",str2term"c_3"),
237 (str2term"bdv_4",str2term"c_4")];
238 (*------------ outcommented WN071210, after inclusion into ROOT.ML
240 rewrite_inst_ thy e_rew_ord
241 (append_rls "erls_isolate_bdvs" e_rls
242 [(Calc ("EqSystem.occur'_exactly'_in",
243 eval_occur_exactly_in
244 "#eval_occur_exactly_in_"))
246 false bdvs (num_str @{separate_bdvs_add) t;
247 (writeln o term2str) t;
248 if term2str t = "L * c_3 + c_4 = 0 + -1 * (-1 * (q_0 * L ^^^ 2) / 2)"
249 then () else error "rewrite.sml rewrite_inst_ bdvs";
251 trace_rewrite:=false;--------------------------------------------*)
254 "----------- check diff 2002--2009-3 --------------------";
255 "----------- check diff 2002--2009-3 --------------------";
256 "----------- check diff 2002--2009-3 --------------------";
257 (*----- 2002 -------------------------------------------------------------------
258 # rls: norm_Rational_noadd_fractions on: 1 / EI * (L * q_0 * x / 2 + -1 *
260 ## rls: discard_minus_ on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2
262 ### try thm: real_diff_minus
263 ### try thm: sym_real_mult_minus1
264 ## rls: rat_mult_poly on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2
266 ### try thm: rat_mult_poly_l
267 ### try thm: rat_mult_poly_r
268 #### eval asms: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
269 ==> 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) =
270 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
271 ##### rls: e_rls-is_polyexp on: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2
273 ###### try calc: Poly.is'_polyexp'
274 ====== calc. to: False
275 ###### try calc: Poly.is'_polyexp'
276 ###### try calc: Poly.is'_polyexp'
277 #### asms false: ["L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp"]
278 ----- 2002 NONE rewrite --------------------------------------------------------
279 ----- 2009 should maintain this behaviour, but: --------------------------------
280 # rls: norm_Rational_noadd_fractions on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
281 ## rls: discard_minus on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
282 ### try thm: real_diff_minus
283 ### try thm: sym_real_mult_minus1
284 ## rls: rat_mult_poly on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
285 ### try thm: rat_mult_poly_l
286 ### try thm: rat_mult_poly_r
287 #### eval asms: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
288 ==> 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) =
289 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
290 ##### rls: e_rls-is_polyexp on: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
291 ###### try calc: Poly.is'_polyexp'
292 ====== calc. to: False
293 ###### try calc: Poly.is'_polyexp'
294 ###### try calc: Poly.is'_polyexp'
295 #### asms accepted: ["L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp"] stored: ["False"]
296 === rewrites to: 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
297 ----- 2009 -------------------------------------------------------------------*)
299 (*the situation as was before repair (asm without Trueprop) is outcommented*)
300 val thy = @{theory "Isac"};
301 "===== example which raised the problem =================";
302 val t = @{term "1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)"};
303 "----- rewrite_set_inst_ norm_Rational_noadd_fractions--";
304 val subs = [(str2term "bdv", str2term "x")];
305 val rls = norm_Rational_noadd_fractions;
306 val NONE (*SOME (t', _)*) = rewrite_set_inst_ thy true subs rls t;
307 "----- rewrite_ rat_mult_poly_r--------------------------";
308 val thm = @{thm rat_mult_poly_r};
309 "?c::real is_polyexp ==> (?a::real) / (?b::real) * ?c = ?a * ?c / ?b";
310 val erls = append_rls "e_rls-is_polyexp" e_rls
311 [Calc ("Poly.is'_polyexp", eval_is_polyexp "")];
312 val NONE (*SOME (t'', _)*) = rewrite_ thy dummy_ord erls true thm t;
313 (*t' = t''; (*false because of further rewrites in t'*)*)
314 "----- rew_sub --------------------------------";
315 val (t''', _, _, _) = rew_sub thy 0 [] dummy_ord erls true [] (prop_of thm) t;
316 (*t'' = t'''; (*true*)*)
317 "----- rewrite_set_ erls --------------------------------";
318 val cond = @{term "(L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)"};
319 val NONE = rewrite_set_ thy true erls cond;
320 (* ^^^^^ goes with '====== calc. to: False' above from beginning*)
322 writeln "===== maximally simplified example =====================";
323 val t = @{term "a / b * (x / x ^^^ 2)"};
324 "?c::real is_polyexp ==> (?a::real) / (?b::real) * ?c = ?a * ?c / ?b";
325 writeln "----- rewrite_set_inst_ norm_Rational_noadd_fractions--";
326 val (*NONE*) SOME (t', asm) = rewrite_set_inst_ thy true subs rls t;
327 term2str t' = "a * x / (b * x ^^^ 2)"; (*rew. by thm outside test case*)
328 (*checked visually: trace_rewrite looks like above for 2009*)
330 writeln "----- rewrite_ rat_mult_poly_r--------------------------";
331 val NONE (*SOME (t'', _)*) = rewrite_ thy dummy_ord erls true thm t;
332 (*t' = t''; (*false because of further rewrites in t'*)*)
333 writeln "----- rew_sub --------------------------------";
334 val (t''', _, _, _) = rew_sub thy 0 [] dummy_ord erls true [] (prop_of thm) t;
335 (*t'' = t'''; (*true*)*)
336 writeln "----- rewrite_set_ erls --------------------------------";
337 val cond = @{term "(x / x ^^^ 2)"};
338 val NONE = rewrite_set_ thy true erls cond;
339 (* ^^^^^ goes with '====== calc. to: False' above from beginning*)
342 "----------- compare all prepat's existing 2010 ---------";
343 "----------- compare all prepat's existing 2010 ---------";
344 "----------- compare all prepat's existing 2010 ---------";
345 val thy = @{theory "Isac"};
346 val t = @{term "a + b * x = (0 ::real)"};
347 val pat = parse_patt thy "?l = (?r ::real)";
348 val precond = parse_patt thy "is_polynomial (?l::real)";(*no infix def*)
349 val precond = parse_patt thy "(?l::real) is_expanded";
351 val inst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
352 val preinst = Envir.subst_term inst precond;
355 "===== Rational.thy: cancel ===";
356 (* pat matched with the current term gives an environment
357 (or not: hen the Rrls not applied);
358 if pre1 and pre2 evaluate to @{term True} in this environment,
359 then the Rrls is applied. *)
360 val t = str2term "(a + b) / c ::real";
361 val pat = parse_patt thy "?r / ?s ::real";
362 val pres = [parse_patt thy "?r is_expanded", parse_patt thy "?s is_expanded"];
363 val prepat = [(pres, pat)];
364 val erls = rational_erls;
365 (* erls got from Rrls {erls, prepat, scr = Rfuns {normal_form, ...}, ...} *)
367 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
368 val asms = map (Envir.subst_term subst) pres;
369 if terms2str asms = "[\"a + b is_expanded\",\"c is_expanded\"]"
370 then () else error "rewrite.sml: prepat cancel subst";
371 if ([], true) = eval__true thy 0 asms [] erls
372 then () else error "rewrite.sml: prepat cancel eval__true";
374 "===== Rational.thy: add_fractions_p ===";
375 (* if each pat* matches with the current term, the Rrls is applied
376 (there are no preconditions to be checked, they are @{term True}) *)
377 val t = str2term "a / b + 1 / 2";
378 val pat = parse_patt thy "?r / ?s + ?u / ?v";
379 val pres = [@{term True}];
380 val prepat = [(pres, pat)];
381 val erls = rational_erls;
382 (* erls got from Rrls {erls, prepat, scr = Rfuns {normal_form, ...}, ...} *)
384 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
385 if ([], true) = eval__true thy 0 (map (Envir.subst_term subst) pres) [] erls
386 then () else error "rewrite.sml: prepat add_fractions_p";
388 "===== Poly.thy: order_mult_ ===";
389 (* ?p matched with the current term gives an environment,
390 which evaluates (the instantiated) "p is_multUnordered" to true*)
391 val t = str2term "x^^^2 * x";
392 val pat = parse_patt thy "?p :: real"
393 val pres = [parse_patt thy "?p is_multUnordered"];
394 val prepat = [(pres, pat)];
395 val erls = append_rls "e_rls-is_multUnordered" e_rls
396 [Calc ("Poly.is'_multUnordered",
397 eval_is_multUnordered "")];
399 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
400 val asms = map (Envir.subst_term subst) pres;
401 if terms2str asms = "[\"x ^^^ 2 * x is_multUnordered\"]"
402 then () else error "rewrite.sml: prepat order_mult_ subst";
403 if ([], true) = eval__true thy 0 asms [] erls
404 then () else error "rewrite.sml: prepat order_mult_ eval__true";
407 "----------- fun app_rev, Rrls, -------------------------";
408 "----------- fun app_rev, Rrls, -------------------------";
409 "----------- fun app_rev, Rrls, -------------------------";
410 val t = str2term "x^^^2 * x";
412 if is_multUnordered t then () else error "rewrite.sml diff. is_multUnordered 2";
413 val tm = str2term "(x^^^2 * x) is_multUnordered";
414 eval_is_multUnordered "testid" "" tm thy;
416 case eval_is_multUnordered "testid" "" tm thy of
417 SOME (_, Const ("HOL.Trueprop", _) $
418 (Const ("HOL.eq", _) $
419 (Const ("Poly.is'_multUnordered", _) $ _) $
420 Const ("HOL.True", _))) => ()
421 | _ => error "rewrite.sml diff. eval_is_multUnordered 2b";
423 tracing "----- begin rewrite x^^^2 * x ---"; trace_rewrite := true;
424 val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
425 tracing "----- end rewrite x^^^2 * x ---"; trace_rewrite := false;
426 if term2str t' = "x * x ^^^ 2" then ()
427 else error "rewrite.sml Poly.is'_multUnordered doesn't work";
429 (* for achieving the previous result, the following code was taken apart *)
430 "----- rewrite__set_ ---";
431 val (thy, i, _, _, (rrls as Rrls _), t) = (thy, 0, true, [], order_mult_, tm);
432 val (t', asm, rew) = app_rev thy (i+1) rrls t;
434 val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
435 fun chk_prepat thy erls [] t = true
436 | chk_prepat thy erls prepat t =
437 let fun chk (pres, pat) =
438 (let val subst: Type.tyenv * Envir.tenv =
439 Pattern.match thy (pat, t)
440 (Vartab.empty, Vartab.empty)
441 in snd (eval__true thy (i+1)
442 (map (Envir.subst_term subst) pres)
446 fun scan_ f [] = false (*scan_ NEVER called by []*)
447 | scan_ f (pp::pps) = if f pp then true
449 in scan_ chk prepat end;
451 (*.apply the normal_form of a rev-set.*)
452 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
453 if chk_prepat thy erls prepat t
454 then ((*tracing("### app_rev': t = "^(term2str t));*)
457 (*fixme val NONE = app_rev' thy rrls t;*)
458 "----- app_rev' ---";
459 val (thy, Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}, t) = (thy, rrls, t);
460 (*fixme false*) chk_prepat thy erls prepat t;
461 "----- chk_prepat ---";
462 val (thy, erls, prepat, t) = (thy, erls, prepat, t);
463 fun chk (pres, pat) =
464 (let val subst: Type.tyenv * Envir.tenv =
465 Pattern.match thy (pat, t)
466 (Vartab.empty, Vartab.empty)
467 in snd (eval__true thy (i+1)
468 (map (Envir.subst_term subst) pres)
472 fun scan_ f [] = false (*scan_ NEVER called by []*)
473 | scan_ f (pp::pps) = if f pp then true
475 tracing "=== poly.sml: scan_ chk prepat begin";
477 tracing "=== poly.sml: scan_ chk prepat end";
480 (*reestablish...*) val t = str2term "x ^^^ 2 * x";
481 val [(pres, pat)] = prepat;
482 val subst: Type.tyenv * Envir.tenv =
483 Pattern.match thy (pat, t)
484 (Vartab.empty, Vartab.empty);
486 (*fixme: asms = ["p is_multUnordered"]...instantiate*)
487 "----- eval__true ---";
488 val asms = (map (Envir.subst_term subst) pres);
489 if terms2str asms = "[\"x ^^^ 2 * x is_multUnordered\"]" then ()
490 else error "rewrite.sml: diff. is_multUnordered, asms";
491 val (thy, i, asms, bdv, rls) =
492 (thy, (i+1), [str2term "(x^^^2 * x) is_multUnordered"],
493 [] : (term * term) list, erls);
494 case eval__true thy i asms bdv rls of
496 | _ => error "rewrite.sml: diff. is_multUnordered, eval__true";
498 "----------- 2011 thms with axclasses -------------------";
499 "----------- 2011 thms with axclasses -------------------";
500 "----------- 2011 thms with axclasses -------------------";
501 val thm = num_str @{thm divide_1};
502 val prop = prop_of thm;
503 atomty prop; (*Type 'a*)
504 val t = str2term "(2*x)/1"; (*Type real*)
506 val (thy, ro, er, inst) =
507 (@{theory "Isac"}, tless_true, eval_rls, [(@{term "bdv::real"}, @{term "x::real"})]);
508 val SOME (t, _) = rewrite_ thy ro er true thm t; (*real matches 'a ?via ring? etc*)
510 "----------- repair NO asms from rls RatEq_eliminate ----";
511 "----------- repair NO asms from rls RatEq_eliminate ----";
512 "----------- repair NO asms from rls RatEq_eliminate ----";
513 val t = str2term "1 / x = 5";
514 trace_rewrite := true;
515 val SOME (t', asm) = rewrite_ thy e_rew_ord e_rls true @{thm rat_mult_denominator_right} t;
516 term2str t' = "1 = 5 * x";
517 terms2str asm = "[\"x ~= 0\"]";
519 ## eval asms: x ~= 0 ==> (1 / x = 5) = (1 = 5 * x)
520 ### rls: e_rls on: x ~= 0
521 ## asms accepted: ["x ~= 0"] stored: ["x ~= 0"]
523 trace_rewrite := false;
525 trace_rewrite := false;
526 val SOME (t', []) = rewrite_set_ thy true RatEq_eliminate t; (*= [] must be = "x ~= 0"*)
527 term2str t' = "1 = 5 * x";
530 #### rls: rateq_erls on: x ~= 0
532 ##### try calc: HOL.eq' <<<------------------------------- here the error comes from
533 ===== calc. to: ~ False
534 ##### try calc: HOL.eq'
535 ##### try thm: not_true
536 ##### try thm: not_false
537 ===== rewrites to: True
539 ### asms accepted: ["x ~= 0"] stored: []
542 trace_rewrite := false;
543 (* WN120317.TODO dropped rateq: the above error is the same in 2002 *)
545 "----------- fun assoc_thm' -----------------------------";
546 "----------- fun assoc_thm' -----------------------------";
547 "----------- fun assoc_thm' -----------------------------";
548 val thy = @{theory ProgLang}
550 val tth = assoc_thm' thy ("sym_#mult_2_3","6 = 2 * 3");
551 if string_of_thm' thy tth = "6 = 2 * 3" then ()
552 else error "assoc_thm' (sym_#mult_2_3, 6 = 2 * 3) changed";
554 val tth = assoc_thm' thy ("add_0_left","");
555 if string_of_thm' thy tth = "0 + ?a = ?a" then ()
556 else error "assoc_thm' (add_0_left,\"\") changed";
558 val tth = assoc_thm' thy ("sym_add_0_left","");
559 if string_of_thm' thy tth = "?t = 0 + ?t" then ()
560 else error "assoc_thm' (sym_add_0_left,\"\") changed";
562 val tth = assoc_thm' thy ("add_commute","");
563 if string_of_thm' thy tth = "?a + ?b = ?b + ?a" then ()
564 else error "assoc_thm' (add_commute,\"\") changed"