src/smltest/IsacKnowledge/polyminus.sml
author wneuper
Thu, 27 Dec 2007 15:20:44 +0100
branchstart-work-070517
changeset 263 cf52bc3a36cb
parent 260 0882b33b1b61
child 264 9e1001a89c66
permissions -rw-r--r--
for PolyMinus at Sch"arding, intermediate, tests ok
wneuper@259
     1
(* tests on PolyMinus
wneuper@259
     2
   author: Walther Neuper
wneuper@259
     3
   WN071207,
wneuper@259
     4
   (c) due to copyright terms
wneuper@259
     5
wneuper@259
     6
use"../smltest/IsacKnowledge/polyminus.sml";
wneuper@259
     7
use"polyminus.sml";
wneuper@259
     8
*)
wneuper@259
     9
val thy = EqSystem.thy;
wneuper@259
    10
wneuper@259
    11
"-----------------------------------------------------------------";
wneuper@259
    12
"table of contents -----------------------------------------------";
wneuper@259
    13
"-----------------------------------------------------------------";
wneuper@259
    14
"----------- watch order_add_mult  -------------------------------";
wneuper@259
    15
"----------- build predicate for +- ordering ---------------------";
wneuper@259
    16
"-----------------------------------------------------------------";
wneuper@259
    17
"-----------------------------------------------------------------";
wneuper@259
    18
"-----------------------------------------------------------------";
wneuper@259
    19
wneuper@259
    20
wneuper@259
    21
"----------- watch order_add_mult  -------------------------------";
wneuper@259
    22
"----------- watch order_add_mult  -------------------------------";
wneuper@259
    23
"----------- watch order_add_mult  -------------------------------";
wneuper@259
    24
"----- with these simple variables it works...";
wneuper@259
    25
trace_rewrite:=true;
wneuper@259
    26
val t = str2term "((a + d) + c) + b";
wneuper@259
    27
