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