test/Tools/isac/ProgLang/calculate.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Tue, 13 Mar 2018 14:41:02 +0100
changeset 59403 ff716184230f
parent 59388 47877d6fa35a
child 59411 3e241a6938ce
permissions -rw-r--r--
TermC: clean test files, Test_Isac OK
neuper@38022
     1
(* Title:  test calculation of values for function constants
neuper@38022
     2
   Author: Walther Neuper 2000
neuper@38022
     3
   (c) copyright due to lincense terms.
neuper@37906
     4
*)
neuper@37906
     5
neuper@38022
     6
"--------------------------------------------------------";
neuper@38022
     7
"table of contents --------------------------------------";
neuper@38022
     8
"--------------------------------------------------------";
neuper@55366
     9
"-calculate.thy: provides 'setup' -----------------------";
neuper@41924
    10
"----------- fun norm -----------------------------------";
wneuper@59255
    11
"----------- check return value of adhoc_thm  ----";
neuper@38032
    12
"----------- fun calculate_ -----------------------------";
neuper@55366
    13
"----------- calculate from script --requires 'setup'----";
neuper@38032
    14
"----------- calculate check test-root-equ --------------";
wneuper@59253
    15
"----------- check calcul,ate bottom up -----------------";
neuper@42223
    16
"----------- Atools.pow Power.power_class.power ---------";
neuper@41934
    17
" ================= calculate.sml: calculate_ 2002 ======";
neuper@38032
    18
"----------- get_pair with 3 args -----------------------";
neuper@38032
    19
"----------- calculate (2 * x is_const) -----------------";
wneuper@59387
    20
"----------- fun get_pair: examples ------------------------------------------------------------";
wneuper@59387
    21
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
wneuper@59403
    22
"----------- fun power -------------------------------------------------------------------------";
wneuper@59403
    23
"----------- fun divisors ----------------------------------------------------------------------";
wneuper@59403
    24
"----------- fun doubles, fun squfact ----------------------------------------------------------";
neuper@38022
    25
"--------------------------------------------------------";
neuper@38022
    26
"--------------------------------------------------------";
neuper@38022
    27
"--------------------------------------------------------";
neuper@37906
    28
wneuper@59255
    29
"----------- check return value of adhoc_thm  ----";
wneuper@59255
    30
"----------- check return value of adhoc_thm  ----";
wneuper@59255
    31
"----------- check return value of adhoc_thm  ----";
neuper@41924
    32
val thy = @{theory "Poly"};
s1210629013@52153
    33
