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