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 \<longrightarrow> exception TYPE --------------------------------------------------";
26 "----------- fun power -------------------------------------------------------------------------";
27 "----------- fun divisors ----------------------------------------------------------------------";
28 "----------- fun doubles, fun squfact ----------------------------------------------------------";
29 "--------------------------------------------------------";
30 "--------------------------------------------------------";
31 "--------------------------------------------------------";
33 "----------- check return value of adhoc_thm ----";
34 "----------- check return value of adhoc_thm ----";
35 "----------- check return value of adhoc_thm ----";
36 val thy = @{theory "Poly"};
37 val cal = snd (assoc_calc' thy "is_polyexp");
38 val t = @{term "(x / x) is_polyexp"};
39 val SOME (thmID, thm) = adhoc_thm thy cal t;
40 (HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop")
42 error "evaluate.sml: adhoc_thm must return Trueprop";
44 "----------- fun calculate_ --------------------------------------------------------------------";
45 "----------- fun calculate_ --------------------------------------------------------------------";
46 "----------- fun calculate_ --------------------------------------------------------------------";
47 (* fun rewrite__set_ \<longrightarrow> fun rew_once works the same way *)
48 val t = TermC.str2term "((1+2)*4/3) \<up> 2";
50 val times = ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
51 val plus = ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
52 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
53 val pow = ("Transcendental.powr", eval_binop "#power_") : string * Eval_Def.eval_fn;
55 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
56 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
57 val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
58 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed";
60 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
61 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
62 val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
63 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed";
65 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
66 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
67 val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
68 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed";
70 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
71 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
72 val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
73 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed";
75 "----------- calculate from Prog --------------------------------- -----------------------------";
76 "----------- calculate from Prog --------------------------------- -----------------------------";
77 "----------- calculate from Prog --------------------------------- -----------------------------";
78 val thy = @{theory "Test"};
79 val fmz = ["realTestGiven (((1+2)*4/3) \<up> 2)", "realTestFind s"];
81 ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
83 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
84 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
85 (*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) \<up> #2)")*)
86 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
87 (*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
88 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
89 (*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
90 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
91 (*nxt = ("Specify_Problem",Specify_Problem ["calculate", "test"])*)
92 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
93 (*nxt = ("Specify_Method",Specify_Method ("Test", "test_calculate"))*)
94 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
95 (*nxt = ("Apply_Method",Apply_Method ("Test", "test_calculate"))*)
97 (*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "PLUS")*)
98 (*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "TIMES")*)
99 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "DIVIDE")*)
100 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "POWER")*)
101 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Check_Postcond",Check_Postcond ["calculate", "test"])*)
102 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("End_Proof'",End_Proof')*)
103 case f of Test_Out.FormKF "16" => () | _ =>
104 error "evaluate.sml: script test_calculate changed behaviour";
107 "----------- calculate check test-root-equ --------------";
108 "----------- calculate check test-root-equ --------------";
109 "----------- calculate check test-root-equ --------------";
110 (*(1): 2nd Test_simplify didn't work:
112 "sqrt (x \<up> 2 + -3 * x) = (-3 + 2 * x + - 1 * (9 + 4 * x)) / (- 1 * 2)"
113 > val rls = ("Test_simplify");
114 > val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
115 val ct = "sqrt (x \<up> 2 + -3 * x) =
116 (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))";
117 ie. cancel does not work properly
119 val thy = @{theory "Test"};
120 val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
122 "sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
123 case calculate_ thy op_ ct of
125 | NONE => error "calculate_ test-root-equ changed";
127 sqrt (x \<up> 2 + -3 * x) =\
128 \(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
129 ............... does not work *)
131 (*--------------(2): does divide work in Test_simplify ?: ------*)
132 val thy = @{theory Test};
133 val t = (Thm.term_of o the o (TermC.parse thy)) "6 / 2";
134 val rls = Test_simplify;
135 val (t,_) = the (rewrite_set_ thy false rls t);
136 (*val t = Free ("3", "Real.real") : term*)
138 (*--------------(3): is_num works ?: -------------------------------------*)
139 val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_num";
141 rewrite_set_ @{theory Test} false tval_rls t;
142 (*val it = SOME (Const (\<^const_name>\<open>True\<close>, "bool"),[]) ... works*)
144 val t = TermC.str2term "2 * x is_num";
145 val NONE = eval_is_num "" "" t (@{theory "Isac_Knowledge"});
148 "----------- check calculate bottom up ------------------";
149 "----------- check calculate bottom up ------------------";
150 "----------- check calculate bottom up ------------------";
151 (*-------------- eval_cancel works: *)
152 Rewrite.trace_on := false; (*true false*)
153 val thy = @{theory Test};
154 val rls = Test_simplify;
155 val t = (Thm.term_of o the o (TermC.parse thy)) "(-4) / 2";
157 val SOME (_, t) = eval_cancel "xxx" \<^const_name>\<open>divide\<close> t thy;
159 (*--------------(5): reproduce (1) with simpler term: ------------*)
160 val t = (Thm.term_of o the o (TermC.parse thy)) "(3+5)/2";
161 case rewrite_set_ thy false rls t of
163 if UnparseC.term t' = "4" then ()
164 else error "rewrite_set_ (3+5)/2 changed 1"
165 | _ => error "rewrite_set_ (3+5)/2 changed 2";
167 val t = (Thm.term_of o the o (TermC.parse thy)) "(3+1+2*x)/2";
168 case rewrite_set_ thy false rls t of
170 if UnparseC.term t' = "2 + x" then () else error "rewrite_set_ (3+1+2*x)/2 changed 1"
171 | _ => error "rewrite_set_ (3+1+2*x)/2 changed 2";
173 Rewrite.trace_on := false; (*true false*)
175 (*--- Rewrite.trace_on 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 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
205 val t = (Thm.term_of o the o (TermC.parse thy)) "x + (- 1 + -3) / 2";
206 val SOME (res, []) = rewrite_set_ thy false rls t;
207 if UnparseC.term res = "- 2 + x" then () else error "rewrite_set_ x + (- 1 + -3) / 2 changed";
210 ### trying calc. 'cancel'
211 @@@ get_pair: binop, t = x + (-4) / 2
213 @@@ get_pair: t else -> NONE
214 @@@ get_pair: binop, t = (-4) / 2
216 @@@ get_pair: t -> NONE
217 @@@ get_pair: t1 -> NONE
219 ### trying calc. 'pow'
222 Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
224 " ================= evaluate.sml: calculate_ 2002 =================== ";
225 " ================= evaluate.sml: calculate_ 2002 =================== ";
226 " ================= evaluate.sml: calculate_ 2002 =================== ";
228 val thy = @{theory Test};
229 val t = (Thm.term_of o the o (TermC.parse thy)) "12 / 3";
230 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
231 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
233 val thy = @{theory Test};
234 val t = (Thm.term_of o the o (TermC.parse thy)) "4 \<up> 2";
235 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
236 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
239 val t = (Thm.term_of o the o (TermC.parse thy)) "((1 + 2) * 4 / 3) \<up> 2";
240 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t;
242 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
244 "(3 * 4 / 3) \<up> 2";
245 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t;
247 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
250 val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
252 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
255 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
257 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
260 if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
263 (*13.9.02 *** calc: operator = pow not defined*)
264 val t = (Thm.term_of o the o (TermC.parse thy)) "3 \<up> 2";
265 val SOME (thmID,thm) =
266 adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t;
267 (*** calc: operator = pow not defined*)
269 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
271 val op_ = \<^const_name>\<open>powr\<close> : string
272 val eval_fn = fn : string -> term -> theory -> (string * term) option*)
274 val SOME (thmid,t') = get_pair thy op_ eval_fn t;
275 (*** calc: operator = pow not defined*)
277 val SOME (id,t') = eval_fn op_ t thy;
278 (*** calc: operator = pow not defined*)
281 ("Transcendental.powr",
282 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>, _))) $
283 (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) => ()
284 | _ => error "3 \<up> 2 CHANGED";
285 val SOME (id, t') = eval_binop thmid op_ t thy;
286 (*** calc: operator = pow not defined*)
288 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
291 "----------- fun cancel_int --------------------------------------------------------------------";
292 "----------- fun cancel_int --------------------------------------------------------------------";
293 "----------- fun cancel_int --------------------------------------------------------------------";
294 if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
295 if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
296 if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
299 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
300 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
301 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
302 val (t1, t2) = (@{term 3}, @{term "2::real"});
304 "~~~~~ fun calcul , args:"; val (op_, (t1, t2)) = ("Groups.plus_class.plus", (t1, t2));
305 val (Const (\<^const_name>\<open>numeral\<close>, _) $ n1) = t1;
306 val (Const (\<^const_name>\<open>numeral\<close>, _) $ n2) = t2;
307 val (T, _) = HOLogic.dest_number t1
308 val (i1, i2) = (HOLogic.dest_numeral n1, HOLogic.dest_numeral n2)
311 "Groups.plus_class.plus" => i1 + i2
312 | "Groups.minus_class.minus" => i1 - i2
313 | "Groups.times_class.times" => i1 * i2
314 | "Transcendental.powr" => power i1 i2
315 | str => raise ERROR ("calcul not impl.for op_ " ^ str)
317 val xxx = HOLogic.mk_number T result;
319 case HOLogic.dest_number xxx of
321 | _ => error "calcul + 2 3 CHANGED";
323 case HOLogic.dest_number (calcul "Groups.minus_class.minus" (t1, t2)) of
325 | _ => error "calcul - 2 3 CHANGED";
327 case HOLogic.dest_number (calcul "Groups.times_class.times" (t1, t2)) of
329 | _ => error "calcul - 2 3 CHANGED";
331 (* (calcul "Rings.divide_class.divide" (t1, t2)
332 ERROR: calcul not impl.for op_ Rings.divide_class.divide*)
334 case HOLogic.dest_number (calcul "Transcendental.powr" (t1, t2)) of
336 | _ => error "calcul - 2 3 CHANGED";
339 "----------- get_pair with 3 args --------------------------------";
340 "----------- get_pair with 3 args --------------------------------";
341 "----------- get_pair with 3 args --------------------------------";
342 val (thy, op_, ef, arg) =
343 (thy, "EqSystem.occur_exactly_in",
344 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
346 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
348 val SOME (str, simpl) = get_pair thy op_ ef arg;
350 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
351 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
354 "----------- calculate (2 * x is_num) -------------------";
355 "----------- calculate (2 * x is_num) -------------------";
356 "----------- calculate (2 * x is_num) -------------------";
357 val t = TermC.str2term "(2::real) * x is_num";
359 val SOME (str, t') = eval_is_num "" "Prog_Expr.is_num" t @{theory Test};
360 if UnparseC.term t' = "(2 * x is_num) = False" then ()
361 else error "is_num 2 * x is_num CHANGED";
363 val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
364 if UnparseC.term t' = "False" then ()
365 else error "rewrite_set_ 2 * x is_num CHANGED";
367 "----------- fun get_pair: examples ------------------------------------------------------------";
368 "----------- fun get_pair: examples ------------------------------------------------------------";
369 "----------- fun get_pair: examples ------------------------------------------------------------";
371 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
372 if isa_str = "Groups.plus_class.plus" then () else error "eval_fn PLUS changed";
374 val t = @{term "3 + 4 :: real"};
375 val SOME (str, term) = get_pair thy isa_str eval_fn t;
376 (*+*)if str = "#: 3 + 4 = 7" andalso UnparseC.term term = "3 + 4 = 7"
377 (*+*)then () else error "get_pair 3 + 4 changed";
379 val t = @{term "(a + 3) + 4 :: real"};
380 val SOME (str, term) = get_pair thy isa_str eval_fn t;
381 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
382 then () else error "get_pair (a + 3) + 4 changed";
384 val t = @{term "(a + 3) + 4 :: real"};
385 val SOME (str, term) = get_pair thy isa_str eval_fn t;
386 if str = "#: a + 3 + 4 = a + 7" andalso UnparseC.term term = "a + 3 + 4 = a + 7"
387 then () else error "get_pair (a + 3) + 4 changed";
389 val t = @{term "x = 5 * (3 + (4 + a) :: real)"};
390 val SOME (str, term) = get_pair thy isa_str eval_fn t;
391 if str = "#: 3 + (4 + a) = 7 + a" andalso UnparseC.term term = "3 + (4 + a) = 7 + a"
392 then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed";
394 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
396 val t = @{term "-4 / - 2 :: real"};
397 val SOME (str, term) = get_pair thy isa_str eval_fn t;
398 if str = "#divide_e~4_~2" andalso UnparseC.term term = "- 4 / - 2 = 2"
399 then () else error "get_pair -4 / - 2 changed";
401 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
403 val t = @{term "2 \<up> 3 :: real"};
404 val SOME (str, term) = get_pair thy isa_str eval_fn t;
405 if str = "#: 2 \<up> 3 = 8" andalso UnparseC.term term = "2 \<up> 3 = 8"
406 then () else error "get_pair 2 \<up> 3 changed";
408 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
409 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
410 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
411 (*--------------------------------------------------------------------vvvvvvvvvv*)
412 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num");
413 val t = @{term "9 is_num"};
414 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
415 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True"
416 then () else error "adhoc_thm 9 is_num changed";
418 case assoc_calc thy \<^const_name>\<open>less\<close> of
419 "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
420 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le");
421 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED";
423 val t = @{term "4 < (4 :: real)"};
424 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
425 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False"
426 then () else error "adhoc_thm 4 < 4 changed";
428 val SOME t = parseNEW @{context} "a < 4";
429 case adhoc_thm thy (isa_str, eval_fn) t of
430 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE";
432 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
433 val SOME t = parseNEW @{context} "1 + (2::real)";
434 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
435 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3"
436 then () else error "adhoc_thm 1 + 2 changed";
438 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
439 val t = @{term "6 / -8 :: real"};
440 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
441 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4"
442 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed";
444 case assoc_calc thy "Prog_Expr.ident" of
445 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed";
446 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident");
448 val t = @{term "3 =!= (3 :: real)"};
449 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
450 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True"
451 then () else error "adhoc_thm (3 =!= 3) changed";
453 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"};
454 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
455 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"
456 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed";
458 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
459 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
460 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
461 val t = TermC.str2term "sqrt 4";
462 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t;
464 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
465 ((ThyC.get_theory "Isac_Knowledge"),
466 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
468 val SOME (thmid, t) =
469 (*case*) get_pair thy op_ eval_fn ct (*of*);
470 (*+*)val "sqrt 4 = 2" = UnparseC.term t;
473 Skip_Proof.make_thm thy t;
475 exception TYPE raised (line 169 of "consts.ML"): Illegal type
476 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
479 "----------- fun power -------------------------------------------------------------------------";
480 "----------- fun power -------------------------------------------------------------------------";
481 "----------- fun power -------------------------------------------------------------------------";
482 if power 2 3 = 8 then () else error "power 2 3 = 8";
483 if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
484 if power ~3 2 = 9 then () else error "power ~3 2 = 9";
485 case \<^try>\<open> power 3 ~2 \<close> of
486 SOME _ => raise error "power 3 ~2: should raise an exn 1"
489 "----------- fun divisors ----------------------------------------------------------------------";
490 "----------- fun divisors ----------------------------------------------------------------------";
491 "----------- fun divisors ----------------------------------------------------------------------";
492 if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
493 if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
494 if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
495 if divisors 11 = [11] then () else error "divisors 11 = [11]";
497 "----------- fun doubles, fun squfact ----------------------------------------------------------";
498 "----------- fun doubles, fun squfact ----------------------------------------------------------";
499 "----------- fun doubles, fun squfact ----------------------------------------------------------";
500 if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
501 if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
503 if squfact 30 = 1 then () else error "squfact 30 changed";
504 if squfact 32 = 4 then () else error "squfact 32 changed";
505 if squfact 60 = 2 then () else error "squfact 60 changed";
506 if squfact 11 = 1 then () else error "squfact 11 changed";