src/Tools/isac/Knowledge/PolyEq.thy
author wenzelm
Fri, 11 Jun 2021 11:49:34 +0200
changeset 60294 6623f5cdcb19
parent 60291 52921aa0e14a
child 60297 73e7175a7d3f
permissions -rw-r--r--
ML antiquotation for formally checked Rule.Eval;
     1 (* theory collecting all knowledge 
     2    (predicates 'is_rootEq_in', 'is_sqrt_in', 'is_ratEq_in')
     3    for PolynomialEquations.
     4    alternative dependencies see @{theory "Isac_Knowledge"}
     5    created by: rlang 
     6          date: 02.07
     7    changed by: rlang
     8    last change by: rlang
     9              date: 03.06.03
    10    (c) by Richard Lang, 2003
    11 *)
    12 
    13 theory PolyEq imports LinEq RootRatEq begin 
    14 
    15 (*-------------------- rules -------------------------------------------------*)
    16 (* type real enforced by op " \<up> " *)
    17 axiomatization where
    18   cancel_leading_coeff1: "Not (c =!= 0) ==> (a + b*bdv + c*bdv \<up> 2 = 0) = 
    19 			                   (a/c + b/c*bdv + bdv \<up> 2 = 0)" and
    20   cancel_leading_coeff2: "Not (c =!= 0) ==> (a - b*bdv + c*bdv \<up> 2 = 0) = 
    21 			                   (a/c - b/c*bdv + bdv \<up> 2 = 0)" and
    22   cancel_leading_coeff3: "Not (c =!= 0) ==> (a + b*bdv - c*bdv \<up> 2 = 0) = 
    23 			                   (a/c + b/c*bdv - bdv \<up> 2 = 0)" and
    24 
    25   cancel_leading_coeff4: "Not (c =!= 0) ==> (a +   bdv + c*bdv \<up> 2 = 0) = 
    26 			                   (a/c + 1/c*bdv + bdv \<up> 2 = 0)" and
    27   cancel_leading_coeff5: "Not (c =!= 0) ==> (a -   bdv + c*bdv \<up> 2 = 0) = 
    28 			                   (a/c - 1/c*bdv + bdv \<up> 2 = 0)" and
    29   cancel_leading_coeff6: "Not (c =!= 0) ==> (a +   bdv - c*bdv \<up> 2 = 0) = 
    30 			                   (a/c + 1/c*bdv - bdv \<up> 2 = 0)" and
    31 
    32   cancel_leading_coeff7: "Not (c =!= 0) ==> (    b*bdv + c*bdv \<up> 2 = 0) = 
    33 			                   (    b/c*bdv + bdv \<up> 2 = 0)" and
    34   cancel_leading_coeff8: "Not (c =!= 0) ==> (    b*bdv - c*bdv \<up> 2 = 0) = 
    35 			                   (    b/c*bdv - bdv \<up> 2 = 0)" and
    36 
    37   cancel_leading_coeff9: "Not (c =!= 0) ==> (      bdv + c*bdv \<up> 2 = 0) = 
    38 			                   (      1/c*bdv + bdv \<up> 2 = 0)" and
    39   cancel_leading_coeff10:"Not (c =!= 0) ==> (      bdv - c*bdv \<up> 2 = 0) = 
    40 			                   (      1/c*bdv - bdv \<up> 2 = 0)" and
    41 
    42   cancel_leading_coeff11:"Not (c =!= 0) ==> (a +      b*bdv \<up> 2 = 0) = 
    43 			                   (a/b +      bdv \<up> 2 = 0)" and
    44   cancel_leading_coeff12:"Not (c =!= 0) ==> (a -      b*bdv \<up> 2 = 0) = 
    45 			                   (a/b -      bdv \<up> 2 = 0)" and
    46   cancel_leading_coeff13:"Not (c =!= 0) ==> (         b*bdv \<up> 2 = 0) = 
    47 			                   (           bdv \<up> 2 = 0/b)" and
    48 
    49   complete_square1:      "(q + p*bdv + bdv \<up> 2 = 0) = 
    50 		         (q + (p/2 + bdv) \<up> 2 = (p/2) \<up> 2)" and
    51   complete_square2:      "(    p*bdv + bdv \<up> 2 = 0) = 
    52 		         (    (p/2 + bdv) \<up> 2 = (p/2) \<up> 2)" and
    53   complete_square3:      "(      bdv + bdv \<up> 2 = 0) = 
    54 		         (    (1/2 + bdv) \<up> 2 = (1/2) \<up> 2)" and
    55 		        
    56   complete_square4:      "(q - p*bdv + bdv \<up> 2 = 0) = 
    57 		         (q + (p/2 - bdv) \<up> 2 = (p/2) \<up> 2)" and
    58   complete_square5:      "(q + p*bdv - bdv \<up> 2 = 0) = 
    59 		         (q + (p/2 - bdv) \<up> 2 = (p/2) \<up> 2)" and
    60 
    61   square_explicit1:      "(a + b \<up> 2 = c) = ( b \<up> 2 = c - a)" and
    62   square_explicit2:      "(a - b \<up> 2 = c) = (-(b \<up> 2) = c - a)" and
    63 
    64   (*bdv_explicit* required type constrain to real in --- (-8 - 2*x + x \<up> 2 = 0),  by rewriting ---*)
    65   bdv_explicit1:         "(a + bdv = b) = (bdv = - a + (b::real))" and
    66   bdv_explicit2:         "(a - bdv = b) = ((-1)*bdv = - a + (b::real))" and
    67   bdv_explicit3:         "((-1)*bdv = b) = (bdv = (-1)*(b::real))" and
    68 
    69   plus_leq:              "(0 <= a + b) = ((-1)*b <= a)"(*Isa?*) and
    70   minus_leq:             "(0 <= a - b) = (     b <= a)"(*Isa?*) and
    71 
    72 (*-- normalise --*)
    73   (*WN0509 compare LinEq.all_left "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)"*)
    74   all_left:              "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)" and
    75   makex1_x:              "a\<up>1  = a"   and
    76   real_assoc_1:          "a+(b+c) = a+b+c" and
    77   real_assoc_2:          "a*(b*c) = a*b*c" and
    78 
    79 (* ---- degree 0 ----*)
    80   d0_true:               "(0=0) = True" and
    81   d0_false:              "[|Not(bdv occurs_in a);Not(a=0)|] ==> (a=0) = False" and
    82 (* ---- degree 1 ----*)
    83   d1_isolate_add1:
    84    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv = 0) = (b*bdv = (-1)*a)" and
    85   d1_isolate_add2:
    86    "[|Not(bdv occurs_in a)|] ==> (a +   bdv = 0) = (  bdv = (-1)*a)" and
    87   d1_isolate_div:
    88    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv = c) = (bdv = c/b)" and
    89 (* ---- degree 2 ----*)
    90   d2_isolate_add1:
    91    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 2=0) = (b*bdv \<up> 2= (-1)*a)" and
    92   d2_isolate_add2:
    93    "[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 2=0) = (  bdv \<up> 2= (-1)*a)" and
    94   d2_isolate_div:
    95    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv \<up> 2=c) = (bdv \<up> 2=c/b)" and
    96   
    97   d2_prescind1:          "(a*bdv + b*bdv \<up> 2 = 0) = (bdv*(a +b*bdv)=0)" and
    98   d2_prescind2:          "(a*bdv +   bdv \<up> 2 = 0) = (bdv*(a +  bdv)=0)" and
    99   d2_prescind3:          "(  bdv + b*bdv \<up> 2 = 0) = (bdv*(1+b*bdv)=0)" and
   100   d2_prescind4:          "(  bdv +   bdv \<up> 2 = 0) = (bdv*(1+  bdv)=0)" and
   101   (* eliminate degree 2 *)
   102   (* thm for neg arguments in sqroot have postfix _neg *)
   103   d2_sqrt_equation1:     "[|(0<=c);Not(bdv occurs_in c)|] ==> 
   104                          (bdv \<up> 2=c) = ((bdv=sqrt c) | (bdv=(-1)*sqrt c ))" and
   105  d2_sqrt_equation1_neg:
   106   "[|(c<0);Not(bdv occurs_in c)|] ==> (bdv \<up> 2=c) = False" and
   107   d2_sqrt_equation2:     "(bdv \<up> 2=0) = (bdv=0)" and
   108   d2_sqrt_equation3:     "(b*bdv \<up> 2=0) = (bdv=0)"
   109 axiomatization where (*AK..if replaced by "and" we get errors:
   110   exception PTREE "nth _ []" raised 
   111   (line 783 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml"):
   112     'fun nth _ []      = raise PTREE "nth _ []"'
   113 and
   114   exception Bind raised 
   115   (line 1097 of "/usr/local/isabisac/test/Tools/isac/Frontend/interface.sml"):
   116     'val (Form f, tac, asms) = pt_extract (pt, p);' *)
   117   (* WN120315 these 2 thms need "::real", because no " \<up> " constrains type as
   118      required in test --- rls d2_polyeq_bdv_only_simplify --- *)
   119   d2_reduce_equation1:   "(bdv*(a +b*bdv)=0) = ((bdv=0)|(a+b*bdv=(0::real)))" and
   120   d2_reduce_equation2:   "(bdv*(a +  bdv)=0) = ((bdv=0)|(a+  bdv=(0::real)))"
   121 
   122 axiomatization where (*..if replaced by "and" we get errors:
   123   exception PTREE "nth _ []" raised 
   124   (line 783 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml"):
   125     'fun nth _ []      = raise PTREE "nth _ []"'
   126 and
   127   exception Bind raised 
   128   (line 1097 of "/usr/local/isabisac/test/Tools/isac/Frontend/interface.sml"):
   129     'val (Form f, tac, asms) = pt_extract (pt, p);' *)
   130   d2_pqformula1:         "[|0<=p \<up> 2 - 4*q|] ==> (q+p*bdv+   bdv \<up> 2=0) =
   131                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 4*q)/2) 
   132                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 4*q)/2))" and
   133   d2_pqformula1_neg:     "[|p \<up> 2 - 4*q<0|] ==> (q+p*bdv+   bdv \<up> 2=0) = False" and
   134   d2_pqformula2:         "[|0<=p \<up> 2 - 4*q|] ==> (q+p*bdv+1*bdv \<up> 2=0) = 
   135                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 4*q)/2) 
   136                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 4*q)/2))" and
   137   d2_pqformula2_neg:     "[|p \<up> 2 - 4*q<0|] ==> (q+p*bdv+1*bdv \<up> 2=0) = False" and
   138   d2_pqformula3:         "[|0<=1 - 4*q|] ==> (q+  bdv+   bdv \<up> 2=0) = 
   139                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
   140                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))" and
   141   d2_pqformula3_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+   bdv \<up> 2=0) = False" and
   142   d2_pqformula4:         "[|0<=1 - 4*q|] ==> (q+  bdv+1*bdv \<up> 2=0) = 
   143                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
   144                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))" and
   145   d2_pqformula4_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+1*bdv \<up> 2=0) = False" and
   146   d2_pqformula5:         "[|0<=p \<up> 2 - 0|] ==> (  p*bdv+   bdv \<up> 2=0) =
   147                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 0)/2) 
   148                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 0)/2))" and
   149  (* d2_pqformula5_neg not need p^2 never less zero in R *)
   150   d2_pqformula6:         "[|0<=p \<up> 2 - 0|] ==> (  p*bdv+1*bdv \<up> 2=0) = 
   151                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 0)/2) 
   152                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 0)/2))" and
   153   (* d2_pqformula6_neg not need p^2 never less zero in R *)
   154    d2_pqformula7:        "[|0<=1 - 0|] ==> (    bdv+   bdv \<up> 2=0) = 
   155                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
   156                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))" and
   157   (* d2_pqformula7_neg not need, because 1<0 ==> False*)
   158   d2_pqformula8:        "[|0<=1 - 0|] ==> (    bdv+1*bdv \<up> 2=0) = 
   159                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
   160                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))" and
   161   (* d2_pqformula8_neg not need, because 1<0 ==> False*)
   162   d2_pqformula9:        "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> 
   163                            (q+    1*bdv \<up> 2=0) = ((bdv= 0 + sqrt(0 - 4*q)/2) 
   164                                                 | (bdv= 0 - sqrt(0 - 4*q)/2))" and
   165   d2_pqformula9_neg:
   166    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+    1*bdv \<up> 2=0) = False" and
   167   d2_pqformula10:
   168    "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> (q+     bdv \<up> 2=0) = 
   169            ((bdv= 0 + sqrt(0 - 4*q)/2) 
   170           | (bdv= 0 - sqrt(0 - 4*q)/2))" and
   171   d2_pqformula10_neg:
   172    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+     bdv \<up> 2=0) = False" and
   173   d2_abcformula1:
   174    "[|0<=b \<up> 2 - 4*a*c|] ==> (c + b*bdv+a*bdv \<up> 2=0) =
   175            ((bdv=( -b + sqrt(b \<up> 2 - 4*a*c))/(2*a)) 
   176           | (bdv=( -b - sqrt(b \<up> 2 - 4*a*c))/(2*a)))" and
   177   d2_abcformula1_neg:
   178    "[|b \<up> 2 - 4*a*c<0|] ==> (c + b*bdv+a*bdv \<up> 2=0) = False" and
   179   d2_abcformula2:
   180    "[|0<=1 - 4*a*c|]     ==> (c+    bdv+a*bdv \<up> 2=0) = 
   181            ((bdv=( -1 + sqrt(1 - 4*a*c))/(2*a)) 
   182           | (bdv=( -1 - sqrt(1 - 4*a*c))/(2*a)))" and
   183   d2_abcformula2_neg:
   184    "[|1 - 4*a*c<0|]     ==> (c+    bdv+a*bdv \<up> 2=0) = False" and
   185   d2_abcformula3:
   186    "[|0<=b \<up> 2 - 4*1*c|] ==> (c + b*bdv+  bdv \<up> 2=0) =
   187            ((bdv=( -b + sqrt(b \<up> 2 - 4*1*c))/(2*1)) 
   188           | (bdv=( -b - sqrt(b \<up> 2 - 4*1*c))/(2*1)))" and
   189   d2_abcformula3_neg:
   190    "[|b \<up> 2 - 4*1*c<0|] ==> (c + b*bdv+  bdv \<up> 2=0) = False" and
   191   d2_abcformula4:
   192    "[|0<=1 - 4*1*c|] ==> (c +   bdv+  bdv \<up> 2=0) =
   193            ((bdv=( -1 + sqrt(1 - 4*1*c))/(2*1)) 
   194           | (bdv=( -1 - sqrt(1 - 4*1*c))/(2*1)))" and
   195   d2_abcformula4_neg:
   196    "[|1 - 4*1*c<0|] ==> (c +   bdv+  bdv \<up> 2=0) = False" and
   197   d2_abcformula5:
   198    "[|Not(bdv occurs_in c); 0<=0 - 4*a*c|] ==> (c +  a*bdv \<up> 2=0) =
   199            ((bdv=( 0 + sqrt(0 - 4*a*c))/(2*a)) 
   200           | (bdv=( 0 - sqrt(0 - 4*a*c))/(2*a)))" and
   201   d2_abcformula5_neg:
   202    "[|Not(bdv occurs_in c); 0 - 4*a*c<0|] ==> (c +  a*bdv \<up> 2=0) = False" and
   203   d2_abcformula6:
   204    "[|Not(bdv occurs_in c); 0<=0 - 4*1*c|]     ==> (c+    bdv \<up> 2=0) = 
   205            ((bdv=( 0 + sqrt(0 - 4*1*c))/(2*1)) 
   206           | (bdv=( 0 - sqrt(0 - 4*1*c))/(2*1)))" and
   207   d2_abcformula6_neg:
   208    "[|Not(bdv occurs_in c); 0 - 4*1*c<0|]     ==> (c+    bdv \<up> 2=0) = False" and
   209   d2_abcformula7:
   210    "[|0<=b \<up> 2 - 0|]     ==> (    b*bdv+a*bdv \<up> 2=0) = 
   211            ((bdv=( -b + sqrt(b \<up> 2 - 0))/(2*a)) 
   212           | (bdv=( -b - sqrt(b \<up> 2 - 0))/(2*a)))" and
   213   (* d2_abcformula7_neg not need b^2 never less zero in R *)
   214   d2_abcformula8:
   215    "[|0<=b \<up> 2 - 0|] ==> (    b*bdv+  bdv \<up> 2=0) =
   216            ((bdv=( -b + sqrt(b \<up> 2 - 0))/(2*1)) 
   217           | (bdv=( -b - sqrt(b \<up> 2 - 0))/(2*1)))" and
   218   (* d2_abcformula8_neg not need b^2 never less zero in R *)
   219   d2_abcformula9:
   220    "[|0<=1 - 0|]     ==> (      bdv+a*bdv \<up> 2=0) = 
   221            ((bdv=( -1 + sqrt(1 - 0))/(2*a)) 
   222           | (bdv=( -1 - sqrt(1 - 0))/(2*a)))" and
   223   (* d2_abcformula9_neg not need, because 1<0 ==> False*)
   224   d2_abcformula10:
   225    "[|0<=1 - 0|] ==> (      bdv+  bdv \<up> 2=0) =
   226            ((bdv=( -1 + sqrt(1 - 0))/(2*1)) 
   227           | (bdv=( -1 - sqrt(1 - 0))/(2*1)))" and
   228   (* d2_abcformula10_neg not need, because 1<0 ==> False*)
   229 
   230 
   231 (* ---- degree 3 ----*)
   232   d3_reduce_equation1:
   233   "(a*bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (a + b*bdv + c*bdv \<up> 2=0))" and
   234   d3_reduce_equation2:
   235   "(  bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (1 + b*bdv + c*bdv \<up> 2=0))" and
   236   d3_reduce_equation3:
   237   "(a*bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (a +   bdv + c*bdv \<up> 2=0))" and
   238   d3_reduce_equation4:
   239   "(  bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (1 +   bdv + c*bdv \<up> 2=0))" and
   240   d3_reduce_equation5:
   241   "(a*bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (a + b*bdv +   bdv \<up> 2=0))" and
   242   d3_reduce_equation6:
   243   "(  bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 + b*bdv +   bdv \<up> 2=0))" and
   244   d3_reduce_equation7:
   245   "(a*bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 +   bdv +   bdv \<up> 2=0))" and
   246   d3_reduce_equation8:
   247   "(  bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 +   bdv +   bdv \<up> 2=0))" and
   248   d3_reduce_equation9:
   249   "(a*bdv             + c*bdv \<up> 3=0) = (bdv=0 | (a         + c*bdv \<up> 2=0))" and
   250   d3_reduce_equation10:
   251   "(  bdv             + c*bdv \<up> 3=0) = (bdv=0 | (1         + c*bdv \<up> 2=0))" and
   252   d3_reduce_equation11:
   253   "(a*bdv             +   bdv \<up> 3=0) = (bdv=0 | (a         +   bdv \<up> 2=0))" and
   254   d3_reduce_equation12:
   255   "(  bdv             +   bdv \<up> 3=0) = (bdv=0 | (1         +   bdv \<up> 2=0))" and
   256   d3_reduce_equation13:
   257   "(        b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (    b*bdv + c*bdv \<up> 2=0))" and
   258   d3_reduce_equation14:
   259   "(          bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (      bdv + c*bdv \<up> 2=0))" and
   260   d3_reduce_equation15:
   261   "(        b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (    b*bdv +   bdv \<up> 2=0))" and
   262   d3_reduce_equation16:
   263   "(          bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (      bdv +   bdv \<up> 2=0))" and
   264   d3_isolate_add1:
   265   "[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 3=0) = (b*bdv \<up> 3= (-1)*a)" and
   266   d3_isolate_add2:
   267   "[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 3=0) = (  bdv \<up> 3= (-1)*a)" and
   268   d3_isolate_div:
   269    "[|Not(b=0);Not(bdv occurs_in a)|] ==> (b*bdv \<up> 3=c) = (bdv \<up> 3=c/b)" and
   270   d3_root_equation2:
   271   "(bdv \<up> 3=0) = (bdv=0)" and
   272   d3_root_equation1:
   273   "(bdv \<up> 3=c) = (bdv = nroot 3 c)" and
   274 
   275 (* ---- degree 4 ----*)
   276  (* RL03.FIXME es wir nicht getestet ob u>0 *)
   277  d4_sub_u1:
   278  "(c+b*bdv \<up> 2+a*bdv \<up> 4=0) =
   279    ((a*u \<up> 2+b*u+c=0) & (bdv \<up> 2=u))" and
   280 
   281 (* ---- 7.3.02 von Termorder ---- *)
   282 
   283   bdv_collect_1:      "l * bdv + m * bdv = (l + m) * bdv" and
   284   bdv_collect_2:      "bdv + m * bdv = (1 + m) * bdv" and
   285   bdv_collect_3:      "l * bdv + bdv = (l + 1) * bdv" and
   286 
   287 (*  bdv_collect_assoc0_1 "l * bdv + m * bdv + k = (l + m) * bdv + k"
   288     bdv_collect_assoc0_2 "bdv + m * bdv + k = (1 + m) * bdv + k"
   289     bdv_collect_assoc0_3 "l * bdv + bdv + k = (l + 1) * bdv + k"
   290 *)
   291   bdv_collect_assoc1_1: "l * bdv + (m * bdv + k) = (l + m) * bdv + k" and
   292   bdv_collect_assoc1_2: "bdv + (m * bdv + k) = (1 + m) * bdv + k" and
   293   bdv_collect_assoc1_3: "l * bdv + (bdv + k) = (l + 1) * bdv + k" and
   294                         
   295   bdv_collect_assoc2_1: "k + l * bdv + m * bdv = k + (l + m) * bdv" and
   296   bdv_collect_assoc2_2: "k + bdv + m * bdv = k + (1 + m) * bdv" and
   297   bdv_collect_assoc2_3: "k + l * bdv + bdv = k + (l + 1) * bdv" and
   298 
   299 
   300   bdv_n_collect_1:     "l * bdv \<up> n + m * bdv \<up> n = (l + m) * bdv \<up> n" and
   301   bdv_n_collect_2:     " bdv \<up> n + m * bdv \<up> n = (1 + m) * bdv \<up> n" and
   302   bdv_n_collect_3:     "l * bdv \<up> n + bdv \<up> n = (l + 1) * bdv \<up> n" (*order!*) and
   303 
   304   bdv_n_collect_assoc1_1:
   305                       "l * bdv \<up> n + (m * bdv \<up> n + k) = (l + m) * bdv \<up> n + k" and
   306   bdv_n_collect_assoc1_2: "bdv \<up> n + (m * bdv \<up> n + k) = (1 + m) * bdv \<up> n + k" and
   307   bdv_n_collect_assoc1_3: "l * bdv \<up> n + (bdv \<up> n + k) = (l + 1) * bdv \<up> n + k" and
   308 
   309   bdv_n_collect_assoc2_1: "k + l * bdv \<up> n + m * bdv \<up> n = k +(l + m) * bdv \<up> n" and
   310   bdv_n_collect_assoc2_2: "k + bdv \<up> n + m * bdv \<up> n = k + (1 + m) * bdv \<up> n" and
   311   bdv_n_collect_assoc2_3: "k + l * bdv \<up> n + bdv \<up> n = k + (l + 1) * bdv \<up> n" and
   312 
   313 (*WN.14.3.03*)
   314   real_minus_div:         "- (a / b) = (-1 * a) / b" and
   315                           
   316   separate_bdv:           "(a * bdv) / b = (a / b) * (bdv::real)" and
   317   separate_bdv_n:         "(a * bdv \<up> n) / b = (a / b) * bdv \<up> n" and
   318   separate_1_bdv:         "bdv / b = (1 / b) * (bdv::real)" and
   319   separate_1_bdv_n:       "bdv \<up> n / b = (1 / b) * bdv \<up> n"
   320 
   321 ML \<open>
   322 (*-------------------------rulse-------------------------*)
   323 val PolyEq_prls = (*3.10.02:just the following order due to subterm evaluation*)
   324   Rule_Set.append_rules "PolyEq_prls" Rule_Set.empty 
   325 	     [\<^rule_eval>\<open>Prog_Expr.ident\<close> (Prog_Expr.eval_ident "#ident_"),
   326 	      \<^rule_eval>\<open>Prog_Expr.matches\<close> (Prog_Expr.eval_matches ""),
   327 	      \<^rule_eval>\<open>Prog_Expr.lhs\<close> (Prog_Expr.eval_lhs ""),
   328 	      \<^rule_eval>\<open>Prog_Expr.rhs\<close> (Prog_Expr.eval_rhs ""),
   329 	      \<^rule_eval>\<open>is_expanded_in\<close> (eval_is_expanded_in ""),
   330 	      \<^rule_eval>\<open>is_poly_in\<close> (eval_is_poly_in ""),
   331 	      \<^rule_eval>\<open>has_degree_in\<close> (eval_has_degree_in ""),    
   332         \<^rule_eval>\<open>is_polyrat_in\<close> (eval_is_polyrat_in ""),
   333 	      (*\<^rule_eval>\<open>Prog_Expr.occurs_in\<close> (Prog_Expr.eval_occurs_in ""),   *) 
   334 	      (*\<^rule_eval>\<open>Prog_Expr.is_const\<close> (Prog_Expr.eval_const "#is_const_"),*)
   335 	      \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
   336         \<^rule_eval>\<open>is_rootTerm_in\<close> (eval_is_rootTerm_in ""),
   337 	      \<^rule_eval>\<open>is_ratequation_in\<close> (eval_is_ratequation_in ""),
   338 	      Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
   339 	      Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false}),
   340 	      Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
   341 	      Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
   342 	      Rule.Thm ("or_true",ThmC.numerals_to_Free @{thm or_true}),
   343 	      Rule.Thm ("or_false",ThmC.numerals_to_Free @{thm or_false})
   344 	       ];
   345 
   346 val PolyEq_erls = 
   347     Rule_Set.merge "PolyEq_erls" LinEq_erls
   348     (Rule_Set.append_rules "ops_preds" calculate_Rational
   349 		[\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
   350 		 Rule.Thm ("plus_leq", ThmC.numerals_to_Free @{thm plus_leq}),
   351 		 Rule.Thm ("minus_leq", ThmC.numerals_to_Free @{thm minus_leq}),
   352 		 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
   353 		 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
   354 		 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3})
   355 		 ]);
   356 
   357 val PolyEq_crls = 
   358     Rule_Set.merge "PolyEq_crls" LinEq_crls
   359     (Rule_Set.append_rules "ops_preds" calculate_Rational
   360 		[\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
   361 		 Rule.Thm ("plus_leq", ThmC.numerals_to_Free @{thm plus_leq}),
   362 		 Rule.Thm ("minus_leq", ThmC.numerals_to_Free @{thm minus_leq}),
   363 		 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
   364 		 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
   365 		 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3})
   366 		 ]);
   367 
   368 val cancel_leading_coeff = prep_rls'(
   369   Rule_Def.Repeat {id = "cancel_leading_coeff", preconds = [], 
   370        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   371       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
   372       rules = 
   373       [Rule.Thm ("cancel_leading_coeff1",ThmC.numerals_to_Free @{thm cancel_leading_coeff1}),
   374        Rule.Thm ("cancel_leading_coeff2",ThmC.numerals_to_Free @{thm cancel_leading_coeff2}),
   375        Rule.Thm ("cancel_leading_coeff3",ThmC.numerals_to_Free @{thm cancel_leading_coeff3}),
   376        Rule.Thm ("cancel_leading_coeff4",ThmC.numerals_to_Free @{thm cancel_leading_coeff4}),
   377        Rule.Thm ("cancel_leading_coeff5",ThmC.numerals_to_Free @{thm cancel_leading_coeff5}),
   378        Rule.Thm ("cancel_leading_coeff6",ThmC.numerals_to_Free @{thm cancel_leading_coeff6}),
   379        Rule.Thm ("cancel_leading_coeff7",ThmC.numerals_to_Free @{thm cancel_leading_coeff7}),
   380        Rule.Thm ("cancel_leading_coeff8",ThmC.numerals_to_Free @{thm cancel_leading_coeff8}),
   381        Rule.Thm ("cancel_leading_coeff9",ThmC.numerals_to_Free @{thm cancel_leading_coeff9}),
   382        Rule.Thm ("cancel_leading_coeff10",ThmC.numerals_to_Free @{thm cancel_leading_coeff10}),
   383        Rule.Thm ("cancel_leading_coeff11",ThmC.numerals_to_Free @{thm cancel_leading_coeff11}),
   384        Rule.Thm ("cancel_leading_coeff12",ThmC.numerals_to_Free @{thm cancel_leading_coeff12}),
   385        Rule.Thm ("cancel_leading_coeff13",ThmC.numerals_to_Free @{thm cancel_leading_coeff13})
   386        ],scr = Rule.Empty_Prog});
   387 
   388 val prep_rls' = Auto_Prog.prep_rls @{theory};
   389 \<close>
   390 ML\<open>
   391 val complete_square = prep_rls'(
   392   Rule_Def.Repeat {id = "complete_square", preconds = [], 
   393        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   394       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [],  errpatts = [],
   395       rules = [Rule.Thm ("complete_square1",ThmC.numerals_to_Free @{thm complete_square1}),
   396 	       Rule.Thm ("complete_square2",ThmC.numerals_to_Free @{thm complete_square2}),
   397 	       Rule.Thm ("complete_square3",ThmC.numerals_to_Free @{thm complete_square3}),
   398 	       Rule.Thm ("complete_square4",ThmC.numerals_to_Free @{thm complete_square4}),
   399 	       Rule.Thm ("complete_square5",ThmC.numerals_to_Free @{thm complete_square5})
   400 	       ],
   401       scr = Rule.Empty_Prog
   402       });
   403 
   404 val polyeq_simplify = prep_rls'(
   405   Rule_Def.Repeat {id = "polyeq_simplify", preconds = [], 
   406        rew_ord = ("termlessI",termlessI), 
   407        erls = PolyEq_erls, 
   408        srls = Rule_Set.Empty, 
   409        calc = [], errpatts = [],
   410        rules = [Rule.Thm  ("real_assoc_1",ThmC.numerals_to_Free @{thm real_assoc_1}),
   411 		Rule.Thm  ("real_assoc_2",ThmC.numerals_to_Free @{thm real_assoc_2}),
   412 		Rule.Thm  ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus}),
   413 		Rule.Thm  ("real_unari_minus",ThmC.numerals_to_Free @{thm real_unari_minus}),
   414 		Rule.Thm  ("realpow_multI",ThmC.numerals_to_Free @{thm realpow_multI}),
   415 		\<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
   416 		\<^rule_eval>\<open>minus\<close> (**)(eval_binop "#sub_"),
   417 		\<^rule_eval>\<open>times\<close> (**)(eval_binop "#mult_"),
   418 		\<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e"),
   419 		\<^rule_eval>\<open>sqrt\<close> (eval_sqrt "#sqrt_"),
   420 		\<^rule_eval>\<open>powr\<close> (**)(eval_binop "#power_"),
   421                 Rule.Rls_ reduce_012
   422                 ],
   423        scr = Rule.Empty_Prog
   424        });
   425 \<close>
   426 rule_set_knowledge
   427   cancel_leading_coeff = cancel_leading_coeff and
   428   complete_square = complete_square and
   429   PolyEq_erls = PolyEq_erls and
   430   polyeq_simplify = polyeq_simplify
   431 ML\<open>
   432 
   433 (* ------------- polySolve ------------------ *)
   434 (* -- d0 -- *)
   435 (*isolate the bound variable in an d0 equation; 'bdv' is a meta-constant*)
   436 val d0_polyeq_simplify = prep_rls'(
   437   Rule_Def.Repeat {id = "d0_polyeq_simplify", preconds = [],
   438        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   439        erls = PolyEq_erls,
   440        srls = Rule_Set.Empty, 
   441        calc = [], errpatts = [],
   442        rules = [Rule.Thm("d0_true",ThmC.numerals_to_Free @{thm d0_true}),
   443 		Rule.Thm("d0_false",ThmC.numerals_to_Free @{thm  d0_false})
   444 		],
   445        scr = Rule.Empty_Prog
   446        });
   447 
   448 (* -- d1 -- *)
   449 (*isolate the bound variable in an d1 equation; 'bdv' is a meta-constant*)
   450 val d1_polyeq_simplify = prep_rls'(
   451   Rule_Def.Repeat {id = "d1_polyeq_simplify", preconds = [],
   452        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   453        erls = PolyEq_erls,
   454        srls = Rule_Set.Empty, 
   455        calc = [], errpatts = [],
   456        rules = [
   457 		Rule.Thm("d1_isolate_add1",ThmC.numerals_to_Free @{thm d1_isolate_add1}), 
   458 		(* a+bx=0 -> bx=-a *)
   459 		Rule.Thm("d1_isolate_add2",ThmC.numerals_to_Free @{thm d1_isolate_add2}), 
   460 		(* a+ x=0 ->  x=-a *)
   461 		Rule.Thm("d1_isolate_div",ThmC.numerals_to_Free @{thm d1_isolate_div})    
   462 		(*   bx=c -> x=c/b *)  
   463 		],
   464        scr = Rule.Empty_Prog
   465        });
   466 
   467 \<close>
   468 subsection \<open>degree 2\<close>
   469 ML\<open>
   470 (* isolate the bound variable in an d2 equation with bdv only;
   471   "bdv" is a meta-constant substituted for the "x" below by isac's rewriter. *)
   472 val d2_polyeq_bdv_only_simplify = prep_rls'(
   473   Rule_Def.Repeat {id = "d2_polyeq_bdv_only_simplify", preconds = [], rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   474     erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
   475     rules =
   476       [Rule.Thm ("d2_prescind1", ThmC.numerals_to_Free @{thm d2_prescind1}), (*   ax+bx^2=0 -> x(a+bx)=0 *)
   477        Rule.Thm ("d2_prescind2", ThmC.numerals_to_Free @{thm d2_prescind2}), (*   ax+ x^2=0 -> x(a+ x)=0 *)
   478        Rule.Thm ("d2_prescind3", ThmC.numerals_to_Free @{thm d2_prescind3}), (*    x+bx^2=0 -> x(1+bx)=0 *)
   479        Rule.Thm ("d2_prescind4", ThmC.numerals_to_Free @{thm d2_prescind4}), (*    x+ x^2=0 -> x(1+ x)=0 *)
   480        Rule.Thm ("d2_sqrt_equation1", ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),    (* x^2=c   -> x=+-sqrt(c) *)
   481        Rule.Thm ("d2_sqrt_equation1_neg", ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}), (* [0<c] x^2=c  -> []*)
   482        Rule.Thm ("d2_sqrt_equation2", ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),    (*  x^2=0 ->    x=0       *)
   483        Rule.Thm ("d2_reduce_equation1", ThmC.numerals_to_Free @{thm d2_reduce_equation1}),(* x(a+bx)=0 -> x=0 |a+bx=0*)
   484        Rule.Thm ("d2_reduce_equation2", ThmC.numerals_to_Free @{thm d2_reduce_equation2}),(* x(a+ x)=0 -> x=0 |a+ x=0*)
   485        Rule.Thm ("d2_isolate_div", ThmC.numerals_to_Free @{thm d2_isolate_div})           (* bx^2=c -> x^2=c/b      *)
   486        ],
   487        scr = Rule.Empty_Prog
   488        });
   489 \<close>
   490 ML\<open>
   491 (* isolate the bound variable in an d2 equation with sqrt only; 
   492    'bdv' is a meta-constant*)
   493 val d2_polyeq_sq_only_simplify = prep_rls'(
   494   Rule_Def.Repeat {id = "d2_polyeq_sq_only_simplify", preconds = [],
   495        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   496        erls = PolyEq_erls,
   497        srls = Rule_Set.Empty, 
   498        calc = [], errpatts = [],
   499        (*asm_thm = [("d2_sqrt_equation1", ""),("d2_sqrt_equation1_neg", ""),
   500                   ("d2_isolate_div", "")],*)
   501        rules = [Rule.Thm("d2_isolate_add1",ThmC.numerals_to_Free @{thm d2_isolate_add1}),
   502                 (* a+   bx^2=0 -> bx^2=(-1)a*)
   503 		Rule.Thm("d2_isolate_add2",ThmC.numerals_to_Free @{thm d2_isolate_add2}),
   504                 (* a+    x^2=0 ->  x^2=(-1)a*)
   505 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
   506                 (*  x^2=0 ->    x=0    *)
   507 		Rule.Thm("d2_sqrt_equation1",ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),
   508                 (* x^2=c   -> x=+-sqrt(c)*)
   509 		Rule.Thm("d2_sqrt_equation1_neg",ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}),
   510                 (* [c<0] x^2=c  -> x=[] *)
   511 		Rule.Thm("d2_isolate_div",ThmC.numerals_to_Free @{thm d2_isolate_div})
   512                  (* bx^2=c -> x^2=c/b*)
   513 		],
   514        scr = Rule.Empty_Prog
   515        });
   516 \<close>
   517 ML\<open>
   518 (* isolate the bound variable in an d2 equation with pqFormula;
   519    'bdv' is a meta-constant*)
   520 val d2_polyeq_pqFormula_simplify = prep_rls'(
   521   Rule_Def.Repeat {id = "d2_polyeq_pqFormula_simplify", preconds = [],
   522        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
   523        srls = Rule_Set.Empty, calc = [], errpatts = [],
   524        rules = [Rule.Thm("d2_pqformula1",ThmC.numerals_to_Free @{thm d2_pqformula1}),
   525                 (* q+px+ x^2=0 *)
   526 		Rule.Thm("d2_pqformula1_neg",ThmC.numerals_to_Free @{thm d2_pqformula1_neg}),
   527                 (* q+px+ x^2=0 *)
   528 		Rule.Thm("d2_pqformula2",ThmC.numerals_to_Free @{thm d2_pqformula2}), 
   529                 (* q+px+1x^2=0 *)
   530 		Rule.Thm("d2_pqformula2_neg",ThmC.numerals_to_Free @{thm d2_pqformula2_neg}),
   531                 (* q+px+1x^2=0 *)
   532 		Rule.Thm("d2_pqformula3",ThmC.numerals_to_Free @{thm d2_pqformula3}),
   533                 (* q+ x+ x^2=0 *)
   534 		Rule.Thm("d2_pqformula3_neg",ThmC.numerals_to_Free @{thm d2_pqformula3_neg}), 
   535                 (* q+ x+ x^2=0 *)
   536 		Rule.Thm("d2_pqformula4",ThmC.numerals_to_Free @{thm d2_pqformula4}),
   537                 (* q+ x+1x^2=0 *)
   538 		Rule.Thm("d2_pqformula4_neg",ThmC.numerals_to_Free @{thm d2_pqformula4_neg}),
   539                 (* q+ x+1x^2=0 *)
   540 		Rule.Thm("d2_pqformula5",ThmC.numerals_to_Free @{thm d2_pqformula5}),
   541                 (*   qx+ x^2=0 *)
   542 		Rule.Thm("d2_pqformula6",ThmC.numerals_to_Free @{thm d2_pqformula6}),
   543                 (*   qx+1x^2=0 *)
   544 		Rule.Thm("d2_pqformula7",ThmC.numerals_to_Free @{thm d2_pqformula7}),
   545                 (*    x+ x^2=0 *)
   546 		Rule.Thm("d2_pqformula8",ThmC.numerals_to_Free @{thm d2_pqformula8}),
   547                 (*    x+1x^2=0 *)
   548 		Rule.Thm("d2_pqformula9",ThmC.numerals_to_Free @{thm d2_pqformula9}),
   549                 (* q   +1x^2=0 *)
   550 		Rule.Thm("d2_pqformula9_neg",ThmC.numerals_to_Free @{thm d2_pqformula9_neg}),
   551                 (* q   +1x^2=0 *)
   552 		Rule.Thm("d2_pqformula10",ThmC.numerals_to_Free @{thm d2_pqformula10}),
   553                 (* q   + x^2=0 *)
   554 		Rule.Thm("d2_pqformula10_neg",ThmC.numerals_to_Free @{thm d2_pqformula10_neg}),
   555                 (* q   + x^2=0 *)
   556 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
   557                 (*       x^2=0 *)
   558 		Rule.Thm("d2_sqrt_equation3",ThmC.numerals_to_Free @{thm d2_sqrt_equation3})
   559                (*      1x^2=0 *)
   560 	       ],scr = Rule.Empty_Prog
   561        });
   562 \<close>
   563 ML\<open>
   564 (* isolate the bound variable in an d2 equation with abcFormula; 
   565    'bdv' is a meta-constant*)
   566 val d2_polyeq_abcFormula_simplify = prep_rls'(
   567   Rule_Def.Repeat {id = "d2_polyeq_abcFormula_simplify", preconds = [],
   568        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
   569        srls = Rule_Set.Empty, calc = [], errpatts = [],
   570        rules = [Rule.Thm("d2_abcformula1",ThmC.numerals_to_Free @{thm d2_abcformula1}),
   571                 (*c+bx+cx^2=0 *)
   572 		Rule.Thm("d2_abcformula1_neg",ThmC.numerals_to_Free @{thm d2_abcformula1_neg}),
   573                 (*c+bx+cx^2=0 *)
   574 		Rule.Thm("d2_abcformula2",ThmC.numerals_to_Free @{thm d2_abcformula2}),
   575                 (*c+ x+cx^2=0 *)
   576 		Rule.Thm("d2_abcformula2_neg",ThmC.numerals_to_Free @{thm d2_abcformula2_neg}),
   577                 (*c+ x+cx^2=0 *)
   578 		Rule.Thm("d2_abcformula3",ThmC.numerals_to_Free @{thm d2_abcformula3}), 
   579                 (*c+bx+ x^2=0 *)
   580 		Rule.Thm("d2_abcformula3_neg",ThmC.numerals_to_Free @{thm d2_abcformula3_neg}),
   581                 (*c+bx+ x^2=0 *)
   582 		Rule.Thm("d2_abcformula4",ThmC.numerals_to_Free @{thm d2_abcformula4}),
   583                 (*c+ x+ x^2=0 *)
   584 		Rule.Thm("d2_abcformula4_neg",ThmC.numerals_to_Free @{thm d2_abcformula4_neg}),
   585                 (*c+ x+ x^2=0 *)
   586 		Rule.Thm("d2_abcformula5",ThmC.numerals_to_Free @{thm d2_abcformula5}),
   587                 (*c+   cx^2=0 *)
   588 		Rule.Thm("d2_abcformula5_neg",ThmC.numerals_to_Free @{thm d2_abcformula5_neg}),
   589                 (*c+   cx^2=0 *)
   590 		Rule.Thm("d2_abcformula6",ThmC.numerals_to_Free @{thm d2_abcformula6}),
   591                 (*c+    x^2=0 *)
   592 		Rule.Thm("d2_abcformula6_neg",ThmC.numerals_to_Free @{thm d2_abcformula6_neg}),
   593                 (*c+    x^2=0 *)
   594 		Rule.Thm("d2_abcformula7",ThmC.numerals_to_Free @{thm d2_abcformula7}),
   595                 (*  bx+ax^2=0 *)
   596 		Rule.Thm("d2_abcformula8",ThmC.numerals_to_Free @{thm d2_abcformula8}),
   597                 (*  bx+ x^2=0 *)
   598 		Rule.Thm("d2_abcformula9",ThmC.numerals_to_Free @{thm d2_abcformula9}),
   599                 (*   x+ax^2=0 *)
   600 		Rule.Thm("d2_abcformula10",ThmC.numerals_to_Free @{thm d2_abcformula10}),
   601                 (*   x+ x^2=0 *)
   602 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
   603                 (*      x^2=0 *)  
   604 		Rule.Thm("d2_sqrt_equation3",ThmC.numerals_to_Free @{thm d2_sqrt_equation3})
   605                (*     bx^2=0 *)  
   606 	       ],
   607        scr = Rule.Empty_Prog
   608        });
   609 \<close>
   610 ML\<open>
   611 
   612 (* isolate the bound variable in an d2 equation; 
   613    'bdv' is a meta-constant*)
   614 val d2_polyeq_simplify = prep_rls'(
   615   Rule_Def.Repeat {id = "d2_polyeq_simplify", preconds = [],
   616        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
   617        srls = Rule_Set.Empty, calc = [], errpatts = [],
   618        rules = [Rule.Thm("d2_pqformula1",ThmC.numerals_to_Free @{thm d2_pqformula1}),
   619                 (* p+qx+ x^2=0 *)
   620 		Rule.Thm("d2_pqformula1_neg",ThmC.numerals_to_Free @{thm d2_pqformula1_neg}),
   621                 (* p+qx+ x^2=0 *)
   622 		Rule.Thm("d2_pqformula2",ThmC.numerals_to_Free @{thm d2_pqformula2}),
   623                 (* p+qx+1x^2=0 *)
   624 		Rule.Thm("d2_pqformula2_neg",ThmC.numerals_to_Free @{thm d2_pqformula2_neg}),
   625                 (* p+qx+1x^2=0 *)
   626 		Rule.Thm("d2_pqformula3",ThmC.numerals_to_Free @{thm d2_pqformula3}),
   627                 (* p+ x+ x^2=0 *)
   628 		Rule.Thm("d2_pqformula3_neg",ThmC.numerals_to_Free @{thm d2_pqformula3_neg}),
   629                 (* p+ x+ x^2=0 *)
   630 		Rule.Thm("d2_pqformula4",ThmC.numerals_to_Free @{thm d2_pqformula4}), 
   631                 (* p+ x+1x^2=0 *)
   632 		Rule.Thm("d2_pqformula4_neg",ThmC.numerals_to_Free @{thm d2_pqformula4_neg}),
   633                 (* p+ x+1x^2=0 *)
   634 		Rule.Thm("d2_abcformula1",ThmC.numerals_to_Free @{thm d2_abcformula1}),
   635                 (* c+bx+cx^2=0 *)
   636 		Rule.Thm("d2_abcformula1_neg",ThmC.numerals_to_Free @{thm d2_abcformula1_neg}),
   637                 (* c+bx+cx^2=0 *)
   638 		Rule.Thm("d2_abcformula2",ThmC.numerals_to_Free @{thm d2_abcformula2}),
   639                 (* c+ x+cx^2=0 *)
   640 		Rule.Thm("d2_abcformula2_neg",ThmC.numerals_to_Free @{thm d2_abcformula2_neg}),
   641                 (* c+ x+cx^2=0 *)
   642 		Rule.Thm("d2_prescind1",ThmC.numerals_to_Free @{thm d2_prescind1}),
   643                 (*   ax+bx^2=0 -> x(a+bx)=0 *)
   644 		Rule.Thm("d2_prescind2",ThmC.numerals_to_Free @{thm d2_prescind2}),
   645                 (*   ax+ x^2=0 -> x(a+ x)=0 *)
   646 		Rule.Thm("d2_prescind3",ThmC.numerals_to_Free @{thm d2_prescind3}),
   647                 (*    x+bx^2=0 -> x(1+bx)=0 *)
   648 		Rule.Thm("d2_prescind4",ThmC.numerals_to_Free @{thm d2_prescind4}),
   649                 (*    x+ x^2=0 -> x(1+ x)=0 *)
   650 		Rule.Thm("d2_isolate_add1",ThmC.numerals_to_Free @{thm d2_isolate_add1}),
   651                 (* a+   bx^2=0 -> bx^2=(-1)a*)
   652 		Rule.Thm("d2_isolate_add2",ThmC.numerals_to_Free @{thm d2_isolate_add2}),
   653                 (* a+    x^2=0 ->  x^2=(-1)a*)
   654 		Rule.Thm("d2_sqrt_equation1",ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),
   655                 (* x^2=c   -> x=+-sqrt(c)*)
   656 		Rule.Thm("d2_sqrt_equation1_neg",ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}),
   657                 (* [c<0] x^2=c   -> x=[]*)
   658 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
   659                 (*  x^2=0 ->    x=0    *)
   660 		Rule.Thm("d2_reduce_equation1",ThmC.numerals_to_Free @{thm d2_reduce_equation1}),
   661                 (* x(a+bx)=0 -> x=0 | a+bx=0*)
   662 		Rule.Thm("d2_reduce_equation2",ThmC.numerals_to_Free @{thm d2_reduce_equation2}),
   663                 (* x(a+ x)=0 -> x=0 | a+ x=0*)
   664 		Rule.Thm("d2_isolate_div",ThmC.numerals_to_Free @{thm d2_isolate_div})
   665                (* bx^2=c -> x^2=c/b*)
   666 	       ],
   667        scr = Rule.Empty_Prog
   668       });
   669 \<close>
   670 ML\<open>
   671 
   672 (* -- d3 -- *)
   673 (* isolate the bound variable in an d3 equation; 'bdv' is a meta-constant *)
   674 val d3_polyeq_simplify = prep_rls'(
   675   Rule_Def.Repeat {id = "d3_polyeq_simplify", preconds = [],
   676        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
   677        srls = Rule_Set.Empty, calc = [], errpatts = [],
   678        rules = 
   679        [Rule.Thm("d3_reduce_equation1",ThmC.numerals_to_Free @{thm d3_reduce_equation1}),
   680 	(*a*bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
   681         (bdv=0 | (a + b*bdv + c*bdv \<up> 2=0)*)
   682 	Rule.Thm("d3_reduce_equation2",ThmC.numerals_to_Free @{thm d3_reduce_equation2}),
   683 	(*  bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
   684         (bdv=0 | (1 + b*bdv + c*bdv \<up> 2=0)*)
   685 	Rule.Thm("d3_reduce_equation3",ThmC.numerals_to_Free @{thm d3_reduce_equation3}),
   686 	(*a*bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
   687         (bdv=0 | (a +   bdv + c*bdv \<up> 2=0)*)
   688 	Rule.Thm("d3_reduce_equation4",ThmC.numerals_to_Free @{thm d3_reduce_equation4}),
   689 	(*  bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
   690         (bdv=0 | (1 +   bdv + c*bdv \<up> 2=0)*)
   691 	Rule.Thm("d3_reduce_equation5",ThmC.numerals_to_Free @{thm d3_reduce_equation5}),
   692 	(*a*bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   693         (bdv=0 | (a + b*bdv +   bdv \<up> 2=0)*)
   694 	Rule.Thm("d3_reduce_equation6",ThmC.numerals_to_Free @{thm d3_reduce_equation6}),
   695 	(*  bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   696         (bdv=0 | (1 + b*bdv +   bdv \<up> 2=0)*)
   697 	Rule.Thm("d3_reduce_equation7",ThmC.numerals_to_Free @{thm d3_reduce_equation7}),
   698 	     (*a*bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
   699              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
   700 	Rule.Thm("d3_reduce_equation8",ThmC.numerals_to_Free @{thm d3_reduce_equation8}),
   701 	     (*  bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
   702              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
   703 	Rule.Thm("d3_reduce_equation9",ThmC.numerals_to_Free @{thm d3_reduce_equation9}),
   704 	     (*a*bdv             + c*bdv \<up> 3=0) = 
   705              (bdv=0 | (a         + c*bdv \<up> 2=0)*)
   706 	Rule.Thm("d3_reduce_equation10",ThmC.numerals_to_Free @{thm d3_reduce_equation10}),
   707 	     (*  bdv             + c*bdv \<up> 3=0) = 
   708              (bdv=0 | (1         + c*bdv \<up> 2=0)*)
   709 	Rule.Thm("d3_reduce_equation11",ThmC.numerals_to_Free @{thm d3_reduce_equation11}),
   710 	     (*a*bdv             +   bdv \<up> 3=0) = 
   711              (bdv=0 | (a         +   bdv \<up> 2=0)*)
   712 	Rule.Thm("d3_reduce_equation12",ThmC.numerals_to_Free @{thm d3_reduce_equation12}),
   713 	     (*  bdv             +   bdv \<up> 3=0) = 
   714              (bdv=0 | (1         +   bdv \<up> 2=0)*)
   715 	Rule.Thm("d3_reduce_equation13",ThmC.numerals_to_Free @{thm d3_reduce_equation13}),
   716 	     (*        b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
   717              (bdv=0 | (    b*bdv + c*bdv \<up> 2=0)*)
   718 	Rule.Thm("d3_reduce_equation14",ThmC.numerals_to_Free @{thm d3_reduce_equation14}),
   719 	     (*          bdv \<up> 2 + c*bdv \<up> 3=0) = 
   720              (bdv=0 | (      bdv + c*bdv \<up> 2=0)*)
   721 	Rule.Thm("d3_reduce_equation15",ThmC.numerals_to_Free @{thm d3_reduce_equation15}),
   722 	     (*        b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   723              (bdv=0 | (    b*bdv +   bdv \<up> 2=0)*)
   724 	Rule.Thm("d3_reduce_equation16",ThmC.numerals_to_Free @{thm d3_reduce_equation16}),
   725 	     (*          bdv \<up> 2 +   bdv \<up> 3=0) = 
   726              (bdv=0 | (      bdv +   bdv \<up> 2=0)*)
   727 	Rule.Thm("d3_isolate_add1",ThmC.numerals_to_Free @{thm d3_isolate_add1}),
   728 	     (*[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 3=0) = 
   729               (bdv=0 | (b*bdv \<up> 3=a)*)
   730 	Rule.Thm("d3_isolate_add2",ThmC.numerals_to_Free @{thm d3_isolate_add2}),
   731              (*[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 3=0) = 
   732               (bdv=0 | (  bdv \<up> 3=a)*)
   733 	Rule.Thm("d3_isolate_div",ThmC.numerals_to_Free @{thm d3_isolate_div}),
   734         (*[|Not(b=0)|] ==> (b*bdv \<up> 3=c) = (bdv \<up> 3=c/b*)
   735         Rule.Thm("d3_root_equation2",ThmC.numerals_to_Free @{thm d3_root_equation2}),
   736         (*(bdv \<up> 3=0) = (bdv=0) *)
   737 	Rule.Thm("d3_root_equation1",ThmC.numerals_to_Free @{thm d3_root_equation1})
   738        (*bdv \<up> 3=c) = (bdv = nroot 3 c*)
   739        ],
   740        scr = Rule.Empty_Prog
   741       });
   742 \<close>
   743 ML\<open>
   744 
   745 (* -- d4 -- *)
   746 (*isolate the bound variable in an d4 equation; 'bdv' is a meta-constant*)
   747 val d4_polyeq_simplify = prep_rls'(
   748   Rule_Def.Repeat {id = "d4_polyeq_simplify", preconds = [],
   749        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
   750        srls = Rule_Set.Empty, calc = [], errpatts = [],
   751        rules = 
   752        [Rule.Thm("d4_sub_u1",ThmC.numerals_to_Free @{thm d4_sub_u1})  
   753        (* ax^4+bx^2+c=0 -> x=+-sqrt(ax^2+bx^+c) *)
   754        ],
   755        scr = Rule.Empty_Prog
   756       });
   757 \<close>
   758 rule_set_knowledge
   759   d0_polyeq_simplify = d0_polyeq_simplify and
   760   d1_polyeq_simplify = d1_polyeq_simplify and
   761   d2_polyeq_simplify = d2_polyeq_simplify and
   762   d2_polyeq_bdv_only_simplify = d2_polyeq_bdv_only_simplify and
   763   d2_polyeq_sq_only_simplify = d2_polyeq_sq_only_simplify and
   764 
   765   d2_polyeq_pqFormula_simplify = d2_polyeq_pqFormula_simplify and
   766   d2_polyeq_abcFormula_simplify = d2_polyeq_abcFormula_simplify and
   767   d3_polyeq_simplify = d3_polyeq_simplify and
   768   d4_polyeq_simplify = d4_polyeq_simplify
   769 
   770 setup \<open>KEStore_Elems.add_pbts
   771   [(Problem.prep_input @{theory} "pbl_equ_univ_poly" [] Problem.id_empty
   772       (["polynomial", "univariate", "equation"],
   773         [("#Given" ,["equality e_e", "solveFor v_v"]),
   774           ("#Where" ,["~((e_e::bool) is_ratequation_in (v_v::real))",
   775 	          "~((lhs e_e) is_rootTerm_in (v_v::real))",
   776 	          "~((rhs e_e) is_rootTerm_in (v_v::real))"]),
   777           ("#Find"  ,["solutions v_v'i'"])],
   778         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [])),
   779     (*--- d0 ---*)
   780     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg0" [] Problem.id_empty
   781       (["degree_0", "polynomial", "univariate", "equation"],
   782         [("#Given" ,["equality e_e", "solveFor v_v"]),
   783           ("#Where" ,["matches (?a = 0) e_e",
   784 	          "(lhs e_e) is_poly_in v_v",
   785 	          "((lhs e_e) has_degree_in v_v ) = 0"]),
   786           ("#Find"  ,["solutions v_v'i'"])],
   787         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d0_polyeq_equation"]])),
   788     (*--- d1 ---*)
   789     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg1" [] Problem.id_empty
   790       (["degree_1", "polynomial", "univariate", "equation"],
   791         [("#Given" ,["equality e_e", "solveFor v_v"]),
   792           ("#Where" ,["matches (?a = 0) e_e",
   793 	          "(lhs e_e) is_poly_in v_v",
   794 	          "((lhs e_e) has_degree_in v_v ) = 1"]),
   795           ("#Find"  ,["solutions v_v'i'"])],
   796         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d1_polyeq_equation"]])),
   797     (*--- d2 ---*)
   798     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg2" [] Problem.id_empty
   799       (["degree_2", "polynomial", "univariate", "equation"],
   800         [("#Given" ,["equality e_e", "solveFor v_v"]),
   801           ("#Where" ,["matches (?a = 0) e_e",
   802 	          "(lhs e_e) is_poly_in v_v ",
   803 	          "((lhs e_e) has_degree_in v_v ) = 2"]),
   804           ("#Find"  ,["solutions v_v'i'"])],
   805         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_equation"]])),
   806     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg2_sqonly" [] Problem.id_empty
   807       (["sq_only", "degree_2", "polynomial", "univariate", "equation"],
   808         [("#Given" ,["equality e_e", "solveFor v_v"]),
   809           ("#Where" ,["matches ( ?a +    ?v_ \<up> 2 = 0) e_e | " ^
   810 	          "matches ( ?a + ?b*?v_ \<up> 2 = 0) e_e | " ^
   811             "matches (         ?v_ \<up> 2 = 0) e_e | " ^
   812             "matches (      ?b*?v_ \<up> 2 = 0) e_e" ,
   813             "Not (matches (?a +    ?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
   814             "Not (matches (?a + ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
   815             "Not (matches (?a +    ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
   816             "Not (matches (?a + ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
   817             "Not (matches (        ?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
   818             "Not (matches (     ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
   819             "Not (matches (        ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
   820             "Not (matches (     ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e)"]),
   821           ("#Find"  ,["solutions v_v'i'"])],
   822         PolyEq_prls, SOME "solve (e_e::bool, v_v)",
   823         [["PolyEq", "solve_d2_polyeq_sqonly_equation"]])),
   824     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg2_bdvonly" [] Problem.id_empty
   825       (["bdv_only", "degree_2", "polynomial", "univariate", "equation"],
   826         [("#Given", ["equality e_e", "solveFor v_v"]),
   827           ("#Where", ["matches (?a*?v_ +    ?v_ \<up> 2 = 0) e_e | " ^
   828             "matches (   ?v_ +    ?v_ \<up> 2 = 0) e_e | " ^
   829             "matches (   ?v_ + ?b*?v_ \<up> 2 = 0) e_e | " ^
   830             "matches (?a*?v_ + ?b*?v_ \<up> 2 = 0) e_e | " ^
   831             "matches (            ?v_ \<up> 2 = 0) e_e | " ^
   832             "matches (         ?b*?v_ \<up> 2 = 0) e_e "]),
   833           ("#Find", ["solutions v_v'i'"])],
   834         PolyEq_prls, SOME "solve (e_e::bool, v_v)",
   835         [["PolyEq", "solve_d2_polyeq_bdvonly_equation"]])),
   836     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg2_pq" [] Problem.id_empty
   837       (["pqFormula", "degree_2", "polynomial", "univariate", "equation"],
   838         [("#Given", ["equality e_e", "solveFor v_v"]),
   839           ("#Where", ["matches (?a + 1*?v_ \<up> 2 = 0) e_e | " ^
   840 	          "matches (?a +   ?v_ \<up> 2 = 0) e_e"]),
   841           ("#Find", ["solutions v_v'i'"])],
   842         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_pq_equation"]])),
   843     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg2_abc" [] Problem.id_empty
   844       (["abcFormula", "degree_2", "polynomial", "univariate", "equation"],
   845         [("#Given", ["equality e_e", "solveFor v_v"]),
   846           ("#Where", ["matches (?a +    ?v_ \<up> 2 = 0) e_e | " ^
   847 	          "matches (?a + ?b*?v_ \<up> 2 = 0) e_e"]),
   848           ("#Find", ["solutions v_v'i'"])],
   849         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_abc_equation"]])),
   850     (*--- d3 ---*)
   851     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg3" [] Problem.id_empty
   852       (["degree_3", "polynomial", "univariate", "equation"],
   853         [("#Given", ["equality e_e", "solveFor v_v"]),
   854           ("#Where", ["matches (?a = 0) e_e",
   855 	          "(lhs e_e) is_poly_in v_v ",
   856 	          "((lhs e_e) has_degree_in v_v) = 3"]),
   857           ("#Find", ["solutions v_v'i'"])],
   858         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d3_polyeq_equation"]])),
   859     (*--- d4 ---*)
   860     (Problem.prep_input @{theory} "pbl_equ_univ_poly_deg4" [] Problem.id_empty
   861       (["degree_4", "polynomial", "univariate", "equation"],
   862         [("#Given", ["equality e_e", "solveFor v_v"]),
   863           ("#Where", ["matches (?a = 0) e_e",
   864 	          "(lhs e_e) is_poly_in v_v ",
   865 	          "((lhs e_e) has_degree_in v_v) = 4"]),
   866           ("#Find", ["solutions v_v'i'"])],
   867         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [(*["PolyEq", "solve_d4_polyeq_equation"]*)])),
   868     (*--- normalise ---*)
   869     (Problem.prep_input @{theory} "pbl_equ_univ_poly_norm" [] Problem.id_empty
   870       (["normalise", "polynomial", "univariate", "equation"],
   871         [("#Given", ["equality e_e", "solveFor v_v"]),
   872           ("#Where", ["(Not((matches (?a = 0 ) e_e ))) |" ^
   873 	          "(Not(((lhs e_e) is_poly_in v_v)))"]),
   874           ("#Find", ["solutions v_v'i'"])],
   875         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "normalise_poly"]])),
   876     (*-------------------------expanded-----------------------*)
   877     (Problem.prep_input @{theory} "pbl_equ_univ_expand" [] Problem.id_empty
   878       (["expanded", "univariate", "equation"],
   879         [("#Given", ["equality e_e", "solveFor v_v"]),
   880           ("#Where", ["matches (?a = 0) e_e",
   881 	          "(lhs e_e) is_expanded_in v_v "]),
   882           ("#Find", ["solutions v_v'i'"])],
   883         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [])),
   884     (*--- d2 ---*)
   885     (Problem.prep_input @{theory} "pbl_equ_univ_expand_deg2" [] Problem.id_empty
   886       (["degree_2", "expanded", "univariate", "equation"],
   887         [("#Given", ["equality e_e", "solveFor v_v"]),
   888           ("#Where", ["((lhs e_e) has_degree_in v_v) = 2"]),
   889           ("#Find", ["solutions v_v'i'"])],
   890          PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "complete_square"]]))]\<close>
   891 
   892 text \<open>"-------------------------methods-----------------------"\<close>
   893 setup \<open>KEStore_Elems.add_mets
   894     [MethodC.prep_input @{theory} "met_polyeq" [] MethodC.id_empty
   895       (["PolyEq"], [],
   896         {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
   897           crls=PolyEq_crls, errpats = [], nrls = norm_Rational},
   898         @{thm refl})]
   899 \<close>
   900 
   901 partial_function (tailrec) normalize_poly_eq :: "bool \<Rightarrow> real \<Rightarrow> bool"
   902   where
   903 "normalize_poly_eq e_e v_v = (
   904   let
   905     e_e = (
   906       (Try (Rewrite ''all_left'')) #>
   907       (Try (Repeat (Rewrite ''makex1_x''))) #>
   908       (Try (Repeat (Rewrite_Set ''expand_binoms''))) #>
   909       (Try (Repeat (Rewrite_Set_Inst [(''bdv'', v_v)] ''make_ratpoly_in''))) #>
   910       (Try (Repeat (Rewrite_Set ''polyeq_simplify''))) ) e_e
   911   in
   912     SubProblem (''PolyEq'', [''polynomial'', ''univariate'', ''equation''], [''no_met''])
   913       [BOOL e_e, REAL v_v])"
   914 setup \<open>KEStore_Elems.add_mets
   915     [MethodC.prep_input @{theory} "met_polyeq_norm" [] MethodC.id_empty
   916       (["PolyEq", "normalise_poly"],
   917         [("#Given" ,["equality e_e", "solveFor v_v"]),
   918           ("#Where" ,["(Not((matches (?a = 0 ) e_e ))) | (Not(((lhs e_e) is_poly_in v_v)))"]),
   919           ("#Find"  ,["solutions v_v'i'"])],
   920         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls, calc=[],
   921           crls=PolyEq_crls, errpats = [], nrls = norm_Rational},
   922         @{thm normalize_poly_eq.simps})]
   923 \<close>
   924 
   925 partial_function (tailrec) solve_poly_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   926   where
   927 "solve_poly_equ e_e v_v = (
   928   let
   929     e_e = (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d0_polyeq_simplify'')) e_e   
   930   in
   931     Or_to_List e_e)"
   932 setup \<open>KEStore_Elems.add_mets
   933     [MethodC.prep_input @{theory} "met_polyeq_d0" [] MethodC.id_empty
   934       (["PolyEq", "solve_d0_polyeq_equation"],
   935         [("#Given" ,["equality e_e", "solveFor v_v"]),
   936           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 0"]),
   937           ("#Find"  ,["solutions v_v'i'"])],
   938         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
   939           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
   940           nrls = norm_Rational},
   941         @{thm solve_poly_equ.simps})]
   942 \<close>
   943 
   944 partial_function (tailrec) solve_poly_eq1 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   945   where
   946 "solve_poly_eq1 e_e v_v = (
   947   let
   948     e_e = (
   949       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d1_polyeq_simplify'')) #>
   950       (Try (Rewrite_Set ''polyeq_simplify'')) #> 
   951       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
   952     L_L = Or_to_List e_e
   953   in
   954     Check_elementwise L_L {(v_v::real). Assumptions})"
   955 setup \<open>KEStore_Elems.add_mets
   956     [MethodC.prep_input @{theory} "met_polyeq_d1" [] MethodC.id_empty
   957       (["PolyEq", "solve_d1_polyeq_equation"],
   958         [("#Given" ,["equality e_e", "solveFor v_v"]),
   959           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 1"]),
   960           ("#Find"  ,["solutions v_v'i'"])],
   961         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
   962           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
   963           nrls = norm_Rational},
   964         @{thm solve_poly_eq1.simps})]
   965 \<close>
   966 
   967 partial_function (tailrec) solve_poly_equ2 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   968   where
   969 "solve_poly_equ2 e_e v_v = (
   970   let
   971     e_e = (
   972       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
   973       (Try (Rewrite_Set ''polyeq_simplify'')) #>
   974       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d1_polyeq_simplify'')) #>
   975       (Try (Rewrite_Set ''polyeq_simplify'')) #>
   976       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
   977     L_L =  Or_to_List e_e
   978   in
   979     Check_elementwise L_L {(v_v::real). Assumptions})"
   980 setup \<open>KEStore_Elems.add_mets
   981     [MethodC.prep_input @{theory} "met_polyeq_d22" [] MethodC.id_empty
   982       (["PolyEq", "solve_d2_polyeq_equation"],
   983         [("#Given" ,["equality e_e", "solveFor v_v"]),
   984           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
   985           ("#Find"  ,["solutions v_v'i'"])],
   986         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
   987           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
   988           nrls = norm_Rational},
   989         @{thm solve_poly_equ2.simps})]
   990 \<close>
   991 
   992 partial_function (tailrec) solve_poly_equ0 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   993   where
   994 "solve_poly_equ0 e_e v_v = (
   995   let
   996      e_e = (
   997        (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_bdv_only_simplify'')) #>
   998        (Try (Rewrite_Set ''polyeq_simplify'')) #>
   999        (Try (Rewrite_Set_Inst [(''bdv'',v_v::real)] ''d1_polyeq_simplify'')) #>
  1000        (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1001        (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1002      L_L = Or_to_List e_e
  1003   in
  1004     Check_elementwise L_L {(v_v::real). Assumptions})"
  1005 setup \<open>KEStore_Elems.add_mets
  1006     [MethodC.prep_input @{theory} "met_polyeq_d2_bdvonly" [] MethodC.id_empty
  1007       (["PolyEq", "solve_d2_polyeq_bdvonly_equation"],
  1008         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1009           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
  1010           ("#Find"  ,["solutions v_v'i'"])],
  1011         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1012           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1013           nrls = norm_Rational},
  1014         @{thm solve_poly_equ0.simps})]
  1015 \<close>
  1016 
  1017 partial_function (tailrec) solve_poly_equ_sqrt :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1018   where
  1019 "solve_poly_equ_sqrt e_e v_v = (
  1020   let
  1021     e_e = (
  1022       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_sq_only_simplify'')) #>
  1023       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1024       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1025     L_L = Or_to_List e_e
  1026   in
  1027     Check_elementwise L_L {(v_v::real). Assumptions})"
  1028 setup \<open>KEStore_Elems.add_mets
  1029     [MethodC.prep_input @{theory} "met_polyeq_d2_sqonly" [] MethodC.id_empty
  1030       (["PolyEq", "solve_d2_polyeq_sqonly_equation"],
  1031         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1032           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
  1033           ("#Find"  ,["solutions v_v'i'"])],
  1034         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1035           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1036           nrls = norm_Rational},
  1037         @{thm solve_poly_equ_sqrt.simps})]
  1038 \<close>
  1039 
  1040 partial_function (tailrec) solve_poly_equ_pq :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1041   where
  1042 "solve_poly_equ_pq e_e v_v = (
  1043   let
  1044     e_e = (
  1045       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_pqFormula_simplify'')) #>
  1046       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1047       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1048     L_L = Or_to_List e_e
  1049   in
  1050     Check_elementwise L_L {(v_v::real). Assumptions})"
  1051 setup \<open>KEStore_Elems.add_mets
  1052     [MethodC.prep_input @{theory} "met_polyeq_d2_pq" [] MethodC.id_empty
  1053       (["PolyEq", "solve_d2_polyeq_pq_equation"],
  1054         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1055           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
  1056           ("#Find"  ,["solutions v_v'i'"])],
  1057         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1058           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1059           nrls = norm_Rational},
  1060         @{thm solve_poly_equ_pq.simps})]
  1061 \<close>
  1062 
  1063 partial_function (tailrec) solve_poly_equ_abc :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1064   where
  1065 "solve_poly_equ_abc e_e v_v = (
  1066   let
  1067     e_e = (
  1068       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_abcFormula_simplify'')) #>
  1069       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1070       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1071     L_L = Or_to_List e_e
  1072   in Check_elementwise L_L {(v_v::real). Assumptions})"
  1073 setup \<open>KEStore_Elems.add_mets
  1074     [MethodC.prep_input @{theory} "met_polyeq_d2_abc" [] MethodC.id_empty
  1075       (["PolyEq", "solve_d2_polyeq_abc_equation"],
  1076         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1077           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
  1078           ("#Find"  ,["solutions v_v'i'"])],
  1079         {rew_ord'="termlessI", rls'=PolyEq_erls,srls=Rule_Set.empty, prls=PolyEq_prls,
  1080           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1081           nrls = norm_Rational},
  1082         @{thm solve_poly_equ_abc.simps})]
  1083 \<close>
  1084 
  1085 partial_function (tailrec) solve_poly_equ3 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1086   where
  1087 "solve_poly_equ3 e_e v_v = (
  1088   let
  1089     e_e = (
  1090       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d3_polyeq_simplify'')) #>
  1091       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1092       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
  1093       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1094       (Try (Rewrite_Set_Inst [(''bdv'',v_v)] ''d1_polyeq_simplify'')) #>
  1095       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1096       (Try (Rewrite_Set ''norm_Rational_parenthesized''))) e_e;
  1097     L_L = Or_to_List e_e
  1098   in
  1099     Check_elementwise L_L {(v_v::real). Assumptions})"
  1100 setup \<open>KEStore_Elems.add_mets
  1101     [MethodC.prep_input @{theory} "met_polyeq_d3" [] MethodC.id_empty
  1102       (["PolyEq", "solve_d3_polyeq_equation"],
  1103         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1104           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 3"]),
  1105           ("#Find"  ,["solutions v_v'i'"])],
  1106         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1107           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1108           nrls = norm_Rational},
  1109         @{thm solve_poly_equ3.simps})]
  1110 \<close>
  1111     (*.solves all expanded (ie. normalised) terms of degree 2.*) 
  1112     (*Oct.02 restriction: 'eval_true 0 =< discriminant' ony for integer values
  1113       by 'PolyEq_erls'; restricted until Float.thy is implemented*)
  1114 partial_function (tailrec) solve_by_completing_square :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1115   where
  1116 "solve_by_completing_square e_e v_v = (
  1117   let e_e = (
  1118     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''cancel_leading_coeff'')) #>
  1119     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''complete_square'')) #>
  1120     (Try (Rewrite ''square_explicit1'')) #>
  1121     (Try (Rewrite ''square_explicit2'')) #>
  1122     (Rewrite ''root_plus_minus'') #>
  1123     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit1''))) #>
  1124     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit2''))) #>
  1125     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit3''))) #>
  1126     (Try (Rewrite_Set ''calculate_RootRat'')) #>
  1127     (Try (Repeat (Calculate ''SQRT'')))) e_e
  1128   in
  1129     Or_to_List e_e)"
  1130 setup \<open>KEStore_Elems.add_mets
  1131     [MethodC.prep_input @{theory} "met_polyeq_complsq" [] MethodC.id_empty
  1132       (["PolyEq", "complete_square"],
  1133         [("#Given" ,["equality e_e", "solveFor v_v"]),
  1134           ("#Where" ,["matches (?a = 0) e_e", "((lhs e_e) has_degree_in v_v) = 2"]),
  1135           ("#Find"  ,["solutions v_v'i'"])],
  1136         {rew_ord'="termlessI",rls'=PolyEq_erls,srls=Rule_Set.empty,prls=PolyEq_prls,
  1137           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1138           nrls = norm_Rational},
  1139         @{thm solve_by_completing_square.simps})]
  1140 \<close>
  1141 
  1142 ML\<open>
  1143 
  1144 (* termorder hacked by MG *)
  1145 local (*. for make_polynomial_in .*)
  1146 
  1147 open Term;  (* for type order = EQUAL | LESS | GREATER *)
  1148 
  1149 fun pr_ord EQUAL = "EQUAL"
  1150   | pr_ord LESS  = "LESS"
  1151   | pr_ord GREATER = "GREATER";
  1152 
  1153 fun dest_hd' _ (Const (a, T)) = (((a, 0), T), 0)
  1154   | dest_hd' x (t as Free (a, T)) =
  1155     if x = t then ((("|||||||||||||", 0), T), 0)                        (*WN*)
  1156     else (((a, 0), T), 1)
  1157   | dest_hd' _ (Var v) = (v, 2)
  1158   | dest_hd' _ (Bound i) = ((("", i), dummyT), 3)
  1159   | dest_hd' _ (Abs (_, T, _)) = ((("", 0), T), 4)
  1160   | dest_hd' _ _ = raise ERROR "dest_hd': uncovered case in fun.def.";
  1161 
  1162 fun size_of_term' x (Const ("Transcendental.powr",_) $ Free (var,_) $ Free (pot,_)) =
  1163     (case x of                                                          (*WN*)
  1164 	    (Free (xstr,_)) => 
  1165 		(if xstr = var then 1000*(the (TermC.int_opt_of_string pot)) else 3)
  1166 	  | _ => raise ERROR ("size_of_term' called with subst = "^
  1167 			      (UnparseC.term x)))
  1168   | size_of_term' x (Free (subst,_)) =
  1169     (case x of
  1170 	    (Free (xstr,_)) => (if xstr = subst then 1000 else 1)
  1171 	  | _ => raise ERROR ("size_of_term' called with subst = "^
  1172 			  (UnparseC.term x)))
  1173   | size_of_term' x (Abs (_,_,body)) = 1 + size_of_term' x body
  1174   | size_of_term' x (f$t) = size_of_term' x f  +  size_of_term' x t
  1175   | size_of_term' _ _ = 1;
  1176 
  1177 fun term_ord' x pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
  1178     (case term_ord' x pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
  1179   | term_ord' x pr thy (t, u) =
  1180     (if pr
  1181      then 
  1182        let
  1183          val (f, ts) = strip_comb t and (g, us) = strip_comb u;
  1184          val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
  1185            commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
  1186          val _ = tracing ("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
  1187            commas(map (UnparseC.term_in_thy thy) us) ^ "]\"");
  1188          val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' x t) ^ ", " ^
  1189            string_of_int (size_of_term' x u) ^ ")");
  1190          val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o (hd_ord x)) (f,g));
  1191          val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o (terms_ord x) str false) (ts, us));
  1192          val _ = tracing ("-------");
  1193        in () end
  1194      else ();
  1195 	  case int_ord (size_of_term' x t, size_of_term' x u) of
  1196 	    EQUAL =>
  1197 	      let val (f, ts) = strip_comb t and (g, us) = strip_comb u 
  1198         in
  1199 	        (case hd_ord x (f, g) of 
  1200 	           EQUAL => (terms_ord x str pr) (ts, us) 
  1201 	         | ord => ord)
  1202 	      end
  1203 	 | ord => ord)
  1204 and hd_ord x (f, g) =                                        (* ~ term.ML *)
  1205   prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) 
  1206             int_ord (dest_hd' x f, dest_hd' x g)
  1207 and terms_ord x _ pr (ts, us) = 
  1208     list_ord (term_ord' x pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
  1209 
  1210 in
  1211 
  1212 fun ord_make_polynomial_in (pr:bool) thy subst tu =
  1213   ((**)tracing ("*** subs variable is: " ^ (Env.subst2str subst)); (**)
  1214 	case subst of
  1215 	  (_, x) :: _ => (term_ord' x pr thy tu = LESS)
  1216 	| _ => raise ERROR ("ord_make_polynomial_in called with subst = " ^ Env.subst2str subst))
  1217 
  1218 end;(*local*)
  1219 
  1220 \<close>
  1221 ML\<open>
  1222 val order_add_mult_in = prep_rls'(
  1223   Rule_Def.Repeat{id = "order_add_mult_in", preconds = [], 
  1224       rew_ord = ("ord_make_polynomial_in",
  1225 		 ord_make_polynomial_in false @{theory "Poly"}),
  1226       erls = Rule_Set.empty,srls = Rule_Set.Empty,
  1227       calc = [], errpatts = [],
  1228       rules = [Rule.Thm ("mult.commute",ThmC.numerals_to_Free @{thm mult.commute}),
  1229 	       (* z * w = w * z *)
  1230 	       Rule.Thm ("real_mult_left_commute",ThmC.numerals_to_Free @{thm real_mult_left_commute}),
  1231 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
  1232 	       Rule.Thm ("mult.assoc",ThmC.numerals_to_Free @{thm mult.assoc}),		
  1233 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
  1234 	       Rule.Thm ("add.commute",ThmC.numerals_to_Free @{thm add.commute}),	
  1235 	       (*z + w = w + z*)
  1236 	       Rule.Thm ("add.left_commute",ThmC.numerals_to_Free @{thm add.left_commute}),
  1237 	       (*x + (y + z) = y + (x + z)*)
  1238 	       Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc})	               
  1239 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
  1240 	       ], scr = Rule.Empty_Prog});
  1241 
  1242 \<close>
  1243 ML\<open>
  1244 val collect_bdv = prep_rls'(
  1245   Rule_Def.Repeat{id = "collect_bdv", preconds = [], 
  1246       rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1247       erls = Rule_Set.empty,srls = Rule_Set.Empty,
  1248       calc = [], errpatts = [],
  1249       rules = [Rule.Thm ("bdv_collect_1",ThmC.numerals_to_Free @{thm bdv_collect_1}),
  1250 	       Rule.Thm ("bdv_collect_2",ThmC.numerals_to_Free @{thm bdv_collect_2}),
  1251 	       Rule.Thm ("bdv_collect_3",ThmC.numerals_to_Free @{thm bdv_collect_3}),
  1252 
  1253 	       Rule.Thm ("bdv_collect_assoc1_1",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_1}),
  1254 	       Rule.Thm ("bdv_collect_assoc1_2",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_2}),
  1255 	       Rule.Thm ("bdv_collect_assoc1_3",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_3}),
  1256 
  1257 	       Rule.Thm ("bdv_collect_assoc2_1",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_1}),
  1258 	       Rule.Thm ("bdv_collect_assoc2_2",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_2}),
  1259 	       Rule.Thm ("bdv_collect_assoc2_3",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_3}),
  1260 
  1261 
  1262 	       Rule.Thm ("bdv_n_collect_1",ThmC.numerals_to_Free @{thm bdv_n_collect_1}),
  1263 	       Rule.Thm ("bdv_n_collect_2",ThmC.numerals_to_Free @{thm bdv_n_collect_2}),
  1264 	       Rule.Thm ("bdv_n_collect_3",ThmC.numerals_to_Free @{thm bdv_n_collect_3}),
  1265 
  1266 	       Rule.Thm ("bdv_n_collect_assoc1_1",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_1}),
  1267 	       Rule.Thm ("bdv_n_collect_assoc1_2",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_2}),
  1268 	       Rule.Thm ("bdv_n_collect_assoc1_3",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_3}),
  1269 
  1270 	       Rule.Thm ("bdv_n_collect_assoc2_1",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_1}),
  1271 	       Rule.Thm ("bdv_n_collect_assoc2_2",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_2}),
  1272 	       Rule.Thm ("bdv_n_collect_assoc2_3",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_3})
  1273 	       ], scr = Rule.Empty_Prog});
  1274 
  1275 \<close>
  1276 ML\<open>
  1277 (*.transforms an arbitrary term without roots to a polynomial [4] 
  1278    according to knowledge/Poly.sml.*) 
  1279 val make_polynomial_in = prep_rls'(
  1280   Rule_Set.Sequence {id = "make_polynomial_in", preconds = []:term list, 
  1281        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1282       erls = Atools_erls, srls = Rule_Set.Empty,
  1283       calc = [], errpatts = [],
  1284       rules = [Rule.Rls_ expand_poly,
  1285 	       Rule.Rls_ order_add_mult_in,
  1286 	       Rule.Rls_ simplify_power,
  1287 	       Rule.Rls_ collect_numerals,
  1288 	       Rule.Rls_ reduce_012,
  1289 	       Rule.Thm ("realpow_oneI",ThmC.numerals_to_Free @{thm realpow_oneI}),
  1290 	       Rule.Rls_ discard_parentheses,
  1291 	       Rule.Rls_ collect_bdv
  1292 	       ],
  1293       scr = Rule.Empty_Prog
  1294       });     
  1295 
  1296 \<close>
  1297 ML\<open>
  1298 val separate_bdvs = 
  1299     Rule_Set.append_rules "separate_bdvs"
  1300 	       collect_bdv
  1301 	       [Rule.Thm ("separate_bdv", ThmC.numerals_to_Free @{thm separate_bdv}),
  1302 		(*"?a * ?bdv / ?b = ?a / ?b * ?bdv"*)
  1303 		Rule.Thm ("separate_bdv_n", ThmC.numerals_to_Free @{thm separate_bdv_n}),
  1304 		Rule.Thm ("separate_1_bdv", ThmC.numerals_to_Free @{thm separate_1_bdv}),
  1305 		(*"?bdv / ?b = (1 / ?b) * ?bdv"*)
  1306 		Rule.Thm ("separate_1_bdv_n", ThmC.numerals_to_Free @{thm separate_1_bdv_n}),
  1307 		(*"?bdv \<up> ?n / ?b = 1 / ?b * ?bdv \<up> ?n"*)
  1308 		Rule.Thm ("add_divide_distrib", 
  1309 		     ThmC.numerals_to_Free @{thm add_divide_distrib})
  1310 		(*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"
  1311 		      WN051031 DOES NOT BELONG TO HERE*)
  1312 		];
  1313 \<close>
  1314 ML\<open>
  1315 val make_ratpoly_in = prep_rls'(
  1316   Rule_Set.Sequence {id = "make_ratpoly_in", preconds = []:term list, 
  1317        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1318       erls = Atools_erls, srls = Rule_Set.Empty,
  1319       calc = [], errpatts = [],
  1320       rules = [Rule.Rls_ norm_Rational,
  1321 	       Rule.Rls_ order_add_mult_in,
  1322 	       Rule.Rls_ discard_parentheses,
  1323 	       Rule.Rls_ separate_bdvs,
  1324 	       (* Rule.Rls_ rearrange_assoc, WN060916 why does cancel_p not work?*)
  1325 	       Rule.Rls_ cancel_p
  1326 	       (*\<^rule_eval>\<open>divide\<close> (eval_cancel "#divide_e") too weak!*)
  1327 	       ],
  1328       scr = Rule.Empty_Prog});      
  1329 \<close>
  1330 rule_set_knowledge
  1331   order_add_mult_in = order_add_mult_in and
  1332   collect_bdv = collect_bdv and
  1333   make_polynomial_in = make_polynomial_in and
  1334   make_ratpoly_in = make_ratpoly_in and
  1335   separate_bdvs = separate_bdvs
  1336 ML \<open>
  1337 \<close> ML \<open>
  1338 \<close> ML \<open>
  1339 \<close>
  1340 end
  1341 
  1342 
  1343 
  1344 
  1345 
  1346