src/Tools/isac/Knowledge/PolyEq.thy
author wneuper <walther.neuper@jku.at>
Mon, 19 Jul 2021 18:29:46 +0200
changeset 60337 cbad4e18e91b
parent 60335 7701598a2182
child 60342 e96abd81a321
permissions -rw-r--r--
cleanup after "eliminate ThmC.numerals_to_Free"
     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 val thy = @{theory};
   323 
   324 (*-------------------------rulse-------------------------*)
   325 val PolyEq_prls = (*3.10.02:just the following order due to subterm evaluation*)
   326   Rule_Set.append_rules "PolyEq_prls" Rule_Set.empty 
   327 	     [Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
   328 	      Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches "#matches_"),
   329 	      Rule.Eval ("Prog_Expr.lhs", Prog_Expr.eval_lhs ""),
   330 	      Rule.Eval ("Prog_Expr.rhs", Prog_Expr.eval_rhs ""),
   331 	      Rule.Eval ("Poly.is_expanded_in", eval_is_expanded_in ""),
   332 	      Rule.Eval ("Poly.is_poly_in", eval_is_poly_in ""),
   333 	      Rule.Eval ("Poly.has_degree_in", eval_has_degree_in ""),    
   334               Rule.Eval ("Poly.is_polyrat_in", eval_is_polyrat_in ""),
   335 	      (*Rule.Eval ("Prog_Expr.occurs_in", Prog_Expr.eval_occurs_in ""),   *) 
   336 	      (*Rule.Eval ("Prog_Expr.is_const", Prog_Expr.eval_const "#is_const_"),*)
   337 	      Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
   338               Rule.Eval ("RootEq.is_rootTerm_in", eval_is_rootTerm_in ""),
   339 	      Rule.Eval ("RatEq.is_ratequation_in", eval_is_ratequation_in ""),
   340 	      Rule.Thm ("not_true", @{thm not_true}),
   341 	      Rule.Thm ("not_false", @{thm not_false}),
   342 	      Rule.Thm ("and_true", @{thm and_true}),
   343 	      Rule.Thm ("and_false", @{thm and_false}),
   344 	      Rule.Thm ("or_true", @{thm or_true}),
   345 	      Rule.Thm ("or_false", @{thm or_false})
   346 	       ];
   347 
   348 val PolyEq_erls = 
   349     Rule_Set.merge "PolyEq_erls" LinEq_erls
   350     (Rule_Set.append_rules "ops_preds" calculate_Rational
   351 		[\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
   352 		 \<^rule_thm>\<open>plus_leq\<close>,
   353 		 \<^rule_thm>\<open>minus_leq\<close>,
   354 		 \<^rule_thm>\<open>rat_leq1\<close>,
   355 		 \<^rule_thm>\<open>rat_leq2\<close>,
   356 		 \<^rule_thm>\<open>rat_leq3\<close>
   357 		 ]);
   358 
   359 val PolyEq_crls = 
   360     Rule_Set.merge "PolyEq_crls" LinEq_crls
   361     (Rule_Set.append_rules "ops_preds" calculate_Rational
   362 		[\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
   363 		 \<^rule_thm>\<open>plus_leq\<close>,
   364 		 \<^rule_thm>\<open>minus_leq\<close>,
   365 		 \<^rule_thm>\<open>rat_leq1\<close>,
   366 		 \<^rule_thm>\<open>rat_leq2\<close>,
   367 		 \<^rule_thm>\<open>rat_leq3\<close>
   368 		 ]);
   369 
   370 val cancel_leading_coeff = prep_rls'(
   371   Rule_Def.Repeat {id = "cancel_leading_coeff", preconds = [], 
   372        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   373       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
   374       rules = 
   375       [\<^rule_thm>\<open>cancel_leading_coeff1\<close>,
   376        \<^rule_thm>\<open>cancel_leading_coeff2\<close>,
   377        \<^rule_thm>\<open>cancel_leading_coeff3\<close>,
   378        \<^rule_thm>\<open>cancel_leading_coeff4\<close>,
   379        \<^rule_thm>\<open>cancel_leading_coeff5\<close>,
   380        \<^rule_thm>\<open>cancel_leading_coeff6\<close>,
   381        \<^rule_thm>\<open>cancel_leading_coeff7\<close>,
   382        \<^rule_thm>\<open>cancel_leading_coeff8\<close>,
   383        \<^rule_thm>\<open>cancel_leading_coeff9\<close>,
   384        \<^rule_thm>\<open>cancel_leading_coeff10\<close>,
   385        \<^rule_thm>\<open>cancel_leading_coeff11\<close>,
   386        \<^rule_thm>\<open>cancel_leading_coeff12\<close>,
   387        \<^rule_thm>\<open>cancel_leading_coeff13\<close>
   388        ],scr = Rule.Empty_Prog});
   389 
   390 val prep_rls' = Auto_Prog.prep_rls @{theory};
   391 \<close>
   392 ML\<open>
   393 val complete_square = prep_rls'(
   394   Rule_Def.Repeat {id = "complete_square", preconds = [], 
   395        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   396       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [],  errpatts = [],
   397       rules = [\<^rule_thm>\<open>complete_square1\<close>,
   398 	       \<^rule_thm>\<open>complete_square2\<close>,
   399 	       \<^rule_thm>\<open>complete_square3\<close>,
   400 	       \<^rule_thm>\<open>complete_square4\<close>,
   401 	       \<^rule_thm>\<open>complete_square5\<close>
   402 	       ],
   403       scr = Rule.Empty_Prog
   404       });
   405 
   406 val polyeq_simplify = prep_rls'(
   407   Rule_Def.Repeat {id = "polyeq_simplify", preconds = [], 
   408        rew_ord = ("termlessI",termlessI), 
   409        erls = PolyEq_erls, 
   410        srls = Rule_Set.Empty, 
   411        calc = [], errpatts = [],
   412        rules = [\<^rule_thm>\<open>real_assoc_1\<close>,
   413 		\<^rule_thm>\<open>real_assoc_2\<close>,
   414 		\<^rule_thm>\<open>real_diff_minus\<close>,
   415 		\<^rule_thm>\<open>real_unari_minus\<close>,
   416 		\<^rule_thm>\<open>realpow_multI\<close>,
   417 		\<^rule_eval>\<open>plus\<close> (**)(eval_binop "#add_"),
   418 		\<^rule_eval>\<open>minus\<close> (**)(eval_binop "#sub_"),
   419 		\<^rule_eval>\<open>times\<close> (**)(eval_binop "#mult_"),
   420 		\<^rule_eval>\<open>divide\<close> (Prog_Expr.eval_cancel "#divide_e"),
   421 		\<^rule_eval>\<open>sqrt\<close> (eval_sqrt "#sqrt_"),
   422 		\<^rule_eval>\<open>powr\<close> (**)(eval_binop "#power_"),
   423                 Rule.Rls_ reduce_012
   424                 ],
   425        scr = Rule.Empty_Prog
   426        });
   427 \<close>
   428 rule_set_knowledge
   429   cancel_leading_coeff = cancel_leading_coeff and
   430   complete_square = complete_square and
   431   PolyEq_erls = PolyEq_erls and
   432   polyeq_simplify = polyeq_simplify
   433 ML\<open>
   434 
   435 (* ------------- polySolve ------------------ *)
   436 (* -- d0 -- *)
   437 (*isolate the bound variable in an d0 equation; 'bdv' is a meta-constant*)
   438 val d0_polyeq_simplify = prep_rls'(
   439   Rule_Def.Repeat {id = "d0_polyeq_simplify", preconds = [],
   440        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
   441        erls = PolyEq_erls,
   442        srls = Rule_Set.Empty, 
   443        calc = [], errpatts = [],
   444        rules = [\<^rule_thm>\<open>d0_true\<close>, \<^rule_thm>\<open>d0_false\<close>],
   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>\<open>d1_isolate_add1\<close>, 
   458 		(* a+bx=0 -> bx=-a *)
   459 		\<^rule_thm>\<open>d1_isolate_add2\<close>, 
   460 		(* a+ x=0 ->  x=-a *)
   461 		\<^rule_thm>\<open>d1_isolate_div\<close>    
   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>\<open>d2_prescind1\<close>, (*   ax+bx^2=0 -> x(a+bx)=0 *)
   477        \<^rule_thm>\<open>d2_prescind2\<close>, (*   ax+ x^2=0 -> x(a+ x)=0 *)
   478        \<^rule_thm>\<open>d2_prescind3\<close>, (*    x+bx^2=0 -> x(1+bx)=0 *)
   479        \<^rule_thm>\<open>d2_prescind4\<close>, (*    x+ x^2=0 -> x(1+ x)=0 *)
   480        \<^rule_thm>\<open>d2_sqrt_equation1\<close>,    (* x^2=c   -> x=+-sqrt(c) *)
   481        \<^rule_thm>\<open>d2_sqrt_equation1_neg\<close>, (* [0<c] x^2=c  -> []*)
   482        \<^rule_thm>\<open>d2_sqrt_equation2\<close>,    (*  x^2=0 ->    x=0       *)
   483        \<^rule_thm>\<open>d2_reduce_equation1\<close>,(* x(a+bx)=0 -> x=0 |a+bx=0*)
   484        \<^rule_thm>\<open>d2_reduce_equation2\<close>,(* x(a+ x)=0 -> x=0 |a+ x=0*)
   485        \<^rule_thm>\<open>d2_isolate_div\<close>           (* 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>\<open>d2_isolate_add1\<close>,
   502                 (* a+   bx^2=0 -> bx^2=(-1)a*)
   503 		\<^rule_thm>\<open>d2_isolate_add2\<close>,
   504                 (* a+    x^2=0 ->  x^2=(-1)a*)
   505 		\<^rule_thm>\<open>d2_sqrt_equation2\<close>,
   506                 (*  x^2=0 ->    x=0    *)
   507 		\<^rule_thm>\<open>d2_sqrt_equation1\<close>,
   508                 (* x^2=c   -> x=+-sqrt(c)*)
   509 		\<^rule_thm>\<open>d2_sqrt_equation1_neg\<close>,
   510                 (* [c<0] x^2=c  -> x=[] *)
   511 		\<^rule_thm>\<open>d2_isolate_div\<close>
   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>\<open>d2_pqformula1\<close>,
   525                 (* q+px+ x^2=0 *)
   526 		\<^rule_thm>\<open>d2_pqformula1_neg\<close>,
   527                 (* q+px+ x^2=0 *)
   528 		\<^rule_thm>\<open>d2_pqformula2\<close>, 
   529                 (* q+px+1x^2=0 *)
   530 		\<^rule_thm>\<open>d2_pqformula2_neg\<close>,
   531                 (* q+px+1x^2=0 *)
   532 		\<^rule_thm>\<open>d2_pqformula3\<close>,
   533                 (* q+ x+ x^2=0 *)
   534 		\<^rule_thm>\<open>d2_pqformula3_neg\<close>, 
   535                 (* q+ x+ x^2=0 *)
   536 		\<^rule_thm>\<open>d2_pqformula4\<close>,
   537                 (* q+ x+1x^2=0 *)
   538 		\<^rule_thm>\<open>d2_pqformula4_neg\<close>,
   539                 (* q+ x+1x^2=0 *)
   540 		\<^rule_thm>\<open>d2_pqformula5\<close>,
   541                 (*   qx+ x^2=0 *)
   542 		\<^rule_thm>\<open>d2_pqformula6\<close>,
   543                 (*   qx+1x^2=0 *)
   544 		\<^rule_thm>\<open>d2_pqformula7\<close>,
   545                 (*    x+ x^2=0 *)
   546 		\<^rule_thm>\<open>d2_pqformula8\<close>,
   547                 (*    x+1x^2=0 *)
   548 		\<^rule_thm>\<open>d2_pqformula9\<close>,
   549                 (* q   +1x^2=0 *)
   550 		\<^rule_thm>\<open>d2_pqformula9_neg\<close>,
   551                 (* q   +1x^2=0 *)
   552 		\<^rule_thm>\<open>d2_pqformula10\<close>,
   553                 (* q   + x^2=0 *)
   554 		\<^rule_thm>\<open>d2_pqformula10_neg\<close>,
   555                 (* q   + x^2=0 *)
   556 		\<^rule_thm>\<open>d2_sqrt_equation2\<close>,
   557                 (*       x^2=0 *)
   558 		\<^rule_thm>\<open>d2_sqrt_equation3\<close>
   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>\<open>d2_abcformula1\<close>,
   571                 (*c+bx+cx^2=0 *)
   572 		\<^rule_thm>\<open>d2_abcformula1_neg\<close>,
   573                 (*c+bx+cx^2=0 *)
   574 		\<^rule_thm>\<open>d2_abcformula2\<close>,
   575                 (*c+ x+cx^2=0 *)
   576 		\<^rule_thm>\<open>d2_abcformula2_neg\<close>,
   577                 (*c+ x+cx^2=0 *)
   578 		\<^rule_thm>\<open>d2_abcformula3\<close>, 
   579                 (*c+bx+ x^2=0 *)
   580 		\<^rule_thm>\<open>d2_abcformula3_neg\<close>,
   581                 (*c+bx+ x^2=0 *)
   582 		\<^rule_thm>\<open>d2_abcformula4\<close>,
   583                 (*c+ x+ x^2=0 *)
   584 		\<^rule_thm>\<open>d2_abcformula4_neg\<close>,
   585                 (*c+ x+ x^2=0 *)
   586 		\<^rule_thm>\<open>d2_abcformula5\<close>,
   587                 (*c+   cx^2=0 *)
   588 		\<^rule_thm>\<open>d2_abcformula5_neg\<close>,
   589                 (*c+   cx^2=0 *)
   590 		\<^rule_thm>\<open>d2_abcformula6\<close>,
   591                 (*c+    x^2=0 *)
   592 		\<^rule_thm>\<open>d2_abcformula6_neg\<close>,
   593                 (*c+    x^2=0 *)
   594 		\<^rule_thm>\<open>d2_abcformula7\<close>,
   595                 (*  bx+ax^2=0 *)
   596 		\<^rule_thm>\<open>d2_abcformula8\<close>,
   597                 (*  bx+ x^2=0 *)
   598 		\<^rule_thm>\<open>d2_abcformula9\<close>,
   599                 (*   x+ax^2=0 *)
   600 		\<^rule_thm>\<open>d2_abcformula10\<close>,
   601                 (*   x+ x^2=0 *)
   602 		\<^rule_thm>\<open>d2_sqrt_equation2\<close>,
   603                 (*      x^2=0 *)  
   604 		\<^rule_thm>\<open>d2_sqrt_equation3\<close>
   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>\<open>d2_pqformula1\<close>,
   619                 (* p+qx+ x^2=0 *)
   620 		\<^rule_thm>\<open>d2_pqformula1_neg\<close>,
   621                 (* p+qx+ x^2=0 *)
   622 		\<^rule_thm>\<open>d2_pqformula2\<close>,
   623                 (* p+qx+1x^2=0 *)
   624 		\<^rule_thm>\<open>d2_pqformula2_neg\<close>,
   625                 (* p+qx+1x^2=0 *)
   626 		\<^rule_thm>\<open>d2_pqformula3\<close>,
   627                 (* p+ x+ x^2=0 *)
   628 		\<^rule_thm>\<open>d2_pqformula3_neg\<close>,
   629                 (* p+ x+ x^2=0 *)
   630 		\<^rule_thm>\<open>d2_pqformula4\<close>, 
   631                 (* p+ x+1x^2=0 *)
   632 		\<^rule_thm>\<open>d2_pqformula4_neg\<close>,
   633                 (* p+ x+1x^2=0 *)
   634 		\<^rule_thm>\<open>d2_abcformula1\<close>,
   635                 (* c+bx+cx^2=0 *)
   636 		\<^rule_thm>\<open>d2_abcformula1_neg\<close>,
   637                 (* c+bx+cx^2=0 *)
   638 		\<^rule_thm>\<open>d2_abcformula2\<close>,
   639                 (* c+ x+cx^2=0 *)
   640 		\<^rule_thm>\<open>d2_abcformula2_neg\<close>,
   641                 (* c+ x+cx^2=0 *)
   642 		\<^rule_thm>\<open>d2_prescind1\<close>,
   643                 (*   ax+bx^2=0 -> x(a+bx)=0 *)
   644 		\<^rule_thm>\<open>d2_prescind2\<close>,
   645                 (*   ax+ x^2=0 -> x(a+ x)=0 *)
   646 		\<^rule_thm>\<open>d2_prescind3\<close>,
   647                 (*    x+bx^2=0 -> x(1+bx)=0 *)
   648 		\<^rule_thm>\<open>d2_prescind4\<close>,
   649                 (*    x+ x^2=0 -> x(1+ x)=0 *)
   650 		\<^rule_thm>\<open>d2_isolate_add1\<close>,
   651                 (* a+   bx^2=0 -> bx^2=(-1)a*)
   652 		\<^rule_thm>\<open>d2_isolate_add2\<close>,
   653                 (* a+    x^2=0 ->  x^2=(-1)a*)
   654 		\<^rule_thm>\<open>d2_sqrt_equation1\<close>,
   655                 (* x^2=c   -> x=+-sqrt(c)*)
   656 		\<^rule_thm>\<open>d2_sqrt_equation1_neg\<close>,
   657                 (* [c<0] x^2=c   -> x=[]*)
   658 		\<^rule_thm>\<open>d2_sqrt_equation2\<close>,
   659                 (*  x^2=0 ->    x=0    *)
   660 		\<^rule_thm>\<open>d2_reduce_equation1\<close>,
   661                 (* x(a+bx)=0 -> x=0 | a+bx=0*)
   662 		\<^rule_thm>\<open>d2_reduce_equation2\<close>,
   663                 (* x(a+ x)=0 -> x=0 | a+ x=0*)
   664 		\<^rule_thm>\<open>d2_isolate_div\<close>
   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>\<open>d3_reduce_equation1\<close>,
   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>\<open>d3_reduce_equation2\<close>,
   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>\<open>d3_reduce_equation3\<close>,
   686 	(*a*bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
   687         (bdv=0 | (a +   bdv + c*bdv \<up> 2=0)*)
   688 	\<^rule_thm>\<open>d3_reduce_equation4\<close>,
   689 	(*  bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
   690         (bdv=0 | (1 +   bdv + c*bdv \<up> 2=0)*)
   691 	\<^rule_thm>\<open>d3_reduce_equation5\<close>,
   692 	(*a*bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   693         (bdv=0 | (a + b*bdv +   bdv \<up> 2=0)*)
   694 	\<^rule_thm>\<open>d3_reduce_equation6\<close>,
   695 	(*  bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   696         (bdv=0 | (1 + b*bdv +   bdv \<up> 2=0)*)
   697 	\<^rule_thm>\<open>d3_reduce_equation7\<close>,
   698 	     (*a*bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
   699              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
   700 	\<^rule_thm>\<open>d3_reduce_equation8\<close>,
   701 	     (*  bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
   702              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
   703 	\<^rule_thm>\<open>d3_reduce_equation9\<close>,
   704 	     (*a*bdv             + c*bdv \<up> 3=0) = 
   705              (bdv=0 | (a         + c*bdv \<up> 2=0)*)
   706 	\<^rule_thm>\<open>d3_reduce_equation10\<close>,
   707 	     (*  bdv             + c*bdv \<up> 3=0) = 
   708              (bdv=0 | (1         + c*bdv \<up> 2=0)*)
   709 	\<^rule_thm>\<open>d3_reduce_equation11\<close>,
   710 	     (*a*bdv             +   bdv \<up> 3=0) = 
   711              (bdv=0 | (a         +   bdv \<up> 2=0)*)
   712 	\<^rule_thm>\<open>d3_reduce_equation12\<close>,
   713 	     (*  bdv             +   bdv \<up> 3=0) = 
   714              (bdv=0 | (1         +   bdv \<up> 2=0)*)
   715 	\<^rule_thm>\<open>d3_reduce_equation13\<close>,
   716 	     (*        b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
   717              (bdv=0 | (    b*bdv + c*bdv \<up> 2=0)*)
   718 	\<^rule_thm>\<open>d3_reduce_equation14\<close>,
   719 	     (*          bdv \<up> 2 + c*bdv \<up> 3=0) = 
   720              (bdv=0 | (      bdv + c*bdv \<up> 2=0)*)
   721 	\<^rule_thm>\<open>d3_reduce_equation15\<close>,
   722 	     (*        b*bdv \<up> 2 +   bdv \<up> 3=0) = 
   723              (bdv=0 | (    b*bdv +   bdv \<up> 2=0)*)
   724 	\<^rule_thm>\<open>d3_reduce_equation16\<close>,
   725 	     (*          bdv \<up> 2 +   bdv \<up> 3=0) = 
   726              (bdv=0 | (      bdv +   bdv \<up> 2=0)*)
   727 	\<^rule_thm>\<open>d3_isolate_add1\<close>,
   728 	     (*[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 3=0) = 
   729               (bdv=0 | (b*bdv \<up> 3=a)*)
   730 	\<^rule_thm>\<open>d3_isolate_add2\<close>,
   731              (*[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 3=0) = 
   732               (bdv=0 | (  bdv \<up> 3=a)*)
   733 	\<^rule_thm>\<open>d3_isolate_div\<close>,
   734         (*[|Not(b=0)|] ==> (b*bdv \<up> 3=c) = (bdv \<up> 3=c/b*)
   735         \<^rule_thm>\<open>d3_root_equation2\<close>,
   736         (*(bdv \<up> 3=0) = (bdv=0) *)
   737 	\<^rule_thm>\<open>d3_root_equation1\<close>
   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>\<open>d4_sub_u1\<close>  
   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 problem pbl_equ_univ_poly : "polynomial/univariate/equation" =
   771   \<open>PolyEq_prls\<close>
   772   CAS: "solve (e_e::bool, v_v)"
   773   Given: "equality e_e" "solveFor v_v"
   774   Where:
   775     "~((e_e::bool) is_ratequation_in (v_v::real))"
   776 	  "~((lhs e_e) is_rootTerm_in (v_v::real))"
   777 	  "~((rhs e_e) is_rootTerm_in (v_v::real))"
   778   Find: "solutions v_v'i'"
   779 
   780 (*--- d0 ---*)
   781 problem pbl_equ_univ_poly_deg0 : "degree_0/polynomial/univariate/equation" =
   782   \<open>PolyEq_prls\<close>
   783   Method: "PolyEq/solve_d0_polyeq_equation"
   784   CAS: "solve (e_e::bool, v_v)"
   785   Given: "equality e_e" "solveFor v_v"
   786   Where:
   787     "matches (?a = 0) e_e"
   788     "(lhs e_e) is_poly_in v_v"
   789     "((lhs e_e) has_degree_in v_v ) = 0"
   790   Find: "solutions v_v'i'"
   791 
   792 (*--- d1 ---*)
   793 problem pbl_equ_univ_poly_deg1 : "degree_1/polynomial/univariate/equation" =
   794   \<open>PolyEq_prls\<close>
   795   Method: "PolyEq/solve_d1_polyeq_equation"
   796   CAS: "solve (e_e::bool, v_v)"
   797   Given: "equality e_e" "solveFor v_v"
   798   Where:
   799     "matches (?a = 0) e_e"
   800 	  "(lhs e_e) is_poly_in v_v"
   801 	  "((lhs e_e) has_degree_in v_v ) = 1"
   802   Find: "solutions v_v'i'"
   803 
   804 (*--- d2 ---*)
   805 problem pbl_equ_univ_poly_deg2 : "degree_2/polynomial/univariate/equation" =
   806   \<open>PolyEq_prls\<close>
   807   Method: "PolyEq/solve_d2_polyeq_equation"
   808   CAS: "solve (e_e::bool, v_v)"
   809   Given: "equality e_e" "solveFor v_v"
   810   Where:
   811     "matches (?a = 0) e_e"
   812     "(lhs e_e) is_poly_in v_v "
   813     "((lhs e_e) has_degree_in v_v ) = 2"
   814   Find: "solutions v_v'i'"
   815 
   816 problem pbl_equ_univ_poly_deg2_sqonly : "sq_only/degree_2/polynomial/univariate/equation" =
   817   \<open>PolyEq_prls\<close>
   818   Method: "PolyEq/solve_d2_polyeq_sqonly_equation"
   819   CAS: "solve (e_e::bool, v_v)"
   820   Given: "equality e_e" "solveFor v_v"
   821   Where:
   822     "matches ( ?a +    ?v_ \<up> 2 = 0) e_e |
   823      matches ( ?a + ?b*?v_ \<up> 2 = 0) e_e |
   824      matches (         ?v_ \<up> 2 = 0) e_e |
   825      matches (      ?b*?v_ \<up> 2 = 0) e_e"
   826     "Not (matches (?a +    ?v_ +    ?v_ \<up> 2 = 0) e_e) &
   827      Not (matches (?a + ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &
   828      Not (matches (?a +    ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &
   829      Not (matches (?a + ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e) &
   830      Not (matches (        ?v_ +    ?v_ \<up> 2 = 0) e_e) &
   831      Not (matches (     ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &
   832      Not (matches (        ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &
   833      Not (matches (     ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e)"
   834   Find: "solutions v_v'i'"
   835 
   836 problem pbl_equ_univ_poly_deg2_bdvonly : "bdv_only/degree_2/polynomial/univariate/equation" =
   837   \<open>PolyEq_prls\<close>
   838   Method: "PolyEq/solve_d2_polyeq_bdvonly_equation"
   839   CAS: "solve (e_e::bool, v_v)"
   840   Given: "equality e_e" "solveFor v_v"
   841   Where:
   842     "matches (?a*?v_ +    ?v_ \<up> 2 = 0) e_e |
   843      matches (   ?v_ +    ?v_ \<up> 2 = 0) e_e |
   844      matches (   ?v_ + ?b*?v_ \<up> 2 = 0) e_e |
   845      matches (?a*?v_ + ?b*?v_ \<up> 2 = 0) e_e |
   846      matches (            ?v_ \<up> 2 = 0) e_e |
   847      matches (         ?b*?v_ \<up> 2 = 0) e_e "
   848   Find: "solutions v_v'i'"
   849 
   850 problem pbl_equ_univ_poly_deg2_pq : "pqFormula/degree_2/polynomial/univariate/equation" =
   851   \<open>PolyEq_prls\<close>
   852   Method: "PolyEq/solve_d2_polyeq_pq_equation"
   853   CAS: "solve (e_e::bool, v_v)"
   854   Given: "equality e_e" "solveFor v_v"
   855   Where:
   856     "matches (?a + 1*?v_ \<up> 2 = 0) e_e |
   857      matches (?a +   ?v_ \<up> 2 = 0) e_e"
   858   Find: "solutions v_v'i'"
   859 
   860 problem pbl_equ_univ_poly_deg2_abc : "abcFormula/degree_2/polynomial/univariate/equation" =
   861   \<open>PolyEq_prls\<close>
   862   Method: "PolyEq/solve_d2_polyeq_abc_equation"
   863   CAS: "solve (e_e::bool, v_v)"
   864   Given: "equality e_e" "solveFor v_v"
   865   Where:
   866     "matches (?a +    ?v_ \<up> 2 = 0) e_e |
   867      matches (?a + ?b*?v_ \<up> 2 = 0) e_e"
   868   Find: "solutions v_v'i'"
   869 
   870 (*--- d3 ---*)
   871 problem pbl_equ_univ_poly_deg3 : "degree_3/polynomial/univariate/equation" =
   872   \<open>PolyEq_prls\<close>
   873   Method: "PolyEq/solve_d3_polyeq_equation"
   874   CAS: "solve (e_e::bool, v_v)"
   875   Given: "equality e_e" "solveFor v_v"
   876   Where:
   877     "matches (?a = 0) e_e"
   878     "(lhs e_e) is_poly_in v_v"
   879     "((lhs e_e) has_degree_in v_v) = 3"
   880   Find: "solutions v_v'i'"
   881 
   882 (*--- d4 ---*)
   883 problem pbl_equ_univ_poly_deg4 : "degree_4/polynomial/univariate/equation" =
   884   \<open>PolyEq_prls\<close>
   885   (*Method: "PolyEq/solve_d4_polyeq_equation"*)
   886   CAS: "solve (e_e::bool, v_v)"
   887   Given: "equality e_e" "solveFor v_v"
   888   Where:
   889     "matches (?a = 0) e_e"
   890     "(lhs e_e) is_poly_in v_v"
   891     "((lhs e_e) has_degree_in v_v) = 4"
   892   Find: "solutions v_v'i'"
   893 
   894 (*--- normalise ---*)
   895 problem pbl_equ_univ_poly_norm : "normalise/polynomial/univariate/equation" =
   896   \<open>PolyEq_prls\<close>
   897   Method: "PolyEq/normalise_poly"
   898   CAS: "solve (e_e::bool, v_v)"
   899   Given: "equality e_e" "solveFor v_v"
   900   Where:
   901     "(Not((matches (?a = 0 ) e_e ))) |
   902      (Not(((lhs e_e) is_poly_in v_v)))"
   903   Find: "solutions v_v'i'"
   904 
   905 (*-------------------------expanded-----------------------*)
   906 problem "pbl_equ_univ_expand" : "expanded/univariate/equation" =
   907   \<open>PolyEq_prls\<close>
   908   CAS: "solve (e_e::bool, v_v)"
   909   Given: "equality e_e" "solveFor v_v"
   910   Where:
   911     "matches (?a = 0) e_e"
   912     "(lhs e_e) is_expanded_in v_v "
   913   Find: "solutions v_v'i'"
   914 
   915 (*--- d2 ---*)
   916 problem pbl_equ_univ_expand_deg2 : "degree_2/expanded/univariate/equation" =
   917   \<open>PolyEq_prls\<close>
   918   Method: "PolyEq/complete_square"
   919   CAS: "solve (e_e::bool, v_v)"
   920   Given: "equality e_e" "solveFor v_v"
   921   Where: "((lhs e_e) has_degree_in v_v) = 2"
   922   Find: "solutions v_v'i'"
   923 
   924 text \<open>"-------------------------methods-----------------------"\<close>
   925 
   926 method met_polyeq : "PolyEq" =
   927   \<open>{rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
   928     crls=PolyEq_crls, errpats = [], nrls = norm_Rational}\<close>
   929 
   930 partial_function (tailrec) normalize_poly_eq :: "bool \<Rightarrow> real \<Rightarrow> bool"
   931   where
   932 "normalize_poly_eq e_e v_v = (
   933   let
   934     e_e = (
   935       (Try (Rewrite ''all_left'')) #>
   936       (Try (Repeat (Rewrite ''makex1_x''))) #>
   937       (Try (Repeat (Rewrite_Set ''expand_binoms''))) #>
   938       (Try (Repeat (Rewrite_Set_Inst [(''bdv'', v_v)] ''make_ratpoly_in''))) #>
   939       (Try (Repeat (Rewrite_Set ''polyeq_simplify''))) ) e_e
   940   in
   941     SubProblem (''PolyEq'', [''polynomial'', ''univariate'', ''equation''], [''no_met''])
   942       [BOOL e_e, REAL v_v])"
   943 
   944 method met_polyeq_norm : "PolyEq/normalise_poly" =
   945   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls, calc=[],
   946     crls=PolyEq_crls, errpats = [], nrls = norm_Rational}\<close>
   947   Program: normalize_poly_eq.simps
   948   Given: "equality e_e" "solveFor v_v"
   949   Where: "(Not((matches (?a = 0 ) e_e ))) | (Not(((lhs e_e) is_poly_in v_v)))"
   950   Find: "solutions v_v'i'"
   951 
   952 partial_function (tailrec) solve_poly_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   953   where
   954 "solve_poly_equ e_e v_v = (
   955   let
   956     e_e = (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d0_polyeq_simplify'')) e_e   
   957   in
   958     Or_to_List e_e)"
   959 
   960 method met_polyeq_d0 : "PolyEq/solve_d0_polyeq_equation" =
   961   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
   962     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
   963     nrls = norm_Rational}\<close>
   964   Program: solve_poly_equ.simps
   965   Given: "equality e_e" "solveFor v_v"
   966   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 0"
   967   Find: "solutions v_v'i'"
   968 
   969 partial_function (tailrec) solve_poly_eq1 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   970   where
   971 "solve_poly_eq1 e_e v_v = (
   972   let
   973     e_e = (
   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 
   981 method met_polyeq_d1 : "PolyEq/solve_d1_polyeq_equation" =
   982   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
   983     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
   984     nrls = norm_Rational}\<close>
   985   Program: solve_poly_eq1.simps
   986   Given: "equality e_e" "solveFor v_v"
   987   Where: "(lhs e_e) is_poly_in v_v" "((lhs e_e) has_degree_in v_v) = 1"
   988   Find: "solutions v_v'i'"
   989 
   990 partial_function (tailrec) solve_poly_equ2 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
   991   where
   992 "solve_poly_equ2 e_e v_v = (
   993   let
   994     e_e = (
   995       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
   996       (Try (Rewrite_Set ''polyeq_simplify'')) #>
   997       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d1_polyeq_simplify'')) #>
   998       (Try (Rewrite_Set ''polyeq_simplify'')) #>
   999       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1000     L_L =  Or_to_List e_e
  1001   in
  1002     Check_elementwise L_L {(v_v::real). Assumptions})"
  1003 
  1004 method met_polyeq_d22 : "PolyEq/solve_d2_polyeq_equation" =
  1005   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1006     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1007     nrls = norm_Rational}\<close>
  1008   Program: solve_poly_equ2.simps
  1009   Given: "equality e_e" "solveFor v_v"
  1010   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 2"
  1011   Find: "solutions v_v'i'"
  1012 
  1013 partial_function (tailrec) solve_poly_equ0 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1014   where
  1015 "solve_poly_equ0 e_e v_v = (
  1016   let
  1017      e_e = (
  1018        (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_bdv_only_simplify'')) #>
  1019        (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1020        (Try (Rewrite_Set_Inst [(''bdv'',v_v::real)] ''d1_polyeq_simplify'')) #>
  1021        (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1022        (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1023      L_L = Or_to_List e_e
  1024   in
  1025     Check_elementwise L_L {(v_v::real). Assumptions})"
  1026 
  1027 method met_polyeq_d2_bdvonly : "PolyEq/solve_d2_polyeq_bdvonly_equation" =
  1028   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1029     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1030     nrls = norm_Rational}\<close>
  1031   Program: solve_poly_equ0.simps
  1032   Given: "equality e_e" "solveFor v_v"
  1033   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 2"
  1034   Find: "solutions v_v'i'"
  1035 
  1036 partial_function (tailrec) solve_poly_equ_sqrt :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1037   where
  1038 "solve_poly_equ_sqrt e_e v_v = (
  1039   let
  1040     e_e = (
  1041       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_sq_only_simplify'')) #>
  1042       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1043       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1044     L_L = Or_to_List e_e
  1045   in
  1046     Check_elementwise L_L {(v_v::real). Assumptions})"
  1047 
  1048 method met_polyeq_d2_sqonly : "PolyEq/solve_d2_polyeq_sqonly_equation" =
  1049   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1050     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1051     nrls = norm_Rational}\<close>
  1052   Program: solve_poly_equ_sqrt.simps
  1053   Given: "equality e_e" "solveFor v_v"
  1054   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 2"
  1055   Find: "solutions v_v'i'"
  1056 
  1057 partial_function (tailrec) solve_poly_equ_pq :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1058   where
  1059 "solve_poly_equ_pq e_e v_v = (
  1060   let
  1061     e_e = (
  1062       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_pqFormula_simplify'')) #>
  1063       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1064       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1065     L_L = Or_to_List e_e
  1066   in
  1067     Check_elementwise L_L {(v_v::real). Assumptions})"
  1068 
  1069 method met_polyeq_d2_pq : "PolyEq/solve_d2_polyeq_pq_equation" =
  1070   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1071     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1072     nrls = norm_Rational}\<close>
  1073   Program: solve_poly_equ_pq.simps
  1074   Given: "equality e_e" "solveFor v_v"
  1075   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 2"
  1076   Find: "solutions v_v'i'"
  1077 
  1078 partial_function (tailrec) solve_poly_equ_abc :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1079   where
  1080 "solve_poly_equ_abc e_e v_v = (
  1081   let
  1082     e_e = (
  1083       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_abcFormula_simplify'')) #>
  1084       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1085       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
  1086     L_L = Or_to_List e_e
  1087   in Check_elementwise L_L {(v_v::real). Assumptions})"
  1088 
  1089 method met_polyeq_d2_abc : "PolyEq/solve_d2_polyeq_abc_equation" =
  1090   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls,srls=Rule_Set.empty, prls=PolyEq_prls,
  1091     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1092     nrls = norm_Rational}\<close>
  1093   Program: solve_poly_equ_abc.simps
  1094   Given: "equality e_e" "solveFor v_v"
  1095   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 2"
  1096   Find: "solutions v_v'i'"
  1097 
  1098 partial_function (tailrec) solve_poly_equ3 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1099   where
  1100 "solve_poly_equ3 e_e v_v = (
  1101   let
  1102     e_e = (
  1103       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d3_polyeq_simplify'')) #>
  1104       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1105       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
  1106       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1107       (Try (Rewrite_Set_Inst [(''bdv'',v_v)] ''d1_polyeq_simplify'')) #>
  1108       (Try (Rewrite_Set ''polyeq_simplify'')) #>
  1109       (Try (Rewrite_Set ''norm_Rational_parenthesized''))) e_e;
  1110     L_L = Or_to_List e_e
  1111   in
  1112     Check_elementwise L_L {(v_v::real). Assumptions})"
  1113 
  1114 method met_polyeq_d3 : "PolyEq/solve_d3_polyeq_equation" =
  1115   \<open>{rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
  1116     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1117     nrls = norm_Rational}\<close>
  1118   Program: solve_poly_equ3.simps
  1119   Given: "equality e_e" "solveFor v_v"
  1120   Where: "(lhs e_e) is_poly_in v_v " "((lhs e_e) has_degree_in v_v) = 3"
  1121   Find: "solutions v_v'i'"
  1122 
  1123     (*.solves all expanded (ie. normalised) terms of degree 2.*)
  1124     (*Oct.02 restriction: 'eval_true 0 =< discriminant' ony for integer values
  1125       by 'PolyEq_erls'; restricted until Float.thy is implemented*)
  1126 partial_function (tailrec) solve_by_completing_square :: "bool \<Rightarrow> real \<Rightarrow> bool list"
  1127   where
  1128 "solve_by_completing_square e_e v_v = (
  1129   let e_e = (
  1130     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''cancel_leading_coeff'')) #>
  1131     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''complete_square'')) #>
  1132     (Try (Rewrite ''square_explicit1'')) #>
  1133     (Try (Rewrite ''square_explicit2'')) #>
  1134     (Rewrite ''root_plus_minus'') #>
  1135     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit1''))) #>
  1136     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit2''))) #>
  1137     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit3''))) #>
  1138     (Try (Rewrite_Set ''calculate_RootRat'')) #>
  1139     (Try (Repeat (Calculate ''SQRT'')))) e_e
  1140   in
  1141     Or_to_List e_e)"
  1142 
  1143 method met_polyeq_complsq : "PolyEq/complete_square" =
  1144   \<open>{rew_ord'="termlessI",rls'=PolyEq_erls,srls=Rule_Set.empty,prls=PolyEq_prls,
  1145     calc=[("sqrt", (\<^const_name>\<open>sqrt\<close>, eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
  1146     nrls = norm_Rational}\<close>
  1147   Program: solve_by_completing_square.simps
  1148   Given: "equality e_e" "solveFor v_v"
  1149   Where: "matches (?a = 0) e_e" "((lhs e_e) has_degree_in v_v) = 2"
  1150   Find: "solutions v_v'i'"
  1151 
  1152 ML\<open>
  1153 
  1154 (* termorder hacked by MG *)
  1155 local (*. for make_polynomial_in .*)
  1156 
  1157 open Term;  (* for type order = EQUAL | LESS | GREATER *)
  1158 
  1159 fun pr_ord EQUAL = "EQUAL"
  1160   | pr_ord LESS  = "LESS"
  1161   | pr_ord GREATER = "GREATER";
  1162 
  1163 fun dest_hd' _ (Const (a, T)) = (((a, 0), T), 0)
  1164   | dest_hd' x (t as Free (a, T)) =
  1165     if x = t then ((("|||||||||||||", 0), T), 0)                        (*WN*)
  1166     else (((a, 0), T), 1)
  1167   | dest_hd' _ (Var v) = (v, 2)
  1168   | dest_hd' _ (Bound i) = ((("", i), dummyT), 3)
  1169   | dest_hd' _ (Abs (_, T, _)) = ((("", 0), T), 4)
  1170   | dest_hd' _ _ = raise ERROR "dest_hd': uncovered case in fun.def.";
  1171 
  1172 fun size_of_term' x (Const (\<^const_name>\<open>Transcendental.powr\<close>,_) $
  1173       Free (var, _) $ Const (\<^const_name>\<open>numeral\<close>, _) $ pot) =
  1174     (case x of                                                          (*WN*)
  1175 	    (Free (xstr, _)) => 
  1176 		    (if xstr = var then 1000 * (HOLogic.dest_numeral pot) else 3)
  1177 	  | _ => raise ERROR ("size_of_term' called with subst = " ^ UnparseC.term x))
  1178   | size_of_term' x (Free (subst, _)) =
  1179     (case x of
  1180 	    (Free (xstr, _)) => (if xstr = subst then 1000 else 1)
  1181 	  | _ => raise ERROR ("size_of_term' called with subst = " ^ UnparseC.term x))
  1182   | size_of_term' x (Abs (_, _, body)) = 1 + size_of_term' x body
  1183   | size_of_term' x (f$t) = size_of_term' x f  +  size_of_term' x t
  1184   | size_of_term' _ _ = 1;
  1185 
  1186 fun term_ord' x pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
  1187     (case term_ord' x pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
  1188   | term_ord' x pr thy (t, u) =
  1189     (if pr
  1190      then 
  1191        let
  1192          val (f, ts) = strip_comb t and (g, us) = strip_comb u;
  1193          val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
  1194            commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
  1195          val _ = tracing ("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
  1196            commas(map (UnparseC.term_in_thy thy) us) ^ "]\"");
  1197          val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' x t) ^ ", " ^
  1198            string_of_int (size_of_term' x u) ^ ")");
  1199          val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o (hd_ord x)) (f,g));
  1200          val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o (terms_ord x) str false) (ts, us));
  1201          val _ = tracing ("-------");
  1202        in () end
  1203      else ();
  1204 	  case int_ord (size_of_term' x t, size_of_term' x u) of
  1205 	    EQUAL =>
  1206 	      let val (f, ts) = strip_comb t and (g, us) = strip_comb u 
  1207         in
  1208 	        (case hd_ord x (f, g) of 
  1209 	           EQUAL => (terms_ord x str pr) (ts, us) 
  1210 	         | ord => ord)
  1211 	      end
  1212 	 | ord => ord)
  1213 and hd_ord x (f, g) =                                        (* ~ term.ML *)
  1214   prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) 
  1215             int_ord (dest_hd' x f, dest_hd' x g)
  1216 and terms_ord x _ pr (ts, us) = 
  1217     list_ord (term_ord' x pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
  1218 
  1219 in(*local*)
  1220 
  1221 fun ord_make_polynomial_in (pr:bool) thy subst (ts, us) =
  1222   ((** )tracing ("*** subs variable is: " ^ (Env.subst2str subst)); ( **)
  1223 	case subst of
  1224 	  (_, x) :: _ => (term_ord' x pr thy (TermC.numerals_to_Free ts, TermC.numerals_to_Free us) = LESS)
  1225 	| _ => raise ERROR ("ord_make_polynomial_in called with subst = " ^ Env.subst2str subst))
  1226 
  1227 end;(*local*)
  1228 
  1229 \<close>
  1230 ML\<open>
  1231 val order_add_mult_in = prep_rls'(
  1232   Rule_Def.Repeat{id = "order_add_mult_in", preconds = [], 
  1233       rew_ord = ("ord_make_polynomial_in", ord_make_polynomial_in false @{theory "Poly"}),
  1234       erls = Rule_Set.empty,srls = Rule_Set.Empty,
  1235       calc = [], errpatts = [],
  1236       rules = [\<^rule_thm>\<open>mult.commute\<close>,
  1237 	       (* z * w = w * z *)
  1238 	       \<^rule_thm>\<open>real_mult_left_commute\<close>,
  1239 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
  1240 	       \<^rule_thm>\<open>mult.assoc\<close>,		
  1241 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
  1242 	       \<^rule_thm>\<open>add.commute\<close>,	
  1243 	       (*z + w = w + z*)
  1244 	       \<^rule_thm>\<open>add.left_commute\<close>,
  1245 	       (*x + (y + z) = y + (x + z)*)
  1246 	       \<^rule_thm>\<open>add.assoc\<close>	               
  1247 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
  1248 	       ], scr = Rule.Empty_Prog});
  1249 
  1250 \<close>
  1251 ML\<open>
  1252 val collect_bdv = prep_rls'(
  1253   Rule_Def.Repeat{id = "collect_bdv", preconds = [], 
  1254       rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1255       erls = Rule_Set.empty,srls = Rule_Set.Empty,
  1256       calc = [], errpatts = [],
  1257       rules = [\<^rule_thm>\<open>bdv_collect_1\<close>,
  1258 	       \<^rule_thm>\<open>bdv_collect_2\<close>,
  1259 	       \<^rule_thm>\<open>bdv_collect_3\<close>,
  1260 
  1261 	       \<^rule_thm>\<open>bdv_collect_assoc1_1\<close>,
  1262 	       \<^rule_thm>\<open>bdv_collect_assoc1_2\<close>,
  1263 	       \<^rule_thm>\<open>bdv_collect_assoc1_3\<close>,
  1264 
  1265 	       \<^rule_thm>\<open>bdv_collect_assoc2_1\<close>,
  1266 	       \<^rule_thm>\<open>bdv_collect_assoc2_2\<close>,
  1267 	       \<^rule_thm>\<open>bdv_collect_assoc2_3\<close>,
  1268 
  1269 
  1270 	       \<^rule_thm>\<open>bdv_n_collect_1\<close>,
  1271 	       \<^rule_thm>\<open>bdv_n_collect_2\<close>,
  1272 	       \<^rule_thm>\<open>bdv_n_collect_3\<close>,
  1273 
  1274 	       \<^rule_thm>\<open>bdv_n_collect_assoc1_1\<close>,
  1275 	       \<^rule_thm>\<open>bdv_n_collect_assoc1_2\<close>,
  1276 	       \<^rule_thm>\<open>bdv_n_collect_assoc1_3\<close>,
  1277 
  1278 	       \<^rule_thm>\<open>bdv_n_collect_assoc2_1\<close>,
  1279 	       \<^rule_thm>\<open>bdv_n_collect_assoc2_2\<close>,
  1280 	       \<^rule_thm>\<open>bdv_n_collect_assoc2_3\<close>
  1281 	       ], scr = Rule.Empty_Prog});
  1282 
  1283 \<close>
  1284 ML\<open>
  1285 (*.transforms an arbitrary term without roots to a polynomial [4] 
  1286    according to knowledge/Poly.sml.*) 
  1287 val make_polynomial_in = prep_rls'(
  1288   Rule_Set.Sequence {id = "make_polynomial_in", preconds = []:term list, 
  1289        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1290       erls = Atools_erls, srls = Rule_Set.Empty,
  1291       calc = [], errpatts = [],
  1292       rules = [Rule.Rls_ expand_poly,
  1293 	       Rule.Rls_ order_add_mult_in,
  1294 	       Rule.Rls_ simplify_power,
  1295 	       Rule.Rls_ collect_numerals,
  1296 	       Rule.Rls_ reduce_012,
  1297 	       \<^rule_thm>\<open>realpow_oneI\<close>,
  1298 	       Rule.Rls_ discard_parentheses,
  1299 	       Rule.Rls_ collect_bdv
  1300 	       ],
  1301       scr = Rule.Empty_Prog
  1302       });     
  1303 
  1304 \<close>
  1305 ML\<open>
  1306 val separate_bdvs = 
  1307     Rule_Set.append_rules "separate_bdvs"
  1308 	       collect_bdv
  1309 	       [\<^rule_thm>\<open>separate_bdv\<close>,
  1310 		(*"?a * ?bdv / ?b = ?a / ?b * ?bdv"*)
  1311 		\<^rule_thm>\<open>separate_bdv_n\<close>,
  1312 		\<^rule_thm>\<open>separate_1_bdv\<close>,
  1313 		(*"?bdv / ?b = (1 / ?b) * ?bdv"*)
  1314 		\<^rule_thm>\<open>separate_1_bdv_n\<close>,
  1315 		(*"?bdv \<up> ?n / ?b = 1 / ?b * ?bdv \<up> ?n"*)
  1316 		\<^rule_thm>\<open>add_divide_distrib\<close>
  1317 		(*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"
  1318 		      WN051031 DOES NOT BELONG TO HERE*)
  1319 		];
  1320 \<close>
  1321 ML\<open>
  1322 val make_ratpoly_in = prep_rls'(
  1323   Rule_Set.Sequence {id = "make_ratpoly_in", preconds = []:term list, 
  1324        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
  1325       erls = Atools_erls, srls = Rule_Set.Empty,
  1326       calc = [], errpatts = [],
  1327       rules = [Rule.Rls_ norm_Rational,
  1328 	       Rule.Rls_ order_add_mult_in,
  1329 	       Rule.Rls_ discard_parentheses,
  1330 	       Rule.Rls_ separate_bdvs,
  1331 	       (* Rule.Rls_ rearrange_assoc, WN060916 why does cancel_p not work?*)
  1332 	       Rule.Rls_ cancel_p
  1333 	       (*\<^rule_eval>\<open>divide\<close> (eval_cancel "#divide_e") too weak!*)
  1334 	       ],
  1335       scr = Rule.Empty_Prog});      
  1336 \<close>
  1337 rule_set_knowledge
  1338   order_add_mult_in = order_add_mult_in and
  1339   collect_bdv = collect_bdv and
  1340   make_polynomial_in = make_polynomial_in and
  1341   make_ratpoly_in = make_ratpoly_in and
  1342   separate_bdvs = separate_bdvs
  1343 ML \<open>
  1344 \<close> ML \<open>
  1345 \<close> ML \<open>
  1346 \<close>
  1347 end
  1348 
  1349 
  1350 
  1351 
  1352 
  1353