test/Tools/isac/Interpret/rewtools.sml
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 02 Sep 2013 16:16:08 +0200
changeset 52101 c3f399ce32af
parent 52062 b3f18f0d55d9
child 52156 aa0884017d48
permissions -rw-r--r--
Test_Isac works again, almost ..

4 files raise errors:
# Interpret/solve.sml: "solve.sml: interSteps on norm_Rational 2"
# Interpret/inform.sml: "inform.sml: [rational,simplification] 2"
# Knowledge/partial_fractions.sml: "autoCalculate for met_partial_fraction changed: final result"
# Knowledge/eqsystem.sml: "eqsystem.sml: exp 7.70 normalize 4x4 by rewrite changed"

The chunk of changes is due to the fact, that Isac's code still is unstable.
The changes are accumulated since e8f46493af82.
akargl@42181
     1
(* Title: test for rewtools.sml
neuper@37906
     2
   authors: Walther Neuper 2000, 2006
neuper@37906
     3
*)
neuper@37906
     4
neuper@38061
     5
"--------------------------------------------------------";
neuper@38061
     6
"--------------------------------------------------------";
neuper@38061
     7
"table of contents --------------------------------------";
neuper@38061
     8
"--------------------------------------------------------";
neuper@48895
     9
(*============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! =================
neuper@42399
    10
"----------- fun make_isab ------------------------------";
neuper@38061
    11
"----------- fun collect_isab_thys ----------------------";
neuper@48895
    12
============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ===============*)
neuper@38061
    13
"----------- fun thy_containing_rls ---------------------";
neuper@38061
    14
"----------- fun thy_containing_cal ---------------------";
neuper@42407
    15
(*============ inhibit exn WN120321 ==============================================
neuper@38061
    16
"----------- initContext Thy_ Integration-demo ----------";
neuper@38061
    17
"----------- initContext..Thy_, fun context_thm ---------";
neuper@38061
    18
"----------- initContext..Thy_, fun context_rls ---------";
neuper@38061
    19
"----------- checkContext..Thy_, fun context_thy --------";
neuper@38061
    20
"----------- checkContext..Thy_, fun context_rls --------";
neuper@38061
    21
"----------- checkContext..Thy_ on last formula ---------"; 
neuper@38061
    22
"----------- fun guh2theID ------------------------------";
neuper@38061
    23
"----------- debugging on Tests/solve_linear_as_rootpbl -";
neuper@38061
    24
"--------------------------------------------------------";
neuper@38061
    25
"----------- fun string_of_thmI for_[.]_) ---------------";
neuper@38061
    26
"----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
neuper@38061
    27
"--------------------------------------------------------";
neuper@38061
    28
"----------- fun filter_appl_rews -----------------------";
neuper@38061
    29
"----------- fun is_contained_in ------------------------";
neuper@42407
    30
============ inhibit exn WN120321 ==============================================*)
neuper@42433
    31
"-------- build fun get_bdv_subst --------------------------------";
neuper@38061
    32
"--------------------------------------------------------";
neuper@38061
    33
"--------------------------------------------------------";
neuper@37906
    34
neuper@42399
    35
"----------- fun make_isab ------------------------------";
neuper@42399
    36
"----------- fun make_isab ------------------------------";
neuper@42407
    37
