test/Tools/isac/ProgLang/calculate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Jan 2014 08:21:45 +0100
changeset 55366 1d2dfa298322
parent 55363 d78bc1342183
child 55380 7be2ad0e4acb
permissions -rw-r--r--
adapted test setup for test
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@38022
     5
12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@38022
     6
        10        20        30        40        50        60        70        80
neuper@37906
     7
*)
neuper@37906
     8
neuper@38022
     9
"--------------------------------------------------------";
neuper@38022
    10
"table of contents --------------------------------------";
neuper@38022
    11
"--------------------------------------------------------";
neuper@55366
    12
"-calculate.thy: provides 'setup' -----------------------";
neuper@41924
    13
"----------- fun norm -----------------------------------";
neuper@38022
    14
"----------- check return value of get_calculation_  ----";
neuper@38032
    15
"----------- fun calculate_ -----------------------------";
neuper@38032
    16
"----------- fun calculate_ -----------------------------";
neuper@55366
    17
"----------- calculate from script --requires 'setup'----";
neuper@38032
    18
"----------- calculate check test-root-equ --------------";
neuper@38032
    19
"----------- check calculate bottom up ------------------";
neuper@42223
    20
"----------- Atools.pow Power.power_class.power ---------";
neuper@41934
    21
" ================= calculate.sml: calculate_ 2002 ======";
neuper@38032
    22
"----------- get_pair with 3 args -----------------------";
neuper@38032
    23
"----------- calculate (2 * x is_const) -----------------";
neuper@38022
    24
"--------------------------------------------------------";
neuper@38022
    25
"--------------------------------------------------------";
neuper@38022
    26
"--------------------------------------------------------";
neuper@37906
    27
neuper@38022
    28
"----------- check return value of get_calculation_  ----";
neuper@38022
    29
"----------- check return value of get_calculation_  ----";
neuper@38022
    30
"----------- check return value of get_calculation_  ----";
neuper@41924
    31
val thy = @{theory "Poly"};
s1210629013@52153
    32
