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 t = @{term "2 + 3 ::real"};
305 "~~~~~ fun calcul , args:"; val (thy, lhs) = (@{theory}, t);
307 Proof_Context.init_global thy
308 |> put_simpset (Simplifier.simpset_of @{theory_context Complex_Main});
309 val eq = Simplifier.rewrite simp_ctxt (Thm.global_cterm_of thy lhs);
311 if ThmC.string_of_thm eq = "2 + 3 \<equiv> 5" then () else error "calcul 1";
313 val rhs = Thm.term_of (Thm.rhs_of eq);
314 val _ = \<^assert> (is_num rhs);
316 (*return value*) rhs;
317 if TermC.to_string rhs = "5" then () else error "calcul 2";
320 "----------- get_pair with 3 args --------------------------------";
321 "----------- get_pair with 3 args --------------------------------";
322 "----------- get_pair with 3 args --------------------------------";
323 val (thy, op_, ef, arg) =
324 (thy, "EqSystem.occur_exactly_in",
325 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
327 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
329 val SOME (str, simpl) = get_pair thy op_ ef arg;
331 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
332 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
335 "----------- calculate (2 * x is_num) -------------------";
336 "----------- calculate (2 * x is_num) -------------------";
337 "----------- calculate (2 * x is_num) -------------------";
338 val t = TermC.str2term "(2::real) * x is_num";
340 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t @{theory Test};
341 if UnparseC.term t' = "(2 * x is_num) = False" then ()
342 else error "is_num 2 * x is_num CHANGED";
344 val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
345 if UnparseC.term t' = "False" then ()
346 else error "rewrite_set_ 2 * x is_num CHANGED";
348 "----------- fun get_pair: examples ------------------------------------------------------------";
349 "----------- fun get_pair: examples ------------------------------------------------------------";
350 "----------- fun get_pair: examples ------------------------------------------------------------";
352 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
353 if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
355 val t = @{term "3 + 4 :: real"};
356 val SOME (str, term) = get_pair thy isa_str eval_fn t;
357 (*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
358 (*+*)then () else error "get_pair 3 + 4 changed";
360 val t = @{term "(a + 3) + 4 :: real"};
361 val SOME (str, term) = get_pair thy isa_str eval_fn t;
362 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
363 then () else error "get_pair (a + 3) + 4 changed";
365 val t = @{term "(a + 3) + 4 :: real"};
366 val SOME (str, term) = get_pair thy isa_str eval_fn t;
367 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
368 then () else error "get_pair (a + 3) + 4 changed";
370 val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
371 val SOME (str, term) = get_pair thy isa_str eval_fn t;
372 if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
373 then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
375 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
377 val t = @{term "-4 / - 2 :: real"};
378 val SOME (str, term) = get_pair thy isa_str eval_fn t;
379 if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
380 then () else error "get_pair -4 / - 2 changed";
382 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
384 val t = @{term "2 \<up> 3 :: real"};
385 val SOME (str, term) = get_pair thy isa_str eval_fn t;
386 if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
387 then () else error "get_pair 2 \<up> 3 changed";
389 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
390 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
391 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
392 (*--------------------------------------------------------------------vvvvvvvvvv*)
393 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num");
394 val t = @{term "9 is_num"};
395 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
396 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True"
397 then () else error "adhoc_thm 9 is_num changed";
399 case assoc_calc thy \<^const_name>\<open>less\<close> of
400 "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
401 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
402 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
404 val t = @{term "4 < (4 :: real)"};
405 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
406 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
407 then () else error "adhoc_thm 4 < 4 changed";
409 val SOME t = parseNEW @{context} "a < 4";
410 case adhoc_thm thy (isa_str, eval_fn) t of
411 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
413 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
414 val SOME t = parseNEW @{context} "1 + (2::real)";
415 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
416 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
417 then () else error "adhoc_thm 1 + 2 changed";
419 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
420 val t = @{term "6 / -8 :: real"};
421 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
422 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
423 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
425 case assoc_calc thy "Prog_Expr.ident" of
426 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
427 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
429 val t = @{term "3 =!= (3 :: real)"};
430 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
431 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
432 then () else error "adhoc_thm (3 =!= 3) changed";
434 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
435 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
436 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"
437 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
439 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
440 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
441 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------";
442 val eval_ = ("Rings.divide_class.divide", eval_cancel "#divide_e" : eval_fn);
443 val t = @{term "- 1 / 2 ::real"};
445 ML\<open>Eval.adhoc_thm\<close> is called while searching terms for adjacent numerals
446 given a certain ML_type\<open>eval_fn\<close> and a certain ML\<open>term\<close> ..
450 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2")
451 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE
453 STEP-INTO BEVORE REMOVING THE ERROR:
454 val SOME ("#divide_e~1_2", adhoc_thm) =
455 Eval.adhoc_thm @{theory} eval_ t;
456 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
458 ("#divide_e~1_2", t'') =
459 (*case*) get_pair thy op_ eval_fn t (*of*);
461 get_pair finds two adjacent numerals and does NOT distinguish between different kinds of
462 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input..
464 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2"
467 val NONE = adhoc_thm @{theory} eval_ t;
468 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t);
470 (*case*) get_pair thy op_ eval_fn t (*of*);
473 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
474 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
475 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
476 val t = TermC.str2term "sqrt 4";
477 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t;
479 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
480 ((ThyC.get_theory "Isac_Knowledge"),
481 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
483 val SOME (thmid, t) =
484 (*case*) get_pair thy op_ eval_fn ct (*of*);
485 (*+*)val "sqrt 4 = 2" = UnparseC.term t;
488 Skip_Proof.make_thm thy t;
490 exception TYPE raised (line 169 of "consts.ML"): Illegal type
491 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
494 "----------- fun power -------------------------------------------------------------------------";
495 "----------- fun power -------------------------------------------------------------------------";
496 "----------- fun power -------------------------------------------------------------------------";
497 if power 2 3 = 8 then () else error "power 2 3 = 8";
498 if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
499 if power ~3 2 = 9 then () else error "power ~3 2 = 9";
500 case \<^try>\<open> power 3 ~2 \<close> of
501 SOME _ => raise error "power 3 ~2: should raise an exn 1"
504 "----------- fun divisors ----------------------------------------------------------------------";
505 "----------- fun divisors ----------------------------------------------------------------------";
506 "----------- fun divisors ----------------------------------------------------------------------";
507 if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
508 if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
509 if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
510 if divisors 11 = [11] then () else error "divisors 11 = [11]";
512 "----------- fun doubles, fun squfact ----------------------------------------------------------";
513 "----------- fun doubles, fun squfact ----------------------------------------------------------";
514 "----------- fun doubles, fun squfact ----------------------------------------------------------";
515 if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
516 if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
518 if squfact 30 = 1 then () else error "squfact 30 changed";
519 if squfact 32 = 4 then () else error "squfact 32 changed";
520 if squfact 60 = 2 then () else error "squfact 60 changed";
521 if squfact 11 = 1 then () else error "squfact 11 changed";