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