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