val Some (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
wneuper@259
    28
if term2str t = "a + (b + (c + d))" then ()
wneuper@259
    29
else raise error "polyminus.sml 1 watch order_add_mult";
wneuper@259
    30
trace_rewrite:=false;
wneuper@259
    31
wneuper@259
    32
"----- the same stepwise...";
wneuper@259
    33
val od = ord_make_polynomial true Poly.thy;
wneuper@259
    34
val t = str2term "((a + d) + c) + b";
wneuper@259
    35
"((a + d) + c) + b"; 
wneuper@259
    36
val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t; term2str t;
wneuper@259
    37
"b + ((a + d) + c)";
wneuper@259
    38
val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t; term2str t;
wneuper@259
    39
"b + (c + (a + d))";
wneuper@259
    40
val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
wneuper@259
    41
"b + (a + (c + d))";
wneuper@259
    42
val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
wneuper@259
    43
"a + (b + (c + d))";
wneuper@259
    44
if term2str t = "a + (b + (c + d))" then ()
wneuper@259
    45
else raise error "polyminus.sml 2 watch order_add_mult";
wneuper@259
    46
wneuper@263
    47
"----- if parentheses are right, left_commute is (almost) sufficient...";
wneuper@259
    48
val t = str2term "a + (d + (c + b))";
wneuper@259
    49
"a + (d + (c + b))";
wneuper@259
    50
val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
wneuper@259
    51
"a + (c + (d + b))";
wneuper@259
    52
val Some (t,_) = rewrite_ thy od e_rls true real_add_commute t;term2str t;
wneuper@259
    53
"a + (c + (b + d))";
wneuper@259
    54
val Some (t,_) = rewrite_ thy od e_rls true real_add_left_commute t;term2str t;
wneuper@259
    55
"a + (b + (c + d))";
wneuper@259
    56
wneuper@259
    57
"----- but we do not want the parentheses at right; thus: cond.rew.";
wneuper@259
    58
"WN0712707 complicated monomials do not yet work ...";
wneuper@259
    59
val t = str2term "((5*a + 4*d) + 3*c) + 2*b";
wneuper@259
    60
val Some (t,_) = rewrite_set_ thy false order_add_mult t; term2str t;
wneuper@263
    61
if term2str t = "2 * b + (3 * c + (4 * d + 5 * a))" then ()
wneuper@263
    62
else raise error "polyminus.sml: order_add_mult changed";
wneuper@259
    63
wneuper@263
    64
"----- here we see rew_sub going into subterm with ord.rew....";
wneuper@263
    65
val od = ord_make_polynomial false Poly.thy;
wneuper@263
    66
val t = str2term "b + a + c + d";
wneuper@263
    67
val Some (t,_) = rewrite_ thy od e_rls false real_add_commute t; term2str t;
wneuper@263
    68
val Some (t,_) = rewrite_ thy od e_rls false real_add_commute t; term2str t;
wneuper@263
    69
(*@@@ rew_sub gosub: t = d + (b + a + c)
wneuper@263
    70
  @@@ rew_sub begin: t = b + a + c*)
wneuper@263
    71
wneuper@263
    72
(*#####################################################################
wneuper@259
    73
wneuper@259
    74
"----------- build predicate for +- ordering ---------------------";
wneuper@259
    75
"----------- build predicate for +- ordering ---------------------";
wneuper@259
    76
"----------- build predicate for +- ordering ---------------------";
wneuper@259
    77
"a" < "b";
wneuper@259
    78
"ba" < "ab";
wneuper@263
    79
"123" < "a"; (*unused due to ---vvv*)
wneuper@263
    80
"12" < "3"; (*true !!!*)
wneuper@259
    81
wneuper@263
    82
" a kleiner b ==> (b + a) = (a + b)";
wneuper@259
    83
str2term "aaa";
wneuper@259
    84
str2term "222 * aaa";
wneuper@259
    85
wneuper@263
    86
case eval_kleiner 0 0 (str2term "12 kleiner 9") 0 of
wneuper@263
    87
    Some ("12 kleiner 9 = False", _) => ()
wneuper@263
    88
  | _ => raise error "polyminus.sml: 12 kleiner 9 = False";
wneuper@263
    89
wneuper@263
    90
case eval_kleiner 0 0 (str2term "a kleiner b") 0 of
wneuper@263
    91
    Some ("a kleiner b = True", _) => ()
wneuper@263
    92
  | _ => raise error "polyminus.sml: a kleiner b = True";
wneuper@263
    93
wneuper@263
    94
"----- test rewrite_, rewrite_set_";
wneuper@263
    95
val od = dummy_ord;
wneuper@263
    96
val erls = erls_ordne_alphabetisch;
wneuper@263
    97
val t = str2term "b + a";
wneuper@263
    98
"############################################";
wneuper@263
    99
val Some (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
wneuper@263
   100
if term2str t = "a + b" then ()
wneuper@263
   101
else raise error "polyminus.sml: ordne_alphabetisch1 b + a";
wneuper@263
   102
wneuper@259
   103
trace_rewrite:=true;
wneuper@259
   104
val t = str2term "b + a";
wneuper@259
   105
val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
wneuper@263
   106
if term2str t = "a + b" then ()
wneuper@263
   107
else raise error "polyminus.sml: ordne_alphabetisch a + b";
wneuper@259
   108
wneuper@259
   109
val t = str2term "2*b + a";
wneuper@259
   110
val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
wneuper@263
   111
if term2str t = "a + 2 * b" then ()
wneuper@263
   112
else raise error "polyminus.sml: ordne_alphabetisch a + 2 * b";
wneuper@259
   113
wneuper@259
   114
val t = str2term "a + c + b";
wneuper@259
   115
val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
wneuper@263
   116
if term2str t = "a + b + c" then ()
wneuper@263
   117
else raise error "polyminus.sml: ordne_alphabetisch a + b + c";
wneuper@263
   118
wneuper@263
   119
"----- rewrite goes into subterms";
wneuper@263
   120
val t = str2term "a + c + b + d";
wneuper@263
   121
val Some (t,_) = rewrite_ thy od erls false tausche_plus_plus t; term2str t;
wneuper@263
   122
if term2str t = "a + b + c + d" then ()
wneuper@263
   123
else raise error "polyminus.sml: ordne_alphabetisch1 a + b + c + d";
wneuper@259
   124
wneuper@259
   125
val t = str2term "a + c + d + b";
wneuper@259
   126
val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
wneuper@263
   127
if term2str t = "a + b + c + d" then ()
wneuper@263
   128
else raise error "polyminus.sml: ordne_alphabetisch2 a + b + c + d";
wneuper@260
   129
wneuper@260
   130
"----- here we see rew_sub going into subterm with cond.rew....";
wneuper@260
   131
val t = str2term "b + a + c + d";
wneuper@260
   132
val Some (t,_) = rewrite_ thy od erls false tausche_plus t; term2str t;
wneuper@263
   133
if term2str t = "a + b + c + d" then ()
wneuper@263
   134
else raise error "polyminus.sml: ordne_alphabetisch3 a + b + c + d";
wneuper@260
   135
wneuper@263
   136
"----- compile rls for the most complicated terms";
wneuper@259
   137
val t = str2term "5*e + 6*f - 8*g - 9 - 7*e - 4*f + 10*g + 12";
wneuper@259
   138
"5 * e + 6 * f - 8 * g - 9 - 7 * e - 4 * f + 10 * g + 12";
wneuper@259
   139
val Some (t,_) = rewrite_set_ thy false ordne_alphabetisch t; term2str t;
wneuper@263
   140
"5 * e - 8 * g + 6 * f - 9 - 7 * e + 10 * g - 4 * f + 12";
wneuper@263
   141
wneuper@263
   142
wneuper@263
   143
trace_rewrite:=false;
wneuper@263
   144
(*
wneuper@263
   145
use"../smltest/IsacKnowledge/polyminus.sml";
wneuper@263
   146
use"polyminus.sml";
wneuper@263
   147
  *)
wneuper@263
   148
wneuper@263
   149
#####################################################################*)