test/Tools/isac/ProgLang/evaluate.sml
author wneuper <walther.neuper@jku.at>
Sat, 17 Jul 2021 14:05:28 +0200
changeset 60329 0c10aeff57d7
parent 60324 5c7128feb370
child 60330 e5e9a6c45597
permissions -rw-r--r--
replace "-*" by "- *" for numerals "*" in test/*
     1 (* Title:  "ProgLang/evaluate.sml"
     2    Author: Walther Neuper 2000
     3    (c) copyright due to lincense terms.
     4 *)
     5 
     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 "--------------------------------------------------------";
    31 
    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")
    40 handle TERM _ => 
    41        error "evaluate.sml: adhoc_thm must return Trueprop";
    42 
    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";
    48 val thy = @{theory};
    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;
    53 
    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";
    58 
    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";
    63 
    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";
    68 
    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";
    73 
    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"];
    79 val (dI',pI',mI') =
    80   ("Test", ["calculate", "test"], ["Test", "test_calculate"]);
    81 
    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"))*)
    95 
    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";
   104 
   105 
   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:
   110 val ct =
   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
   117 *)
   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
   123   SOME _ => ()
   124 | NONE => error "calculate_ test-root-equ changed";
   125 (*
   126            sqrt (x \<up> 2 + -3 * x) =\
   127  \(-9) / (- 2) + (-3 / (- 2) + (x * ((-4) / (- 2)) + x * (2 / (- 2))))
   128 ............... does not work *)
   129 
   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*)
   136 
   137 (*--------------(3): is_const works ?: -------------------------------------*)
   138  val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
   139  TermC.atomty t;
   140  rewrite_set_ @{theory Test} false tval_rls t;
   141 (*val it = SOME (Const ("HOL.True", "bool"),[]) ... works*)
   142 
   143  val t = TermC.str2term "2 * x is_const";
   144  val SOME (str,t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
   145  UnparseC.term t';
   146  
   147 
   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";
   156 
   157 val SOME (_, t) = eval_cancel "xxx" "Rings.divide_class.divide" t thy;
   158 
   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
   162   SOME (t', []) =>
   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";
   166 
   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";
   172 
   173  Rewrite.trace_on:=false; (*=true3.6.03*)
   174 
   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);
   178 :
   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'
   185 :
   186 "x + (-4) / 2"
   187 -------------------------------------while before Isabelle20002:
   188  val ct = "(#-3 + #2 * x + #- 1) // #2";
   189  val (ct,_) = the (rewrite_set thy'  false rls ct);
   190 :
   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'
   198 :
   199 "#- 2 + x"
   200 -----------------------------------------------------------------*)
   201 
   202 
   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";
   209 "x + (-4) / 2";						
   210 (*
   211 ### trying calc. 'cancel'
   212 @@@ get_pair: binop, t = x + (-4) / 2
   213 @@@ get_pair: t else
   214 @@@ get_pair: t else -> NONE
   215 @@@ get_pair: binop, t = (-4) / 2
   216 @@@ get_pair: then 1
   217 @@@ get_pair: t -> NONE
   218 @@@ get_pair: t1 -> NONE
   219 @@@ adhoc_thm': NONE
   220 ### trying calc. 'pow'
   221 *)
   222 
   223  Rewrite.trace_on:=false; (*WN130722: =true stopped Test_Isac.thy*)
   224 
   225 " ================= evaluate.sml: calculate_ 2002 =================== ";
   226 " ================= evaluate.sml: calculate_ 2002 =================== ";
   227 " ================= evaluate.sml: calculate_ 2002 =================== ";
   228 
   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;
   233 "12 / 3 = 4";
   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;
   238 "4 ^ 2 = 16";
   239 
   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;
   242 "1 + 2 = 3";
   243  val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
   244  UnparseC.term 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;
   247 "3 * 4 = 12";
   248  val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
   249  UnparseC.term t;
   250 "(12 / 3) \<up> 2";
   251  val SOME (thmID,thm) =adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"DIVIDE")))t;
   252 "12 / 3 = 4";
   253  val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
   254  UnparseC.term t;
   255 "4 \<up> 2";
   256  val SOME (thmID,thm) = adhoc_thm thy(the(LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER")))t;
   257 "4 \<up> 2 = 16";
   258  val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
   259  UnparseC.term t;
   260 "16";
   261  if it <> "16" then error "evaluate.sml: new behaviour in calculate_"
   262  else ();
   263 
   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*)
   269 
   270   val (op_, eval_fn) = the (LibraryC.assoc(KEStore_Elems.get_calcs @{theory},"POWER"));
   271   (*
   272 val op_ = "Transcendental.powr" : string
   273 val eval_fn = fn : string -> term -> theory -> (string * term) option*)
   274 
   275   val SOME (thmid,t') = get_pair thy op_ eval_fn t;
   276 (*** calc: operator = pow not defined*)
   277 
   278   val SOME (id,t') = eval_fn op_ t thy;
   279 (*** calc: operator = pow not defined*)
   280 
   281 case (op_, t) of
   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*)
   288 
   289 if UnparseC.term t' = "3 \<up> 2 = 9" then () else error "eval_binop  3 \<up> 2 = 9  CHANGED";
   290 
   291 
   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";
   298 
   299 
   300 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
   301 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
   302 "----------- RE-BUILD fun calcul ---------------------------------------------------------------";
   303 val (t1, t2) = (@{term 3}, @{term "2::real"});
   304 
   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)
   310     val result =
   311       case op_ of
   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)
   317   (*in*)
   318     val xxx = HOLogic.mk_number T result;
   319   (*end*)
   320 case HOLogic.dest_number xxx of
   321   (_, 5) => ()
   322 | _ => error "calcul + 2 3 CHANGED";
   323 
   324 case HOLogic.dest_number (calcul "Groups.minus_class.minus" (t1, t2)) of
   325   (_, 1) => xxx
   326 | _ => error "calcul - 2 3 CHANGED";
   327 
   328 case HOLogic.dest_number (calcul "Groups.times_class.times" (t1, t2)) of
   329   (_, 6) => xxx
   330 | _ => error "calcul - 2 3 CHANGED";
   331 
   332 (*                       (calcul "Rings.divide_class.divide" (t1, t2)
   333 ERROR: calcul not impl.for op_ Rings.divide_class.divide*)
   334 
   335 case HOLogic.dest_number (calcul "Transcendental.powr" (t1, t2)) of
   336   (_, 9) => xxx
   337 | _ => error "calcul - 2 3 CHANGED";
   338 
   339 
   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,
   346      TermC.str2term
   347       "[] from [c, c_2, c_3, c_4] occur_exactly_in - 1 * (q_0 * L \<up> 2) / 2"
   348       );
   349 val SOME (str, simpl) = get_pair thy op_ ef arg;
   350 if str = 
   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";
   353 
   354 
   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";
   362 
   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";
   366 
   367 "----------- fun get_pair: examples ------------------------------------------------------------";
   368 "----------- fun get_pair: examples ------------------------------------------------------------";
   369 "----------- fun get_pair: examples ------------------------------------------------------------";
   370 val thy = @{theory};
   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";
   373 
   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";
   378 
   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";
   383 
   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";
   388 
   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";
   393 
   394 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
   395 
   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";
   400 
   401 val SOME (isa_str, eval_fn) = LibraryC.assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
   402 
   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";
   407 
   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";
   417 
   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";
   422 
   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";
   427 
   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";
   431 
   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";
   437 
   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";
   443 
   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");
   447 
   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";
   452 
   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";
   457 
   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 
   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
   467 ( **)
   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*);
   473 (** )
   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
   477 ( **)
   478 
   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"
   487 | NONE => ();
   488 
   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]";
   496 
   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";
   502 
   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";