test/Tools/isac/ProgLang/calculate.sml
author Walther Neuper <walther.neuper@jku.at>
Tue, 03 Sep 2019 12:40:27 +0200
changeset 59603 30cd47104ad7
parent 59592 99c8d2ff63eb
child 59686 3ce3d089bd64
permissions -rw-r--r--
lucin: reorganise theories in ProgLang

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