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