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