(*============ inhibit exn WN120321 ==============================================
neuper@42399
    38
"----------- fun make_isab ------------------------------";
neuper@42399
    39
(* rlsthmsNOTisac: contains thms in rls requested from Isabelle ---" *)
neuper@42400
    40
map #1 (rlsthmsNOTisac : (string * term) list) = (*WN101011, Isabelle2009-2*)
neuper@38061
    41
["refl", "o_apply", "del_base", "del_rec", "LENGTH_CONS", "LENGTH_NIL",
neuper@38061
    42
 "list_diff_def", "take_Nil", "take_Cons", "if_True", "if_False",
neuper@52062
    43
 "sym_real_mult_minus1", "distrib_right", "distrib_left",
neuper@38061
    44
 "sym_realpow_twoI", "sym_realpow_addI", "mult_1_right",
neuper@38061
    45
 "sym_real_mult_2", "mult_1_left", "mult_zero_left", "mult_zero_right",
neuper@48763
    46
 "add_0_left", "add_0_right", "divide_zero_left", "sym_mult_assoc",
neuper@48764
    47
 "order_refl", "minus_minus", "mult_commute", "mult_assoc",
neuper@38061
    48
 "add_commute", "add_left_commute", "add_assoc", "minus_mult_left",
neuper@38061
    49
 "right_minus", "sym_add_assoc", "left_diff_distrib",
neuper@38061
    50
 "right_diff_distrib", "minus_divide_left", "times_divide_eq_right",
neuper@38061
    51
 "times_divide_eq_left", "divide_divide_eq_left",
neuper@38061
    52
 "divide_divide_eq_right", "divide_1", "add_divide_distrib",
neuper@38061
    53
 "sym_rmult_assoc"]; 
neuper@42399
    54
if length rlsthmsNOTisac > 34 then () 
neuper@38061
    55
else error "rewtools.sml: some rlsthmsNOTisac dropped";
neuper@37906
    56
neuper@42399
    57
"----- FIXME.WN11xxxx: rlsthmsNOTisac DOES contain thms from isac ---";
neuper@42400
    58
map (thmID_of_derivation_name o #1) rlsthmsNOTisac;
neuper@42399
    59
"----- FIXME.WN11xxxx: sym_* in rlsthmsNOTisac DOES contain thms from isac ---";
neuper@38062
    60
val symthms = [("real_mult_minus1", @{thm real_mult_minus1}),
neuper@38062
    61
               ("realpow_twoI", @{thm realpow_twoI}),
neuper@38062
    62
               ("realpow_addI", @{thm realpow_addI}),
neuper@38062
    63
               ("real_mult_2", @{thm real_mult_2}),
neuper@48763
    64
               ("mult_assoc", @{thm mult_assoc}),
neuper@38062
    65
               ("add_assoc", @{thm add_assoc}),
neuper@38062
    66
               ("rmult_assoc", @{thm rmult_assoc})];
neuper@38062
    67
map (Thm.derivation_name o #2) symthms;
neuper@37906
    68
neuper@38061
    69
"----------- fun collect_isab_thys ----------------------";
neuper@38061
    70
"----------- fun collect_isab_thys ----------------------";
neuper@38061
    71
"----------- fun collect_isab_thys ----------------------";
akargl@42108
    72
val ancestors = Theory.ancestors_of @{theory "Complex_Main"};
neuper@38061
    73
val isabthms = (flat o (map Theory.axioms_of)) ancestors;
neuper@38061
    74
neuper@38061
    75
val isacrules = (flat o (map (thms_of_rls o #2 o #2))) (! ruleset');
neuper@37906
    76
(*thms from rulesets*)
akargl@42181
    77
(*=== inhibit exn AK110725 =============================================================
neuper@37906
    78
val isacrlsthms = ((map rep_thm_G') o flat o 
akargl@42181
    79
		 (map (PureThy.all_thms_of_rls o #2 o #2))) (!ruleset');
neuper@37906
    80
length isacrlsthms;
neuper@37906
    81
(*takes a few seconds...
neuper@37906
    82
val isacrlsthms = gen_distinct eq_thmI isacrlsthms;
neuper@37906
    83
length isacrlsthms;
neuper@37906
    84
"----- theorems used in isac's rulesets -----vvvvvvvvvvvvvvvvvvvvv";
neuper@37906
    85
print_depth 99; map #1 isacrlsthms; print_depth 3;
neuper@37906
    86
"----- theorems used in isac's rulesets -----^^^^^^^^^^^^^^^^^^^^^";
neuper@37906
    87
...*)
neuper@37906
    88
akargl@42181
    89
neuper@37906
    90
(!theory');
neuper@37906
    91
map #2 (!theory');
neuper@37936
    92
map (PureThy.all_thms_of o #2) (!theory');
neuper@37936
    93
val isacthms = (flat o (map (PureThy.all_thms_of o #2))) (!theory');
neuper@37906
    94
(*takes a few seconds...
neuper@37906
    95
val rlsthmsNOTisac = gen_diff eq_thmI (isacrlsthms, isacthms);
neuper@37906
    96
length rlsthmsNOTisac;
neuper@37906
    97
"----- theorems from rulesets NOT def. in isac -----vvvvvvvvvvvvvv";
neuper@37906
    98
print_depth 99; map #1 rlsthmsNOTisac; print_depth 3;
neuper@37906
    99
"----- theorems from rulesets NOT def. in isac -----^^^^^^^^^^^^^^";
neuper@37906
   100
...*)
neuper@37906
   101
neuper@37906
   102
"----- for 'fun make_isab_thm_thy'";
neuper@37936
   103
inter eq_thmI isacrlsthms (PureThy.all_thms_of (nth 1 ancestors));
neuper@37936
   104
inter eq_thmI;
neuper@37936
   105
(inter eq_thmI);
neuper@37936
   106
(inter eq_thmI) isacrlsthms;
neuper@37906
   107
(*takes a few seconds...
neuper@37936
   108
curry (inter eq_thmI) isacrlsthms (PureThy.all_thms_of (nth 9 ancestors));
neuper@37906
   109
neuper@37906
   110
val thy = (nth 52 ancestors);
neuper@37936
   111
val sec = ((inter eq_thmI) isacrlsthms o PureThy.all_thms_of) (nth 52 ancestors);
neuper@37936
   112
length (PureThy.all_thms_of (nth 9 ancestors));
neuper@37906
   113
length sec;
neuper@37906
   114
...*)
neuper@37906
   115
(*takes 1 minute...
neuper@37906
   116
print_depth 99; 
neuper@37936
   117
map ((inter eq_thmI) rlsthmsNOTisac o PureThy.all_thms_of) ancestors;
neuper@37906
   118
print_depth 3;
neuper@37906
   119
*)
neuper@37906
   120
neuper@37906
   121
(*takes some seconds...
neuper@37906
   122
val isab_thm_thy = (flat o (map (make_isab_thm_thy rlsthmsNOTisac)))
neuper@37906
   123
		       ((#ancestors o rep_theory) first_isac_thy);
neuper@37906
   124
print_depth 99; isab_thm_thy; print_depth 3;
neuper@37906
   125
*)
akargl@42181
   126
=== inhibit exn AK110725 =============================================================*)
neuper@42407
   127
============ inhibit exn WN120321 ==============================================*)
neuper@37906
   128
neuper@37906
   129
neuper@37906
   130
neuper@38061
   131
"----------- fun thy_containing_rls ---------------------";
neuper@38061
   132
"----------- fun thy_containing_rls ---------------------";
neuper@38061
   133
"----------- fun thy_containing_rls ---------------------";
neuper@42407
   134
infix mem; (*from Isabelle2002*)
neuper@42407
   135
fun x mem [] = false
neuper@42407
   136
  | x mem (y :: ys) = x = y orelse x mem ys;
neuper@42407
   137
neuper@38058
   138
val thy' = "Biegelinie";
neuper@42407
   139
    val dropthys =
neuper@42407
   140
      takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
neuper@42407
   141
        (rev (!theory'));
neuper@42407
   142
neuper@48891
   143
(*========== inhibit exn WN1130621 Isabelle2012-->13 !thehier! ====================
neuper@37906
   144
if length (!theory') <> length dropthys then ()
neuper@42407
   145
else error "thy_containing_rls changed 1";
neuper@37906
   146
neuper@42407
   147
		    val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys;
neuper@38061
   148
neuper@42407
   149
if dropthys' = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin"](*, "Biegelinie",..,"Test",.*)
neuper@42407
   150
then () else error "thy_containing_rls changed ancestors_rls";
neuper@42407
   151
neuper@42407
   152
"Isac" mem dropthys';
neuper@42407
   153
op mem ("Isac", dropthys');
neuper@37906
   154
(op mem) o swap;
neuper@42407
   155
((op mem) o swap) (dropthys', "Isac");
neuper@37906
   156
curry ((op mem) o swap);
neuper@42407
   157
curry ((op mem) o swap) dropthys' "Isac";
neuper@42407
   158
		val ancestors_rls = 
neuper@42407
   159
		  filter_out ((curry ((op mem) o swap) dropthys') o ((#1 o #2): rls'*(theory' * rls)->theory'))
neuper@42407
   160
		     (rev (!ruleset'));
neuper@37906
   161
neuper@42407
   162
take (10, map #1 ancestors_rls) = 
neuper@42407
   163
  ["expand_binomtest", "make_polytest", "rearrange_assoc", "ac_plus_times", "norm_equation", 
neuper@42407
   164
   "matches", "isolate_bdv", "isolate_root", "tval_rls", "Test_simplify"]; (*..all rls in each*)
neuper@42407
   165
neuper@42433
   166
(* WN120523 popped up again ?!?!?
neuper@42407
   167
if length (!ruleset') <> length ancestors_rls then ()
neuper@42407
   168
else error "rewtools.sml: diff.behav. in thy_containing_rls 2 ERRATICAL?";
neuper@42433
   169
*)
akargl@42181
   170
neuper@37906
   171
val rls' = "norm_Poly";
neuper@42407
   172
case assoc (ancestors_rls, rls') of
neuper@37926
   173
    SOME (thy', _) => thyID2theory' thy'
neuper@42407
   174
  | _ => error ("thy_containing_rls : rls '" ^ rls' ^
neuper@42407
   175
			  "' not in !rulset' und thy '" ^ thy' ^ "'");
neuper@37906
   176
neuper@38058
   177
if thy_containing_rls thy' rls' = ("IsacKnowledge", "Poly") then ()
neuper@42407
   178
else error "thy_containing_rls 3: changed with (Biegelinie, norm_Poly)";
neuper@42407
   179
neuper@42407
   180
"~~~~~ fun thy_containing_rls, args:"; val (thy', rls') = ("Biegelinie" ,"norm_Poly");
neuper@42407
   181
    val rls' = strip_thy rls'
neuper@42407
   182
    val thy' = thyID2theory' thy'
neuper@42407
   183
    val dropthys =
neuper@42407
   184
      takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
neuper@42407
   185
        (rev (!theory'));
neuper@42407
   186
neuper@42407
   187
map #1 dropthys = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin"]; (*= true WN120410*)
neuper@42407
   188
neuper@42407
   189
    val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys: string list;
neuper@42407
   190
		    val ancestors_rls = 
neuper@42407
   191
		      filter_out ((curry ((op mem) o swap) dropthys') o ((#1 o #2): rls'*(theory' * rls)->theory'))
neuper@42407
   192
		        (rev (!ruleset'));
neuper@42407
   193
		
neuper@42407
   194
case assoc (ancestors_rls, rls') of
neuper@42407
   195
  SOME ("Poly", Seq {id = "norm_Poly", ...}) => ()
neuper@42407
   196
| _ => error "thy_containing_rls changed 2";
neuper@48891
   197
============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
neuper@37906
   198
neuper@37906
   199
neuper@38061
   200
"----------- fun thy_containing_cal ---------------------";
neuper@38061
   201
"----------- fun thy_containing_cal ---------------------";
neuper@38061
   202
"----------- fun thy_containing_cal ---------------------";
neuper@38058
   203
val thy' = "Atools";
neuper@42407
   204
    val dropthys =
neuper@42407
   205
      takewhile [] (not o (curry op= thy') o (#1:theory' * theory -> theory'))
neuper@42407
   206
        (rev (!theory'));
neuper@42407
   207
neuper@37906
   208
length dropthys <> length (!theory');
neuper@42407
   209
neuper@42407
   210
    val dropthys' = map (get_thy o (#1 : (theory' * theory) -> theory')) dropthys;
neuper@42407
   211
neuper@48891
   212
(*========== inhibit exn WN1130621 Isabelle2012-->13 !thehier! ====================
neuper@42407
   213
if dropthys' = ["Isac", "Inverse_Z_Transform", "DiophantEq", "AlgEin", "Biegelinie",
neuper@42407
   214
  "Vect", "PolyMinus", "Frontend", "Partial_Fractions", "DiffApp", "Test", "EqSystem", "Integrate",
neuper@42407
   215
  "Diff", "LogExp", "Trig", "Calculus", "PolyEq", "RootRatEq", "RootRat", "RatEq", "RootEq",
neuper@42407
   216
  "LinEq", "Root", "Equation", "Rational", "Poly", "Simplify"] (*, "Atools", ..*)
neuper@42407
   217
then () else error "thy_containing_cal changed ancestors_rls for Atools";
neuper@37906
   218
neuper@37906
   219
(rev (!calclist'));
neuper@37906
   220
map #1 (rev (!calclist'));
neuper@37906
   221
map (#1 : calc -> string) (rev (!calclist'));
neuper@37906
   222
neuper@42407
   223
    val ancestors_cal =
neuper@42407
   224
      filter_out ((curry ((op mem) o swap) dropthys') o (#1 : calc -> string))
neuper@42407
   225
        (rev (!calclist'));
neuper@42407
   226
neuper@42409
   227
if thy_containing_cal "Biegelinie" "PLUS" = ("IsacKnowledge", "plus") 
neuper@42409
   228
                    (*WN120410: SHOULD BE = ("IsacKnowledge", "Atools")*)
neuper@42409
   229
then () else error "(wrong) thy_containing_cal 'Biegelinie' 'PLUS' changed";
neuper@48891
   230
============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
neuper@42407
   231
neuper@38061
   232
"----------- initContext Thy_ Integration-demo ----------";
neuper@38061
   233
"----------- initContext Thy_ Integration-demo ----------";
neuper@38061
   234
"----------- initContext Thy_ Integration-demo ----------";
neuper@37906
   235
states:=[];
neuper@37906
   236
CalcTree
neuper@37906
   237
[(["functionTerm (2 * x)","integrateBy x","antiDerivative FF"], 
neuper@38058
   238
  ("Integrate",["integrate","function"],
neuper@37906
   239
  ["diff","integration"]))];
neuper@37906
   240
Iterator 1;
neuper@37906
   241
moveActiveRoot 1;
neuper@37906
   242
autoCalculate 1 CompleteCalc;
neuper@37906
   243
interSteps 1 ([1],Res);
neuper@37906
   244
interSteps 1 ([1,1],Res);
neuper@37906
   245
val ((pt,p),_) = get_calc 1; show_pt pt;
neuper@37906
   246
if existpt' ([1,1,1], Frm) pt then ()
neuper@38031
   247
else error "integrate.sml: interSteps on Rewrite_Set_Inst 1";
neuper@37906
   248
initContext  1 Thy_ ([1,1,1], Frm);
neuper@37906
   249
neuper@38061
   250
"----------- initContext..Thy_, fun context_thm ---------";
neuper@38061
   251
"----------- initContext..Thy_, fun context_thm ---------";
neuper@38061
   252
"----------- initContext..Thy_, fun context_thm ---------";
neuper@41970
   253
states:=[]; (*start of calculation, return No.1*)
neuper@41970
   254
CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   255
  ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   256
   ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   257
Iterator 1; moveActiveRoot 1;
neuper@37906
   258
autoCalculate 1 CompleteCalc;
neuper@37906
   259
neuper@37906
   260
"----- no thy-context at result -----";
neuper@37906
   261
val p = ([], Res);
neuper@37906
   262
initContext 1 Thy_ p;
neuper@37906
   263
neuper@37906
   264
interSteps 1 ([2], Res);
neuper@37906
   265
interSteps 1 ([3,1], Res);
neuper@37906
   266
val ((pt,_),_) = get_calc 1; show_pt pt;
neuper@37906
   267
neuper@37906
   268
val p = ([2,4], Res);
neuper@37906
   269
val tac = Rewrite ("radd_left_commute","");
neuper@48892
   270
(*============ inhibit exn WN120321 ==============================================
neuper@37906
   271
initContext 1 Thy_ p;
neuper@37906
   272
(*Res->Res, Rewrite "radd_left_commute 1 + (-2 + x) = 0 -> -2 + (1 + x) = 0
neuper@37906
   273
  --- in initContext..Thy_ ---*)
neuper@37906
   274
val ContThm {thm,result,...} = context_thy (pt,p) tac;
neuper@48892
   275
(*WN130621: thm = "thy_isac_WN120320: AT Isa2009-2-->11 BROKEN": guh !!!!!!!!!!!!!!!!!!!!!!!!!*)
neuper@37906
   276
if thm = "thy_isac_Test-thm-radd_left_commute" 
neuper@37906
   277
   andalso term2str result = "-2 + (1 + x) = 0" then ()
neuper@38031
   278
else error"rewtools.sml initContext..Th_ thy_Test-thm-radd_left_commute";
neuper@37906
   279
akargl@42108
   280
neuper@37906
   281
val p = ([3,1,1], Frm);
neuper@37906
   282
val tac = Rewrite_Inst (["(bdv, x)"],("risolate_bdv_add",""));
neuper@37906
   283
initContext 1 Thy_ p;
neuper@37906
   284
(*Frm->Res, Rewrite_Inst "risolate_bdv_add"  -1 + x = 0 -> x = 0 + -1 * -1
neuper@37906
   285
  --- in initContext..Thy_ ---*)
neuper@37906
   286
val ContThmInst {thm,result,...} = context_thy (pt,p) tac;
neuper@37906
   287
if thm =  "thy_isac_Test-thm-risolate_bdv_add"
neuper@37906
   288
   andalso term2str result = "x = 0 + -1 * -1" then ()
neuper@38031
   289
else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
neuper@37906
   290
neuper@37906
   291
initContext 1 Thy_ ([2,5], Res);
neuper@37906
   292
(*Res->Res, Calculate "plus"  -2 + (1 + x) = 0 -> -1 + x = 0
neuper@37906
   293
  --- in initContext..Thy_ ---*)
neuper@37906
   294
neuper@37906
   295
neuper@38061
   296
"----------- initContext..Thy_, fun context_rls ---------";
neuper@38061
   297
"----------- initContext..Thy_, fun context_rls ---------";
neuper@38061
   298
"----------- initContext..Thy_, fun context_rls ---------";
neuper@37906
   299
(*using pt from above*)
neuper@37906
   300
val p = ([1], Res);
neuper@37906
   301
val tac = Rewrite_Set "Test_simplify";
neuper@37906
   302
initContext 1 Thy_ p;
neuper@37906
   303
(*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
neuper@37906
   304
  --- in initContext..Thy_ ---*)
neuper@37906
   305
val ContRls {rls,result,...} = context_thy (pt,p) tac;
neuper@37906
   306
if rls = "thy_isac_Test-rls-Test_simplify" 
neuper@37906
   307
   andalso term2str result = "-1 + x = 0" then ()
neuper@38031
   308
else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
neuper@37906
   309
neuper@37906
   310
val p = ([3,1], Frm);
neuper@37906
   311
val tac = Rewrite_Set_Inst (["(bdv, x)"],"isolate_bdv");
neuper@37906
   312
initContext 1 Thy_ p;
neuper@37906
   313
(*Frm->Res, Rewrite_Set_Inst "isolate_bdv" -1 + x = 0 ->  x = 0 + -1 * -1
neuper@37906
   314
  --- in initContext..Thy_ ---*)
neuper@37906
   315
val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
neuper@37906
   316
if rls =  "thy_isac_Test-rls-isolate_bdv"
neuper@37906
   317
   andalso term2str result = "x = 0 + -1 * -1" then ()
neuper@38031
   318
else error "rewtools.sml initContext..Th_ thy_Test-thm-risolate_bdv_add";
neuper@37906
   319
neuper@38061
   320
"----------- checkContext..Thy_, fun context_thy --------";
neuper@38061
   321
"----------- checkContext..Thy_, fun context_thy --------";
neuper@38061
   322
"----------- checkContext..Thy_, fun context_thy --------";
neuper@37906
   323
(*using pt from above*)
neuper@37906
   324
neuper@37906
   325
val p = ([2,4], Res);
neuper@37906
   326
val tac = Rewrite ("radd_left_commute","");
neuper@37906
   327
checkContext 1 p "thy_Test-thm-radd_left_commute";
neuper@37906
   328
(* radd_left_commute: 1 + (-2 + x) = 0 -> -2 + (1 + x) = 0
neuper@37906
   329
  --- in checkContext..Thy_ ---*)
neuper@37906
   330
val ContThm {thm,result,...} = context_thy (pt,p) tac;
neuper@37906
   331
if thm =  "thy_isac_Test-thm-radd_left_commute"
neuper@37906
   332
   andalso term2str result = "-2 + (1 + x) = 0" then ()
neuper@38031
   333
else error "rewtools.sml checkContext.._ thy_Test-thm-radd_left_commute";
neuper@37906
   334
neuper@37906
   335
val p = ([3,1,1], Frm);
neuper@37906
   336
val tac = Rewrite_Inst (["(bdv,x)"],("risolate_bdv_add",""));
neuper@37906
   337
checkContext 1 p "thy_Test-thm-risolate_bdv_add";
neuper@37906
   338
(* risolate_bdv_add:  -1 + x = 0 -> x = 0 + -1 * -1
neuper@37906
   339
  --- in checkContext..Thy_ ---*)
neuper@37906
   340
val ContThmInst {thm,result,...} = context_thy (pt,p) tac;
neuper@37906
   341
if thm =  "thy_isac_Test-thm-risolate_bdv_add"
neuper@37906
   342
   andalso term2str result = "x = 0 + -1 * -1" then ()
neuper@38031
   343
else error "rewtools.sml checkContext..T_ thy_Test-thm-risolate_bdv_add";
neuper@37906
   344
neuper@37906
   345
val p = ([2,5], Res);
neuper@37906
   346
val tac = Calculate "plus";
neuper@37906
   347
(*checkContext..Thy_ 1 ([2,5], Res);*)
neuper@37906
   348
(*FIXXXME #######################vvvvv kestoreID !!!!!!!!!!!!!!!!*)
neuper@37906
   349
checkContext 1 p ;
neuper@37906
   350
(* Calculate "plus"  -2 + (1 + x) = 0 -> -1 + x = 0
neuper@37906
   351
  --- in checkContext..Thy_ ---*)
neuper@37906
   352
neuper@38061
   353
"----------- checkContext..Thy_, fun context_rls --------";
neuper@38061
   354
"----------- checkContext..Thy_, fun context_rls --------";
neuper@38061
   355
"----------- checkContext..Thy_, fun context_rls --------";
neuper@37906
   356
(*using pt from above*)
neuper@37906
   357
show_pt pt;
neuper@37906
   358
neuper@37906
   359
val p = ([1], Res);
neuper@37906
   360
val tac = Rewrite_Set "Test_simplify";
neuper@37906
   361
checkContext 1 p "thy_isac_Test-rls-Test_simplify";
neuper@37906
   362
(*Res->Res, Rewrite_Set "Test_simplify" x + 1 + -1 * 2 = 0 -> -1 + x = 0
neuper@37906
   363
  --- in checkContext..Thy_ ---*)
neuper@37906
   364
val ContRls {rls,result,...} = context_thy (pt,p) tac;
neuper@37906
   365
if rls = "thy_isac_Test-rls-Test_simplify" 
neuper@37906
   366
   andalso term2str result = "-1 + x = 0" then ()
neuper@38031
   367
else error "rewtools.sml checkContext..Thy_ thy_Test-rls-Test_simplify";
neuper@37906
   368
neuper@37906
   369
val p = ([3,1], Frm);
neuper@37906
   370
val tac = Rewrite_Set_Inst (["(bdv, x)"],"isolate_bdv");
neuper@37906
   371
checkContext 1 p "thy_Test-rls-isolate_bdv";
neuper@37906
   372
val ContRlsInst {rls,result,...} = context_thy (pt,p) tac;
neuper@37906
   373
if rls = "thy_isac_Test-rls-isolate_bdv" 
neuper@37906
   374
   andalso term2str result = "x = 0 + -1 * -1" then ()
neuper@38031
   375
else error "rewtools.sml checkContext..Thy_ thy_Test-thm-isolate_bdv";
neuper@37906
   376
neuper@38061
   377
"----------- checkContext..Thy_ on last formula ---------"; 
neuper@38061
   378
"----------- checkContext..Thy_ on last formula ---------"; 
neuper@38061
   379
"----------- checkContext..Thy_ on last formula ---------"; 
neuper@41970
   380
states:=[]; (*start of calculation, return No.1*)
neuper@41970
   381
CalcTree [(["equality (x+1=(2::real))", "solveFor x","solutions L"], 
neuper@41970
   382
  ("Test", ["sqroot-test","univariate","equation","test"],
neuper@37906
   383
   ["Test","squ-equ-test-subpbl1"]))];
neuper@37906
   384
Iterator 1; moveActiveRoot 1;
neuper@37906
   385
neuper@37906
   386
autoCalculate 1 CompleteCalcHead;
neuper@37906
   387
autoCalculate 1 (Step 1);
neuper@37906
   388
val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
neuper@37906
   389
initContext 1 Thy_ ([1], Frm);
neuper@37906
   390
checkContext 1 ([1], Frm) "thy_isac_Test-thm-radd_left_commute";
neuper@37906
   391
neuper@37906
   392
autoCalculate 1 (Step 1);
neuper@37906
   393
val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
neuper@37906
   394
initContext 1 Thy_ ([1], Res);
neuper@37906
   395
checkContext 1 ([1], Res) "thy_isac_Test-rls-Test_simplify";
neuper@37906
   396
neuper@48892
   397
============ inhibit exn WN1130621 Isabelle2012-->13 !thehier! ==================*)
neuper@48892
   398
neuper@37906
   399
neuper@38061
   400
"----------- fun guh2theID ------------------------------";
neuper@38061
   401
"----------- fun guh2theID ------------------------------";
neuper@38061
   402
"----------- fun guh2theID ------------------------------";
akargl@42181
   403
neuper@37906
   404
val guh = "thy_scri_ListG-thm-zip_Nil";
neuper@52101
   405
print_depth 3; (*999*)
akargl@42181
   406
take_fromto 1 4 (Symbol.explode guh);
akargl@42181
   407
take_fromto 5 9 (Symbol.explode guh);
akargl@42181
   408
val rest = takerest (9,(Symbol.explode guh)); 
neuper@37906
   409
neuper@37906
   410
separate "-" rest;
neuper@37906
   411
space_implode "-" rest;
neuper@37906
   412
commas rest;
neuper@37906
   413
neuper@37906
   414
val delim = "-";
neuper@37906
   415
val thyID = takewhile [] (not o (curry op= delim)) rest;
neuper@37906
   416
val rest' = dropuntil (curry op= delim) rest;
neuper@37906
   417
val setc = take_fromto 1 5 rest';
neuper@37906
   418
val xstr = takerest (5, rest');
neuper@37906
   419
neuper@37906
   420
if guh2theID guh = ["IsacScripts", "ListG", "Theorems", "zip_Nil"] then ()
neuper@38031
   421
else error "rewtools.sml: guh2theID thy_scri_ListG-thm-zip_Nil changed";
neuper@37906
   422
neuper@37906
   423
neuper@38061
   424
"----------- debugging on Tests/solve_linear_as_rootpbl -";
neuper@38061
   425
"----------- debugging on Tests/solve_linear_as_rootpbl -";
neuper@38061
   426
"----------- debugging on Tests/solve_linear_as_rootpbl -";
akargl@42108
   427
"----- initContext -----";
neuper@37906
   428
states:=[];
neuper@37906
   429
CalcTree 
neuper@42124
   430
    [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
neuper@38058
   431
      ("Test",
neuper@37906
   432
       ["linear","univariate","equation","test"],
neuper@37906
   433
       ["Test","solve_linear"]))];
neuper@37906
   434
Iterator 1; moveActiveRoot 1;
neuper@37906
   435
autoCalculate 1 CompleteCalcHead;
neuper@37906
   436
neuper@37906
   437
autoCalculate 1 (Step 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
neuper@37906
   438
if is_curr_endof_calc pt ([1],Frm) then ()
neuper@38031
   439
else error "rewtools.sml is_curr_endof_calc ([1],Frm)";
neuper@37906
   440
neuper@37906
   441
autoCalculate 1 (Step 1); val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
akargl@42125
   442
neuper@37906
   443
if not (is_curr_endof_calc pt ([1],Frm)) then ()
neuper@38031
   444
else error "rewtools.sml is_curr_endof_calc ([1],Frm) not";
neuper@37906
   445
if is_curr_endof_calc pt ([1],Res) then ()
neuper@38031
   446
else error "rewtools.sml is_curr_endof_calc ([1],Res)";
neuper@37906
   447
neuper@37906
   448
initContext 1 Thy_ ([1],Res);
neuper@37906
   449
neuper@37906
   450
"----- checkContext -----";
neuper@37906
   451
states:=[];
neuper@37906
   452
CalcTree 
neuper@42124
   453
    [(["equality (1+-1*2+x=(0::real))", "solveFor x", "solutions L"],
neuper@38058
   454
      ("Test",
neuper@37906
   455
       ["linear","univariate","equation","test"],
neuper@37906
   456
       ["Test","solve_linear"]))];
neuper@37906
   457
Iterator 1; moveActiveRoot 1;
neuper@37906
   458
autoCalculate 1 CompleteCalc;
neuper@37906
   459
interSteps 1 ([1],Res);
akargl@42108
   460
neuper@37906
   461
val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
neuper@37906
   462
checkContext 1 ([1],Res) "thy_isac_Test-rls-Test_simplify";
neuper@37906
   463
neuper@37906
   464
interSteps 1 ([2],Res);
neuper@37906
   465
val (ptp as (pt,p), tacis) = get_calc 1; show_pt pt;
neuper@37906
   466
neuper@37906
   467
checkContext 1 ([2,1],Res) "thy_isac_Test-rls-Test_simplify";
neuper@37906
   468
checkContext 1 ([2,2],Res) "thy_isac_Test-rls-Test_simplify";
neuper@37906
   469
akargl@42125
   470
neuper@38061
   471
"----------- fun string_of_thmI for_[.]_) ---------------";
neuper@38061
   472
"----------- fun string_of_thmI for_[.]_) ---------------";
neuper@38061
   473
"----------- fun string_of_thmI for_[.]_) ---------------";
neuper@37906
   474
"----- these work ?!?";
akargl@42181
   475
(*========== inhibit exn 110718 ================================================
akargl@42181
   476
(* ERROR: constructor real_minus_eq_cancel has not been declared *)
neuper@37906
   477
val th = sym_thm real_minus_eq_cancel;
neuper@37906
   478
val Th = sym_Thm (Thm ("real_minus_eq_cancel", real_minus_eq_cancel));
akargl@42181
   479
val th'= mk_thm ( @{theory "Isac"} ) ((de_quote o string_of_thm) real_minus_eq_cancel);
akargl@42181
   480
val th'= mk_thm Biegelinie.thy((de_quote o string_of_thm) real_minus_eq_cancel);
neuper@37906
   481
neuper@37906
   482
"----- DIFFERENCE TO ABOVE ?!?: this is still ok, when called in next_tac...";
neuper@37906
   483
val ((pt,(p,p_)), _) = get_calc 1; show_pt pt;
neuper@37906
   484
val Appl (Rewrite' (_,_,_,_,thm',_,_)) =
neuper@37906
   485
    applicable_in (p,p_) pt (Rewrite ("sym_real_minus_eq_cancel",""));
neuper@37906
   486
"- compose stac as done in | appy (*leaf*) by handle_leaf";
akargl@42108
   487
neuper@37906
   488
val (th, sr, E, a, v, t) = 
neuper@38058
   489
    ("Biegelinie", 
neuper@37906
   490
     (#srls o get_met) ["IntegrierenUndKonstanteBestimmen"],
neuper@37906
   491
     [(str2term "q__::bool", str2term "q x = q_0")], 
neuper@37926
   492
     SOME (str2term "q x = q_0"),
neuper@37906
   493
     str2term "q__::bool", 
neuper@37906
   494
     str2term "(Rewrite sym_real_minus_eq_cancel False) (q__::bool)");
neuper@37906
   495
val (a', STac stac) = handle_leaf "next  " th sr E a v t;
neuper@37906
   496
term2str stac;
neuper@37906
   497
"--- but this \"m\" is already corrupted";
neuper@37906
   498
val (m,_) = stac2tac_ EmptyPtree (assoc_thy th) stac;
neuper@37906
   499
"- because in assoc_thm'...";
neuper@37906
   500
val (thy, (thmid, ct')) = (Biegelinie.thy, ("sym_real_minus_eq_cancel",""));
neuper@37906
   501
val "s"::"y"::"m"::"_"::id = explode thmid;
neuper@37969
   502
((num_str o (get_thm thy)) (implode id)) RS sym;
neuper@37906
   503
((get_thm thy) (implode id)) RS sym;
neuper@37906
   504
"... this creates [.]";
neuper@37906
   505
((get_thm thy) (implode id));
neuper@37906
   506
"... while this has _NO_ [.]";
neuper@37906
   507
neuper@37906
   508
"----- thus we repair the [.] in string_of_thmI...";
neuper@37969
   509
val thm = ((num_str o (get_thm thy)) (implode id)) RS sym;
neuper@37906
   510
if string_of_thmI thm = "(?b1 = ?a1) = (- ?b1 = - ?a1)" then ()
neuper@38031
   511
else error ("rewtools.sml: string_of_thmI " ^ string_of_thm thm ^
neuper@37906
   512
		  " = " ^ string_of_thmI thm);
akargl@42108
   513
========== inhibit exn 110718 ================================================*)
neuper@37906
   514
neuper@38061
   515
"----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
neuper@38061
   516
"----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
neuper@38061
   517
"----------- (sym_real_minus_eq_cancel, (?b1 = ?a1) ..._[";
neuper@37906
   518
states:=[];
neuper@37906
   519
CalcTree [(["Traegerlaenge L","Streckenlast q_0","Biegelinie y",
neuper@37906
   520
	     "RandbedingungenBiegung [y 0 = 0, y L = 0]",
neuper@37906
   521
	     "RandbedingungenMoment [M_b 0 = 0, M_b L = 0]",
neuper@37906
   522
	     "FunktionsVariable x"],
neuper@38058
   523
	    ("Biegelinie",
neuper@37906
   524
	     ["MomentBestimmte","Biegelinien"],
neuper@37906
   525
	     ["IntegrierenUndKonstanteBestimmen"]))];
neuper@37906
   526
moveActiveRoot 1;
neuper@37906
   527
autoCalculate 1 CompleteCalcHead;
neuper@37906
   528
autoCalculate 1 (Step 1) (*Apply_Method*);
neuper@37906
   529
autoCalculate 1 (Step 1) (*->GENERATED ([1], Frm)*);
akargl@42108
   530
(*========== inhibit exn 110718 ================================================
akargl@42108
   531
neuper@37906
   532
"--- this was corrupted before 'fun string_of_thmI'";
neuper@37906
   533
val ((pt,(p,p_)), _) = get_calc 1; show_pt pt;
neuper@37906
   534
if get_obj g_tac pt p = Rewrite ("sym_real_minus_eq_cancel", 
neuper@37906
   535
				 "(?b1 = ?a1) = (- ?b1 = - ?a1)") then ()
neuper@38031
   536
else error "rewtools.sml: string_of_thmI ?!?";
neuper@37906
   537
neuper@37906
   538
getTactic 1 ([1],Frm);
neuper@38061
   539
"----------- fun filter_appl_rews -----------------------";
neuper@38061
   540
"----------- fun filter_appl_rews -----------------------";
neuper@38061
   541
"----------- fun filter_appl_rews -----------------------";
neuper@37906
   542
val f = str2term "a + z + 2*a + 3*z + 5 + 6";
neuper@38050
   543
val thy = assoc_thy "Isac";
neuper@37906
   544
val subst = [(*TODO.WN071231 test Rewrite_Inst*)];
neuper@37906
   545
val rls = Test_simplify;
neuper@37906
   546
(* val rls = rls_p_33;      filter_appl_rews  ---> length 2
neuper@37906
   547
   val rls = norm_Poly;     filter_appl_rews  ---> length 1
neuper@37906
   548
   *)
neuper@37906
   549
if filter_appl_rews thy subst f rls =
neuper@37906
   550
   [Rewrite ("radd_commute", "?m + ?n = ?n + ?m"),
neuper@37906
   551
    Rewrite ("radd_assoc", "?m + ?n + ?k = ?m + (?n + ?k)"),
neuper@37906
   552
    Calculate "plus"] then () 
neuper@38031
   553
else error "rewtools.sml filter_appl_rews a + z + 2*a + 3*z + 5 + 6";
akargl@42108
   554
============ inhibit exn 110718 ==============================================*)
neuper@37906
   555
neuper@37906
   556
neuper@38061
   557
"----------- fun is_contained_in ------------------------";
neuper@38061
   558
"----------- fun is_contained_in ------------------------";
neuper@38061
   559
"----------- fun is_contained_in ------------------------";
neuper@37969
   560
val r1 = Thm ("real_diff_minus",num_str @{thm real_diff_minus});
neuper@37906
   561
if contains_rule r1 Test_simplify then ()
neuper@38031
   562
else error "rewtools.sml contains_rule Thm";
neuper@37906
   563
neuper@38014
   564
val r1 = Calc ("Groups.plus_class.plus", eval_binop "#add_");
neuper@37906
   565
if contains_rule r1 Test_simplify then ()
neuper@38031
   566
else error "rewtools.sml contains_rule Calc";
neuper@37906
   567
neuper@38014
   568
val r1 = Calc ("Groups.minus_class.minus", eval_binop "#add_");
neuper@37906
   569
if not (contains_rule r1 Test_simplify) then ()
neuper@38031
   570
else error "rewtools.sml contains_rule Calc";
neuper@42400
   571
neuper@42400
   572
neuper@42433
   573
"-------- build fun get_bdv_subst --------------------------------";
neuper@42433
   574
"-------- build fun get_bdv_subst --------------------------------";
neuper@42433
   575
"-------- build fun get_bdv_subst --------------------------------";
neuper@48790
   576
val {scr = Prog prog, ...} = get_met ["diff", "differentiate_on_R"];
neuper@42433
   577
val env = [(str2term "v_v", str2term "x")];
neuper@42433
   578
subst2str env = "[\"\n(v_v, x)\"]";
neuper@42433
   579
neuper@42433
   580
"~~~~~ fun get_bdv_subst, args:"; val (prog, env) = (prog, env);
neuper@42433
   581
    fun scan (Const _) = NONE
neuper@42433
   582
      | scan (Free _) = NONE
neuper@42433
   583
      | scan (Var _) = NONE
neuper@42433
   584
      | scan (Bound _) = NONE
neuper@42433
   585
      | scan (t as Const ("List.list.Cons", _) $
neuper@42433
   586
         (Const ("Product_Type.Pair", _) $ Free (str, _) $ _) $ _) =
neuper@42433
   587
           if is_bdv_subst t then SOME t else NONE
neuper@42433
   588
      | scan (Abs (_, _, body)) = scan body
neuper@42433
   589
      | scan (t1 $ t2) =
neuper@42433
   590
          case scan t1 of
neuper@42433
   591
            NONE => scan t2
neuper@42433
   592
          | SOME subst => SOME subst
neuper@42433
   593
neuper@42433
   594
val SOME tm = scan prog;
neuper@42433
   595
val subst = tm |> subst_atomic env |> isalist2list |> map isapair2pair: subst;
neuper@42433
   596
if term2str tm = "[(bdv, v_v)]" then () else error "get_bdv_subst changed 1";
neuper@42433
   597
neuper@42433
   598
if subst2subs subst = ["(bdv, x)"] then () else error "get_bdv_subst changed 2";
neuper@42433
   599
neuper@42433
   600
case get_bdv_subst prog env of
neuper@42433
   601
  (SOME ["(bdv, x)"], [(Free ("bdv", _), Free ("x", _))]: subst) => ()
neuper@42433
   602
| _ => error "get_bdv_subst changed 3";
neuper@42433
   603
neuper@42433
   604
val (SOME subs, _) = get_bdv_subst prog env;
neuper@42433
   605
Rewrite_Inst (subs, ("diff_sin_chain","")) (*<<<----- this is the intended usage*)
neuper@42433
   606