1 (* Title: "ProgLang/evaluate.sml"
2 test calculation of values for function constants
3 Author: Walther Neuper 2000
4 (c) copyright due to lincense terms.
7 "--------------------------------------------------------";
8 "table of contents --------------------------------------";
9 "--------------------------------------------------------";
10 "-calculate.thy: provides 'setup' -----------------------";
11 "----------- fun norm -----------------------------------";
12 "----------- check return value of adhoc_thm ----";
13 "----------- fun calculate_ --------------------------------------------------------------------";
14 "----------- calculate from Prog --------------------------------- -----------------------------";
15 "----------- calculate from script --requires 'setup'----";
16 "----------- calculate check test-root-equ --------------";
17 "----------- check calculate bottom up -----------------";
18 "----------- Prog_Expr.pow Power.power_class.power ---------";
19 "----------- fun cancel_int --------------------------------------------------------------------";
20 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
21 "----------- get_pair with 3 args -----------------------";
22 "----------- calculate (2 * x is_num) -------------------";
23 "----------- fun get_pair: examples ------------------------------------------------------------";
24 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
25 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
26 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
27 "----------- fun power -------------------------------------------------------------------------";
28 "----------- fun divisors ----------------------------------------------------------------------";
29 "----------- fun doubles, fun squfact ----------------------------------------------------------";
30 "--------------------------------------------------------";
31 "--------------------------------------------------------";
32 "--------------------------------------------------------";
34 "----------- check return value of adhoc_thm ----";
35 "----------- check return value of adhoc_thm ----";
36 "----------- check return value of adhoc_thm ----";
37 val thy = @{theory "Poly"};
38 val cal = snd (assoc_calc' thy "is_polyexp");
39 val t = @{term "(x / x) is_polyexp"};
40 val SOME (thmID, thm) = adhoc_thm thy cal t;
41 (HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop")
43 error "evaluate.sml: adhoc_thm must return Trueprop";
45 "----------- fun calculate_ --------------------------------------------------------------------";
46 "----------- fun calculate_ --------------------------------------------------------------------";
47 "----------- fun calculate_ --------------------------------------------------------------------";
48 (* fun rewrite__set_ \<longrightarrow> fun rew_once works the same way *)
49 val t = TermC.str2term "((1+2)*4/3) \<up> 2";
51 val times = ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
52 val plus = ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
53 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
54 val pow = ("Transcendental.powr", eval_binop "#power_") : string * Eval_Def.eval_fn;
56 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
57 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
58 val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
59 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed";
61 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
62 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
63 val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
64 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed";
66 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
67 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
68 val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
69 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed";
71 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
72 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
73 val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
74 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed";
76 "----------- calculate from Prog --------------------------------- -----------------------------";
77 "----------- calculate from Prog --------------------------------- -----------------------------";
78 "----------- calculate from Prog --------------------------------- -----------------------------";
79 val thy = @{theory "Test"};
80 val fmz = ["realTestGiven (((1+2)*4/3) \<up> 2)", "realTestFind s"];
82 ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
84 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
85 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
86 (*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) \<up> #2)")*)
87 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
88 (*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
89 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
90 (*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
91 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
92 (*nxt = ("Specify_Problem",Specify_Problem ["calculate", "test"])*)
93 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
94 (*nxt = ("Specify_Method",Specify_Method ("Test", "test_calculate"))*)
95 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
96 (*nxt = ("Apply_Method",Apply_Method ("Test", "test_calculate"))*)
98 (*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "PLUS")*)
99 (*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "TIMES")*)
100 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "DIVIDE")*)
101 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "POWER")*)
102 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Check_Postcond",Check_Postcond ["calculate", "test"])*)
103 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("End_Proof'",End_Proof')*)
104 case f of Test_Out.FormKF "16" => () | _ =>
105 error "evaluate.sml: script test_calculate changed behaviour";
108 "----------- calculate check test-root-equ --------------";
109 "----------- calculate check test-root-equ --------------";
110 "----------- calculate check test-root-equ --------------";
111 (*(1): 2nd Test_simplify didn't work:
113 "sqrt (x \<up> 2 + -3 * x) = (-3 + 2 * x + - 1 * (9 + 4 * x)) / (- 1 * 2)"
114 > val rls = ("Test_simplify");
115 > val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
116 val ct = "sqrt (x \<up> 2 + -3 * x) =
117 (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))";
118 ie. cancel does not work properly
120 val thy = @{theory "Test"};
121 val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
123 "sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
124 case calculate_ thy op_ ct of
126 | NONE => error "calculate_ test-root-equ changed";
128 sqrt (x \<up> 2 + -3 * x) =\
129 \(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
130 ............... does not work *)
132 (*--------------(2): does divide work in Test_simplify ?: ------*)
133 val thy = @{theory Test};
134 val t = (Thm.term_of o the o (TermC.parse thy)) "6 / 2";
135 val rls = Test_simplify;
136 val (t,_) = the (rewrite_set_ thy false rls t);
137 (*val t = Free ("3", "Real.real") : term*)
139 (*--------------(3): is_num works ?: -------------------------------------*)
140 val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_num";
142 rewrite_set_ @{theory Test} false tval_rls t;
143 (*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
145 val t = TermC.str2term "2 * x is_num";
146 val NONE = eval_is_num "" "" t (@{theory "Isac_Knowledge"});
149 "----------- check calculate bottom up ------------------";
150 "----------- check calculate bottom up ------------------";
151 "----------- check calculate bottom up ------------------";
152 (*-------------- eval_cancel works: *)
153 Rewrite.trace_on := false; (*true false*)
154 val thy = @{theory Test};
155 val rls = Test_simplify;
156 val t = (Thm.term_of o the o (TermC.parse thy)) "(-4) / 2";
158 val SOME (_, t) = eval_cancel "xxx" \<^const_name>\<open>divide\<close> t thy;
160 (*--------------(5): reproduce (1) with simpler term: ------------*)
161 val t = (Thm.term_of o the o (TermC.parse thy)) "(3+5)/2";
162 case rewrite_set_ thy false rls t of
164 if UnparseC.term t' = "4" then ()
165 else error "rewrite_set_ (3+5)/2 changed 1"
166 | _ => error "rewrite_set_ (3+5)/2 changed 2";
168 val t = (Thm.term_of o the o (TermC.parse thy)) "(3+1+2*x)/2";
169 case rewrite_set_ thy false rls t of
171 if UnparseC.term t' = "2 + x" then () else error "rewrite_set_ (3+1+2*x)/2 changed 1"
172 | _ => error "rewrite_set_ (3+1+2*x)/2 changed 2";
174 Rewrite.trace_on := false; (*true false*)
176 (*--- Rewrite.trace_on before correction of ... --------------------
177 val ct = "(-3 + 2 * x + - 1) / 2";
178 val (ct,_) = the (rewrite_set thy' false rls ct);
180 ### trying thm 'root_ge0_2'
181 ### rewrite_set_: x + (- 1 + -3) / 2
182 ### trying thm 'radd_real_const_eq'
183 ### trying thm 'radd_real_const'
184 ### rewrite_set_: x + (-4) / 2
185 ### trying thm 'rcollect_right'
188 -------------------------------------while before Isabelle20002:
189 val ct = "(#-3 + #2 * x + #- 1) // #2";
190 val (ct,_) = the (rewrite_set thy' false rls ct);
192 ### trying thm 'root_ge0_2'
193 ### rewrite_set_: x + (#- 1 + #-3) // #2
194 ### trying thm 'radd_real_const_eq'
195 ### trying thm 'radd_real_const'
196 ### rewrite_set_: x + #-4 // #2
197 ### rewrite_set_: x + #- 2
198 ### trying thm 'rcollect_right'
201 -----------------------------------------------------------------*)
204 (*===================*)
205 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
206 val t = (Thm.term_of o the o (TermC.parse thy)) "x + (- 1 + -3) / 2";
207 val SOME (res, []) = rewrite_set_ thy false rls t;
208 if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_ x + (- 1 + -3) / 2 changed";
211 ### trying calc. 'cancel'
212 @@@ get_pair: binop, t = x + (-4) / 2
214 @@@ get_pair: t else -> NONE
215 @@@ get_pair: binop, t = (-4) / 2
217 @@@ get_pair: t -> NONE
218 @@@ get_pair: t1 -> NONE
220 ### trying calc. 'pow'
223 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
225 " ================= evaluate.sml: calculate_ 2002 =================== ";
226 " ================= evaluate.sml: calculate_ 2002 =================== ";
227 " ================= evaluate.sml: calculate_ 2002 =================== ";
229 val thy = @{theory Test};
230 val t = (Thm.term_of o the o (TermC.parse thy)) "12 / 3";
231 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
232 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
234 val thy = @{theory Test};
235 val t = (Thm.term_of o the o (TermC.parse thy)) "4 \<up> 2";
236 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
237 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
240 val t = (Thm.term_of o the o (TermC.parse thy)) "((1 + 2) * 4 / 3) \<up> 2";
241 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
243 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
245 "(3 * 4 / 3) \<up> 2";
246 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
248 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
251 val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
253 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
256 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
258 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
261 if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
264 (*13.9.02 *** calc: operator = pow not defined*)
265 val t = (Thm.term_of o the o (TermC.parse thy)) "3 \<up> 2";
266 val SOME (thmID,thm) =
267 adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
268 (*** calc: operator = pow not defined*)
270 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
272 val op_ = \<^const_name>\<open>powr\<close> : string
273 val eval_fn = fn : string -> term -> theory -> (string * term) option*)
275 val SOME (thmid,t') = get_pair thy op_ eval_fn t;
276 (*** calc: operator = pow not defined*)
278 val SOME (id,t') = eval_fn op_ t thy;
279 (*** calc: operator = pow not defined*)
282 ("Transcendental.powr",
283 Const (\<^const_name>\<open>powr\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _))) $
284 (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
285 | _ => error "3 \<up> 2 CHANGED";
286 val SOME (id, t') = eval_binop thmid op_ t thy;
287 (*** calc: operator = pow not defined*)
289 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
292 "----------- fun cancel_int --------------------------------------------------------------------";
293 "----------- fun cancel_int --------------------------------------------------------------------";
294 "----------- fun cancel_int --------------------------------------------------------------------";
295 if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
296 if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
297 if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
300 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
301 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
302 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
303 val (t1, t2) = (@{term 3}, @{term "2::real"});
305 "~~~~~ fun calcul , args:"; val (op_, (t1, t2)) = ("Groups.plus_class.plus", (t1, t2));
306 val (Const (\<^const_name>\<open>numeral\<close>, _) $ n1) = t1;
307 val (Const (\<^const_name>\<open>numeral\<close>, _) $ n2) = t2;
308 val (T, _) = HOLogic.dest_number t1
309 val (i1, i2) = (HOLogic.dest_numeral n1, HOLogic.dest_numeral n2)
312 "Groups.plus_class.plus" => i1 + i2
313 | "Groups.minus_class.minus" => i1 - i2
314 | "Groups.times_class.times" => i1 * i2
315 | "Transcendental.powr" => power i1 i2
316 | str => raise ERROR ("calcul not impl.for op_ " ^ str)
318 val xxx = HOLogic.mk_number T result;
320 case HOLogic.dest_number xxx of
322 | _ => error "calcul + 2 3 CHANGED";
324 case HOLogic.dest_number (calcul "Groups.minus_class.minus" (t1, t2)) of
326 | _ => error "calcul - 2 3 CHANGED";
328 case HOLogic.dest_number (calcul "Groups.times_class.times" (t1, t2)) of
330 | _ => error "calcul - 2 3 CHANGED";
332 (* (calcul "Rings.divide_class.divide" (t1, t2)
333 ERROR: calcul not impl.for op_ Rings.divide_class.divide*)
335 case HOLogic.dest_number (calcul "Transcendental.powr" (t1, t2)) of
337 | _ => error "calcul - 2 3 CHANGED";
340 "----------- get_pair with 3 args --------------------------------";
341 "----------- get_pair with 3 args --------------------------------";
342 "----------- get_pair with 3 args --------------------------------";
343 val (thy, op_, ef, arg) =
344 (thy, "EqSystem.occur_exactly_in",
345 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
347 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
349 val SOME (str, simpl) = get_pair thy op_ ef arg;
351 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
352 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
355 "----------- calculate (2 * x is_num) -------------------";
356 "----------- calculate (2 * x is_num) -------------------";
357 "----------- calculate (2 * x is_num) -------------------";
358 val t = TermC.str2term "(2::real) * x is_num";
360 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t @{theory Test};
361 if UnparseC.term t' = "(2 * x is_num) = False" then ()
362 else error "is_num 2 * x is_num CHANGED";
364 val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
365 if UnparseC.term t' = "False" then ()
366 else error "rewrite_set_ 2 * x is_num CHANGED";
368 "----------- fun get_pair: examples ------------------------------------------------------------";
369 "----------- fun get_pair: examples ------------------------------------------------------------";
370 "----------- fun get_pair: examples ------------------------------------------------------------";
372 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
373 if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
375 val t = @{term "3 + 4 :: real"};
376 val SOME (str, term) = get_pair thy isa_str eval_fn t;
377 (*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
378 (*+*)then () else error "get_pair 3 + 4 changed";
380 val t = @{term "(a + 3) + 4 :: real"};
381 val SOME (str, term) = get_pair thy isa_str eval_fn t;
382 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
383 then () else error "get_pair (a + 3) + 4 changed";
385 val t = @{term "(a + 3) + 4 :: real"};
386 val SOME (str, term) = get_pair thy isa_str eval_fn t;
387 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
388 then () else error "get_pair (a + 3) + 4 changed";
390 val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
391 val SOME (str, term) = get_pair thy isa_str eval_fn t;
392 if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
393 then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
395 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
397 val t = @{term "-4 / - 2 :: real"};
398 val SOME (str, term) = get_pair thy isa_str eval_fn t;
399 if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
400 then () else error "get_pair -4 / - 2 changed";
402 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
404 val t = @{term "2 \<up> 3 :: real"};
405 val SOME (str, term) = get_pair thy isa_str eval_fn t;
406 if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
407 then () else error "get_pair 2 \<up> 3 changed";
409 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
410 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
411 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
412 (*--------------------------------------------------------------------vvvvvvvvvv*)
413 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num");
414 val t = @{term "9 is_num"};
415 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
416 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True"
417 then () else error "adhoc_thm 9 is_num changed";
419 case assoc_calc thy \<^const_name>\<open>less\<close> of
420 "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
421 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
422 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
424 val t = @{term "4 < (4 :: real)"};
425 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
426 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
427 then () else error "adhoc_thm 4 < 4 changed";
429 val SOME t = parseNEW @{context} "a < 4";
430 case adhoc_thm thy (isa_str, eval_fn) t of
431 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
433 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
434 val SOME t = parseNEW @{context} "1 + (2::real)";
435 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
436 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
437 then () else error "adhoc_thm 1 + 2 changed";
439 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
440 val t = @{term "6 / -8 :: real"};
441 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
442 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
443 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
445 case assoc_calc thy "Prog_Expr.ident" of
446 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
447 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
449 val t = @{term "3 =!= (3 :: real)"};
450 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
451 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
452 then () else error "adhoc_thm (3 =!= 3) changed";
454 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
455 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
456 if str = "#ident_(4 + (4 * x + x \<up> 2))_(0)" andalso ThmC_Def.string_of_thm thm = "(4 + (4 * x + x \<up> 2) =!= 0) = False"
457 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
459 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
460 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
461 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
462 val eval_ = ("Rings.divide_class.divide", eval_cancel "#divide_e" : eval_fn);
463 val t = @{term "- 1 / 2 ::real"};
465 ML\<open>Eval.adhoc_thm\<close> is called while searching terms for adjacent numerals
466 given a certain ML_type\<open>eval_fn\<close> and a certain ML\<open>term\<close> ..
470 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2")
471 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE
473 STEP-INTO BEVORE REMOVING THE ERROR:
474 val SOME ("#divide_e~1_2", adhoc_thm) =
475 Eval.adhoc_thm @{theory} eval_ t;
476 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
478 ("#divide_e~1_2", t'') =
479 (*case*) get_pair thy op_ eval_fn t (*of*);
481 get_pair finds two adjacent numerals and does NOT distinguish between different kinds of
482 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input..
484 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2"
488 adhoc_thm @{theory} eval_ t;
489 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
490 val SOME ("#divide_e~1_2", t') =
491 (*case*) get_pair thy op_ eval_fn t (*of*);
493 (*+*)UnparseC.term t = "- 1 / 2";
494 (*+*)UnparseC.term t' = "- 1 / 2 = - 1 / 2"; "HOL.Trueprop";
496 if t = (TermC.rhs o HOLogic.dest_Trueprop) t'
497 then () else error "fun adhoc_thm + fun eval_cancel CHANGED";
500 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
501 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
502 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
503 val t = TermC.str2term "sqrt 4";
504 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t;
506 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
507 ((ThyC.get_theory "Isac_Knowledge"),
508 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
510 val SOME (thmid, t) =
511 (*case*) get_pair thy op_ eval_fn ct (*of*);
512 (*+*)val "sqrt 4 = 2" = UnparseC.term t;
515 Skip_Proof.make_thm thy t;
517 exception TYPE raised (line 169 of "consts.ML"): Illegal type
518 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
521 "----------- fun power -------------------------------------------------------------------------";
522 "----------- fun power -------------------------------------------------------------------------";
523 "----------- fun power -------------------------------------------------------------------------";
524 if power 2 3 = 8 then () else error "power 2 3 = 8";
525 if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
526 if power ~3 2 = 9 then () else error "power ~3 2 = 9";
527 case \<^try>\<open> power 3 ~2 \<close> of
528 SOME _ => raise error "power 3 ~2: should raise an exn 1"
531 "----------- fun divisors ----------------------------------------------------------------------";
532 "----------- fun divisors ----------------------------------------------------------------------";
533 "----------- fun divisors ----------------------------------------------------------------------";
534 if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
535 if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
536 if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
537 if divisors 11 = [11] then () else error "divisors 11 = [11]";
539 "----------- fun doubles, fun squfact ----------------------------------------------------------";
540 "----------- fun doubles, fun squfact ----------------------------------------------------------";
541 "----------- fun doubles, fun squfact ----------------------------------------------------------";
542 if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
543 if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
545 if squfact 30 = 1 then () else error "squfact 30 changed";
546 if squfact 32 = 4 then () else error "squfact 32 changed";
547 if squfact 60 = 2 then () else error "squfact 60 changed";
548 if squfact 11 = 1 then () else error "squfact 11 changed";