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 session --------";
15 "----------- conditional rewriting without Isac session -";
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 "----------- fun rewrite_ down to Pattern.match ------------------------------------------------";
26 "----------- fun mk_thm ------------------------------------------------------------------------";
27 "--------------------------------------------------------";
28 "--------------------------------------------------------";
29 "--------------------------------------------------------";
32 "----------- assemble rewrite ---------------------------";
33 "----------- assemble rewrite ---------------------------";
34 "----------- assemble rewrite ---------------------------";
35 "===== rewriting by thm with 'a";
36 (*show_types := true;*)
38 val thy = @{theory Complex_Main};
39 val ctxt = @{context};
40 val thm = @{thm add.commute};
41 val t = (Thm.term_of o the) (parse thy "((r + u) + t) + s");
42 "----- from old: fun rewrite__";
44 val r = (((inst_bdv bdv) o norm o #prop o Thm.rep_thm) thm);
45 "----- from old: and rew_sub";
46 val (LHS,RHS) = (dest_equals' o strip_trueprop
47 o Logic.strip_imp_concl) r;
49 val insts = Pattern.match thy (LHS,t) (Vartab.empty, Vartab.empty);*)
50 "----- fun match_rew in Pure/pattern.ML";
51 val rtm = the_default RHS (Term.rename_abs LHS t RHS);
53 writeln(Syntax.string_of_term ctxt rtm);
54 writeln(Syntax.string_of_term ctxt LHS);
55 writeln(Syntax.string_of_term ctxt t);
57 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty));
58 val (rew, RHS) = (Envir.subst_term
59 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty)) rtm, rtm);
60 (*lookup in isabelle?trace?response...*)
61 writeln(Syntax.string_of_term ctxt rew);
62 writeln(Syntax.string_of_term ctxt RHS);
63 "===== rewriting: prep insertion into rew_sub";
64 val thy = @{theory Complex_Main};
65 val ctxt = @{context};
66 val thm = @{thm nonzero_divide_mult_cancel_right};
67 val r = Thm.prop_of thm;
68 val tm = @{term "x / (2 * x)::real"};
70 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
71 o Logic.strip_imp_concl) r;
72 val r' = Envir.subst_term (Pattern.match thy (LHS, tm)
73 (Vartab.empty, Vartab.empty)) r;
74 val p' = (fst o Logic.strip_prems) (Logic.count_prems r', [], r');
75 val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
76 o Logic.strip_imp_concl) r';
78 (*is displayed on top of <response> buffer...*)
79 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r');
80 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} t');
83 "----------- test rewriting without Isac's thys ---------";
84 "----------- test rewriting without Isac's thys ---------";
85 "----------- test rewriting without Isac's thys ---------";
87 "===== rewriting with Isabelle2009-1 only, i.e without isac-hacks";
88 val thy = @{theory Complex_Main};
89 val ctxt = @{context};
90 val thm = @{thm add.commute};
91 val tm = @{term "x + y*z::real"};
93 val SOME (r,_) = (rewrite_ thy dummy_ord e_rls false thm tm)
94 handle _ => error "rewrite.sml diff.behav. in rewriting";
95 (*is displayed on _TOP_ of <response> buffer...*)
96 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
97 if r = @{term "y*z + x::real"}
98 then () else error "rewrite.sml diff.result in rewriting";
100 "----- rewriting a subterm";
101 val tm = @{term "w*(x + y*z)::real"};
103 val SOME (r,_) = (rewrite_ thy dummy_ord e_rls false thm tm)
104 handle _ => error "rewrite.sml diff.behav. in rew_sub";
106 "----- ordered rewriting";
107 fun tord (_:subst) pp = Term_Ord.termless pp;
108 if tord [] (@{term "x + y*z::real"}, @{term "y*z + x::real"}) then ()
109 else error "rewrite.sml diff.behav. in ord.rewr.";
111 val NONE = (rewrite_ thy tord e_rls false thm tm)
112 handle _ => error "rewrite.sml diff.behav. in rewriting";
113 (*is displayed on _TOP_ of <response> buffer...*)
114 Pretty.writeln (Proof_Context.pretty_term_abbrev @{context} r);
116 val tm = @{term "x*y + z::real"};
117 val SOME (r,_) = (rewrite_ thy tord e_rls false thm tm)
118 handle _ => error "rewrite.sml diff.behav. in rewriting";
121 "----------- conditional rewriting without Isac's thys --";
122 "----------- conditional rewriting without Isac's thys --";
123 "----------- conditional rewriting without Isac's thys --";
125 "===== prepr cond.rew. with Pattern.match";
126 val thy = @{theory Complex_Main};
127 val ctxt = @{context};
128 val thm = @{thm nonzero_divide_mult_cancel_right};
129 val rule = Thm.prop_of thm;
130 val tm = @{term "x / (2 * x)::real"};
132 val prem = Logic.strip_imp_prems rule;
133 val nps = Logic.count_prems rule;
134 val prems = Logic.strip_prems (nps, [], rule);
136 val eq = Logic.strip_imp_concl rule;
137 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop) eq;
139 val mtcs = Pattern.match thy (LHS, tm) (Vartab.empty, Vartab.empty);
140 val rule' = Envir.subst_term mtcs rule;
142 val prems' = (fst o Logic.strip_prems)
143 (Logic.count_prems rule', [], rule');
144 val RHS' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
145 o Logic.strip_imp_concl) rule';
147 "----- conditional rewriting creating an assumption";
148 "----- conditional rewriting creating an assumption";
149 val thm = @{thm nonzero_divide_mult_cancel_right};
150 val tm = @{term "x / (2 * x)::real"};
151 val SOME (rew, asm) = (rewrite_ thy dummy_ord e_rls false thm tm)
152 handle _ => error "rewrite.sml diff.behav. in cond.rew.";
154 if rew = @{term "1 / 2::real"} then () (* the rewrite is _NO_ Trueprop *)
155 else error "rewrite.sml diff.result in cond.rew.";
157 if hd asm = @{term "x \<noteq> (0::real)"} (* dropped Trueprop $ ...*)
158 then () else error "rewrite.sml diff.asm in cond.rew.";
159 "----- conditional rewriting immediately: can only be done with ";
160 "------Isabelle numerals, because erls cannot handle them yet.";
163 "----------- step through 'and rew_sub': ----------------";
164 "----------- step through 'and rew_sub': ----------------";
165 "----------- step through 'and rew_sub': ----------------";
166 (*and make asms without Trueprop, beginning with the result:*)
167 val tm = @{term "x / (2 * x)::real"};
168 val (t', asm, _, _) = rew_sub thy 0 [] dummy_ord e_rls true [] (Thm.prop_of thm) tm;
169 (*show_types := false;*)
170 "----- evaluate arguments";
171 val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) =
172 (thy, 0, [], dummy_ord, e_rls, true, [], (Thm.prop_of thm), tm);
173 "----- step 1: LHS, RHS of rule";
174 val (LHS, RHS) = (HOLogic.dest_eq o HOLogic.dest_Trueprop
175 o Logic.strip_imp_concl) r;
176 term2str r = "?b \<noteq> (0::?'a) \<Longrightarrow> ?b / (?a * ?b) = (1::?'a) / ?a";
177 term2str LHS = "?b / (?a * ?b)"; term2str RHS = "(1::?'a) / ?a";
178 "----- step 2: the rule instantiated";
179 val r' = Envir.subst_term
180 (Pattern.match thy (LHS, t) (Vartab.empty, Vartab.empty)) r;
181 term2str r' = "x \<noteq> 0 \<Longrightarrow> x / (2 * x) = 1 / 2";
182 "----- step 3: get the (instantiated) assumption(s)";
183 val p' = (fst o Logic.strip_prems) (Logic.count_prems r', [], r');
184 term2str (hd p') = "x \<noteq> 0";
185 "=====vvv make asms without Trueprop ---vvv";
186 val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems)
187 (Logic.count_prems r', [], r'));
189 [Const ("HOL.Not", _) $ (Const ("HOL.eq", _)
190 $ Free ("x", _) $ Const ("Groups.zero_class.zero", _))] => ()
191 | _ => error "rewrite.sml assumption changed";
192 "=====^^^ make asms without Trueprop ---^^^";
193 "----- step 4: get the (instantiated) RHS";
194 val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop
195 o Logic.strip_imp_concl) r';
196 term2str t' = "1 / 2";
198 "----------- step through 'fun rewrite_terms_' ---------";
199 "----------- step through 'fun rewrite_terms_' ---------";
200 "----------- step through 'fun rewrite_terms_' ---------";
201 "----- step 0: args for rewrite_terms_, local fun";
202 val (thy, ord, erls, equs, t) =
203 (@{theory "Biegelinie"}, dummy_ord, Erls, [str2term "x = 0"],
204 str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2");
205 "----- step 1: args for rew_";
206 val ((t', asm'), (rules as r::rs), t) = ((e_term, []), equs, t);
207 "----- step 2: rew_sub";
208 rew_sub thy 1 [] ord erls false [] (Trueprop $ r) t;
209 "----- step 3: step through rew_sub -- inefficient: goes into subterms";
212 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
213 writeln "----------- rewrite_terms_ 1---------------------------";
214 if term2str t' = "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
215 else error "rewrite.sml rewrite_terms_ [x = 0]";
217 val equs = [str2term "M_b 0 = 0"];
218 val t = str2term "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2";
219 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
220 writeln "----------- rewrite_terms_ 2---------------------------";
221 if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
222 else error "rewrite.sml rewrite_terms_ [M_b 0 = 0]";
224 val equs = [str2term "x = 0", str2term"M_b 0 = 0"];
225 val t = str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2";
226 val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t;
227 writeln "----------- rewrite_terms_ 3---------------------------";
228 if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then ()
229 else error "rewrite.sml rewrite_terms_ [x = 0, M_b 0 = 0]";
232 "----------- rewrite_inst_ bdvs -------------------------";
233 "----------- rewrite_inst_ bdvs -------------------------";
234 "----------- rewrite_inst_ bdvs -------------------------";
235 (*see smltest/Scripts/term_G.sml: inst_bdv 2*)
236 val t = str2term"-1 * (q_0 * L ^^^ 2) / 2 + (L * c_3 + c_4) = 0";
237 val bdvs = [(str2term"bdv_1",str2term"c"),
238 (str2term"bdv_2",str2term"c_2"),
239 (str2term"bdv_3",str2term"c_3"),
240 (str2term"bdv_4",str2term"c_4")];
241 (*------------ outcommented WN071210, after inclusion into ROOT.ML
243 rewrite_inst_ thy e_rew_ord
244 (append_rls "erls_isolate_bdvs" e_rls
245 [(Calc ("EqSystem.occur'_exactly'_in",
246 eval_occur_exactly_in
247 "#eval_occur_exactly_in_"))
249 false bdvs (num_str @{separate_bdvs_add) t;
250 (writeln o term2str) t;
251 if term2str t = "L * c_3 + c_4 = 0 + -1 * (-1 * (q_0 * L ^^^ 2) / 2)"
252 then () else error "rewrite.sml rewrite_inst_ bdvs";
254 trace_rewrite:=false;--------------------------------------------*)
257 "----------- check diff 2002--2009-3 --------------------";
258 "----------- check diff 2002--2009-3 --------------------";
259 "----------- check diff 2002--2009-3 --------------------";
260 (*----- 2002 -------------------------------------------------------------------
261 # rls: norm_Rational_noadd_fractions on: 1 / EI * (L * q_0 * x / 2 + -1 *
263 ## rls: discard_minus_ on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2
265 ### try thm: real_diff_minus
266 ### try thm: sym_real_mult_minus1
267 ## rls: rat_mult_poly on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2
269 ### try thm: rat_mult_poly_l
270 ### try thm: rat_mult_poly_r
271 #### eval asms: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
272 ==> 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) =
273 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
274 ##### rls: e_rls-is_polyexp on: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2
276 ###### try calc: Poly.is'_polyexp'
277 ====== calc. to: False
278 ###### try calc: Poly.is'_polyexp'
279 ###### try calc: Poly.is'_polyexp'
280 #### asms false: ["L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp"]
281 ----- 2002 NONE rewrite --------------------------------------------------------
282 ----- 2009 should maintain this behaviour, but: --------------------------------
283 # rls: norm_Rational_noadd_fractions on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
284 ## rls: discard_minus on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
285 ### try thm: real_diff_minus
286 ### try thm: sym_real_mult_minus1
287 ## rls: rat_mult_poly on: 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)
288 ### try thm: rat_mult_poly_l
289 ### try thm: rat_mult_poly_r
290 #### eval asms: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
291 ==> 1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) =
292 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
293 ##### rls: e_rls-is_polyexp on: L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp
294 ###### try calc: Poly.is'_polyexp'
295 ====== calc. to: False
296 ###### try calc: Poly.is'_polyexp'
297 ###### try calc: Poly.is'_polyexp'
298 #### asms accepted: ["L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2 is_polyexp"] stored: ["False"]
299 === rewrites to: 1 * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2) / EI
300 ----- 2009 -------------------------------------------------------------------*)
302 (*the situation as was before repair (asm without Trueprop) is outcommented*)
303 val thy = @{theory "Isac"};
304 "===== example which raised the problem =================";
305 val t = @{term "1 / EI * (L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)"};
306 "----- rewrite_set_inst_ norm_Rational_noadd_fractions--";
307 val subs = [(@{term "bdv"}, @{term "x"})];
308 val rls = norm_Rational_noadd_fractions;
309 val SOME (t', asms) = rewrite_set_inst_ thy true subs rls t;
310 if term2str t' = "1 / EI * (L * q_0 * x / 2 + -1 * 1 * q_0 * x ^^^ 2 / 2)" andalso
311 terms2str asms = "[]" then {}
312 else error "this was NONE with Isabelle2013-2 ?!?"
313 "----- rewrite_ rat_mult_poly_r--------------------------";
314 val thm = @{thm rat_mult_poly_r};
315 "?c::real is_polyexp ==> (?a::real) / (?b::real) * ?c = ?a * ?c / ?b";
316 val erls = append_rls "e_rls-is_polyexp" e_rls
317 [Calc ("Poly.is'_polyexp", eval_is_polyexp "")];
318 val NONE (*SOME (t'', _)*) = rewrite_ thy dummy_ord erls true thm t;
319 (*t' = t''; (*false because of further rewrites in t'*)*)
320 "----- rew_sub --------------------------------";
321 val (t''', _, _, _) = rew_sub thy 0 [] dummy_ord erls true [] (Thm.prop_of thm) t;
322 (*t'' = t'''; (*true*)*)
323 "----- rewrite_set_ erls --------------------------------";
324 val cond = @{term "(L * q_0 * x / 2 + -1 * q_0 * x ^^^ 2 / 2)"};
325 val NONE = rewrite_set_ thy true erls cond;
326 (* ^^^^^ goes with '====== calc. to: False' above from beginning*)
328 writeln "===== maximally simplified example =====================";
329 val t = @{term "a / b * (x / x ^^^ 2)"};
330 "?c::real is_polyexp ==> (?a::real) / (?b::real) * ?c = ?a * ?c / ?b";
331 writeln "----- rewrite_set_inst_ norm_Rational_noadd_fractions--";
332 val (*NONE*) SOME (t', asm) = rewrite_set_inst_ thy true subs rls t;
333 term2str t' = "a * x / (b * x ^^^ 2)"; (*rew. by thm outside test case*)
334 (*checked visually: trace_rewrite looks like above for 2009*)
336 writeln "----- rewrite_ rat_mult_poly_r--------------------------";
337 val NONE (*SOME (t'', _)*) = rewrite_ thy dummy_ord erls true thm t;
338 (*t' = t''; (*false because of further rewrites in t'*)*)
339 writeln "----- rew_sub --------------------------------";
340 val (t''', _, _, _) = rew_sub thy 0 [] dummy_ord erls true [] (Thm.prop_of thm) t;
341 (*t'' = t'''; (*true*)*)
342 writeln "----- rewrite_set_ erls --------------------------------";
343 val cond = @{term "(x / x ^^^ 2)"};
344 val NONE = rewrite_set_ thy true erls cond;
345 (* ^^^^^ goes with '====== calc. to: False' above from beginning*)
348 "----------- compare all prepat's existing 2010 ---------";
349 "----------- compare all prepat's existing 2010 ---------";
350 "----------- compare all prepat's existing 2010 ---------";
351 val thy = @{theory "Isac"};
352 val t = @{term "a + b * x = (0 ::real)"};
353 val pat = parse_patt thy "?l = (?r ::real)";
354 val precond = parse_patt thy "is_polynomial (?l::real)";(*no infix def*)
355 val precond = parse_patt thy "(?l::real) is_expanded";
357 val inst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
358 val preinst = Envir.subst_term inst precond;
361 "===== Rational.thy: cancel ===";
362 (* pat matched with the current term gives an environment
363 (or not: hen the Rrls not applied);
364 if pre1 and pre2 evaluate to @{term True} in this environment,
365 then the Rrls is applied. *)
366 val t = str2term "(a + b) / c ::real";
367 val pat = parse_patt thy "?r / ?s ::real";
368 val pres = [parse_patt thy "?r is_expanded", parse_patt thy "?s is_expanded"];
369 val prepat = [(pres, pat)];
370 val erls = rational_erls;
371 (* erls got from Rrls {erls, prepat, scr = Rfuns {normal_form, ...}, ...} *)
373 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
374 val asms = map (Envir.subst_term subst) pres;
375 if terms2str asms = "[\"a + b is_expanded\",\"c is_expanded\"]"
376 then () else error "rewrite.sml: prepat cancel subst";
377 if ([], true) = eval__true thy 0 asms [] erls
378 then () else error "rewrite.sml: prepat cancel eval__true";
380 "===== Rational.thy: add_fractions_p ===";
381 (* if each pat* matches with the current term, the Rrls is applied
382 (there are no preconditions to be checked, they are @{term True}) *)
383 val t = str2term "a / b + 1 / 2";
384 val pat = parse_patt thy "?r / ?s + ?u / ?v";
385 val pres = [@{term True}];
386 val prepat = [(pres, pat)];
387 val erls = rational_erls;
388 (* erls got from Rrls {erls, prepat, scr = Rfuns {normal_form, ...}, ...} *)
390 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
391 if ([], true) = eval__true thy 0 (map (Envir.subst_term subst) pres) [] erls
392 then () else error "rewrite.sml: prepat add_fractions_p";
394 "===== Poly.thy: order_mult_ ===";
395 (* ?p matched with the current term gives an environment,
396 which evaluates (the instantiated) "p is_multUnordered" to true*)
397 val t = str2term "x^^^2 * x";
398 val pat = parse_patt thy "?p :: real"
399 val pres = [parse_patt thy "?p is_multUnordered"];
400 val prepat = [(pres, pat)];
401 val erls = append_rls "e_rls-is_multUnordered" e_rls
402 [Calc ("Poly.is'_multUnordered",
403 eval_is_multUnordered "")];
405 val subst = Pattern.match thy (pat, t) (Vartab.empty, Vartab.empty);
406 val asms = map (Envir.subst_term subst) pres;
407 if terms2str asms = "[\"x ^^^ 2 * x is_multUnordered\"]"
408 then () else error "rewrite.sml: prepat order_mult_ subst";
409 if ([], true) = eval__true thy 0 asms [] erls
410 then () else error "rewrite.sml: prepat order_mult_ eval__true";
413 "----------- fun app_rev, Rrls, -------------------------";
414 "----------- fun app_rev, Rrls, -------------------------";
415 "----------- fun app_rev, Rrls, -------------------------";
416 val t = str2term "x^^^2 * x";
418 if is_multUnordered t then () else error "rewrite.sml diff. is_multUnordered 2";
419 val tm = str2term "(x^^^2 * x) is_multUnordered";
420 eval_is_multUnordered "testid" "" tm thy;
422 case eval_is_multUnordered "testid" "" tm thy of
423 SOME (_, Const ("HOL.Trueprop", _) $
424 (Const ("HOL.eq", _) $
425 (Const ("Poly.is'_multUnordered", _) $ _) $
426 Const ("HOL.True", _))) => ()
427 | _ => error "rewrite.sml diff. eval_is_multUnordered 2b";
429 tracing "----- begin rewrite x^^^2 * x ---"; trace_rewrite := true;
430 val SOME (t', _) = rewrite_set_ thy true order_mult_ t;
431 tracing "----- end rewrite x^^^2 * x ---"; trace_rewrite := false;
432 if term2str t' = "x * x ^^^ 2" then ()
433 else error "rewrite.sml Poly.is'_multUnordered doesn't work";
435 (* for achieving the previous result, the following code was taken apart *)
436 "----- rewrite__set_ ---";
437 val (thy, i, _, _, (rrls as Rrls _), t) = (thy, 0, true, [], order_mult_, tm);
438 val (t', asm, rew) = app_rev thy (i+1) rrls t;
440 val (thy, i, rrls, t) = (thy, (i+1), rrls, t);
441 fun chk_prepat thy erls [] t = true
442 | chk_prepat thy erls prepat t =
443 let fun chk (pres, pat) =
444 (let val subst: Type.tyenv * Envir.tenv =
445 Pattern.match thy (pat, t)
446 (Vartab.empty, Vartab.empty)
447 in snd (eval__true thy (i+1)
448 (map (Envir.subst_term subst) pres)
452 fun scan_ f [] = false (*scan_ NEVER called by []*)
453 | scan_ f (pp::pps) = if f pp then true
455 in scan_ chk prepat end;
457 (*.apply the normal_form of a rev-set.*)
458 fun app_rev' thy (Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}) t =
459 if chk_prepat thy erls prepat t
460 then ((*tracing("### app_rev': t = "^(term2str t));*)
463 (*fixme val NONE = app_rev' thy rrls t;*)
464 "----- app_rev' ---";
465 val (thy, Rrls{erls,prepat,scr=Rfuns{normal_form,...},...}, t) = (thy, rrls, t);
466 (*fixme false*) chk_prepat thy erls prepat t;
467 "----- chk_prepat ---";
468 val (thy, erls, prepat, t) = (thy, erls, prepat, t);
469 fun chk (pres, pat) =
470 (let val subst: Type.tyenv * Envir.tenv =
471 Pattern.match thy (pat, t)
472 (Vartab.empty, Vartab.empty)
473 in snd (eval__true thy (i+1)
474 (map (Envir.subst_term subst) pres)
478 fun scan_ f [] = false (*scan_ NEVER called by []*)
479 | scan_ f (pp::pps) = if f pp then true
481 tracing "=== poly.sml: scan_ chk prepat begin";
483 tracing "=== poly.sml: scan_ chk prepat end";
486 (*reestablish...*) val t = str2term "x ^^^ 2 * x";
487 val [(pres, pat)] = prepat;
488 val subst: Type.tyenv * Envir.tenv =
489 Pattern.match thy (pat, t)
490 (Vartab.empty, Vartab.empty);
492 (*fixme: asms = ["p is_multUnordered"]...instantiate*)
493 "----- eval__true ---";
494 val asms = (map (Envir.subst_term subst) pres);
495 if terms2str asms = "[\"x ^^^ 2 * x is_multUnordered\"]" then ()
496 else error "rewrite.sml: diff. is_multUnordered, asms";
497 val (thy, i, asms, bdv, rls) =
498 (thy, (i+1), [str2term "(x^^^2 * x) is_multUnordered"],
499 [] : (term * term) list, erls);
500 case eval__true thy i asms bdv rls of
502 | _ => error "rewrite.sml: diff. is_multUnordered, eval__true";
504 "----------- 2011 thms with axclasses -------------------";
505 "----------- 2011 thms with axclasses -------------------";
506 "----------- 2011 thms with axclasses -------------------";
507 val thm = num_str @{thm div_by_1};
508 val prop = Thm.prop_of thm;
509 atomty prop; (*Type 'a*)
510 val t = str2term "(2*x)/1"; (*Type real*)
512 val (thy, ro, er, inst) =
513 (@{theory "Isac"}, tless_true, eval_rls, [(@{term "bdv::real"}, @{term "x::real"})]);
514 val SOME (t, _) = rewrite_ thy ro er true thm t; (*real matches 'a ?via ring? etc*)
516 "----------- repair NO asms from rls RatEq_eliminate ----";
517 "----------- repair NO asms from rls RatEq_eliminate ----";
518 "----------- repair NO asms from rls RatEq_eliminate ----";
519 val t = str2term "1 / x = 5";
520 trace_rewrite := true;
521 val SOME (t', asm) = rewrite_ thy e_rew_ord e_rls true @{thm rat_mult_denominator_right} t;
522 term2str t' = "1 = 5 * x";
523 terms2str asm = "[\"x ~= 0\"]";
525 ## eval asms: x ~= 0 ==> (1 / x = 5) = (1 = 5 * x)
526 ### rls: e_rls on: x ~= 0
527 ## asms accepted: ["x ~= 0"] stored: ["x ~= 0"]
529 trace_rewrite := false;
531 trace_rewrite := false;
532 val SOME (t', []) = rewrite_set_ thy true RatEq_eliminate t; (*= [] must be = "x ~= 0"*)
533 term2str t' = "1 = 5 * x";
536 #### rls: rateq_erls on: x ~= 0
538 ##### try calc: HOL.eq' <<<------------------------------- here the error comes from
539 ===== calc. to: ~ False
540 ##### try calc: HOL.eq'
541 ##### try thm: not_true
542 ##### try thm: not_false
543 ===== rewrites to: True
545 ### asms accepted: ["x ~= 0"] stored: []
548 trace_rewrite := false;
549 (* WN120317.TODO dropped rateq: the above error is the same in 2002 *)
551 "----------- fun assoc_thm' -----------------------------";
552 "----------- fun assoc_thm' -----------------------------";
553 "----------- fun assoc_thm' -----------------------------";
554 val thy = @{theory ProgLang}
556 val tth = assoc_thm' thy ("sym_#mult_2_3","6 = 2 * 3");
557 if string_of_thm' thy tth = "6 = 2 * 3" then ()
558 else error "assoc_thm' (sym_#mult_2_3, 6 = 2 * 3) changed";
560 val tth = assoc_thm' thy ("add_0_left","");
561 if string_of_thm' thy tth = "0 + ?a = ?a" then ()
562 else error "assoc_thm' (add_0_left,\"\") changed";
564 val tth = assoc_thm' thy ("sym_add_0_left","");
565 if string_of_thm' thy tth = "?t = 0 + ?t" then ()
566 else error "assoc_thm' (sym_add_0_left,\"\") changed";
568 val tth = assoc_thm' thy ("add_commute","");
569 if string_of_thm' thy tth = "?a + ?b = ?b + ?a" then ()
570 else error "assoc_thm' (add_commute,\"\") changed"
572 "----------- fun rewrite_ down to Pattern.match ------------------------------------------------";
573 "----------- fun rewrite_ down to Pattern.match ------------------------------------------------";
574 "----------- fun rewrite_ down to Pattern.match ------------------------------------------------";
575 "~~~~~ fun rewrite_ , args:"; val (thy, rew_ord, erls, bool, thm, term) =
576 (@{theory}, dummy_ord, e_rls, false, @{thm distrib_left}, @{term "x * (y + z) :: int"});
577 "~~~~~ fun rewrite__ , args:"; val (thy, i, bdv, tless, rls, put_asm, thm, ct) =
578 (thy, 1, [], rew_ord, erls, bool, thm, term);
579 "~~~~~ and rew_sub , args:"; val (thy, i, bdv, tless, rls, put_asm, lrd, r, t) =
580 (thy, i, bdv, tless, rls, put_asm, [], (((inst_bdv bdv) o norm o #prop o Thm.rep_thm) thm), ct)
581 val (lhss, rhss) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r
582 val r' = Envir.subst_term (Pattern.match thy (lhss, t) (Vartab.empty, Vartab.empty)) r
583 val p' = map HOLogic.dest_Trueprop ((fst o Logic.strip_prems) (Logic.count_prems r', [], r'))
584 val t' = (snd o HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r'
586 if term2str lhss = "?a * (?b + ?c)" andalso term2str t = "x * (y + z)" then ()
587 else error "ARGS FOR Pattern.match CHANGED";
588 val match = Pattern.match thy (lhss, t) (Vartab.empty, Vartab.empty);
589 if (Envir.subst_term match r |> term2str) = "x * (y + z) = x * y + x * z" then ()
590 else error "Pattern.match CHANGED";
592 "----------- fun mk_thm ------------------------------------------------------------------------";
593 "----------- fun mk_thm ------------------------------------------------------------------------";
594 "----------- fun mk_thm ------------------------------------------------------------------------";
596 val str = "?r ^^^ 2 = ?r * ?r";
597 val thm = realpow_twoI;
599 val t1 = (#prop o rep_thm) (num_str thm);
600 val t2 = Trueprop $ ((Thm.term_of o the o (parse thy)) str);
602 val it = true : bool ... !!!
603 val th1 = (num_str thm);
604 val th2 = ((*num_str*) (mk_thm thy str)) handle e => print_exn e;
606 ML> val it = false : bool ... HIDDEN DIFFERENCES IRRELEVANT FOR ISAC ?!
608 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
609 val str = "k ~= 0 ==> m * k / (n * k) = m / n";
610 val thm = real_mult_div_cancel2;
612 val t1 = (#prop o rep_thm) (num_str thm);
613 val t2 = ((Thm.term_of o the o (parse thy)) str);
615 val it = false : bool ... Var .. Free
616 val th1 = (num_str thm);
617 val th2 = ((*num_str*) (mk_thm thy str)) handle e => print_exn e;
619 ML> val it = false : bool ... PLUS HIDDEN DIFFERENCES IRRELEVANT FOR ISAC ?!