src/Tools/isac/Knowledge/Test.thy
author Walther Neuper <neuper@ist.tugraz.at>
Sun, 22 Sep 2013 18:09:05 +0200
changeset 52125 6f1d3415dc68
parent 52105 2786cc9704c8
child 52140 b7cdced159f1
permissions -rw-r--r--
add functions accessing Theory_Data in parallel to those accessing "ruleset' = Unsynchronized.ref"

updates have been done incrementally following Build_Isac.thy:
# ./bin/isabelle jedit -l HOL src/Tools/isac/ProgLang/ProgLang.thy &
# ./bin/isabelle jedit -l HOL src/Tools/isac/Interpret/Interpret.thy &
# ./bin/isabelle jedit -l HOL src/Tools/isac/xmlsrc/xmlsrc.thy &
# ./bin/isabelle jedit -l HOL src/Tools/isac/Frontend/Frontend.thy &

Note, that the original access function "fun assoc_rls" is still outcommented;
so the old and new functionality is established in parallel.
     1 (* some tests are based on specficially simple scripts etc.
     2    Author: Walther Neuper 2003
     3    (c) due to copyright terms
     4 *) 
     5 
     6 theory Test imports Atools Poly Rational Root Diff begin
     7  
     8 consts
     9 
    10 (*"cancel":: [real, real] => real    (infixl "'/'/'/" 70) ...divide 2002*)
    11 
    12   Expand'_binomtest
    13              :: "['y,  
    14 		    'y] => 'y"
    15                ("((Script Expand'_binomtest (_ =))//  
    16                    (_))" 9)
    17 
    18   Solve'_univar'_err
    19              :: "[bool,real,bool,  
    20 		    bool list] => bool list"
    21                ("((Script Solve'_univar'_err (_ _ _ =))//  
    22                    (_))" 9)
    23   
    24   Solve'_linear
    25              :: "[bool,real,  
    26 		    bool list] => bool list"
    27                ("((Script Solve'_linear (_ _ =))//  
    28                    (_))" 9)
    29 
    30 (*17.9.02 aus SqRoot.thy------------------------------vvv---*)
    31 
    32   "is'_root'_free"   :: "'a => bool"      ("is'_root'_free _" 10)
    33   "contains'_root"   :: "'a => bool"      ("contains'_root _" 10)
    34 
    35   "precond'_rootmet" :: "'a => bool"      ("precond'_rootmet _" 10)
    36   "precond'_rootpbl" :: "'a => bool"      ("precond'_rootpbl _" 10)
    37   "precond'_submet"  :: "'a => bool"      ("precond'_submet _" 10)
    38   "precond'_subpbl"  :: "'a => bool"      ("precond'_subpbl _" 10)
    39 
    40   Solve'_root'_equation 
    41              :: "[bool,real,  
    42 		    bool list] => bool list"
    43                ("((Script Solve'_root'_equation (_ _ =))//  
    44                    (_))" 9)
    45 
    46   Solve'_plain'_square 
    47              :: "[bool,real,  
    48 		    bool list] => bool list"
    49                ("((Script Solve'_plain'_square (_ _ =))//  
    50                    (_))" 9)
    51 
    52   Norm'_univar'_equation 
    53              :: "[bool,real,  
    54 		    bool] => bool"
    55                ("((Script Norm'_univar'_equation (_ _ =))//  
    56                    (_))" 9)
    57 
    58   STest'_simplify
    59              :: "['z,  
    60 		    'z] => 'z"
    61                ("((Script STest'_simplify (_ =))//  
    62                    (_))" 9)
    63 
    64 (*17.9.02 aus SqRoot.thy------------------------------^^^---*)  
    65 
    66 axioms(*axiomatization where*) (*TODO: prove as theorems*)
    67 
    68   radd_mult_distrib2:      "(k::real) * (m + n) = k * m + k * n" (*and*)
    69   rdistr_right_assoc:      "(k::real) + l * n + m * n = k + (l + m) * n" (*and*)
    70   rdistr_right_assoc_p:    "l * n + (m * n + (k::real)) = (l + m) * n + k" (*and*)
    71   rdistr_div_right:        "((k::real) + l) / n = k / n + l / n" (*and*)
    72   rcollect_right:
    73           "[| l is_const; m is_const |] ==> (l::real)*n + m*n = (l + m) * n" (*and*)
    74   rcollect_one_left:
    75           "m is_const ==> (n::real) + m * n = (1 + m) * n" (*and*)
    76   rcollect_one_left_assoc:
    77           "m is_const ==> (k::real) + n + m * n = k + (1 + m) * n" (*and*)
    78   rcollect_one_left_assoc_p:
    79           "m is_const ==> n + (m * n + (k::real)) = (1 + m) * n + k" (*and*)
    80 
    81   rtwo_of_the_same:        "a + a = 2 * a" (*and*)
    82   rtwo_of_the_same_assoc:  "(x + a) + a = x + 2 * a" (*and*)
    83   rtwo_of_the_same_assoc_p:"a + (a + x) = 2 * a + x" (*and*)
    84 
    85   rcancel_den:             "not(a=0) ==> a * (b / a) = b" (*and*)
    86   rcancel_const:           "[| a is_const; b is_const |] ==> a*(x/b) = a/b*x" (*and*)
    87   rshift_nominator:        "(a::real) * b / c = a / c * b" (*and*)
    88 
    89   exp_pow:                 "(a ^^^ b) ^^^ c = a ^^^ (b * c)" (*and*)
    90   rsqare:                  "(a::real) * a = a ^^^ 2" (*and*)
    91   power_1:                 "(a::real) ^^^ 1 = a" (*and*)
    92   rbinom_power_2:          "((a::real) + b)^^^ 2 = a^^^ 2 + 2*a*b + b^^^ 2" (*and*)
    93 
    94   rmult_1:                 "1 * k = (k::real)" (*and*)
    95   rmult_1_right:           "k * 1 = (k::real)" (*and*)
    96   rmult_0:                 "0 * k = (0::real)" (*and*)
    97   rmult_0_right:           "k * 0 = (0::real)" (*and*)
    98   radd_0:                  "0 + k = (k::real)" (*and*)
    99   radd_0_right:            "k + 0 = (k::real)" (*and*)
   100 
   101   radd_real_const_eq:
   102           "[| a is_const; c is_const; d is_const |] ==> a/d + c/d = (a+c)/(d::real)" (*and*)
   103   radd_real_const:
   104           "[| a is_const; b is_const; c is_const; d is_const |] ==> a/b + c/d = (a*d + b*c)/(b*(d::real))"  
   105    (*and*)
   106 (*for AC-operators*)
   107   radd_commute:            "(m::real) + (n::real) = n + m" (*and*)
   108   radd_left_commute:       "(x::real) + (y + z) = y + (x + z)" (*and*)
   109   radd_assoc:              "(m::real) + n + k = m + (n + k)" (*and*)
   110   rmult_commute:           "(m::real) * n = n * m" (*and*)
   111   rmult_left_commute:      "(x::real) * (y * z) = y * (x * z)" (*and*)
   112   rmult_assoc:             "(m::real) * n * k = m * (n * k)" (*and*)
   113 
   114 (*for equations: 'bdv' is a meta-constant*)
   115   risolate_bdv_add:       "((k::real) + bdv = m) = (bdv = m + (-1)*k)" (*and*)
   116   risolate_bdv_mult_add:  "((k::real) + n*bdv = m) = (n*bdv = m + (-1)*k)" (*and*)
   117   risolate_bdv_mult:      "((n::real) * bdv = m) = (bdv = m / n)" (*and*)
   118 
   119   rnorm_equation_add:
   120       "~(b =!= 0) ==> (a = b) = (a + (-1)*b = 0)" (*and*)
   121 
   122 (*17.9.02 aus SqRoot.thy------------------------------vvv---*) 
   123   root_ge0:            "0 <= a ==> 0 <= sqrt a" (*and*)
   124   (*should be dropped with better simplification in eval_rls ...*)
   125   root_add_ge0:
   126 	"[| 0 <= a; 0 <= b |] ==> (0 <= sqrt a + sqrt b) = True" (*and*)
   127   root_ge0_1:
   128 	"[| 0<=a; 0<=b; 0<=c |] ==> (0 <= a * sqrt b + sqrt c) = True" (*and*)
   129   root_ge0_2:
   130 	"[| 0<=a; 0<=b; 0<=c |] ==> (0 <= sqrt a + b * sqrt c) = True" (*and*)
   131 
   132 
   133   rroot_square_inv:         "(sqrt a)^^^ 2 = a" (*and*)
   134   rroot_times_root:         "sqrt a * sqrt b = sqrt(a*b)" (*and*)
   135   rroot_times_root_assoc:   "(a * sqrt b) * sqrt c = a * sqrt(b*c)" (*and*)
   136   rroot_times_root_assoc_p: "sqrt b * (sqrt c * a)= sqrt(b*c) * a" (*and*)
   137 
   138 
   139 (*for root-equations*)
   140   square_equation_left:
   141           "[| 0 <= a; 0 <= b |] ==> (((sqrt a)=b)=(a=(b^^^ 2)))" (*and*)
   142   square_equation_right:
   143           "[| 0 <= a; 0 <= b |] ==> ((a=(sqrt b))=((a^^^ 2)=b))" (*and*)
   144   (*causes frequently non-termination:*)
   145   square_equation:  
   146           "[| 0 <= a; 0 <= b |] ==> ((a=b)=((a^^^ 2)=b^^^ 2))" (*and*)
   147   
   148   risolate_root_add:        "(a+  sqrt c = d) = (  sqrt c = d + (-1)*a)" (*and*)
   149   risolate_root_mult:       "(a+b*sqrt c = d) = (b*sqrt c = d + (-1)*a)" (*and*)
   150   risolate_root_div:        "(a * sqrt c = d) = (  sqrt c = d / a)" (*and*)
   151 
   152 (*for polynomial equations of degree 2; linear case in RatArith*)
   153   mult_square:		"(a*bdv^^^2 = b) = (bdv^^^2 = b / a)" (*and*)
   154   constant_square:       "(a + bdv^^^2 = b) = (bdv^^^2 = b + -1*a)" (*and*)
   155   constant_mult_square:  "(a + b*bdv^^^2 = c) = (b*bdv^^^2 = c + -1*a)" (*and*)
   156 
   157   square_equality: 
   158 	     "0 <= a ==> (x^^^2 = a) = ((x=sqrt a) | (x=-1*sqrt a))" (*and*)
   159   square_equality_0:
   160 	     "(x^^^2 = 0) = (x = 0)" (*and*)
   161 
   162 (*isolate root on the LEFT hand side of the equation
   163   otherwise shuffling from left to right would not terminate*)  
   164 
   165   rroot_to_lhs:
   166           "is_root_free a ==> (a = sqrt b) = (a + (-1)*sqrt b = 0)" (*and*)
   167   rroot_to_lhs_mult:
   168           "is_root_free a ==> (a = c*sqrt b) = (a + (-1)*c*sqrt b = 0)" (*and*)
   169   rroot_to_lhs_add_mult:
   170           "is_root_free a ==> (a = d+c*sqrt b) = (a + (-1)*c*sqrt b = d)"
   171 (*17.9.02 aus SqRoot.thy------------------------------^^^---*)  
   172 
   173 ML {*
   174 val thy = @{theory};
   175 
   176 (** evaluation of numerals and predicates **)
   177 
   178 (*does a term contain a root ? WN110518 seems incorrect, compare contains_root*)
   179 fun eval_root_free (thmid:string) _ (t as (Const (op0, t0) $ arg)) thy = 
   180   if strip_thy op0 <> "is'_root'_free" 
   181     then error ("eval_root_free: wrong " ^ op0)
   182   else if const_in (strip_thy op0) arg
   183   then SOME (mk_thmid thmid "" (term_to_string''' thy arg)"",
   184 	       Trueprop $ (mk_equality (t, @{term False})))
   185   else SOME (mk_thmid thmid "" (term_to_string''' thy arg)"",
   186 	       Trueprop $ (mk_equality (t, @{term True})))
   187 | eval_root_free _ _ _ _ = NONE; 
   188 
   189 (*does a term contain a root ?*)
   190 fun eval_contains_root (thmid:string) _ 
   191 		       (t as (Const("Test.contains'_root",t0) $ arg)) thy = 
   192   if member op = (ids_of arg) "sqrt"
   193   then SOME (mk_thmid thmid "" (term_to_string''' thy arg)"",
   194 	       Trueprop $ (mk_equality (t, @{term True})))
   195   else SOME (mk_thmid thmid "" (term_to_string''' thy arg)"",
   196 	       Trueprop $ (mk_equality (t, @{term False})))
   197 | eval_contains_root _ _ _ _ = NONE; 
   198 
   199 (*dummy precondition for root-met of x+1=2*)
   200 fun eval_precond_rootmet (thmid:string) _ (t as (Const ("Test.precond'_rootmet", _) $ arg)) thy = 
   201     SOME (mk_thmid thmid "" (term_to_string''' thy arg)"",
   202       Trueprop $ (mk_equality (t, @{term True})))
   203   | eval_precond_rootmet _ _ _ _ = NONE; 
   204 
   205 (*dummy precondition for root-pbl of x+1=2*)
   206 fun eval_precond_rootpbl (thmid:string) _ (t as (Const ("Test.precond'_rootpbl", _) $ arg)) thy = 
   207     SOME (mk_thmid thmid "" (term_to_string''' thy arg) "",
   208 	    Trueprop $ (mk_equality (t, @{term True})))
   209 	| eval_precond_rootpbl _ _ _ _ = NONE; 
   210 
   211 calclist':= overwritel (!calclist', 
   212    [("is_root_free", ("Test.is'_root'_free", 
   213 		      eval_root_free"#is_root_free_e")),
   214     ("contains_root", ("Test.contains'_root",
   215 		       eval_contains_root"#contains_root_")),
   216     ("Test.precond'_rootmet", ("Test.precond'_rootmet",
   217 		       eval_precond_rootmet"#Test.precond_rootmet_")),
   218     ("Test.precond'_rootpbl", ("Test.precond'_rootpbl",
   219 		       eval_precond_rootpbl"#Test.precond_rootpbl_"))
   220     ]);
   221 
   222 (** term order **)
   223 fun term_order (_:subst) tu = (term_ordI [] tu = LESS);
   224 *}
   225 ML {*
   226 (** rule sets **)
   227 
   228 val testerls = 
   229   Rls {id = "testerls", preconds = [], rew_ord = ("termlessI",termlessI), 
   230       erls = e_rls, srls = Erls, 
   231       calc = [], errpatts = [], 
   232       rules = [Thm ("refl",num_str @{thm refl}),
   233 	       Thm ("order_refl",num_str @{thm order_refl}),
   234 	       Thm ("radd_left_cancel_le",num_str @{thm radd_left_cancel_le}),
   235 	       Thm ("not_true",num_str @{thm not_true}),
   236 	       Thm ("not_false",num_str @{thm not_false}),
   237 	       Thm ("and_true",num_str @{thm and_true}),
   238 	       Thm ("and_false",num_str @{thm and_false}),
   239 	       Thm ("or_true",num_str @{thm or_true}),
   240 	       Thm ("or_false",num_str @{thm or_false}),
   241 	       Thm ("and_commute",num_str @{thm and_commute}),
   242 	       Thm ("or_commute",num_str @{thm or_commute}),
   243 
   244 	       Calc ("Atools.is'_const",eval_const "#is_const_"),
   245 	       Calc ("Tools.matches",eval_matches ""),
   246     
   247 	       Calc ("Groups.plus_class.plus",eval_binop "#add_"),
   248 	       Calc ("Groups.times_class.times",eval_binop "#mult_"),
   249 	       Calc ("Atools.pow" ,eval_binop "#power_"),
   250 		    
   251 	       Calc ("Orderings.ord_class.less",eval_equ "#less_"),
   252 	       Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
   253 	     	    
   254 	       Calc ("Atools.ident",eval_ident "#ident_")],
   255       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   256       }:rls;      
   257 *}
   258 ML {*
   259 (*.for evaluation of conditions in rewrite rules.*)
   260 (*FIXXXXXXME 10.8.02: handle like _simplify*)
   261 val tval_rls =  
   262   Rls{id = "tval_rls", preconds = [], 
   263       rew_ord = ("sqrt_right",sqrt_right false (Thy_Info.get_theory "Pure")), 
   264       erls=testerls,srls = e_rls, 
   265       calc=[], errpatts = [],
   266       rules = [Thm ("refl",num_str @{thm refl}),
   267 	       Thm ("order_refl",num_str @{thm order_refl}),
   268 	       Thm ("radd_left_cancel_le",num_str @{thm radd_left_cancel_le}),
   269 	       Thm ("not_true",num_str @{thm not_true}),
   270 	       Thm ("not_false",num_str @{thm not_false}),
   271 	       Thm ("and_true",num_str @{thm and_true}),
   272 	       Thm ("and_false",num_str @{thm and_false}),
   273 	       Thm ("or_true",num_str @{thm or_true}),
   274 	       Thm ("or_false",num_str @{thm or_false}),
   275 	       Thm ("and_commute",num_str @{thm and_commute}),
   276 	       Thm ("or_commute",num_str @{thm or_commute}),
   277 
   278 	       Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
   279 
   280 	       Thm ("root_ge0",num_str @{thm root_ge0}),
   281 	       Thm ("root_add_ge0",num_str @{thm root_add_ge0}),
   282 	       Thm ("root_ge0_1",num_str @{thm root_ge0_1}),
   283 	       Thm ("root_ge0_2",num_str @{thm root_ge0_2}),
   284 
   285 	       Calc ("Atools.is'_const",eval_const "#is_const_"),
   286 	       Calc ("Test.is'_root'_free",eval_root_free "#is_root_free_e"),
   287 	       Calc ("Tools.matches",eval_matches ""),
   288 	       Calc ("Test.contains'_root",
   289 		     eval_contains_root"#contains_root_"),
   290     
   291 	       Calc ("Groups.plus_class.plus",eval_binop "#add_"),
   292 	       Calc ("Groups.times_class.times",eval_binop "#mult_"),
   293 	       Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
   294 	       Calc ("Atools.pow" ,eval_binop "#power_"),
   295 		    
   296 	       Calc ("Orderings.ord_class.less",eval_equ "#less_"),
   297 	       Calc ("Orderings.ord_class.less_eq",eval_equ "#less_equal_"),
   298 	     	    
   299 	       Calc ("Atools.ident",eval_ident "#ident_")],
   300       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   301       }:rls;      
   302 *}
   303 ML {*
   304 
   305 ruleset' := overwritelthy @{theory} (!ruleset',
   306   [("testerls", prep_rls testerls)
   307    ]);
   308 *}
   309 setup {* KEStore_Elems.add_rlss [("testerls", (Context.theory_name @{theory}, prep_rls testerls))] *}
   310 ML {*
   311 
   312 
   313 (*make () dissappear*)   
   314 val rearrange_assoc =
   315   Rls{id = "rearrange_assoc", preconds = [], 
   316       rew_ord = ("e_rew_ord",e_rew_ord), 
   317       erls = e_rls, srls = e_rls, calc = [], errpatts = [],
   318       rules = 
   319       [Thm ("sym_add_assoc",num_str (@{thm add_assoc} RS @{thm sym})),
   320        Thm ("sym_rmult_assoc",num_str (@{thm rmult_assoc} RS @{thm sym}))],
   321       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   322       }:rls;      
   323 
   324 val ac_plus_times =
   325   Rls{id = "ac_plus_times", preconds = [], rew_ord = ("term_order",term_order),
   326       erls = e_rls, srls = e_rls, calc = [], errpatts = [],
   327       rules = 
   328       [Thm ("radd_commute",num_str @{thm radd_commute}),
   329        Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
   330        Thm ("add_assoc",num_str @{thm add_assoc}),
   331        Thm ("rmult_commute",num_str @{thm rmult_commute}),
   332        Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
   333        Thm ("rmult_assoc",num_str @{thm rmult_assoc})],
   334       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   335       }:rls;      
   336 
   337 (*todo: replace by Rewrite("rnorm_equation_add",num_str @{thm rnorm_equation_add)*)
   338 val norm_equation =
   339   Rls{id = "norm_equation", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
   340       erls = tval_rls, srls = e_rls, calc = [], errpatts = [],
   341       rules = [Thm ("rnorm_equation_add",num_str @{thm rnorm_equation_add})
   342 	       ],
   343       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   344       }:rls;      
   345 *}
   346 ML {*
   347 (** rule sets **)
   348 
   349 val STest_simplify =     (*   vv--- not changed to real by parse*)
   350   "Script STest_simplify (t_t::'z) =                           " ^
   351   "(Repeat" ^
   352   "    ((Try (Repeat (Rewrite real_diff_minus False))) @@        " ^
   353   "     (Try (Repeat (Rewrite radd_mult_distrib2 False))) @@  " ^
   354   "     (Try (Repeat (Rewrite rdistr_right_assoc False))) @@  " ^
   355   "     (Try (Repeat (Rewrite rdistr_right_assoc_p False))) @@" ^
   356   "     (Try (Repeat (Rewrite rdistr_div_right False))) @@    " ^
   357   "     (Try (Repeat (Rewrite rbinom_power_2 False))) @@      " ^
   358 	
   359   "     (Try (Repeat (Rewrite radd_commute False))) @@        " ^
   360   "     (Try (Repeat (Rewrite radd_left_commute False))) @@   " ^
   361   "     (Try (Repeat (Rewrite add_assoc False))) @@          " ^
   362   "     (Try (Repeat (Rewrite rmult_commute False))) @@       " ^
   363   "     (Try (Repeat (Rewrite rmult_left_commute False))) @@  " ^
   364   "     (Try (Repeat (Rewrite rmult_assoc False))) @@         " ^
   365 	
   366   "     (Try (Repeat (Rewrite radd_real_const_eq False))) @@   " ^
   367   "     (Try (Repeat (Rewrite radd_real_const False))) @@   " ^
   368   "     (Try (Repeat (Calculate PLUS))) @@   " ^
   369   "     (Try (Repeat (Calculate TIMES))) @@   " ^
   370   "     (Try (Repeat (Calculate divide_))) @@" ^
   371   "     (Try (Repeat (Calculate POWER))) @@  " ^
   372 	
   373   "     (Try (Repeat (Rewrite rcollect_right False))) @@   " ^
   374   "     (Try (Repeat (Rewrite rcollect_one_left False))) @@   " ^
   375   "     (Try (Repeat (Rewrite rcollect_one_left_assoc False))) @@   " ^
   376   "     (Try (Repeat (Rewrite rcollect_one_left_assoc_p False))) @@   " ^
   377 	
   378   "     (Try (Repeat (Rewrite rshift_nominator False))) @@   " ^
   379   "     (Try (Repeat (Rewrite rcancel_den False))) @@   " ^
   380   "     (Try (Repeat (Rewrite rroot_square_inv False))) @@   " ^
   381   "     (Try (Repeat (Rewrite rroot_times_root False))) @@   " ^
   382   "     (Try (Repeat (Rewrite rroot_times_root_assoc_p False))) @@   " ^
   383   "     (Try (Repeat (Rewrite rsqare False))) @@   " ^
   384   "     (Try (Repeat (Rewrite power_1 False))) @@   " ^
   385   "     (Try (Repeat (Rewrite rtwo_of_the_same False))) @@   " ^
   386   "     (Try (Repeat (Rewrite rtwo_of_the_same_assoc_p False))) @@   " ^
   387 	
   388   "     (Try (Repeat (Rewrite rmult_1 False))) @@   " ^
   389   "     (Try (Repeat (Rewrite rmult_1_right False))) @@   " ^
   390   "     (Try (Repeat (Rewrite rmult_0 False))) @@   " ^
   391   "     (Try (Repeat (Rewrite rmult_0_right False))) @@   " ^
   392   "     (Try (Repeat (Rewrite radd_0 False))) @@   " ^
   393   "     (Try (Repeat (Rewrite radd_0_right False)))) " ^
   394   " t_t)";
   395 
   396 *}
   397 ML {*
   398 (* expects * distributed over + *)
   399 val Test_simplify =
   400   Rls{id = "Test_simplify", preconds = [], 
   401       rew_ord = ("sqrt_right",sqrt_right false (Thy_Info.get_theory "Pure")),
   402       erls = tval_rls, srls = e_rls, 
   403       calc=[(*since 040209 filled by prep_rls*)], errpatts = [],
   404       rules = [
   405 	       Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
   406 	       Thm ("radd_mult_distrib2",num_str @{thm radd_mult_distrib2}),
   407 	       Thm ("rdistr_right_assoc",num_str @{thm rdistr_right_assoc}),
   408 	       Thm ("rdistr_right_assoc_p",num_str @{thm rdistr_right_assoc_p}),
   409 	       Thm ("rdistr_div_right",num_str @{thm rdistr_div_right}),
   410 	       Thm ("rbinom_power_2",num_str @{thm rbinom_power_2}),	       
   411 
   412                Thm ("radd_commute",num_str @{thm radd_commute}), 
   413 	       Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
   414 	       Thm ("add_assoc",num_str @{thm add_assoc}),
   415 	       Thm ("rmult_commute",num_str @{thm rmult_commute}),
   416 	       Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
   417 	       Thm ("rmult_assoc",num_str @{thm rmult_assoc}),
   418 
   419 	       Thm ("radd_real_const_eq",num_str @{thm radd_real_const_eq}),
   420 	       Thm ("radd_real_const",num_str @{thm radd_real_const}),
   421 	       (* these 2 rules are invers to distr_div_right wrt. termination.
   422 		  thus they MUST be done IMMEDIATELY before calc *)
   423 	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
   424 	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
   425 	       Calc ("Fields.inverse_class.divide", eval_cancel "#divide_e"),
   426 	       Calc ("Atools.pow", eval_binop "#power_"),
   427 
   428 	       Thm ("rcollect_right",num_str @{thm rcollect_right}),
   429 	       Thm ("rcollect_one_left",num_str @{thm rcollect_one_left}),
   430 	       Thm ("rcollect_one_left_assoc",num_str @{thm rcollect_one_left_assoc}),
   431 	       Thm ("rcollect_one_left_assoc_p",num_str @{thm rcollect_one_left_assoc_p}),
   432 
   433 	       Thm ("rshift_nominator",num_str @{thm rshift_nominator}),
   434 	       Thm ("rcancel_den",num_str @{thm rcancel_den}),
   435 	       Thm ("rroot_square_inv",num_str @{thm rroot_square_inv}),
   436 	       Thm ("rroot_times_root",num_str @{thm rroot_times_root}),
   437 	       Thm ("rroot_times_root_assoc_p",num_str @{thm rroot_times_root_assoc_p}),
   438 	       Thm ("rsqare",num_str @{thm rsqare}),
   439 	       Thm ("power_1",num_str @{thm power_1}),
   440 	       Thm ("rtwo_of_the_same",num_str @{thm rtwo_of_the_same}),
   441 	       Thm ("rtwo_of_the_same_assoc_p",num_str @{thm rtwo_of_the_same_assoc_p}),
   442 
   443 	       Thm ("rmult_1",num_str @{thm rmult_1}),
   444 	       Thm ("rmult_1_right",num_str @{thm rmult_1_right}),
   445 	       Thm ("rmult_0",num_str @{thm rmult_0}),
   446 	       Thm ("rmult_0_right",num_str @{thm rmult_0_right}),
   447 	       Thm ("radd_0",num_str @{thm radd_0}),
   448 	       Thm ("radd_0_right",num_str @{thm radd_0_right})
   449 	       ],
   450       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   451 		    (*since 040209 filled by prep_rls: STest_simplify*)
   452       }:rls;      
   453 *}
   454 ML {*
   455 
   456 (** rule sets **)
   457 
   458 
   459 
   460 (*isolate the root in a root-equation*)
   461 val isolate_root =
   462   Rls{id = "isolate_root", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord), 
   463       erls=tval_rls,srls = e_rls, calc=[], errpatts = [],
   464       rules = [Thm ("rroot_to_lhs",num_str @{thm rroot_to_lhs}),
   465 	       Thm ("rroot_to_lhs_mult",num_str @{thm rroot_to_lhs_mult}),
   466 	       Thm ("rroot_to_lhs_add_mult",num_str @{thm rroot_to_lhs_add_mult}),
   467 	       Thm ("risolate_root_add",num_str @{thm risolate_root_add}),
   468 	       Thm ("risolate_root_mult",num_str @{thm risolate_root_mult}),
   469 	       Thm ("risolate_root_div",num_str @{thm risolate_root_div})       ],
   470       scr = Prog ((term_of o the o (parse thy)) 
   471       "empty_script")
   472       }:rls;
   473 
   474 (*isolate the bound variable in an equation; 'bdv' is a meta-constant*)
   475 val isolate_bdv =
   476     Rls{id = "isolate_bdv", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
   477 	erls=tval_rls,srls = e_rls, calc= [], errpatts = [],
   478 	rules = 
   479 	[Thm ("risolate_bdv_add",num_str @{thm risolate_bdv_add}),
   480 	 Thm ("risolate_bdv_mult_add",num_str @{thm risolate_bdv_mult_add}),
   481 	 Thm ("risolate_bdv_mult",num_str @{thm risolate_bdv_mult}),
   482 	 Thm ("mult_square",num_str @{thm mult_square}),
   483 	 Thm ("constant_square",num_str @{thm constant_square}),
   484 	 Thm ("constant_mult_square",num_str @{thm constant_mult_square})
   485 	 ],
   486 	scr = Prog ((term_of o the o (parse thy)) 
   487 			  "empty_script")
   488 	}:rls;      
   489 *}
   490 ML {*
   491 
   492 (* association list for calculate_, calculate
   493    "Groups.plus_class.plus" etc. not usable in scripts *)
   494 val calclist = 
   495     [
   496      (*as Tools.ML*)
   497      ("Vars"    ,("Tools.Vars"    ,eval_var "#Vars_")),
   498      ("matches",("Tools.matches",eval_matches "#matches_")),
   499      ("lhs"    ,("Tools.lhs"    ,eval_lhs "")),
   500      (*aus Atools.ML*)
   501      ("PLUS"    ,("Groups.plus_class.plus"        ,eval_binop "#add_")),
   502      ("TIMES"   ,("Groups.times_class.times"        ,eval_binop "#mult_")),
   503      ("DIVIDE" ,("Fields.inverse_class.divide"  ,eval_cancel "#divide_e")),
   504      ("POWER"  ,("Atools.pow"  ,eval_binop "#power_")),
   505      ("is_const",("Atools.is'_const",eval_const "#is_const_")),
   506      ("le"      ,("Orderings.ord_class.less"        ,eval_equ "#less_")),
   507      ("leq"     ,("Orderings.ord_class.less_eq"       ,eval_equ "#less_equal_")),
   508      ("ident"   ,("Atools.ident",eval_ident "#ident_")),
   509      (*von hier (ehem.SqRoot*)
   510      ("sqrt"    ,("NthRoot.sqrt"   ,eval_sqrt "#sqrt_")),
   511      ("Test.is_root_free",("is'_root'_free", eval_root_free"#is_root_free_e")),
   512      ("Test.contains_root",("contains'_root",
   513 			    eval_contains_root"#contains_root_"))
   514      ];
   515 
   516 ruleset' := overwritelthy @{theory} (!ruleset',
   517   [("Test_simplify", prep_rls Test_simplify),
   518    ("tval_rls", prep_rls tval_rls),
   519    ("isolate_root", prep_rls isolate_root),
   520    ("isolate_bdv", prep_rls isolate_bdv),
   521    ("matches", 
   522     prep_rls (append_rls "matches" testerls 
   523 			 [Calc ("Tools.matches",eval_matches "#matches_")]))
   524    ]);
   525 *}
   526 setup {* KEStore_Elems.add_rlss 
   527   [("Test_simplify", (Context.theory_name @{theory}, prep_rls Test_simplify)), 
   528   ("tval_rls", (Context.theory_name @{theory}, prep_rls tval_rls)), 
   529   ("isolate_root", (Context.theory_name @{theory}, prep_rls isolate_root)), 
   530   ("isolate_bdv", (Context.theory_name @{theory}, prep_rls isolate_bdv)), 
   531   ("matches", (Context.theory_name @{theory}, prep_rls
   532     (append_rls "matches" testerls [Calc ("Tools.matches",eval_matches "#matches_")])))] *}
   533 
   534 ML {*
   535 (** problem types **)
   536 store_pbt
   537  (prep_pbt thy "pbl_test" [] e_pblID
   538  (["test"],
   539   [],
   540   e_rls, NONE, []));
   541 store_pbt
   542  (prep_pbt thy "pbl_test_equ" [] e_pblID
   543  (["equation","test"],
   544   [("#Given" ,["equality e_e","solveFor v_v"]),
   545    ("#Where" ,["matches (?a = ?b) e_e"]),
   546    ("#Find"  ,["solutions v_v'i'"])
   547   ],
   548   assoc_rls "matches",
   549   SOME "solve (e_e::bool, v_v)", []));
   550 
   551 store_pbt
   552  (prep_pbt thy "pbl_test_uni" [] e_pblID
   553  (["univariate","equation","test"],
   554   [("#Given" ,["equality e_e","solveFor v_v"]),
   555    ("#Where" ,["matches (?a = ?b) e_e"]),
   556    ("#Find"  ,["solutions v_v'i'"])
   557   ],
   558   assoc_rls "matches",
   559   SOME "solve (e_e::bool, v_v)", []));
   560 
   561 store_pbt
   562  (prep_pbt thy "pbl_test_uni_lin" [] e_pblID
   563  (["linear","univariate","equation","test"],
   564   [("#Given" ,["equality e_e","solveFor v_v"]),
   565    ("#Where" ,["(matches (   v_v = 0) e_e) | (matches (   ?b*v_v = 0) e_e) |" ^
   566 	       "(matches (?a+v_v = 0) e_e) | (matches (?a+?b*v_v = 0) e_e)  "]),
   567    ("#Find"  ,["solutions v_v'i'"])
   568   ],
   569   assoc_rls "matches", 
   570   SOME "solve (e_e::bool, v_v)", [["Test","solve_linear"]]));
   571 
   572 (*25.8.01 ------
   573 store_pbt
   574  (prep_pbt thy
   575  (["thy"],
   576   [("#Given" ,"boolTestGiven g_g"),
   577    ("#Find"  ,"boolTestFind f_f")
   578   ],
   579   []));
   580 
   581 store_pbt
   582  (prep_pbt thy
   583  (["testeq","thy"],
   584   [("#Given" ,"boolTestGiven g_g"),
   585    ("#Find"  ,"boolTestFind f_f")
   586   ],
   587   []));
   588 
   589 
   590 val ttt = (term_of o the o (parse (Thy_Info.get_theory "Isac"))) "(matches (   v_v = 0) e_e)";
   591 
   592  ------ 25.8.01*)
   593 
   594 *}
   595 ML {*
   596 (** methods **)
   597 store_met
   598  (prep_met @{theory "Diff"} "met_test" [] e_metID
   599  (["Test"],
   600    [],
   601    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
   602     crls=Atools_erls, errpats = [], nrls = e_rls}, "empty_script"));
   603 *}
   604 ML {*
   605 store_met
   606  (prep_met thy "met_test_solvelin" [] e_metID
   607  (["Test","solve_linear"]:metID,
   608   [("#Given" ,["equality e_e","solveFor v_v"]),
   609     ("#Where" ,["matches (?a = ?b) e_e"]),
   610     ("#Find"  ,["solutions v_v'i'"])
   611     ],
   612    {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
   613     prls = assoc_rls "matches", calc = [], crls = tval_rls,
   614     errpats = [], nrls = Test_simplify},
   615  "Script Solve_linear (e_e::bool) (v_v::real)=                     " ^
   616  "(let e_e =                                                       " ^
   617  "  Repeat                                                         " ^
   618  "    (((Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@  " ^
   619  "      (Rewrite_Set Test_simplify False))) e_e" ^
   620  " in [e_e::bool])"
   621  )
   622 (*, prep_met thy (*test for equations*)
   623  (["Test","testeq"]:metID,
   624   [("#Given" ,["boolTestGiven g_g"]),
   625    ("#Find"  ,["boolTestFind f_f"])
   626     ],
   627   {rew_ord'="e_rew_ord",rls'="tval_rls",asm_rls=[],
   628    asm_thm=[("square_equation_left","")]},
   629  "Script Testeq (e_q::bool) =                                         " ^
   630    "Repeat                                                            " ^
   631    " (let e_e = Try (Repeat (Rewrite rroot_square_inv False e_q));      " ^
   632    "      e_e = Try (Repeat (Rewrite square_equation_left True e_e)); " ^
   633    "      e_e = Try (Repeat (Rewrite rmult_0 False e_e))                " ^
   634    "   in e_e) Until (is_root_free e_e)" (*deleted*)
   635  )
   636 , ---------27.4.02*)
   637 );
   638 
   639 *}
   640 ML {*
   641 ruleset' := overwritelthy @{theory} (!ruleset',
   642   [("norm_equation", prep_rls norm_equation),
   643    ("ac_plus_times", prep_rls ac_plus_times),
   644    ("rearrange_assoc", prep_rls rearrange_assoc)
   645    ]);
   646 *}
   647 setup {* KEStore_Elems.add_rlss 
   648   [("norm_equation", (Context.theory_name @{theory}, prep_rls norm_equation)), 
   649   ("ac_plus_times", (Context.theory_name @{theory}, prep_rls ac_plus_times)), 
   650   ("rearrange_assoc", (Context.theory_name @{theory}, prep_rls rearrange_assoc))] *}
   651 ML {*
   652 
   653 
   654 fun bin_o (Const (op_,(Type ("fun",
   655 	   [Type (s2,[]),Type ("fun",
   656 	    [Type (s4,tl4),Type (s5,tl5)])])))) = 
   657     if (s2=s4)andalso(s4=s5)then[op_]else[]
   658     | bin_o _                                   = [];
   659 
   660 fun bin_op (t1 $ t2) = union op = (bin_op t1) (bin_op t2)
   661   | bin_op t         =  bin_o t;
   662 fun is_bin_op t = ((bin_op t)<>[]);
   663 
   664 fun bin_op_arg1 ((Const (op_,(Type ("fun",
   665 	   [Type (s2,[]),Type ("fun",
   666 	    [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) = 
   667     arg1;
   668 fun bin_op_arg2 ((Const (op_,(Type ("fun",
   669 	   [Type (s2,[]),Type ("fun",
   670 	    [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) = 
   671     arg2;
   672 
   673 
   674 exception NO_EQUATION_TERM;
   675 fun is_equation ((Const ("HOL.eq",(Type ("fun",
   676 		 [Type (_,[]),Type ("fun",
   677 		  [Type (_,[]),Type ("bool",[])])])))) $ _ $ _) 
   678                   = true
   679   | is_equation _ = false;
   680 fun equ_lhs ((Const ("HOL.eq",(Type ("fun",
   681 		 [Type (_,[]),Type ("fun",
   682 		  [Type (_,[]),Type ("bool",[])])])))) $ l $ r) 
   683               = l
   684   | equ_lhs _ = raise NO_EQUATION_TERM;
   685 fun equ_rhs ((Const ("HOL.eq",(Type ("fun",
   686 		 [Type (_,[]),Type ("fun",
   687 		  [Type (_,[]),Type ("bool",[])])])))) $ l $ r) 
   688               = r
   689   | equ_rhs _ = raise NO_EQUATION_TERM;
   690 
   691 
   692 fun atom (Const (_,Type (_,[])))           = true
   693   | atom (Free  (_,Type (_,[])))           = true
   694   | atom (Var   (_,Type (_,[])))           = true
   695 (*| atom (_     (_,"?DUMMY"   ))           = true ..ML-error *)
   696   | atom((Const ("Bin.integ_of_bin",_)) $ _) = true
   697   | atom _                                 = false;
   698 
   699 fun varids (Const  (s,Type (_,[])))         = [strip_thy s]
   700   | varids (Free   (s,Type (_,[])))         = if is_no s then []
   701 					      else [strip_thy s]
   702   | varids (Var((s,_),Type (_,[])))         = [strip_thy s]
   703 (*| varids (_      (s,"?DUMMY"   ))         =   ..ML-error *)
   704   | varids((Const ("Bin.integ_of_bin",_)) $ _)= [](*8.01: superfluous?*)
   705   | varids (Abs(a,T,t)) = union op = [a] (varids t)
   706   | varids (t1 $ t2) = union op = (varids t1) (varids t2)
   707   | varids _         = [];
   708 (*> val t = term_of (hd (parse Diophant.thy "x"));
   709 val t = Free ("x","?DUMMY") : term
   710 > varids t;
   711 val it = [] : string list          [] !!! *)
   712 
   713 
   714 fun bin_ops_only ((Const op_) $ t1 $ t2) = 
   715     if(is_bin_op (Const op_))
   716     then(bin_ops_only t1)andalso(bin_ops_only t2)
   717     else false
   718   | bin_ops_only t =
   719     if atom t then true else bin_ops_only t;
   720 
   721 fun polynomial opl t bdVar = (* bdVar TODO *)
   722     subset op = (bin_op t, opl) andalso (bin_ops_only t);
   723 
   724 fun poly_equ opl bdVar t = is_equation t (* bdVar TODO *) 
   725     andalso polynomial opl (equ_lhs t) bdVar 
   726     andalso polynomial opl (equ_rhs t) bdVar
   727     andalso (subset op = (varids bdVar, varids (equ_lhs t)) orelse
   728              subset op = (varids bdVar, varids (equ_lhs t)));
   729 
   730 (*fun max is =
   731     let fun max_ m [] = m 
   732 	  | max_ m (i::is) = if m<i then max_ i is else max_ m is;
   733     in max_ (hd is) is end;
   734 > max [1,5,3,7,4,2];
   735 val it = 7 : int  *)
   736 
   737 fun max (a,b) = if a < b then b else a;
   738 
   739 fun degree addl mul bdVar t =
   740 let
   741 fun deg _ _ v (Const  (s,Type (_,[])))         = if v=strip_thy s then 1 else 0
   742   | deg _ _ v (Free   (s,Type (_,[])))         = if v=strip_thy s then 1 else 0
   743   | deg _ _ v (Var((s,_),Type (_,[])))         = if v=strip_thy s then 1 else 0
   744 (*| deg _ _ v (_     (s,"?DUMMY"   ))          =   ..ML-error *) 
   745   | deg _ _ v((Const ("Bin.integ_of_bin",_)) $ _ )= 0 
   746   | deg addl mul v (h $ t1 $ t2) =
   747     if subset op = (bin_op h, addl)
   748     then max (deg addl mul v t1  ,deg addl mul v t2)
   749     else (*mul!*)(deg addl mul v t1)+(deg addl mul v t2)
   750 in if polynomial (addl @ [mul]) t bdVar
   751    then SOME (deg addl mul (id_of bdVar) t) else (NONE:int option)
   752 end;
   753 fun degree_ addl mul bdVar t = (* do not export *)
   754     let fun opt (SOME i)= i
   755 	  | opt  NONE   = 0
   756 in opt (degree addl mul bdVar t) end;
   757 
   758 
   759 fun linear addl mul t bdVar = (degree_ addl mul bdVar t)<2;
   760 
   761 fun linear_equ addl mul bdVar t =
   762     if is_equation t 
   763     then let val degl = degree_ addl mul bdVar (equ_lhs t);
   764 	     val degr = degree_ addl mul bdVar (equ_rhs t)
   765 	 in if (degl>0 orelse degr>0)andalso max(degl,degr)<2
   766 		then true else false
   767 	 end
   768     else false;
   769 (* strip_thy op_  before *)
   770 fun is_div_op (dv,(Const (op_,(Type ("fun",
   771 	   [Type (s2,[]),Type ("fun",
   772 	    [Type (s4,tl4),Type (s5,tl5)])])))) )= (dv = strip_thy op_)
   773   | is_div_op _ = false;
   774 
   775 fun is_denom bdVar div_op t =
   776     let fun is bool[v]dv (Const  (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
   777 	  | is bool[v]dv (Free   (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false) 
   778 	  | is bool[v]dv (Var((s,_),Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
   779 	  | is bool[v]dv((Const ("Bin.integ_of_bin",_)) $ _) = false
   780 	  | is bool[v]dv (h$n$d) = 
   781 	      if is_div_op(dv,h) 
   782 	      then (is false[v]dv n)orelse(is true[v]dv d)
   783 	      else (is bool [v]dv n)orelse(is bool[v]dv d)
   784 in is false (varids bdVar) (strip_thy div_op) t end;
   785 
   786 
   787 fun rational t div_op bdVar = 
   788     is_denom bdVar div_op t andalso bin_ops_only t;
   789 
   790 *}
   791 ML {*
   792 
   793 (** problem types **)
   794 
   795 store_pbt
   796  (prep_pbt thy "pbl_test_uni_plain2" [] e_pblID
   797  (["plain_square","univariate","equation","test"],
   798   [("#Given" ,["equality e_e","solveFor v_v"]),
   799    ("#Where" ,["(matches (?a + ?b*v_v ^^^2 = 0) e_e) |" ^
   800 	       "(matches (     ?b*v_v ^^^2 = 0) e_e) |" ^
   801 	       "(matches (?a +    v_v ^^^2 = 0) e_e) |" ^
   802 	       "(matches (        v_v ^^^2 = 0) e_e)"]),
   803    ("#Find"  ,["solutions v_v'i'"])
   804   ],
   805   assoc_rls "matches", 
   806   SOME "solve (e_e::bool, v_v)", [["Test","solve_plain_square"]]));
   807 (*
   808  val e_e = (term_of o the o (parse thy)) "e_e::bool";
   809  val ve = (term_of o the o (parse thy)) "4 + 3*x^^^2 = 0";
   810  val env = [(e_,ve)];
   811 
   812  val pre = (term_of o the o (parse thy))
   813 	      "(matches (a + b*v_v ^^^2 = 0, e_e::bool)) |" ^
   814 	      "(matches (    b*v_v ^^^2 = 0, e_e::bool)) |" ^
   815 	      "(matches (a +   v_v ^^^2 = 0, e_e::bool)) |" ^
   816 	      "(matches (      v_v ^^^2 = 0, e_e::bool))";
   817  val prei = subst_atomic env pre;
   818  val cpre = (cterm_of thy) prei;
   819 
   820  val SOME (ct,_) = rewrite_set_ thy false tval_rls cpre;
   821 val ct = "True | False | False | False" : cterm 
   822 
   823 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   824 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   825 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   826 val ct = "HOL.True" : cterm
   827 
   828 *)
   829 
   830 *}
   831 ML {*
   832 store_pbt
   833  (prep_pbt thy "pbl_test_uni_poly" [] e_pblID
   834  (["polynomial","univariate","equation","test"],
   835   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   836    ("#Where" ,["HOL.False"]),
   837    ("#Find"  ,["solutions v_v'i'"]) 
   838   ],
   839   e_rls, SOME "solve (e_e::bool, v_v)", []));
   840 
   841 store_pbt
   842  (prep_pbt thy "pbl_test_uni_poly_deg2" [] e_pblID
   843  (["degree_two","polynomial","univariate","equation","test"],
   844   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   845    ("#Find"  ,["solutions v_v'i'"]) 
   846   ],
   847   e_rls, SOME "solve (v_v ^^^2 + p_p * v_v + q__q = 0, v_v)", []));
   848 
   849 store_pbt
   850  (prep_pbt thy "pbl_test_uni_poly_deg2_pq" [] e_pblID
   851  (["pq_formula","degree_two","polynomial","univariate","equation","test"],
   852   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   853    ("#Find"  ,["solutions v_v'i'"]) 
   854   ],
   855   e_rls, SOME "solve (v_v ^^^2 + p_p * v_v + q__q = 0, v_v)", []));
   856 
   857 store_pbt
   858  (prep_pbt thy "pbl_test_uni_poly_deg2_abc" [] e_pblID
   859  (["abc_formula","degree_two","polynomial","univariate","equation","test"],
   860   [("#Given" ,["equality (a_a * x ^^^2 + b_b * x + c_c = 0)","solveFor v_v"]),
   861    ("#Find"  ,["solutions v_v'i'"]) 
   862   ],
   863   e_rls, SOME "solve (a_a * x ^^^2 + b_b * x + c_c = 0, v_v)", []));
   864 
   865 *}
   866 ML {*
   867 store_pbt
   868  (prep_pbt thy "pbl_test_uni_root" [] e_pblID
   869  (["squareroot","univariate","equation","test"],
   870   [("#Given" ,["equality e_e","solveFor v_v"]),
   871    ("#Where" ,["precond_rootpbl v_v"]),
   872    ("#Find"  ,["solutions v_v'i'"]) 
   873   ],
   874   append_rls "contains_root" e_rls [Calc ("Test.contains'_root",
   875 			  eval_contains_root "#contains_root_")], 
   876   SOME "solve (e_e::bool, v_v)", [["Test","square_equation"]]));
   877 
   878 store_pbt
   879  (prep_pbt thy "pbl_test_uni_norm" [] e_pblID
   880  (["normalize","univariate","equation","test"],
   881   [("#Given" ,["equality e_e","solveFor v_v"]),
   882    ("#Where" ,[]),
   883    ("#Find"  ,["solutions v_v'i'"]) 
   884   ],
   885   e_rls, SOME "solve (e_e::bool, v_v)", [["Test","norm_univar_equation"]]));
   886 
   887 store_pbt
   888  (prep_pbt thy "pbl_test_uni_roottest" [] e_pblID
   889  (["sqroot-test","univariate","equation","test"],
   890   [("#Given" ,["equality e_e","solveFor v_v"]),
   891    ("#Where" ,["precond_rootpbl v_v"]),
   892    ("#Find"  ,["solutions v_v'i'"]) 
   893   ],
   894   e_rls, SOME "solve (e_e::bool, v_v)", []));
   895 
   896 store_pbt
   897  (prep_pbt thy "pbl_test_intsimp" [] e_pblID
   898  (["inttype","test"],
   899   [("#Given" ,["intTestGiven t_t"]),
   900    ("#Where" ,[]),
   901    ("#Find"  ,["intTestFind s_s"]) 
   902   ],
   903   e_rls, NONE, [["Test","intsimp"]])); 
   904 (*
   905 show_ptyps();
   906 get_pbt ["inttype","test"];
   907 *)
   908 
   909 *}
   910 
   911 ML {*
   912 store_met
   913  (prep_met thy  "met_test_sqrt" [] e_metID
   914 (*root-equation, version for tests before 8.01.01*)
   915  (["Test","sqrt-equ-test"]:metID,
   916   [("#Given" ,["equality e_e","solveFor v_v"]),
   917    ("#Where" ,["contains_root (e_e::bool)"]),
   918    ("#Find"  ,["solutions v_v'i'"])
   919    ],
   920   {rew_ord'="e_rew_ord",rls'=tval_rls,
   921    srls =append_rls "srls_contains_root" e_rls 
   922 		    [Calc ("Test.contains'_root",eval_contains_root "")],
   923    prls =append_rls "prls_contains_root" e_rls 
   924 		    [Calc ("Test.contains'_root",eval_contains_root "")],
   925    calc=[],
   926    crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
   927    asm_thm=[("square_equation_left",""),
   928 	    ("square_equation_right","")]*)},
   929  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
   930  "(let e_e = " ^
   931  "   ((While (contains_root e_e) Do" ^
   932  "      ((Rewrite square_equation_left True) @@" ^
   933  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
   934  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
   935  "       (Try (Rewrite_Set isolate_root False)) @@" ^
   936  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
   937  "    (Try (Rewrite_Set norm_equation False)) @@" ^
   938  "    (Try (Rewrite_Set Test_simplify False)) @@" ^
   939  "    (Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@" ^
   940  "    (Try (Rewrite_Set Test_simplify False)))" ^
   941  "   e_e" ^
   942  " in [e_e::bool])"
   943   ));
   944 
   945 *}
   946 ML {*
   947 store_met
   948  (prep_met thy  "met_test_sqrt2" [] e_metID
   949 (*root-equation ... for test-*.sml until 8.01*)
   950  (["Test","squ-equ-test2"]:metID,
   951   [("#Given" ,["equality e_e","solveFor v_v"]),
   952    ("#Find"  ,["solutions v_v'i'"])
   953    ],
   954   {rew_ord'="e_rew_ord",rls'=tval_rls,
   955    srls = append_rls "srls_contains_root" e_rls 
   956 		     [Calc ("Test.contains'_root",eval_contains_root"")],
   957    prls=e_rls,calc=[],
   958    crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
   959    asm_thm=[("square_equation_left",""),
   960 	    ("square_equation_right","")]*)},
   961  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
   962  "(let e_e = " ^
   963  "   ((While (contains_root e_e) Do" ^
   964  "      ((Rewrite square_equation_left True) @@" ^
   965  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
   966  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
   967  "       (Try (Rewrite_Set isolate_root False)) @@" ^
   968  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
   969  "    (Try (Rewrite_Set norm_equation False)) @@" ^
   970  "    (Try (Rewrite_Set Test_simplify False)) @@" ^
   971  "    (Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@" ^
   972  "    (Try (Rewrite_Set Test_simplify False)))" ^
   973  "   e_e;" ^
   974  "  (L_L::bool list) = Tac subproblem_equation_dummy;          " ^
   975  "  L_L = Tac solve_equation_dummy                             " ^
   976  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
   977   ));
   978 
   979 *}
   980 ML {*
   981 store_met
   982  (prep_met thy "met_test_squ_sub" [] e_metID
   983 (*tests subproblem fixed linear*)
   984  (["Test","squ-equ-test-subpbl1"]:metID,
   985   [("#Given" ,["equality e_e","solveFor v_v"]),
   986    ("#Where" ,["precond_rootmet v_v"]),
   987    ("#Find"  ,["solutions v_v'i'"])
   988    ],
   989   {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
   990    prls = append_rls "prls_met_test_squ_sub" e_rls
   991      [Calc ("Test.precond'_rootmet", eval_precond_rootmet "")],
   992    calc=[], crls=tval_rls, errpats = [], nrls = Test_simplify},
   993   "Script Solve_root_equation (e_e::bool) (v_v::real) =       " ^
   994   " (let e_e = ((Try (Rewrite_Set norm_equation False)) @@    " ^
   995   "            (Try (Rewrite_Set Test_simplify False))) e_e;  " ^
   996   "     (L_L::bool list) =                                    " ^
   997   "            (SubProblem (Test',                            " ^
   998   "                         [linear,univariate,equation,test]," ^
   999   "                         [Test,solve_linear])              " ^
  1000   "                        [BOOL e_e, REAL v_v])              " ^
  1001   "  in Check_elementwise L_L {(v_v::real). Assumptions})     "
  1002   ));
  1003 
  1004 *}
  1005 ML {*
  1006 store_met
  1007  (prep_met thy "met_test_squ_sub2" [] e_metID
  1008  (*tests subproblem fixed degree 2*)
  1009  (["Test","squ-equ-test-subpbl2"]:metID,
  1010   [("#Given" ,["equality e_e","solveFor v_v"]),
  1011    ("#Find"  ,["solutions v_v'i'"])
  1012    ],
  1013   {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,prls=e_rls,calc=[],
  1014     crls=tval_rls, errpats = [], nrls = e_rls(*,
  1015    asm_rls=[],asm_thm=[("square_equation_left",""),
  1016 	    ("square_equation_right","")]*)},
  1017    "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1018    " (let e_e = Try (Rewrite_Set norm_equation False) e_e;              " ^
  1019    "(L_L::bool list) = (SubProblem (Test',[linear,univariate,equation,test]," ^
  1020    "                    [Test,solve_by_pq_formula]) [BOOL e_e, REAL v_v])" ^
  1021    "in Check_elementwise L_L {(v_v::real). Assumptions})"
  1022    )); 
  1023 
  1024 *}
  1025 ML {*
  1026 store_met
  1027  (prep_met thy "met_test_squ_nonterm" [] e_metID
  1028  (*root-equation: see foils..., but notTerminating*)
  1029  (["Test","square_equation...notTerminating"]:metID,
  1030   [("#Given" ,["equality e_e","solveFor v_v"]),
  1031    ("#Find"  ,["solutions v_v'i'"])
  1032    ],
  1033   {rew_ord'="e_rew_ord",rls'=tval_rls,
  1034    srls = append_rls "srls_contains_root" e_rls 
  1035 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1036    prls=e_rls,calc=[],
  1037     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1038    asm_thm=[("square_equation_left",""),
  1039 	    ("square_equation_right","")]*)},
  1040  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1041  "(let e_e = " ^
  1042  "   ((While (contains_root e_e) Do" ^
  1043  "      ((Rewrite square_equation_left True) @@" ^
  1044  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1045  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1046  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1047  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1048  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1049  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1050  "   e_e;" ^
  1051  "  (L_L::bool list) =                                        " ^
  1052  "    (SubProblem (Test',[linear,univariate,equation,test]," ^
  1053  "                 [Test,solve_linear]) [BOOL e_e, REAL v_v])" ^
  1054  "in Check_elementwise L_L {(v_v::real). Assumptions})"
  1055   ));
  1056 
  1057 *}
  1058 ML {*
  1059 store_met
  1060  (prep_met thy  "met_test_eq1" [] e_metID
  1061 (*root-equation1:*)
  1062  (["Test","square_equation1"]:metID,
  1063    [("#Given" ,["equality e_e","solveFor v_v"]),
  1064     ("#Find"  ,["solutions v_v'i'"])
  1065     ],
  1066    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1067    srls = append_rls "srls_contains_root" e_rls 
  1068 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1069    prls=e_rls,calc=[],
  1070     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1071    asm_thm=[("square_equation_left",""),
  1072 	    ("square_equation_right","")]*)},
  1073  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1074  "(let e_e = " ^
  1075  "   ((While (contains_root e_e) Do" ^
  1076  "      ((Rewrite square_equation_left True) @@" ^
  1077  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1078  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1079  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1080  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1081  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1082  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1083  "   e_e;" ^
  1084  "  (L_L::bool list) = (SubProblem (Test',[linear,univariate,equation,test]," ^
  1085  "                    [Test,solve_linear]) [BOOL e_e, REAL v_v])" ^
  1086  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1087   ));
  1088 
  1089 *}
  1090 ML {*
  1091 store_met
  1092  (prep_met thy "met_test_squ2" [] e_metID
  1093  (*root-equation2*)
  1094  (["Test","square_equation2"]:metID,
  1095    [("#Given" ,["equality e_e","solveFor v_v"]),
  1096     ("#Find"  ,["solutions v_v'i'"])
  1097     ],
  1098    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1099    srls = append_rls "srls_contains_root" e_rls 
  1100 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1101    prls=e_rls,calc=[],
  1102     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1103    asm_thm=[("square_equation_left",""),
  1104 	    ("square_equation_right","")]*)},
  1105  "Script Solve_root_equation (e_e::bool) (v_v::real)  =  " ^
  1106  "(let e_e = " ^
  1107  "   ((While (contains_root e_e) Do" ^
  1108  "      (((Rewrite square_equation_left True) Or " ^
  1109  "        (Rewrite square_equation_right True)) @@" ^
  1110  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1111  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1112  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1113  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1114  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1115  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1116  "   e_e;" ^
  1117  "  (L_L::bool list) = (SubProblem (Test',[plain_square,univariate,equation,test]," ^
  1118  "                    [Test,solve_plain_square]) [BOOL e_e, REAL v_v])" ^
  1119  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1120   ));
  1121 
  1122 *}
  1123 ML {*
  1124 store_met
  1125  (prep_met thy "met_test_squeq" [] e_metID
  1126  (*root-equation*)
  1127  (["Test","square_equation"]:metID,
  1128    [("#Given" ,["equality e_e","solveFor v_v"]),
  1129     ("#Find"  ,["solutions v_v'i'"])
  1130     ],
  1131    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1132    srls = append_rls "srls_contains_root" e_rls 
  1133 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1134    prls=e_rls,calc=[],
  1135     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1136    asm_thm=[("square_equation_left",""),
  1137 	    ("square_equation_right","")]*)},
  1138  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1139  "(let e_e = " ^
  1140  "   ((While (contains_root e_e) Do" ^
  1141  "      (((Rewrite square_equation_left True) Or" ^
  1142  "        (Rewrite square_equation_right True)) @@" ^
  1143  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1144  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1145  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1146  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1147  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1148  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1149  "   e_e;" ^
  1150  "  (L_L::bool list) = (SubProblem (Test',[univariate,equation,test]," ^
  1151  "                    [no_met]) [BOOL e_e, REAL v_v])" ^
  1152  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1153   ) ); (*#######*)
  1154 
  1155 *}
  1156 ML {*
  1157 store_met
  1158  (prep_met thy "met_test_eq_plain" [] e_metID
  1159  (*solve_plain_square*)
  1160  (["Test","solve_plain_square"]:metID,
  1161    [("#Given",["equality e_e","solveFor v_v"]),
  1162    ("#Where" ,["(matches (?a + ?b*v_v ^^^2 = 0) e_e) |" ^
  1163 	       "(matches (     ?b*v_v ^^^2 = 0) e_e) |" ^
  1164 	       "(matches (?a +    v_v ^^^2 = 0) e_e) |" ^
  1165 	       "(matches (        v_v ^^^2 = 0) e_e)"]), 
  1166    ("#Find"  ,["solutions v_v'i'"]) 
  1167    ],
  1168    {rew_ord'="e_rew_ord",rls'=tval_rls,calc=[],srls=e_rls,
  1169     prls = assoc_rls "matches",
  1170     crls=tval_rls, errpats = [], nrls = e_rls(*,
  1171     asm_rls=[],asm_thm=[]*)},
  1172   "Script Solve_plain_square (e_e::bool) (v_v::real) =           " ^
  1173    " (let e_e = ((Try (Rewrite_Set isolate_bdv False)) @@         " ^
  1174    "            (Try (Rewrite_Set Test_simplify False)) @@     " ^
  1175    "            ((Rewrite square_equality_0 False) Or        " ^
  1176    "             (Rewrite square_equality True)) @@            " ^
  1177    "            (Try (Rewrite_Set tval_rls False))) e_e             " ^
  1178    "  in ((Or_to_List e_e)::bool list))"
  1179  ));
  1180 
  1181 *}
  1182 
  1183 ML {*
  1184 store_met
  1185  (prep_met thy "met_test_norm_univ" [] e_metID
  1186  (["Test","norm_univar_equation"]:metID,
  1187    [("#Given",["equality e_e","solveFor v_v"]),
  1188    ("#Where" ,[]), 
  1189    ("#Find"  ,["solutions v_v'i'"]) 
  1190    ],
  1191    {rew_ord'="e_rew_ord",rls'=tval_rls,srls = e_rls,prls=e_rls,
  1192    calc=[],
  1193     crls=tval_rls, errpats = [], nrls = e_rls},
  1194   "Script Norm_univar_equation (e_e::bool) (v_v::real) =      " ^
  1195    " (let e_e = ((Try (Rewrite rnorm_equation_add False)) @@   " ^
  1196    "            (Try (Rewrite_Set Test_simplify False))) e_e   " ^
  1197    "  in (SubProblem (Test',[univariate,equation,test],         " ^
  1198    "                    [no_met]) [BOOL e_e, REAL v_v]))"
  1199  ));
  1200 
  1201 (*17.9.02 aus SqRoot.ML------------------------------^^^---*)  
  1202 
  1203 store_met
  1204 (prep_met thy "met_test_intsimp" [] e_metID
  1205  (["Test","intsimp"]:metID,
  1206   [("#Given" ,["intTestGiven t_t"]),
  1207    ("#Where" ,[]),
  1208    ("#Find"  ,["intTestFind s_s"]) 
  1209   ],
  1210    {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
  1211     prls = e_rls, calc = [], crls = tval_rls, errpats = [], nrls = Test_simplify},
  1212  "Script STest_simplify (t_t::int) =                  " ^
  1213  "(Repeat                                                          " ^
  1214  "    ((Try (Calculate PLUS)) @@  " ^
  1215  "     (Try (Calculate TIMES))) t_t::int)"
  1216  ));
  1217 
  1218 *}
  1219 
  1220 ML {*
  1221 (*8.4.03  aus Poly.ML--------------------------------vvv---
  1222   make_polynomial  ---> make_poly
  1223   ^-- for user          ^-- for systest _ONLY_*)  
  1224 
  1225 local (*. for make_polytest .*)
  1226 
  1227 open Term;  (* for type order = EQUAL | LESS | GREATER *)
  1228 
  1229 fun pr_ord EQUAL = "EQUAL"
  1230   | pr_ord LESS  = "LESS"
  1231   | pr_ord GREATER = "GREATER";
  1232 
  1233 fun dest_hd' (Const (a, T)) =                          (* ~ term.ML *)
  1234   (case a of
  1235      "Atools.pow" => ((("|||||||||||||", 0), T), 0)           (*WN greatest *)
  1236    | _ => (((a, 0), T), 0))
  1237   | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
  1238   | dest_hd' (Var v) = (v, 2)
  1239   | dest_hd' (Bound i) = ((("", i), dummyT), 3)
  1240   | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
  1241 (* RL *)
  1242 fun get_order_pow (t $ (Free(order,_))) = 
  1243     	(case int_of_str (order) of
  1244 	             SOME d => d
  1245 		   | NONE   => 0)
  1246   | get_order_pow _ = 0;
  1247 
  1248 fun size_of_term' (Const(str,_) $ t) =
  1249   if "Atools.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*)
  1250   | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
  1251   | size_of_term' (f$t) = size_of_term' f  +  size_of_term' t
  1252   | size_of_term' _ = 1;
  1253 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
  1254     (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) 
  1255                                    | ord => ord)
  1256   | term_ord' pr thy (t, u) =
  1257     (if pr then 
  1258 	 let val (f, ts) = strip_comb t and (g, us) = strip_comb u;
  1259 	     val _ = tracing ("t= f@ts= \"" ^ term2str f ^ "\" @ \"[" ^
  1260 	                      commas(map term2str ts) ^ "]\"")
  1261 	     val _ = tracing ("u= g@us= \"" ^ term2str g ^"\" @ \"[" ^
  1262 	                      commas(map term2str us) ^"]\"")
  1263 	     val _ = tracing ("size_of_term(t,u)= (" ^
  1264 	                      string_of_int (size_of_term' t) ^ ", " ^
  1265 	                      string_of_int (size_of_term' u) ^ ")")
  1266 	     val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o hd_ord) (f,g))
  1267 	     val _ = tracing ("terms_ord(ts,us) = " ^
  1268 			      (pr_ord o terms_ord str false) (ts,us));
  1269 	     val _ = tracing "-------"
  1270 	 in () end
  1271        else ();
  1272 	 case int_ord (size_of_term' t, size_of_term' u) of
  1273 	   EQUAL =>
  1274 	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
  1275 	       (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us) 
  1276 	     | ord => ord)
  1277 	     end
  1278 	 | ord => ord)
  1279 and hd_ord (f, g) =                                        (* ~ term.ML *)
  1280   prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
  1281 and terms_ord str pr (ts, us) = 
  1282     list_ord (term_ord' pr (assoc_thy "Isac"))(ts, us);
  1283 in
  1284 
  1285 fun ord_make_polytest (pr:bool) thy (_:subst) tu = 
  1286     (term_ord' pr thy(***) tu = LESS );
  1287 
  1288 end;(*local*)
  1289 *}
  1290 ML {*
  1291 
  1292 rew_ord' := overwritel (!rew_ord',
  1293 [("termlessI", termlessI),
  1294  ("ord_make_polytest", ord_make_polytest false thy)
  1295  ]);
  1296 
  1297 (*WN060510 this was a preparation for prep_rls ...
  1298 val scr_make_polytest = 
  1299 "Script Expand_binomtest t_t =" ^
  1300 "(Repeat                       " ^
  1301 "((Try (Repeat (Rewrite real_diff_minus         False))) @@ " ^ 
  1302 
  1303 " (Try (Repeat (Rewrite distrib_right   False))) @@ " ^	 
  1304 " (Try (Repeat (Rewrite distrib_left  False))) @@ " ^	
  1305 " (Try (Repeat (Rewrite left_diff_distrib  False))) @@ " ^	
  1306 " (Try (Repeat (Rewrite right_diff_distrib False))) @@ " ^	
  1307 
  1308 " (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^		   
  1309 " (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^		   
  1310 " (Try (Repeat (Rewrite add_0_left      False))) @@ " ^	 
  1311 
  1312 " (Try (Repeat (Rewrite mult_commute       False))) @@ " ^		
  1313 " (Try (Repeat (Rewrite real_mult_left_commute  False))) @@ " ^	
  1314 " (Try (Repeat (Rewrite mult_assoc         False))) @@ " ^		
  1315 " (Try (Repeat (Rewrite add_commute        False))) @@ " ^		
  1316 " (Try (Repeat (Rewrite add_left_commute   False))) @@ " ^	 
  1317 " (Try (Repeat (Rewrite add_assoc          False))) @@ " ^	 
  1318 
  1319 " (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^	 
  1320 " (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^	 
  1321 " (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^		
  1322 " (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^		
  1323 
  1324 " (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^		
  1325 " (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^	
  1326 
  1327 " (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^		
  1328 " (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^   
  1329 
  1330 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1331 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1332 " (Try (Repeat (Calculate POWER)))) " ^  
  1333 " t_t)";
  1334 -----------------------------------------------------*)
  1335 
  1336 val make_polytest =
  1337   Rls{id = "make_polytest", preconds = []:term list, 
  1338       rew_ord = ("ord_make_polytest", ord_make_polytest false @{theory "Poly"}),
  1339       erls = testerls, srls = Erls,
  1340       calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
  1341 	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
  1342 	      ("POWER", ("Atools.pow", eval_binop "#power_"))
  1343 	      ], errpatts = [],
  1344       rules = [Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
  1345 	       (*"a - b = a + (-1) * b"*)
  1346 	       Thm ("distrib_right" ,num_str @{thm distrib_right}),
  1347 	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
  1348 	       Thm ("distrib_left",num_str @{thm distrib_left}),
  1349 	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
  1350 	       Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),
  1351 	       (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
  1352 	       Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),
  1353 	       (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
  1354 	       Thm ("mult_1_left",num_str @{thm mult_1_left}),                 
  1355 	       (*"1 * z = z"*)
  1356 	       Thm ("mult_zero_left",num_str @{thm mult_zero_left}),        
  1357 	       (*"0 * z = 0"*)
  1358 	       Thm ("add_0_left",num_str @{thm add_0_left}),
  1359 	       (*"0 + z = z"*)
  1360 
  1361 	       (*AC-rewriting*)
  1362 	       Thm ("mult_commute",num_str @{thm mult_commute}),
  1363 	       (* z * w = w * z *)
  1364 	       Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
  1365 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
  1366 	       Thm ("mult_assoc",num_str @{thm mult_assoc}),		
  1367 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
  1368 	       Thm ("add_commute",num_str @{thm add_commute}),	
  1369 	       (*z + w = w + z*)
  1370 	       Thm ("add_left_commute",num_str @{thm add_left_commute}),
  1371 	       (*x + (y + z) = y + (x + z)*)
  1372 	       Thm ("add_assoc",num_str @{thm add_assoc}),	               
  1373 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
  1374 
  1375 	       Thm ("sym_realpow_twoI",
  1376                      num_str (@{thm realpow_twoI} RS @{thm sym})),	
  1377 	       (*"r1 * r1 = r1 ^^^ 2"*)
  1378 	       Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),		
  1379 	       (*"r * r ^^^ n = r ^^^ (n + 1)"*)
  1380 	       Thm ("sym_real_mult_2",
  1381                      num_str (@{thm real_mult_2} RS @{thm sym})),	
  1382 	       (*"z1 + z1 = 2 * z1"*)
  1383 	       Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),	
  1384 	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
  1385 
  1386 	       Thm ("real_num_collect",num_str @{thm real_num_collect}), 
  1387 	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
  1388 	       Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
  1389 	       (*"[| l is_const; m is_const |] ==>  
  1390 				l * n + (m * n + k) =  (l + m) * n + k"*)
  1391 	       Thm ("real_one_collect",num_str @{thm real_one_collect}),	
  1392 	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
  1393 	       Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
  1394 	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
  1395 
  1396 	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1397 	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1398 	       Calc ("Atools.pow", eval_binop "#power_")
  1399 	       ],
  1400       scr = EmptyScr(*Prog ((term_of o the o (parse thy)) 
  1401       scr_make_polytest)*)
  1402       }:rls; 
  1403 *}
  1404 ML {*     
  1405 (*WN060510 this was done before 'fun prep_rls' ...------------------------
  1406 val scr_expand_binomtest =
  1407 "Script Expand_binomtest t_t =" ^
  1408 "(Repeat                       " ^
  1409 "((Try (Repeat (Rewrite real_plus_binom_pow2    False))) @@ " ^
  1410 " (Try (Repeat (Rewrite real_plus_binom_times   False))) @@ " ^
  1411 " (Try (Repeat (Rewrite real_minus_binom_pow2   False))) @@ " ^
  1412 " (Try (Repeat (Rewrite real_minus_binom_times  False))) @@ " ^
  1413 " (Try (Repeat (Rewrite real_plus_minus_binom1  False))) @@ " ^
  1414 " (Try (Repeat (Rewrite real_plus_minus_binom2  False))) @@ " ^
  1415 
  1416 " (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^
  1417 " (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^
  1418 " (Try (Repeat (Rewrite add_0_left      False))) @@ " ^
  1419 
  1420 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1421 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1422 " (Try (Repeat (Calculate POWER))) @@ " ^
  1423 
  1424 " (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^
  1425 " (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^
  1426 " (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^
  1427 " (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^
  1428 
  1429 " (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^
  1430 " (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^
  1431 
  1432 " (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^
  1433 " (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^ 
  1434 
  1435 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1436 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1437 " (Try (Repeat (Calculate POWER)))) " ^  
  1438 " t_t)";
  1439 --------------------------------------------------------------------------*)
  1440 
  1441 val expand_binomtest =
  1442   Rls{id = "expand_binomtest", preconds = [], 
  1443       rew_ord = ("termlessI",termlessI),
  1444       erls = testerls, srls = Erls,
  1445       calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
  1446 	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
  1447 	      ("POWER", ("Atools.pow", eval_binop "#power_"))
  1448 	      ], errpatts = [],
  1449       rules = 
  1450       [Thm ("real_plus_binom_pow2"  ,num_str @{thm real_plus_binom_pow2}),     
  1451 	       (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
  1452        Thm ("real_plus_binom_times" ,num_str @{thm real_plus_binom_times}),    
  1453 	      (*"(a + b)*(a + b) = ...*)
  1454        Thm ("real_minus_binom_pow2" ,num_str @{thm real_minus_binom_pow2}),   
  1455        (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
  1456        Thm ("real_minus_binom_times",num_str @{thm real_minus_binom_times}),   
  1457        (*"(a - b)*(a - b) = ...*)
  1458        Thm ("real_plus_minus_binom1",num_str @{thm real_plus_minus_binom1}),   
  1459         (*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
  1460        Thm ("real_plus_minus_binom2",num_str @{thm real_plus_minus_binom2}),   
  1461         (*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
  1462        (*RL 020915*)
  1463        Thm ("real_pp_binom_times",num_str @{thm real_pp_binom_times}), 
  1464         (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
  1465        Thm ("real_pm_binom_times",num_str @{thm real_pm_binom_times}), 
  1466         (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
  1467        Thm ("real_mp_binom_times",num_str @{thm real_mp_binom_times}), 
  1468         (*(a - b)*(c p d) = a*c + a*d - b*c - b*d*)
  1469        Thm ("real_mm_binom_times",num_str @{thm real_mm_binom_times}), 
  1470         (*(a - b)*(c p d) = a*c - a*d - b*c + b*d*)
  1471        Thm ("realpow_multI",num_str @{thm realpow_multI}),                
  1472         (*(a*b)^^^n = a^^^n * b^^^n*)
  1473        Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
  1474         (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
  1475        Thm ("real_minus_binom_pow3",num_str @{thm real_minus_binom_pow3}),
  1476         (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
  1477 
  1478 
  1479      (*  Thm ("distrib_right" ,num_str @{thm distrib_right}),	
  1480 	 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
  1481 	Thm ("distrib_left",num_str @{thm distrib_left}),	
  1482 	(*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
  1483 	Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),	
  1484 	(*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
  1485 	Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),	
  1486 	(*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
  1487 	*)
  1488 	
  1489 	Thm ("mult_1_left",num_str @{thm mult_1_left}),              
  1490          (*"1 * z = z"*)
  1491 	Thm ("mult_zero_left",num_str @{thm mult_zero_left}),              
  1492          (*"0 * z = 0"*)
  1493 	Thm ("add_0_left",num_str @{thm add_0_left}),
  1494          (*"0 + z = z"*)
  1495 
  1496 	Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1497 	Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1498 	Calc ("Atools.pow", eval_binop "#power_"),
  1499         (*	       
  1500 	 Thm ("mult_commute",num_str @{thm mult_commute}),		
  1501         (*AC-rewriting*)
  1502 	Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
  1503 	Thm ("mult_assoc",num_str @{thm mult_assoc}),
  1504 	Thm ("add_commute",num_str @{thm add_commute}),	
  1505 	Thm ("add_left_commute",num_str @{thm add_left_commute}),
  1506 	Thm ("add_assoc",num_str @{thm add_assoc}),
  1507 	*)
  1508 	
  1509 	Thm ("sym_realpow_twoI",
  1510               num_str (@{thm realpow_twoI} RS @{thm sym})),
  1511 	(*"r1 * r1 = r1 ^^^ 2"*)
  1512 	Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),			
  1513 	(*"r * r ^^^ n = r ^^^ (n + 1)"*)
  1514 	(*Thm ("sym_real_mult_2",
  1515                 num_str (@{thm real_mult_2} RS @{thm sym})),
  1516 	(*"z1 + z1 = 2 * z1"*)*)
  1517 	Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),		
  1518 	(*"z1 + (z1 + k) = 2 * z1 + k"*)
  1519 
  1520 	Thm ("real_num_collect",num_str @{thm real_num_collect}), 
  1521 	(*"[| l is_const; m is_const |] ==> l * n + m * n = (l + m) * n"*)
  1522 	Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),	
  1523 	(*"[| l is_const; m is_const |] ==>  l * n + (m * n + k) =  (l + m) * n + k"*)
  1524 	Thm ("real_one_collect",num_str @{thm real_one_collect}),		
  1525 	(*"m is_const ==> n + m * n = (1 + m) * n"*)
  1526 	Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
  1527 	(*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
  1528 
  1529 	Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1530 	Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1531 	Calc ("Atools.pow", eval_binop "#power_")
  1532 	],
  1533       scr = EmptyScr
  1534 (*Script ((term_of o the o (parse thy)) scr_expand_binomtest)*)
  1535       }:rls;      
  1536 
  1537 
  1538 ruleset' := overwritelthy @{theory} (!ruleset',
  1539    [("make_polytest", prep_rls make_polytest),
  1540     ("expand_binomtest", prep_rls expand_binomtest)
  1541     ]);
  1542 *}
  1543 setup {* KEStore_Elems.add_rlss 
  1544   [("make_polytest", (Context.theory_name @{theory}, prep_rls make_polytest)), 
  1545   ("expand_binomtest", (Context.theory_name @{theory}, prep_rls expand_binomtest))] *}
  1546 
  1547 end