src/smltest/Scripts/scrtools.sml
author wneuper
Sat, 30 Sep 2006 11:39:40 +0200
branchstart_Take
changeset 669 aaa641d8546d
parent 598 5e49c921df27
permissions -rw-r--r--
began with inform for Simplify
wneuper@543
     1
(* tests on tools for scripts
wneuper@543
     2
   author: Walther Neuper
wneuper@543
     3
   060605,
wneuper@543
     4
   (c) due to copyright terms
wneuper@543
     5
wneuper@543
     6
use"../smltest/Scripts/scrtools.sml";
wneuper@543
     7
use"scrtools.sml";
wneuper@543
     8
*)
wneuper@543
     9
"-----------------------------------------------------------------";
wneuper@543
    10
"table of contents -----------------------------------------------";
wneuper@543
    11
"-----------------------------------------------------------------";
wneuper@543
    12
"-------- test auto-generated script '(Repeat (Calculate times))'-";
wneuper@543
    13
"-------- test the same called by interSteps norm_Poly -----------";
wneuper@543
    14
"-------- test the same called by interSteps norm_Rational -------";
wneuper@548
    15
"-------- check auto-gen.script for Rewrite_Set_Inst -------------";
wneuper@543
    16
"-----------------------------------------------------------------";
wneuper@543
    17
"-----------------------------------------------------------------";
wneuper@543
    18
"-----------------------------------------------------------------";
wneuper@543
    19
wneuper@543
    20
wneuper@543
    21
"-------- test auto-generated script '(Repeat (Calculate times))'-";
wneuper@543
    22
"-------- test auto-generated script '(Repeat (Calculate times))'-";
wneuper@543
    23
"-------- test auto-generated script '(Repeat (Calculate times))'-";
wneuper@543
    24
val Seq {scr = Script auto_script,...} = assoc_rls "norm_Poly";
wneuper@543
    25
writeln(term2str auto_script);
wneuper@543
    26
atomty auto_script;
wneuper@543
    27
wneuper@543
    28
