
neuper@37906: (* theory collecting all knowledge 
neuper@37906:    (predicates 'is_rootEq_in', 'is_sqrt_in', 'is_ratEq_in')
neuper@37906:    for PolynomialEquations.
wneuper@59592:    alternative dependencies see @{theory "Isac_Knowledge"}
neuper@37906:    created by: rlang 
neuper@37906:          date: 02.07
neuper@37906:    changed by: rlang
neuper@37906:    last change by: rlang
neuper@37906:              date: 03.06.03
neuper@37954:    (c) by Richard Lang, 2003
neuper@37906: *)
neuper@37906: 
neuper@37954: theory PolyEq imports LinEq RootRatEq begin 
neuper@37906: 
neuper@37906: (*-------------------- rules -------------------------------------------------*)
walther@60242: (* type real enforced by op " \<up> " *)
neuper@52148: axiomatization where
walther@60242:   cancel_leading_coeff1: "Not (c =!= 0) ==> (a + b*bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c + b/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff2: "Not (c =!= 0) ==> (a - b*bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c - b/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff3: "Not (c =!= 0) ==> (a + b*bdv - c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c + b/c*bdv - bdv \<up> 2 = 0)" and
neuper@37906: 
walther@60242:   cancel_leading_coeff4: "Not (c =!= 0) ==> (a +   bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c + 1/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff5: "Not (c =!= 0) ==> (a -   bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c - 1/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff6: "Not (c =!= 0) ==> (a +   bdv - c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/c + 1/c*bdv - bdv \<up> 2 = 0)" and
neuper@37906: 
walther@60242:   cancel_leading_coeff7: "Not (c =!= 0) ==> (    b*bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (    b/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff8: "Not (c =!= 0) ==> (    b*bdv - c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (    b/c*bdv - bdv \<up> 2 = 0)" and
neuper@37906: 
walther@60242:   cancel_leading_coeff9: "Not (c =!= 0) ==> (      bdv + c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (      1/c*bdv + bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff10:"Not (c =!= 0) ==> (      bdv - c*bdv \<up> 2 = 0) = 
walther@60242: 			                   (      1/c*bdv - bdv \<up> 2 = 0)" and
neuper@37906: 
walther@60242:   cancel_leading_coeff11:"Not (c =!= 0) ==> (a +      b*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/b +      bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff12:"Not (c =!= 0) ==> (a -      b*bdv \<up> 2 = 0) = 
walther@60242: 			                   (a/b -      bdv \<up> 2 = 0)" and
walther@60242:   cancel_leading_coeff13:"Not (c =!= 0) ==> (         b*bdv \<up> 2 = 0) = 
walther@60242: 			                   (           bdv \<up> 2 = 0/b)" and
neuper@37906: 
walther@60242:   complete_square1:      "(q + p*bdv + bdv \<up> 2 = 0) = 
walther@60242: 		         (q + (p/2 + bdv) \<up> 2 = (p/2) \<up> 2)" and
walther@60242:   complete_square2:      "(    p*bdv + bdv \<up> 2 = 0) = 
walther@60242: 		         (    (p/2 + bdv) \<up> 2 = (p/2) \<up> 2)" and
walther@60242:   complete_square3:      "(      bdv + bdv \<up> 2 = 0) = 
walther@60242: 		         (    (1/2 + bdv) \<up> 2 = (1/2) \<up> 2)" and
neuper@37906: 		        
walther@60242:   complete_square4:      "(q - p*bdv + bdv \<up> 2 = 0) = 
walther@60242: 		         (q + (p/2 - bdv) \<up> 2 = (p/2) \<up> 2)" and
walther@60242:   complete_square5:      "(q + p*bdv - bdv \<up> 2 = 0) = 
walther@60242: 		         (q + (p/2 - bdv) \<up> 2 = (p/2) \<up> 2)" and
neuper@37906: 
walther@60242:   square_explicit1:      "(a + b \<up> 2 = c) = ( b \<up> 2 = c - a)" and
walther@60242:   square_explicit2:      "(a - b \<up> 2 = c) = (-(b \<up> 2) = c - a)" and
neuper@37906: 
walther@60242:   (*bdv_explicit* required type constrain to real in --- (-8 - 2*x + x \<up> 2 = 0),  by rewriting ---*)
neuper@52148:   bdv_explicit1:         "(a + bdv = b) = (bdv = - a + (b::real))" and
neuper@52148:   bdv_explicit2:         "(a - bdv = b) = ((-1)*bdv = - a + (b::real))" and
neuper@52148:   bdv_explicit3:         "((-1)*bdv = b) = (bdv = (-1)*(b::real))" and
neuper@37906: 
neuper@52148:   plus_leq:              "(0 <= a + b) = ((-1)*b <= a)"(*Isa?*) and
neuper@52148:   minus_leq:             "(0 <= a - b) = (     b <= a)"(*Isa?*) and
neuper@37906: 
wneuper@59370: (*-- normalise --*)
neuper@37906:   (*WN0509 compare LinEq.all_left "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)"*)
neuper@52148:   all_left:              "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)" and
walther@60242:   makex1_x:              "a\<up>1  = a"   and
neuper@52148:   real_assoc_1:          "a+(b+c) = a+b+c" and
neuper@52148:   real_assoc_2:          "a*(b*c) = a*b*c" and
neuper@37906: 
neuper@37906: (* ---- degree 0 ----*)
neuper@52148:   d0_true:               "(0=0) = True" and
neuper@52148:   d0_false:              "[|Not(bdv occurs_in a);Not(a=0)|] ==> (a=0) = False" and
neuper@37906: (* ---- degree 1 ----*)
neuper@37983:   d1_isolate_add1:
neuper@52148:    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv = 0) = (b*bdv = (-1)*a)" and
neuper@37983:   d1_isolate_add2:
neuper@52148:    "[|Not(bdv occurs_in a)|] ==> (a +   bdv = 0) = (  bdv = (-1)*a)" and
neuper@37983:   d1_isolate_div:
neuper@52148:    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv = c) = (bdv = c/b)" and
neuper@37906: (* ---- degree 2 ----*)
neuper@37983:   d2_isolate_add1:
walther@60242:    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 2=0) = (b*bdv \<up> 2= (-1)*a)" and
neuper@37983:   d2_isolate_add2:
walther@60242:    "[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 2=0) = (  bdv \<up> 2= (-1)*a)" and
neuper@37983:   d2_isolate_div:
walther@60242:    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv \<up> 2=c) = (bdv \<up> 2=c/b)" and
neuper@42394:   
walther@60242:   d2_prescind1:          "(a*bdv + b*bdv \<up> 2 = 0) = (bdv*(a +b*bdv)=0)" and
walther@60242:   d2_prescind2:          "(a*bdv +   bdv \<up> 2 = 0) = (bdv*(a +  bdv)=0)" and
walther@60242:   d2_prescind3:          "(  bdv + b*bdv \<up> 2 = 0) = (bdv*(1+b*bdv)=0)" and
walther@60242:   d2_prescind4:          "(  bdv +   bdv \<up> 2 = 0) = (bdv*(1+  bdv)=0)" and
neuper@37906:   (* eliminate degree 2 *)
neuper@37906:   (* thm for neg arguments in sqroot have postfix _neg *)
neuper@37983:   d2_sqrt_equation1:     "[|(0<=c);Not(bdv occurs_in c)|] ==> 
walther@60242:                          (bdv \<up> 2=c) = ((bdv=sqrt c) | (bdv=(-1)*sqrt c ))" and
t@42197:  d2_sqrt_equation1_neg:
walther@60242:   "[|(c<0);Not(bdv occurs_in c)|] ==> (bdv \<up> 2=c) = False" and
walther@60242:   d2_sqrt_equation2:     "(bdv \<up> 2=0) = (bdv=0)" and
walther@60242:   d2_sqrt_equation3:     "(b*bdv \<up> 2=0) = (bdv=0)"
neuper@52148: axiomatization where (*AK..if replaced by "and" we get errors:
t@42203:   exception PTREE "nth _ []" raised 
t@42203:   (line 783 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml"):
t@42203:     'fun nth _ []      = raise PTREE "nth _ []"'
t@42203: and
t@42203:   exception Bind raised 
t@42203:   (line 1097 of "/usr/local/isabisac/test/Tools/isac/Frontend/interface.sml"):
t@42203:     'val (Form f, tac, asms) = pt_extract (pt, p);' *)
walther@60242:   (* WN120315 these 2 thms need "::real", because no " \<up> " constrains type as
neuper@42394:      required in test --- rls d2_polyeq_bdv_only_simplify --- *)
neuper@52148:   d2_reduce_equation1:   "(bdv*(a +b*bdv)=0) = ((bdv=0)|(a+b*bdv=(0::real)))" and
neuper@42394:   d2_reduce_equation2:   "(bdv*(a +  bdv)=0) = ((bdv=0)|(a+  bdv=(0::real)))"
neuper@52148: 
neuper@52148: axiomatization where (*..if replaced by "and" we get errors:
t@42203:   exception PTREE "nth _ []" raised 
t@42203:   (line 783 of "/usr/local/isabisac/src/Tools/isac/Interpret/ctree.sml"):
t@42203:     'fun nth _ []      = raise PTREE "nth _ []"'
t@42203: and
t@42203:   exception Bind raised 
t@42203:   (line 1097 of "/usr/local/isabisac/test/Tools/isac/Frontend/interface.sml"):
t@42203:     'val (Form f, tac, asms) = pt_extract (pt, p);' *)
walther@60242: d2_pqformula1:         "[|0<=p \<up> 2 - 4*q|] ==> (q+p*bdv+   bdv \<up> 2=0) =
walther@60242:                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 4*q)/2) 
walther@60242:                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 4*q)/2))" and
walther@60242:   d2_pqformula1_neg:     "[|p \<up> 2 - 4*q<0|] ==> (q+p*bdv+   bdv \<up> 2=0) = False" and
walther@60242:   d2_pqformula2:         "[|0<=p \<up> 2 - 4*q|] ==> (q+p*bdv+1*bdv \<up> 2=0) = 
walther@60242:                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 4*q)/2) 
walther@60242:                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 4*q)/2))" and
walther@60242:   d2_pqformula2_neg:     "[|p \<up> 2 - 4*q<0|] ==> (q+p*bdv+1*bdv \<up> 2=0) = False" and
walther@60242:   d2_pqformula3:         "[|0<=1 - 4*q|] ==> (q+  bdv+   bdv \<up> 2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
neuper@52148:                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))" and
walther@60242:   d2_pqformula3_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+   bdv \<up> 2=0) = False" and
walther@60242:   d2_pqformula4:         "[|0<=1 - 4*q|] ==> (q+  bdv+1*bdv \<up> 2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
neuper@52148:                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))" and
walther@60242:   d2_pqformula4_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+1*bdv \<up> 2=0) = False" and
walther@60242:   d2_pqformula5:         "[|0<=p \<up> 2 - 0|] ==> (  p*bdv+   bdv \<up> 2=0) =
walther@60242:                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 0)/2) 
walther@60242:                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 0)/2))" and
t@42203:  (* d2_pqformula5_neg not need p^2 never less zero in R *)
walther@60242:   d2_pqformula6:         "[|0<=p \<up> 2 - 0|] ==> (  p*bdv+1*bdv \<up> 2=0) = 
walther@60242:                            ((bdv= (-1)*(p/2) + sqrt(p \<up> 2 - 0)/2) 
walther@60242:                           | (bdv= (-1)*(p/2) - sqrt(p \<up> 2 - 0)/2))" and
neuper@37906:   (* d2_pqformula6_neg not need p^2 never less zero in R *)
walther@60242:    d2_pqformula7:        "[|0<=1 - 0|] ==> (    bdv+   bdv \<up> 2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
neuper@52148:                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))" and
neuper@37906:   (* d2_pqformula7_neg not need, because 1<0 ==> False*)
walther@60242:   d2_pqformula8:        "[|0<=1 - 0|] ==> (    bdv+1*bdv \<up> 2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
neuper@52148:                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))" and
neuper@37906:   (* d2_pqformula8_neg not need, because 1<0 ==> False*)
neuper@37983:   d2_pqformula9:        "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> 
walther@60242:                            (q+    1*bdv \<up> 2=0) = ((bdv= 0 + sqrt(0 - 4*q)/2) 
neuper@52148:                                                 | (bdv= 0 - sqrt(0 - 4*q)/2))" and
neuper@37983:   d2_pqformula9_neg:
walther@60242:    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+    1*bdv \<up> 2=0) = False" and
neuper@37983:   d2_pqformula10:
walther@60242:    "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> (q+     bdv \<up> 2=0) = 
neuper@37906:            ((bdv= 0 + sqrt(0 - 4*q)/2) 
neuper@52148:           | (bdv= 0 - sqrt(0 - 4*q)/2))" and
neuper@37983:   d2_pqformula10_neg:
walther@60242:    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+     bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula1:
walther@60242:    "[|0<=b \<up> 2 - 4*a*c|] ==> (c + b*bdv+a*bdv \<up> 2=0) =
walther@60242:            ((bdv=( -b + sqrt(b \<up> 2 - 4*a*c))/(2*a)) 
walther@60242:           | (bdv=( -b - sqrt(b \<up> 2 - 4*a*c))/(2*a)))" and
neuper@37983:   d2_abcformula1_neg:
walther@60242:    "[|b \<up> 2 - 4*a*c<0|] ==> (c + b*bdv+a*bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula2:
walther@60242:    "[|0<=1 - 4*a*c|]     ==> (c+    bdv+a*bdv \<up> 2=0) = 
neuper@37906:            ((bdv=( -1 + sqrt(1 - 4*a*c))/(2*a)) 
neuper@52148:           | (bdv=( -1 - sqrt(1 - 4*a*c))/(2*a)))" and
neuper@37983:   d2_abcformula2_neg:
walther@60242:    "[|1 - 4*a*c<0|]     ==> (c+    bdv+a*bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula3:
walther@60242:    "[|0<=b \<up> 2 - 4*1*c|] ==> (c + b*bdv+  bdv \<up> 2=0) =
walther@60242:            ((bdv=( -b + sqrt(b \<up> 2 - 4*1*c))/(2*1)) 
walther@60242:           | (bdv=( -b - sqrt(b \<up> 2 - 4*1*c))/(2*1)))" and
neuper@37983:   d2_abcformula3_neg:
walther@60242:    "[|b \<up> 2 - 4*1*c<0|] ==> (c + b*bdv+  bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula4:
walther@60242:    "[|0<=1 - 4*1*c|] ==> (c +   bdv+  bdv \<up> 2=0) =
neuper@37906:            ((bdv=( -1 + sqrt(1 - 4*1*c))/(2*1)) 
neuper@52148:           | (bdv=( -1 - sqrt(1 - 4*1*c))/(2*1)))" and
neuper@37983:   d2_abcformula4_neg:
walther@60242:    "[|1 - 4*1*c<0|] ==> (c +   bdv+  bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula5:
walther@60242:    "[|Not(bdv occurs_in c); 0<=0 - 4*a*c|] ==> (c +  a*bdv \<up> 2=0) =
neuper@37906:            ((bdv=( 0 + sqrt(0 - 4*a*c))/(2*a)) 
neuper@52148:           | (bdv=( 0 - sqrt(0 - 4*a*c))/(2*a)))" and
neuper@37983:   d2_abcformula5_neg:
walther@60242:    "[|Not(bdv occurs_in c); 0 - 4*a*c<0|] ==> (c +  a*bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula6:
walther@60242:    "[|Not(bdv occurs_in c); 0<=0 - 4*1*c|]     ==> (c+    bdv \<up> 2=0) = 
neuper@37906:            ((bdv=( 0 + sqrt(0 - 4*1*c))/(2*1)) 
neuper@52148:           | (bdv=( 0 - sqrt(0 - 4*1*c))/(2*1)))" and
neuper@37983:   d2_abcformula6_neg:
walther@60242:    "[|Not(bdv occurs_in c); 0 - 4*1*c<0|]     ==> (c+    bdv \<up> 2=0) = False" and
neuper@37983:   d2_abcformula7:
walther@60242:    "[|0<=b \<up> 2 - 0|]     ==> (    b*bdv+a*bdv \<up> 2=0) = 
walther@60242:            ((bdv=( -b + sqrt(b \<up> 2 - 0))/(2*a)) 
walther@60242:           | (bdv=( -b - sqrt(b \<up> 2 - 0))/(2*a)))" and
neuper@37906:   (* d2_abcformula7_neg not need b^2 never less zero in R *)
neuper@37983:   d2_abcformula8:
walther@60242:    "[|0<=b \<up> 2 - 0|] ==> (    b*bdv+  bdv \<up> 2=0) =
walther@60242:            ((bdv=( -b + sqrt(b \<up> 2 - 0))/(2*1)) 
walther@60242:           | (bdv=( -b - sqrt(b \<up> 2 - 0))/(2*1)))" and
neuper@37906:   (* d2_abcformula8_neg not need b^2 never less zero in R *)
neuper@37983:   d2_abcformula9:
walther@60242:    "[|0<=1 - 0|]     ==> (      bdv+a*bdv \<up> 2=0) = 
neuper@37906:            ((bdv=( -1 + sqrt(1 - 0))/(2*a)) 
neuper@52148:           | (bdv=( -1 - sqrt(1 - 0))/(2*a)))" and
neuper@37906:   (* d2_abcformula9_neg not need, because 1<0 ==> False*)
neuper@37983:   d2_abcformula10:
walther@60242:    "[|0<=1 - 0|] ==> (      bdv+  bdv \<up> 2=0) =
neuper@37906:            ((bdv=( -1 + sqrt(1 - 0))/(2*1)) 
neuper@52148:           | (bdv=( -1 - sqrt(1 - 0))/(2*1)))" and
neuper@37906:   (* d2_abcformula10_neg not need, because 1<0 ==> False*)
neuper@37906: 
t@42203: 
neuper@37906: (* ---- degree 3 ----*)
neuper@37983:   d3_reduce_equation1:
walther@60242:   "(a*bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (a + b*bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation2:
walther@60242:   "(  bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (1 + b*bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation3:
walther@60242:   "(a*bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (a +   bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation4:
walther@60242:   "(  bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (1 +   bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation5:
walther@60242:   "(a*bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (a + b*bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation6:
walther@60242:   "(  bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 + b*bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation7:
walther@60242:   "(a*bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 +   bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation8:
walther@60242:   "(  bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (1 +   bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation9:
walther@60242:   "(a*bdv             + c*bdv \<up> 3=0) = (bdv=0 | (a         + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation10:
walther@60242:   "(  bdv             + c*bdv \<up> 3=0) = (bdv=0 | (1         + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation11:
walther@60242:   "(a*bdv             +   bdv \<up> 3=0) = (bdv=0 | (a         +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation12:
walther@60242:   "(  bdv             +   bdv \<up> 3=0) = (bdv=0 | (1         +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation13:
walther@60242:   "(        b*bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (    b*bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation14:
walther@60242:   "(          bdv \<up> 2 + c*bdv \<up> 3=0) = (bdv=0 | (      bdv + c*bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation15:
walther@60242:   "(        b*bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (    b*bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_reduce_equation16:
walther@60242:   "(          bdv \<up> 2 +   bdv \<up> 3=0) = (bdv=0 | (      bdv +   bdv \<up> 2=0))" and
neuper@37983:   d3_isolate_add1:
walther@60242:   "[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 3=0) = (b*bdv \<up> 3= (-1)*a)" and
neuper@37983:   d3_isolate_add2:
walther@60242:   "[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 3=0) = (  bdv \<up> 3= (-1)*a)" and
neuper@37983:   d3_isolate_div:
walther@60242:    "[|Not(b=0);Not(bdv occurs_in a)|] ==> (b*bdv \<up> 3=c) = (bdv \<up> 3=c/b)" and
neuper@37983:   d3_root_equation2:
walther@60242:   "(bdv \<up> 3=0) = (bdv=0)" and
neuper@37983:   d3_root_equation1:
walther@60242:   "(bdv \<up> 3=c) = (bdv = nroot 3 c)" and
neuper@37906: 
neuper@37906: (* ---- degree 4 ----*)
neuper@37906:  (* RL03.FIXME es wir nicht getestet ob u>0 *)
neuper@37989:  d4_sub_u1:
walther@60242:  "(c+b*bdv \<up> 2+a*bdv \<up> 4=0) =
walther@60242:    ((a*u \<up> 2+b*u+c=0) & (bdv \<up> 2=u))" and
neuper@37906: 
neuper@37906: (* ---- 7.3.02 von Termorder ---- *)
neuper@37906: 
neuper@52148:   bdv_collect_1:      "l * bdv + m * bdv = (l + m) * bdv" and
neuper@52148:   bdv_collect_2:      "bdv + m * bdv = (1 + m) * bdv" and
neuper@52148:   bdv_collect_3:      "l * bdv + bdv = (l + 1) * bdv" and
neuper@37906: 
neuper@37906: (*  bdv_collect_assoc0_1 "l * bdv + m * bdv + k = (l + m) * bdv + k"
neuper@37906:     bdv_collect_assoc0_2 "bdv + m * bdv + k = (1 + m) * bdv + k"
neuper@37906:     bdv_collect_assoc0_3 "l * bdv + bdv + k = (l + 1) * bdv + k"
neuper@37906: *)
neuper@52148:   bdv_collect_assoc1_1: "l * bdv + (m * bdv + k) = (l + m) * bdv + k" and
neuper@52148:   bdv_collect_assoc1_2: "bdv + (m * bdv + k) = (1 + m) * bdv + k" and
neuper@52148:   bdv_collect_assoc1_3: "l * bdv + (bdv + k) = (l + 1) * bdv + k" and
neuper@38030:                         
neuper@52148:   bdv_collect_assoc2_1: "k + l * bdv + m * bdv = k + (l + m) * bdv" and
neuper@52148:   bdv_collect_assoc2_2: "k + bdv + m * bdv = k + (1 + m) * bdv" and
neuper@52148:   bdv_collect_assoc2_3: "k + l * bdv + bdv = k + (l + 1) * bdv" and
neuper@37906: 
neuper@37906: 
walther@60242:   bdv_n_collect_1:     "l * bdv \<up> n + m * bdv \<up> n = (l + m) * bdv \<up> n" and
walther@60242:   bdv_n_collect_2:     " bdv \<up> n + m * bdv \<up> n = (1 + m) * bdv \<up> n" and
walther@60242:   bdv_n_collect_3:     "l * bdv \<up> n + bdv \<up> n = (l + 1) * bdv \<up> n" (*order!*) and
neuper@37906: 
neuper@38030:   bdv_n_collect_assoc1_1:
walther@60242:                       "l * bdv \<up> n + (m * bdv \<up> n + k) = (l + m) * bdv \<up> n + k" and
walther@60242:   bdv_n_collect_assoc1_2: "bdv \<up> n + (m * bdv \<up> n + k) = (1 + m) * bdv \<up> n + k" and
walther@60242:   bdv_n_collect_assoc1_3: "l * bdv \<up> n + (bdv \<up> n + k) = (l + 1) * bdv \<up> n + k" and
neuper@37906: 
walther@60242:   bdv_n_collect_assoc2_1: "k + l * bdv \<up> n + m * bdv \<up> n = k +(l + m) * bdv \<up> n" and
walther@60242:   bdv_n_collect_assoc2_2: "k + bdv \<up> n + m * bdv \<up> n = k + (1 + m) * bdv \<up> n" and
walther@60242:   bdv_n_collect_assoc2_3: "k + l * bdv \<up> n + bdv \<up> n = k + (l + 1) * bdv \<up> n" and
neuper@37906: 
neuper@37906: (*WN.14.3.03*)
neuper@52148:   real_minus_div:         "- (a / b) = (-1 * a) / b" and
neuper@38030:                           
neuper@52148:   separate_bdv:           "(a * bdv) / b = (a / b) * (bdv::real)" and
walther@60242:   separate_bdv_n:         "(a * bdv \<up> n) / b = (a / b) * bdv \<up> n" and
neuper@52148:   separate_1_bdv:         "bdv / b = (1 / b) * (bdv::real)" and
walther@60242:   separate_1_bdv_n:       "bdv \<up> n / b = (1 / b) * bdv \<up> n"
neuper@37906: 
wneuper@59472: ML \<open>
neuper@37972: val thy = @{theory};
neuper@37972: 
neuper@37954: (*-------------------------rulse-------------------------*)
neuper@37954: val PolyEq_prls = (*3.10.02:just the following order due to subterm evaluation*)
walther@59852:   Rule_Set.append_rules "PolyEq_prls" Rule_Set.empty 
walther@59878: 	     [Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
walther@59878: 	      Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches ""),
walther@59878: 	      Rule.Eval ("Prog_Expr.lhs", Prog_Expr.eval_lhs ""),
walther@59878: 	      Rule.Eval ("Prog_Expr.rhs", Prog_Expr.eval_rhs ""),
walther@59878: 	      Rule.Eval ("Poly.is'_expanded'_in", eval_is_expanded_in ""),
walther@59878: 	      Rule.Eval ("Poly.is'_poly'_in", eval_is_poly_in ""),
walther@59878: 	      Rule.Eval ("Poly.has'_degree'_in", eval_has_degree_in ""),    
walther@59878:               Rule.Eval ("Poly.is'_polyrat'_in", eval_is_polyrat_in ""),
walther@59878: 	      (*Rule.Eval ("Prog_Expr.occurs'_in", Prog_Expr.eval_occurs_in ""),   *) 
walther@59878: 	      (*Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_"),*)
walther@59878: 	      Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@59878:               Rule.Eval ("RootEq.is'_rootTerm'_in", eval_is_rootTerm_in ""),
walther@59878: 	      Rule.Eval ("RatEq.is'_ratequation'_in", eval_is_ratequation_in ""),
walther@59871: 	      Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
walther@59871: 	      Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false}),
walther@59871: 	      Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
walther@59871: 	      Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
walther@59871: 	      Rule.Thm ("or_true",ThmC.numerals_to_Free @{thm or_true}),
walther@59871: 	      Rule.Thm ("or_false",ThmC.numerals_to_Free @{thm or_false})
neuper@37954: 	       ];
neuper@37954: 
neuper@37954: val PolyEq_erls = 
walther@59852:     Rule_Set.merge "PolyEq_erls" LinEq_erls
walther@59852:     (Rule_Set.append_rules "ops_preds" calculate_Rational
walther@59878: 		[Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@59871: 		 Rule.Thm ("plus_leq", ThmC.numerals_to_Free @{thm plus_leq}),
walther@59871: 		 Rule.Thm ("minus_leq", ThmC.numerals_to_Free @{thm minus_leq}),
walther@59871: 		 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
walther@59871: 		 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
walther@59871: 		 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3})
neuper@37954: 		 ]);
neuper@37954: 
neuper@37954: val PolyEq_crls = 
walther@59852:     Rule_Set.merge "PolyEq_crls" LinEq_crls
walther@59852:     (Rule_Set.append_rules "ops_preds" calculate_Rational
walther@59878: 		[Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
walther@59871: 		 Rule.Thm ("plus_leq", ThmC.numerals_to_Free @{thm plus_leq}),
walther@59871: 		 Rule.Thm ("minus_leq", ThmC.numerals_to_Free @{thm minus_leq}),
walther@59871: 		 Rule.Thm ("rat_leq1", ThmC.numerals_to_Free @{thm rat_leq1}),
walther@59871: 		 Rule.Thm ("rat_leq2", ThmC.numerals_to_Free @{thm rat_leq2}),
walther@59871: 		 Rule.Thm ("rat_leq3", ThmC.numerals_to_Free @{thm rat_leq3})
neuper@37954: 		 ]);
neuper@37954: 
s1210629013@55444: val cancel_leading_coeff = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "cancel_leading_coeff", preconds = [], 
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
walther@59851:       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@37989:       rules = 
walther@59871:       [Rule.Thm ("cancel_leading_coeff1",ThmC.numerals_to_Free @{thm cancel_leading_coeff1}),
walther@59871:        Rule.Thm ("cancel_leading_coeff2",ThmC.numerals_to_Free @{thm cancel_leading_coeff2}),
walther@59871:        Rule.Thm ("cancel_leading_coeff3",ThmC.numerals_to_Free @{thm cancel_leading_coeff3}),
walther@59871:        Rule.Thm ("cancel_leading_coeff4",ThmC.numerals_to_Free @{thm cancel_leading_coeff4}),
walther@59871:        Rule.Thm ("cancel_leading_coeff5",ThmC.numerals_to_Free @{thm cancel_leading_coeff5}),
walther@59871:        Rule.Thm ("cancel_leading_coeff6",ThmC.numerals_to_Free @{thm cancel_leading_coeff6}),
walther@59871:        Rule.Thm ("cancel_leading_coeff7",ThmC.numerals_to_Free @{thm cancel_leading_coeff7}),
walther@59871:        Rule.Thm ("cancel_leading_coeff8",ThmC.numerals_to_Free @{thm cancel_leading_coeff8}),
walther@59871:        Rule.Thm ("cancel_leading_coeff9",ThmC.numerals_to_Free @{thm cancel_leading_coeff9}),
walther@59871:        Rule.Thm ("cancel_leading_coeff10",ThmC.numerals_to_Free @{thm cancel_leading_coeff10}),
walther@59871:        Rule.Thm ("cancel_leading_coeff11",ThmC.numerals_to_Free @{thm cancel_leading_coeff11}),
walther@59871:        Rule.Thm ("cancel_leading_coeff12",ThmC.numerals_to_Free @{thm cancel_leading_coeff12}),
walther@59871:        Rule.Thm ("cancel_leading_coeff13",ThmC.numerals_to_Free @{thm cancel_leading_coeff13})
walther@59878:        ],scr = Rule.Empty_Prog});
s1210629013@55444: 
walther@59618: val prep_rls' = Auto_Prog.prep_rls @{theory};
wneuper@59472: \<close>
wneuper@59472: ML\<open>
s1210629013@55444: val complete_square = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "complete_square", preconds = [], 
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
walther@59851:       erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [],  errpatts = [],
walther@59871:       rules = [Rule.Thm ("complete_square1",ThmC.numerals_to_Free @{thm complete_square1}),
walther@59871: 	       Rule.Thm ("complete_square2",ThmC.numerals_to_Free @{thm complete_square2}),
walther@59871: 	       Rule.Thm ("complete_square3",ThmC.numerals_to_Free @{thm complete_square3}),
walther@59871: 	       Rule.Thm ("complete_square4",ThmC.numerals_to_Free @{thm complete_square4}),
walther@59871: 	       Rule.Thm ("complete_square5",ThmC.numerals_to_Free @{thm complete_square5})
neuper@37954: 	       ],
walther@59878:       scr = Rule.Empty_Prog
wneuper@59406:       });
neuper@37954: 
s1210629013@55444: val polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "polyeq_simplify", preconds = [], 
neuper@37954:        rew_ord = ("termlessI",termlessI), 
neuper@37954:        erls = PolyEq_erls, 
walther@59851:        srls = Rule_Set.Empty, 
neuper@42451:        calc = [], errpatts = [],
walther@59871:        rules = [Rule.Thm  ("real_assoc_1",ThmC.numerals_to_Free @{thm real_assoc_1}),
walther@59871: 		Rule.Thm  ("real_assoc_2",ThmC.numerals_to_Free @{thm real_assoc_2}),
walther@59871: 		Rule.Thm  ("real_diff_minus",ThmC.numerals_to_Free @{thm real_diff_minus}),
walther@59871: 		Rule.Thm  ("real_unari_minus",ThmC.numerals_to_Free @{thm real_unari_minus}),
walther@59871: 		Rule.Thm  ("realpow_multI",ThmC.numerals_to_Free @{thm realpow_multI}),
walther@59878: 		Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
walther@59878: 		Rule.Eval ("Groups.minus_class.minus", (**)eval_binop "#sub_"),
walther@59878: 		Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
walther@59878: 		Rule.Eval ("Rings.divide_class.divide", Prog_Expr.eval_cancel "#divide_e"),
walther@59878: 		Rule.Eval ("NthRoot.sqrt", eval_sqrt "#sqrt_"),
walther@59878: 		Rule.Eval ("Prog_Expr.pow" , (**)eval_binop "#power_"),
wneuper@59416:                 Rule.Rls_ reduce_012
neuper@37954:                 ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
wneuper@59472: \<close>
wneuper@59472: setup \<open>KEStore_Elems.add_rlss 
neuper@52125:   [("cancel_leading_coeff", (Context.theory_name @{theory}, cancel_leading_coeff)), 
neuper@52125:   ("complete_square", (Context.theory_name @{theory}, complete_square)), 
neuper@52125:   ("PolyEq_erls", (Context.theory_name @{theory}, PolyEq_erls)), 
wneuper@59472:   ("polyeq_simplify", (Context.theory_name @{theory}, polyeq_simplify))]\<close>
wneuper@59472: ML\<open>
neuper@37954: 
neuper@37954: (* ------------- polySolve ------------------ *)
neuper@37954: (* -- d0 -- *)
neuper@37954: (*isolate the bound variable in an d0 equation; 'bdv' is a meta-constant*)
s1210629013@55444: val d0_polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d0_polyeq_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, 
neuper@42451:        calc = [], errpatts = [],
walther@59871:        rules = [Rule.Thm("d0_true",ThmC.numerals_to_Free @{thm d0_true}),
walther@59871: 		Rule.Thm("d0_false",ThmC.numerals_to_Free @{thm  d0_false})
neuper@37954: 		],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
neuper@37954: 
neuper@37954: (* -- d1 -- *)
neuper@37954: (*isolate the bound variable in an d1 equation; 'bdv' is a meta-constant*)
s1210629013@55444: val d1_polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d1_polyeq_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, 
neuper@42451:        calc = [], errpatts = [],
neuper@37954:        rules = [
walther@59871: 		Rule.Thm("d1_isolate_add1",ThmC.numerals_to_Free @{thm d1_isolate_add1}), 
neuper@37954: 		(* a+bx=0 -> bx=-a *)
walther@59871: 		Rule.Thm("d1_isolate_add2",ThmC.numerals_to_Free @{thm d1_isolate_add2}), 
neuper@37954: 		(* a+ x=0 ->  x=-a *)
walther@59871: 		Rule.Thm("d1_isolate_div",ThmC.numerals_to_Free @{thm d1_isolate_div})    
neuper@37954: 		(*   bx=c -> x=c/b *)  
neuper@37954: 		],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
neuper@37954: 
wneuper@59472: \<close>
wneuper@59472: subsection \<open>degree 2\<close>
wneuper@59472: ML\<open>
neuper@42394: (* isolate the bound variable in an d2 equation with bdv only;
neuper@42394:   "bdv" is a meta-constant substituted for the "x" below by isac's rewriter. *)
s1210629013@55444: val d2_polyeq_bdv_only_simplify = prep_rls'(
walther@59857:   Rule_Def.Repeat {id = "d2_polyeq_bdv_only_simplify", preconds = [], rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
walther@59851:     erls = PolyEq_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@42394:     rules =
walther@59871:       [Rule.Thm ("d2_prescind1", ThmC.numerals_to_Free @{thm d2_prescind1}), (*   ax+bx^2=0 -> x(a+bx)=0 *)
walther@59871:        Rule.Thm ("d2_prescind2", ThmC.numerals_to_Free @{thm d2_prescind2}), (*   ax+ x^2=0 -> x(a+ x)=0 *)
walther@59871:        Rule.Thm ("d2_prescind3", ThmC.numerals_to_Free @{thm d2_prescind3}), (*    x+bx^2=0 -> x(1+bx)=0 *)
walther@59871:        Rule.Thm ("d2_prescind4", ThmC.numerals_to_Free @{thm d2_prescind4}), (*    x+ x^2=0 -> x(1+ x)=0 *)
walther@59871:        Rule.Thm ("d2_sqrt_equation1", ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),    (* x^2=c   -> x=+-sqrt(c) *)
walther@59871:        Rule.Thm ("d2_sqrt_equation1_neg", ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}), (* [0<c] x^2=c  -> []*)
walther@59871:        Rule.Thm ("d2_sqrt_equation2", ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),    (*  x^2=0 ->    x=0       *)
walther@59871:        Rule.Thm ("d2_reduce_equation1", ThmC.numerals_to_Free @{thm d2_reduce_equation1}),(* x(a+bx)=0 -> x=0 |a+bx=0*)
walther@59871:        Rule.Thm ("d2_reduce_equation2", ThmC.numerals_to_Free @{thm d2_reduce_equation2}),(* x(a+ x)=0 -> x=0 |a+ x=0*)
walther@59871:        Rule.Thm ("d2_isolate_div", ThmC.numerals_to_Free @{thm d2_isolate_div})           (* bx^2=c -> x^2=c/b      *)
neuper@42394:        ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: (* isolate the bound variable in an d2 equation with sqrt only; 
neuper@37954:    'bdv' is a meta-constant*)
s1210629013@55444: val d2_polyeq_sq_only_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d2_polyeq_sq_only_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, 
neuper@42451:        calc = [], errpatts = [],
walther@59997:        (*asm_thm = [("d2_sqrt_equation1", ""),("d2_sqrt_equation1_neg", ""),
walther@59997:                   ("d2_isolate_div", "")],*)
walther@59871:        rules = [Rule.Thm("d2_isolate_add1",ThmC.numerals_to_Free @{thm d2_isolate_add1}),
neuper@37954:                 (* a+   bx^2=0 -> bx^2=(-1)a*)
walther@59871: 		Rule.Thm("d2_isolate_add2",ThmC.numerals_to_Free @{thm d2_isolate_add2}),
neuper@37954:                 (* a+    x^2=0 ->  x^2=(-1)a*)
walther@59871: 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
neuper@37954:                 (*  x^2=0 ->    x=0    *)
walther@59871: 		Rule.Thm("d2_sqrt_equation1",ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),
neuper@37954:                 (* x^2=c   -> x=+-sqrt(c)*)
walther@59871: 		Rule.Thm("d2_sqrt_equation1_neg",ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}),
neuper@37954:                 (* [c<0] x^2=c  -> x=[] *)
walther@59871: 		Rule.Thm("d2_isolate_div",ThmC.numerals_to_Free @{thm d2_isolate_div})
neuper@37954:                  (* bx^2=c -> x^2=c/b*)
neuper@37954: 		],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: (* isolate the bound variable in an d2 equation with pqFormula;
neuper@37954:    'bdv' is a meta-constant*)
s1210629013@55444: val d2_polyeq_pqFormula_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d2_polyeq_pqFormula_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871:        rules = [Rule.Thm("d2_pqformula1",ThmC.numerals_to_Free @{thm d2_pqformula1}),
neuper@37954:                 (* q+px+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula1_neg",ThmC.numerals_to_Free @{thm d2_pqformula1_neg}),
neuper@37954:                 (* q+px+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula2",ThmC.numerals_to_Free @{thm d2_pqformula2}), 
neuper@37954:                 (* q+px+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula2_neg",ThmC.numerals_to_Free @{thm d2_pqformula2_neg}),
neuper@37954:                 (* q+px+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula3",ThmC.numerals_to_Free @{thm d2_pqformula3}),
neuper@37954:                 (* q+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula3_neg",ThmC.numerals_to_Free @{thm d2_pqformula3_neg}), 
neuper@37954:                 (* q+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula4",ThmC.numerals_to_Free @{thm d2_pqformula4}),
neuper@37954:                 (* q+ x+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula4_neg",ThmC.numerals_to_Free @{thm d2_pqformula4_neg}),
neuper@37954:                 (* q+ x+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula5",ThmC.numerals_to_Free @{thm d2_pqformula5}),
neuper@37954:                 (*   qx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula6",ThmC.numerals_to_Free @{thm d2_pqformula6}),
neuper@37954:                 (*   qx+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula7",ThmC.numerals_to_Free @{thm d2_pqformula7}),
neuper@37954:                 (*    x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula8",ThmC.numerals_to_Free @{thm d2_pqformula8}),
neuper@37954:                 (*    x+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula9",ThmC.numerals_to_Free @{thm d2_pqformula9}),
neuper@37954:                 (* q   +1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula9_neg",ThmC.numerals_to_Free @{thm d2_pqformula9_neg}),
neuper@37954:                 (* q   +1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula10",ThmC.numerals_to_Free @{thm d2_pqformula10}),
neuper@37954:                 (* q   + x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula10_neg",ThmC.numerals_to_Free @{thm d2_pqformula10_neg}),
neuper@37954:                 (* q   + x^2=0 *)
walther@59871: 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
neuper@37954:                 (*       x^2=0 *)
walther@59871: 		Rule.Thm("d2_sqrt_equation3",ThmC.numerals_to_Free @{thm d2_sqrt_equation3})
neuper@37954:                (*      1x^2=0 *)
walther@59878: 	       ],scr = Rule.Empty_Prog
wneuper@59406:        });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: (* isolate the bound variable in an d2 equation with abcFormula; 
neuper@37954:    'bdv' is a meta-constant*)
s1210629013@55444: val d2_polyeq_abcFormula_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d2_polyeq_abcFormula_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871:        rules = [Rule.Thm("d2_abcformula1",ThmC.numerals_to_Free @{thm d2_abcformula1}),
neuper@37954:                 (*c+bx+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula1_neg",ThmC.numerals_to_Free @{thm d2_abcformula1_neg}),
neuper@37954:                 (*c+bx+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula2",ThmC.numerals_to_Free @{thm d2_abcformula2}),
neuper@37954:                 (*c+ x+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula2_neg",ThmC.numerals_to_Free @{thm d2_abcformula2_neg}),
neuper@37954:                 (*c+ x+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula3",ThmC.numerals_to_Free @{thm d2_abcformula3}), 
neuper@37954:                 (*c+bx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula3_neg",ThmC.numerals_to_Free @{thm d2_abcformula3_neg}),
neuper@37954:                 (*c+bx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula4",ThmC.numerals_to_Free @{thm d2_abcformula4}),
neuper@37954:                 (*c+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula4_neg",ThmC.numerals_to_Free @{thm d2_abcformula4_neg}),
neuper@37954:                 (*c+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula5",ThmC.numerals_to_Free @{thm d2_abcformula5}),
neuper@37954:                 (*c+   cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula5_neg",ThmC.numerals_to_Free @{thm d2_abcformula5_neg}),
neuper@37954:                 (*c+   cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula6",ThmC.numerals_to_Free @{thm d2_abcformula6}),
neuper@37954:                 (*c+    x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula6_neg",ThmC.numerals_to_Free @{thm d2_abcformula6_neg}),
neuper@37954:                 (*c+    x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula7",ThmC.numerals_to_Free @{thm d2_abcformula7}),
neuper@37954:                 (*  bx+ax^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula8",ThmC.numerals_to_Free @{thm d2_abcformula8}),
neuper@37954:                 (*  bx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula9",ThmC.numerals_to_Free @{thm d2_abcformula9}),
neuper@37954:                 (*   x+ax^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula10",ThmC.numerals_to_Free @{thm d2_abcformula10}),
neuper@37954:                 (*   x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
neuper@37954:                 (*      x^2=0 *)  
walther@59871: 		Rule.Thm("d2_sqrt_equation3",ThmC.numerals_to_Free @{thm d2_sqrt_equation3})
neuper@37954:                (*     bx^2=0 *)  
neuper@37954: 	       ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:        });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: 
neuper@37954: (* isolate the bound variable in an d2 equation; 
neuper@37954:    'bdv' is a meta-constant*)
s1210629013@55444: val d2_polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d2_polyeq_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, calc = [], errpatts = [],
walther@59871:        rules = [Rule.Thm("d2_pqformula1",ThmC.numerals_to_Free @{thm d2_pqformula1}),
neuper@37954:                 (* p+qx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula1_neg",ThmC.numerals_to_Free @{thm d2_pqformula1_neg}),
neuper@37954:                 (* p+qx+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula2",ThmC.numerals_to_Free @{thm d2_pqformula2}),
neuper@37954:                 (* p+qx+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula2_neg",ThmC.numerals_to_Free @{thm d2_pqformula2_neg}),
neuper@37954:                 (* p+qx+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula3",ThmC.numerals_to_Free @{thm d2_pqformula3}),
neuper@37954:                 (* p+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula3_neg",ThmC.numerals_to_Free @{thm d2_pqformula3_neg}),
neuper@37954:                 (* p+ x+ x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula4",ThmC.numerals_to_Free @{thm d2_pqformula4}), 
neuper@37954:                 (* p+ x+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_pqformula4_neg",ThmC.numerals_to_Free @{thm d2_pqformula4_neg}),
neuper@37954:                 (* p+ x+1x^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula1",ThmC.numerals_to_Free @{thm d2_abcformula1}),
neuper@37954:                 (* c+bx+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula1_neg",ThmC.numerals_to_Free @{thm d2_abcformula1_neg}),
neuper@37954:                 (* c+bx+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula2",ThmC.numerals_to_Free @{thm d2_abcformula2}),
neuper@37954:                 (* c+ x+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_abcformula2_neg",ThmC.numerals_to_Free @{thm d2_abcformula2_neg}),
neuper@37954:                 (* c+ x+cx^2=0 *)
walther@59871: 		Rule.Thm("d2_prescind1",ThmC.numerals_to_Free @{thm d2_prescind1}),
neuper@37954:                 (*   ax+bx^2=0 -> x(a+bx)=0 *)
walther@59871: 		Rule.Thm("d2_prescind2",ThmC.numerals_to_Free @{thm d2_prescind2}),
neuper@37954:                 (*   ax+ x^2=0 -> x(a+ x)=0 *)
walther@59871: 		Rule.Thm("d2_prescind3",ThmC.numerals_to_Free @{thm d2_prescind3}),
neuper@37954:                 (*    x+bx^2=0 -> x(1+bx)=0 *)
walther@59871: 		Rule.Thm("d2_prescind4",ThmC.numerals_to_Free @{thm d2_prescind4}),
neuper@37954:                 (*    x+ x^2=0 -> x(1+ x)=0 *)
walther@59871: 		Rule.Thm("d2_isolate_add1",ThmC.numerals_to_Free @{thm d2_isolate_add1}),
neuper@37954:                 (* a+   bx^2=0 -> bx^2=(-1)a*)
walther@59871: 		Rule.Thm("d2_isolate_add2",ThmC.numerals_to_Free @{thm d2_isolate_add2}),
neuper@37954:                 (* a+    x^2=0 ->  x^2=(-1)a*)
walther@59871: 		Rule.Thm("d2_sqrt_equation1",ThmC.numerals_to_Free @{thm d2_sqrt_equation1}),
neuper@37954:                 (* x^2=c   -> x=+-sqrt(c)*)
walther@59871: 		Rule.Thm("d2_sqrt_equation1_neg",ThmC.numerals_to_Free @{thm d2_sqrt_equation1_neg}),
neuper@37954:                 (* [c<0] x^2=c   -> x=[]*)
walther@59871: 		Rule.Thm("d2_sqrt_equation2",ThmC.numerals_to_Free @{thm d2_sqrt_equation2}),
neuper@37954:                 (*  x^2=0 ->    x=0    *)
walther@59871: 		Rule.Thm("d2_reduce_equation1",ThmC.numerals_to_Free @{thm d2_reduce_equation1}),
neuper@37954:                 (* x(a+bx)=0 -> x=0 | a+bx=0*)
walther@59871: 		Rule.Thm("d2_reduce_equation2",ThmC.numerals_to_Free @{thm d2_reduce_equation2}),
neuper@37954:                 (* x(a+ x)=0 -> x=0 | a+ x=0*)
walther@59871: 		Rule.Thm("d2_isolate_div",ThmC.numerals_to_Free @{thm d2_isolate_div})
neuper@37954:                (* bx^2=c -> x^2=c/b*)
neuper@37954: 	       ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:       });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: 
neuper@37954: (* -- d3 -- *)
neuper@37954: (* isolate the bound variable in an d3 equation; 'bdv' is a meta-constant *)
s1210629013@55444: val d3_polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d3_polyeq_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@37954:        rules = 
walther@59871:        [Rule.Thm("d3_reduce_equation1",ThmC.numerals_to_Free @{thm d3_reduce_equation1}),
walther@60242: 	(*a*bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (a + b*bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation2",ThmC.numerals_to_Free @{thm d3_reduce_equation2}),
walther@60242: 	(*  bdv + b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (1 + b*bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation3",ThmC.numerals_to_Free @{thm d3_reduce_equation3}),
walther@60242: 	(*a*bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (a +   bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation4",ThmC.numerals_to_Free @{thm d3_reduce_equation4}),
walther@60242: 	(*  bdv +   bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (1 +   bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation5",ThmC.numerals_to_Free @{thm d3_reduce_equation5}),
walther@60242: 	(*a*bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (a + b*bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation6",ThmC.numerals_to_Free @{thm d3_reduce_equation6}),
walther@60242: 	(*  bdv + b*bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:         (bdv=0 | (1 + b*bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation7",ThmC.numerals_to_Free @{thm d3_reduce_equation7}),
walther@60242: 	     (*a*bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation8",ThmC.numerals_to_Free @{thm d3_reduce_equation8}),
walther@60242: 	     (*  bdv +   bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (1 +   bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation9",ThmC.numerals_to_Free @{thm d3_reduce_equation9}),
walther@60242: 	     (*a*bdv             + c*bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (a         + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation10",ThmC.numerals_to_Free @{thm d3_reduce_equation10}),
walther@60242: 	     (*  bdv             + c*bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (1         + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation11",ThmC.numerals_to_Free @{thm d3_reduce_equation11}),
walther@60242: 	     (*a*bdv             +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (a         +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation12",ThmC.numerals_to_Free @{thm d3_reduce_equation12}),
walther@60242: 	     (*  bdv             +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (1         +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation13",ThmC.numerals_to_Free @{thm d3_reduce_equation13}),
walther@60242: 	     (*        b*bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (    b*bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation14",ThmC.numerals_to_Free @{thm d3_reduce_equation14}),
walther@60242: 	     (*          bdv \<up> 2 + c*bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (      bdv + c*bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation15",ThmC.numerals_to_Free @{thm d3_reduce_equation15}),
walther@60242: 	     (*        b*bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (    b*bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_reduce_equation16",ThmC.numerals_to_Free @{thm d3_reduce_equation16}),
walther@60242: 	     (*          bdv \<up> 2 +   bdv \<up> 3=0) = 
walther@60242:              (bdv=0 | (      bdv +   bdv \<up> 2=0)*)
walther@59871: 	Rule.Thm("d3_isolate_add1",ThmC.numerals_to_Free @{thm d3_isolate_add1}),
walther@60242: 	     (*[|Not(bdv occurs_in a)|] ==> (a + b*bdv \<up> 3=0) = 
walther@60242:               (bdv=0 | (b*bdv \<up> 3=a)*)
walther@59871: 	Rule.Thm("d3_isolate_add2",ThmC.numerals_to_Free @{thm d3_isolate_add2}),
walther@60242:              (*[|Not(bdv occurs_in a)|] ==> (a +   bdv \<up> 3=0) = 
walther@60242:               (bdv=0 | (  bdv \<up> 3=a)*)
walther@59871: 	Rule.Thm("d3_isolate_div",ThmC.numerals_to_Free @{thm d3_isolate_div}),
walther@60242:         (*[|Not(b=0)|] ==> (b*bdv \<up> 3=c) = (bdv \<up> 3=c/b*)
walther@59871:         Rule.Thm("d3_root_equation2",ThmC.numerals_to_Free @{thm d3_root_equation2}),
walther@60242:         (*(bdv \<up> 3=0) = (bdv=0) *)
walther@59871: 	Rule.Thm("d3_root_equation1",ThmC.numerals_to_Free @{thm d3_root_equation1})
walther@60242:        (*bdv \<up> 3=c) = (bdv = nroot 3 c*)
neuper@37954:        ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:       });
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: 
neuper@37954: (* -- d4 -- *)
neuper@37954: (*isolate the bound variable in an d4 equation; 'bdv' is a meta-constant*)
s1210629013@55444: val d4_polyeq_simplify = prep_rls'(
walther@59851:   Rule_Def.Repeat {id = "d4_polyeq_simplify", preconds = [],
walther@59857:        rew_ord = ("e_rew_ord",Rewrite_Ord.e_rew_ord), erls = PolyEq_erls,
walther@59851:        srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@37954:        rules = 
walther@59871:        [Rule.Thm("d4_sub_u1",ThmC.numerals_to_Free @{thm d4_sub_u1})  
neuper@37954:        (* ax^4+bx^2+c=0 -> x=+-sqrt(ax^2+bx^+c) *)
neuper@37954:        ],
walther@59878:        scr = Rule.Empty_Prog
wneuper@59406:       });
wneuper@59472: \<close>
wneuper@59472: setup \<open>KEStore_Elems.add_rlss 
neuper@52125:   [("d0_polyeq_simplify", (Context.theory_name @{theory}, d0_polyeq_simplify)), 
neuper@52125:   ("d1_polyeq_simplify", (Context.theory_name @{theory}, d1_polyeq_simplify)), 
neuper@52125:   ("d2_polyeq_simplify", (Context.theory_name @{theory}, d2_polyeq_simplify)), 
neuper@52125:   ("d2_polyeq_bdv_only_simplify", (Context.theory_name @{theory}, d2_polyeq_bdv_only_simplify)), 
neuper@52125:   ("d2_polyeq_sq_only_simplify", (Context.theory_name @{theory}, d2_polyeq_sq_only_simplify)),
neuper@52125: 
neuper@52125:   ("d2_polyeq_pqFormula_simplify",
neuper@52125:     (Context.theory_name @{theory}, d2_polyeq_pqFormula_simplify)), 
neuper@52125:   ("d2_polyeq_abcFormula_simplify",
neuper@52125:     (Context.theory_name @{theory}, d2_polyeq_abcFormula_simplify)), 
neuper@52125:   ("d3_polyeq_simplify", (Context.theory_name @{theory}, d3_polyeq_simplify)), 
wneuper@59472:   ("d4_polyeq_simplify", (Context.theory_name @{theory}, d4_polyeq_simplify))]\<close>
walther@60258: 
wneuper@59472: setup \<open>KEStore_Elems.add_pbts
walther@59973:   [(Problem.prep_input thy "pbl_equ_univ_poly" [] Problem.id_empty
walther@59997:       (["polynomial", "univariate", "equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where" ,["~((e_e::bool) is_ratequation_in (v_v::real))",
s1210629013@55339: 	          "~((lhs e_e) is_rootTerm_in (v_v::real))",
s1210629013@55339: 	          "~((rhs e_e) is_rootTerm_in (v_v::real))"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [])),
s1210629013@55339:     (*--- d0 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg0" [] Problem.id_empty
walther@59997:       (["degree_0", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where" ,["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_poly_in v_v",
s1210629013@55339: 	          "((lhs e_e) has_degree_in v_v ) = 0"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d0_polyeq_equation"]])),
s1210629013@55339:     (*--- d1 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg1" [] Problem.id_empty
walther@59997:       (["degree_1", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where" ,["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_poly_in v_v",
s1210629013@55339: 	          "((lhs e_e) has_degree_in v_v ) = 1"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d1_polyeq_equation"]])),
s1210629013@55339:     (*--- d2 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg2" [] Problem.id_empty
walther@59997:       (["degree_2", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where" ,["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_poly_in v_v ",
s1210629013@55339: 	          "((lhs e_e) has_degree_in v_v ) = 2"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_equation"]])),
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg2_sqonly" [] Problem.id_empty
walther@59997:       (["sq_only", "degree_2", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
walther@60242:           ("#Where" ,["matches ( ?a +    ?v_ \<up> 2 = 0) e_e | " ^
walther@60242: 	          "matches ( ?a + ?b*?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (         ?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (      ?b*?v_ \<up> 2 = 0) e_e" ,
walther@60242:             "Not (matches (?a +    ?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (?a + ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (?a +    ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (?a + ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (        ?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (     ?b*?v_ +    ?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (        ?v_ + ?c*?v_ \<up> 2 = 0) e_e) &" ^
walther@60242:             "Not (matches (     ?b*?v_ + ?c*?v_ \<up> 2 = 0) e_e)"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339:         PolyEq_prls, SOME "solve (e_e::bool, v_v)",
walther@59997:         [["PolyEq", "solve_d2_polyeq_sqonly_equation"]])),
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg2_bdvonly" [] Problem.id_empty
walther@59997:       (["bdv_only", "degree_2", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
walther@60242:           ("#Where", ["matches (?a*?v_ +    ?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (   ?v_ +    ?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (   ?v_ + ?b*?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (?a*?v_ + ?b*?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (            ?v_ \<up> 2 = 0) e_e | " ^
walther@60242:             "matches (         ?b*?v_ \<up> 2 = 0) e_e "]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
s1210629013@55339:         PolyEq_prls, SOME "solve (e_e::bool, v_v)",
walther@59997:         [["PolyEq", "solve_d2_polyeq_bdvonly_equation"]])),
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg2_pq" [] Problem.id_empty
walther@59997:       (["pqFormula", "degree_2", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
walther@60242:           ("#Where", ["matches (?a + 1*?v_ \<up> 2 = 0) e_e | " ^
walther@60242: 	          "matches (?a +   ?v_ \<up> 2 = 0) e_e"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_pq_equation"]])),
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg2_abc" [] Problem.id_empty
walther@59997:       (["abcFormula", "degree_2", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
walther@60242:           ("#Where", ["matches (?a +    ?v_ \<up> 2 = 0) e_e | " ^
walther@60242: 	          "matches (?a + ?b*?v_ \<up> 2 = 0) e_e"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d2_polyeq_abc_equation"]])),
s1210629013@55339:     (*--- d3 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg3" [] Problem.id_empty
walther@59997:       (["degree_3", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where", ["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_poly_in v_v ",
s1210629013@55339: 	          "((lhs e_e) has_degree_in v_v) = 3"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "solve_d3_polyeq_equation"]])),
s1210629013@55339:     (*--- d4 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_deg4" [] Problem.id_empty
walther@59997:       (["degree_4", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where", ["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_poly_in v_v ",
s1210629013@55339: 	          "((lhs e_e) has_degree_in v_v) = 4"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59997:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [(*["PolyEq", "solve_d4_polyeq_equation"]*)])),
wneuper@59370:     (*--- normalise ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_poly_norm" [] Problem.id_empty
walther@59997:       (["normalise", "polynomial", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where", ["(Not((matches (?a = 0 ) e_e ))) |" ^
s1210629013@55339: 	          "(Not(((lhs e_e) is_poly_in v_v)))"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59842:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "normalise_poly"]])),
s1210629013@55339:     (*-------------------------expanded-----------------------*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_expand" [] Problem.id_empty
walther@59997:       (["expanded", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where", ["matches (?a = 0) e_e",
s1210629013@55339: 	          "(lhs e_e) is_expanded_in v_v "]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
s1210629013@55339:         PolyEq_prls, SOME "solve (e_e::bool, v_v)", [])),
s1210629013@55339:     (*--- d2 ---*)
walther@59973:     (Problem.prep_input thy "pbl_equ_univ_expand_deg2" [] Problem.id_empty
walther@59997:       (["degree_2", "expanded", "univariate", "equation"],
walther@59997:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where", ["((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55339:           ("#Find", ["solutions v_v'i'"])],
walther@59997:          PolyEq_prls, SOME "solve (e_e::bool, v_v)", [["PolyEq", "complete_square"]]))]\<close>
neuper@37954: 
wneuper@59472: text \<open>"-------------------------methods-----------------------"\<close>
wneuper@59472: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq" [] MethodC.id_empty
s1210629013@55373:       (["PolyEq"], [],
walther@59852:         {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
s1210629013@55373:           crls=PolyEq_crls, errpats = [], nrls = norm_Rational},
wneuper@59545:         @{thm refl})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) normalize_poly_eq :: "bool \<Rightarrow> real \<Rightarrow> bool"
wneuper@59504:   where
walther@59635: "normalize_poly_eq e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite ''all_left'')) #>
walther@59637:       (Try (Repeat (Rewrite ''makex1_x''))) #>
walther@59637:       (Try (Repeat (Rewrite_Set ''expand_binoms''))) #>
walther@59637:       (Try (Repeat (Rewrite_Set_Inst [(''bdv'', v_v)] ''make_ratpoly_in''))) #>
walther@59635:       (Try (Repeat (Rewrite_Set ''polyeq_simplify''))) ) e_e
walther@59635:   in
walther@59635:     SubProblem (''PolyEq'', [''polynomial'', ''univariate'', ''equation''], [''no_met''])
wneuper@59504:       [BOOL e_e, REAL v_v])"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_norm" [] MethodC.id_empty
walther@59842:       (["PolyEq", "normalise_poly"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
walther@59842:           ("#Where" ,["(Not((matches (?a = 0 ) e_e ))) | (Not(((lhs e_e) is_poly_in v_v)))"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls, calc=[],
s1210629013@55373:           crls=PolyEq_crls, errpats = [], nrls = norm_Rational},
wneuper@59551:         @{thm normalize_poly_eq.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504:   where
walther@59635: "solve_poly_equ e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d0_polyeq_simplify'')) e_e   
walther@59635:   in
walther@59635:     Or_to_List e_e)"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d0" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d0_polyeq_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 0"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_eq1 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635:   where
walther@59635: "solve_poly_eq1 e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d1_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #> 
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
walther@59635:     L_L = Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d1" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d1_polyeq_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 1"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_eq1.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ2 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504:   where
walther@59635: "solve_poly_equ2 e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d1_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
walther@59635:     L_L =  Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d22" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d2_polyeq_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ2.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ0 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635:   where
walther@59635: "solve_poly_equ0 e_e v_v = (
walther@59635:   let
walther@59635:      e_e = (
walther@59637:        (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_bdv_only_simplify'')) #>
walther@59637:        (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59637:        (Try (Rewrite_Set_Inst [(''bdv'',v_v::real)] ''d1_polyeq_simplify'')) #>
walther@59637:        (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:        (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
wneuper@59504:      L_L = Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d2_bdvonly" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d2_polyeq_bdvonly_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ0.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ_sqrt :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504:   where
walther@59635: "solve_poly_equ_sqrt e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_sq_only_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
wneuper@59504:     L_L = Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d2_sqonly" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d2_polyeq_sqonly_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ_sqrt.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ_pq :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635:   where
walther@59635: "solve_poly_equ_pq e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_pqFormula_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
walther@59635:     L_L = Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d2_pq" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d2_polyeq_pq_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ_pq.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ_abc :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504:   where
walther@59635: "solve_poly_equ_abc e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_abcFormula_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized'')) ) e_e;
walther@59635:     L_L = Or_to_List e_e
wneuper@59504:   in Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d2_abc" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d2_polyeq_abc_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls,srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ_abc.simps})]
wneuper@59473: \<close>
wneuper@59545: 
wneuper@59504: partial_function (tailrec) solve_poly_equ3 :: "bool \<Rightarrow> real \<Rightarrow> bool list"
walther@59635:   where
walther@59635: "solve_poly_equ3 e_e v_v = (
walther@59635:   let
walther@59635:     e_e = (
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d3_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''d2_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set_Inst [(''bdv'',v_v)] ''d1_polyeq_simplify'')) #>
walther@59637:       (Try (Rewrite_Set ''polyeq_simplify'')) #>
walther@59635:       (Try (Rewrite_Set ''norm_Rational_parenthesized''))) e_e;
walther@59635:     L_L = Or_to_List e_e
walther@59635:   in
walther@59635:     Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_d3" [] MethodC.id_empty
walther@59997:       (["PolyEq", "solve_d3_polyeq_equation"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["(lhs e_e) is_poly_in v_v ", "((lhs e_e) has_degree_in v_v) = 3"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI", rls'=PolyEq_erls, srls=Rule_Set.empty, prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_poly_equ3.simps})]
wneuper@59473: \<close>
wneuper@59370:     (*.solves all expanded (ie. normalised) terms of degree 2.*) 
s1210629013@55373:     (*Oct.02 restriction: 'eval_true 0 =< discriminant' ony for integer values
s1210629013@55373:       by 'PolyEq_erls'; restricted until Float.thy is implemented*)
wneuper@59504: partial_function (tailrec) solve_by_completing_square :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504:   where
walther@59635: "solve_by_completing_square e_e v_v = (
walther@59635:   let e_e = (
walther@59637:     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''cancel_leading_coeff'')) #>
walther@59637:     (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''complete_square'')) #>
walther@59637:     (Try (Rewrite ''square_explicit1'')) #>
walther@59637:     (Try (Rewrite ''square_explicit2'')) #>
walther@59637:     (Rewrite ''root_plus_minus'') #>
walther@59637:     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit1''))) #>
walther@59637:     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit2''))) #>
walther@59637:     (Try (Repeat (Rewrite_Inst [(''bdv'', v_v)] ''bdv_explicit3''))) #>
walther@59637:     (Try (Rewrite_Set ''calculate_RootRat'')) #>
walther@59635:     (Try (Repeat (Calculate ''SQRT'')))) e_e
walther@59635:   in
walther@59635:     Or_to_List e_e)"
wneuper@59473: setup \<open>KEStore_Elems.add_mets
walther@60154:     [MethodC.prep_input thy "met_polyeq_complsq" [] MethodC.id_empty
walther@59997:       (["PolyEq", "complete_square"],
walther@59997:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where" ,["matches (?a = 0) e_e", "((lhs e_e) has_degree_in v_v) = 2"]),
s1210629013@55373:           ("#Find"  ,["solutions v_v'i'"])],
walther@59852:         {rew_ord'="termlessI",rls'=PolyEq_erls,srls=Rule_Set.empty,prls=PolyEq_prls,
s1210629013@55373:           calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))], crls=PolyEq_crls, errpats = [],
s1210629013@55373:           nrls = norm_Rational},
wneuper@59551:         @{thm solve_by_completing_square.simps})]
wneuper@59472: \<close>
s1210629013@55373: 
wneuper@59472: ML\<open>
neuper@37954: 
neuper@37954: (* termorder hacked by MG *)
neuper@37954: local (*. for make_polynomial_in .*)
neuper@37954: 
neuper@37954: open Term;  (* for type order = EQUAL | LESS | GREATER *)
neuper@37954: 
neuper@37954: fun pr_ord EQUAL = "EQUAL"
neuper@37954:   | pr_ord LESS  = "LESS"
neuper@37954:   | pr_ord GREATER = "GREATER";
neuper@37954: 
walther@60263: fun dest_hd' _ (Const (a, T)) = (((a, 0), T), 0)
neuper@37954:   | dest_hd' x (t as Free (a, T)) =
neuper@37954:     if x = t then ((("|||||||||||||", 0), T), 0)                        (*WN*)
neuper@37954:     else (((a, 0), T), 1)
walther@60263:   | dest_hd' _ (Var v) = (v, 2)
walther@60263:   | dest_hd' _ (Bound i) = ((("", i), dummyT), 3)
walther@60263:   | dest_hd' _ (Abs (_, T, _)) = ((("", 0), T), 4)
walther@60263:   | dest_hd' _ _ = raise ERROR "dest_hd': uncovered case in fun.def.";
neuper@37954: 
walther@59603: fun size_of_term' x (Const ("Prog_Expr.pow",_) $ Free (var,_) $ Free (pot,_)) =
neuper@37954:     (case x of                                                          (*WN*)
neuper@37954: 	    (Free (xstr,_)) => 
walther@59875: 		(if xstr = var then 1000*(the (TermC.int_opt_of_string pot)) else 3)
walther@59962: 	  | _ => raise ERROR ("size_of_term' called with subst = "^
walther@59868: 			      (UnparseC.term x)))
neuper@37954:   | size_of_term' x (Free (subst,_)) =
neuper@37954:     (case x of
neuper@37954: 	    (Free (xstr,_)) => (if xstr = subst then 1000 else 1)
walther@59962: 	  | _ => raise ERROR ("size_of_term' called with subst = "^
walther@59868: 			  (UnparseC.term x)))
neuper@37954:   | size_of_term' x (Abs (_,_,body)) = 1 + size_of_term' x body
neuper@37954:   | size_of_term' x (f$t) = size_of_term' x f  +  size_of_term' x t
walther@60263:   | size_of_term' _ _ = 1;
neuper@37954: 
neuper@37989: fun term_ord' x pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
neuper@52070:     (case term_ord' x pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
neuper@37989:   | term_ord' x pr thy (t, u) =
neuper@52070:     (if pr
neuper@52070:      then 
neuper@52070:        let
neuper@52070:          val (f, ts) = strip_comb t and (g, us) = strip_comb u;
walther@59870:          val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
walther@59870:            commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
walther@59870:          val _ = tracing ("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
walther@59870:            commas(map (UnparseC.term_in_thy thy) us) ^ "]\"");
neuper@52070:          val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' x t) ^ ", " ^
neuper@52070:            string_of_int (size_of_term' x u) ^ ")");
neuper@52070:          val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o (hd_ord x)) (f,g));
neuper@52070:          val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o (terms_ord x) str false) (ts, us));
neuper@52070:          val _ = tracing ("-------");
neuper@52070:        in () end
neuper@52070:      else ();
neuper@52070: 	  case int_ord (size_of_term' x t, size_of_term' x u) of
neuper@52070: 	    EQUAL =>
neuper@52070: 	      let val (f, ts) = strip_comb t and (g, us) = strip_comb u 
neuper@52070:         in
neuper@52070: 	        (case hd_ord x (f, g) of 
neuper@52070: 	           EQUAL => (terms_ord x str pr) (ts, us) 
neuper@52070: 	         | ord => ord)
neuper@52070: 	      end
neuper@37954: 	 | ord => ord)
neuper@37954: and hd_ord x (f, g) =                                        (* ~ term.ML *)
neuper@37989:   prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) 
neuper@37989:             int_ord (dest_hd' x f, dest_hd' x g)
walther@60263: and terms_ord x _ pr (ts, us) = 
walther@59881:     list_ord (term_ord' x pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
neuper@52070: 
neuper@37954: in
neuper@37954: 
walther@60263: fun ord_make_polynomial_in (pr:bool) thy subst tu =
walther@60263:   ((**)tracing ("*** subs variable is: " ^ (Env.subst2str subst)); (**)
neuper@37954: 	case subst of
walther@60263: 	  (_, x) :: _ => (term_ord' x pr thy tu = LESS)
walther@60263: 	| _ => raise ERROR ("ord_make_polynomial_in called with subst = " ^ Env.subst2str subst))
walther@60263: 
neuper@37989: end;(*local*)
neuper@37954: 
wneuper@59472: \<close>
wneuper@59472: ML\<open>
s1210629013@55444: val order_add_mult_in = prep_rls'(
walther@59851:   Rule_Def.Repeat{id = "order_add_mult_in", preconds = [], 
neuper@37954:       rew_ord = ("ord_make_polynomial_in",
neuper@52139: 		 ord_make_polynomial_in false @{theory "Poly"}),
walther@59852:       erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451:       calc = [], errpatts = [],
walther@59877:       rules = [Rule.Thm ("mult.commute",ThmC.numerals_to_Free @{thm mult.commute}),
neuper@37954: 	       (* z * w = w * z *)
walther@59871: 	       Rule.Thm ("real_mult_left_commute",ThmC.numerals_to_Free @{thm real_mult_left_commute}),
neuper@37954: 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
walther@59877: 	       Rule.Thm ("mult.assoc",ThmC.numerals_to_Free @{thm mult.assoc}),		
neuper@37954: 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
walther@59877: 	       Rule.Thm ("add.commute",ThmC.numerals_to_Free @{thm add.commute}),	
neuper@37954: 	       (*z + w = w + z*)
walther@59877: 	       Rule.Thm ("add.left_commute",ThmC.numerals_to_Free @{thm add.left_commute}),
neuper@37954: 	       (*x + (y + z) = y + (x + z)*)
walther@59877: 	       Rule.Thm ("add.assoc",ThmC.numerals_to_Free @{thm add.assoc})	               
neuper@37954: 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
walther@59878: 	       ], scr = Rule.Empty_Prog});
neuper@37954: 
wneuper@59472: \<close>
wneuper@59472: ML\<open>
s1210629013@55444: val collect_bdv = prep_rls'(
walther@59851:   Rule_Def.Repeat{id = "collect_bdv", preconds = [], 
walther@59857:       rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852:       erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451:       calc = [], errpatts = [],
walther@59871:       rules = [Rule.Thm ("bdv_collect_1",ThmC.numerals_to_Free @{thm bdv_collect_1}),
walther@59871: 	       Rule.Thm ("bdv_collect_2",ThmC.numerals_to_Free @{thm bdv_collect_2}),
walther@59871: 	       Rule.Thm ("bdv_collect_3",ThmC.numerals_to_Free @{thm bdv_collect_3}),
neuper@37954: 
walther@59871: 	       Rule.Thm ("bdv_collect_assoc1_1",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_1}),
walther@59871: 	       Rule.Thm ("bdv_collect_assoc1_2",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_2}),
walther@59871: 	       Rule.Thm ("bdv_collect_assoc1_3",ThmC.numerals_to_Free @{thm bdv_collect_assoc1_3}),
neuper@37954: 
walther@59871: 	       Rule.Thm ("bdv_collect_assoc2_1",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_1}),
walther@59871: 	       Rule.Thm ("bdv_collect_assoc2_2",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_2}),
walther@59871: 	       Rule.Thm ("bdv_collect_assoc2_3",ThmC.numerals_to_Free @{thm bdv_collect_assoc2_3}),
neuper@37954: 
neuper@37954: 
walther@59871: 	       Rule.Thm ("bdv_n_collect_1",ThmC.numerals_to_Free @{thm bdv_n_collect_1}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_2",ThmC.numerals_to_Free @{thm bdv_n_collect_2}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_3",ThmC.numerals_to_Free @{thm bdv_n_collect_3}),
neuper@37954: 
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc1_1",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_1}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc1_2",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_2}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc1_3",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc1_3}),
neuper@37954: 
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc2_1",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_1}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc2_2",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_2}),
walther@59871: 	       Rule.Thm ("bdv_n_collect_assoc2_3",ThmC.numerals_to_Free @{thm bdv_n_collect_assoc2_3})
walther@59878: 	       ], scr = Rule.Empty_Prog});
neuper@37954: 
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: (*.transforms an arbitrary term without roots to a polynomial [4] 
neuper@37954:    according to knowledge/Poly.sml.*) 
s1210629013@55444: val make_polynomial_in = prep_rls'(
walther@59878:   Rule_Set.Sequence {id = "make_polynomial_in", preconds = []:term list, 
walther@59857:        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851:       erls = Atools_erls, srls = Rule_Set.Empty,
neuper@42451:       calc = [], errpatts = [],
wneuper@59416:       rules = [Rule.Rls_ expand_poly,
wneuper@59416: 	       Rule.Rls_ order_add_mult_in,
wneuper@59416: 	       Rule.Rls_ simplify_power,
wneuper@59416: 	       Rule.Rls_ collect_numerals,
wneuper@59416: 	       Rule.Rls_ reduce_012,
walther@59871: 	       Rule.Thm ("realpow_oneI",ThmC.numerals_to_Free @{thm realpow_oneI}),
wneuper@59416: 	       Rule.Rls_ discard_parentheses,
wneuper@59416: 	       Rule.Rls_ collect_bdv
neuper@37954: 	       ],
walther@59878:       scr = Rule.Empty_Prog
wneuper@59406:       });     
neuper@37954: 
wneuper@59472: \<close>
wneuper@59472: ML\<open>
neuper@37954: val separate_bdvs = 
walther@59852:     Rule_Set.append_rules "separate_bdvs"
neuper@37954: 	       collect_bdv
walther@59871: 	       [Rule.Thm ("separate_bdv", ThmC.numerals_to_Free @{thm separate_bdv}),
neuper@37954: 		(*"?a * ?bdv / ?b = ?a / ?b * ?bdv"*)
walther@59871: 		Rule.Thm ("separate_bdv_n", ThmC.numerals_to_Free @{thm separate_bdv_n}),
walther@59871: 		Rule.Thm ("separate_1_bdv", ThmC.numerals_to_Free @{thm separate_1_bdv}),
neuper@37954: 		(*"?bdv / ?b = (1 / ?b) * ?bdv"*)
walther@59871: 		Rule.Thm ("separate_1_bdv_n", ThmC.numerals_to_Free @{thm separate_1_bdv_n}),
walther@60242: 		(*"?bdv \<up> ?n / ?b = 1 / ?b * ?bdv \<up> ?n"*)
wneuper@59416: 		Rule.Thm ("add_divide_distrib", 
walther@59871: 		     ThmC.numerals_to_Free @{thm add_divide_distrib})
neuper@37954: 		(*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"
neuper@37954: 		      WN051031 DOES NOT BELONG TO HERE*)
neuper@37954: 		];
wneuper@59472: \<close>
wneuper@59472: ML\<open>
s1210629013@55444: val make_ratpoly_in = prep_rls'(
walther@59878:   Rule_Set.Sequence {id = "make_ratpoly_in", preconds = []:term list, 
walther@59857:        rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851:       erls = Atools_erls, srls = Rule_Set.Empty,
neuper@42451:       calc = [], errpatts = [],
wneuper@59416:       rules = [Rule.Rls_ norm_Rational,
wneuper@59416: 	       Rule.Rls_ order_add_mult_in,
wneuper@59416: 	       Rule.Rls_ discard_parentheses,
wneuper@59416: 	       Rule.Rls_ separate_bdvs,
wneuper@59416: 	       (* Rule.Rls_ rearrange_assoc, WN060916 why does cancel_p not work?*)
wneuper@59416: 	       Rule.Rls_ cancel_p
walther@59878: 	       (*Rule.Eval ("Rings.divide_class.divide"  , eval_cancel "#divide_e") too weak!*)
neuper@37954: 	       ],
walther@59878:       scr = Rule.Empty_Prog});      
wneuper@59472: \<close>
wneuper@59472: setup \<open>KEStore_Elems.add_rlss 
neuper@52130:   [("order_add_mult_in", (Context.theory_name @{theory}, order_add_mult_in)), 
neuper@52130:   ("collect_bdv", (Context.theory_name @{theory}, collect_bdv)), 
neuper@52130:   ("make_polynomial_in", (Context.theory_name @{theory}, make_polynomial_in)), 
neuper@52130:   ("make_ratpoly_in", (Context.theory_name @{theory}, make_ratpoly_in)), 
wneuper@59472:   ("separate_bdvs", (Context.theory_name @{theory}, separate_bdvs))]\<close>
neuper@37954: 
neuper@37906: end
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 




