1 (* Title: "ProgLang/evaluate.sml"
2 Author: Walther Neuper 2000
3 (c) copyright due to lincense terms.
6 "--------------------------------------------------------";
7 "table of contents --------------------------------------";
8 "--------------------------------------------------------";
9 "-calculate.thy: provides 'setup' -----------------------";
10 "----------- fun norm -----------------------------------";
11 "----------- check return value of adhoc_thm ----";
12 "----------- fun calculate_ --------------------------------------------------------------------";
13 "----------- calculate from Prog --------------------------------- -----------------------------";
14 "----------- calculate from script --requires 'setup'----";
15 "----------- calculate check test-root-equ --------------";
16 "----------- check calculate bottom up -----------------";
17 "----------- Prog_Expr.pow Power.power_class.power ---------";
18 "----------- fun cancel_int --------------------------------------------------------------------";
19 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
20 "----------- get_pair with 3 args -----------------------";
21 "----------- calculate (2 * x is_const) -----------------";
22 "----------- fun get_pair: examples ------------------------------------------------------------";
23 "----------- fun adhoc_thm: examples -----------------------------------------------------------";
24 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------";
25 "----------- fun power -------------------------------------------------------------------------";
26 "----------- fun divisors ----------------------------------------------------------------------";
27 "----------- fun doubles, fun squfact ----------------------------------------------------------";
28 "--------------------------------------------------------";
29 "--------------------------------------------------------";
30 "--------------------------------------------------------";
32 "----------- check return value of adhoc_thm ----";
33 "----------- check return value of adhoc_thm ----";
34 "----------- check return value of adhoc_thm ----";
35 val thy = @{theory "Poly"};
36 val cal = snd (assoc_calc' thy "is_polyexp");
37 val t = @{term "(x / x) is_polyexp"};
38 val SOME (thmID, thm) = adhoc_thm thy cal t;
39 (HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop")
41 error "evaluate.sml: adhoc_thm must return Trueprop";
43 "----------- fun calculate_ --------------------------------------------------------------------";
44 "----------- fun calculate_ --------------------------------------------------------------------";
45 "----------- fun calculate_ --------------------------------------------------------------------";
46 (* fun rewrite__set_ \<longrightarrow> fun rew_once works the same way *)
47 val t = TermC.str2term "((1+2)*4/3) \<up> 2";
49 val times = ("Groups.times_class.times", eval_binop "#mult_") : string * Eval_Def.eval_fn;
50 val plus = ("Groups.plus_class.plus", eval_binop "#add_") : string * Eval_Def.eval_fn;
51 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn;
52 val pow = ("Transcendental.powr", eval_binop "#power_") : string * Eval_Def.eval_fn;
54 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t);
55 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t;
56 val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
57 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed";
59 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t');
60 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t';
61 val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
62 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed";
64 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t'');
65 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t;
66 val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
67 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed";
69 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t''');
70 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t;
71 val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord Rule_Set.empty true adh_thm t;
72 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed";
74 "----------- calculate from Prog --------------------------------- -----------------------------";
75 "----------- calculate from Prog --------------------------------- -----------------------------";
76 "----------- calculate from Prog --------------------------------- -----------------------------";
77 val thy = @{theory "Test"};
78 val fmz = ["realTestGiven (((1+2)*4/3) \<up> 2)", "realTestFind s"];
80 ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
82 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
83 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
84 (*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) \<up> #2)")*)
85 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
86 (*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
87 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
88 (*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
89 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
90 (*nxt = ("Specify_Problem",Specify_Problem ["calculate", "test"])*)
91 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
92 (*nxt = ("Specify_Method",Specify_Method ("Test", "test_calculate"))*)
93 val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
94 (*nxt = ("Apply_Method",Apply_Method ("Test", "test_calculate"))*)
96 (*[1], Frm*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "PLUS")*)
97 (*[1], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "TIMES")*)
98 (*[2], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "DIVIDE")*)
99 (*[3], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Calculate",Calculate "POWER")*)
100 (*[4], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("Check_Postcond",Check_Postcond ["calculate", "test"])*)
101 (*[], Res*)val (p,_,f,nxt,_,pt) = me nxt p [1] pt; (*nxt = ("End_Proof'",End_Proof')*)
102 case f of Test_Out.FormKF "16" => () | _ =>
103 error "evaluate.sml: script test_calculate changed behaviour";
106 "----------- calculate check test-root-equ --------------";
107 "----------- calculate check test-root-equ --------------";
108 "----------- calculate check test-root-equ --------------";
109 (*(1): 2nd Test_simplify didn't work:
111 "sqrt (x \<up> 2 + -3 * x) = (-3 + 2 * x + - 1 * (9 + 4 * x)) / (- 1 * 2)"
112 > val rls = ("Test_simplify");
113 > val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
114 val ct = "sqrt (x \<up> 2 + -3 * x) =
115 (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))";
116 ie. cancel does not work properly
118 val thy = @{theory "Test"};
119 val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"));
120 val ct = ThmC_Def.num_to_Free @{term
121 "sqrt (x \<up> 2 + -3 * x) = (-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))"};
122 case calculate_ thy op_ ct of
124 | NONE => error "calculate_ test-root-equ changed";
126 sqrt (x \<up> 2 + -3 * x) =\
127 \(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
128 ............... does not work *)
130 (*--------------(2): does divide work in Test_simplify ?: ------*)
131 val thy = @{theory Test};
132 val t = (Thm.term_of o the o (TermC.parse thy)) "6 / 2";
133 val rls = Test_simplify;
134 val (t,_) = the (rewrite_set_ thy false rls t);
135 (*val t = Free ("3", "Real.real") : term*)
137 (*--------------(3): is_const works ?: -------------------------------------*)
138 val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
140 rewrite_set_ @{theory Test} false tval_rls t;
141 (*val it = SOME (Const ("HOL.True", "bool"),[]) ... works*)
143 val t = TermC.str2term "2 * x is_const";
144 val SOME (str,t') = eval_const "" "" 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;
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" "Rings.divide_class.divide" 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
169 SOME (t', _) => (*WAS "x + 2" WITH OLD numerals TOODOO?*)
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; (*=true3.6.03*)
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 (*WAS "x + - 2" WITH OLD numerals TOODOO?*)
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_ = "Transcendental.powr" : 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 ("Transcendental.powr", _) $ (Const ("Num.numeral_class.numeral", _) $ (Const ("Num.num.Bit1", _) $ Const ("Num.num.One", _))) $
284 (Const ("Num.numeral_class.numeral", _) $ (Const ("Num.num.Bit0", _) $ Const ("Num.num.One", _)))) => ()
285 | _ => error "3 \<up> 2 CHANGED";
286 val SOME (id, t') = eval_binop thmid op_ t thy;
287 (*** calc: operator = pow not defined*)
289 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop 3 \<up> 2 = 9 CHANGED";
292 "----------- fun cancel_int --------------------------------------------------------------------";
293 "----------- fun cancel_int --------------------------------------------------------------------";
294 "----------- fun cancel_int --------------------------------------------------------------------";
295 if cancel_int (~4, 2) = (~1, (2, 1)) then () else error "cancel_int (~4, 2) CHANGED";
296 if cancel_int (4, ~8) = (~1, (1, 2)) then () else error "cancel_int (4, ~8) CHANGED";
297 if cancel_int (6, 4) = (1, (3, 2)) then () else error "cancel_int (6, 4)CHANGED";
300 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
301 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
302 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
303 val (t1, t2) = (@{term 3}, @{term "2::real"});
305 "~~~~~ fun calcul , args:"; val (op_, (t1, t2)) = ("Groups.plus_class.plus", (t1, t2));
306 val (Const ("Num.numeral_class.numeral", _) $ n1) = t1;
307 val (Const ("Num.numeral_class.numeral", _) $ n2) = t2;
308 val (T, _) = HOLogic.dest_number t1
309 val (i1, i2) = (HOLogic.dest_numeral n1, HOLogic.dest_numeral n2)
312 "Groups.plus_class.plus" => i1 + i2
313 | "Groups.minus_class.minus" => i1 - i2
314 | "Groups.times_class.times" => i1 * i2
315 | "Transcendental.powr" => power i1 i2
316 | str => raise ERROR ("calcul not impl.for op_ " ^ str)
318 val xxx = HOLogic.mk_number T result;
320 case HOLogic.dest_number xxx of
322 | _ => error "calcul + 2 3 CHANGED";
324 case HOLogic.dest_number (calcul "Groups.minus_class.minus" (t1, t2)) of
326 | _ => error "calcul - 2 3 CHANGED";
328 case HOLogic.dest_number (calcul "Groups.times_class.times" (t1, t2)) of
330 | _ => error "calcul - 2 3 CHANGED";
332 (* (calcul "Rings.divide_class.divide" (t1, t2)
333 ERROR: calcul not impl.for op_ Rings.divide_class.divide*)
335 case HOLogic.dest_number (calcul "Transcendental.powr" (t1, t2)) of
337 | _ => error "calcul - 2 3 CHANGED";
340 "----------- get_pair with 3 args --------------------------------";
341 "----------- get_pair with 3 args --------------------------------";
342 "----------- get_pair with 3 args --------------------------------";
343 val (thy, op_, ef, arg) =
344 (thy, "EqSystem.occur_exactly_in",
345 assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd,
347 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
349 val SOME (str, simpl) = get_pair thy op_ ef arg;
351 "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2 = True"
352 then () else error "evaluate.sml get_pair with 3 args:occur_exactly_in";
355 "----------- calculate (2 * x is_const) -----------------";
356 "----------- calculate (2 * x is_const) -----------------";
357 "----------- calculate (2 * x is_const) -----------------";
358 val t = TermC.str2term "2 * x is_const";
359 val SOME (str, t') = eval_const "" "" t @{theory Test};
360 if UnparseC.term t' = "(2 * x is_const) = False" then ()
361 else error "eval_const 2 * x is_const 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_const 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_const");
413 val t = @{term "9 is_const"};
414 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
415 if str = "#is_const_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_const) = True"
416 then () else error "adhoc_thm 9 is_const changed";
418 case assoc_calc thy "Orderings.ord_class.less" 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";
463 (* TODO.ThmC.numerals_to_Free 1 * )
464 exception TYPE raised (line 169 of "consts.ML"): Illegal type
465 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
466 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t
468 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) =
469 ((ThyC.get_theory "Isac_Knowledge"),
470 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> theory -> (string * term) option), t);
471 val SOME (thmid, t) =
472 (*case*) get_pair thy op_ eval_fn ct (*of*);
474 exception TYPE raised (line 169 of "consts.ML"): Illegal type
475 for constant "HOL.eq" :: real \<Rightarrow> (num \<Rightarrow> real) \<Rightarrow> bool (**)
476 Skip_Proof.make_thm thy t
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";