
neuper@37906: (* theory collecting all knowledge 
neuper@37906:    (predicates 'is_rootEq_in', 'is_sqrt_in', 'is_ratEq_in')
neuper@37906:    for PolynomialEquations.
neuper@37906:    alternative dependencies see Isac.thy
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: consts
neuper@37906: 
neuper@37906: (*---------scripts--------------------------*)
neuper@37906:   Complete'_square
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Complete'_square (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:  (*----- poly ----- *)	 
neuper@37906:   Normalize'_poly
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Normalize'_poly (_ _=))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d0'_polyeq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d0'_polyeq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d1'_polyeq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d1'_polyeq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d2'_polyeq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d2'_polyeq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d2'_polyeq'_sqonly'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d2'_polyeq'_sqonly'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d2'_polyeq'_bdvonly'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d2'_polyeq'_bdvonly'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d2'_polyeq'_pq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d2'_polyeq'_pq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d2'_polyeq'_abc'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d2'_polyeq'_abc'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d3'_polyeq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d3'_polyeq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Solve'_d4'_polyeq'_equation
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Solve'_d4'_polyeq'_equation (_ _ =))// 
neuper@37954:                   (_))" 9)
neuper@37906:   Biquadrat'_poly
neuper@37954:              :: "[bool,real, 
neuper@37954: 		   bool list] => bool list"
neuper@37954:                ("((Script Biquadrat'_poly (_ _=))// 
neuper@37954:                   (_))" 9)
neuper@37906: 
neuper@37906: (*-------------------- rules -------------------------------------------------*)
neuper@37954: axioms 
neuper@37906: 
neuper@37983:   cancel_leading_coeff1: "Not (c =!= 0) ==> (a + b*bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c + b/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff2: "Not (c =!= 0) ==> (a - b*bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c - b/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff3: "Not (c =!= 0) ==> (a + b*bdv - c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c + b/c*bdv - bdv^^^2 = 0)"
neuper@37906: 
neuper@37983:   cancel_leading_coeff4: "Not (c =!= 0) ==> (a +   bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c + 1/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff5: "Not (c =!= 0) ==> (a -   bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c - 1/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff6: "Not (c =!= 0) ==> (a +   bdv - c*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/c + 1/c*bdv - bdv^^^2 = 0)"
neuper@37906: 
neuper@37983:   cancel_leading_coeff7: "Not (c =!= 0) ==> (    b*bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (    b/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff8: "Not (c =!= 0) ==> (    b*bdv - c*bdv^^^2 = 0) = 
neuper@37954: 			                   (    b/c*bdv - bdv^^^2 = 0)"
neuper@37906: 
neuper@37983:   cancel_leading_coeff9: "Not (c =!= 0) ==> (      bdv + c*bdv^^^2 = 0) = 
neuper@37954: 			                   (      1/c*bdv + bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff10:"Not (c =!= 0) ==> (      bdv - c*bdv^^^2 = 0) = 
neuper@37954: 			                   (      1/c*bdv - bdv^^^2 = 0)"
neuper@37906: 
neuper@37983:   cancel_leading_coeff11:"Not (c =!= 0) ==> (a +      b*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/b +      bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff12:"Not (c =!= 0) ==> (a -      b*bdv^^^2 = 0) = 
neuper@37954: 			                   (a/b -      bdv^^^2 = 0)"
neuper@37983:   cancel_leading_coeff13:"Not (c =!= 0) ==> (         b*bdv^^^2 = 0) = 
neuper@37954: 			                   (           bdv^^^2 = 0/b)"
neuper@37906: 
neuper@37983:   complete_square1:      "(q + p*bdv + bdv^^^2 = 0) = 
neuper@37954: 		         (q + (p/2 + bdv)^^^2 = (p/2)^^^2)"
neuper@37983:   complete_square2:      "(    p*bdv + bdv^^^2 = 0) = 
neuper@37954: 		         (    (p/2 + bdv)^^^2 = (p/2)^^^2)"
neuper@37983:   complete_square3:      "(      bdv + bdv^^^2 = 0) = 
neuper@37954: 		         (    (1/2 + bdv)^^^2 = (1/2)^^^2)"
neuper@37906: 		        
neuper@37983:   complete_square4:      "(q - p*bdv + bdv^^^2 = 0) = 
neuper@37954: 		         (q + (p/2 - bdv)^^^2 = (p/2)^^^2)"
neuper@37983:   complete_square5:      "(q + p*bdv - bdv^^^2 = 0) = 
neuper@37954: 		         (q + (p/2 - bdv)^^^2 = (p/2)^^^2)"
neuper@37906: 
neuper@37983:   square_explicit1:      "(a + b^^^2 = c) = ( b^^^2 = c - a)"
neuper@37983:   square_explicit2:      "(a - b^^^2 = c) = (-(b^^^2) = c - a)"
neuper@37906: 
neuper@37983:   bdv_explicit1:         "(a + bdv = b) = (bdv = - a + b)"
neuper@37983:   bdv_explicit2:         "(a - bdv = b) = ((-1)*bdv = - a + b)"
neuper@37983:   bdv_explicit3:         "((-1)*bdv = b) = (bdv = (-1)*b)"
neuper@37906: 
neuper@37983:   plus_leq:              "(0 <= a + b) = ((-1)*b <= a)"(*Isa?*)
neuper@37983:   minus_leq:             "(0 <= a - b) = (     b <= a)"(*Isa?*)
neuper@37906: 
neuper@37906: (*-- normalize --*)
neuper@37906:   (*WN0509 compare LinEq.all_left "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)"*)
neuper@37983:   all_left:              "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)"
neuper@37983:   makex1_x:              "a^^^1  = a"  
neuper@37983:   real_assoc_1:          "a+(b+c) = a+b+c"
neuper@37983:   real_assoc_2:          "a*(b*c) = a*b*c"
neuper@37906: 
neuper@37906: (* ---- degree 0 ----*)
neuper@37983:   d0_true:               "(0=0) = True"
neuper@37983:   d0_false:              "[|Not(bdv occurs_in a);Not(a=0)|] ==> (a=0) = False"
neuper@37906: (* ---- degree 1 ----*)
neuper@37983:   d1_isolate_add1:
neuper@37906:    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv = 0) = (b*bdv = (-1)*a)"
neuper@37983:   d1_isolate_add2:
neuper@37906:    "[|Not(bdv occurs_in a)|] ==> (a +   bdv = 0) = (  bdv = (-1)*a)"
neuper@37983:   d1_isolate_div:
neuper@37906:    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv = c) = (bdv = c/b)"
neuper@37906: (* ---- degree 2 ----*)
neuper@37983:   d2_isolate_add1:
neuper@37906:    "[|Not(bdv occurs_in a)|] ==> (a + b*bdv^^^2=0) = (b*bdv^^^2= (-1)*a)"
neuper@37983:   d2_isolate_add2:
neuper@37906:    "[|Not(bdv occurs_in a)|] ==> (a +   bdv^^^2=0) = (  bdv^^^2= (-1)*a)"
neuper@37983:   d2_isolate_div:
neuper@37906:    "[|Not(b=0);Not(bdv occurs_in c)|] ==> (b*bdv^^^2=c) = (bdv^^^2=c/b)"
neuper@37954: 
neuper@37983:   d2_prescind1:          "(a*bdv + b*bdv^^^2 = 0) = (bdv*(a +b*bdv)=0)"
neuper@37983:   d2_prescind2:          "(a*bdv +   bdv^^^2 = 0) = (bdv*(a +  bdv)=0)"
neuper@37983:   d2_prescind3:          "(  bdv + b*bdv^^^2 = 0) = (bdv*(1+b*bdv)=0)"
neuper@37983:   d2_prescind4:          "(  bdv +   bdv^^^2 = 0) = (bdv*(1+  bdv)=0)"
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)|] ==> 
neuper@37954:                          (bdv^^^2=c) = ((bdv=sqrt c) | (bdv=(-1)*sqrt c ))"
neuper@37983:   d2_sqrt_equation1_neg:
neuper@37906:   "[|(c<0);Not(bdv occurs_in c)|] ==> (bdv^^^2=c) = False"
neuper@37983:   d2_sqrt_equation2:     "(bdv^^^2=0) = (bdv=0)"
neuper@37983:   d2_sqrt_equation3:     "(b*bdv^^^2=0) = (bdv=0)"
neuper@37983:   d2_reduce_equation1:   "(bdv*(a +b*bdv)=0) = ((bdv=0)|(a+b*bdv=0))"
neuper@37983:   d2_reduce_equation2:   "(bdv*(a +  bdv)=0) = ((bdv=0)|(a+  bdv=0))"
neuper@37983:   d2_pqformula1:         "[|0<=p^^^2 - 4*q|] ==> (q+p*bdv+   bdv^^^2=0) =
neuper@37954:                            ((bdv= (-1)*(p/2) + sqrt(p^^^2 - 4*q)/2) 
neuper@37954:                           | (bdv= (-1)*(p/2) - sqrt(p^^^2 - 4*q)/2))"
neuper@37983:   d2_pqformula1_neg:     "[|p^^^2 - 4*q<0|] ==> (q+p*bdv+   bdv^^^2=0) = False"
neuper@37983:   d2_pqformula2:         "[|0<=p^^^2 - 4*q|] ==> (q+p*bdv+1*bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(p/2) + sqrt(p^^^2 - 4*q)/2) 
neuper@37954:                           | (bdv= (-1)*(p/2) - sqrt(p^^^2 - 4*q)/2))"
neuper@37983:   d2_pqformula2_neg:     "[|p^^^2 - 4*q<0|] ==> (q+p*bdv+1*bdv^^^2=0) = False"
neuper@37983:   d2_pqformula3:         "[|0<=1 - 4*q|] ==> (q+  bdv+   bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
neuper@37954:                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))"
neuper@37983:   d2_pqformula3_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+   bdv^^^2=0) = False"
neuper@37983:   d2_pqformula4:         "[|0<=1 - 4*q|] ==> (q+  bdv+1*bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 4*q)/2) 
neuper@37954:                           | (bdv= (-1)*(1/2) - sqrt(1 - 4*q)/2))"
neuper@37983:   d2_pqformula4_neg:     "[|1 - 4*q<0|] ==> (q+  bdv+1*bdv^^^2=0) = False"
neuper@37983:   d2_pqformula5:         "[|0<=p^^^2 - 0|] ==> (  p*bdv+   bdv^^^2=0) =
neuper@37954:                            ((bdv= (-1)*(p/2) + sqrt(p^^^2 - 0)/2) 
neuper@37954:                           | (bdv= (-1)*(p/2) - sqrt(p^^^2 - 0)/2))"
neuper@37906:   (* d2_pqformula5_neg not need p^2 never less zero in R *)
neuper@37983:   d2_pqformula6:         "[|0<=p^^^2 - 0|] ==> (  p*bdv+1*bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(p/2) + sqrt(p^^^2 - 0)/2) 
neuper@37954:                           | (bdv= (-1)*(p/2) - sqrt(p^^^2 - 0)/2))"
neuper@37906:   (* d2_pqformula6_neg not need p^2 never less zero in R *)
neuper@37983:   d2_pqformula7:        "[|0<=1 - 0|] ==> (    bdv+   bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
neuper@37954:                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))"
neuper@37906:   (* d2_pqformula7_neg not need, because 1<0 ==> False*)
neuper@37983:   d2_pqformula8:        "[|0<=1 - 0|] ==> (    bdv+1*bdv^^^2=0) = 
neuper@37954:                            ((bdv= (-1)*(1/2) + sqrt(1 - 0)/2) 
neuper@37954:                           | (bdv= (-1)*(1/2) - sqrt(1 - 0)/2))"
neuper@37906:   (* d2_pqformula8_neg not need, because 1<0 ==> False*)
neuper@37983:   d2_pqformula9:        "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> 
neuper@37954:                            (q+    1*bdv^^^2=0) = ((bdv= 0 + sqrt(0 - 4*q)/2) 
neuper@37954:                                                 | (bdv= 0 - sqrt(0 - 4*q)/2))"
neuper@37983:   d2_pqformula9_neg:
neuper@37906:    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+    1*bdv^^^2=0) = False"
neuper@37983:   d2_pqformula10:
neuper@37906:    "[|Not(bdv occurs_in q); 0<= (-1)*4*q|] ==> (q+     bdv^^^2=0) = 
neuper@37906:            ((bdv= 0 + sqrt(0 - 4*q)/2) 
neuper@37906:           | (bdv= 0 - sqrt(0 - 4*q)/2))"
neuper@37983:   d2_pqformula10_neg:
neuper@37906:    "[|Not(bdv occurs_in q); (-1)*4*q<0|] ==> (q+     bdv^^^2=0) = False"
neuper@37983:   d2_abcformula1:
neuper@37906:    "[|0<=b^^^2 - 4*a*c|] ==> (c + b*bdv+a*bdv^^^2=0) =
neuper@37906:            ((bdv=( -b + sqrt(b^^^2 - 4*a*c))/(2*a)) 
neuper@37906:           | (bdv=( -b - sqrt(b^^^2 - 4*a*c))/(2*a)))"
neuper@37983:   d2_abcformula1_neg:
neuper@37906:    "[|b^^^2 - 4*a*c<0|] ==> (c + b*bdv+a*bdv^^^2=0) = False"
neuper@37983:   d2_abcformula2:
neuper@37906:    "[|0<=1 - 4*a*c|]     ==> (c+    bdv+a*bdv^^^2=0) = 
neuper@37906:            ((bdv=( -1 + sqrt(1 - 4*a*c))/(2*a)) 
neuper@37906:           | (bdv=( -1 - sqrt(1 - 4*a*c))/(2*a)))"
neuper@37983:   d2_abcformula2_neg:
neuper@37906:    "[|1 - 4*a*c<0|]     ==> (c+    bdv+a*bdv^^^2=0) = False"
neuper@37983:   d2_abcformula3:
neuper@37906:    "[|0<=b^^^2 - 4*1*c|] ==> (c + b*bdv+  bdv^^^2=0) =
neuper@37906:            ((bdv=( -b + sqrt(b^^^2 - 4*1*c))/(2*1)) 
neuper@37906:           | (bdv=( -b - sqrt(b^^^2 - 4*1*c))/(2*1)))"
neuper@37983:   d2_abcformula3_neg:
neuper@37906:    "[|b^^^2 - 4*1*c<0|] ==> (c + b*bdv+  bdv^^^2=0) = False"
neuper@37983:   d2_abcformula4:
neuper@37906:    "[|0<=1 - 4*1*c|] ==> (c +   bdv+  bdv^^^2=0) =
neuper@37906:            ((bdv=( -1 + sqrt(1 - 4*1*c))/(2*1)) 
neuper@37906:           | (bdv=( -1 - sqrt(1 - 4*1*c))/(2*1)))"
neuper@37983:   d2_abcformula4_neg:
neuper@37906:    "[|1 - 4*1*c<0|] ==> (c +   bdv+  bdv^^^2=0) = False"
neuper@37983:   d2_abcformula5:
neuper@37906:    "[|Not(bdv occurs_in c); 0<=0 - 4*a*c|] ==> (c +  a*bdv^^^2=0) =
neuper@37906:            ((bdv=( 0 + sqrt(0 - 4*a*c))/(2*a)) 
neuper@37906:           | (bdv=( 0 - sqrt(0 - 4*a*c))/(2*a)))"
neuper@37983:   d2_abcformula5_neg:
neuper@37906:    "[|Not(bdv occurs_in c); 0 - 4*a*c<0|] ==> (c +  a*bdv^^^2=0) = False"
neuper@37983:   d2_abcformula6:
neuper@37906:    "[|Not(bdv occurs_in c); 0<=0 - 4*1*c|]     ==> (c+    bdv^^^2=0) = 
neuper@37906:            ((bdv=( 0 + sqrt(0 - 4*1*c))/(2*1)) 
neuper@37906:           | (bdv=( 0 - sqrt(0 - 4*1*c))/(2*1)))"
neuper@37983:   d2_abcformula6_neg:
neuper@37906:    "[|Not(bdv occurs_in c); 0 - 4*1*c<0|]     ==> (c+    bdv^^^2=0) = False"
neuper@37983:   d2_abcformula7:
neuper@37906:    "[|0<=b^^^2 - 0|]     ==> (    b*bdv+a*bdv^^^2=0) = 
neuper@37906:            ((bdv=( -b + sqrt(b^^^2 - 0))/(2*a)) 
neuper@37906:           | (bdv=( -b - sqrt(b^^^2 - 0))/(2*a)))"
neuper@37906:   (* d2_abcformula7_neg not need b^2 never less zero in R *)
neuper@37983:   d2_abcformula8:
neuper@37906:    "[|0<=b^^^2 - 0|] ==> (    b*bdv+  bdv^^^2=0) =
neuper@37906:            ((bdv=( -b + sqrt(b^^^2 - 0))/(2*1)) 
neuper@37906:           | (bdv=( -b - sqrt(b^^^2 - 0))/(2*1)))"
neuper@37906:   (* d2_abcformula8_neg not need b^2 never less zero in R *)
neuper@37983:   d2_abcformula9:
neuper@37906:    "[|0<=1 - 0|]     ==> (      bdv+a*bdv^^^2=0) = 
neuper@37906:            ((bdv=( -1 + sqrt(1 - 0))/(2*a)) 
neuper@37906:           | (bdv=( -1 - sqrt(1 - 0))/(2*a)))"
neuper@37906:   (* d2_abcformula9_neg not need, because 1<0 ==> False*)
neuper@37983:   d2_abcformula10:
neuper@37906:    "[|0<=1 - 0|] ==> (      bdv+  bdv^^^2=0) =
neuper@37906:            ((bdv=( -1 + sqrt(1 - 0))/(2*1)) 
neuper@37906:           | (bdv=( -1 - sqrt(1 - 0))/(2*1)))"
neuper@37906:   (* d2_abcformula10_neg not need, because 1<0 ==> False*)
neuper@37906: 
neuper@37906: (* ---- degree 3 ----*)
neuper@37983:   d3_reduce_equation1:
neuper@37906:   "(a*bdv + b*bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (a + b*bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation2:
neuper@37906:   "(  bdv + b*bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (1 + b*bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation3:
neuper@37906:   "(a*bdv +   bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (a +   bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation4:
neuper@37906:   "(  bdv +   bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (1 +   bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation5:
neuper@37906:   "(a*bdv + b*bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (a + b*bdv +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation6:
neuper@37906:   "(  bdv + b*bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (1 + b*bdv +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation7:
neuper@37906:   "(a*bdv +   bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (1 +   bdv +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation8:
neuper@37906:   "(  bdv +   bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (1 +   bdv +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation9:
neuper@37906:   "(a*bdv             + c*bdv^^^3=0) = (bdv=0 | (a         + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation10:
neuper@37906:   "(  bdv             + c*bdv^^^3=0) = (bdv=0 | (1         + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation11:
neuper@37906:   "(a*bdv             +   bdv^^^3=0) = (bdv=0 | (a         +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation12:
neuper@37906:   "(  bdv             +   bdv^^^3=0) = (bdv=0 | (1         +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation13:
neuper@37906:   "(        b*bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (    b*bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation14:
neuper@37906:   "(          bdv^^^2 + c*bdv^^^3=0) = (bdv=0 | (      bdv + c*bdv^^^2=0))"
neuper@37983:   d3_reduce_equation15:
neuper@37906:   "(        b*bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (    b*bdv +   bdv^^^2=0))"
neuper@37983:   d3_reduce_equation16:
neuper@37906:   "(          bdv^^^2 +   bdv^^^3=0) = (bdv=0 | (      bdv +   bdv^^^2=0))"
neuper@37983:   d3_isolate_add1:
neuper@37906:   "[|Not(bdv occurs_in a)|] ==> (a + b*bdv^^^3=0) = (b*bdv^^^3= (-1)*a)"
neuper@37983:   d3_isolate_add2:
neuper@37906:   "[|Not(bdv occurs_in a)|] ==> (a +   bdv^^^3=0) = (  bdv^^^3= (-1)*a)"
neuper@37983:   d3_isolate_div:
neuper@37906:    "[|Not(b=0);Not(bdv occurs_in a)|] ==> (b*bdv^^^3=c) = (bdv^^^3=c/b)"
neuper@37983:   d3_root_equation2:
neuper@37906:   "(bdv^^^3=0) = (bdv=0)"
neuper@37983:   d3_root_equation1:
neuper@37906:   "(bdv^^^3=c) = (bdv = nroot 3 c)"
neuper@37906: 
neuper@37906: (* ---- degree 4 ----*)
neuper@37906:  (* RL03.FIXME es wir nicht getestet ob u>0 *)
neuper@37989:  d4_sub_u1:
neuper@37906:  "(c+b*bdv^^^2+a*bdv^^^4=0) =
neuper@37906:    ((a*u^^^2+b*u+c=0) & (bdv^^^2=u))"
neuper@37906: 
neuper@37906: (* ---- 7.3.02 von Termorder ---- *)
neuper@37906: 
neuper@37983:   bdv_collect_1:      "l * bdv + m * bdv = (l + m) * bdv"
neuper@37983:   bdv_collect_2:      "bdv + m * bdv = (1 + m) * bdv"
neuper@37983:   bdv_collect_3:      "l * bdv + bdv = (l + 1) * bdv"
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@37983:   bdv_collect_assoc1_1:"l * bdv + (m * bdv + k) = (l + m) * bdv + k"
neuper@37983:   bdv_collect_assoc1_2:"bdv + (m * bdv + k) = (1 + m) * bdv + k"
neuper@37983:   bdv_collect_assoc1_3:"l * bdv + (bdv + k) = (l + 1) * bdv + k"
neuper@37906: 
neuper@37983:   bdv_collect_assoc2_1:"k + l * bdv + m * bdv = k + (l + m) * bdv"
neuper@37983:   bdv_collect_assoc2_2:"k + bdv + m * bdv = k + (1 + m) * bdv"
neuper@37983:   bdv_collect_assoc2_3:"k + l * bdv + bdv = k + (l + 1) * bdv"
neuper@37906: 
neuper@37906: 
neuper@37983:   bdv_n_collect_1:     "l * bdv^^^n + m * bdv^^^n = (l + m) * bdv^^^n"
neuper@37983:   bdv_n_collect_2:     " bdv^^^n + m * bdv^^^n = (1 + m) * bdv^^^n"
neuper@37983:   bdv_n_collect_3:     "l * bdv^^^n + bdv^^^n = (l + 1) * bdv^^^n"   (*order!*)
neuper@37906: 
neuper@37983:   bdv_n_collect_assoc1_1:"l * bdv^^^n + (m * bdv^^^n + k) = (l + m) * bdv^^^n + k"
neuper@37983:   bdv_n_collect_assoc1_2:"bdv^^^n + (m * bdv^^^n + k) = (1 + m) * bdv^^^n + k"
neuper@37983:   bdv_n_collect_assoc1_3:"l * bdv^^^n + (bdv^^^n + k) = (l + 1) * bdv^^^n + k"
neuper@37906: 
neuper@37983:   bdv_n_collect_assoc2_1:"k + l * bdv^^^n + m * bdv^^^n = k + (l + m) * bdv^^^n"
neuper@37983:   bdv_n_collect_assoc2_2:"k + bdv^^^n + m * bdv^^^n = k + (1 + m) * bdv^^^n"
neuper@37983:   bdv_n_collect_assoc2_3:"k + l * bdv^^^n + bdv^^^n = k + (l + 1) * bdv^^^n"
neuper@37906: 
neuper@37906: (*WN.14.3.03*)
neuper@37983:   real_minus_div:        "- (a / b) = (-1 * a) / b"
neuper@37906: 
neuper@37983:   separate_bdv:          "(a * bdv) / b = (a / b) * bdv"
neuper@37983:   separate_bdv_n:        "(a * bdv ^^^ n) / b = (a / b) * bdv ^^^ n"
neuper@37983:   separate_1_bdv:        "bdv / b = (1 / b) * bdv"
neuper@37983:   separate_1_bdv_n:      "bdv ^^^ n / b = (1 / b) * bdv ^^^ n"
neuper@37906: 
neuper@37954: ML {*
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*)
neuper@37954:   append_rls "PolyEq_prls" e_rls 
neuper@37954: 	     [Calc ("Atools.ident",eval_ident "#ident_"),
neuper@37954: 	      Calc ("Tools.matches",eval_matches ""),
neuper@37954: 	      Calc ("Tools.lhs"    ,eval_lhs ""),
neuper@37954: 	      Calc ("Tools.rhs"    ,eval_rhs ""),
neuper@37954: 	      Calc ("Poly.is'_expanded'_in",eval_is_expanded_in ""),
neuper@37954: 	      Calc ("Poly.is'_poly'_in",eval_is_poly_in ""),
neuper@37954: 	      Calc ("Poly.has'_degree'_in",eval_has_degree_in ""),    
neuper@37954:               Calc ("Poly.is'_polyrat'_in",eval_is_polyrat_in ""),
neuper@37954: 	      (*Calc ("Atools.occurs'_in",eval_occurs_in ""),   *) 
neuper@37954: 	      (*Calc ("Atools.is'_const",eval_const "#is_const_"),*)
neuper@37954: 	      Calc ("op =",eval_equal "#equal_"),
neuper@37954:               Calc ("RootEq.is'_rootTerm'_in",eval_is_rootTerm_in ""),
neuper@37954: 	      Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
neuper@37969: 	      Thm ("not_true",num_str @{thm not_true}),
neuper@37969: 	      Thm ("not_false",num_str @{thm not_false}),
neuper@37969: 	      Thm ("and_true",num_str @{thm and_true}),
neuper@37969: 	      Thm ("and_false",num_str @{thm and_false}),
neuper@37969: 	      Thm ("or_true",num_str @{thm or_true}),
neuper@37969: 	      Thm ("or_false",num_str @{thm or_false})
neuper@37954: 	       ];
neuper@37954: 
neuper@37954: val PolyEq_erls = 
neuper@37954:     merge_rls "PolyEq_erls" LinEq_erls
neuper@37954:     (append_rls "ops_preds" calculate_Rational
neuper@37954: 		[Calc ("op =",eval_equal "#equal_"),
neuper@37969: 		 Thm ("plus_leq", num_str @{thm plus_leq}),
neuper@37969: 		 Thm ("minus_leq", num_str @{thm minus_leq}),
neuper@37969: 		 Thm ("rat_leq1", num_str @{thm rat_leq1}),
neuper@37969: 		 Thm ("rat_leq2", num_str @{thm rat_leq2}),
neuper@37969: 		 Thm ("rat_leq3", num_str @{thm rat_leq3})
neuper@37954: 		 ]);
neuper@37954: 
neuper@37954: val PolyEq_crls = 
neuper@37954:     merge_rls "PolyEq_crls" LinEq_crls
neuper@37954:     (append_rls "ops_preds" calculate_Rational
neuper@37954: 		[Calc ("op =",eval_equal "#equal_"),
neuper@37969: 		 Thm ("plus_leq", num_str @{thm plus_leq}),
neuper@37969: 		 Thm ("minus_leq", num_str @{thm minus_leq}),
neuper@37969: 		 Thm ("rat_leq1", num_str @{thm rat_leq1}),
neuper@37969: 		 Thm ("rat_leq2", num_str @{thm rat_leq2}),
neuper@37969: 		 Thm ("rat_leq3", num_str @{thm rat_leq3})
neuper@37954: 		 ]);
neuper@37954: 
neuper@37954: val cancel_leading_coeff = prep_rls(
neuper@37954:   Rls {id = "cancel_leading_coeff", preconds = [], 
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:       erls = PolyEq_erls, srls = Erls, calc = [], (*asm_thm = [],*)
neuper@37989:       rules = 
neuper@37989:       [Thm ("cancel_leading_coeff1",num_str @{thm cancel_leading_coeff1}),
neuper@37989:        Thm ("cancel_leading_coeff2",num_str @{thm cancel_leading_coeff2}),
neuper@37989:        Thm ("cancel_leading_coeff3",num_str @{thm cancel_leading_coeff3}),
neuper@37989:        Thm ("cancel_leading_coeff4",num_str @{thm cancel_leading_coeff4}),
neuper@37989:        Thm ("cancel_leading_coeff5",num_str @{thm cancel_leading_coeff5}),
neuper@37989:        Thm ("cancel_leading_coeff6",num_str @{thm cancel_leading_coeff6}),
neuper@37989:        Thm ("cancel_leading_coeff7",num_str @{thm cancel_leading_coeff7}),
neuper@37989:        Thm ("cancel_leading_coeff8",num_str @{thm cancel_leading_coeff8}),
neuper@37989:        Thm ("cancel_leading_coeff9",num_str @{thm cancel_leading_coeff9}),
neuper@37989:        Thm ("cancel_leading_coeff10",num_str @{thm cancel_leading_coeff10}),
neuper@37989:        Thm ("cancel_leading_coeff11",num_str @{thm cancel_leading_coeff11}),
neuper@37989:        Thm ("cancel_leading_coeff12",num_str @{thm cancel_leading_coeff12}),
neuper@37989:        Thm ("cancel_leading_coeff13",num_str @{thm cancel_leading_coeff13})
neuper@37989:        ],scr = Script ((term_of o the o (parse thy)) "empty_script")}:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: val complete_square = prep_rls(
neuper@37954:   Rls {id = "complete_square", preconds = [], 
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:       erls = PolyEq_erls, srls = Erls, calc = [], (*asm_thm = [],*)
neuper@37969:       rules = [Thm ("complete_square1",num_str @{thm complete_square1}),
neuper@37969: 	       Thm ("complete_square2",num_str @{thm complete_square2}),
neuper@37969: 	       Thm ("complete_square3",num_str @{thm complete_square3}),
neuper@37969: 	       Thm ("complete_square4",num_str @{thm complete_square4}),
neuper@37969: 	       Thm ("complete_square5",num_str @{thm complete_square5})
neuper@37954: 	       ],
neuper@37954:       scr = Script ((term_of o the o (parse thy)) 
neuper@37954:       "empty_script")
neuper@37954:       }:rls);
neuper@37954: 
neuper@37954: val polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "polyeq_simplify", preconds = [], 
neuper@37954:        rew_ord = ("termlessI",termlessI), 
neuper@37954:        erls = PolyEq_erls, 
neuper@37954:        srls = Erls, 
neuper@37954:        calc = [], 
neuper@37954:        (*asm_thm = [],*)
neuper@37969:        rules = [Thm  ("real_assoc_1",num_str @{thm real_assoc_1}),
neuper@37969: 		Thm  ("real_assoc_2",num_str @{thm real_assoc_2}),
neuper@37969: 		Thm  ("real_diff_minus",num_str @{thm real_diff_minus}),
neuper@37969: 		Thm  ("real_unari_minus",num_str @{thm real_unari_minus}),
neuper@37969: 		Thm  ("realpow_multI",num_str @{thm realpow_multI}),
neuper@37954: 		Calc ("op +",eval_binop "#add_"),
neuper@37954: 		Calc ("op -",eval_binop "#sub_"),
neuper@37954: 		Calc ("op *",eval_binop "#mult_"),
neuper@37981: 		Calc ("HOL.divide", eval_cancel "#divide_e"),
neuper@37982: 		Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
neuper@37954: 		Calc ("Atools.pow" ,eval_binop "#power_"),
neuper@37954:                 Rls_ reduce_012
neuper@37954:                 ],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37954: 
neuper@37967: ruleset' := overwritelthy @{theory} (!ruleset',
neuper@37954: 		[("cancel_leading_coeff",cancel_leading_coeff),
neuper@37954: 		 ("complete_square",complete_square),
neuper@37954: 		 ("PolyEq_erls",PolyEq_erls),(*FIXXXME:del with rls.rls'*)
neuper@37954: 		 ("polyeq_simplify",polyeq_simplify)]);
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: 
neuper@37954: (* ------------- polySolve ------------------ *)
neuper@37954: (* -- d0 -- *)
neuper@37954: (*isolate the bound variable in an d0 equation; 'bdv' is a meta-constant*)
neuper@37954: val d0_polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "d0_polyeq_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
neuper@37954:        srls = Erls, 
neuper@37954:        calc = [], 
neuper@37954:        (*asm_thm = [],*)
neuper@37969:        rules = [Thm("d0_true",num_str @{thm d0_true}),
neuper@37969: 		Thm("d0_false",num_str @{thm  d0_false})
neuper@37954: 		],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37954: 
neuper@37954: (* -- d1 -- *)
neuper@37954: (*isolate the bound variable in an d1 equation; 'bdv' is a meta-constant*)
neuper@37954: val d1_polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "d1_polyeq_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
neuper@37954:        srls = Erls, 
neuper@37954:        calc = [], 
neuper@37954:        (*asm_thm = [("d1_isolate_div","")],*)
neuper@37954:        rules = [
neuper@37969: 		Thm("d1_isolate_add1",num_str @{thm d1_isolate_add1}), 
neuper@37954: 		(* a+bx=0 -> bx=-a *)
neuper@37969: 		Thm("d1_isolate_add2",num_str @{thm d1_isolate_add2}), 
neuper@37954: 		(* a+ x=0 ->  x=-a *)
neuper@37969: 		Thm("d1_isolate_div",num_str @{thm d1_isolate_div})    
neuper@37954: 		(*   bx=c -> x=c/b *)  
neuper@37954: 		],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (* -- d2 -- *)
neuper@37954: (* isolate the bound variable in an d2 equation with bdv only; 
neuper@37954:    'bdv' is a meta-constant*)
neuper@37954: val d2_polyeq_bdv_only_simplify = prep_rls(
neuper@37954:   Rls {id = "d2_polyeq_bdv_only_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
neuper@37954:        srls = Erls, 
neuper@37954:        calc = [], 
neuper@37954:        (*asm_thm = [("d2_sqrt_equation1",""),("d2_sqrt_equation1_neg",""),
neuper@37954:                   ("d2_isolate_div","")],*)
neuper@37969:        rules = [Thm("d2_prescind1",num_str @{thm d2_prescind1}),
neuper@37954:                 (*   ax+bx^2=0 -> x(a+bx)=0 *)
neuper@37969: 		Thm("d2_prescind2",num_str @{thm d2_prescind2}),
neuper@37954:                 (*   ax+ x^2=0 -> x(a+ x)=0 *)
neuper@37969: 		Thm("d2_prescind3",num_str @{thm d2_prescind3}),
neuper@37954:                 (*    x+bx^2=0 -> x(1+bx)=0 *)
neuper@37969: 		Thm("d2_prescind4",num_str @{thm d2_prescind4}),
neuper@37954:                 (*    x+ x^2=0 -> x(1+ x)=0 *)
neuper@37969: 		Thm("d2_sqrt_equation1",num_str @{thm d2_sqrt_equation1}),
neuper@37954:                 (* x^2=c   -> x=+-sqrt(c)*)
neuper@37969: 		Thm("d2_sqrt_equation1_neg",num_str @{thm d2_sqrt_equation1_neg}),
neuper@37954:                 (* [0<c] x^2=c  -> [] *)
neuper@37969: 		Thm("d2_sqrt_equation2",num_str @{thm d2_sqrt_equation2}),
neuper@37954:                 (*  x^2=0 ->    x=0    *)
neuper@37969: 		Thm("d2_reduce_equation1",num_str @{thm d2_reduce_equation1}),
neuper@37954:                 (* x(a+bx)=0 -> x=0 | a+bx=0*)
neuper@37969: 		Thm("d2_reduce_equation2",num_str @{thm d2_reduce_equation2}),
neuper@37954:                 (* x(a+ x)=0 -> x=0 | a+ x=0*)
neuper@37969: 		Thm("d2_isolate_div",num_str @{thm d2_isolate_div})
neuper@37954:                 (* bx^2=c -> x^2=c/b*)
neuper@37954: 		],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (* isolate the bound variable in an d2 equation with sqrt only; 
neuper@37954:    'bdv' is a meta-constant*)
neuper@37954: val d2_polyeq_sq_only_simplify = prep_rls(
neuper@37954:   Rls {id = "d2_polyeq_sq_only_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37954:        erls = PolyEq_erls,
neuper@37954:        srls = Erls, 
neuper@37954:        calc = [], 
neuper@37954:        (*asm_thm = [("d2_sqrt_equation1",""),("d2_sqrt_equation1_neg",""),
neuper@37954:                   ("d2_isolate_div","")],*)
neuper@37969:        rules = [Thm("d2_isolate_add1",num_str @{thm d2_isolate_add1}),
neuper@37954:                 (* a+   bx^2=0 -> bx^2=(-1)a*)
neuper@37969: 		Thm("d2_isolate_add2",num_str @{thm d2_isolate_add2}),
neuper@37954:                 (* a+    x^2=0 ->  x^2=(-1)a*)
neuper@37969: 		Thm("d2_sqrt_equation2",num_str @{thm d2_sqrt_equation2}),
neuper@37954:                 (*  x^2=0 ->    x=0    *)
neuper@37969: 		Thm("d2_sqrt_equation1",num_str @{thm d2_sqrt_equation1}),
neuper@37954:                 (* x^2=c   -> x=+-sqrt(c)*)
neuper@37969: 		Thm("d2_sqrt_equation1_neg",num_str @{thm d2_sqrt_equation1_neg}),
neuper@37954:                 (* [c<0] x^2=c  -> x=[] *)
neuper@37969: 		Thm("d2_isolate_div",num_str @{thm d2_isolate_div})
neuper@37954:                  (* bx^2=c -> x^2=c/b*)
neuper@37954: 		],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (* isolate the bound variable in an d2 equation with pqFormula;
neuper@37954:    'bdv' is a meta-constant*)
neuper@37954: val d2_polyeq_pqFormula_simplify = prep_rls(
neuper@37954:   Rls {id = "d2_polyeq_pqFormula_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord), erls = PolyEq_erls,
neuper@37954:        srls = Erls, calc = [], 
neuper@37969:        rules = [Thm("d2_pqformula1",num_str @{thm d2_pqformula1}),
neuper@37954:                 (* q+px+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula1_neg",num_str @{thm d2_pqformula1_neg}),
neuper@37954:                 (* q+px+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula2",num_str @{thm d2_pqformula2}), 
neuper@37954:                 (* q+px+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula2_neg",num_str @{thm d2_pqformula2_neg}),
neuper@37954:                 (* q+px+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula3",num_str @{thm d2_pqformula3}),
neuper@37954:                 (* q+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula3_neg",num_str @{thm d2_pqformula3_neg}), 
neuper@37954:                 (* q+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula4",num_str @{thm d2_pqformula4}),
neuper@37954:                 (* q+ x+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula4_neg",num_str @{thm d2_pqformula4_neg}),
neuper@37954:                 (* q+ x+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula5",num_str @{thm d2_pqformula5}),
neuper@37954:                 (*   qx+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula6",num_str @{thm d2_pqformula6}),
neuper@37954:                 (*   qx+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula7",num_str @{thm d2_pqformula7}),
neuper@37954:                 (*    x+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula8",num_str @{thm d2_pqformula8}),
neuper@37954:                 (*    x+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula9",num_str @{thm d2_pqformula9}),
neuper@37954:                 (* q   +1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula9_neg",num_str @{thm d2_pqformula9_neg}),
neuper@37954:                 (* q   +1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula10",num_str @{thm d2_pqformula10}),
neuper@37954:                 (* q   + x^2=0 *)
neuper@37969: 		Thm("d2_pqformula10_neg",num_str @{thm d2_pqformula10_neg}),
neuper@37954:                 (* q   + x^2=0 *)
neuper@37969: 		Thm("d2_sqrt_equation2",num_str @{thm d2_sqrt_equation2}),
neuper@37954:                 (*       x^2=0 *)
neuper@37969: 		Thm("d2_sqrt_equation3",num_str @{thm d2_sqrt_equation3})
neuper@37954:                (*      1x^2=0 *)
neuper@37989: 	       ],scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (* isolate the bound variable in an d2 equation with abcFormula; 
neuper@37954:    'bdv' is a meta-constant*)
neuper@37954: val d2_polyeq_abcFormula_simplify = prep_rls(
neuper@37954:   Rls {id = "d2_polyeq_abcFormula_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord), erls = PolyEq_erls,
neuper@37954:        srls = Erls, calc = [], 
neuper@37969:        rules = [Thm("d2_abcformula1",num_str @{thm d2_abcformula1}),
neuper@37954:                 (*c+bx+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula1_neg",num_str @{thm d2_abcformula1_neg}),
neuper@37954:                 (*c+bx+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula2",num_str @{thm d2_abcformula2}),
neuper@37954:                 (*c+ x+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula2_neg",num_str @{thm d2_abcformula2_neg}),
neuper@37954:                 (*c+ x+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula3",num_str @{thm d2_abcformula3}), 
neuper@37954:                 (*c+bx+ x^2=0 *)
neuper@37969: 		Thm("d2_abcformula3_neg",num_str @{thm d2_abcformula3_neg}),
neuper@37954:                 (*c+bx+ x^2=0 *)
neuper@37969: 		Thm("d2_abcformula4",num_str @{thm d2_abcformula4}),
neuper@37954:                 (*c+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_abcformula4_neg",num_str @{thm d2_abcformula4_neg}),
neuper@37954:                 (*c+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_abcformula5",num_str @{thm d2_abcformula5}),
neuper@37954:                 (*c+   cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula5_neg",num_str @{thm d2_abcformula5_neg}),
neuper@37954:                 (*c+   cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula6",num_str @{thm d2_abcformula6}),
neuper@37954:                 (*c+    x^2=0 *)
neuper@37969: 		Thm("d2_abcformula6_neg",num_str @{thm d2_abcformula6_neg}),
neuper@37954:                 (*c+    x^2=0 *)
neuper@37969: 		Thm("d2_abcformula7",num_str @{thm d2_abcformula7}),
neuper@37954:                 (*  bx+ax^2=0 *)
neuper@37969: 		Thm("d2_abcformula8",num_str @{thm d2_abcformula8}),
neuper@37954:                 (*  bx+ x^2=0 *)
neuper@37969: 		Thm("d2_abcformula9",num_str @{thm d2_abcformula9}),
neuper@37954:                 (*   x+ax^2=0 *)
neuper@37969: 		Thm("d2_abcformula10",num_str @{thm d2_abcformula10}),
neuper@37954:                 (*   x+ x^2=0 *)
neuper@37969: 		Thm("d2_sqrt_equation2",num_str @{thm d2_sqrt_equation2}),
neuper@37954:                 (*      x^2=0 *)  
neuper@37969: 		Thm("d2_sqrt_equation3",num_str @{thm d2_sqrt_equation3})
neuper@37954:                (*     bx^2=0 *)  
neuper@37954: 	       ],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:        }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: 
neuper@37954: (* isolate the bound variable in an d2 equation; 
neuper@37954:    'bdv' is a meta-constant*)
neuper@37954: val d2_polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "d2_polyeq_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord), erls = PolyEq_erls,
neuper@37954:        srls = Erls, calc = [], 
neuper@37969:        rules = [Thm("d2_pqformula1",num_str @{thm d2_pqformula1}),
neuper@37954:                 (* p+qx+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula1_neg",num_str @{thm d2_pqformula1_neg}),
neuper@37954:                 (* p+qx+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula2",num_str @{thm d2_pqformula2}),
neuper@37954:                 (* p+qx+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula2_neg",num_str @{thm d2_pqformula2_neg}),
neuper@37954:                 (* p+qx+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula3",num_str @{thm d2_pqformula3}),
neuper@37954:                 (* p+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula3_neg",num_str @{thm d2_pqformula3_neg}),
neuper@37954:                 (* p+ x+ x^2=0 *)
neuper@37969: 		Thm("d2_pqformula4",num_str @{thm d2_pqformula4}), 
neuper@37954:                 (* p+ x+1x^2=0 *)
neuper@37969: 		Thm("d2_pqformula4_neg",num_str @{thm d2_pqformula4_neg}),
neuper@37954:                 (* p+ x+1x^2=0 *)
neuper@37969: 		Thm("d2_abcformula1",num_str @{thm d2_abcformula1}),
neuper@37954:                 (* c+bx+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula1_neg",num_str @{thm d2_abcformula1_neg}),
neuper@37954:                 (* c+bx+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula2",num_str @{thm d2_abcformula2}),
neuper@37954:                 (* c+ x+cx^2=0 *)
neuper@37969: 		Thm("d2_abcformula2_neg",num_str @{thm d2_abcformula2_neg}),
neuper@37954:                 (* c+ x+cx^2=0 *)
neuper@37969: 		Thm("d2_prescind1",num_str @{thm d2_prescind1}),
neuper@37954:                 (*   ax+bx^2=0 -> x(a+bx)=0 *)
neuper@37969: 		Thm("d2_prescind2",num_str @{thm d2_prescind2}),
neuper@37954:                 (*   ax+ x^2=0 -> x(a+ x)=0 *)
neuper@37969: 		Thm("d2_prescind3",num_str @{thm d2_prescind3}),
neuper@37954:                 (*    x+bx^2=0 -> x(1+bx)=0 *)
neuper@37969: 		Thm("d2_prescind4",num_str @{thm d2_prescind4}),
neuper@37954:                 (*    x+ x^2=0 -> x(1+ x)=0 *)
neuper@37969: 		Thm("d2_isolate_add1",num_str @{thm d2_isolate_add1}),
neuper@37954:                 (* a+   bx^2=0 -> bx^2=(-1)a*)
neuper@37969: 		Thm("d2_isolate_add2",num_str @{thm d2_isolate_add2}),
neuper@37954:                 (* a+    x^2=0 ->  x^2=(-1)a*)
neuper@37969: 		Thm("d2_sqrt_equation1",num_str @{thm d2_sqrt_equation1}),
neuper@37954:                 (* x^2=c   -> x=+-sqrt(c)*)
neuper@37969: 		Thm("d2_sqrt_equation1_neg",num_str @{thm d2_sqrt_equation1_neg}),
neuper@37954:                 (* [c<0] x^2=c   -> x=[]*)
neuper@37969: 		Thm("d2_sqrt_equation2",num_str @{thm d2_sqrt_equation2}),
neuper@37954:                 (*  x^2=0 ->    x=0    *)
neuper@37969: 		Thm("d2_reduce_equation1",num_str @{thm d2_reduce_equation1}),
neuper@37954:                 (* x(a+bx)=0 -> x=0 | a+bx=0*)
neuper@37969: 		Thm("d2_reduce_equation2",num_str @{thm d2_reduce_equation2}),
neuper@37954:                 (* x(a+ x)=0 -> x=0 | a+ x=0*)
neuper@37969: 		Thm("d2_isolate_div",num_str @{thm d2_isolate_div})
neuper@37954:                (* bx^2=c -> x^2=c/b*)
neuper@37954: 	       ],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:       }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: 
neuper@37954: (* -- d3 -- *)
neuper@37954: (* isolate the bound variable in an d3 equation; 'bdv' is a meta-constant *)
neuper@37954: val d3_polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "d3_polyeq_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord), erls = PolyEq_erls,
neuper@37954:        srls = Erls, calc = [], 
neuper@37954:        rules = 
neuper@37969:        [Thm("d3_reduce_equation1",num_str @{thm d3_reduce_equation1}),
neuper@37954: 	(*a*bdv + b*bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (a + b*bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation2",num_str @{thm d3_reduce_equation2}),
neuper@37954: 	(*  bdv + b*bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (1 + b*bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation3",num_str @{thm d3_reduce_equation3}),
neuper@37954: 	(*a*bdv +   bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (a +   bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation4",num_str @{thm d3_reduce_equation4}),
neuper@37954: 	(*  bdv +   bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (1 +   bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation5",num_str @{thm d3_reduce_equation5}),
neuper@37954: 	(*a*bdv + b*bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (a + b*bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation6",num_str @{thm d3_reduce_equation6}),
neuper@37954: 	(*  bdv + b*bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:         (bdv=0 | (1 + b*bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation7",num_str @{thm d3_reduce_equation7}),
neuper@37954: 	     (*a*bdv +   bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (1 +   bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation8",num_str @{thm d3_reduce_equation8}),
neuper@37954: 	     (*  bdv +   bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (1 +   bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation9",num_str @{thm d3_reduce_equation9}),
neuper@37954: 	     (*a*bdv             + c*bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (a         + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation10",num_str @{thm d3_reduce_equation10}),
neuper@37954: 	     (*  bdv             + c*bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (1         + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation11",num_str @{thm d3_reduce_equation11}),
neuper@37954: 	     (*a*bdv             +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (a         +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation12",num_str @{thm d3_reduce_equation12}),
neuper@37954: 	     (*  bdv             +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (1         +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation13",num_str @{thm d3_reduce_equation13}),
neuper@37954: 	     (*        b*bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (    b*bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation14",num_str @{thm d3_reduce_equation14}),
neuper@37954: 	     (*          bdv^^^2 + c*bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (      bdv + c*bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation15",num_str @{thm d3_reduce_equation15}),
neuper@37954: 	     (*        b*bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (    b*bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_reduce_equation16",num_str @{thm d3_reduce_equation16}),
neuper@37954: 	     (*          bdv^^^2 +   bdv^^^3=0) = 
neuper@37954:              (bdv=0 | (      bdv +   bdv^^^2=0)*)
neuper@37969: 	Thm("d3_isolate_add1",num_str @{thm d3_isolate_add1}),
neuper@37954: 	     (*[|Not(bdv occurs_in a)|] ==> (a + b*bdv^^^3=0) = 
neuper@37954:               (bdv=0 | (b*bdv^^^3=a)*)
neuper@37969: 	Thm("d3_isolate_add2",num_str @{thm d3_isolate_add2}),
neuper@37954:              (*[|Not(bdv occurs_in a)|] ==> (a +   bdv^^^3=0) = 
neuper@37954:               (bdv=0 | (  bdv^^^3=a)*)
neuper@37969: 	Thm("d3_isolate_div",num_str @{thm d3_isolate_div}),
neuper@37954:         (*[|Not(b=0)|] ==> (b*bdv^^^3=c) = (bdv^^^3=c/b*)
neuper@37969:         Thm("d3_root_equation2",num_str @{thm d3_root_equation2}),
neuper@37954:         (*(bdv^^^3=0) = (bdv=0) *)
neuper@37969: 	Thm("d3_root_equation1",num_str @{thm d3_root_equation1})
neuper@37954:        (*bdv^^^3=c) = (bdv = nroot 3 c*)
neuper@37954:        ],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:       }:rls);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: 
neuper@37954: (* -- d4 -- *)
neuper@37954: (*isolate the bound variable in an d4 equation; 'bdv' is a meta-constant*)
neuper@37954: val d4_polyeq_simplify = prep_rls(
neuper@37954:   Rls {id = "d4_polyeq_simplify", preconds = [],
neuper@37954:        rew_ord = ("e_rew_ord",e_rew_ord), erls = PolyEq_erls,
neuper@37954:        srls = Erls, calc = [], 
neuper@37954:        rules = 
neuper@37989:        [Thm("d4_sub_u1",num_str @{thm d4_sub_u1})  
neuper@37954:        (* ax^4+bx^2+c=0 -> x=+-sqrt(ax^2+bx^+c) *)
neuper@37954:        ],
neuper@37954:        scr = Script ((term_of o the o (parse thy)) "empty_script")
neuper@37954:       }:rls);
neuper@37954:   
neuper@37954: ruleset' := 
neuper@37967: overwritelthy @{theory} 
neuper@37954:               (!ruleset',
neuper@37954:                [("d0_polyeq_simplify", d0_polyeq_simplify),
neuper@37954:                 ("d1_polyeq_simplify", d1_polyeq_simplify),
neuper@37954:                 ("d2_polyeq_simplify", d2_polyeq_simplify),
neuper@37954:                 ("d2_polyeq_bdv_only_simplify", d2_polyeq_bdv_only_simplify),
neuper@37954:                 ("d2_polyeq_sq_only_simplify", d2_polyeq_sq_only_simplify),
neuper@37954:                 ("d2_polyeq_pqFormula_simplify", d2_polyeq_pqFormula_simplify),
neuper@37954:                 ("d2_polyeq_abcFormula_simplify", 
neuper@37954:                  d2_polyeq_abcFormula_simplify),
neuper@37954:                 ("d3_polyeq_simplify", d3_polyeq_simplify),
neuper@37954: 		("d4_polyeq_simplify", d4_polyeq_simplify)
neuper@37954: 	      ]);
neuper@37989: *}
neuper@37989: ML{*
neuper@37954:     
neuper@37954: (*------------------------problems------------------------*)
neuper@37954: (*
neuper@37954: (get_pbt ["degree_2","polynomial","univariate","equation"]);
neuper@37954: show_ptyps(); 
neuper@37954: *)
neuper@37954: 
neuper@37954: (*-------------------------poly-----------------------*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly" [] e_pblID
neuper@37954:  (["polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37982:    ("#Where" ,["~((e_e::bool) is_ratequation_in (v_v::real))",
neuper@37982: 	       "~((lhs e_e) is_rootTerm_in (v_v::real))",
neuper@37982: 	       "~((rhs e_e) is_rootTerm_in (v_v::real))"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:    ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   []));
neuper@37954: (*--- d0 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg0" [] e_pblID
neuper@37954:  (["degree_0","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_poly_in v_v",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v ) = 0"
neuper@37954: 	      ]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d0_polyeq_equation"]]));
neuper@37954: 
neuper@37954: (*--- d1 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg1" [] e_pblID
neuper@37954:  (["degree_1","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_poly_in v_v",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v ) = 1"
neuper@37954: 	      ]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d1_polyeq_equation"]]));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (*--- d2 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg2" [] e_pblID
neuper@37954:  (["degree_2","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v ) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d2_polyeq_equation"]]));
neuper@37954: 
neuper@37954:  store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg2_sqonly" [] e_pblID
neuper@37954:  (["sq_only","degree_2","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches ( ?a +    ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches ( ?a + ?b*?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (         ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (      ?b*?v_^^^2 = 0) e_e" ,
neuper@37981: 	       "Not (matches (?a +    ?v_ +    ?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (?a + ?b*?v_ +    ?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (?a +    ?v_ + ?c*?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (?a + ?b*?v_ + ?c*?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (        ?v_ +    ?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (     ?b*?v_ +    ?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (        ?v_ + ?c*?v_^^^2 = 0) e_e) &" ^
neuper@37981: 	       "Not (matches (     ?b*?v_ + ?c*?v_^^^2 = 0) e_e)"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d2_polyeq_sqonly_equation"]]));
neuper@37954: 
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg2_bdvonly" [] e_pblID
neuper@37954:  (["bdv_only","degree_2","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a*?v_ +    ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (   ?v_ +    ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (   ?v_ + ?b*?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (?a*?v_ + ?b*?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (            ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (         ?b*?v_^^^2 = 0) e_e "]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d2_polyeq_bdvonly_equation"]]));
neuper@37954: 
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg2_pq" [] e_pblID
neuper@37954:  (["pqFormula","degree_2","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a + 1*?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (?a +   ?v_^^^2 = 0) e_e"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d2_polyeq_pq_equation"]]));
neuper@37954: 
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg2_abc" [] e_pblID
neuper@37954:  (["abcFormula","degree_2","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a +    ?v_^^^2 = 0) e_e | " ^
neuper@37981: 	       "matches (?a + ?b*?v_^^^2 = 0) e_e"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d2_polyeq_abc_equation"]]));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (*--- d3 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg3" [] e_pblID
neuper@37954:  (["degree_3","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 3"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","solve_d3_polyeq_equation"]]));
neuper@37954: 
neuper@37954: (*--- d4 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_deg4" [] e_pblID
neuper@37954:  (["degree_4","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 4"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [(*["PolyEq","solve_d4_polyeq_equation"]*)]));
neuper@37954: 
neuper@37954: (*--- normalize ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_poly_norm" [] e_pblID
neuper@37954:  (["normalize","polynomial","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(Not((matches (?a = 0 ) e_e ))) |" ^
neuper@37981: 	       "(Not(((lhs e_e) is_poly_in v_v)))"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","normalize_poly"]]));
neuper@37954: (*-------------------------expanded-----------------------*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_expand" [] e_pblID
neuper@37954:  (["expanded","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e",
neuper@37981: 	       "(lhs e_e) is_expanded_in v_v "]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:    ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   []));
neuper@37954: 
neuper@37954: (*--- d2 ---*)
neuper@37954: store_pbt
neuper@37972:  (prep_pbt thy "pbl_equ_univ_expand_deg2" [] e_pblID
neuper@37954:  (["degree_2","expanded","univariate","equation"],
neuper@37981:   [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37981:   PolyEq_prls, SOME "solve (e_e::bool, v_v)",
neuper@37954:   [["PolyEq","complete_square"]]));
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37989: val scr =     
neuper@37989:     "Script Normalize_poly (e_e::bool) (v_v::real) =                     " ^
neuper@37989:     "(let e_e =((Try         (Rewrite     all_left          False)) @@  " ^ 
neuper@37989:     "          (Try (Repeat (Rewrite     makex1_x         False))) @@  " ^ 
neuper@37989:     "          (Try (Repeat (Rewrite_Set expand_binoms    False))) @@  " ^ 
neuper@37989:     "          (Try (Repeat (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37989:     "                                 make_ratpoly_in     False))) @@  " ^
neuper@37989:     "          (Try (Repeat (Rewrite_Set polyeq_simplify  False)))) e_e " ^
neuper@37989:     " in (SubProblem (PolyEq',[polynomial,univariate,equation], [no_met])   " ^
neuper@37989:     "                 [BOOL e_e, REAL v_v]))";
neuper@37989: parse thy scr;
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: "-------------------------methods-----------------------";
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq" [] e_metID
neuper@37954:  (["PolyEq"],
neuper@37954:    [],
neuper@37954:    {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational}, "empty_script"));
neuper@37954: 
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_norm" [] e_metID
neuper@37954:  (["PolyEq","normalize_poly"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(Not((matches (?a = 0 ) e_e ))) |" ^
neuper@37981: 	       "(Not(((lhs e_e) is_poly_in v_v)))"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37954:     calc=[],
neuper@37989:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:     "Script Normalize_poly (e_e::bool) (v_v::real) =                     " ^
neuper@37981:     "(let e_e =((Try         (Rewrite     all_left          False)) @@  " ^ 
neuper@37954:     "          (Try (Repeat (Rewrite     makex1_x         False))) @@  " ^ 
neuper@37954:     "          (Try (Repeat (Rewrite_Set expand_binoms    False))) @@  " ^ 
neuper@37989:     "          (Try (Repeat (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                                 make_ratpoly_in     False))) @@  " ^
neuper@37981:     "          (Try (Repeat (Rewrite_Set polyeq_simplify  False)))) e_e " ^
neuper@37989:     " in (SubProblem (PolyEq',[polynomial,univariate,equation], [no_met])   " ^
neuper@37989:     "                 [BOOL e_e, REAL v_v]))"
neuper@37954:    ));
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d0" [] e_metID
neuper@37954:  (["PolyEq","solve_d0_polyeq_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 0"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d0_polyeq_equation  (e_e::bool) (v_v::real)  = " ^
neuper@37989:     "(let e_e =  ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]      " ^
neuper@37981:     "                  d0_polyeq_simplify  False))) e_e        " ^
neuper@37981:     " in ((Or_to_List e_e)::bool list))"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d1" [] e_metID
neuper@37954:  (["PolyEq","solve_d1_polyeq_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 1"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37989:    {rew_ord'="termlessI", rls'=PolyEq_erls, srls=e_rls, prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37989:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d1_polyeq_equation  (e_e::bool) (v_v::real)  =   " ^
neuper@37989:     "(let e_e =  ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]        " ^
neuper@37954:     "                  d1_polyeq_simplify   True))          @@  " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify  False)) @@  " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)            " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d22" [] e_metID
neuper@37954:  (["PolyEq","solve_d2_polyeq_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d2_polyeq_equation  (e_e::bool) (v_v::real) =      " ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                    d2_polyeq_simplify           True)) @@   " ^
neuper@37954:     "             (Try (Rewrite_Set polyeq_simplify   False)) @@  " ^
neuper@37989:     "             (Try (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                    d1_polyeq_simplify            True)) @@  " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify    False)) @@  " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)              " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d2_bdvonly" [] e_metID
neuper@37954:  (["PolyEq","solve_d2_polyeq_bdvonly_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d2_polyeq_bdvonly_equation  (e_e::bool) (v_v::real) =" ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                   d2_polyeq_bdv_only_simplify    True)) @@  " ^
neuper@37954:     "             (Try (Rewrite_Set polyeq_simplify   False)) @@  " ^
neuper@37989:     "             (Try (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                   d1_polyeq_simplify             True)) @@  " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify    False)) @@  " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)              " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d2_sqonly" [] e_metID
neuper@37954:  (["PolyEq","solve_d2_polyeq_sqonly_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d2_polyeq_sqonly_equation  (e_e::bool) (v_v::real) =" ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]          " ^
neuper@37954:     "                   d2_polyeq_sq_only_simplify     True)) @@   " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify    False)) @@   " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e; " ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)               " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d2_pq" [] e_metID
neuper@37954:  (["PolyEq","solve_d2_polyeq_pq_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d2_polyeq_pq_equation  (e_e::bool) (v_v::real) =   " ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]         " ^
neuper@37954:     "                   d2_polyeq_pqFormula_simplify   True)) @@  " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify    False)) @@  " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)              " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d2_abc" [] e_metID
neuper@37954:  (["PolyEq","solve_d2_polyeq_abc_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d2_polyeq_abc_equation  (e_e::bool) (v_v::real) =   " ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]          " ^
neuper@37954:     "                   d2_polyeq_abcFormula_simplify   True)) @@  " ^
neuper@37954:     "            (Try (Rewrite_Set polyeq_simplify     False)) @@  " ^
neuper@37989:     "            (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)               " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:  ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_d3" [] e_metID
neuper@37954:  (["PolyEq","solve_d3_polyeq_equation"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["(lhs e_e) is_poly_in v_v ",
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 3"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",
neuper@37954:     rls'=PolyEq_erls,
neuper@37954:     srls=e_rls,
neuper@37954:     prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37982:    "Script Solve_d3_polyeq_equation  (e_e::bool) (v_v::real) =     " ^
neuper@37989:     "  (let e_e = ((Try (Rewrite_Set_Inst [(bdv,v_v::real)]        " ^
neuper@37954:     "                    d3_polyeq_simplify           True)) @@  " ^
neuper@37954:     "             (Try (Rewrite_Set polyeq_simplify  False)) @@  " ^
neuper@37989:     "             (Try (Rewrite_Set_Inst [(bdv,v_v::real)]        " ^
neuper@37954:     "                    d2_polyeq_simplify           True)) @@  " ^
neuper@37954:     "             (Try (Rewrite_Set polyeq_simplify  False)) @@  " ^
neuper@37989:     "             (Try (Rewrite_Set_Inst [(bdv,v_v::real)]        " ^   
neuper@37954:     "                    d1_polyeq_simplify           True)) @@  " ^
neuper@37954:     "             (Try (Rewrite_Set polyeq_simplify  False)) @@  " ^
neuper@37989:     "             (Try (Rewrite_Set norm_Rational_parenthesized False))) e_e;" ^
neuper@37989:     " (L_L::bool list) = ((Or_to_List e_e)::bool list)             " ^
neuper@37991:     " in Check_elementwise L_LL {(v_v::real). Assumptions} )"
neuper@37954:    ));
neuper@37989: *}
neuper@37989: ML{*
neuper@37954:  (*.solves all expanded (ie. normalized) terms of degree 2.*) 
neuper@37954:  (*Oct.02 restriction: 'eval_true 0 =< discriminant' ony for integer values
neuper@37954:    by 'PolyEq_erls'; restricted until Float.thy is implemented*)
neuper@37954: store_met
neuper@37972:  (prep_met thy "met_polyeq_complsq" [] e_metID
neuper@37954:  (["PolyEq","complete_square"],
neuper@37981:    [("#Given" ,["equality e_e","solveFor v_v"]),
neuper@37981:    ("#Where" ,["matches (?a = 0) e_e", 
neuper@37981: 	       "((lhs e_e) has_degree_in v_v) = 2"]),
neuper@38010:    ("#Find"  ,["solutions v'i'"])
neuper@37954:   ],
neuper@37954:    {rew_ord'="termlessI",rls'=PolyEq_erls,srls=e_rls,prls=PolyEq_prls,
neuper@37982:     calc=[("sqrt", ("NthRoot.sqrt", eval_sqrt "#sqrt_"))],
neuper@37954:     crls=PolyEq_crls, nrls=norm_Rational},
neuper@37989:    "Script Complete_square (e_e::bool) (v_v::real) =                         " ^
neuper@37989:    "(let e_e = " ^ 
neuper@37989:    "    ((Try (Rewrite_Set_Inst [(bdv,v_v)] cancel_leading_coeff True)) " ^
neuper@37989:    "        @@ (Try (Rewrite_Set_Inst [(bdv,v_v)] complete_square True))     " ^
neuper@37954:    "        @@ (Try (Rewrite square_explicit1 False))                       " ^
neuper@37954:    "        @@ (Try (Rewrite square_explicit2 False))                       " ^
neuper@37954:    "        @@ (Rewrite root_plus_minus True)                               " ^
neuper@37989:    "        @@ (Try (Repeat (Rewrite_Inst [(bdv,v_v)] bdv_explicit1 False))) " ^
neuper@37989:    "        @@ (Try (Repeat (Rewrite_Inst [(bdv,v_v)] bdv_explicit2 False))) " ^
neuper@37954:    "        @@ (Try (Repeat                                                 " ^
neuper@37989:    "                  (Rewrite_Inst [(bdv,v_v)] bdv_explicit3 False)))       " ^
neuper@37954:    "        @@ (Try (Rewrite_Set calculate_RootRat False))                  " ^
neuper@37981:    "        @@ (Try (Repeat (Calculate SQRT)))) e_e                         " ^
neuper@37981:    " in ((Or_to_List e_e)::bool list))"
neuper@37954:    ));
neuper@37989: *}
neuper@37989: ML{*
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: 
neuper@37954: fun dest_hd' x (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)
neuper@37954:   | dest_hd' x (Var v) = (v, 2)
neuper@37954:   | dest_hd' x (Bound i) = ((("", i), dummyT), 3)
neuper@37954:   | dest_hd' x (Abs (_, T, _)) = ((("", 0), T), 4);
neuper@37954: 
neuper@37954: fun size_of_term' x (Const ("Atools.pow",_) $ Free (var,_) $ Free (pot,_)) =
neuper@37954:     (case x of                                                          (*WN*)
neuper@37954: 	    (Free (xstr,_)) => 
neuper@37954: 		(if xstr = var then 1000*(the (int_of_str pot)) else 3)
neuper@37954: 	  | _ => raise error ("size_of_term' called with subst = "^
neuper@37954: 			      (term2str 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)
neuper@37954: 	  | _ => raise error ("size_of_term' called with subst = "^
neuper@37954: 			  (term2str 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
neuper@37954:   | size_of_term' x _ = 1;
neuper@37954: 
neuper@37954: 
neuper@37989: fun term_ord' x pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
neuper@37989:       (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@37954:       (if pr then 
neuper@37954: 	 let
neuper@37954: 	   val (f, ts) = strip_comb t and (g, us) = strip_comb u;
neuper@37954: 	   val _=writeln("t= f@ts= \""^
neuper@37954: 	      ((Syntax.string_of_term (thy2ctxt thy)) f)^"\" @ \"["^
neuper@37989: 	      (commas(map (Syntax.string_of_term (thy2ctxt thy)) ts))^"]\"");
neuper@37954: 	   val _=writeln("u= g@us= \""^
neuper@37954: 	      ((Syntax.string_of_term (thy2ctxt thy)) g)^"\" @ \"["^
neuper@37989: 	      (commas(map (Syntax.string_of_term (thy2ctxt thy)) us))^"]\"");
neuper@37954: 	   val _=writeln("size_of_term(t,u)= ("^
neuper@37954: 	      (string_of_int(size_of_term' x t))^", "^
neuper@37954: 	      (string_of_int(size_of_term' x u))^")");
neuper@37954: 	   val _=writeln("hd_ord(f,g)      = "^((pr_ord o (hd_ord x))(f,g)));
neuper@37954: 	   val _=writeln("terms_ord(ts,us) = "^
neuper@37989: 			   ((pr_ord o (terms_ord x) str false)(ts, us)));
neuper@37954: 	   val _=writeln("-------");
neuper@37954: 	 in () end
neuper@37954:        else ();
neuper@37954: 	 case int_ord (size_of_term' x t, size_of_term' x u) of
neuper@37954: 	   EQUAL =>
neuper@37954: 	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
neuper@37954: 	       (case hd_ord x (f, g) of EQUAL => (terms_ord x str pr) (ts, us) 
neuper@37954: 	     | ord => ord)
neuper@37954: 	     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)
neuper@37954: and terms_ord x str pr (ts, us) = 
neuper@37989:     list_ord (term_ord' x pr (assoc_thy "Isac"))(ts, us);
neuper@37954: in
neuper@37954: 
neuper@37954: fun ord_make_polynomial_in (pr:bool) thy subst tu = 
neuper@37954:     let
neuper@37954: 	(* val _=writeln("*** subs variable is: "^(subst2str subst)); *)
neuper@37954:     in
neuper@37954: 	case subst of
neuper@37954: 	    (_,x)::_ => (term_ord' x pr thy tu = LESS)
neuper@37954: 	  | _ => raise error ("ord_make_polynomial_in called with subst = "^
neuper@37954: 			  (subst2str subst))
neuper@37954:     end;
neuper@37989: end;(*local*)
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: val order_add_mult_in = prep_rls(
neuper@37954:   Rls{id = "order_add_mult_in", preconds = [], 
neuper@37954:       rew_ord = ("ord_make_polynomial_in",
neuper@37989: 		 ord_make_polynomial_in false (theory "Poly")),
neuper@37954:       erls = e_rls,srls = Erls,
neuper@37954:       calc = [],
neuper@37954:       (*asm_thm = [],*)
neuper@37969:       rules = [Thm ("real_mult_commute",num_str @{thm real_mult_commute}),
neuper@37954: 	       (* z * w = w * z *)
neuper@37969: 	       Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
neuper@37954: 	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
neuper@37969: 	       Thm ("real_mult_assoc",num_str @{thm real_mult_assoc}),		
neuper@37954: 	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
neuper@37965: 	       Thm ("add_commute",num_str @{thm add_commute}),	
neuper@37954: 	       (*z + w = w + z*)
neuper@37965: 	       Thm ("add_left_commute",num_str @{thm add_left_commute}),
neuper@37954: 	       (*x + (y + z) = y + (x + z)*)
neuper@37965: 	       Thm ("add_assoc",num_str @{thm add_assoc})	               
neuper@37954: 	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
neuper@37954: 	       ], scr = EmptyScr}:rls);
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: val collect_bdv = prep_rls(
neuper@37954:   Rls{id = "collect_bdv", preconds = [], 
neuper@37954:       rew_ord = ("dummy_ord", dummy_ord),
neuper@37954:       erls = e_rls,srls = Erls,
neuper@37954:       calc = [],
neuper@37954:       (*asm_thm = [],*)
neuper@37969:       rules = [Thm ("bdv_collect_1",num_str @{thm bdv_collect_1}),
neuper@37969: 	       Thm ("bdv_collect_2",num_str @{thm bdv_collect_2}),
neuper@37969: 	       Thm ("bdv_collect_3",num_str @{thm bdv_collect_3}),
neuper@37954: 
neuper@37969: 	       Thm ("bdv_collect_assoc1_1",num_str @{thm bdv_collect_assoc1_1}),
neuper@37969: 	       Thm ("bdv_collect_assoc1_2",num_str @{thm bdv_collect_assoc1_2}),
neuper@37969: 	       Thm ("bdv_collect_assoc1_3",num_str @{thm bdv_collect_assoc1_3}),
neuper@37954: 
neuper@37969: 	       Thm ("bdv_collect_assoc2_1",num_str @{thm bdv_collect_assoc2_1}),
neuper@37969: 	       Thm ("bdv_collect_assoc2_2",num_str @{thm bdv_collect_assoc2_2}),
neuper@37969: 	       Thm ("bdv_collect_assoc2_3",num_str @{thm bdv_collect_assoc2_3}),
neuper@37954: 
neuper@37954: 
neuper@37969: 	       Thm ("bdv_n_collect_1",num_str @{thm bdv_n_collect_1}),
neuper@37969: 	       Thm ("bdv_n_collect_2",num_str @{thm bdv_n_collect_2}),
neuper@37969: 	       Thm ("bdv_n_collect_3",num_str @{thm bdv_n_collect_3}),
neuper@37954: 
neuper@37969: 	       Thm ("bdv_n_collect_assoc1_1",num_str @{thm bdv_n_collect_assoc1_1}),
neuper@37969: 	       Thm ("bdv_n_collect_assoc1_2",num_str @{thm bdv_n_collect_assoc1_2}),
neuper@37969: 	       Thm ("bdv_n_collect_assoc1_3",num_str @{thm bdv_n_collect_assoc1_3}),
neuper@37954: 
neuper@37969: 	       Thm ("bdv_n_collect_assoc2_1",num_str @{thm bdv_n_collect_assoc2_1}),
neuper@37969: 	       Thm ("bdv_n_collect_assoc2_2",num_str @{thm bdv_n_collect_assoc2_2}),
neuper@37989: 	       Thm ("bdv_n_collect_assoc2_3",num_str @{thm bdv_n_collect_assoc2_3})
neuper@37954: 	       ], scr = EmptyScr}:rls);
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: (*.transforms an arbitrary term without roots to a polynomial [4] 
neuper@37954:    according to knowledge/Poly.sml.*) 
neuper@37954: val make_polynomial_in = prep_rls(
neuper@37954:   Seq {id = "make_polynomial_in", preconds = []:term list, 
neuper@37954:        rew_ord = ("dummy_ord", dummy_ord),
neuper@37954:       erls = Atools_erls, srls = Erls,
neuper@37954:       calc = [], (*asm_thm = [],*)
neuper@37954:       rules = [Rls_ expand_poly,
neuper@37954: 	       Rls_ order_add_mult_in,
neuper@37954: 	       Rls_ simplify_power,
neuper@37954: 	       Rls_ collect_numerals,
neuper@37954: 	       Rls_ reduce_012,
neuper@37969: 	       Thm ("realpow_oneI",num_str @{thm realpow_oneI}),
neuper@37954: 	       Rls_ discard_parentheses,
neuper@37954: 	       Rls_ collect_bdv
neuper@37954: 	       ],
neuper@37954:       scr = EmptyScr
neuper@37954:       }:rls);     
neuper@37954: 
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: val separate_bdvs = 
neuper@37954:     append_rls "separate_bdvs"
neuper@37954: 	       collect_bdv
neuper@37989: 	       [Thm ("separate_bdv", num_str @{thm separate_bdv}),
neuper@37954: 		(*"?a * ?bdv / ?b = ?a / ?b * ?bdv"*)
neuper@37989: 		Thm ("separate_bdv_n", num_str @{thm separate_bdv_n}),
neuper@37989: 		Thm ("separate_1_bdv", num_str @{thm separate_1_bdv}),
neuper@37954: 		(*"?bdv / ?b = (1 / ?b) * ?bdv"*)
neuper@37989: 		Thm ("separate_1_bdv_n", num_str @{thm separate_1_bdv_n}),
neuper@37954: 		(*"?bdv ^^^ ?n / ?b = 1 / ?b * ?bdv ^^^ ?n"*)
neuper@37990: 		Thm ("add_divide_distrib", 
neuper@37989: 		     num_str @{thm add_divide_distrib})
neuper@37954: 		(*"(?x + ?y) / ?z = ?x / ?z + ?y / ?z"
neuper@37954: 		      WN051031 DOES NOT BELONG TO HERE*)
neuper@37954: 		];
neuper@37989: *}
neuper@37989: ML{*
neuper@37954: val make_ratpoly_in = prep_rls(
neuper@37954:   Seq {id = "make_ratpoly_in", preconds = []:term list, 
neuper@37954:        rew_ord = ("dummy_ord", dummy_ord),
neuper@37954:       erls = Atools_erls, srls = Erls,
neuper@37954:       calc = [], (*asm_thm = [],*)
neuper@37954:       rules = [Rls_ norm_Rational,
neuper@37954: 	       Rls_ order_add_mult_in,
neuper@37954: 	       Rls_ discard_parentheses,
neuper@37954: 	       Rls_ separate_bdvs,
neuper@37954: 	       (* Rls_ rearrange_assoc, WN060916 why does cancel_p not work?*)
neuper@37954: 	       Rls_ cancel_p
neuper@37981: 	       (*Calc ("HOL.divide"  ,eval_cancel "#divide_e") too weak!*)
neuper@37954: 	       ],
neuper@37954:       scr = EmptyScr}:rls);      
neuper@37954: 
neuper@37954: 
neuper@37967: ruleset' := overwritelthy @{theory} (!ruleset',
neuper@37954:   [("order_add_mult_in", order_add_mult_in),
neuper@37954:    ("collect_bdv", collect_bdv),
neuper@37954:    ("make_polynomial_in", make_polynomial_in),
neuper@37954:    ("make_ratpoly_in", make_ratpoly_in),
neuper@37954:    ("separate_bdvs", separate_bdvs)
neuper@37954:    ]);
neuper@37954: *}
neuper@37954: 
neuper@37906: end
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 
neuper@37906: 




