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