src/Tools/isac/Knowledge/Test.thy
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 16 Sep 2013 12:20:00 +0200
changeset 52105 2786cc9704c8
parent 52070 77138c64f4f6
child 52125 6f1d3415dc68
permissions -rw-r--r--
Test_Isac works again, perfectly ..

# the same tests works as in 8df4b6196660 (the *child* of "Test_Isac works...")
# ..EXCEPT those marked with "exception Div raised"
# for general state of tests see Test_Isac section {* history of tests *}.
     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 
   310 (*make () dissappear*)   
   311 val rearrange_assoc =
   312   Rls{id = "rearrange_assoc", preconds = [], 
   313       rew_ord = ("e_rew_ord",e_rew_ord), 
   314       erls = e_rls, srls = e_rls, calc = [], errpatts = [],
   315       rules = 
   316       [Thm ("sym_add_assoc",num_str (@{thm add_assoc} RS @{thm sym})),
   317        Thm ("sym_rmult_assoc",num_str (@{thm rmult_assoc} RS @{thm sym}))],
   318       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   319       }:rls;      
   320 
   321 val ac_plus_times =
   322   Rls{id = "ac_plus_times", preconds = [], rew_ord = ("term_order",term_order),
   323       erls = e_rls, srls = e_rls, calc = [], errpatts = [],
   324       rules = 
   325       [Thm ("radd_commute",num_str @{thm radd_commute}),
   326        Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
   327        Thm ("add_assoc",num_str @{thm add_assoc}),
   328        Thm ("rmult_commute",num_str @{thm rmult_commute}),
   329        Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
   330        Thm ("rmult_assoc",num_str @{thm rmult_assoc})],
   331       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   332       }:rls;      
   333 
   334 (*todo: replace by Rewrite("rnorm_equation_add",num_str @{thm rnorm_equation_add)*)
   335 val norm_equation =
   336   Rls{id = "norm_equation", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
   337       erls = tval_rls, srls = e_rls, calc = [], errpatts = [],
   338       rules = [Thm ("rnorm_equation_add",num_str @{thm rnorm_equation_add})
   339 	       ],
   340       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   341       }:rls;      
   342 *}
   343 ML {*
   344 (** rule sets **)
   345 
   346 val STest_simplify =     (*   vv--- not changed to real by parse*)
   347   "Script STest_simplify (t_t::'z) =                           " ^
   348   "(Repeat" ^
   349   "    ((Try (Repeat (Rewrite real_diff_minus False))) @@        " ^
   350   "     (Try (Repeat (Rewrite radd_mult_distrib2 False))) @@  " ^
   351   "     (Try (Repeat (Rewrite rdistr_right_assoc False))) @@  " ^
   352   "     (Try (Repeat (Rewrite rdistr_right_assoc_p False))) @@" ^
   353   "     (Try (Repeat (Rewrite rdistr_div_right False))) @@    " ^
   354   "     (Try (Repeat (Rewrite rbinom_power_2 False))) @@      " ^
   355 	
   356   "     (Try (Repeat (Rewrite radd_commute False))) @@        " ^
   357   "     (Try (Repeat (Rewrite radd_left_commute False))) @@   " ^
   358   "     (Try (Repeat (Rewrite add_assoc False))) @@          " ^
   359   "     (Try (Repeat (Rewrite rmult_commute False))) @@       " ^
   360   "     (Try (Repeat (Rewrite rmult_left_commute False))) @@  " ^
   361   "     (Try (Repeat (Rewrite rmult_assoc False))) @@         " ^
   362 	
   363   "     (Try (Repeat (Rewrite radd_real_const_eq False))) @@   " ^
   364   "     (Try (Repeat (Rewrite radd_real_const False))) @@   " ^
   365   "     (Try (Repeat (Calculate PLUS))) @@   " ^
   366   "     (Try (Repeat (Calculate TIMES))) @@   " ^
   367   "     (Try (Repeat (Calculate divide_))) @@" ^
   368   "     (Try (Repeat (Calculate POWER))) @@  " ^
   369 	
   370   "     (Try (Repeat (Rewrite rcollect_right False))) @@   " ^
   371   "     (Try (Repeat (Rewrite rcollect_one_left False))) @@   " ^
   372   "     (Try (Repeat (Rewrite rcollect_one_left_assoc False))) @@   " ^
   373   "     (Try (Repeat (Rewrite rcollect_one_left_assoc_p False))) @@   " ^
   374 	
   375   "     (Try (Repeat (Rewrite rshift_nominator False))) @@   " ^
   376   "     (Try (Repeat (Rewrite rcancel_den False))) @@   " ^
   377   "     (Try (Repeat (Rewrite rroot_square_inv False))) @@   " ^
   378   "     (Try (Repeat (Rewrite rroot_times_root False))) @@   " ^
   379   "     (Try (Repeat (Rewrite rroot_times_root_assoc_p False))) @@   " ^
   380   "     (Try (Repeat (Rewrite rsqare False))) @@   " ^
   381   "     (Try (Repeat (Rewrite power_1 False))) @@   " ^
   382   "     (Try (Repeat (Rewrite rtwo_of_the_same False))) @@   " ^
   383   "     (Try (Repeat (Rewrite rtwo_of_the_same_assoc_p False))) @@   " ^
   384 	
   385   "     (Try (Repeat (Rewrite rmult_1 False))) @@   " ^
   386   "     (Try (Repeat (Rewrite rmult_1_right False))) @@   " ^
   387   "     (Try (Repeat (Rewrite rmult_0 False))) @@   " ^
   388   "     (Try (Repeat (Rewrite rmult_0_right False))) @@   " ^
   389   "     (Try (Repeat (Rewrite radd_0 False))) @@   " ^
   390   "     (Try (Repeat (Rewrite radd_0_right False)))) " ^
   391   " t_t)";
   392 
   393 *}
   394 ML {*
   395 (* expects * distributed over + *)
   396 val Test_simplify =
   397   Rls{id = "Test_simplify", preconds = [], 
   398       rew_ord = ("sqrt_right",sqrt_right false (Thy_Info.get_theory "Pure")),
   399       erls = tval_rls, srls = e_rls, 
   400       calc=[(*since 040209 filled by prep_rls*)], errpatts = [],
   401       rules = [
   402 	       Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
   403 	       Thm ("radd_mult_distrib2",num_str @{thm radd_mult_distrib2}),
   404 	       Thm ("rdistr_right_assoc",num_str @{thm rdistr_right_assoc}),
   405 	       Thm ("rdistr_right_assoc_p",num_str @{thm rdistr_right_assoc_p}),
   406 	       Thm ("rdistr_div_right",num_str @{thm rdistr_div_right}),
   407 	       Thm ("rbinom_power_2",num_str @{thm rbinom_power_2}),	       
   408 
   409                Thm ("radd_commute",num_str @{thm radd_commute}), 
   410 	       Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
   411 	       Thm ("add_assoc",num_str @{thm add_assoc}),
   412 	       Thm ("rmult_commute",num_str @{thm rmult_commute}),
   413 	       Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
   414 	       Thm ("rmult_assoc",num_str @{thm rmult_assoc}),
   415 
   416 	       Thm ("radd_real_const_eq",num_str @{thm radd_real_const_eq}),
   417 	       Thm ("radd_real_const",num_str @{thm radd_real_const}),
   418 	       (* these 2 rules are invers to distr_div_right wrt. termination.
   419 		  thus they MUST be done IMMEDIATELY before calc *)
   420 	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
   421 	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
   422 	       Calc ("Fields.inverse_class.divide", eval_cancel "#divide_e"),
   423 	       Calc ("Atools.pow", eval_binop "#power_"),
   424 
   425 	       Thm ("rcollect_right",num_str @{thm rcollect_right}),
   426 	       Thm ("rcollect_one_left",num_str @{thm rcollect_one_left}),
   427 	       Thm ("rcollect_one_left_assoc",num_str @{thm rcollect_one_left_assoc}),
   428 	       Thm ("rcollect_one_left_assoc_p",num_str @{thm rcollect_one_left_assoc_p}),
   429 
   430 	       Thm ("rshift_nominator",num_str @{thm rshift_nominator}),
   431 	       Thm ("rcancel_den",num_str @{thm rcancel_den}),
   432 	       Thm ("rroot_square_inv",num_str @{thm rroot_square_inv}),
   433 	       Thm ("rroot_times_root",num_str @{thm rroot_times_root}),
   434 	       Thm ("rroot_times_root_assoc_p",num_str @{thm rroot_times_root_assoc_p}),
   435 	       Thm ("rsqare",num_str @{thm rsqare}),
   436 	       Thm ("power_1",num_str @{thm power_1}),
   437 	       Thm ("rtwo_of_the_same",num_str @{thm rtwo_of_the_same}),
   438 	       Thm ("rtwo_of_the_same_assoc_p",num_str @{thm rtwo_of_the_same_assoc_p}),
   439 
   440 	       Thm ("rmult_1",num_str @{thm rmult_1}),
   441 	       Thm ("rmult_1_right",num_str @{thm rmult_1_right}),
   442 	       Thm ("rmult_0",num_str @{thm rmult_0}),
   443 	       Thm ("rmult_0_right",num_str @{thm rmult_0_right}),
   444 	       Thm ("radd_0",num_str @{thm radd_0}),
   445 	       Thm ("radd_0_right",num_str @{thm radd_0_right})
   446 	       ],
   447       scr = Prog ((term_of o the o (parse thy)) "empty_script")
   448 		    (*since 040209 filled by prep_rls: STest_simplify*)
   449       }:rls;      
   450 *}
   451 ML {*
   452 
   453 (** rule sets **)
   454 
   455 
   456 
   457 (*isolate the root in a root-equation*)
   458 val isolate_root =
   459   Rls{id = "isolate_root", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord), 
   460       erls=tval_rls,srls = e_rls, calc=[], errpatts = [],
   461       rules = [Thm ("rroot_to_lhs",num_str @{thm rroot_to_lhs}),
   462 	       Thm ("rroot_to_lhs_mult",num_str @{thm rroot_to_lhs_mult}),
   463 	       Thm ("rroot_to_lhs_add_mult",num_str @{thm rroot_to_lhs_add_mult}),
   464 	       Thm ("risolate_root_add",num_str @{thm risolate_root_add}),
   465 	       Thm ("risolate_root_mult",num_str @{thm risolate_root_mult}),
   466 	       Thm ("risolate_root_div",num_str @{thm risolate_root_div})       ],
   467       scr = Prog ((term_of o the o (parse thy)) 
   468       "empty_script")
   469       }:rls;
   470 
   471 (*isolate the bound variable in an equation; 'bdv' is a meta-constant*)
   472 val isolate_bdv =
   473     Rls{id = "isolate_bdv", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
   474 	erls=tval_rls,srls = e_rls, calc= [], errpatts = [],
   475 	rules = 
   476 	[Thm ("risolate_bdv_add",num_str @{thm risolate_bdv_add}),
   477 	 Thm ("risolate_bdv_mult_add",num_str @{thm risolate_bdv_mult_add}),
   478 	 Thm ("risolate_bdv_mult",num_str @{thm risolate_bdv_mult}),
   479 	 Thm ("mult_square",num_str @{thm mult_square}),
   480 	 Thm ("constant_square",num_str @{thm constant_square}),
   481 	 Thm ("constant_mult_square",num_str @{thm constant_mult_square})
   482 	 ],
   483 	scr = Prog ((term_of o the o (parse thy)) 
   484 			  "empty_script")
   485 	}:rls;      
   486 *}
   487 ML {*
   488 
   489 (* association list for calculate_, calculate
   490    "Groups.plus_class.plus" etc. not usable in scripts *)
   491 val calclist = 
   492     [
   493      (*as Tools.ML*)
   494      ("Vars"    ,("Tools.Vars"    ,eval_var "#Vars_")),
   495      ("matches",("Tools.matches",eval_matches "#matches_")),
   496      ("lhs"    ,("Tools.lhs"    ,eval_lhs "")),
   497      (*aus Atools.ML*)
   498      ("PLUS"    ,("Groups.plus_class.plus"        ,eval_binop "#add_")),
   499      ("TIMES"   ,("Groups.times_class.times"        ,eval_binop "#mult_")),
   500      ("DIVIDE" ,("Fields.inverse_class.divide"  ,eval_cancel "#divide_e")),
   501      ("POWER"  ,("Atools.pow"  ,eval_binop "#power_")),
   502      ("is_const",("Atools.is'_const",eval_const "#is_const_")),
   503      ("le"      ,("Orderings.ord_class.less"        ,eval_equ "#less_")),
   504      ("leq"     ,("Orderings.ord_class.less_eq"       ,eval_equ "#less_equal_")),
   505      ("ident"   ,("Atools.ident",eval_ident "#ident_")),
   506      (*von hier (ehem.SqRoot*)
   507      ("sqrt"    ,("NthRoot.sqrt"   ,eval_sqrt "#sqrt_")),
   508      ("Test.is_root_free",("is'_root'_free", eval_root_free"#is_root_free_e")),
   509      ("Test.contains_root",("contains'_root",
   510 			    eval_contains_root"#contains_root_"))
   511      ];
   512 
   513 ruleset' := overwritelthy @{theory} (!ruleset',
   514   [("Test_simplify", prep_rls Test_simplify),
   515    ("tval_rls", prep_rls tval_rls),
   516    ("isolate_root", prep_rls isolate_root),
   517    ("isolate_bdv", prep_rls isolate_bdv),
   518    ("matches", 
   519     prep_rls (append_rls "matches" testerls 
   520 			 [Calc ("Tools.matches",eval_matches "#matches_")]))
   521    ]);
   522 
   523 *}
   524 ML {*
   525 (** problem types **)
   526 store_pbt
   527  (prep_pbt thy "pbl_test" [] e_pblID
   528  (["test"],
   529   [],
   530   e_rls, NONE, []));
   531 store_pbt
   532  (prep_pbt thy "pbl_test_equ" [] e_pblID
   533  (["equation","test"],
   534   [("#Given" ,["equality e_e","solveFor v_v"]),
   535    ("#Where" ,["matches (?a = ?b) e_e"]),
   536    ("#Find"  ,["solutions v_v'i'"])
   537   ],
   538   assoc_rls "matches",
   539   SOME "solve (e_e::bool, v_v)", []));
   540 
   541 store_pbt
   542  (prep_pbt thy "pbl_test_uni" [] e_pblID
   543  (["univariate","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_lin" [] e_pblID
   553  (["linear","univariate","equation","test"],
   554   [("#Given" ,["equality e_e","solveFor v_v"]),
   555    ("#Where" ,["(matches (   v_v = 0) e_e) | (matches (   ?b*v_v = 0) e_e) |" ^
   556 	       "(matches (?a+v_v = 0) e_e) | (matches (?a+?b*v_v = 0) e_e)  "]),
   557    ("#Find"  ,["solutions v_v'i'"])
   558   ],
   559   assoc_rls "matches", 
   560   SOME "solve (e_e::bool, v_v)", [["Test","solve_linear"]]));
   561 
   562 (*25.8.01 ------
   563 store_pbt
   564  (prep_pbt thy
   565  (["thy"],
   566   [("#Given" ,"boolTestGiven g_g"),
   567    ("#Find"  ,"boolTestFind f_f")
   568   ],
   569   []));
   570 
   571 store_pbt
   572  (prep_pbt thy
   573  (["testeq","thy"],
   574   [("#Given" ,"boolTestGiven g_g"),
   575    ("#Find"  ,"boolTestFind f_f")
   576   ],
   577   []));
   578 
   579 
   580 val ttt = (term_of o the o (parse (Thy_Info.get_theory "Isac"))) "(matches (   v_v = 0) e_e)";
   581 
   582  ------ 25.8.01*)
   583 
   584 *}
   585 ML {*
   586 (** methods **)
   587 store_met
   588  (prep_met @{theory "Diff"} "met_test" [] e_metID
   589  (["Test"],
   590    [],
   591    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
   592     crls=Atools_erls, errpats = [], nrls = e_rls}, "empty_script"));
   593 *}
   594 ML {*
   595 store_met
   596  (prep_met thy "met_test_solvelin" [] e_metID
   597  (["Test","solve_linear"]:metID,
   598   [("#Given" ,["equality e_e","solveFor v_v"]),
   599     ("#Where" ,["matches (?a = ?b) e_e"]),
   600     ("#Find"  ,["solutions v_v'i'"])
   601     ],
   602    {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
   603     prls = assoc_rls "matches", calc = [], crls = tval_rls,
   604     errpats = [], nrls = Test_simplify},
   605  "Script Solve_linear (e_e::bool) (v_v::real)=                     " ^
   606  "(let e_e =                                                       " ^
   607  "  Repeat                                                         " ^
   608  "    (((Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@  " ^
   609  "      (Rewrite_Set Test_simplify False))) e_e" ^
   610  " in [e_e::bool])"
   611  )
   612 (*, prep_met thy (*test for equations*)
   613  (["Test","testeq"]:metID,
   614   [("#Given" ,["boolTestGiven g_g"]),
   615    ("#Find"  ,["boolTestFind f_f"])
   616     ],
   617   {rew_ord'="e_rew_ord",rls'="tval_rls",asm_rls=[],
   618    asm_thm=[("square_equation_left","")]},
   619  "Script Testeq (e_q::bool) =                                         " ^
   620    "Repeat                                                            " ^
   621    " (let e_e = Try (Repeat (Rewrite rroot_square_inv False e_q));      " ^
   622    "      e_e = Try (Repeat (Rewrite square_equation_left True e_e)); " ^
   623    "      e_e = Try (Repeat (Rewrite rmult_0 False e_e))                " ^
   624    "   in e_e) Until (is_root_free e_e)" (*deleted*)
   625  )
   626 , ---------27.4.02*)
   627 );
   628 
   629 *}
   630 ML {*
   631 ruleset' := overwritelthy @{theory} (!ruleset',
   632   [("norm_equation", prep_rls norm_equation),
   633    ("ac_plus_times", prep_rls ac_plus_times),
   634    ("rearrange_assoc", prep_rls rearrange_assoc)
   635    ]);
   636 
   637 
   638 fun bin_o (Const (op_,(Type ("fun",
   639 	   [Type (s2,[]),Type ("fun",
   640 	    [Type (s4,tl4),Type (s5,tl5)])])))) = 
   641     if (s2=s4)andalso(s4=s5)then[op_]else[]
   642     | bin_o _                                   = [];
   643 
   644 fun bin_op (t1 $ t2) = union op = (bin_op t1) (bin_op t2)
   645   | bin_op t         =  bin_o t;
   646 fun is_bin_op t = ((bin_op t)<>[]);
   647 
   648 fun bin_op_arg1 ((Const (op_,(Type ("fun",
   649 	   [Type (s2,[]),Type ("fun",
   650 	    [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) = 
   651     arg1;
   652 fun bin_op_arg2 ((Const (op_,(Type ("fun",
   653 	   [Type (s2,[]),Type ("fun",
   654 	    [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) = 
   655     arg2;
   656 
   657 
   658 exception NO_EQUATION_TERM;
   659 fun is_equation ((Const ("HOL.eq",(Type ("fun",
   660 		 [Type (_,[]),Type ("fun",
   661 		  [Type (_,[]),Type ("bool",[])])])))) $ _ $ _) 
   662                   = true
   663   | is_equation _ = false;
   664 fun equ_lhs ((Const ("HOL.eq",(Type ("fun",
   665 		 [Type (_,[]),Type ("fun",
   666 		  [Type (_,[]),Type ("bool",[])])])))) $ l $ r) 
   667               = l
   668   | equ_lhs _ = raise NO_EQUATION_TERM;
   669 fun equ_rhs ((Const ("HOL.eq",(Type ("fun",
   670 		 [Type (_,[]),Type ("fun",
   671 		  [Type (_,[]),Type ("bool",[])])])))) $ l $ r) 
   672               = r
   673   | equ_rhs _ = raise NO_EQUATION_TERM;
   674 
   675 
   676 fun atom (Const (_,Type (_,[])))           = true
   677   | atom (Free  (_,Type (_,[])))           = true
   678   | atom (Var   (_,Type (_,[])))           = true
   679 (*| atom (_     (_,"?DUMMY"   ))           = true ..ML-error *)
   680   | atom((Const ("Bin.integ_of_bin",_)) $ _) = true
   681   | atom _                                 = false;
   682 
   683 fun varids (Const  (s,Type (_,[])))         = [strip_thy s]
   684   | varids (Free   (s,Type (_,[])))         = if is_no s then []
   685 					      else [strip_thy s]
   686   | varids (Var((s,_),Type (_,[])))         = [strip_thy s]
   687 (*| varids (_      (s,"?DUMMY"   ))         =   ..ML-error *)
   688   | varids((Const ("Bin.integ_of_bin",_)) $ _)= [](*8.01: superfluous?*)
   689   | varids (Abs(a,T,t)) = union op = [a] (varids t)
   690   | varids (t1 $ t2) = union op = (varids t1) (varids t2)
   691   | varids _         = [];
   692 (*> val t = term_of (hd (parse Diophant.thy "x"));
   693 val t = Free ("x","?DUMMY") : term
   694 > varids t;
   695 val it = [] : string list          [] !!! *)
   696 
   697 
   698 fun bin_ops_only ((Const op_) $ t1 $ t2) = 
   699     if(is_bin_op (Const op_))
   700     then(bin_ops_only t1)andalso(bin_ops_only t2)
   701     else false
   702   | bin_ops_only t =
   703     if atom t then true else bin_ops_only t;
   704 
   705 fun polynomial opl t bdVar = (* bdVar TODO *)
   706     subset op = (bin_op t, opl) andalso (bin_ops_only t);
   707 
   708 fun poly_equ opl bdVar t = is_equation t (* bdVar TODO *) 
   709     andalso polynomial opl (equ_lhs t) bdVar 
   710     andalso polynomial opl (equ_rhs t) bdVar
   711     andalso (subset op = (varids bdVar, varids (equ_lhs t)) orelse
   712              subset op = (varids bdVar, varids (equ_lhs t)));
   713 
   714 (*fun max is =
   715     let fun max_ m [] = m 
   716 	  | max_ m (i::is) = if m<i then max_ i is else max_ m is;
   717     in max_ (hd is) is end;
   718 > max [1,5,3,7,4,2];
   719 val it = 7 : int  *)
   720 
   721 fun max (a,b) = if a < b then b else a;
   722 
   723 fun degree addl mul bdVar t =
   724 let
   725 fun deg _ _ v (Const  (s,Type (_,[])))         = if v=strip_thy s then 1 else 0
   726   | deg _ _ v (Free   (s,Type (_,[])))         = if v=strip_thy s then 1 else 0
   727   | deg _ _ v (Var((s,_),Type (_,[])))         = if v=strip_thy s then 1 else 0
   728 (*| deg _ _ v (_     (s,"?DUMMY"   ))          =   ..ML-error *) 
   729   | deg _ _ v((Const ("Bin.integ_of_bin",_)) $ _ )= 0 
   730   | deg addl mul v (h $ t1 $ t2) =
   731     if subset op = (bin_op h, addl)
   732     then max (deg addl mul v t1  ,deg addl mul v t2)
   733     else (*mul!*)(deg addl mul v t1)+(deg addl mul v t2)
   734 in if polynomial (addl @ [mul]) t bdVar
   735    then SOME (deg addl mul (id_of bdVar) t) else (NONE:int option)
   736 end;
   737 fun degree_ addl mul bdVar t = (* do not export *)
   738     let fun opt (SOME i)= i
   739 	  | opt  NONE   = 0
   740 in opt (degree addl mul bdVar t) end;
   741 
   742 
   743 fun linear addl mul t bdVar = (degree_ addl mul bdVar t)<2;
   744 
   745 fun linear_equ addl mul bdVar t =
   746     if is_equation t 
   747     then let val degl = degree_ addl mul bdVar (equ_lhs t);
   748 	     val degr = degree_ addl mul bdVar (equ_rhs t)
   749 	 in if (degl>0 orelse degr>0)andalso max(degl,degr)<2
   750 		then true else false
   751 	 end
   752     else false;
   753 (* strip_thy op_  before *)
   754 fun is_div_op (dv,(Const (op_,(Type ("fun",
   755 	   [Type (s2,[]),Type ("fun",
   756 	    [Type (s4,tl4),Type (s5,tl5)])])))) )= (dv = strip_thy op_)
   757   | is_div_op _ = false;
   758 
   759 fun is_denom bdVar div_op t =
   760     let fun is bool[v]dv (Const  (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
   761 	  | is bool[v]dv (Free   (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false) 
   762 	  | is bool[v]dv (Var((s,_),Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
   763 	  | is bool[v]dv((Const ("Bin.integ_of_bin",_)) $ _) = false
   764 	  | is bool[v]dv (h$n$d) = 
   765 	      if is_div_op(dv,h) 
   766 	      then (is false[v]dv n)orelse(is true[v]dv d)
   767 	      else (is bool [v]dv n)orelse(is bool[v]dv d)
   768 in is false (varids bdVar) (strip_thy div_op) t end;
   769 
   770 
   771 fun rational t div_op bdVar = 
   772     is_denom bdVar div_op t andalso bin_ops_only t;
   773 
   774 *}
   775 ML {*
   776 
   777 (** problem types **)
   778 
   779 store_pbt
   780  (prep_pbt thy "pbl_test_uni_plain2" [] e_pblID
   781  (["plain_square","univariate","equation","test"],
   782   [("#Given" ,["equality e_e","solveFor v_v"]),
   783    ("#Where" ,["(matches (?a + ?b*v_v ^^^2 = 0) e_e) |" ^
   784 	       "(matches (     ?b*v_v ^^^2 = 0) e_e) |" ^
   785 	       "(matches (?a +    v_v ^^^2 = 0) e_e) |" ^
   786 	       "(matches (        v_v ^^^2 = 0) e_e)"]),
   787    ("#Find"  ,["solutions v_v'i'"])
   788   ],
   789   assoc_rls "matches", 
   790   SOME "solve (e_e::bool, v_v)", [["Test","solve_plain_square"]]));
   791 (*
   792  val e_e = (term_of o the o (parse thy)) "e_e::bool";
   793  val ve = (term_of o the o (parse thy)) "4 + 3*x^^^2 = 0";
   794  val env = [(e_,ve)];
   795 
   796  val pre = (term_of o the o (parse thy))
   797 	      "(matches (a + b*v_v ^^^2 = 0, e_e::bool)) |" ^
   798 	      "(matches (    b*v_v ^^^2 = 0, e_e::bool)) |" ^
   799 	      "(matches (a +   v_v ^^^2 = 0, e_e::bool)) |" ^
   800 	      "(matches (      v_v ^^^2 = 0, e_e::bool))";
   801  val prei = subst_atomic env pre;
   802  val cpre = (cterm_of thy) prei;
   803 
   804  val SOME (ct,_) = rewrite_set_ thy false tval_rls cpre;
   805 val ct = "True | False | False | False" : cterm 
   806 
   807 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   808 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   809 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
   810 val ct = "HOL.True" : cterm
   811 
   812 *)
   813 
   814 *}
   815 ML {*
   816 store_pbt
   817  (prep_pbt thy "pbl_test_uni_poly" [] e_pblID
   818  (["polynomial","univariate","equation","test"],
   819   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   820    ("#Where" ,["HOL.False"]),
   821    ("#Find"  ,["solutions v_v'i'"]) 
   822   ],
   823   e_rls, SOME "solve (e_e::bool, v_v)", []));
   824 
   825 store_pbt
   826  (prep_pbt thy "pbl_test_uni_poly_deg2" [] e_pblID
   827  (["degree_two","polynomial","univariate","equation","test"],
   828   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   829    ("#Find"  ,["solutions v_v'i'"]) 
   830   ],
   831   e_rls, SOME "solve (v_v ^^^2 + p_p * v_v + q__q = 0, v_v)", []));
   832 
   833 store_pbt
   834  (prep_pbt thy "pbl_test_uni_poly_deg2_pq" [] e_pblID
   835  (["pq_formula","degree_two","polynomial","univariate","equation","test"],
   836   [("#Given" ,["equality (v_v ^^^2 + p_p * v_v + q__q = 0)","solveFor v_v"]),
   837    ("#Find"  ,["solutions v_v'i'"]) 
   838   ],
   839   e_rls, SOME "solve (v_v ^^^2 + p_p * v_v + q__q = 0, v_v)", []));
   840 
   841 store_pbt
   842  (prep_pbt thy "pbl_test_uni_poly_deg2_abc" [] e_pblID
   843  (["abc_formula","degree_two","polynomial","univariate","equation","test"],
   844   [("#Given" ,["equality (a_a * x ^^^2 + b_b * x + c_c = 0)","solveFor v_v"]),
   845    ("#Find"  ,["solutions v_v'i'"]) 
   846   ],
   847   e_rls, SOME "solve (a_a * x ^^^2 + b_b * x + c_c = 0, v_v)", []));
   848 
   849 *}
   850 ML {*
   851 store_pbt
   852  (prep_pbt thy "pbl_test_uni_root" [] e_pblID
   853  (["squareroot","univariate","equation","test"],
   854   [("#Given" ,["equality e_e","solveFor v_v"]),
   855    ("#Where" ,["precond_rootpbl v_v"]),
   856    ("#Find"  ,["solutions v_v'i'"]) 
   857   ],
   858   append_rls "contains_root" e_rls [Calc ("Test.contains'_root",
   859 			  eval_contains_root "#contains_root_")], 
   860   SOME "solve (e_e::bool, v_v)", [["Test","square_equation"]]));
   861 
   862 store_pbt
   863  (prep_pbt thy "pbl_test_uni_norm" [] e_pblID
   864  (["normalize","univariate","equation","test"],
   865   [("#Given" ,["equality e_e","solveFor v_v"]),
   866    ("#Where" ,[]),
   867    ("#Find"  ,["solutions v_v'i'"]) 
   868   ],
   869   e_rls, SOME "solve (e_e::bool, v_v)", [["Test","norm_univar_equation"]]));
   870 
   871 store_pbt
   872  (prep_pbt thy "pbl_test_uni_roottest" [] e_pblID
   873  (["sqroot-test","univariate","equation","test"],
   874   [("#Given" ,["equality e_e","solveFor v_v"]),
   875    ("#Where" ,["precond_rootpbl v_v"]),
   876    ("#Find"  ,["solutions v_v'i'"]) 
   877   ],
   878   e_rls, SOME "solve (e_e::bool, v_v)", []));
   879 
   880 store_pbt
   881  (prep_pbt thy "pbl_test_intsimp" [] e_pblID
   882  (["inttype","test"],
   883   [("#Given" ,["intTestGiven t_t"]),
   884    ("#Where" ,[]),
   885    ("#Find"  ,["intTestFind s_s"]) 
   886   ],
   887   e_rls, NONE, [["Test","intsimp"]])); 
   888 (*
   889 show_ptyps();
   890 get_pbt ["inttype","test"];
   891 *)
   892 
   893 *}
   894 
   895 ML {*
   896 store_met
   897  (prep_met thy  "met_test_sqrt" [] e_metID
   898 (*root-equation, version for tests before 8.01.01*)
   899  (["Test","sqrt-equ-test"]:metID,
   900   [("#Given" ,["equality e_e","solveFor v_v"]),
   901    ("#Where" ,["contains_root (e_e::bool)"]),
   902    ("#Find"  ,["solutions v_v'i'"])
   903    ],
   904   {rew_ord'="e_rew_ord",rls'=tval_rls,
   905    srls =append_rls "srls_contains_root" e_rls 
   906 		    [Calc ("Test.contains'_root",eval_contains_root "")],
   907    prls =append_rls "prls_contains_root" e_rls 
   908 		    [Calc ("Test.contains'_root",eval_contains_root "")],
   909    calc=[],
   910    crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
   911    asm_thm=[("square_equation_left",""),
   912 	    ("square_equation_right","")]*)},
   913  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
   914  "(let e_e = " ^
   915  "   ((While (contains_root e_e) Do" ^
   916  "      ((Rewrite square_equation_left True) @@" ^
   917  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
   918  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
   919  "       (Try (Rewrite_Set isolate_root False)) @@" ^
   920  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
   921  "    (Try (Rewrite_Set norm_equation False)) @@" ^
   922  "    (Try (Rewrite_Set Test_simplify False)) @@" ^
   923  "    (Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@" ^
   924  "    (Try (Rewrite_Set Test_simplify False)))" ^
   925  "   e_e" ^
   926  " in [e_e::bool])"
   927   ));
   928 
   929 *}
   930 ML {*
   931 store_met
   932  (prep_met thy  "met_test_sqrt2" [] e_metID
   933 (*root-equation ... for test-*.sml until 8.01*)
   934  (["Test","squ-equ-test2"]:metID,
   935   [("#Given" ,["equality e_e","solveFor v_v"]),
   936    ("#Find"  ,["solutions v_v'i'"])
   937    ],
   938   {rew_ord'="e_rew_ord",rls'=tval_rls,
   939    srls = append_rls "srls_contains_root" e_rls 
   940 		     [Calc ("Test.contains'_root",eval_contains_root"")],
   941    prls=e_rls,calc=[],
   942    crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
   943    asm_thm=[("square_equation_left",""),
   944 	    ("square_equation_right","")]*)},
   945  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
   946  "(let e_e = " ^
   947  "   ((While (contains_root e_e) Do" ^
   948  "      ((Rewrite square_equation_left True) @@" ^
   949  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
   950  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
   951  "       (Try (Rewrite_Set isolate_root False)) @@" ^
   952  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
   953  "    (Try (Rewrite_Set norm_equation False)) @@" ^
   954  "    (Try (Rewrite_Set Test_simplify False)) @@" ^
   955  "    (Rewrite_Set_Inst [(bdv,v_v::real)] isolate_bdv False) @@" ^
   956  "    (Try (Rewrite_Set Test_simplify False)))" ^
   957  "   e_e;" ^
   958  "  (L_L::bool list) = Tac subproblem_equation_dummy;          " ^
   959  "  L_L = Tac solve_equation_dummy                             " ^
   960  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
   961   ));
   962 
   963 *}
   964 ML {*
   965 store_met
   966  (prep_met thy "met_test_squ_sub" [] e_metID
   967 (*tests subproblem fixed linear*)
   968  (["Test","squ-equ-test-subpbl1"]:metID,
   969   [("#Given" ,["equality e_e","solveFor v_v"]),
   970    ("#Where" ,["precond_rootmet v_v"]),
   971    ("#Find"  ,["solutions v_v'i'"])
   972    ],
   973   {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
   974    prls = append_rls "prls_met_test_squ_sub" e_rls
   975      [Calc ("Test.precond'_rootmet", eval_precond_rootmet "")],
   976    calc=[], crls=tval_rls, errpats = [], nrls = Test_simplify},
   977   "Script Solve_root_equation (e_e::bool) (v_v::real) =       " ^
   978   " (let e_e = ((Try (Rewrite_Set norm_equation False)) @@    " ^
   979   "            (Try (Rewrite_Set Test_simplify False))) e_e;  " ^
   980   "     (L_L::bool list) =                                    " ^
   981   "            (SubProblem (Test',                            " ^
   982   "                         [linear,univariate,equation,test]," ^
   983   "                         [Test,solve_linear])              " ^
   984   "                        [BOOL e_e, REAL v_v])              " ^
   985   "  in Check_elementwise L_L {(v_v::real). Assumptions})     "
   986   ));
   987 
   988 *}
   989 ML {*
   990 store_met
   991  (prep_met thy "met_test_squ_sub2" [] e_metID
   992  (*tests subproblem fixed degree 2*)
   993  (["Test","squ-equ-test-subpbl2"]:metID,
   994   [("#Given" ,["equality e_e","solveFor v_v"]),
   995    ("#Find"  ,["solutions v_v'i'"])
   996    ],
   997   {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,prls=e_rls,calc=[],
   998     crls=tval_rls, errpats = [], nrls = e_rls(*,
   999    asm_rls=[],asm_thm=[("square_equation_left",""),
  1000 	    ("square_equation_right","")]*)},
  1001    "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1002    " (let e_e = Try (Rewrite_Set norm_equation False) e_e;              " ^
  1003    "(L_L::bool list) = (SubProblem (Test',[linear,univariate,equation,test]," ^
  1004    "                    [Test,solve_by_pq_formula]) [BOOL e_e, REAL v_v])" ^
  1005    "in Check_elementwise L_L {(v_v::real). Assumptions})"
  1006    )); 
  1007 
  1008 *}
  1009 ML {*
  1010 store_met
  1011  (prep_met thy "met_test_squ_nonterm" [] e_metID
  1012  (*root-equation: see foils..., but notTerminating*)
  1013  (["Test","square_equation...notTerminating"]:metID,
  1014   [("#Given" ,["equality e_e","solveFor v_v"]),
  1015    ("#Find"  ,["solutions v_v'i'"])
  1016    ],
  1017   {rew_ord'="e_rew_ord",rls'=tval_rls,
  1018    srls = append_rls "srls_contains_root" e_rls 
  1019 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1020    prls=e_rls,calc=[],
  1021     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1022    asm_thm=[("square_equation_left",""),
  1023 	    ("square_equation_right","")]*)},
  1024  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1025  "(let e_e = " ^
  1026  "   ((While (contains_root e_e) Do" ^
  1027  "      ((Rewrite square_equation_left True) @@" ^
  1028  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1029  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1030  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1031  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1032  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1033  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1034  "   e_e;" ^
  1035  "  (L_L::bool list) =                                        " ^
  1036  "    (SubProblem (Test',[linear,univariate,equation,test]," ^
  1037  "                 [Test,solve_linear]) [BOOL e_e, REAL v_v])" ^
  1038  "in Check_elementwise L_L {(v_v::real). Assumptions})"
  1039   ));
  1040 
  1041 *}
  1042 ML {*
  1043 store_met
  1044  (prep_met thy  "met_test_eq1" [] e_metID
  1045 (*root-equation1:*)
  1046  (["Test","square_equation1"]:metID,
  1047    [("#Given" ,["equality e_e","solveFor v_v"]),
  1048     ("#Find"  ,["solutions v_v'i'"])
  1049     ],
  1050    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1051    srls = append_rls "srls_contains_root" e_rls 
  1052 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1053    prls=e_rls,calc=[],
  1054     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1055    asm_thm=[("square_equation_left",""),
  1056 	    ("square_equation_right","")]*)},
  1057  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1058  "(let e_e = " ^
  1059  "   ((While (contains_root e_e) Do" ^
  1060  "      ((Rewrite square_equation_left True) @@" ^
  1061  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1062  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1063  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1064  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1065  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1066  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1067  "   e_e;" ^
  1068  "  (L_L::bool list) = (SubProblem (Test',[linear,univariate,equation,test]," ^
  1069  "                    [Test,solve_linear]) [BOOL e_e, REAL v_v])" ^
  1070  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1071   ));
  1072 
  1073 *}
  1074 ML {*
  1075 store_met
  1076  (prep_met thy "met_test_squ2" [] e_metID
  1077  (*root-equation2*)
  1078  (["Test","square_equation2"]:metID,
  1079    [("#Given" ,["equality e_e","solveFor v_v"]),
  1080     ("#Find"  ,["solutions v_v'i'"])
  1081     ],
  1082    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1083    srls = append_rls "srls_contains_root" e_rls 
  1084 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1085    prls=e_rls,calc=[],
  1086     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1087    asm_thm=[("square_equation_left",""),
  1088 	    ("square_equation_right","")]*)},
  1089  "Script Solve_root_equation (e_e::bool) (v_v::real)  =  " ^
  1090  "(let e_e = " ^
  1091  "   ((While (contains_root e_e) Do" ^
  1092  "      (((Rewrite square_equation_left True) Or " ^
  1093  "        (Rewrite square_equation_right True)) @@" ^
  1094  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1095  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1096  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1097  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1098  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1099  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1100  "   e_e;" ^
  1101  "  (L_L::bool list) = (SubProblem (Test',[plain_square,univariate,equation,test]," ^
  1102  "                    [Test,solve_plain_square]) [BOOL e_e, REAL v_v])" ^
  1103  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1104   ));
  1105 
  1106 *}
  1107 ML {*
  1108 store_met
  1109  (prep_met thy "met_test_squeq" [] e_metID
  1110  (*root-equation*)
  1111  (["Test","square_equation"]:metID,
  1112    [("#Given" ,["equality e_e","solveFor v_v"]),
  1113     ("#Find"  ,["solutions v_v'i'"])
  1114     ],
  1115    {rew_ord'="e_rew_ord",rls'=tval_rls,
  1116    srls = append_rls "srls_contains_root" e_rls 
  1117 		     [Calc ("Test.contains'_root",eval_contains_root"")],
  1118    prls=e_rls,calc=[],
  1119     crls=tval_rls, errpats = [], nrls = e_rls(*,asm_rls=[],
  1120    asm_thm=[("square_equation_left",""),
  1121 	    ("square_equation_right","")]*)},
  1122  "Script Solve_root_equation (e_e::bool) (v_v::real) =  " ^
  1123  "(let e_e = " ^
  1124  "   ((While (contains_root e_e) Do" ^
  1125  "      (((Rewrite square_equation_left True) Or" ^
  1126  "        (Rewrite square_equation_right True)) @@" ^
  1127  "       (Try (Rewrite_Set Test_simplify False)) @@" ^
  1128  "       (Try (Rewrite_Set rearrange_assoc False)) @@" ^
  1129  "       (Try (Rewrite_Set isolate_root False)) @@" ^
  1130  "       (Try (Rewrite_Set Test_simplify False)))) @@" ^
  1131  "    (Try (Rewrite_Set norm_equation False)) @@" ^
  1132  "    (Try (Rewrite_Set Test_simplify False)))" ^
  1133  "   e_e;" ^
  1134  "  (L_L::bool list) = (SubProblem (Test',[univariate,equation,test]," ^
  1135  "                    [no_met]) [BOOL e_e, REAL v_v])" ^
  1136  "  in Check_elementwise L_L {(v_v::real). Assumptions})"
  1137   ) ); (*#######*)
  1138 
  1139 *}
  1140 ML {*
  1141 store_met
  1142  (prep_met thy "met_test_eq_plain" [] e_metID
  1143  (*solve_plain_square*)
  1144  (["Test","solve_plain_square"]:metID,
  1145    [("#Given",["equality e_e","solveFor v_v"]),
  1146    ("#Where" ,["(matches (?a + ?b*v_v ^^^2 = 0) e_e) |" ^
  1147 	       "(matches (     ?b*v_v ^^^2 = 0) e_e) |" ^
  1148 	       "(matches (?a +    v_v ^^^2 = 0) e_e) |" ^
  1149 	       "(matches (        v_v ^^^2 = 0) e_e)"]), 
  1150    ("#Find"  ,["solutions v_v'i'"]) 
  1151    ],
  1152    {rew_ord'="e_rew_ord",rls'=tval_rls,calc=[],srls=e_rls,
  1153     prls = assoc_rls "matches",
  1154     crls=tval_rls, errpats = [], nrls = e_rls(*,
  1155     asm_rls=[],asm_thm=[]*)},
  1156   "Script Solve_plain_square (e_e::bool) (v_v::real) =           " ^
  1157    " (let e_e = ((Try (Rewrite_Set isolate_bdv False)) @@         " ^
  1158    "            (Try (Rewrite_Set Test_simplify False)) @@     " ^
  1159    "            ((Rewrite square_equality_0 False) Or        " ^
  1160    "             (Rewrite square_equality True)) @@            " ^
  1161    "            (Try (Rewrite_Set tval_rls False))) e_e             " ^
  1162    "  in ((Or_to_List e_e)::bool list))"
  1163  ));
  1164 
  1165 *}
  1166 
  1167 ML {*
  1168 store_met
  1169  (prep_met thy "met_test_norm_univ" [] e_metID
  1170  (["Test","norm_univar_equation"]:metID,
  1171    [("#Given",["equality e_e","solveFor v_v"]),
  1172    ("#Where" ,[]), 
  1173    ("#Find"  ,["solutions v_v'i'"]) 
  1174    ],
  1175    {rew_ord'="e_rew_ord",rls'=tval_rls,srls = e_rls,prls=e_rls,
  1176    calc=[],
  1177     crls=tval_rls, errpats = [], nrls = e_rls},
  1178   "Script Norm_univar_equation (e_e::bool) (v_v::real) =      " ^
  1179    " (let e_e = ((Try (Rewrite rnorm_equation_add False)) @@   " ^
  1180    "            (Try (Rewrite_Set Test_simplify False))) e_e   " ^
  1181    "  in (SubProblem (Test',[univariate,equation,test],         " ^
  1182    "                    [no_met]) [BOOL e_e, REAL v_v]))"
  1183  ));
  1184 
  1185 (*17.9.02 aus SqRoot.ML------------------------------^^^---*)  
  1186 
  1187 store_met
  1188 (prep_met thy "met_test_intsimp" [] e_metID
  1189  (["Test","intsimp"]:metID,
  1190   [("#Given" ,["intTestGiven t_t"]),
  1191    ("#Where" ,[]),
  1192    ("#Find"  ,["intTestFind s_s"]) 
  1193   ],
  1194    {rew_ord' = "e_rew_ord", rls' = tval_rls, srls = e_rls,
  1195     prls = e_rls, calc = [], crls = tval_rls, errpats = [], nrls = Test_simplify},
  1196  "Script STest_simplify (t_t::int) =                  " ^
  1197  "(Repeat                                                          " ^
  1198  "    ((Try (Calculate PLUS)) @@  " ^
  1199  "     (Try (Calculate TIMES))) t_t::int)"
  1200  ));
  1201 
  1202 *}
  1203 
  1204 ML {*
  1205 (*8.4.03  aus Poly.ML--------------------------------vvv---
  1206   make_polynomial  ---> make_poly
  1207   ^-- for user          ^-- for systest _ONLY_*)  
  1208 
  1209 local (*. for make_polytest .*)
  1210 
  1211 open Term;  (* for type order = EQUAL | LESS | GREATER *)
  1212 
  1213 fun pr_ord EQUAL = "EQUAL"
  1214   | pr_ord LESS  = "LESS"
  1215   | pr_ord GREATER = "GREATER";
  1216 
  1217 fun dest_hd' (Const (a, T)) =                          (* ~ term.ML *)
  1218   (case a of
  1219      "Atools.pow" => ((("|||||||||||||", 0), T), 0)           (*WN greatest *)
  1220    | _ => (((a, 0), T), 0))
  1221   | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
  1222   | dest_hd' (Var v) = (v, 2)
  1223   | dest_hd' (Bound i) = ((("", i), dummyT), 3)
  1224   | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
  1225 (* RL *)
  1226 fun get_order_pow (t $ (Free(order,_))) = 
  1227     	(case int_of_str (order) of
  1228 	             SOME d => d
  1229 		   | NONE   => 0)
  1230   | get_order_pow _ = 0;
  1231 
  1232 fun size_of_term' (Const(str,_) $ t) =
  1233   if "Atools.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*)
  1234   | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
  1235   | size_of_term' (f$t) = size_of_term' f  +  size_of_term' t
  1236   | size_of_term' _ = 1;
  1237 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
  1238     (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) 
  1239                                    | ord => ord)
  1240   | term_ord' pr thy (t, u) =
  1241     (if pr then 
  1242 	 let val (f, ts) = strip_comb t and (g, us) = strip_comb u;
  1243 	     val _ = tracing ("t= f@ts= \"" ^ term2str f ^ "\" @ \"[" ^
  1244 	                      commas(map term2str ts) ^ "]\"")
  1245 	     val _ = tracing ("u= g@us= \"" ^ term2str g ^"\" @ \"[" ^
  1246 	                      commas(map term2str us) ^"]\"")
  1247 	     val _ = tracing ("size_of_term(t,u)= (" ^
  1248 	                      string_of_int (size_of_term' t) ^ ", " ^
  1249 	                      string_of_int (size_of_term' u) ^ ")")
  1250 	     val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o hd_ord) (f,g))
  1251 	     val _ = tracing ("terms_ord(ts,us) = " ^
  1252 			      (pr_ord o terms_ord str false) (ts,us));
  1253 	     val _ = tracing "-------"
  1254 	 in () end
  1255        else ();
  1256 	 case int_ord (size_of_term' t, size_of_term' u) of
  1257 	   EQUAL =>
  1258 	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
  1259 	       (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us) 
  1260 	     | ord => ord)
  1261 	     end
  1262 	 | ord => ord)
  1263 and hd_ord (f, g) =                                        (* ~ term.ML *)
  1264   prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
  1265 and terms_ord str pr (ts, us) = 
  1266     list_ord (term_ord' pr (assoc_thy "Isac"))(ts, us);
  1267 in
  1268 
  1269 fun ord_make_polytest (pr:bool) thy (_:subst) tu = 
  1270     (term_ord' pr thy(***) tu = LESS );
  1271 
  1272 end;(*local*)
  1273 *}
  1274 ML {*
  1275 
  1276 rew_ord' := overwritel (!rew_ord',
  1277 [("termlessI", termlessI),
  1278  ("ord_make_polytest", ord_make_polytest false thy)
  1279  ]);
  1280 
  1281 (*WN060510 this was a preparation for prep_rls ...
  1282 val scr_make_polytest = 
  1283 "Script Expand_binomtest t_t =" ^
  1284 "(Repeat                       " ^
  1285 "((Try (Repeat (Rewrite real_diff_minus         False))) @@ " ^ 
  1286 
  1287 " (Try (Repeat (Rewrite distrib_right   False))) @@ " ^	 
  1288 " (Try (Repeat (Rewrite distrib_left  False))) @@ " ^	
  1289 " (Try (Repeat (Rewrite left_diff_distrib  False))) @@ " ^	
  1290 " (Try (Repeat (Rewrite right_diff_distrib False))) @@ " ^	
  1291 
  1292 " (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^		   
  1293 " (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^		   
  1294 " (Try (Repeat (Rewrite add_0_left      False))) @@ " ^	 
  1295 
  1296 " (Try (Repeat (Rewrite mult_commute       False))) @@ " ^		
  1297 " (Try (Repeat (Rewrite real_mult_left_commute  False))) @@ " ^	
  1298 " (Try (Repeat (Rewrite mult_assoc         False))) @@ " ^		
  1299 " (Try (Repeat (Rewrite add_commute        False))) @@ " ^		
  1300 " (Try (Repeat (Rewrite add_left_commute   False))) @@ " ^	 
  1301 " (Try (Repeat (Rewrite add_assoc          False))) @@ " ^	 
  1302 
  1303 " (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^	 
  1304 " (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^	 
  1305 " (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^		
  1306 " (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^		
  1307 
  1308 " (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^		
  1309 " (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^	
  1310 
  1311 " (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^		
  1312 " (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^   
  1313 
  1314 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1315 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1316 " (Try (Repeat (Calculate POWER)))) " ^  
  1317 " t_t)";
  1318 -----------------------------------------------------*)
  1319 
  1320 val make_polytest =
  1321   Rls{id = "make_polytest", preconds = []:term list, 
  1322       rew_ord = ("ord_make_polytest", ord_make_polytest false @{theory "Poly"}),
  1323       erls = testerls, srls = Erls,
  1324       calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
  1325 	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
  1326 	      ("POWER", ("Atools.pow", eval_binop "#power_"))
  1327 	      ], errpatts = [],
  1328       rules = [Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
  1329 	       (*"a - b = a + (-1) * b"*)
  1330 	       Thm ("distrib_right" ,num_str @{thm distrib_right}),
  1331 	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
  1332 	       Thm ("distrib_left",num_str @{thm distrib_left}),
  1333 	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
  1334 	       Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),
  1335 	       (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
  1336 	       Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),
  1337 	       (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
  1338 	       Thm ("mult_1_left",num_str @{thm mult_1_left}),                 
  1339 	       (*"1 * z = z"*)
  1340 	       Thm ("mult_zero_left",num_str @{thm mult_zero_left}),        
  1341 	       (*"0 * z = 0"*)
  1342 	       Thm ("add_0_left",num_str @{thm add_0_left}),
  1343 	       (*"0 + z = z"*)
  1344 
  1345 	       (*AC-rewriting*)
  1346 	       Thm ("mult_commute",num_str @{thm mult_commute}),
  1347 	       (* z * w = w * z *)
  1348 	       Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
  1349 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
  1350 	       Thm ("mult_assoc",num_str @{thm mult_assoc}),		
  1351 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
  1352 	       Thm ("add_commute",num_str @{thm add_commute}),	
  1353 	       (*z + w = w + z*)
  1354 	       Thm ("add_left_commute",num_str @{thm add_left_commute}),
  1355 	       (*x + (y + z) = y + (x + z)*)
  1356 	       Thm ("add_assoc",num_str @{thm add_assoc}),	               
  1357 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
  1358 
  1359 	       Thm ("sym_realpow_twoI",
  1360                      num_str (@{thm realpow_twoI} RS @{thm sym})),	
  1361 	       (*"r1 * r1 = r1 ^^^ 2"*)
  1362 	       Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),		
  1363 	       (*"r * r ^^^ n = r ^^^ (n + 1)"*)
  1364 	       Thm ("sym_real_mult_2",
  1365                      num_str (@{thm real_mult_2} RS @{thm sym})),	
  1366 	       (*"z1 + z1 = 2 * z1"*)
  1367 	       Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),	
  1368 	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
  1369 
  1370 	       Thm ("real_num_collect",num_str @{thm real_num_collect}), 
  1371 	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
  1372 	       Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
  1373 	       (*"[| l is_const; m is_const |] ==>  
  1374 				l * n + (m * n + k) =  (l + m) * n + k"*)
  1375 	       Thm ("real_one_collect",num_str @{thm real_one_collect}),	
  1376 	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
  1377 	       Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
  1378 	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
  1379 
  1380 	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1381 	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1382 	       Calc ("Atools.pow", eval_binop "#power_")
  1383 	       ],
  1384       scr = EmptyScr(*Prog ((term_of o the o (parse thy)) 
  1385       scr_make_polytest)*)
  1386       }:rls; 
  1387 *}
  1388 ML {*     
  1389 (*WN060510 this was done before 'fun prep_rls' ...------------------------
  1390 val scr_expand_binomtest =
  1391 "Script Expand_binomtest t_t =" ^
  1392 "(Repeat                       " ^
  1393 "((Try (Repeat (Rewrite real_plus_binom_pow2    False))) @@ " ^
  1394 " (Try (Repeat (Rewrite real_plus_binom_times   False))) @@ " ^
  1395 " (Try (Repeat (Rewrite real_minus_binom_pow2   False))) @@ " ^
  1396 " (Try (Repeat (Rewrite real_minus_binom_times  False))) @@ " ^
  1397 " (Try (Repeat (Rewrite real_plus_minus_binom1  False))) @@ " ^
  1398 " (Try (Repeat (Rewrite real_plus_minus_binom2  False))) @@ " ^
  1399 
  1400 " (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^
  1401 " (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^
  1402 " (Try (Repeat (Rewrite add_0_left      False))) @@ " ^
  1403 
  1404 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1405 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1406 " (Try (Repeat (Calculate POWER))) @@ " ^
  1407 
  1408 " (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^
  1409 " (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^
  1410 " (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^
  1411 " (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^
  1412 
  1413 " (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^
  1414 " (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^
  1415 
  1416 " (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^
  1417 " (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^ 
  1418 
  1419 " (Try (Repeat (Calculate PLUS  ))) @@ " ^
  1420 " (Try (Repeat (Calculate TIMES ))) @@ " ^
  1421 " (Try (Repeat (Calculate POWER)))) " ^  
  1422 " t_t)";
  1423 --------------------------------------------------------------------------*)
  1424 
  1425 val expand_binomtest =
  1426   Rls{id = "expand_binomtest", preconds = [], 
  1427       rew_ord = ("termlessI",termlessI),
  1428       erls = testerls, srls = Erls,
  1429       calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
  1430 	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
  1431 	      ("POWER", ("Atools.pow", eval_binop "#power_"))
  1432 	      ], errpatts = [],
  1433       rules = 
  1434       [Thm ("real_plus_binom_pow2"  ,num_str @{thm real_plus_binom_pow2}),     
  1435 	       (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
  1436        Thm ("real_plus_binom_times" ,num_str @{thm real_plus_binom_times}),    
  1437 	      (*"(a + b)*(a + b) = ...*)
  1438        Thm ("real_minus_binom_pow2" ,num_str @{thm real_minus_binom_pow2}),   
  1439        (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
  1440        Thm ("real_minus_binom_times",num_str @{thm real_minus_binom_times}),   
  1441        (*"(a - b)*(a - b) = ...*)
  1442        Thm ("real_plus_minus_binom1",num_str @{thm real_plus_minus_binom1}),   
  1443         (*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
  1444        Thm ("real_plus_minus_binom2",num_str @{thm real_plus_minus_binom2}),   
  1445         (*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
  1446        (*RL 020915*)
  1447        Thm ("real_pp_binom_times",num_str @{thm real_pp_binom_times}), 
  1448         (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
  1449        Thm ("real_pm_binom_times",num_str @{thm real_pm_binom_times}), 
  1450         (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
  1451        Thm ("real_mp_binom_times",num_str @{thm real_mp_binom_times}), 
  1452         (*(a - b)*(c p d) = a*c + a*d - b*c - b*d*)
  1453        Thm ("real_mm_binom_times",num_str @{thm real_mm_binom_times}), 
  1454         (*(a - b)*(c p d) = a*c - a*d - b*c + b*d*)
  1455        Thm ("realpow_multI",num_str @{thm realpow_multI}),                
  1456         (*(a*b)^^^n = a^^^n * b^^^n*)
  1457        Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
  1458         (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
  1459        Thm ("real_minus_binom_pow3",num_str @{thm real_minus_binom_pow3}),
  1460         (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
  1461 
  1462 
  1463      (*  Thm ("distrib_right" ,num_str @{thm distrib_right}),	
  1464 	 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
  1465 	Thm ("distrib_left",num_str @{thm distrib_left}),	
  1466 	(*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
  1467 	Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),	
  1468 	(*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
  1469 	Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),	
  1470 	(*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
  1471 	*)
  1472 	
  1473 	Thm ("mult_1_left",num_str @{thm mult_1_left}),              
  1474          (*"1 * z = z"*)
  1475 	Thm ("mult_zero_left",num_str @{thm mult_zero_left}),              
  1476          (*"0 * z = 0"*)
  1477 	Thm ("add_0_left",num_str @{thm add_0_left}),
  1478          (*"0 + z = z"*)
  1479 
  1480 	Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1481 	Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1482 	Calc ("Atools.pow", eval_binop "#power_"),
  1483         (*	       
  1484 	 Thm ("mult_commute",num_str @{thm mult_commute}),		
  1485         (*AC-rewriting*)
  1486 	Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
  1487 	Thm ("mult_assoc",num_str @{thm mult_assoc}),
  1488 	Thm ("add_commute",num_str @{thm add_commute}),	
  1489 	Thm ("add_left_commute",num_str @{thm add_left_commute}),
  1490 	Thm ("add_assoc",num_str @{thm add_assoc}),
  1491 	*)
  1492 	
  1493 	Thm ("sym_realpow_twoI",
  1494               num_str (@{thm realpow_twoI} RS @{thm sym})),
  1495 	(*"r1 * r1 = r1 ^^^ 2"*)
  1496 	Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),			
  1497 	(*"r * r ^^^ n = r ^^^ (n + 1)"*)
  1498 	(*Thm ("sym_real_mult_2",
  1499                 num_str (@{thm real_mult_2} RS @{thm sym})),
  1500 	(*"z1 + z1 = 2 * z1"*)*)
  1501 	Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),		
  1502 	(*"z1 + (z1 + k) = 2 * z1 + k"*)
  1503 
  1504 	Thm ("real_num_collect",num_str @{thm real_num_collect}), 
  1505 	(*"[| l is_const; m is_const |] ==> l * n + m * n = (l + m) * n"*)
  1506 	Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),	
  1507 	(*"[| l is_const; m is_const |] ==>  l * n + (m * n + k) =  (l + m) * n + k"*)
  1508 	Thm ("real_one_collect",num_str @{thm real_one_collect}),		
  1509 	(*"m is_const ==> n + m * n = (1 + m) * n"*)
  1510 	Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
  1511 	(*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
  1512 
  1513 	Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
  1514 	Calc ("Groups.times_class.times", eval_binop "#mult_"),
  1515 	Calc ("Atools.pow", eval_binop "#power_")
  1516 	],
  1517       scr = EmptyScr
  1518 (*Script ((term_of o the o (parse thy)) scr_expand_binomtest)*)
  1519       }:rls;      
  1520 
  1521 
  1522 ruleset' := overwritelthy @{theory} (!ruleset',
  1523    [("make_polytest", prep_rls make_polytest),
  1524     ("expand_binomtest", prep_rls expand_binomtest)
  1525     ]);
  1526 *}
  1527 
  1528 end