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 = (\<^const_name>\<open>realpow\<close>, 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 ctxt = (ThyC.id_to_ctxt "Test")
135 val t = TermC.parseNEW' ctxt "6 / 2";
136 val rls = Test_simplify;
137 val (t,_) = the (rewrite_set_ thy false rls t);
138 (*val t = Free ("3", "Real.real") : term*)
140 (*--------------(3): is_num works ?: -------------------------------------*)
141 val t = TermC.parseNEW' ctxt "2 is_num";
143 rewrite_set_ @{theory Test} false tval_rls t;
144 (*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
146 val t = TermC.str2term "2 * x is_num";
147 val NONE = eval_is_num "" "" t (@{theory "Isac_Knowledge"});
150 "----------- check calculate bottom up ------------------";
151 "----------- check calculate bottom up ------------------";
152 "----------- check calculate bottom up ------------------";
153 (*-------------- eval_cancel works: *)
154 Rewrite.trace_on := false; (*true false*)
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_ thy 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_ thy 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 Rewrite.trace_on := false; (*true false*)
177 (*--- Rewrite.trace_on before correction of ... --------------------
178 val ct = "(-3 + 2 * x + - 1) / 2";
179 val (ct,_) = the (rewrite_set thy' false rls ct);
181 ### trying thm 'root_ge0_2'
182 ### rewrite_set_: x + (- 1 + -3) / 2
183 ### trying thm 'radd_real_const_eq'
184 ### trying thm 'radd_real_const'
185 ### rewrite_set_: x + (-4) / 2
186 ### trying thm 'rcollect_right'
189 -------------------------------------while before Isabelle20002:
190 val ct = "(#-3 + #2 * x + #- 1) // #2";
191 val (ct,_) = the (rewrite_set thy' false rls ct);
193 ### trying thm 'root_ge0_2'
194 ### rewrite_set_: x + (#- 1 + #-3) // #2
195 ### trying thm 'radd_real_const_eq'
196 ### trying thm 'radd_real_const'
197 ### rewrite_set_: x + #-4 // #2
198 ### rewrite_set_: x + #- 2
199 ### trying thm 'rcollect_right'
202 -----------------------------------------------------------------*)
205 (*===================*)
206 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
207 val t = TermC.parseNEW' ctxt "x + (- 1 + -3) / (2::real)";
208 val SOME (res, []) = rewrite_set_ thy false rls t;
209 if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_ x + (- 1 + -3) / 2 changed";
212 ### trying calc. 'cancel'
213 @@@ get_pair: binop, t = x + (-4) / 2
215 @@@ get_pair: t else -> NONE
216 @@@ get_pair: binop, t = (-4) / 2
218 @@@ get_pair: t -> NONE
219 @@@ get_pair: t1 -> NONE
221 ### trying calc. 'pow'
224 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
226 " ================= evaluate.sml: calculate_ 2002 =================== ";
227 " ================= evaluate.sml: calculate_ 2002 =================== ";
228 " ================= evaluate.sml: calculate_ 2002 =================== ";
230 val thy = @{theory Test};
231 val t = TermC.parseNEW' ctxt "12 / 3";
232 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
233 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
235 val thy = @{theory Test};
236 val t = TermC.parseNEW' ctxt "4 \<up> 2";
237 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
238 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
241 val t = TermC.parseNEW' ctxt "((1 + 2) * 4 / 3) \<up> 2";
242 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
244 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
246 "(3 * 4 / 3) \<up> 2";
247 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
249 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
252 val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
254 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
257 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
259 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
262 if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
265 (*13.9.02 *** calc: operator = pow not defined*)
266 val t = TermC.parseNEW' ctxt "3 \<up> 2";
267 val SOME (thmID,thm) =
268 adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
269 (*** calc: operator = pow not defined*)
271 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
273 val op_ = \<^const_name>\<open>realpow\<close> : string
274 val eval_fn = fn : string -> term -> theory -> (string * term) option*)
276 val SOME (thmid,t') = get_pair thy op_ eval_fn t;
277 (*** calc: operator = pow not defined*)
279 val SOME (id,t') = eval_fn op_ t thy;
280 (*** calc: operator = pow not defined*)
283 (\<^const_name>\<open>realpow\<close>,
284 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>, _))) $
285 (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
286 | _ => error "3 \<up> 2 CHANGED";
287 val SOME (id, t') = eval_binop thmid op_ t thy;
288 (*** calc: operator = pow not defined*)
290 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
293 "----------- fun cancel_int --------------------------------------------------------------------";
294 "----------- fun cancel_int --------------------------------------------------------------------";
295 "----------- fun cancel_int --------------------------------------------------------------------";
296 if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
297 if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
298 if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
301 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
302 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
303 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
304 val t = @{term "2 + 3 ::real"};
306 "~~~~~ fun calcul , args:"; val (thy, lhs) = (@{theory}, t);
308 Proof_Context.init_global thy
309 |> put_simpset (Simplifier.simpset_of @{theory_context BaseDefinitions});
310 val eq = Simplifier.rewrite simp_ctxt (Thm.global_cterm_of thy lhs);
312 if ThmC.string_of_thm eq = "2 + 3 \<equiv> 5" then () else error "calcul 1";
314 val rhs = Thm.term_of (Thm.rhs_of eq);
315 val _ = \<^assert> (is_num rhs);
317 (*return value*) rhs;
318 if TermC.to_string rhs = "5" then () else error "calcul 2";
321 "----------- get_pair with 3 args --------------------------------";
322 "----------- get_pair with 3 args --------------------------------";
323 "----------- get_pair with 3 args --------------------------------";
324 val (thy, op_, ef, arg) =
325 (thy, "EqSystem.occur_exactly_in",
326 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
328 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
330 val SOME (str, simpl) = get_pair thy op_ ef arg;
332 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
333 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
336 "----------- calculate (2 * x is_num) -------------------";
337 "----------- calculate (2 * x is_num) -------------------";
338 "----------- calculate (2 * x is_num) -------------------";
339 val t = TermC.str2term "(2::real) * x is_num";
341 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t @{theory Test};
342 if UnparseC.term t' = "(2 * x is_num) = False" then ()
343 else error "is_num 2 * x is_num CHANGED";
345 val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
346 if UnparseC.term t' = "False" then ()
347 else error "rewrite_set_ 2 * x is_num CHANGED";
349 "----------- fun get_pair: examples ------------------------------------------------------------";
350 "----------- fun get_pair: examples ------------------------------------------------------------";
351 "----------- fun get_pair: examples ------------------------------------------------------------";
353 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
354 if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
356 val t = @{term "3 + 4 :: real"};
357 val SOME (str, term) = get_pair thy isa_str eval_fn t;
358 (*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
359 (*+*)then () else error "get_pair 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 "(a + 3) + 4 :: real"};
367 val SOME (str, term) = get_pair thy isa_str eval_fn t;
368 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
369 then () else error "get_pair (a + 3) + 4 changed";
371 val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
372 val SOME (str, term) = get_pair thy isa_str eval_fn t;
373 if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
374 then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
376 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
378 val t = @{term "-4 / - 2 :: real"};
379 val SOME (str, term) = get_pair thy isa_str eval_fn t;
380 if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
381 then () else error "get_pair -4 / - 2 changed";
383 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
385 val t = @{term "2 \<up> 3 :: real"};
386 val SOME (str, term) = get_pair thy isa_str eval_fn t;
387 if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
388 then () else error "get_pair 2 \<up> 3 changed";
390 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
391 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
392 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
393 (*--------------------------------------------------------------------vvvvvvvvvv*)
394 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num");
395 val t = @{term "9 is_num"};
396 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
397 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True"
398 then () else error "adhoc_thm 9 is_num changed";
400 case assoc_calc thy \<^const_name>\<open>less\<close> of
401 "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
402 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
403 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
405 val t = @{term "4 < (4 :: real)"};
406 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
407 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
408 then () else error "adhoc_thm 4 < 4 changed";
410 val SOME t = parseNEW @{context} "a < 4";
411 case adhoc_thm thy (isa_str, eval_fn) t of
412 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
414 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
415 val SOME t = parseNEW @{context} "1 + (2::real)";
416 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
417 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
418 then () else error "adhoc_thm 1 + 2 changed";
420 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
421 val t = @{term "6 / -8 :: real"};
422 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
423 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
424 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
426 case assoc_calc thy "Prog_Expr.ident" of
427 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
428 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
430 val t = @{term "3 =!= (3 :: real)"};
431 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
432 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
433 then () else error "adhoc_thm (3 =!= 3) changed";
435 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
436 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
437 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"
438 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
440 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
441 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
442 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
443 val eval_ = ("Rings.divide_class.divide", eval_cancel "#divide_e" : eval_fn);
444 val t = @{term "- 1 / 2 ::real"};
446 ML\<open>Eval.adhoc_thm\<close> is called while searching terms for adjacent numerals
447 given a certain ML_type\<open>eval_fn\<close> and a certain ML\<open>term\<close> ..
451 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2")
452 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE
454 STEP-INTO BEVORE REMOVING THE ERROR:
455 val SOME ("#divide_e~1_2", adhoc_thm) =
456 Eval.adhoc_thm @{theory} eval_ t;
457 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
459 ("#divide_e~1_2", t'') =
460 (*case*) get_pair thy op_ eval_fn t (*of*);
462 get_pair finds two adjacent numerals and does NOT distinguish between different kinds of
463 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input..
465 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2"
468 val NONE = adhoc_thm @{theory} eval_ t;
469 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
471 (*case*) get_pair thy op_ eval_fn t (*of*);
474 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
475 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
476 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
477 val t = TermC.str2term "sqrt 4";
478 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t;
480 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
481 ((ThyC.get_theory "Isac_Knowledge"),
482 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
484 val SOME (thmid, t) =
485 (*case*) get_pair thy op_ eval_fn ct (*of*);
486 (*+*)val "sqrt 4 = 2" = UnparseC.term t;
489 Skip_Proof.make_thm thy t;
491 exception TYPE raised (line 169 of "consts.ML"): Illegal type
492 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
495 "----------- fun power -------------------------------------------------------------------------";
496 "----------- fun power -------------------------------------------------------------------------";
497 "----------- fun power -------------------------------------------------------------------------";
498 if power 2 3 = 8 then () else error "power 2 3 = 8";
499 if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
500 if power ~3 2 = 9 then () else error "power ~3 2 = 9";
501 case \<^try>\<open> power 3 ~2 \<close> of
502 SOME _ => raise error "power 3 ~2: should raise an exn 1"
505 "----------- fun divisors ----------------------------------------------------------------------";
506 "----------- fun divisors ----------------------------------------------------------------------";
507 "----------- fun divisors ----------------------------------------------------------------------";
508 if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
509 if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
510 if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
511 if divisors 11 = [11] then () else error "divisors 11 = [11]";
513 "----------- fun doubles, fun squfact ----------------------------------------------------------";
514 "----------- fun doubles, fun squfact ----------------------------------------------------------";
515 "----------- fun doubles, fun squfact ----------------------------------------------------------";
516 if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
517 if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
519 if squfact 30 = 1 then () else error "squfact 30 changed";
520 if squfact 32 = 4 then () else error "squfact 32 changed";
521 if squfact 60 = 2 then () else error "squfact 60 changed";
522 if squfact 11 = 1 then () else error "squfact 11 changed";