val cal = snd (assoc_calc' thy "is_polyexp");
neuper@38022
    34
val t = @{term "(x / x) is_polyexp"};
wneuper@59255
    35
val SOME (thmID, thm) = adhoc_thm thy cal t;
wneuper@59188
    36
(HOLogic.dest_Trueprop (Thm.prop_of thm); writeln "all thms wrapped by Trueprop")
neuper@38022
    37
handle TERM _ => 
wneuper@59255
    38
       error "calculate.sml: adhoc_thm must return Trueprop";
neuper@38022
    39
neuper@38033
    40
"----------- fun calculate_ -----------------------------";
neuper@38033
    41
"----------- fun calculate_ -----------------------------";
neuper@38033
    42
"----------- fun calculate_ -----------------------------";
neuper@41924
    43
val thy = @{theory "Test"};
neuper@38033
    44
"===== test 1";
wneuper@59188
    45
val t = (Thm.term_of o the o (parse thy)) "1+2";
wneuper@59255
    46
val SOME (thmID,thm) = adhoc_thm thy (the(assoc(calclist,"PLUS"))) t;
wneuper@59195
    47
term2str (Thm.prop_of thm) = "1 + 2 = 3";
neuper@38033
    48
neuper@38033
    49
"===== test 2";
wneuper@59188
    50
val t = (Thm.term_of o the o (parse thy)) "((1+2)*4/3)^^^2";
wneuper@59255
    51
val SOME (thmID,thm) = adhoc_thm thy (the(assoc(calclist,"PLUS"))) t;
neuper@38033
    52
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@41931
    53
if term2str t = "(3 * 4 / 3) ^^^ 2" then ()
neuper@41931
    54
else error "calculate.sml: ((1+2)*4/3)^^^2 --> (3 * 4 / 3) ^^^ 2";
neuper@38033
    55
neuper@38033
    56
"===== test 3b -- 2 contiued";
wneuper@59255
    57
val SOME (thmID,thm) = adhoc_thm thy (the(assoc(calclist,"TIMES"))) t;
neuper@38033
    58
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
    59
term2str t;
neuper@38033
    60
(*val it = "(#12 // #3) ^^^ #2" : string*)
neuper@37906
    61
neuper@38033
    62
"===== test 4";
wneuper@59255
    63
val SOME (thmID,thm) = adhoc_thm thy(the(assoc(calclist,"DIVIDE")))t;
neuper@38032
    64
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
    65
term2str t;
neuper@38033
    66
(*it = "#4 ^^^ #2" : string*)
neuper@38033
    67
neuper@38033
    68
"===== test 5";
wneuper@59255
    69
val SOME (thmID,thm) = adhoc_thm thy(the(assoc(calclist,"POWER")))t;
neuper@38032
    70
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@41931
    71
(*show_types := false;*)
neuper@38037
    72
if term2str t <> "16" then error "calculate.sml: new behaviour in calculate_"
neuper@37906
    73
else ();
neuper@37906
    74
neuper@37906
    75
neuper@37906
    76
val fmz = ["realTestGiven (((1+2)*4/3)^^^2)","realTestFind s"];
neuper@37906
    77
val (dI',pI',mI') =
neuper@38035
    78
  ("Test",["calculate","test"],["Test","test_calculate"]);
neuper@38035
    79
neuper@37906
    80
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
    81
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
    82
(*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) ^^^#2)")*)
neuper@37906
    83
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
    84
(*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
neuper@37906
    85
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
    86
(*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
neuper@37906
    87
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
    88
(*nxt = ("Specify_Problem",Specify_Problem ["calculate","test"])*)
neuper@37906
    89
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
    90
(*nxt = ("Specify_Method",Specify_Method ("Test","test_calculate"))*)
neuper@37906
    91
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
    92
(*nxt = ("Apply_Method",Apply_Method ("Test","test_calculate"))*)
neuper@37906
    93
neuper@37906
    94
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
    95
(*nxt = ("Calculate",Calculate "PLUS")*)
neuper@37906
    96
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
    97
(*nxt = ("Calculate",Calculate "TIMES")*)
neuper@37906
    98
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
    99
(*nxt = ("Calculate",Calculate "DIVIDE")*)
neuper@37906
   100
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
   101
(*nxt = ("Calculate",Calculate "POWER")*)
neuper@37906
   102
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   103
(*nxt = ("Check_Postcond",Check_Postcond ["calculate","test"])*)
neuper@37906
   104
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   105
(*nxt = ("End_Proof'",End_Proof')*)
wneuper@59267
   106
case f of FormKF "16" => () | _ =>
wneuper@59253
   107
error "calculate.sml: script test_calculate changed behaviour";
neuper@37906
   108
neuper@37906
   109
neuper@38032
   110
"----------- calculate check test-root-equ --------------";
neuper@38032
   111
"----------- calculate check test-root-equ --------------";
neuper@38032
   112
"----------- calculate check test-root-equ --------------";
neuper@37906
   113
(*(1): 2nd Test_simplify didn't work:
neuper@37906
   114
val ct =
neuper@37906
   115
  "sqrt (x ^^^ 2 + -3 * x) = (-3 + 2 * x + -1 * (9 + 4 * x)) / (-1 * 2)"
neuper@37906
   116
> val rls = ("Test_simplify");
neuper@37906
   117
> val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
neuper@37906
   118
val ct = "sqrt (x ^^^ 2 + -3 * x) =
neuper@37906
   119
(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))";
neuper@37906
   120
ie. cancel does not work properly
neuper@37906
   121
*)
wneuper@59382
   122
 val thy = @{theory "Test"};
wneuper@59382
   123
 val op_ = the (assoc (calclist, "DIVIDE"));
wneuper@59382
   124
 val ct = numbers_to_string @{term
wneuper@59382
   125
   "sqrt (x ^^^ 2 + -3 * x) = (-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))"};
wneuper@59382
   126
case calculate_ thy op_ ct of
wneuper@59382
   127
  SOME _ => ()
wneuper@59382
   128
| NONE => error "calculate_ test-root-equ changed";
neuper@37906
   129
(*
neuper@37906
   130
           sqrt (x ^^^ 2 + -3 * x) =\
neuper@37906
   131
 \(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))
neuper@37906
   132
............... does not work *)
neuper@37906
   133
neuper@37906
   134
(*--------------(2): does divide work in Test_simplify ?: ------*)
akargl@42188
   135
 val thy = @{theory Test};
wneuper@59188
   136
 val t = (Thm.term_of o the o (parse thy)) "6 / 2";
neuper@37906
   137
 val rls = Test_simplify;
neuper@37906
   138
 val (t,_) = the (rewrite_set_ thy false rls t);
neuper@55279
   139
(*val t = Free ("3","Real.real") : term*)
neuper@37906
   140
neuper@37906
   141
(*--------------(3): is_const works ?: -------------------------------------*)
wneuper@59188
   142
 val t = (Thm.term_of o the o (parse @{theory Test})) "2 is_const";
neuper@37906
   143
 atomty t;
akargl@42188
   144
 rewrite_set_ @{theory Test} false tval_rls t;
neuper@41928
   145
(*val it = SOME (Const ("HOL.True","bool"),[]) ... works*)
neuper@37906
   146
neuper@37906
   147
 val t = str2term "2 * x is_const";
akargl@42188
   148
 val SOME (str,t') = eval_const "" "" t (@{theory "Isac"});
neuper@37906
   149
 term2str t';
neuper@37906
   150
 
neuper@37906
   151
neuper@38032
   152
"----------- check calculate bottom up ------------------";
neuper@38032
   153
"----------- check calculate bottom up ------------------";
neuper@38032
   154
"----------- check calculate bottom up ------------------";
neuper@37906
   155
(*-------------- eval_cancel works: *)
neuper@52070
   156
 trace_rewrite:=false;
akargl@42188
   157
 val thy = @{theory Test};
wneuper@59384
   158
 val rls = Test_simplify;
wneuper@59188
   159
 val t = (Thm.term_of o the o (parse thy)) "(-4) / 2";
akargl@42188
   160
wneuper@59360
   161
val SOME (_, t) = eval_cancel "xxx" "Rings.divide_class.divide" t thy;
akargl@42188
   162
neuper@37906
   163
(*--------------(5): reproduce (1) with simpler term: ------------*)
wneuper@59384
   164
 val t = (Thm.term_of o the o (parse thy)) "(3+5)/2";
wneuper@59384
   165
case rewrite_set_ thy false rls t of
wneuper@59384
   166
  SOME (Free ("4", _), []) => ()
wneuper@59384
   167
| _ => error "rewrite_set_ (3+5)/2 changed";
neuper@37906
   168
wneuper@59384
   169
 val t = (Thm.term_of o the o (parse thy)) "(3+1+2*x)/2";
wneuper@59384
   170
case rewrite_set_ thy false rls t of
wneuper@59384
   171
  SOME (Const ("Groups.plus_class.plus", _) $ Free ("2", _) $ Free ("x", _), []) => ()
wneuper@59384
   172
| _ => error "rewrite_set_ (3+1+2*x)/2 changed";
neuper@37906
   173
neuper@52070
   174
 trace_rewrite:=false; (*=true3.6.03*)
akargl@42218
   175
neuper@37906
   176
(*--- trace_rewrite before correction of ... --------------------
neuper@37906
   177
 val ct = "(-3 + 2 * x + -1) / 2";
neuper@37906
   178
 val (ct,_) = the (rewrite_set thy'  false rls ct);
neuper@37906
   179
:
neuper@37906
   180
### trying thm 'root_ge0_2'
neuper@37906
   181
### rewrite_set_: x + (-1 + -3) / 2
neuper@37906
   182
### trying thm 'radd_real_const_eq'
neuper@37906
   183
### trying thm 'radd_real_const'
neuper@37906
   184
### rewrite_set_: x + (-4) / 2
neuper@37906
   185
### trying thm 'rcollect_right'
neuper@37906
   186
:
neuper@37906
   187
"x + (-4) / 2"
neuper@37906
   188
-------------------------------------while before Isabelle20002:
neuper@37906
   189
 val ct = "(#-3 + #2 * x + #-1) // #2";
neuper@37906
   190
 val (ct,_) = the (rewrite_set thy'  false rls ct);
neuper@37906
   191
:
neuper@37906
   192
### trying thm 'root_ge0_2'
neuper@37906
   193
### rewrite_set_: x + (#-1 + #-3) // #2
neuper@37906
   194
### trying thm 'radd_real_const_eq'
neuper@37906
   195
### trying thm 'radd_real_const'
neuper@37906
   196
### rewrite_set_: x + #-4 // #2
neuper@37906
   197
### rewrite_set_: x + #-2
neuper@37906
   198
### trying thm 'rcollect_right'
neuper@37906
   199
:
neuper@37906
   200
"#-2 + x"
neuper@37906
   201
-----------------------------------------------------------------*)
neuper@37906
   202
neuper@37906
   203
neuper@37906
   204
(*===================*)
neuper@52070
   205
 trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*)
wneuper@59384
   206
 val t = (Thm.term_of o the o (parse thy))  "x + (-1 + -3) / 2";
wneuper@59384
   207
val SOME (res, []) = rewrite_set_ thy false rls t;
wneuper@59384
   208
if term2str res = "-2 + x" then () else error "rewrite_set_  x + (-1 + -3) / 2  changed";
neuper@37906
   209
"x + (-4) / 2";						
neuper@37906
   210
(*
neuper@37906
   211
### trying calc. 'cancel'
neuper@37906
   212
@@@ get_pair: binop, t = x + (-4) / 2
neuper@37906
   213
@@@ get_pair: t else
neuper@38032
   214
@@@ get_pair: t else -> NONE
neuper@37906
   215
@@@ get_pair: binop, t = (-4) / 2
neuper@37906
   216
@@@ get_pair: then 1
neuper@38032
   217
@@@ get_pair: t -> NONE
neuper@38032
   218
@@@ get_pair: t1 -> NONE
wneuper@59255
   219
@@@ adhoc_thm': NONE
neuper@37906
   220
### trying calc. 'pow'
neuper@37906
   221
*)
neuper@37906
   222
neuper@52070
   223
 trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*)
neuper@37906
   224
neuper@42223
   225
"----------- Atools.pow Power.power_class.power ---------";
neuper@42223
   226
"----------- Atools.pow Power.power_class.power ---------";
neuper@42223
   227
"----------- Atools.pow Power.power_class.power ---------";
wneuper@59188
   228
val t = (Thm.term_of o the o (parseold thy)) "1 ^ aaa";
neuper@42223
   229
atomty t;
neuper@37906
   230
(*** -------------
neuper@37906
   231
*** Const ( Nat.power, ['a, nat] => 'a)
neuper@37906
   232
*** . Free ( 1, 'a)
neuper@37906
   233
*** . Free ( aaa, nat) *)
akargl@42218
   234
neuper@42223
   235
val t = str2term "1 ^^^ aaa";
neuper@42223
   236
atomty t;
neuper@42223
   237
(**** 
neuper@42223
   238
*** Const (Atools.pow, real => real => real)
neuper@42223
   239
*** . Free (1, real)
neuper@42223
   240
*** . Free (aaa, real)
neuper@42223
   241
*** *);
neuper@37906
   242
neuper@37906
   243
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   244
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   245
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   246
akargl@42188
   247
val thy = @{theory Test};
wneuper@59188
   248
val t = (Thm.term_of o the o (parse thy)) "12 / 3";
wneuper@59255
   249
val SOME (thmID,thm) = adhoc_thm thy(the(assoc(calclist,"DIVIDE")))t;
neuper@38032
   250
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@37906
   251
"12 / 3 = 4";
akargl@42188
   252
val thy = @{theory Test};
wneuper@59188
   253
val t = (Thm.term_of o the o (parse thy)) "4 ^^^ 2";
wneuper@59255
   254
val SOME (thmID,thm) = adhoc_thm thy(the(assoc(calclist,"POWER"))) t;
neuper@38032
   255
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@37906
   256
"4 ^ 2 = 16";
neuper@37906
   257
wneuper@59188
   258
 val t = (Thm.term_of o the o (parse thy)) "((1 + 2) * 4 / 3) ^^^ 2";
wneuper@59255
   259
 val SOME (thmID,thm) = adhoc_thm thy (the(assoc(calclist,"PLUS"))) t;
neuper@37906
   260
"1 + 2 = 3";
neuper@38032
   261
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   262
 term2str t;
neuper@37906
   263
"(3 * 4 / 3) ^^^ 2";
wneuper@59255
   264
 val SOME (thmID,thm) = adhoc_thm thy (the(assoc(calclist,"TIMES")))t;
neuper@37906
   265
"3 * 4 = 12";
neuper@38032
   266
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   267
 term2str t;
neuper@37906
   268
"(12 / 3) ^^^ 2";
wneuper@59255
   269
 val SOME (thmID,thm) =adhoc_thm thy(the(assoc(calclist,"DIVIDE")))t;
neuper@37906
   270
"12 / 3 = 4";
neuper@38032
   271
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   272
 term2str t;
neuper@37906
   273
"4 ^^^ 2";
wneuper@59255
   274
 val SOME (thmID,thm) = adhoc_thm thy(the(assoc(calclist,"POWER")))t;
neuper@37906
   275
"4 ^^^ 2 = 16";
neuper@38032
   276
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   277
 term2str t;
neuper@37906
   278
"16";
neuper@38031
   279
 if it <> "16" then error "calculate.sml: new behaviour in calculate_"
neuper@37906
   280
 else ();
neuper@37906
   281
neuper@37906
   282
(*13.9.02 *** calc: operator = pow not defined*)
wneuper@59188
   283
  val t = (Thm.term_of o the o (parse thy)) "3^^^2";
neuper@38032
   284
  val SOME (thmID,thm) = 
wneuper@59255
   285
      adhoc_thm thy (the(assoc(calclist,"POWER"))) t;
neuper@37906
   286
(*** calc: operator = pow not defined*)
neuper@37906
   287
neuper@38033
   288
  val (op_, eval_fn) = the (assoc(calclist,"POWER"));
neuper@37906
   289
  (*
neuper@37906
   290
val op_ = "Atools.pow" : string
neuper@37906
   291
val eval_fn = fn : string -> term -> theory -> (string * term) option*)
neuper@37906
   292
neuper@38032
   293
  val SOME (thmid,t') = get_pair thy op_ eval_fn t;
neuper@37906
   294
(*** calc: operator = pow not defined*)
neuper@37906
   295
neuper@38032
   296
  val SOME (id,t') = eval_fn op_ t thy;
neuper@37906
   297
(*** calc: operator = pow not defined*)
neuper@37906
   298
neuper@37906
   299
  val (thmid, (Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2))) = (op_, t);
neuper@38032
   300
  val SOME (id,t') = eval_binop thmid op_ t thy;
neuper@37906
   301
(*** calc: operator = pow not defined*)
neuper@37906
   302
akargl@42188
   303
neuper@37906
   304
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   305
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   306
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   307
val (thy, op_, ef, arg) =
neuper@37906
   308
    (thy, "EqSystem.occur'_exactly'_in", 
wneuper@59361
   309
     assoc_calc' (Thy_Info_get_theory "EqSystem") "occur_exactly_in" |> snd |> snd,
neuper@37906
   310
     str2term
akargl@42188
   311
      "[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2"
neuper@37906
   312
      );
neuper@38032
   313
val SOME (str, simpl) = get_pair thy op_ ef arg;
neuper@37906
   314
if str = 
akargl@42188
   315
"[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2 = True"
neuper@38031
   316
then () else error "calculate.sml get_pair with 3 args:occur_exactly_in";
neuper@37906
   317
neuper@37906
   318
neuper@38032
   319
"----------- calculate (2 * x is_const) -----------------";
neuper@38032
   320
"----------- calculate (2 * x is_const) -----------------";
neuper@38032
   321
"----------- calculate (2 * x is_const) -----------------";
neuper@37906
   322
val t = str2term "2 * x is_const";
akargl@42188
   323
val SOME (str, t') = eval_const "" "" t @{theory Test};
neuper@37906
   324
term2str t';
neuper@37906
   325
"(2 * x is_const) = False";
neuper@37906
   326
akargl@42188
   327
val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
neuper@37906
   328
term2str t';
neuper@41928
   329
"HOL.False";
wneuper@59387
   330
wneuper@59387
   331
"----------- fun get_pair: examples ------------------------------------------------------------";
wneuper@59387
   332
"----------- fun get_pair: examples ------------------------------------------------------------";
wneuper@59387
   333
"----------- fun get_pair: examples ------------------------------------------------------------";
wneuper@59388
   334
val thy = @{theory};
wneuper@59388
   335
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
wneuper@59388
   336
wneuper@59388
   337
val t = (Thm.term_of o the o (parse thy)) "3 + 4";
wneuper@59388
   338
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   339
if str =  "#: 3 + 4 = 7" andalso term2str term = "3 + 4 = 7"
wneuper@59388
   340
then () else error "get_pair  3 + 4  changed";
wneuper@59388
   341
wneuper@59388
   342
val t = (Thm.term_of o the o (parse thy)) "(a + 3) + 4";
wneuper@59388
   343
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   344
if str =  "#: a + 3 + 4 = a + 7" andalso term2str term = "a + 3 + 4 = a + 7"
wneuper@59388
   345
then () else error "get_pair  (a + 3) + 4  changed";
wneuper@59388
   346
wneuper@59388
   347
val t = (Thm.term_of o the o (parse thy)) "(a + 3) + 4";
wneuper@59388
   348
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   349
if str =  "#: a + 3 + 4 = a + 7" andalso term2str term = "a + 3 + 4 = a + 7"
wneuper@59388
   350
then () else error "get_pair  (a + 3) + 4  changed";
wneuper@59388
   351
wneuper@59388
   352
val t = (Thm.term_of o the o (parse thy)) "x = 5 * (3 + (4 + a))";
wneuper@59388
   353
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   354
if str =  "#: 3 + (4 + a) = 7 + a" andalso term2str term = "3 + (4 + a) = 7 + a"
wneuper@59388
   355
then ((* !!! gets subterm !!!*)) else error "get_pair  x = 5 * (3 + (4 + a))  (subterm) changed";
wneuper@59388
   356
wneuper@59388
   357
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
wneuper@59388
   358
wneuper@59388
   359
val t = (Thm.term_of o the o (parse thy)) "-4 / -2";
wneuper@59388
   360
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   361
if str =  "#divide_e-4_-2" andalso term2str term = "-4 / -2 = 2"
wneuper@59388
   362
then () else error "get_pair  -4 / -2   changed";
wneuper@59388
   363
wneuper@59388
   364
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "POWER");
wneuper@59388
   365
wneuper@59388
   366
val t = (Thm.term_of o the o (parse thy)) "2 ^^^ 3";
wneuper@59388
   367
val SOME (str, term) = get_pair thy isa_str eval_fn t;
wneuper@59388
   368
if str =  "#: 2 ^^^ 3 = 8" andalso term2str term = "2 ^^^ 3 = 8"
wneuper@59388
   369
then () else error "get_pair  2 ^^^ 3   changed";
wneuper@59388
   370
wneuper@59387
   371
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
wneuper@59387
   372
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
wneuper@59387
   373
"----------- fun adhoc_thm: examples -----------------------------------------------------------";
wneuper@59388
   374
(*--------------------------------------------------------------------vvvvvvvvvv*)
wneuper@59388
   375
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "is_const");
wneuper@59388
   376
val SOME t = parseNEW @{context} "9 is_const";
wneuper@59388
   377
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   378
if str = "#is_const_9_" andalso thm2str thm = "(9 is_const) = True"
wneuper@59388
   379
then () else error "adhoc_thm  9 is_const  changed";
wneuper@59387
   380
wneuper@59387
   381
wneuper@59388
   382
case assoc_calc thy "Orderings.ord_class.less" of
wneuper@59388
   383
  "le" => () | _ => error "Orderings.ord_class.less <-> le changed";
wneuper@59388
   384
(*--------------------------------------------------------------------vvvvvvvvvv*)
wneuper@59388
   385
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "le");
wneuper@59387
   386
wneuper@59388
   387
val SOME t = parseNEW @{context} "4 < 4";
wneuper@59388
   388
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   389
if str = "#less_4_4" andalso thm2str thm = "(4 < 4) = False"
wneuper@59388
   390
then () else error "adhoc_thm  4 < 4  changed";
wneuper@59387
   391
wneuper@59388
   392
val SOME t = parseNEW @{context} "a < 4";
wneuper@59388
   393
case adhoc_thm thy (isa_str, eval_fn) t of
wneuper@59388
   394
NONE => () | _ => error "adhoc_thm  a < 4  does NOT result in NONE";
wneuper@59387
   395
wneuper@59387
   396
wneuper@59388
   397
(*--------------------------------------------------------------------vvvvvvvvvv*)
wneuper@59388
   398
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "PLUS");
wneuper@59388
   399
val SOME t = parseNEW @{context} "1 + 2";
wneuper@59388
   400
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   401
if str = "#: 1 + 2 = 3" andalso thm2str thm = "1 + 2 = 3"
wneuper@59388
   402
then () else error "adhoc_thm  1 + 2  changed";
wneuper@59387
   403
wneuper@59388
   404
(*--------------------------------------------------------------------vvvvvvvvvv*)
wneuper@59388
   405
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "DIVIDE");
wneuper@59388
   406
val SOME t = parseNEW @{context} "6 / -8";
wneuper@59388
   407
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   408
if str = "#divide_e6_-8" andalso thm2str thm = "6 / -8 = -3 / 4"
wneuper@59388
   409
then () else error "adhoc_thm  1 + 2  changed";
wneuper@59387
   410
wneuper@59387
   411
wneuper@59388
   412
case assoc_calc thy "Atools.ident" of
wneuper@59388
   413
  "ident" => () | _ => error "Atools.ident <-> ident  changed";
wneuper@59388
   414
(*--------------------------------------------------------------------vvvvvvvvvv*)
wneuper@59388
   415
val SOME (isa_str, eval_fn) = assoc (KEStore_Elems.get_calcs @{theory}, "ident");
wneuper@59387
   416
wneuper@59388
   417
val SOME t = parseNEW @{context} "3 =!= 3";
wneuper@59388
   418
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   419
if str = "#ident_(3)_(3)" andalso thm2str thm = "(3 =!= 3) = True"
wneuper@59388
   420
then () else error "adhoc_thm  (3 =!= 3)  changed";
wneuper@59387
   421
wneuper@59388
   422
val SOME t = parseNEW @{context} "\<not> (4 + (4 * x + x ^ 2) =!= 0)";
wneuper@59388
   423
val SOME (str, thm) = adhoc_thm thy (isa_str, eval_fn) t;
wneuper@59388
   424
if str = "#ident_(4 + (4 * x + x ^ 2))_(0)" andalso thm2str thm = "(4 + (4 * x + x ^ 2) =!= 0) = False"
wneuper@59388
   425
then () else error "adhoc_thm  (\<not> (4 + (4 * x + x ^ 2) =!= 0))  changed";
wneuper@59403
   426
wneuper@59403
   427
"----------- fun power -------------------------------------------------------------------------";
wneuper@59403
   428
"----------- fun power -------------------------------------------------------------------------";
wneuper@59403
   429
"----------- fun power -------------------------------------------------------------------------";
wneuper@59403
   430
if power 2 3 = 8 then () else error "power 2 3 = 8";
wneuper@59403
   431
if power ~2 3 = ~8 then () else error "power ~2 3 = ~8";
wneuper@59403
   432
if power ~3 2 = 9 then () else error "power ~3 2 = 9";
wneuper@59403
   433
(power 3 ~2; error "power 3 ~2: should raise an exn") handle _ => 000;
wneuper@59403
   434
wneuper@59403
   435
"----------- fun divisors ----------------------------------------------------------------------";
wneuper@59403
   436
"----------- fun divisors ----------------------------------------------------------------------";
wneuper@59403
   437
"----------- fun divisors ----------------------------------------------------------------------";
wneuper@59403
   438
if divisors 30 = [5, 3, 2] then () else error "divisors 30 = [5, 3, 2]";
wneuper@59403
   439
if divisors 32 = [2, 2, 2, 2, 2] then () else error "divisors 32 = [2, 2, 2, 2, 2]";
wneuper@59403
   440
if divisors 60 = [5, 3, 2, 2] then () else error "divisors 60 = [5, 3, 2, 2]";
wneuper@59403
   441
if divisors 11 = [11] then () else error "divisors 11 = [11]";
wneuper@59403
   442
wneuper@59403
   443
"----------- fun doubles, fun squfact ----------------------------------------------------------";
wneuper@59403
   444
"----------- fun doubles, fun squfact ----------------------------------------------------------";
wneuper@59403
   445
"----------- fun doubles, fun squfact ----------------------------------------------------------";
wneuper@59403
   446
if doubles [2,3,4] = [] then () else error "doubles [2,3,4] changed";
wneuper@59403
   447
if doubles [2,3,3,5,5,7] = [5, 3] then () else error "doubles [2,3,3,5,5,7] changed";
wneuper@59403
   448
wneuper@59403
   449
if squfact 30 = 1 then () else error "squfact  30  changed";
wneuper@59403
   450
if squfact 32 = 4 then () else error "squfact  32  changed";
wneuper@59403
   451
if squfact 60 = 2 then () else error "squfact  60  changed";
wneuper@59403
   452
if squfact 11 = 1 then () else error "squfact  11  changed";