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 ctxt = Proof_Context.init_global @{theory}
52 val times = ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
53 val plus = ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
54 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
55 val pow = (\<^const_name>\<open>realpow\<close>, eval_binop "#power_") : string * Eval_Def.eval_fn;
57 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
58 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
59 val SOME (t', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
60 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed";
62 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
63 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
64 val SOME (t'', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
65 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed";
67 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
68 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
69 val SOME (t''', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
70 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed";
72 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
73 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
74 val SOME (t'''', []) = rewrite__ ctxt 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
75 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed";
77 "----------- calculate from Prog --------------------------------- -----------------------------";
78 "----------- calculate from Prog --------------------------------- -----------------------------";
79 "----------- calculate from Prog --------------------------------- -----------------------------";
80 val thy = @{theory "Test"};
81 val fmz = ["realTestGiven (((1+2)*4/3) \<up> 2)", "realTestFind s"];
83 ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
85 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
86 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
87 (*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) \<up> #2)")*)
88 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
89 (*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
90 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
91 (*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
92 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
93 (*nxt = ("Specify_Problem",Specify_Problem ["calculate", "test"])*)
94 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
95 (*nxt = ("Specify_Method",Specify_Method ("Test", "test_calculate"))*)
96 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
97 (*nxt = ("Apply_Method",Apply_Method ("Test", "test_calculate"))*)
99 (*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "PLUS")*)
100 (*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "TIMES")*)
101 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "DIVIDE")*)
102 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "POWER")*)
103 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Check_Postcond",Check_Postcond ["calculate", "test"])*)
104 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("End_Proof'",End_Proof')*)
105 case f of Test_Out.FormKF "16" => () | _ =>
106 error "evaluate.sml: script test_calculate changed behaviour";
109 "----------- calculate check test-root-equ --------------";
110 "----------- calculate check test-root-equ --------------";
111 "----------- calculate check test-root-equ --------------";
112 (*(1): 2nd Test_simplify didn't work:
114 "sqrt (x \<up> 2 + -3 * x) = (-3 + 2 * x + - 1 * (9 + 4 * x)) / (- 1 * 2)"
115 > val rls = ("Test_simplify");
116 > val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
117 val ct = "sqrt (x \<up> 2 + -3 * x) =
118 (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))";
119 ie. cancel does not work properly
121 val thy = @{theory "Test"};
122 val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
124 "sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
125 case calculate_ ctxt op_ ct of
127 | NONE => error "calculate_ test-root-equ changed";
129 sqrt (x \<up> 2 + -3 * x) =\
130 \(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
131 ............... does not work *)
133 (*--------------(2): does divide work in Test_simplify ?: ------*)
134 val thy = @{theory Test};
135 val ctxt = (ThyC.id_to_ctxt "Test")
136 val t = TermC.parseNEW' ctxt "6 / 2";
137 val rls = Test_simplify;
138 val (t,_) = the (rewrite_set_ ctxt false rls t);
139 (*val t = Free ("3", "Real.real") : term*)
141 (*--------------(3): is_num works ?: -------------------------------------*)
142 val t = TermC.parseNEW' ctxt "2 is_num";
144 rewrite_set_ ctxt false tval_rls t;
145 (*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
147 val t = TermC.str2term "2 * x is_num";
148 val NONE = eval_is_num "" "" t (@{theory "Isac_Knowledge"});
151 "----------- check calculate bottom up ------------------";
152 "----------- check calculate bottom up ------------------";
153 "----------- check calculate bottom up ------------------";
154 (*-------------- eval_cancel works: *)
155 val thy = @{theory Test};
156 val rls = Test_simplify;
157 val t = TermC.parseNEW' ctxt "(-4) / 2";
159 val SOME (_, t) = eval_cancel "xxx" \<^const_name>\<open>divide\<close> t thy;
161 (*--------------(5): reproduce (1) with simpler term: ------------*)
162 val t = TermC.parseNEW' ctxt "(3+5)/(2::real)";
163 case rewrite_set_ ctxt false rls t of
165 if UnparseC.term t' = "4" then ()
166 else error "rewrite_set_ (3+5)/2 changed 1"
167 | _ => error "rewrite_set_ (3+5)/2 changed 2";
169 val t = TermC.parseNEW' ctxt "(3+1+2*x)/(2::real)";
170 case rewrite_set_ ctxt false rls t of
172 if UnparseC.term t' = "2 + x" then () else error "rewrite_set_ (3+1+2*x)/2 changed 1"
173 | _ => error "rewrite_set_ (3+1+2*x)/2 changed 2";
175 (*--- trace_rewrite before correction of ... --------------------
176 val ct = "(-3 + 2 * x + - 1) / 2";
177 val (ct,_) = the (rewrite_set thy' false rls ct);
179 ### trying thm 'root_ge0_2'
180 ### rewrite_set_: x + (- 1 + -3) / 2
181 ### trying thm 'radd_real_const_eq'
182 ### trying thm 'radd_real_const'
183 ### rewrite_set_: x + (-4) / 2
184 ### trying thm 'rcollect_right'
187 -------------------------------------while before Isabelle20002:
188 val ct = "(#-3 + #2 * x + #- 1) // #2";
189 val (ct,_) = the (rewrite_set thy' false rls ct);
191 ### trying thm 'root_ge0_2'
192 ### rewrite_set_: x + (#- 1 + #-3) // #2
193 ### trying thm 'radd_real_const_eq'
194 ### trying thm 'radd_real_const'
195 ### rewrite_set_: x + #-4 // #2
196 ### rewrite_set_: x + #- 2
197 ### trying thm 'rcollect_right'
200 -----------------------------------------------------------------*)
203 (*===================*)
204 val t = TermC.parseNEW' ctxt "x + (- 1 + -3) / (2::real)";
205 val SOME (res, []) = rewrite_set_ ctxt false rls t;
206 if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_ x + (- 1 + -3) / 2 changed";
209 ### trying calc. 'cancel'
210 @@@ get_pair: binop, t = x + (-4) / 2
212 @@@ get_pair: t else -> NONE
213 @@@ get_pair: binop, t = (-4) / 2
215 @@@ get_pair: t -> NONE
216 @@@ get_pair: t1 -> NONE
218 ### trying calc. 'pow'
221 " ================= evaluate.sml: calculate_ 2002 =================== ";
222 " ================= evaluate.sml: calculate_ 2002 =================== ";
223 " ================= evaluate.sml: calculate_ 2002 =================== ";
225 val thy = @{theory Test};
226 val t = TermC.parseNEW' ctxt "12 / 3";
227 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
228 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
230 val thy = @{theory Test};
231 val t = TermC.parseNEW' ctxt "4 \<up> 2";
232 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
233 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
236 val t = TermC.parseNEW' ctxt "((1 + 2) * 4 / 3) \<up> 2";
237 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
239 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
241 "(3 * 4 / 3) \<up> 2";
242 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
244 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
247 val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
249 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
252 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
254 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t;
257 if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
260 (*13.9.02 *** calc: operator = pow not defined*)
261 val t = TermC.parseNEW' ctxt "3 \<up> 2";
262 val SOME (thmID,thm) =
263 adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
264 (*** calc: operator = pow not defined*)
266 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
268 val op_ = \<^const_name>\<open>realpow\<close> : string
269 val eval_fn = fn : string -> term -> theory -> (string * term) option*)
271 val SOME (thmid,t') = get_pair thy op_ eval_fn t;
272 (*** calc: operator = pow not defined*)
274 val SOME (id,t') = eval_fn op_ t thy;
275 (*** calc: operator = pow not defined*)
278 (\<^const_name>\<open>realpow\<close>,
279 Const (\<^const_name>\<open>realpow\<close>, _) $ (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit1\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _))) $
280 (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
281 | _ => error "3 \<up> 2 CHANGED";
282 val SOME (id, t') = eval_binop thmid op_ t thy;
283 (*** calc: operator = pow not defined*)
285 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
288 "----------- fun cancel_int --------------------------------------------------------------------";
289 "----------- fun cancel_int --------------------------------------------------------------------";
290 "----------- fun cancel_int --------------------------------------------------------------------";
291 if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
292 if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
293 if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
296 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
297 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
298 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
299 val t = @{term "2 + 3 ::real"};
301 "~~~~~ fun calcul , args:"; val (thy, lhs) = (@{theory}, t);
303 Proof_Context.init_global thy
304 |> put_simpset (Simplifier.simpset_of @{theory_context BaseDefinitions});
305 val eq = Simplifier.rewrite simp_ctxt (Thm.global_cterm_of thy lhs);
307 if ThmC.string_of_thm eq = "2 + 3 \<equiv> 5" then () else error "calcul 1";
309 val rhs = Thm.term_of (Thm.rhs_of eq);
310 val _ = \<^assert> (is_num rhs);
312 (*return value*) rhs;
313 if TermC.to_string rhs = "5" then () else error "calcul 2";
316 "----------- get_pair with 3 args --------------------------------";
317 "----------- get_pair with 3 args --------------------------------";
318 "----------- get_pair with 3 args --------------------------------";
319 val (thy, op_, ef, arg) =
320 (thy, "EqSystem.occur_exactly_in",
321 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
323 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
325 val SOME (str, simpl) = get_pair thy op_ ef arg;
327 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
328 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
331 "----------- calculate (2 * x is_num) -------------------";
332 "----------- calculate (2 * x is_num) -------------------";
333 "----------- calculate (2 * x is_num) -------------------";
334 val t = TermC.str2term "(2::real) * x is_num";
336 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t @{theory Test};
337 if UnparseC.term t' = "(2 * x is_num) = False" then ()
338 else error "is_num 2 * x is_num CHANGED";
340 val SOME (t',_) = rewrite_set_ ctxt false tval_rls t;
341 if UnparseC.term t' = "False" then ()
342 else error "rewrite_set_ 2 * x is_num CHANGED";
344 "----------- fun get_pair: examples ------------------------------------------------------------";
345 "----------- fun get_pair: examples ------------------------------------------------------------";
346 "----------- fun get_pair: examples ------------------------------------------------------------";
348 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
349 if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
351 val t = @{term "3 + 4 :: real"};
352 val SOME (str, term) = get_pair thy isa_str eval_fn t;
353 (*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
354 (*+*)then () else error "get_pair 3 + 4 changed";
356 val t = @{term "(a + 3) + 4 :: real"};
357 val SOME (str, term) = get_pair thy isa_str eval_fn t;
358 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
359 then () else error "get_pair (a + 3) + 4 changed";
361 val t = @{term "(a + 3) + 4 :: real"};
362 val SOME (str, term) = get_pair thy isa_str eval_fn t;
363 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
364 then () else error "get_pair (a + 3) + 4 changed";
366 val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
367 val SOME (str, term) = get_pair thy isa_str eval_fn t;
368 if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
369 then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
371 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
373 val t = @{term "-4 / - 2 :: real"};
374 val SOME (str, term) = get_pair thy isa_str eval_fn t;
375 if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
376 then () else error "get_pair -4 / - 2 changed";
378 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
380 val t = @{term "2 \<up> 3 :: real"};
381 val SOME (str, term) = get_pair thy isa_str eval_fn t;
382 if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
383 then () else error "get_pair 2 \<up> 3 changed";
385 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
386 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
387 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
388 (*--------------------------------------------------------------------vvvvvvvvvv*)
389 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num");
390 val t = @{term "9 is_num"};
391 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
392 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True"
393 then () else error "adhoc_thm 9 is_num changed";
395 case assoc_calc thy \<^const_name>\<open>less\<close> of
396 "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
397 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
398 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
400 val t = @{term "4 < (4 :: real)"};
401 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
402 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
403 then () else error "adhoc_thm 4 < 4 changed";
405 val SOME t = parseNEW @{context} "a < 4";
406 case adhoc_thm thy (isa_str, eval_fn) t of
407 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
409 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
410 val SOME t = parseNEW @{context} "1 + (2::real)";
411 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
412 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
413 then () else error "adhoc_thm 1 + 2 changed";
415 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
416 val t = @{term "6 / -8 :: real"};
417 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
418 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
419 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
421 case assoc_calc thy "Prog_Expr.ident" of
422 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
423 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
425 val t = @{term "3 =!= (3 :: real)"};
426 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
427 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
428 then () else error "adhoc_thm (3 =!= 3) changed";
430 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
431 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
432 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"
433 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
435 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
436 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
437 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
438 val eval_ = ("Rings.divide_class.divide", eval_cancel "#divide_e" : eval_fn);
439 val t = @{term "- 1 / 2 ::real"};
441 ML\<open>Eval.adhoc_thm\<close> is called while searching terms for adjacent numerals
442 given a certain ML_type\<open>eval_fn\<close> and a certain ML\<open>term\<close> ..
446 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2")
447 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE
449 STEP-INTO BEVORE REMOVING THE ERROR:
450 val SOME ("#divide_e~1_2", adhoc_thm) =
451 Eval.adhoc_thm @{theory} eval_ t;
452 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
454 ("#divide_e~1_2", t'') =
455 (*case*) get_pair thy op_ eval_fn t (*of*);
457 get_pair finds two adjacent numerals and does NOT distinguish between different kinds of
458 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input..
460 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2"
463 val NONE = adhoc_thm @{theory} eval_ t;
464 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
466 (*case*) get_pair thy op_ eval_fn t (*of*);
469 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
470 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
471 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
472 val t = TermC.str2term "sqrt 4";
473 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t;
475 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
476 ((ThyC.get_theory "Isac_Knowledge"),
477 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
479 val SOME (thmid, t) =
480 (*case*) get_pair thy op_ eval_fn ct (*of*);
481 (*+*)val "sqrt 4 = 2" = UnparseC.term t;
484 Skip_Proof.make_thm thy t;
486 exception TYPE raised (line 169 of "consts.ML"): Illegal type
487 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
490 "----------- fun power -------------------------------------------------------------------------";
491 "----------- fun power -------------------------------------------------------------------------";
492 "----------- fun power -------------------------------------------------------------------------";
493 if power 2 3 = 8 then () else error "power 2 3 = 8";
494 if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
495 if power ~3 2 = 9 then () else error "power ~3 2 = 9";
496 case \<^try>\<open> power 3 ~2 \<close> of
497 SOME _ => raise error "power 3 ~2: should raise an exn 1"
500 "----------- fun divisors ----------------------------------------------------------------------";
501 "----------- fun divisors ----------------------------------------------------------------------";
502 "----------- fun divisors ----------------------------------------------------------------------";
503 if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
504 if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
505 if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
506 if divisors 11 = [11] then () else error "divisors 11 = [11]";
508 "----------- fun doubles, fun squfact ----------------------------------------------------------";
509 "----------- fun doubles, fun squfact ----------------------------------------------------------";
510 "----------- fun doubles, fun squfact ----------------------------------------------------------";
511 if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
512 if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
514 if squfact 30 = 1 then () else error "squfact 30 changed";
515 if squfact 32 = 4 then () else error "squfact 32 changed";
516 if squfact 60 = 2 then () else error "squfact 60 changed";
517 if squfact 11 = 1 then () else error "squfact 11 changed";