val cal = snd (assoc_calc' thy "is_polyexp");
neuper@38022
    33
val t = @{term "(x / x) is_polyexp"};
neuper@38022
    34
val SOME (thmID, thm) = get_calculation_ thy cal t;
neuper@38022
    35
(HOLogic.dest_Trueprop (prop_of thm); writeln "all thms wrapped by Trueprop")
neuper@38022
    36
handle TERM _ => 
neuper@38031
    37
       error "calculate.sml: get_calculation_ must return Trueprop";
neuper@38022
    38
neuper@38033
    39
"----------- fun calculate_ -----------------------------";
neuper@38033
    40
"----------- fun calculate_ -----------------------------";
neuper@38033
    41
"----------- fun calculate_ -----------------------------";
neuper@41924
    42
val thy = @{theory "Test"};
neuper@38033
    43
"===== test 1";
neuper@38033
    44
val t = (term_of o the o (parse thy)) "1+2";
neuper@38033
    45
val SOME (thmID,thm) = get_calculation_ thy (the(assoc(calclist,"PLUS"))) t;
neuper@38033
    46
term2str (prop_of thm) = "1 + 2 = 3";
neuper@38033
    47
neuper@38033
    48
"===== test 2";
neuper@38033
    49
val t = (term_of o the o (parse thy)) "((1+2)*4/3)^^^2";
neuper@38033
    50
val SOME (thmID,thm) = get_calculation_ thy (the(assoc(calclist,"PLUS"))) t;
neuper@38033
    51
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@41931
    52
if term2str t = "(3 * 4 / 3) ^^^ 2" then ()
neuper@41931
    53
else error "calculate.sml: ((1+2)*4/3)^^^2 --> (3 * 4 / 3) ^^^ 2";
neuper@38033
    54
neuper@38033
    55
"===== test 3b -- 2 contiued";
neuper@38033
    56
val SOME (thmID,thm) = get_calculation_ thy (the(assoc(calclist,"TIMES"))) t;
neuper@38033
    57
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
    58
term2str t;
neuper@38033
    59
(*val it = "(#12 // #3) ^^^ #2" : string*)
neuper@37906
    60
neuper@38033
    61
"===== test 4";
neuper@38033
    62
val SOME (thmID,thm) = get_calculation_ thy(the(assoc(calclist,"DIVIDE")))t;
neuper@38032
    63
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
    64
term2str t;
neuper@38033
    65
(*it = "#4 ^^^ #2" : string*)
neuper@38033
    66
neuper@38033
    67
"===== test 5";
neuper@38033
    68
val SOME (thmID,thm) = get_calculation_ thy(the(assoc(calclist,"POWER")))t;
neuper@38032
    69
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@41931
    70
(*show_types := false;*)
neuper@38037
    71
if term2str t <> "16" then error "calculate.sml: new behaviour in calculate_"
neuper@37906
    72
else ();
neuper@37906
    73
neuper@38032
    74
"----------- calculate from script ----------------------";
neuper@38032
    75
"----------- calculate from script ----------------------";
neuper@38032
    76
"----------- calculate from script ----------------------";
neuper@37906
    77
store_met
neuper@41924
    78
 (prep_met (@{theory "Test"}) "met_testcal" [] e_metID
neuper@37906
    79
 (["Test","test_calculate"]:metID,
neuper@38035
    80
  [("#Given" ,["realTestGiven t_t"]),
neuper@38035
    81
   ("#Find"  ,["realTestFind s_s"])
neuper@37906
    82
   ],
neuper@37906
    83
  {rew_ord'="sqrt_right",rls'=tval_rls,srls=e_rls,prls=e_rls,
neuper@38033
    84
   calc=[("PLUS"    ,("op +"        ,eval_binop "#add_")),
neuper@38034
    85
	 ("TIMES"   ,("Groups.times_class.times"        ,eval_binop "#mult_")),
neuper@38033
    86
	 ("DIVIDE" ,("HOL.divide"  ,eval_cancel "#divide_")),
neuper@38033
    87
	 ("POWER"  ,("Atools.pow"  ,eval_binop "#power_"))],
neuper@42425
    88
   crls=tval_rls, errpats = [], nrls=e_rls(*,
neuper@37906
    89
   asm_rls=[],asm_thm=[]*)},
neuper@38035
    90
  "Script STest_simplify (t_t::real) =          \
neuper@37906
    91
  \(Repeat                                        \
neuper@38035
    92
  \ ((Try (Repeat (Calculate PLUS))) @@   \
neuper@38035
    93
  \  (Try (Repeat (Calculate TIMES))) @@  \
neuper@38035
    94
  \  (Try (Repeat (Calculate DIVIDE))) @@ \
neuper@38035
    95
  \  (Try (Repeat (Calculate POWER))))) t_t"
neuper@37906
    96
   ));
neuper@37906
    97
neuper@37906
    98
val fmz = ["realTestGiven (((1+2)*4/3)^^^2)","realTestFind s"];
neuper@37906
    99
val (dI',pI',mI') =
neuper@38035
   100
  ("Test",["calculate","test"],["Test","test_calculate"]);
neuper@38035
   101
neuper@37906
   102
val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
neuper@37906
   103
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   104
(*nxt =("Add_Given",Add_Given "realTestGiven (((#1 + #2) * #4 // #3) ^^^#2)")*)
neuper@37906
   105
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   106
(*nxt = ("Add_Find",Add_Find "realTestFind s") : string * tac*)
neuper@37906
   107
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
   108
(*nxt = ("Specify_Theory",Specify_Theory "Test") : string * tac*)
neuper@37906
   109
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   110
(*nxt = ("Specify_Problem",Specify_Problem ["calculate","test"])*)
neuper@37906
   111
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
   112
(*nxt = ("Specify_Method",Specify_Method ("Test","test_calculate"))*)
neuper@37906
   113
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38035
   114
(*nxt = ("Apply_Method",Apply_Method ("Test","test_calculate"))*)
neuper@37906
   115
neuper@37906
   116
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
   117
(*nxt = ("Calculate",Calculate "PLUS")*)
neuper@37906
   118
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
   119
(*nxt = ("Calculate",Calculate "TIMES")*)
neuper@37906
   120
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
   121
(*nxt = ("Calculate",Calculate "DIVIDE")*)
neuper@37906
   122
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@38033
   123
(*nxt = ("Calculate",Calculate "POWER")*)
neuper@37906
   124
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   125
(*nxt = ("Check_Postcond",Check_Postcond ["calculate","test"])*)
neuper@37906
   126
val (p,_,f,nxt,_,pt) = me nxt p [1] pt;
neuper@37906
   127
(*nxt = ("End_Proof'",End_Proof')*)
neuper@37906
   128
if f = Form' (FormKF (~1,EdUndef,0,Nundef,"16")) then ()
neuper@38031
   129
else error "calculate.sml: script test_calculate changed behaviour";
neuper@37906
   130
neuper@37906
   131
neuper@38032
   132
"----------- calculate check test-root-equ --------------";
neuper@38032
   133
"----------- calculate check test-root-equ --------------";
neuper@38032
   134
"----------- calculate check test-root-equ --------------";
neuper@37906
   135
(*(1): 2nd Test_simplify didn't work:
neuper@37906
   136
val ct =
neuper@37906
   137
  "sqrt (x ^^^ 2 + -3 * x) = (-3 + 2 * x + -1 * (9 + 4 * x)) / (-1 * 2)"
neuper@37906
   138
> val rls = ("Test_simplify");
neuper@37906
   139
> val (ct,_) = the (rewrite_set thy' ("tval_rls") false rls ct);
neuper@37906
   140
val ct = "sqrt (x ^^^ 2 + -3 * x) =
neuper@37906
   141
(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))";
neuper@37906
   142
ie. cancel does not work properly
neuper@37906
   143
*)
neuper@38035
   144
 val thy = "Test";
neuper@38033
   145
 val op_ = "DIVIDE";
neuper@37906
   146
 val ct = "sqrt (x ^^^ 2 + -3 * x) =\
neuper@37906
   147
 \(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))";
neuper@38032
   148
 val SOME (ct,_) = calculate thy (the(assoc(calclist,op_))) ct;
neuper@37906
   149
 writeln ct;
neuper@37906
   150
(*
neuper@37906
   151
           sqrt (x ^^^ 2 + -3 * x) =\
neuper@37906
   152
 \(-9) / (-2) + (-3 / (-2) + (x * ((-4) / (-2)) + x * (2 / (-2))))
neuper@37906
   153
............... does not work *)
neuper@37906
   154
neuper@37906
   155
(*--------------(2): does divide work in Test_simplify ?: ------*)
akargl@42188
   156
 val thy = @{theory Test};
neuper@37906
   157
 val t = (term_of o the o (parse thy)) "6 / 2";
neuper@37906
   158
 val rls = Test_simplify;
neuper@37906
   159
 val (t,_) = the (rewrite_set_ thy false rls t);
neuper@55279
   160
(*val t = Free ("3","Real.real") : term*)
neuper@37906
   161
neuper@38035
   162
 val thy = "Test";
neuper@37906
   163
 val t = "6 / 2";
neuper@37906
   164
 val rls = "Test_simplify";
neuper@37906
   165
 val (t,_) = the (rewrite_set thy false rls t);
neuper@37906
   166
(*val t = "3" : string
neuper@37906
   167
      ....... works, thus: which rule in SqRoot_simplify works differently ?*)
neuper@37906
   168
neuper@37906
   169
neuper@37906
   170
(*--------------(3): is_const works ?: -------------------------------------*)
akargl@42188
   171
 val t = (term_of o the o (parse @{theory Test})) "2 is_const";
neuper@37906
   172
 atomty t;
akargl@42188
   173
 rewrite_set_ @{theory Test} false tval_rls t;
neuper@41928
   174
(*val it = SOME (Const ("HOL.True","bool"),[]) ... works*)
neuper@37906
   175
neuper@37906
   176
 val t = str2term "2 * x is_const";
akargl@42188
   177
 val SOME (str,t') = eval_const "" "" t (@{theory "Isac"});
neuper@37906
   178
 term2str t';
neuper@37906
   179
 
neuper@37906
   180
neuper@38032
   181
"----------- check calculate bottom up ------------------";
neuper@38032
   182
"----------- check calculate bottom up ------------------";
neuper@38032
   183
"----------- check calculate bottom up ------------------";
neuper@37906
   184
(*-------------- eval_cancel works: *)
neuper@52070
   185
 trace_rewrite:=false;
akargl@42188
   186
 val thy = @{theory Test};
neuper@37906
   187
 val t = (term_of o the o (parse thy)) "(-4) / 2";
akargl@42188
   188
neuper@48789
   189
val SOME (_, t) = eval_cancel "xxx" "Fields.inverse_class.divide" t thy;
akargl@42188
   190
neuper@37906
   191
 term2str t;
neuper@37906
   192
"-4 / 2 = (-2)";
neuper@37906
   193
(*-------------- but ... *)
neuper@37906
   194
 val ct = "x + (-4) / 2";
akargl@42188
   195
akargl@42218
   196
val thy' = "Test"; (* added AK110727 *)
neuper@37906
   197
 val (ct,_) = the (rewrite_set thy' false rls ct);
akargl@42188
   198
neuper@37906
   199
"(-2) + x";
neuper@37906
   200
(*-------------- while ... *)
neuper@37906
   201
 val ct = "(-4) / 2";
akargl@42202
   202
neuper@37906
   203
 val (ct,_) = the (rewrite_set thy'  false rls ct);
akargl@42202
   204
neuper@37906
   205
"-2";
neuper@37906
   206
neuper@37906
   207
(*--------------(5): reproduce (1) with simpler term: ------------*)
neuper@38035
   208
 val thy = "Test";
neuper@37906
   209
 val t = "(3+5)/2";
neuper@37906
   210
 val (t,_) = the (rewrite_set thy false rls t);
neuper@37906
   211
(*val t = "4" ... works*)
neuper@37906
   212
neuper@37906
   213
 val t = "(3+1+2*x)/2";
neuper@37906
   214
 val (t,_) = the (rewrite_set thy false rls t);
neuper@37906
   215
(*val t = "2 + x" ... works*)
neuper@37906
   216
neuper@52070
   217
 trace_rewrite:=false; (*=true3.6.03*)
akargl@42218
   218
neuper@38035
   219
 val thy = "Test";
neuper@37906
   220
 val rls = "Test_simplify";
neuper@37906
   221
 val t = "(3+(1+2*x))/2";
neuper@37906
   222
 val (t,_) = the (rewrite_set thy false rls t);
neuper@37906
   223
(*val t = "2 + x" ... works: give up----------------------------------------*)
neuper@37906
   224
 trace_rewrite:=false; 
neuper@37906
   225
neuper@52070
   226
 trace_rewrite:=false; (*=true3.6.03*)
akargl@42188
   227
 val thy = @{theory Test};
neuper@37906
   228
 val rls = Test_simplify;
neuper@37906
   229
 val t = str2term "(3+(1+2*x))/2";
neuper@38032
   230
 val SOME (t',asm) = rewrite_set_ thy false rls t;
neuper@37906
   231
 term2str t';
neuper@37906
   232
(*val t = "2 + x" ... works: give up----------------------------------------*)
neuper@37906
   233
 trace_rewrite:=false; 
neuper@37906
   234
neuper@37906
   235
neuper@37906
   236
neuper@37906
   237
neuper@37906
   238
(*--- trace_rewrite before correction of ... --------------------
neuper@37906
   239
 val ct = "(-3 + 2 * x + -1) / 2";
neuper@37906
   240
 val (ct,_) = the (rewrite_set thy'  false rls ct);
neuper@37906
   241
:
neuper@37906
   242
### trying thm 'root_ge0_2'
neuper@37906
   243
### rewrite_set_: x + (-1 + -3) / 2
neuper@37906
   244
### trying thm 'radd_real_const_eq'
neuper@37906
   245
### trying thm 'radd_real_const'
neuper@37906
   246
### rewrite_set_: x + (-4) / 2
neuper@37906
   247
### trying thm 'rcollect_right'
neuper@37906
   248
:
neuper@37906
   249
"x + (-4) / 2"
neuper@37906
   250
-------------------------------------while before Isabelle20002:
neuper@37906
   251
 val ct = "(#-3 + #2 * x + #-1) // #2";
neuper@37906
   252
 val (ct,_) = the (rewrite_set thy'  false rls ct);
neuper@37906
   253
:
neuper@37906
   254
### trying thm 'root_ge0_2'
neuper@37906
   255
### rewrite_set_: x + (#-1 + #-3) // #2
neuper@37906
   256
### trying thm 'radd_real_const_eq'
neuper@37906
   257
### trying thm 'radd_real_const'
neuper@37906
   258
### rewrite_set_: x + #-4 // #2
neuper@37906
   259
### rewrite_set_: x + #-2
neuper@37906
   260
### trying thm 'rcollect_right'
neuper@37906
   261
:
neuper@37906
   262
"#-2 + x"
neuper@37906
   263
-----------------------------------------------------------------*)
neuper@37906
   264
neuper@37906
   265
neuper@37906
   266
(*===================*)
neuper@52070
   267
 trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*)
neuper@38035
   268
 val thy' = "Test";
neuper@37906
   269
 val rls = "Test_simplify";		
neuper@37906
   270
 val ct = "x + (-1 + -3) / 2";
neuper@37906
   271
 val (ct,_) = the (rewrite_set thy'  false rls ct);	
neuper@37906
   272
"x + (-4) / 2";						
neuper@37906
   273
(*
neuper@37906
   274
### trying calc. 'cancel'
neuper@37906
   275
@@@ get_pair: binop, t = x + (-4) / 2
neuper@37906
   276
@@@ get_pair: t else
neuper@38032
   277
@@@ get_pair: t else -> NONE
neuper@37906
   278
@@@ get_pair: binop, t = (-4) / 2
neuper@37906
   279
@@@ get_pair: then 1
neuper@38032
   280
@@@ get_pair: t -> NONE
neuper@38032
   281
@@@ get_pair: t1 -> NONE
neuper@38032
   282
@@@ get_calculation: NONE
neuper@37906
   283
### trying calc. 'pow'
neuper@37906
   284
*)
neuper@37906
   285
neuper@52070
   286
 trace_rewrite:=false; (*WN130722: =true stopped Test_Isac.thy*)
neuper@38035
   287
 val thy' = "Test";
neuper@37906
   288
 val rls = "Test_simplify";		
neuper@37906
   289
 val ct = "x + (-4) / 2";
neuper@37906
   290
 val (ct,_) = the (rewrite_set thy'  false rls ct);	
neuper@37906
   291
"(-2) + x";
neuper@37906
   292
(*
neuper@37906
   293
### trying calc. 'cancel'
neuper@37906
   294
@@@ get_pair: binop, t = x + -4 / 2
neuper@37906
   295
@@@ get_pair: t else
neuper@38032
   296
@@@ get_pair: t else -> NONE
neuper@37906
   297
@@@ get_pair: binop, t = -4 / 2
neuper@37906
   298
@@@ get_pair: then 1
neuper@38032
   299
@@@ get_calculation: SOME #cancel_-4_2
neuper@37906
   300
### calc. to: x + (-2)
neuper@37906
   301
### trying calc. 'cancel'
neuper@37906
   302
*)
neuper@37906
   303
 trace_rewrite:=false;
neuper@37906
   304
neuper@42223
   305
"----------- Atools.pow Power.power_class.power ---------";
neuper@42223
   306
"----------- Atools.pow Power.power_class.power ---------";
neuper@42223
   307
"----------- Atools.pow Power.power_class.power ---------";
neuper@42223
   308
val t = (term_of o the o (parseold thy)) "1 ^ aaa";
neuper@42223
   309
atomty t;
neuper@37906
   310
(*** -------------
neuper@37906
   311
*** Const ( Nat.power, ['a, nat] => 'a)
neuper@37906
   312
*** . Free ( 1, 'a)
neuper@37906
   313
*** . Free ( aaa, nat) *)
akargl@42218
   314
neuper@42223
   315
val t = str2term "1 ^^^ aaa";
neuper@42223
   316
atomty t;
neuper@42223
   317
(**** 
neuper@42223
   318
*** Const (Atools.pow, real => real => real)
neuper@42223
   319
*** . Free (1, real)
neuper@42223
   320
*** . Free (aaa, real)
neuper@42223
   321
*** *);
neuper@37906
   322
neuper@37906
   323
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   324
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   325
" ================= calculate.sml: calculate_ 2002 =================== ";
neuper@37906
   326
akargl@42188
   327
val thy = @{theory Test};
neuper@37906
   328
val t = (term_of o the o (parse thy)) "12 / 3";
neuper@38033
   329
val SOME (thmID,thm) = get_calculation_ thy(the(assoc(calclist,"DIVIDE")))t;
neuper@38032
   330
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@37906
   331
"12 / 3 = 4";
akargl@42188
   332
val thy = @{theory Test};
neuper@37906
   333
val t = (term_of o the o (parse thy)) "4 ^^^ 2";
neuper@38033
   334
val SOME (thmID,thm) = get_calculation_ thy(the(assoc(calclist,"POWER"))) t;
neuper@38032
   335
val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@37906
   336
"4 ^ 2 = 16";
neuper@37906
   337
neuper@37906
   338
 val t = (term_of o the o (parse thy)) "((1 + 2) * 4 / 3) ^^^ 2";
neuper@38033
   339
 val SOME (thmID,thm) = get_calculation_ thy (the(assoc(calclist,"PLUS"))) t;
neuper@37906
   340
"1 + 2 = 3";
neuper@38032
   341
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   342
 term2str t;
neuper@37906
   343
"(3 * 4 / 3) ^^^ 2";
neuper@38033
   344
 val SOME (thmID,thm) = get_calculation_ thy (the(assoc(calclist,"TIMES")))t;
neuper@37906
   345
"3 * 4 = 12";
neuper@38032
   346
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   347
 term2str t;
neuper@37906
   348
"(12 / 3) ^^^ 2";
neuper@38033
   349
 val SOME (thmID,thm) =get_calculation_ thy(the(assoc(calclist,"DIVIDE")))t;
neuper@37906
   350
"12 / 3 = 4";
neuper@38032
   351
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   352
 term2str t;
neuper@37906
   353
"4 ^^^ 2";
neuper@38033
   354
 val SOME (thmID,thm) = get_calculation_ thy(the(assoc(calclist,"POWER")))t;
neuper@37906
   355
"4 ^^^ 2 = 16";
neuper@38032
   356
 val SOME (t,_) = rewrite_ thy tless_true tval_rls true thm t;
neuper@38033
   357
 term2str t;
neuper@37906
   358
"16";
neuper@38031
   359
 if it <> "16" then error "calculate.sml: new behaviour in calculate_"
neuper@37906
   360
 else ();
neuper@37906
   361
neuper@37906
   362
(*13.9.02 *** calc: operator = pow not defined*)
neuper@37906
   363
  val t = (term_of o the o (parse thy)) "3^^^2";
neuper@38032
   364
  val SOME (thmID,thm) = 
neuper@38033
   365
      get_calculation_ thy (the(assoc(calclist,"POWER"))) t;
neuper@37906
   366
(*** calc: operator = pow not defined*)
neuper@37906
   367
neuper@38033
   368
  val (op_, eval_fn) = the (assoc(calclist,"POWER"));
neuper@37906
   369
  (*
neuper@37906
   370
val op_ = "Atools.pow" : string
neuper@37906
   371
val eval_fn = fn : string -> term -> theory -> (string * term) option*)
neuper@37906
   372
neuper@38032
   373
  val SOME (thmid,t') = get_pair thy op_ eval_fn t;
neuper@37906
   374
(*** calc: operator = pow not defined*)
neuper@37906
   375
neuper@38032
   376
  val SOME (id,t') = eval_fn op_ t thy;
neuper@37906
   377
(*** calc: operator = pow not defined*)
neuper@37906
   378
neuper@37906
   379
  val (thmid, (Const (op0,t0) $ Free (n1,t1) $ Free(n2,t2))) = (op_, t);
neuper@38032
   380
  val SOME (id,t') = eval_binop thmid op_ t thy;
neuper@37906
   381
(*** calc: operator = pow not defined*)
neuper@37906
   382
akargl@42188
   383
neuper@37906
   384
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   385
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   386
"----------- get_pair with 3 args --------------------------------";
neuper@37906
   387
val (thy, op_, ef, arg) =
neuper@37906
   388
    (thy, "EqSystem.occur'_exactly'_in", 
s1210629013@52158
   389
     assoc_calc' (Thy_Info.get_theory "EqSystem") "occur_exactly_in" |> snd |> snd,
neuper@37906
   390
     str2term
akargl@42188
   391
      "[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2"
neuper@37906
   392
      );
neuper@38032
   393
val SOME (str, simpl) = get_pair thy op_ ef arg;
neuper@37906
   394
if str = 
akargl@42188
   395
"[] from [c, c_2, c_3, c_4] occur_exactly_in -1 * (q_0 * L ^^^ 2) / 2 = True"
neuper@38031
   396
then () else error "calculate.sml get_pair with 3 args:occur_exactly_in";
neuper@37906
   397
neuper@37906
   398
neuper@38032
   399
"----------- calculate (2 * x is_const) -----------------";
neuper@38032
   400
"----------- calculate (2 * x is_const) -----------------";
neuper@38032
   401
"----------- calculate (2 * x is_const) -----------------";
neuper@37906
   402
val t = str2term "2 * x is_const";
akargl@42188
   403
val SOME (str, t') = eval_const "" "" t @{theory Test};
neuper@37906
   404
term2str t';
neuper@37906
   405
"(2 * x is_const) = False";
neuper@37906
   406
akargl@42188
   407
val SOME (t',_) = rewrite_set_ @{theory Test} false tval_rls t;
neuper@37906
   408
term2str t';
neuper@41928
   409
"HOL.False";