test/Tools/isac/ProgLang/calculate.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Sep 2010 09:06:56 +0200
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 38022 e6d356fc4d38
child 38032 121765ba0a34
permissions -rw-r--r--
tuned error and writeln

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