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