53 val plus = ("Groups.plus_class.plus", Calc_Binop.numeric "#add_") : string * Eval_Def.eval_fn; |
53 val plus = ("Groups.plus_class.plus", Calc_Binop.numeric "#add_") : string * Eval_Def.eval_fn; |
54 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn; |
54 val divide = ("Rings.divide_class.divide", eval_cancel "#divide_e") : string * Eval_Def.eval_fn; |
55 val pow = (\<^const_name>\<open>realpow\<close>, Calc_Binop.numeric "#power_") : string * Eval_Def.eval_fn; |
55 val pow = (\<^const_name>\<open>realpow\<close>, Calc_Binop.numeric "#power_") : string * Eval_Def.eval_fn; |
56 |
56 |
57 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t); |
57 "~~~~~ fun calculate_ , args:"; val (thy, isa_fn, t) = (thy, plus, t); |
58 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t; |
58 val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{context} isa_fn t; |
59 val SOME (t', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
59 val SOME (t', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
60 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed"; |
60 if UnparseC.term t' = "(3 * 4 / 3) \<up> 2" then () else error "calculate_ 1 + 2 = 3 changed"; |
61 |
61 |
62 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t'); |
62 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t'); |
63 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t'; |
63 val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{context} isa_fn t'; |
64 val SOME (t'', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
64 val SOME (t'', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
65 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed"; |
65 if UnparseC.term t'' = "(12 / 3) \<up> 2" then () else error "calculate_ 3 * 4 = 12 changed"; |
66 |
66 |
67 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t''); |
67 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t''); |
68 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t; |
68 val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{context} isa_fn t; |
69 val SOME (t''', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
69 val SOME (t''', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
70 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed"; |
70 if UnparseC.term t''' = "4 \<up> 2" then () else error "calculate_ 12 / 3 = 4 changed"; |
71 |
71 |
72 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t'''); |
72 "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t'''); |
73 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t; |
73 val SOME ("#: 4 \<up> 2 = 16", adh_thm) = adhoc_thm @{context} isa_fn t; |
74 val SOME (t'''', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
74 val SOME (t'''', []) = rewrite__ ctxt 0 [] Rewrite_Ord.function_empty Rule_Set.empty true adh_thm t; |
75 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed"; |
75 if UnparseC.term t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed"; |
76 |
76 |
77 "----------- calculate from Prog --------------------------------- -----------------------------"; |
77 "----------- calculate from Prog --------------------------------- -----------------------------"; |
78 "----------- calculate from Prog --------------------------------- -----------------------------"; |
78 "----------- calculate from Prog --------------------------------- -----------------------------"; |
222 " ================= evaluate.sml: calculate_ 2002 =================== "; |
222 " ================= evaluate.sml: calculate_ 2002 =================== "; |
223 " ================= evaluate.sml: calculate_ 2002 =================== "; |
223 " ================= evaluate.sml: calculate_ 2002 =================== "; |
224 |
224 |
225 val thy = @{theory Test}; |
225 val thy = @{theory Test}; |
226 val t = TermC.parseNEW' ctxt "12 / 3"; |
226 val t = TermC.parseNEW' ctxt "12 / 3"; |
227 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; |
227 val SOME (thmID,thm) = adhoc_thm ctxt(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; |
228 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
228 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
229 "12 / 3 = 4"; |
229 "12 / 3 = 4"; |
230 val thy = @{theory Test}; |
230 val thy = @{theory Test}; |
231 val t = TermC.parseNEW' ctxt "4 \<up> 2"; |
231 val t = TermC.parseNEW' ctxt "4 \<up> 2"; |
232 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; |
232 val SOME (thmID,thm) = adhoc_thm ctxt(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; |
233 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
233 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
234 "4 ^ 2 = 16"; |
234 "4 ^ 2 = 16"; |
235 |
235 |
236 val t = TermC.parseNEW' ctxt "((1 + 2) * 4 / 3) \<up> 2"; |
236 val t = TermC.parseNEW' ctxt "((1 + 2) * 4 / 3) \<up> 2"; |
237 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t; |
237 val SOME (thmID,thm) = adhoc_thm ctxt (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t; |
238 "1 + 2 = 3"; |
238 "1 + 2 = 3"; |
239 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
239 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
240 UnparseC.term t; |
240 UnparseC.term t; |
241 "(3 * 4 / 3) \<up> 2"; |
241 "(3 * 4 / 3) \<up> 2"; |
242 val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t; |
242 val SOME (thmID,thm) = adhoc_thm ctxt (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t; |
243 "3 * 4 = 12"; |
243 "3 * 4 = 12"; |
244 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
244 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
245 UnparseC.term t; |
245 UnparseC.term t; |
246 "(12 / 3) \<up> 2"; |
246 "(12 / 3) \<up> 2"; |
247 val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; |
247 val SOME (thmID,thm) =adhoc_thm ctxt(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; |
248 "12 / 3 = 4"; |
248 "12 / 3 = 4"; |
249 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
249 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
250 UnparseC.term t; |
250 UnparseC.term t; |
251 "4 \<up> 2"; |
251 "4 \<up> 2"; |
252 val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t; |
252 val SOME (thmID,thm) = adhoc_thm ctxt(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t; |
253 "4 \<up> 2 = 16"; |
253 "4 \<up> 2 = 16"; |
254 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
254 val SOME (t,_) = rewrite_ ctxt tless_true tval_rls true thm t; |
255 UnparseC.term t; |
255 UnparseC.term t; |
256 "16"; |
256 "16"; |
257 if it <> "16" then error "evaluate.sml: new behaviour in calculate_" |
257 if it <> "16" then error "evaluate.sml: new behaviour in calculate_" |
258 else (); |
258 else (); |
259 |
259 |
260 (*13.9.02 *** calc: operator = pow not defined*) |
260 (*13.9.02 *** calc: operator = pow not defined*) |
261 val t = TermC.parseNEW' ctxt "3 \<up> 2"; |
261 val t = TermC.parseNEW' ctxt "3 \<up> 2"; |
262 val SOME (thmID,thm) = |
262 val SOME (thmID,thm) = |
263 adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; |
263 adhoc_thm ctxt (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; |
264 (*** calc: operator = pow not defined*) |
264 (*** calc: operator = pow not defined*) |
265 |
265 |
266 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")); |
266 val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")); |
267 (* |
267 (* |
268 val op_ = \<^const_name>\<open>realpow\<close> : string |
268 val op_ = \<^const_name>\<open>realpow\<close> : string |
386 "----------- fun adhoc_thm: examples -----------------------------------------------------------"; |
386 "----------- fun adhoc_thm: examples -----------------------------------------------------------"; |
387 "----------- fun adhoc_thm: examples -----------------------------------------------------------"; |
387 "----------- fun adhoc_thm: examples -----------------------------------------------------------"; |
388 (*--------------------------------------------------------------------vvvvvvvvvv*) |
388 (*--------------------------------------------------------------------vvvvvvvvvv*) |
389 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num"); |
389 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_num"); |
390 val t = @{term "9 is_num"}; |
390 val t = @{term "9 is_num"}; |
391 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
391 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
392 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True" |
392 if str = "#is_num_9_" andalso ThmC_Def.string_of_thm thm = "(9 is_num) = True" |
393 then () else error "adhoc_thm 9 is_num changed"; |
393 then () else error "adhoc_thm 9 is_num changed"; |
394 |
394 |
395 case assoc_calc thy \<^const_name>\<open>less\<close> of |
395 case assoc_calc thy \<^const_name>\<open>less\<close> of |
396 "le" => () | _ => error "Orderings.ord_class.less <-> le changed"; |
396 "le" => () | _ => error "Orderings.ord_class.less <-> le changed"; |
397 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le"); |
397 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le"); |
398 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED"; |
398 if isa_str = "Orderings.ord_class.less" then () else error "adhoc_thm (4 < 4) = False CHANGED"; |
399 |
399 |
400 val t = @{term "4 < (4 :: real)"}; |
400 val t = @{term "4 < (4 :: real)"}; |
401 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
401 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
402 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False" |
402 if str = "#less_4_4" andalso ThmC_Def.string_of_thm thm = "(4 < 4) = False" |
403 then () else error "adhoc_thm 4 < 4 changed"; |
403 then () else error "adhoc_thm 4 < 4 changed"; |
404 |
404 |
405 val SOME t = parseNEW @{context} "a < 4"; |
405 val SOME t = parseNEW @{context} "a < 4"; |
406 case adhoc_thm thy (isa_str, eval_fn) t of |
406 case adhoc_thm ctxt (isa_str, eval_fn) t of |
407 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE"; |
407 NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE"; |
408 |
408 |
409 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS"); |
409 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS"); |
410 val SOME t = parseNEW @{context} "1 + (2::real)"; |
410 val SOME t = parseNEW @{context} "1 + (2::real)"; |
411 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
411 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
412 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3" |
412 if str = "#: 1 + 2 = 3" andalso ThmC_Def.string_of_thm thm = "1 + 2 = 3" |
413 then () else error "adhoc_thm 1 + 2 changed"; |
413 then () else error "adhoc_thm 1 + 2 changed"; |
414 |
414 |
415 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"); |
415 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"); |
416 val t = @{term "6 / -8 :: real"}; |
416 val t = @{term "6 / -8 :: real"}; |
417 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
417 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
418 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4" |
418 if str = "#divide_e6_~8" andalso ThmC_Def.string_of_thm thm = "6 / - 8 = - 3 / 4" |
419 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed"; |
419 then () else error "adhoc_thm 6 / -8 = - 3 / 4 changed"; |
420 |
420 |
421 case assoc_calc thy "Prog_Expr.ident" of |
421 case assoc_calc thy "Prog_Expr.ident" of |
422 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed"; |
422 "ident" => () | _ => error "Prog_Expr.ident <-> ident changed"; |
423 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident"); |
423 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident"); |
424 |
424 |
425 val t = @{term "3 =!= (3 :: real)"}; |
425 val t = @{term "3 =!= (3 :: real)"}; |
426 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
426 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
427 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True" |
427 if str = "#ident_(3)_(3)" andalso ThmC_Def.string_of_thm thm = "(3 =!= 3) = True" |
428 then () else error "adhoc_thm (3 =!= 3) changed"; |
428 then () else error "adhoc_thm (3 =!= 3) changed"; |
429 |
429 |
430 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"}; |
430 val t = @{term "\<not> ((4 :: real) + (4 * x + x \<up> 2) =!= 0)"}; |
431 val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; |
431 val SOME (str, thm) = adhoc_thm ctxt (isa_str, eval_fn) t; |
432 if str = "#ident_(4 + (4 * x + x \<up> 2))_(0)" andalso ThmC_Def.string_of_thm thm = "(4 + (4 * x + x \<up> 2) =!= 0) = False" |
432 if str = "#ident_(4 + (4 * x + x \<up> 2))_(0)" andalso ThmC_Def.string_of_thm thm = "(4 + (4 * x + x \<up> 2) =!= 0) = False" |
433 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed"; |
433 then () else error "adhoc_thm (\<not> (4 + (4 * x + x ^ 2) =!= 0)) changed"; |
434 |
434 |
435 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------"; |
435 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------"; |
436 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------"; |
436 "----------- fun adhoc_thm + fun eval_cancel ---------------------------------------------------"; |
446 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2") |
446 Eval.get_pair for \<^const_name>\<open>divide\<close> \<longrightarrow> SOME (_, "- 1 / 2 = - 1 / 2") |
447 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE |
447 but rewrite__ on "x = - 0 \<or> x = - 1 / 2" \<longrightarrow> NONE |
448 |
448 |
449 STEP-INTO BEVORE REMOVING THE ERROR: |
449 STEP-INTO BEVORE REMOVING THE ERROR: |
450 val SOME ("#divide_e~1_2", adhoc_thm) = |
450 val SOME ("#divide_e~1_2", adhoc_thm) = |
451 Eval.adhoc_thm @{theory} eval_ t; |
451 Eval.adhoc_thm @{context} eval_ t; |
452 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t); |
452 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t); |
453 val SOME |
453 val SOME |
454 ("#divide_e~1_2", t'') = |
454 ("#divide_e~1_2", t'') = |
455 (*case*) get_pair ctxt op_ eval_fn t (*of*); |
455 (*case*) get_pair ctxt op_ eval_fn t (*of*); |
456 (* |
456 (* |
458 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input.. |
458 \<^ML_type>\<open>eval_fn\<close>. In case of \<^ML>\<open>eval_cancel\<close> the return value WAS the same as the input.. |
459 *) |
459 *) |
460 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2" |
460 (*+*)ThmC.string_of_thm adhoc_thm = "- 1 / 2 = - 1 / 2" |
461 *) |
461 *) |
462 |
462 |
463 val NONE = adhoc_thm @{theory} eval_ t; |
463 val NONE = adhoc_thm @{context} eval_ t; |
464 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t); |
464 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), t) = (@{theory}, eval_, t); |
465 val NONE = |
465 val NONE = |
466 (*case*) get_pair ctxt op_ eval_fn t (*of*); |
466 (*case*) get_pair ctxt op_ eval_fn t (*of*); |
467 |
467 |
468 |
468 |
469 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
469 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
470 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
470 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
471 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
471 "----------- fun adhoc_thm \<longrightarrow> exception TYPE --------------------------------------------------"; |
472 val t = TermC.str2term "sqrt 4"; |
472 val t = TermC.str2term "sqrt 4"; |
473 Eval.adhoc_thm (ThyC.get_theory "Isac_Knowledge") ("NthRoot.sqrt", eval_sqrt "#sqrt_") t; |
473 Eval.adhoc_thm @{context} ("NthRoot.sqrt", eval_sqrt "#sqrt_") t; |
474 |
474 |
475 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) = |
475 "~~~~~ fun adhoc_thm , args:"; val (thy, (op_, eval_fn), ct) = |
476 ((ThyC.get_theory "Isac_Knowledge"), |
476 ((ThyC.get_theory "Isac_Knowledge"), |
477 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> Proof.context -> (string * term) option), t); |
477 ("NthRoot.sqrt", eval_sqrt "#sqrt_": string -> term -> Proof.context -> (string * term) option), t); |
478 |
478 |