store_met
wneuper@598
    29
 (prep_met Test.thy "met_testinter" [] e_metID
wneuper@543
    30
 (["Test","test_interSteps_1"]:metID,
wneuper@543
    31
  [("#Given" ,["term t_"]),
wneuper@543
    32
   ("#Find"  ,["normalform n_"])
wneuper@543
    33
   ],
wneuper@543
    34
  {rew_ord'="dummy_ord",rls'=tval_rls,calc=[],srls=e_rls,prls=e_rls,
wneuper@543
    35
   crls=tval_rls, nrls=e_rls},
wneuper@543
    36
"Script Stepwise t_   =                         \
wneuper@543
    37
 \(Try (Rewrite_Set discard_minus_ False) @@    \
wneuper@543
    38
 \ Try (Rewrite_Set expand_poly_ False) @@      \
wneuper@543
    39
 \ Try (Repeat (Calculate times)) @@            \
wneuper@543
    40
 \ Try (Rewrite_Set order_mult_rls_ False) @@   \
wneuper@543
    41
 \ Try (Rewrite_Set simplify_power_ False) @@   \
wneuper@543
    42
 \ Try (Rewrite_Set calc_add_mult_pow_ False) @@\
wneuper@543
    43
 \ Try (Rewrite_Set reduce_012_mult_ False) @@  \
wneuper@543
    44
 \ Try (Rewrite_Set order_add_rls_ False) @@    \
wneuper@543
    45
 \ Try (Rewrite_Set collect_numerals_ False) @@ \
wneuper@543
    46
 \ Try (Rewrite_Set reduce_012_ False) @@       \
wneuper@543
    47
 \ Try (Rewrite_Set discard_parentheses_ False))\
wneuper@543
    48
 \ t_"
wneuper@543
    49
(*presently this script cannot become equal in types to auto_script, because:
wneuper@543
    50
  this t_ must be either 'real' or 'bool'  #1#, 
wneuper@543
    51
  while the auto_script must be 'z and type-instantiated before usage*)
wneuper@543
    52
 ));
wneuper@543
    53
show_mets(); 
wneuper@544
    54
val {scr = Script parsed_script,...} = get_met ["Test","test_interSteps_1"];
wneuper@544
    55
writeln(term2str parsed_script);
wneuper@544
    56
atomty parsed_script;
wneuper@543
    57
wneuper@544
    58
(*the structure of the auto-gen. script is interpreted correctly*)
wneuper@543
    59
states:=[];
wneuper@543
    60
CalcTree
wneuper@543
    61
[(["term (b + a - b)",(*this is Schalk 299b*)
wneuper@543
    62
	   "normalform N"], 
wneuper@543
    63
  ("Poly.thy",["polynomial","simplification"],
wneuper@543
    64
  ["Test","test_interSteps_1"]))];
wneuper@543
    65
Iterator 1;
wneuper@543
    66
moveActiveRoot 1;
wneuper@543
    67
autoCalculate 1 CompleteCalcHead;
wneuper@543
    68
wneuper@544
    69
fetchProposedTactic 1  (*..Apply_Method*);
wneuper@543
    70
autoCalculate 1 (Step 1);
wneuper@544
    71
getTactic 1 ([1], Frm)  (*still empty*);
wneuper@543
    72
wneuper@544
    73
fetchProposedTactic 1  (*discard_minus_*);
wneuper@543
    74
autoCalculate 1 (Step 1);
wneuper@544
    75
wneuper@544
    76
fetchProposedTactic 1  (*order_add_rls_*);
wneuper@544
    77
autoCalculate 1 (Step 1);
wneuper@544
    78
wneuper@544
    79
fetchProposedTactic 1  (*collect_numerals_*);
wneuper@544
    80
autoCalculate 1 (Step 1);
wneuper@543
    81
wneuper@543
    82
autoCalculate 1 CompleteCalc;
wneuper@543
    83
wneuper@543
    84
val ((pt,p),_) = get_calc 1; show_pt pt;
wneuper@543
    85
if existpt' ([1], Frm) pt then ()
wneuper@545
    86
else raise error "scrtools.sml: test-script test_interSteps_1 doesnt work";
wneuper@544
    87
wneuper@543
    88
wneuper@543
    89
"-------- test the same called by interSteps norm_Poly -----------";
wneuper@543
    90
"-------- test the same called by interSteps norm_Poly -----------";
wneuper@543
    91
"-------- test the same called by interSteps norm_Poly -----------";
wneuper@543
    92
val Seq {scr = Script auto_script,...} = assoc_rls "norm_Poly";
wneuper@543
    93
writeln(term2str auto_script);
wneuper@543
    94
atomty auto_script;
wneuper@544
    95
wneuper@543
    96
states:=[];
wneuper@543
    97
CalcTree
wneuper@543
    98
[(["term (b + a - b)", "normalform N"], 
wneuper@543
    99
  ("Poly.thy",["polynomial","simplification"],
wneuper@543
   100
  ["simplification","for_polynomials"]))];
wneuper@543
   101
Iterator 1;
wneuper@543
   102
moveActiveRoot 1;
wneuper@543
   103
autoCalculate 1 CompleteCalc;
wneuper@543
   104
wneuper@543
   105
interSteps 1 ([], Res);
wneuper@543
   106
val ((pt,p),_) = get_calc 1; show_pt pt;
wneuper@543
   107
wneuper@543
   108
interSteps 1 ([1], Res);
wneuper@545
   109
val ((pt,p),_) = get_calc 1; show_pt pt;
wneuper@545
   110
if existpt' ([1,4], Res) pt then ()
wneuper@545
   111
else raise error  "scrtools.sml: auto-generated norm_Poly doesnt work";
wneuper@544
   112
wneuper@546
   113
wneuper@546
   114
wneuper@543
   115
"-------- test the same called by interSteps norm_Rational -------";
wneuper@543
   116
"-------- test the same called by interSteps norm_Rational -------";
wneuper@543
   117
"-------- test the same called by interSteps norm_Rational -------";
wneuper@585
   118
val Seq {scr = Script auto_script,...} = assoc_rls "norm_Rational";
wneuper@543
   119
writeln(term2str auto_script);
wneuper@543
   120
atomty auto_script;
wneuper@669
   121
(***
wneuper@669
   122
*** Const (Script.Stepwise, ['z, 'z] => 'z)
wneuper@669
   123
*** . Free (t_, 'z)
wneuper@669
   124
*** . Const (Script.Seq, ['a => 'a, 'a => 'a, 'a] => 'a)
wneuper@669
   125
*** . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   126
*** . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   127
*** . . . . Free (discard_minus_, Script.ID)
wneuper@669
   128
*** . . . . Const (False, bool)
wneuper@669
   129
*** . . Const (Script.Seq, ['a => 'a, 'a => 'a, 'a] => 'a)
wneuper@669
   130
*** . . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   131
*** . . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   132
*** . . . . . Free (rat_mult_poly, Script.ID)
wneuper@669
   133
*** . . . . . Const (False, bool)
wneuper@669
   134
*** . . . Const (Script.Seq, ['a => 'a, 'a => 'a, 'a] => 'a)
wneuper@669
   135
*** . . . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   136
*** . . . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   137
*** . . . . . . Free (make_rat_poly_with_parentheses, Script.ID)
wneuper@669
   138
*** . . . . . . Const (False, bool)
wneuper@669
   139
*** . . . . Const (Script.Seq, ['a => 'a, 'a => 'a, 'a] => 'a)
wneuper@669
   140
*** . . . . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   141
*** . . . . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   142
*** . . . . . . . Free (cancel_p_rls, Script.ID)
wneuper@669
   143
*** . . . . . . . Const (False, bool)
wneuper@669
   144
*** . . . . . Const (Script.Seq, ['a => 'a, 'a => 'a, 'a] => 'a)
wneuper@669
   145
*** . . . . . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   146
*** . . . . . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   147
*** . . . . . . . . Free (norm_Rational_rls, Script.ID)
wneuper@669
   148
*** . . . . . . . . Const (False, bool)
wneuper@669
   149
*** . . . . . . Const (Script.Try, ['a => 'a, 'a] => 'a)
wneuper@669
   150
*** . . . . . . . Const (Script.Rewrite'_Set, [Script.ID, bool, 'a] => 'a)
wneuper@669
   151
*** . . . . . . . . Free (discard_parentheses_, Script.ID)
wneuper@669
   152
*** . . . . . . . . Const (False, bool)
wneuper@669
   153
*** . . Free (t_, 'a)
wneuper@669
   154
***)
wneuper@543
   155
states:=[];
wneuper@543
   156
CalcTree
wneuper@543
   157
[(["term (b + a - b)", "normalform N"], 
wneuper@543
   158
  ("Poly.thy",["polynomial","simplification"],
wneuper@543
   159
  ["simplification","of_rationals"]))];
wneuper@543
   160
Iterator 1;
wneuper@543
   161
moveActiveRoot 1;
wneuper@543
   162
autoCalculate 1 CompleteCalc;
wneuper@543
   163
wneuper@543
   164
interSteps 1 ([], Res);
wneuper@543
   165
val ((pt,p),_) = get_calc 1; show_pt pt;
wneuper@543
   166
wneuper@543
   167
interSteps 1 ([1], Res);
wneuper@543
   168
val ((pt,p),_) = get_calc 1; show_pt pt;
wneuper@669
   169
wneuper@669
   170
(*with "Script SimplifyScript (t_::real) =                \
wneuper@669
   171
       \  ((Rewrite_Set norm_Rational False) t_)"
wneuper@669
   172
val (Form form, Some tac, asm) = pt_extract (pt, ([1], Res));
wneuper@585
   173
*)
wneuper@669
   174
val (Form form, Some tac, asm) = pt_extract (pt, ([2], Res));
wneuper@585
   175
case (term2str form, tac, terms2strs asm) of
wneuper@585
   176
    ("a", Check_Postcond ["polynomial", "simplification"], []) => ()
wneuper@585
   177
  | _ => raise error "scrtools.sml: auto-generated norm_Rational doesnt work";
wneuper@543
   178
wneuper@548
   179
wneuper@548
   180
wneuper@548
   181
"-------- check auto-gen.script for Rewrite_Set_Inst -------------";
wneuper@548
   182
"-------- check auto-gen.script for Rewrite_Set_Inst -------------";
wneuper@548
   183
"-------- check auto-gen.script for Rewrite_Set_Inst -------------";
wneuper@549
   184
val rls = assoc_rls "integration";
wneuper@549
   185
val Seq {scr = Script auto_script,...} = rls;
wneuper@548
   186
writeln(term2str auto_script);
wneuper@548
   187
wneuper@549
   188
if contain_bdv (get_rules rls) then ()
wneuper@549
   189
else raise error "scrtools.sml: contain_bdv doesnt work for 'integration'";
wneuper@549
   190
wneuper@548
   191
two_scr_arg auto_script;
wneuper@549
   192
init_istate (Rewrite_Set_Inst (["(bdv, x)"], "integration_rules")) 
wneuper@549
   193
			      (str2term "someTermWithBdv");