wneuper@59546: (* Title: "ProgLang/calculate.sml" wneuper@59546: test calculation of values for function constants neuper@38022: Author: Walther Neuper 2000 neuper@38022: (c) copyright due to lincense terms. neuper@37906: *) neuper@37906: neuper@38022: "--------------------------------------------------------"; neuper@38022: "table of contents --------------------------------------"; neuper@38022: "--------------------------------------------------------"; neuper@55366: "-calculate.thy: provides 'setup' -----------------------"; neuper@41924: "----------- fun norm -----------------------------------"; wneuper@59255: "----------- check return value of adhoc_thm ----"; wneuper@59411: "----------- fun calculate_ --------------------------------------------------------------------"; wneuper@59411: "----------- calculate from Prog --------------------------------- -----------------------------"; neuper@55366: "----------- calculate from script --requires 'setup'----"; neuper@38032: "----------- calculate check test-root-equ --------------"; wneuper@59253: "----------- check calcul,ate bottom up -----------------"; walther@59603: "----------- Prog_Expr.pow Power.power_class.power ---------"; neuper@41934: " ================= calculate.sml: calculate_ 2002 ======"; neuper@38032: "----------- get_pair with 3 args -----------------------"; neuper@38032: "----------- calculate (2 * x is_const) -----------------"; wneuper@59387: "----------- fun get_pair: examples ------------------------------------------------------------"; wneuper@59387: "----------- fun adhoc_thm: examples -----------------------------------------------------------"; wneuper@59403: "----------- fun power -------------------------------------------------------------------------"; wneuper@59403: "----------- fun divisors ----------------------------------------------------------------------"; wneuper@59403: "----------- fun doubles, fun squfact ----------------------------------------------------------"; neuper@38022: "--------------------------------------------------------"; neuper@38022: "--------------------------------------------------------"; neuper@38022: "--------------------------------------------------------"; neuper@37906: wneuper@59255: "----------- check return value of adhoc_thm ----"; wneuper@59255: "----------- check return value of adhoc_thm ----"; wneuper@59255: "----------- check return value of adhoc_thm ----"; neuper@41924: val thy = @{theory "Poly"}; s1210629013@52153: val cal = snd (assoc_calc' thy "is_polyexp"); neuper@38022: val t = @{term "(x / x) is_polyexp"}; wneuper@59255: val SOME (thmID, thm) = adhoc_thm thy cal t; wneuper@59188: (HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop") neuper@38022: handle TERM _ => wneuper@59255: error "calculate.sml: adhoc_thm must return Trueprop"; neuper@38022: wneuper@59411: "----------- fun calculate_ --------------------------------------------------------------------"; wneuper@59411: "----------- fun calculate_ --------------------------------------------------------------------"; wneuper@59411: "----------- fun calculate_ --------------------------------------------------------------------"; wneuper@59411: (* fun rewrite__set_ \ fun rew_once works the same way *) wneuper@59411: val t = str2term "((1+2)*4/3)^^^2"; wneuper@59411: val thy = @{theory}; wneuper@59411: val times = ("Groups.times_class.times", eval_binop "#mult_") : string * eval_fn; wneuper@59411: val plus = ("Groups.plus_class.plus",eval_binop "#add_") : string * eval_fn; wneuper@59411: val divide = ("Rings.divide_class.divide" ,eval_cancel "#divide_e") : string * eval_fn; walther@59603: val pow = ("Prog_Expr.pow" ,eval_binop "#power_") : string * eval_fn; wneuper@59411: wneuper@59411: "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, plus, t); wneuper@59411: val SOME ("#: 1 + 2 = 3", adh_thm) = adhoc_thm @{theory} isa_fn t; wneuper@59411: val SOME (t', []) = rewrite__ thy 0 [] e_rew_ord e_rls true adh_thm t; wneuper@59411: if term2str t' = "(3 * 4 / 3) ^^^ 2" then () else error "calculate_ 1 + 2 = 3 changed"; wneuper@59411: wneuper@59411: "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, times, t'); wneuper@59411: val SOME ("#: 3 * 4 = 12", adh_thm) = adhoc_thm @{theory} isa_fn t'; wneuper@59411: val SOME (t'', []) = rewrite__ thy 0 [] e_rew_ord e_rls true adh_thm t; wneuper@59411: if term2str t'' = "(12 / 3) ^^^ 2" then () else error "calculate_ 3 * 4 = 12 changed"; wneuper@59411: wneuper@59411: "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, divide, t''); wneuper@59411: val SOME ("#divide_e12_3", adh_thm) = adhoc_thm @{theory} isa_fn t; wneuper@59411: val SOME (t''', []) = rewrite__ thy 0 [] e_rew_ord e_rls true adh_thm t; wneuper@59411: if term2str t''' = "4 ^^^ 2" then () else error "calculate_ 12 / 3 = 4 changed"; wneuper@59411: wneuper@59411: "~~~~~ fun calculate_, args:"; val (thy, isa_fn, t) = (thy, pow, t'''); wneuper@59411: val SOME ("#: 4 ^^^ 2 = 16", adh_thm) = adhoc_thm @{theory} isa_fn t; wneuper@59411: val SOME (t'''', []) = rewrite__ thy 0 [] e_rew_ord e_rls true adh_thm t; wneuper@59411: if term2str t'''' = "16" then () else error "calculate_ 12 / 3 = 4 changed"; wneuper@59411: wneuper@59411: "----------- calculate from Prog --------------------------------- -----------------------------"; wneuper@59411: "----------- calculate from Prog --------------------------------- -----------------------------"; wneuper@59411: "----------- calculate from Prog --------------------------------- -----------------------------"; neuper@41924: val thy = @{theory "Test"}; neuper@37906: val fmz = ["realTestGiven (((1+2)*4/3)^^^2)","realTestFind s"]; neuper@37906: val (dI',pI',mI') = neuper@38035: ("Test",["calculate","test"],["Test","test_calculate"]); neuper@38035: neuper@37906: val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))]; neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@37906: (*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) ^^^#2)")*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@37906: (*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38035: (*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@37906: (*nxt = ("Specify_Problem",Specify_Problem ["calculate","test"])*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38035: (*nxt = ("Specify_Method",Specify_Method ("Test","test_calculate"))*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38035: (*nxt = ("Apply_Method",Apply_Method ("Test","test_calculate"))*) neuper@37906: neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38033: (*nxt = ("Calculate",Calculate "PLUS")*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38033: (*nxt = ("Calculate",Calculate "TIMES")*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38033: (*nxt = ("Calculate",Calculate "DIVIDE")*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@38033: (*nxt = ("Calculate",Calculate "POWER")*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@37906: (*nxt = ("Check_Postcond",Check_Postcond ["calculate","test"])*) neuper@37906: val (p,_,f,nxt,_,pt) = me nxt p [1] pt; neuper@37906: (*nxt = ("End_Proof'",End_Proof')*) wneuper@59267: case f of FormKF "16" => () | _ => wneuper@59253: error "calculate.sml: script test_calculate changed behaviour"; neuper@37906: neuper@37906: neuper@38032: "----------- calculate check test-root-equ --------------"; neuper@38032: "----------- calculate check test-root-equ --------------"; neuper@38032: "----------- calculate check test-root-equ --------------"; neuper@37906: (*(1): 2nd Test_simplify didn't work: neuper@37906: val ct = neuper@37906: "sqrt (x ^^^ 2 + -3 * x) = (-3 + 2 * x + -1 * (9 + 4 * x)) / (-1 * 2)" neuper@37906: > val rls = ("Test_simplify"); neuper@37906: > val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct); neuper@37906: val ct = "sqrt (x ^^^ 2 + -3 * x) = neuper@37906: (-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))"; neuper@37906: ie. cancel does not work properly neuper@37906: *) wneuper@59382: val thy = @{theory "Test"}; walther@59686: val op_ = the (LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE")); wneuper@59382: val ct = numbers_to_string @{term wneuper@59382: "sqrt (x ^^^ 2 + -3 * x) = (-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))"}; wneuper@59382: case calculate_ thy op_ ct of wneuper@59382: SOME _ => () wneuper@59382: | NONE => error "calculate_ test-root-equ changed"; neuper@37906: (* neuper@37906: sqrt (x ^^^ 2 + -3 * x) =\ neuper@37906: \(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2)))) neuper@37906: ............... does not work *) neuper@37906: neuper@37906: (*--------------(2): does divide work in Test_simplify ?: ------*) akargl@42188: val thy = @{theory Test}; wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "6 / 2"; neuper@37906: val rls = Test_simplify; neuper@37906: val (t,_) = the (rewrite_set_ thy false rls t); neuper@55279: (*val t = Free ("3","Real.real") : term*) neuper@37906: neuper@37906: (*--------------(3): is_const works ?: -------------------------------------*) wneuper@59188: val t = (Thm.term_of o the o (parse @{theory Test})) "2 is_const"; neuper@37906: atomty t; akargl@42188: rewrite_set_ @{theory Test} false tval_rls t; neuper@41928: (*val it = SOME (Const ("HOL.True","bool"),[]) ... works*) neuper@37906: neuper@37906: val t = str2term "2 * x is_const"; wneuper@59592: val SOME (str,t') = eval_const "" "" t (@{theory "Isac_Knowledge"}); neuper@37906: term2str t'; neuper@37906: neuper@37906: neuper@38032: "----------- check calculate bottom up ------------------"; neuper@38032: "----------- check calculate bottom up ------------------"; neuper@38032: "----------- check calculate bottom up ------------------"; neuper@37906: (*-------------- eval_cancel works: *) neuper@52070: trace_rewrite:=false; akargl@42188: val thy = @{theory Test}; wneuper@59384: val rls = Test_simplify; wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "(-4) / 2"; akargl@42188: wneuper@59360: val SOME (_, t) = eval_cancel "xxx" "Rings.divide_class.divide" t thy; akargl@42188: neuper@37906: (*--------------(5): reproduce (1) with simpler term: ------------*) wneuper@59384: val t = (Thm.term_of o the o (parse thy)) "(3+5)/2"; wneuper@59384: case rewrite_set_ thy false rls t of wneuper@59384: SOME (Free ("4", _), []) => () wneuper@59384: | _ => error "rewrite_set_ (3+5)/2 changed"; neuper@37906: wneuper@59384: val t = (Thm.term_of o the o (parse thy)) "(3+1+2*x)/2"; wneuper@59384: case rewrite_set_ thy false rls t of wneuper@59384: SOME (Const ("Groups.plus_class.plus", _) $ Free ("2", _) $ Free ("x", _), []) => () wneuper@59384: | _ => error "rewrite_set_ (3+1+2*x)/2 changed"; neuper@37906: neuper@52070: trace_rewrite:=false; (*=true3.6.03*) akargl@42218: neuper@37906: (*--- trace_rewrite before correction of ... -------------------- neuper@37906: val ct = "(-3 + 2 * x + -1) / 2"; neuper@37906: val (ct,_) = the (rewrite_set thy' false rls ct); neuper@37906: : neuper@37906: ### trying thm 'root_ge0_2' neuper@37906: ### rewrite_set_: x + (-1 + -3) / 2 neuper@37906: ### trying thm 'radd_real_const_eq' neuper@37906: ### trying thm 'radd_real_const' neuper@37906: ### rewrite_set_: x + (-4) / 2 neuper@37906: ### trying thm 'rcollect_right' neuper@37906: : neuper@37906: "x + (-4) / 2" neuper@37906: -------------------------------------while before Isabelle20002: neuper@37906: val ct = "(#-3 + #2 * x + #-1) // #2"; neuper@37906: val (ct,_) = the (rewrite_set thy' false rls ct); neuper@37906: : neuper@37906: ### trying thm 'root_ge0_2' neuper@37906: ### rewrite_set_: x + (#-1 + #-3) // #2 neuper@37906: ### trying thm 'radd_real_const_eq' neuper@37906: ### trying thm 'radd_real_const' neuper@37906: ### rewrite_set_: x + #-4 // #2 neuper@37906: ### rewrite_set_: x + #-2 neuper@37906: ### trying thm 'rcollect_right' neuper@37906: : neuper@37906: "#-2 + x" neuper@37906: -----------------------------------------------------------------*) neuper@37906: neuper@37906: neuper@37906: (*===================*) neuper@52070: trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*) wneuper@59384: val t = (Thm.term_of o the o (parse thy)) "x + (-1 + -3) / 2"; wneuper@59384: val SOME (res, []) = rewrite_set_ thy false rls t; wneuper@59384: if term2str res = "-2 + x" then () else error "rewrite_set_ x + (-1 + -3) / 2 changed"; neuper@37906: "x + (-4) / 2"; neuper@37906: (* neuper@37906: ### trying calc. 'cancel' neuper@37906: @@@ get_pair: binop, t = x + (-4) / 2 neuper@37906: @@@ get_pair: t else neuper@38032: @@@ get_pair: t else -> NONE neuper@37906: @@@ get_pair: binop, t = (-4) / 2 neuper@37906: @@@ get_pair: then 1 neuper@38032: @@@ get_pair: t -> NONE neuper@38032: @@@ get_pair: t1 -> NONE wneuper@59255: @@@ adhoc_thm': NONE neuper@37906: ### trying calc. 'pow' neuper@37906: *) neuper@37906: neuper@52070: trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*) neuper@37906: walther@59603: "----------- Prog_Expr.pow Power.power_class.power ---------"; walther@59603: "----------- Prog_Expr.pow Power.power_class.power ---------"; walther@59603: "----------- Prog_Expr.pow Power.power_class.power ---------"; wneuper@59188: val t = (Thm.term_of o the o (parseold thy)) "1 ^ aaa"; neuper@42223: atomty t; neuper@37906: (*** ------------- neuper@37906: *** Const ( Nat.power, ['a, nat] => 'a) neuper@37906: *** . Free ( 1, 'a) neuper@37906: *** . Free ( aaa, nat) *) akargl@42218: neuper@42223: val t = str2term "1 ^^^ aaa"; neuper@42223: atomty t; neuper@42223: (**** walther@59603: *** Const (Prog_Expr.pow, real => real => real) neuper@42223: *** . Free (1, real) neuper@42223: *** . Free (aaa, real) neuper@42223: *** *); neuper@37906: neuper@37906: " ================= calculate.sml: calculate_ 2002 =================== "; neuper@37906: " ================= calculate.sml: calculate_ 2002 =================== "; neuper@37906: " ================= calculate.sml: calculate_ 2002 =================== "; neuper@37906: akargl@42188: val thy = @{theory Test}; wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "12 / 3"; walther@59686: val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@37906: "12 / 3 = 4"; akargl@42188: val thy = @{theory Test}; wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "4 ^^^ 2"; walther@59686: val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@37906: "4 ^ 2 = 16"; neuper@37906: wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "((1 + 2) * 4 / 3) ^^^ 2"; walther@59686: val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"PLUS"))) t; neuper@37906: "1 + 2 = 3"; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@38033: term2str t; neuper@37906: "(3 * 4 / 3) ^^^ 2"; walther@59686: val SOME (thmID,thm) = adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"TIMES")))t; neuper@37906: "3 * 4 = 12"; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@38033: term2str t; neuper@37906: "(12 / 3) ^^^ 2"; walther@59686: val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t; neuper@37906: "12 / 3 = 4"; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@38033: term2str t; neuper@37906: "4 ^^^ 2"; walther@59686: val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t; neuper@37906: "4 ^^^ 2 = 16"; neuper@38032: val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t; neuper@38033: term2str t; neuper@37906: "16"; neuper@38031: if it <> "16" then error "calculate.sml: new behaviour in calculate_" neuper@37906: else (); neuper@37906: neuper@37906: (*13.9.02 *** calc: operator = pow not defined*) wneuper@59188: val t = (Thm.term_of o the o (parse thy)) "3^^^2"; neuper@38032: val SOME (thmID,thm) = walther@59686: adhoc_thm thy (the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"))) t; neuper@37906: (*** calc: operator = pow not defined*) neuper@37906: walther@59686: val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")); neuper@37906: (* walther@59603: val op_ = "Prog_Expr.pow" : string neuper@37906: val eval_fn = fn : string -> term -> theory -> (string * term) option*) neuper@37906: neuper@38032: val SOME (thmid,t') = get_pair thy op_ eval_fn t; neuper@37906: (*** calc: operator = pow not defined*) neuper@37906: neuper@38032: val SOME (id,t') = eval_fn op_ t thy; neuper@37906: (*** calc: operator = pow not defined*) neuper@37906: neuper@37906: val (thmid, (Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2))) = (op_, t); neuper@38032: val SOME (id,t') = eval_binop thmid op_ t thy; neuper@37906: (*** calc: operator = pow not defined*) neuper@37906: akargl@42188: neuper@37906: "----------- get_pair with 3 args --------------------------------"; neuper@37906: "----------- get_pair with 3 args --------------------------------"; neuper@37906: "----------- get_pair with 3 args --------------------------------"; neuper@37906: val (thy, op_, ef, arg) = neuper@37906: (thy, "EqSystem.occur'_exactly'_in", wneuper@59462: assoc_calc' (@{theory "EqSystem"}) "occur_exactly_in" |> snd |> snd, neuper@37906: str2term akargl@42188: "[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2" neuper@37906: ); neuper@38032: val SOME (str, simpl) = get_pair thy op_ ef arg; neuper@37906: if str = akargl@42188: "[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2 = True" neuper@38031: then () else error "calculate.sml get_pair with 3 args:occur_exactly_in"; neuper@37906: neuper@37906: neuper@38032: "----------- calculate (2 * x is_const) -----------------"; neuper@38032: "----------- calculate (2 * x is_const) -----------------"; neuper@38032: "----------- calculate (2 * x is_const) -----------------"; neuper@37906: val t = str2term "2 * x is_const"; akargl@42188: val SOME (str, t') = eval_const "" "" t @{theory Test}; neuper@37906: term2str t'; neuper@37906: "(2 * x is_const) = False"; neuper@37906: akargl@42188: val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t; neuper@37906: term2str t'; neuper@41928: "HOL.False"; wneuper@59387: wneuper@59387: "----------- fun get_pair: examples ------------------------------------------------------------"; wneuper@59387: "----------- fun get_pair: examples ------------------------------------------------------------"; wneuper@59387: "----------- fun get_pair: examples ------------------------------------------------------------"; wneuper@59388: val thy = @{theory}; walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS"); wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "3 + 4"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#: 3 + 4 = 7" andalso term2str term = "3 + 4 = 7" wneuper@59388: then () else error "get_pair 3 + 4 changed"; wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "(a + 3) + 4"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#: a + 3 + 4 = a + 7" andalso term2str term = "a + 3 + 4 = a + 7" wneuper@59388: then () else error "get_pair (a + 3) + 4 changed"; wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "(a + 3) + 4"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#: a + 3 + 4 = a + 7" andalso term2str term = "a + 3 + 4 = a + 7" wneuper@59388: then () else error "get_pair (a + 3) + 4 changed"; wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "x = 5 * (3 + (4 + a))"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#: 3 + (4 + a) = 7 + a" andalso term2str term = "3 + (4 + a) = 7 + a" wneuper@59388: then ((* !!! gets subterm !!!*)) else error "get_pair x = 5 * (3 + (4 + a)) (subterm) changed"; wneuper@59388: walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"); wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "-4 / -2"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#divide_e-4_-2" andalso term2str term = "-4 / -2 = 2" wneuper@59388: then () else error "get_pair -4 / -2 changed"; wneuper@59388: walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER"); wneuper@59388: wneuper@59388: val t = (Thm.term_of o the o (parse thy)) "2 ^^^ 3"; wneuper@59388: val SOME (str, term) = get_pair thy isa_str eval_fn t; wneuper@59388: if str = "#: 2 ^^^ 3 = 8" andalso term2str term = "2 ^^^ 3 = 8" wneuper@59388: then () else error "get_pair 2 ^^^ 3 changed"; wneuper@59388: wneuper@59387: "----------- fun adhoc_thm: examples -----------------------------------------------------------"; wneuper@59387: "----------- fun adhoc_thm: examples -----------------------------------------------------------"; wneuper@59387: "----------- fun adhoc_thm: examples -----------------------------------------------------------"; wneuper@59388: (*--------------------------------------------------------------------vvvvvvvvvv*) walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "is_const"); wneuper@59388: val SOME t = parseNEW @{context} "9 is_const"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#is_const_9_" andalso thm2str thm = "(9 is_const) = True" wneuper@59388: then () else error "adhoc_thm 9 is_const changed"; wneuper@59387: wneuper@59387: wneuper@59388: case assoc_calc thy "Orderings.ord_class.less" of wneuper@59388: "le" => () | _ => error "Orderings.ord_class.less <-> le changed"; wneuper@59388: (*--------------------------------------------------------------------vvvvvvvvvv*) walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "le"); wneuper@59387: wneuper@59388: val SOME t = parseNEW @{context} "4 < 4"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#less_4_4" andalso thm2str thm = "(4 < 4) = False" wneuper@59388: then () else error "adhoc_thm 4 < 4 changed"; wneuper@59387: wneuper@59388: val SOME t = parseNEW @{context} "a < 4"; wneuper@59388: case adhoc_thm thy (isa_str, eval_fn) t of wneuper@59388: NONE => () | _ => error "adhoc_thm a < 4 does NOT result in NONE"; wneuper@59387: wneuper@59387: wneuper@59388: (*--------------------------------------------------------------------vvvvvvvvvv*) walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "PLUS"); wneuper@59388: val SOME t = parseNEW @{context} "1 + 2"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#: 1 + 2 = 3" andalso thm2str thm = "1 + 2 = 3" wneuper@59388: then () else error "adhoc_thm 1 + 2 changed"; wneuper@59387: wneuper@59388: (*--------------------------------------------------------------------vvvvvvvvvv*) walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE"); wneuper@59388: val SOME t = parseNEW @{context} "6 / -8"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#divide_e6_-8" andalso thm2str thm = "6 / -8 = -3 / 4" wneuper@59388: then () else error "adhoc_thm 1 + 2 changed"; wneuper@59387: wneuper@59387: walther@59603: case assoc_calc thy "Prog_Expr.ident" of walther@59603: "ident" => () | _ => error "Prog_Expr.ident <-> ident changed"; wneuper@59388: (*--------------------------------------------------------------------vvvvvvvvvv*) walther@59686: val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "ident"); wneuper@59387: wneuper@59388: val SOME t = parseNEW @{context} "3 =!= 3"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#ident_(3)_(3)" andalso thm2str thm = "(3 =!= 3) = True" wneuper@59388: then () else error "adhoc_thm (3 =!= 3) changed"; wneuper@59387: wneuper@59388: val SOME t = parseNEW @{context} "\ (4 + (4 * x + x ^ 2) =!= 0)"; wneuper@59388: val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t; wneuper@59388: if str = "#ident_(4 + (4 * x + x ^ 2))_(0)" andalso thm2str thm = "(4 + (4 * x + x ^ 2) =!= 0) = False" wneuper@59388: then () else error "adhoc_thm (\ (4 + (4 * x + x ^ 2) =!= 0)) changed"; wneuper@59403: wneuper@59403: "----------- fun power -------------------------------------------------------------------------"; wneuper@59403: "----------- fun power -------------------------------------------------------------------------"; wneuper@59403: "----------- fun power -------------------------------------------------------------------------"; wneuper@59403: if power 2 3 = 8 then () else error "power 2 3 = 8"; wneuper@59403: if power ~2 3 = ~8 then () else error "power ~2 3 = ~8"; wneuper@59403: if power ~3 2 = 9 then () else error "power ~3 2 = 9"; wneuper@59403: (power 3 ~2; error "power 3 ~2: should raise an exn") handle _ => 000; wneuper@59403: wneuper@59403: "----------- fun divisors ----------------------------------------------------------------------"; wneuper@59403: "----------- fun divisors ----------------------------------------------------------------------"; wneuper@59403: "----------- fun divisors ----------------------------------------------------------------------"; wneuper@59403: if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]"; wneuper@59403: if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]"; wneuper@59403: if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]"; wneuper@59403: if divisors 11 = [11] then () else error "divisors 11 = [11]"; wneuper@59403: wneuper@59403: "----------- fun doubles, fun squfact ----------------------------------------------------------"; wneuper@59403: "----------- fun doubles, fun squfact ----------------------------------------------------------"; wneuper@59403: "----------- fun doubles, fun squfact ----------------------------------------------------------"; wneuper@59403: if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed"; wneuper@59403: if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed"; wneuper@59403: wneuper@59403: if squfact 30 = 1 then () else error "squfact 30 changed"; wneuper@59403: if squfact 32 = 4 then () else error "squfact 32 changed"; wneuper@59403: if squfact 60 = 2 then () else error "squfact 60 changed"; wneuper@59403: if squfact 11 = 1 then () else error "squfact 11 changed";