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