test/Tools/isac/Knowledge/termorder.sml
author Walther Neuper <neuper@ist.tugraz.at>
Tue, 28 Sep 2010 09:06:56 +0200
branchisac-update-Isa09-2
changeset 38031 460c24a6a6ba
parent 37991 028442673981
child 38050 4c52ad406c20
permissions -rw-r--r--
tuned error and writeln

# raise error --> error
# writeln in atomtyp, atomty, atomt and xmlsrc
     1  (* tests on rewrite orders
     2     author Matthias Goldgruber 2003
     3 
     4     WN0509 do not use this file anymore, since orders require thy:
     5     do tests in the smltest/IsacKnowledge/file.sml 
     6     where file.ML defines the respective order !
     7 
     8 use"../smltest/IsacKnowledge/termorder.sml";
     9 *)
    10 
    11 
    12   (*MK die ersten Tests*)
    13   val substa = [(e_term, (term_of o the o (parse thy)) "a")];
    14   val substb = [(e_term, (term_of o the o (parse thy)) "b")];
    15   val substx = [(e_term, (term_of o the o (parse thy)) "x")];
    16 
    17   val x1 = (term_of o the o (parse thy)) "a + b + x";
    18   val x2 = (term_of o the o (parse thy)) "a + x + b";
    19   val x3 = (term_of o the o (parse thy)) "a + x + b";
    20   val x4 = (term_of o the o (parse thy)) "x + a + b";
    21 
    22 if ord_make_polynomial_in true thy substx (x1,x2) = true(*LESS *) then ()
    23 else error "termorder.sml diff.behav ord_make_polynomial_in #1";
    24  
    25 if ord_make_polynomial_in true thy substa (x1,x2) = true(*LESS *) then ()
    26 else error "termorder.sml diff.behav ord_make_polynomial_in #2";
    27 
    28 if ord_make_polynomial_in true thy substb (x1,x2) = false(*GREATER*) then ()
    29 else error "termorder.sml diff.behav ord_make_polynomial_in #3";
    30 
    31   val aa = (term_of o the o (parse thy)) "-1 * a * x";
    32   val bb = (term_of o the o (parse thy)) "x^^^3";
    33   ord_make_polynomial_in true thy substx (aa, bb);
    34   true; (* => LESS *) 
    35   
    36   val aa = (term_of o the o (parse thy)) "-1 * a * x";
    37   val bb = (term_of o the o (parse thy)) "x^^^3";
    38   ord_make_polynomial_in true thy substa (aa, bb);
    39   false; (* => GREATER *)
    40 
    41   (*und nach dem Re-engineering der Termorders in den 'rulesets' 
    42     kannst Du die 'gr"osste' Variable frei w"ahlen: *)
    43   val bdv= (term_of o the o (parse thy)) "bdv";
    44   val x  = (term_of o the o (parse thy)) "x";
    45   val a  = (term_of o the o (parse thy)) "a";
    46   val b  = (term_of o the o (parse thy)) "b";
    47   val SOME (t',_) = 
    48       rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in x2;
    49 if term2str t' = "b + x + a" then ()
    50 else error "termorder.sml diff.behav ord_make_polynomial_in #11";
    51 
    52   val NONE = 
    53       rewrite_set_inst_ thy false [(bdv,b)] make_polynomial_in x2;
    54   term2str t';
    55   "a + x + b";
    56 
    57   val SOME (t',_) = 
    58       rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in x2;
    59 if term2str t' = "a + b + x" then ()
    60 else error "termorder.sml diff.behav ord_make_polynomial_in #13";
    61 
    62 
    63 
    64   val ppp' = "-6 + -5*x + x^^^3 + -1*x^^^2 + -1*x^^^3 + -14*x^^^2";
    65   val ppp  = (term_of o the o (parse thy)) ppp';
    66   val SOME (t',_) = 
    67       rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ppp;
    68 (*MG 2003...
    69   term2str t';
    70   "(-6) + (-5 * x + (-15 * x ^^^ 2))";*)
    71 if term2str t' = "-6 + -5 * x + -15 * x ^^^ 2 + 0" then ()
    72 else error "termorder.sml diff.behav ord_make_polynomial_in #14";
    73 
    74   val SOME (t',_) = 
    75       rewrite_set_inst "Isac"false [("bdv","x")] "make_polynomial_in" ppp';
    76 (*MG 2003...
    77   "(-6) + (-5 * x + (-15) * x ^^^ 2)";*)
    78 if t' = "-6 + -5 * x + -15 * x ^^^ 2 + 0" then ()
    79 else error "termorder.sml diff.behav ord_make_polynomial_in #15";
    80 
    81   val ttt' = "(3*x + 5)/18";
    82   val ttt = (term_of o the o (parse thy)) ttt';
    83   val SOME (uuu,_) = 
    84       rewrite_set_inst_ thy false [(bdv,x)] make_polynomial_in ttt;
    85 if term2str uuu = "(5 + 3 * x) / 18" then ()
    86 else error "termorder.sml diff.behav ord_make_polynomial_in #16";
    87 
    88   val SOME (uuu,_) = 
    89       rewrite_set_ thy false make_polynomial ttt;
    90 if term2str uuu = "(5 + 3 * x) / 18" then ()
    91 else error "termorder.sml diff.behav ord_make_polynomial_in #16";
    92 
    93 
    94 
    95 
    96 (*-----------28.2.03: war nicht upgedatet (und ausgeklammert in ROOT.ML
    97 
    98   (*Aufgabe zum Einstieg in die Arbeit...*)
    99   val t = (term_of o the o (parse thy)) "a*b - (a+b)*x + x^^^2 = 0";
   100   (*ein 'ruleset' aus Poly.ML wird angewandt...*)
   101   val SOME (t,_) = rewrite_set_ thy Poly_erls false make_polynomial t;
   102   term2str t;
   103   "a * b + (-1 * (a * x) + (-1 * (b * x) + x ^^^ 2)) = 0";
   104   val SOME (t,_) = 
   105       rewrite_set_inst_ thy Poly_erls false [("bdv","a")] make_polynomial_in t;
   106   term2str t;
   107   "x ^^^ 2 + (-1 * (b * x) + (-1 * (x * a) + b * a)) = 0";
   108 (* bei Verwendung von "size_of-term" nach MG :*)
   109 (*"x ^^^ 2 + (-1 * (b * x) + (b * a + -1 * (x * a))) = 0"  !!! *)
   110 
   111   (*wir holen 'a' wieder aus der Klammerung heraus...*)
   112   val SOME (t,_) = rewrite_set_ thy Poly_erls false discard_parentheses t;
   113   term2str t;
   114    "x ^^^ 2 + -1 * b * x + -1 * x * a + b * a = 0";
   115 (* "x ^^^ 2 + -1 * b * x + b * a + -1 * x * a = 0" !!! *)
   116 
   117   val SOME (t,_) =
   118       rewrite_set_inst_ thy Poly_erls false [("bdv","a")] make_polynomial_in t;
   119   term2str t;
   120   "x ^^^ 2 + (-1 * (b * x) + a * (b + -1 * x)) = 0"; 
   121   (*da sind wir fast am Ziel: make_polynomial_in 'a' sollte ergeben
   122   "x ^^^ 2 + (-1 * (b * x)) + (b + -1 * x) * a = 0"*)
   123 
   124   (*das rewriting l"asst sich beobachten mit
   125   trace_rewrite:=true;
   126   *)
   127 
   128 
   129 
   130 "------15.11.02 --------------------------";
   131   val t = (term_of o the o (parse thy)) "1 + a * x + b * x";
   132   val bdv = (term_of o the o (parse thy)) "bdv";
   133   val a = (term_of o the o (parse thy)) "a";
   134  
   135  trace_rewrite:=true;
   136  (* Anwenden einer Regelmenge aus Termorder.ML: *)
   137  val SOME (t,_) =
   138      rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in t;
   139  term2str t;
   140  val SOME (t,_) =
   141      rewrite_set_ thy false discard_parentheses t;
   142  term2str t;
   143 "1 + b * x + x * a";
   144 
   145  val t = (term_of o the o (parse thy)) "1 + a * (x + b * x) + a^^^2";
   146  val SOME (t,_) =
   147      rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in t;
   148  term2str t;
   149  val SOME (t,_) =
   150      rewrite_set_ thy false discard_parentheses t;
   151  term2str t;
   152 "1 + (x + b * x) * a + a ^^^ 2";
   153 
   154  val t = (term_of o the o (parse thy)) "1 + a ^^^2 * x + b * a + 7*a^^^2";
   155  val SOME (t,_) =
   156      rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in t;
   157  term2str t;
   158  val SOME (t,_) =
   159      rewrite_set_ thy false discard_parentheses t;
   160  term2str t;
   161 "1 + b * a + (7 + x) * a ^^^ 2";
   162 
   163 (* MG2003
   164  Atools.thy       grundlegende Algebra
   165  Poly.thy         Polynome
   166  Rational.thy     Br"uche
   167  Root.thy         Wurzeln
   168  RootRat.thy      Wurzen + Br"uche
   169  Termorder.thy    BITTE NUR HIERHER SCHREIBEN (...WN03)
   170 
   171  cd"knowledge";
   172  remove_thy"Termorder";
   173  use_thy"Isac";
   174 
   175  get_thm Termorder.thy "bdv_n_collect";
   176  get_thm Isac.thy "bdv_n_collect";
   177 
   178 *)
   179  val t = (term_of o the o (parse thy)) "a ^^^2 * x + 7 * a^^^2";
   180  val SOME (t,_) =
   181      rewrite_set_inst_ thy false [(bdv,a)] make_polynomial_in t;
   182  term2str t;
   183  val SOME (t,_) =
   184      rewrite_set_ thy false discard_parentheses t;
   185  term2str t;
   186 "(7 + x) * a ^^^ 2";
   187 
   188  val t = (term_of o the o (parse Termorder.thy)) "Pi";
   189 
   190  val t = (term_of o the o (parseold thy)) "7";
   191 
   192 ----------------------------------------------------------------------*)