src/Tools/isac/Knowledge/Poly.thy
author wenzelm
Mon, 21 Jun 2021 20:06:12 +0200
changeset 60313 8d89a214aedc
parent 60312 35f7b2f61797
child 60331 40eb8aa2b0d6
permissions -rw-r--r--
Isar command 'calculation' as front-end for KEStore_Elems.add_calcs, without change of semantics;
neuper@37906
     1
(* WN.020812: theorems in the Reals,
neuper@37906
     2
   necessary for special rule sets, in addition to Isabelle2002.
neuper@37906
     3
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
neuper@37906
     4
   !!! THIS IS THE _least_ NUMBER OF ADDITIONAL THEOREMS !!!
neuper@37906
     5
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
walther@60242
     6
   xxxI contain \<up> instead of ^ in the respective theorem xxx in 2002
neuper@37906
     7
   changed by: Richard Lang 020912
neuper@37906
     8
*)
neuper@37906
     9
neuper@37950
    10
theory Poly imports Simplify begin
neuper@37906
    11
wneuper@59523
    12
subsection \<open>remark on term-structure of polynomials\<close>
wneuper@59523
    13
text \<open>
wneuper@59523
    14
WN190319:
wneuper@59523
    15
the code below reflects missing coordination between two authors:
wneuper@59523
    16
* ML: built the equation solver; simple rule-sets, programs; better predicates for specifications.
wneuper@59523
    17
* MG: built simplification of polynomials with AC rewriting by ML code
wneuper@59523
    18
wneuper@59523
    19
WN020919:
wneuper@59523
    20
*** there are 5 kinds of expanded normalforms ***
wneuper@59523
    21
wneuper@59523
    22
[1] 'complete polynomial' (Komplettes Polynom), univariate
wneuper@59523
    23
   a_0 + a_1.x^1 +...+ a_n.x^n   not (a_n = 0)
wneuper@59523
    24
	        not (a_n = 0), some a_i may be zero (DON'T disappear),
wneuper@59523
    25
                variables in monomials lexicographically ordered and complete,
wneuper@59523
    26
                x written as 1*x^1, ...
wneuper@59523
    27
[2] 'polynomial' (Polynom), univariate and multivariate
wneuper@59523
    28
   a_0 + a_1.x +...+ a_n.x^n   not (a_n = 0)
wneuper@59523
    29
   a_0 + a_1.x_1.x_2^n_12...x_m^n_1m +...+  a_n.x_1^n.x_2^n_n2...x_m^n_nm
wneuper@59523
    30
	        not (a_n = 0), some a_i may be zero (ie. monomials disappear),
wneuper@59523
    31
                exponents and coefficients equal 1 are not (WN060904.TODO in cancel_p_)shown,
wneuper@59523
    32
                and variables in monomials are lexicographically ordered  
walther@60242
    33
   examples: [1]: "1 + (-10) * x \<up> 1 + 25 * x \<up> 2"
walther@60242
    34
	     [1]: "11 + 0 * x \<up> 1 + 1 * x \<up> 2"
walther@60242
    35
	     [2]: "x + (-50) * x \<up> 3"
walther@60242
    36
	     [2]: "(-1) * x * y \<up> 2 + 7 * x \<up> 3"
wneuper@59523
    37
wneuper@59523
    38
[3] 'expanded_term' (Ausmultiplizierter Term):
wneuper@59523
    39
   pull out unary minus to binary minus, 
wneuper@59523
    40
   as frequently exercised in schools; other conditions for [2] hold however
walther@60242
    41
   examples: "a \<up> 2 - 2 * a * b + b \<up> 2"
walther@60242
    42
	     "4 * x \<up> 2 - 9 * y \<up> 2"
wneuper@59523
    43
[4] 'polynomial_in' (Polynom in): 
wneuper@59523
    44
   polynomial in 1 variable with arbitrary coefficients
walther@60242
    45
   examples: "2 * x + (-50) * x \<up> 3"                     (poly in x)
walther@60242
    46
	     "(u + v) + (2 * u \<up> 2) * a + (-u) * a \<up> 2 (poly in a)
wneuper@59523
    47
[5] 'expanded_in' (Ausmultiplizierter Termin in): 
wneuper@59523
    48
   analoguous to [3] with binary minus like [3]
walther@60242
    49
   examples: "2 * x - 50 * x \<up> 3"                     (expanded in x)
walther@60242
    50
	     "(u + v) + (2 * u \<up> 2) * a - u * a \<up> 2 (expanded in a)
wneuper@59523
    51
\<close>
wneuper@59523
    52
subsection \<open>consts definition for predicates in specifications\<close>
neuper@37906
    53
consts
neuper@37906
    54
walther@60278
    55
  is_expanded_in :: "[real, real] => bool" ("_ is'_expanded'_in _") 
walther@60278
    56
  is_poly_in     :: "[real, real] => bool" ("_ is'_poly'_in _")   (*RL DA *)
walther@60278
    57
  has_degree_in  :: "[real, real] => real" ("_ has'_degree'_in _")(*RL DA *)
walther@60278
    58
  is_polyrat_in  :: "[real, real] => bool" ("_ is'_polyrat'_in _")(*RL030626*)
neuper@37906
    59
walther@60278
    60
  is_multUnordered:: "real => bool" ("_ is'_multUnordered") 
walther@60278
    61
  is_addUnordered :: "real => bool" ("_ is'_addUnordered") (*WN030618*)
walther@60278
    62
  is_polyexp      :: "real => bool" ("_ is'_polyexp") 
neuper@37906
    63
wneuper@59523
    64
subsection \<open>theorems not yet adopted from Isabelle\<close>
neuper@52148
    65
axiomatization where (*.not contained in Isabelle2002,
neuper@37906
    66
         stated as axioms, TODO: prove as theorems;
walther@60242
    67
         theorem-IDs 'xxxI' with \<up> instead of ^ in 'xxx' in Isabelle2002.*)
neuper@37906
    68
walther@60242
    69
  realpow_pow:             "(a \<up> b) \<up> c = a \<up> (b * c)" and
walther@60242
    70
  realpow_addI:            "r \<up> (n + m) = r \<up> n * r \<up> m" and
walther@60242
    71
  realpow_addI_assoc_l:    "r \<up> n * (r \<up> m * s) = r \<up> (n + m) * s" and
walther@60242
    72
  realpow_addI_assoc_r:    "s * r \<up> n * r \<up> m = s * r \<up> (n + m)" and
neuper@37906
    73
		  
walther@60242
    74
  realpow_oneI:            "r \<up> 1 = r" and
walther@60242
    75
  realpow_zeroI:            "r \<up> 0 = 1" and
walther@60242
    76
  realpow_eq_oneI:         "1 \<up> n = 1" and
walther@60242
    77
  realpow_multI:           "(r * s) \<up> n = r \<up> n * s \<up> n"  and
neuper@37974
    78
  realpow_multI_poly:      "[| r is_polyexp; s is_polyexp |] ==>
walther@60242
    79
			      (r * s) \<up> n = r \<up> n * s \<up> n"  and
walther@60242
    80
  realpow_minus_oneI:      "(- 1) \<up> (2 * n) = 1"  and 
wneuper@59589
    81
  real_diff_0:		         "0 - x = - (x::real)" and
neuper@37906
    82
walther@60242
    83
  realpow_twoI:            "r \<up> 2 = r * r" and
walther@60242
    84
  realpow_twoI_assoc_l:	  "r * (r * s) = r \<up> 2 * s" and
walther@60242
    85
  realpow_twoI_assoc_r:	  "s * r * r = s * r \<up> 2" and
walther@60242
    86
  realpow_two_atom:        "r is_atom ==> r * r = r \<up> 2" and
walther@60242
    87
  realpow_plus_1:          "r * r \<up> n = r \<up> (n + 1)"   and       
walther@60242
    88
  realpow_plus_1_assoc_l:  "r * (r \<up> m * s) = r \<up> (1 + m) * s"  and
walther@60242
    89
  realpow_plus_1_assoc_l2: "r \<up> m * (r * s) = r \<up> (1 + m) * s"  and
walther@60242
    90
  realpow_plus_1_assoc_r:  "s * r * r \<up> m = s * r \<up> (1 + m)" and
walther@60242
    91
  realpow_plus_1_atom:     "r is_atom ==> r * r \<up> n = r \<up> (1 + n)" and
neuper@37974
    92
  realpow_def_atom:        "[| Not (r is_atom); 1 < n |]
walther@60242
    93
			   ==> r \<up> n = r * r \<up> (n + -1)" and
walther@60242
    94
  realpow_addI_atom:       "r is_atom ==> r \<up> n * r \<up> m = r \<up> (n + m)" and
neuper@37906
    95
neuper@37906
    96
walther@60278
    97
  realpow_minus_even:	     "n is_even ==> (- r) \<up> n = r \<up> n" and
walther@60242
    98
  realpow_minus_odd:       "Not (n is_even) ==> (- r) \<up> n = -1 * r \<up> n" and
neuper@37906
    99
neuper@37906
   100
neuper@37906
   101
(* RL 020914 *)
neuper@52148
   102
  real_pp_binom_times:     "(a + b)*(c + d) = a*c + a*d + b*c + b*d" and
neuper@52148
   103
  real_pm_binom_times:     "(a + b)*(c - d) = a*c - a*d + b*c - b*d" and
neuper@52148
   104
  real_mp_binom_times:     "(a - b)*(c + d) = a*c + a*d - b*c - b*d" and
neuper@52148
   105
  real_mm_binom_times:     "(a - b)*(c - d) = a*c - a*d - b*c + b*d" and
walther@60242
   106
  real_plus_binom_pow3:    "(a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" and
neuper@37974
   107
  real_plus_binom_pow3_poly: "[| a is_polyexp; b is_polyexp |] ==> 
walther@60242
   108
			    (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" and
walther@60242
   109
  real_minus_binom_pow3:   "(a - b) \<up> 3 = a \<up> 3 - 3*a \<up> 2*b + 3*a*b \<up> 2 - b \<up> 3" and
walther@60242
   110
  real_minus_binom_pow3_p: "(a + -1 * b) \<up> 3 = a \<up> 3 + -3*a \<up> 2*b + 3*a*b \<up> 2 +
walther@60242
   111
                           -1*b \<up> 3" and
neuper@37974
   112
(* real_plus_binom_pow:        "[| n is_const;  3 < n |] ==>
walther@60260
   113
			       (a + b) \<up> n = (a + b) * (a + b)\<up>(n - 1)" *)
walther@60242
   114
  real_plus_binom_pow4:   "(a + b) \<up> 4 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
neuper@52148
   115
                           *(a + b)" and
neuper@37974
   116
  real_plus_binom_pow4_poly: "[| a is_polyexp; b is_polyexp |] ==> 
walther@60242
   117
			   (a + b) \<up> 4 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
neuper@52148
   118
                           *(a + b)" and
walther@60242
   119
  real_plus_binom_pow5:    "(a + b) \<up> 5 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
walther@60242
   120
                           *(a \<up> 2 + 2*a*b + b \<up> 2)" and
neuper@37974
   121
  real_plus_binom_pow5_poly: "[| a is_polyexp; b is_polyexp |] ==> 
walther@60242
   122
			        (a + b) \<up> 5 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 
walther@60242
   123
                                + b \<up> 3)*(a \<up> 2 + 2*a*b + b \<up> 2)" and
neuper@52148
   124
  real_diff_plus:          "a - b = a + -b" (*17.3.03: do_NOT_use*) and
neuper@52148
   125
  real_diff_minus:         "a - b = a + -1 * b" and
walther@60242
   126
  real_plus_binom_times:   "(a + b)*(a + b) = a \<up> 2 + 2*a*b + b \<up> 2" and
walther@60242
   127
  real_minus_binom_times:  "(a - b)*(a - b) = a \<up> 2 - 2*a*b + b \<up> 2" and
neuper@37906
   128
  (*WN071229 changed for Schaerding -----vvv*)
walther@60260
   129
  (*real_plus_binom_pow2:  "(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
walther@60242
   130
  real_plus_binom_pow2:    "(a + b) \<up> 2 = (a + b) * (a + b)" and
walther@60242
   131
  (*WN071229 changed for Schaerding -----\<up>*)
neuper@37974
   132
  real_plus_binom_pow2_poly: "[| a is_polyexp; b is_polyexp |] ==>
walther@60242
   133
			       (a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2" and
walther@60242
   134
  real_minus_binom_pow2:      "(a - b) \<up> 2 = a \<up> 2 - 2*a*b + b \<up> 2" and
walther@60242
   135
  real_minus_binom_pow2_p:    "(a - b) \<up> 2 = a \<up> 2 + -2*a*b + b \<up> 2" and
walther@60242
   136
  real_plus_minus_binom1:     "(a + b)*(a - b) = a \<up> 2 - b \<up> 2" and
walther@60242
   137
  real_plus_minus_binom1_p:   "(a + b)*(a - b) = a \<up> 2 + -1*b \<up> 2" and
walther@60242
   138
  real_plus_minus_binom1_p_p: "(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2" and
walther@60242
   139
  real_plus_minus_binom2:     "(a - b)*(a + b) = a \<up> 2 - b \<up> 2" and
walther@60242
   140
  real_plus_minus_binom2_p:   "(a - b)*(a + b) = a \<up> 2 + -1*b \<up> 2" and
walther@60242
   141
  real_plus_minus_binom2_p_p: "(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2" and
walther@60242
   142
  real_plus_binom_times1:     "(a +  1*b)*(a + -1*b) = a \<up> 2 + -1*b \<up> 2" and
walther@60242
   143
  real_plus_binom_times2:     "(a + -1*b)*(a +  1*b) = a \<up> 2 + -1*b \<up> 2" and
neuper@37906
   144
neuper@37974
   145
  real_num_collect:           "[| l is_const; m is_const |] ==>
neuper@52148
   146
			      l * n + m * n = (l + m) * n" and
neuper@37906
   147
(* FIXME.MG.0401: replace 'real_num_collect_assoc' 
neuper@37906
   148
	by 'real_num_collect_assoc_l' ... are equal, introduced by MG ! *)
neuper@37974
   149
  real_num_collect_assoc:     "[| l is_const; m is_const |] ==> 
neuper@52148
   150
			      l * n + (m * n + k) = (l + m) * n + k" and
neuper@37974
   151
  real_num_collect_assoc_l:   "[| l is_const; m is_const |] ==>
neuper@37950
   152
			      l * n + (m * n + k) = (l + m)
neuper@52148
   153
				* n + k" and
neuper@37974
   154
  real_num_collect_assoc_r:   "[| l is_const; m is_const |] ==>
neuper@52148
   155
			      (k + m * n) + l * n = k + (l + m) * n" and
neuper@52148
   156
  real_one_collect:           "m is_const ==> n + m * n = (1 + m) * n" and
neuper@37906
   157
(* FIXME.MG.0401: replace 'real_one_collect_assoc' 
neuper@37906
   158
	by 'real_one_collect_assoc_l' ... are equal, introduced by MG ! *)
neuper@52148
   159
  real_one_collect_assoc:     "m is_const ==> n + (m * n + k) = (1 + m)* n + k" and
neuper@37906
   160
neuper@52148
   161
  real_one_collect_assoc_l:   "m is_const ==> n + (m * n + k) = (1 + m) * n + k" and
neuper@52148
   162
  real_one_collect_assoc_r:  "m is_const ==> (k + n) +  m * n = k + (1 + m) * n" and
neuper@37906
   163
neuper@37906
   164
(* FIXME.MG.0401: replace 'real_mult_2_assoc' 
neuper@37906
   165
	by 'real_mult_2_assoc_l' ... are equal, introduced by MG ! *)
neuper@52148
   166
  real_mult_2_assoc:          "z1 + (z1 + k) = 2 * z1 + k" and
neuper@52148
   167
  real_mult_2_assoc_l:        "z1 + (z1 + k) = 2 * z1 + k" and
neuper@52148
   168
  real_mult_2_assoc_r:        "(k + z1) + z1 = k + 2 * z1" and
neuper@37906
   169
wneuper@59587
   170
  real_mult_left_commute: "z1 * (z2 * z3) = z2 * (z1 * z3)" and
wneuper@59587
   171
  real_mult_minus1:       "-1 * z = - (z::real)" and
wneuper@59587
   172
  real_mult_2:            "2 * z = z + (z::real)" and
wneuper@59587
   173
neuper@52148
   174
  real_add_mult_distrib_poly: "w is_polyexp ==> (z1 + z2) * w = z1 * w + z2 * w" and
neuper@37974
   175
  real_add_mult_distrib2_poly:"w is_polyexp ==> w * (z1 + z2) = w * z1 + w * z2"
neuper@37950
   176
walther@60278
   177
wneuper@59523
   178
subsection \<open>auxiliary functions\<close>
wneuper@59530
   179
ML \<open>
wneuper@59530
   180
val poly_consts =
wenzelm@60309
   181
  [\<^const_name>\<open>plus\<close>, \<^const_name>\<open>minus\<close>,
wenzelm@60309
   182
  \<^const_name>\<open>divide\<close>, \<^const_name>\<open>times\<close>,
wenzelm@60309
   183
  \<^const_name>\<open>powr\<close>];
wneuper@59530
   184
\<close>
wneuper@59523
   185
subsubsection \<open>for predicates in specifications (ML)\<close>
wneuper@59472
   186
ML \<open>
wneuper@59522
   187
(*--- auxiliary for is_expanded_in, is_poly_in, has_degree_in ---*)
wneuper@59522
   188
(*. a 'monomial t in variable v' is a term t with
wneuper@59522
   189
  either (1) v NOT existent in t, or (2) v contained in t,
wneuper@59522
   190
  if (1) then degree 0
wneuper@59522
   191
  if (2) then v is a factor on the very right, ev. with exponent.*)
wneuper@59522
   192
fun factor_right_deg (*case 2*)
wenzelm@60309
   193
	    (Const (\<^const_name>\<open>times\<close>, _) $ t1 $ (Const (\<^const_name>\<open>powr\<close>,_) $ vv $ Free (d, _))) v =
walther@59603
   194
	   if vv = v andalso not (Prog_Expr.occurs_in v t1) then SOME (TermC.int_of_str d) else NONE
wenzelm@60309
   195
  | factor_right_deg (Const (\<^const_name>\<open>powr\<close>,_) $ vv $ Free (d,_)) v =
wneuper@59522
   196
	   if (vv = v) then SOME (TermC.int_of_str d) else NONE
wenzelm@60309
   197
  | factor_right_deg (Const (\<^const_name>\<open>times\<close>,_) $ t1 $ vv) v = 
walther@59603
   198
	   if vv = v andalso not (Prog_Expr.occurs_in v t1) then SOME 1 else NONE
wneuper@59522
   199
  | factor_right_deg vv v =
wneuper@59522
   200
	  if (vv = v) then SOME 1 else NONE;    
wneuper@59522
   201
fun mono_deg_in m v =  (*case 1*)
walther@59603
   202
	if not (Prog_Expr.occurs_in v m) then (*case 1*) SOME 0 else factor_right_deg m v;
wneuper@59522
   203
wneuper@59522
   204
fun expand_deg_in t v =
wneuper@59522
   205
	let
wenzelm@60309
   206
    fun edi ~1 ~1 (Const (\<^const_name>\<open>plus\<close>, _) $ t1 $ t2) =
wneuper@59522
   207
          (case mono_deg_in t2 v of (* $ is left associative*)
wneuper@59522
   208
            SOME d' => edi d' d' t1 | NONE => NONE)
wenzelm@60309
   209
      | edi ~1 ~1 (Const (\<^const_name>\<open>minus\<close>, _) $ t1 $ t2) =
wneuper@59522
   210
          (case mono_deg_in t2 v of
wneuper@59522
   211
            SOME d' => edi d' d' t1 | NONE => NONE)
wenzelm@60309
   212
      | edi d dmax (Const (\<^const_name>\<open>minus\<close>, _) $ t1 $ t2) =
wneuper@59522
   213
          (case mono_deg_in t2 v of (*(d = 0 andalso d' = 0) handle 3+4-...4 +x*)
wneuper@59522
   214
	        SOME d' => if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
wneuper@59522
   215
          | NONE => NONE)
wenzelm@60309
   216
      | edi d dmax (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
wneuper@59522
   217
          (case mono_deg_in t2 v of
wneuper@59522
   218
            SOME d' =>    (*RL (d = 0 andalso d' = 0) need to handle 3+4-...4 +x*)
wneuper@59522
   219
              if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
wneuper@59522
   220
          | NONE => NONE)
wneuper@59522
   221
      | edi ~1 ~1 t =
wneuper@59522
   222
          (case mono_deg_in t v of d as SOME _ => d | NONE => NONE)
wneuper@59522
   223
      | edi d dmax t = (*basecase last*)
wneuper@59522
   224
    	    (case mono_deg_in t v of
wneuper@59522
   225
    	      SOME d' => if d > d' orelse (d = 0 andalso d' = 0) then SOME dmax else NONE
wneuper@59522
   226
		      | NONE => NONE)
wneuper@59522
   227
	in edi ~1 ~1 t end;
wneuper@59522
   228
wneuper@59522
   229
fun poly_deg_in t v =
wneuper@59522
   230
	let
wenzelm@60309
   231
    fun edi ~1 ~1 (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
wneuper@59522
   232
		    (case mono_deg_in t2 v of (* $ is left associative *)
wneuper@59522
   233
		      SOME d' => edi d' d' t1
wneuper@59522
   234
        | NONE => NONE)
wenzelm@60309
   235
	    | edi d dmax (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
wneuper@59522
   236
		    (case mono_deg_in t2 v of
wneuper@59522
   237
	        SOME d' =>    (*RL (d = 0 andalso (d' = 0)) handle 3+4-...4 +x*)
wneuper@59522
   238
            if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
wneuper@59522
   239
        | NONE => NONE)
wneuper@59522
   240
	    | edi ~1 ~1 t =
wneuper@59522
   241
        (case mono_deg_in t v of
wneuper@59522
   242
		      d as SOME _ => d
wneuper@59522
   243
        | NONE => NONE)
wneuper@59522
   244
	    | edi d dmax t = (* basecase last *)
wneuper@59522
   245
		    (case mono_deg_in t v of
wneuper@59522
   246
		      SOME d' =>
wneuper@59522
   247
            if d > d' orelse (d = 0 andalso d' = 0) then SOME dmax else NONE
wneuper@59522
   248
        | NONE => NONE)
wneuper@59522
   249
	in edi ~1 ~1 t end;
wneuper@59523
   250
\<close>
neuper@37950
   251
wneuper@59523
   252
subsubsection \<open>for hard-coded AC rewriting (MG)\<close>
wneuper@59523
   253
ML \<open>
wneuper@59523
   254
(**. MG.03: make_polynomial_ ... uses SML-fun for ordering .**)
neuper@37950
   255
wneuper@59523
   256
(*FIXME.0401: make SML-order local to make_polynomial(_) *)
wneuper@59523
   257
(*FIXME.0401: replace 'make_polynomial'(old) by 'make_polynomial_'(MG) *)
wneuper@59523
   258
(* Polynom --> List von Monomen *) 
wenzelm@60309
   259
fun poly2list (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) = 
wneuper@59523
   260
    (poly2list t1) @ (poly2list t2)
wneuper@59523
   261
  | poly2list t = [t];
neuper@37950
   262
wneuper@59523
   263
(* Monom --> Liste von Variablen *)
wenzelm@60309
   264
fun monom2list (Const (\<^const_name>\<open>times\<close>,_) $ t1 $ t2) = 
wneuper@59523
   265
    (monom2list t1) @ (monom2list t2)
wneuper@59523
   266
  | monom2list t = [t];
neuper@37950
   267
wneuper@59523
   268
(* liefert Variablenname (String) einer Variablen und Basis bei Potenz *)
wenzelm@60309
   269
fun get_basStr (Const (\<^const_name>\<open>powr\<close>,_) $ Free (str, _) $ _) = str
wneuper@59523
   270
  | get_basStr (Free (str, _)) = str
wneuper@59523
   271
  | get_basStr _ = "|||"; (* gross gewichtet; für Brüch ect. *)
wneuper@59523
   272
(*| get_basStr t = 
walther@59962
   273
    raise ERROR("get_basStr: called with t= "^(UnparseC.term t));*)
neuper@37950
   274
wneuper@59523
   275
(* liefert Hochzahl (String) einer Variablen bzw Gewichtstring (zum Sortieren) *)
wenzelm@60309
   276
fun get_potStr (Const (\<^const_name>\<open>powr\<close>,_) $ Free _ $ Free (str, _)) = str
wenzelm@60309
   277
  | get_potStr (Const (\<^const_name>\<open>powr\<close>,_) $ Free _ $ _ ) = "|||" (* gross gewichtet *)
wneuper@59523
   278
  | get_potStr (Free (_, _)) = "---" (* keine Hochzahl --> kleinst gewichtet *)
wneuper@59523
   279
  | get_potStr _ = "||||||"; (* gross gewichtet; für Brüch ect. *)
wneuper@59523
   280
(*| get_potStr t = 
walther@59962
   281
    raise ERROR("get_potStr: called with t= "^(UnparseC.term t));*)
neuper@37978
   282
wneuper@59523
   283
(* Umgekehrte string_ord *)
wneuper@59523
   284
val string_ord_rev =  rev_order o string_ord;
wneuper@59523
   285
		
wneuper@59523
   286
 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen) 
wneuper@59523
   287
    innerhalb eines Monomes:
wneuper@59523
   288
    - zuerst lexikographisch nach Variablenname 
wneuper@59523
   289
    - wenn gleich: nach steigender Potenz *)
wneuper@59523
   290
fun var_ord (a,b: term) = prod_ord string_ord string_ord 
wneuper@59523
   291
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
neuper@37950
   292
wneuper@59523
   293
(* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen); 
wneuper@59523
   294
   verwendet zum Sortieren von Monomen mittels Gesamtgradordnung:
wneuper@59523
   295
   - zuerst lexikographisch nach Variablenname 
wneuper@59523
   296
   - wenn gleich: nach sinkender Potenz*)
wneuper@59523
   297
fun var_ord_revPow (a,b: term) = prod_ord string_ord string_ord_rev 
wneuper@59523
   298
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
neuper@37950
   299
wneuper@59523
   300
wneuper@59523
   301
(* Ordnet ein Liste von Variablen (und Potenzen) lexikographisch *)
wneuper@59523
   302
val sort_varList = sort var_ord;
wneuper@59523
   303
wneuper@59523
   304
(* Entfernet aeussersten Operator (Wurzel) aus einem Term und schreibt 
wneuper@59523
   305
   Argumente in eine Liste *)
wneuper@59523
   306
fun args u : term list =
wneuper@59523
   307
    let fun stripc (f$t, ts) = stripc (f, t::ts)
wneuper@59523
   308
	  | stripc (t as Free _, ts) = (t::ts)
wneuper@59523
   309
	  | stripc (_, ts) = ts
wneuper@59523
   310
    in stripc (u, []) end;
wneuper@59523
   311
                                    
wneuper@59523
   312
(* liefert True, falls der Term (Liste von Termen) nur Zahlen 
wneuper@59523
   313
   (keine Variablen) enthaelt *)
wneuper@59523
   314
fun filter_num [] = true
wneuper@59523
   315
  | filter_num [Free x] = if (TermC.is_num (Free x)) then true
wneuper@59523
   316
				else false
wneuper@59523
   317
  | filter_num ((Free _)::_) = false
wneuper@59523
   318
  | filter_num ts =
wneuper@59523
   319
    (filter_num o (filter_out TermC.is_num) o flat o (map args)) ts;
wneuper@59523
   320
wneuper@59523
   321
(* liefert True, falls der Term nur Zahlen (keine Variablen) enthaelt 
wneuper@59523
   322
   dh. er ist ein numerischer Wert und entspricht einem Koeffizienten *)
wneuper@59523
   323
fun is_nums t = filter_num [t];
wneuper@59523
   324
wneuper@59523
   325
(* Berechnet den Gesamtgrad eines Monoms *)
wneuper@59523
   326
local 
wneuper@59523
   327
    fun counter (n, []) = n
wneuper@59523
   328
      | counter (n, x :: xs) = 
wneuper@59523
   329
	if (is_nums x) then
wneuper@59523
   330
	    counter (n, xs) 
wneuper@59523
   331
	else 
wneuper@59523
   332
	    (case x of 
wenzelm@60309
   333
		 (Const (\<^const_name>\<open>powr\<close>, _) $ Free _ $ Free (str_h, T)) => 
wneuper@59523
   334
		     if (is_nums (Free (str_h, T))) then
walther@59875
   335
			 counter (n + (the (TermC.int_opt_of_string str_h)), xs)
wneuper@59523
   336
		     else counter (n + 1000, xs) (*FIXME.MG?!*)
wenzelm@60309
   337
	       | (Const (\<^const_name>\<open>powr\<close>, _) $ Free _ $ _ ) => 
wneuper@59523
   338
		     counter (n + 1000, xs) (*FIXME.MG?!*)
wneuper@59523
   339
	       | (Free _) => counter (n + 1, xs)
walther@59962
   340
	     (*| _ => raise ERROR("monom_degree: called with factor: "^(UnparseC.term x)))*)
wneuper@59523
   341
	       | _ => counter (n + 10000, xs)) (*FIXME.MG?! ... Brüche ect.*)
wneuper@59523
   342
in  
wneuper@59523
   343
    fun monom_degree l = counter (0, l) 
wneuper@59523
   344
end;(*local*)
wneuper@59523
   345
wneuper@59523
   346
(* wie Ordnung dict_ord (lexicographische Ordnung zweier Listen, mit Vergleich 
wneuper@59523
   347
   der Listen-Elemente mit elem_ord) - Elemente die Bedingung cond erfuellen, 
wneuper@59523
   348
   werden jedoch dabei ignoriert (uebersprungen)  *)
wneuper@59523
   349
fun dict_cond_ord _ _ ([], []) = EQUAL
wneuper@59523
   350
  | dict_cond_ord _ _ ([], _ :: _) = LESS
wneuper@59523
   351
  | dict_cond_ord _ _ (_ :: _, []) = GREATER
wneuper@59523
   352
  | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
wneuper@59523
   353
    (case (cond x, cond y) of 
wneuper@59523
   354
	 (false, false) => (case elem_ord (x, y) of 
wneuper@59523
   355
				EQUAL => dict_cond_ord elem_ord cond (xs, ys) 
wneuper@59523
   356
			      | ord => ord)
wneuper@59523
   357
       | (false, true)  => dict_cond_ord elem_ord cond (x :: xs, ys)
wneuper@59523
   358
       | (true, false)  => dict_cond_ord elem_ord cond (xs, y :: ys)
wneuper@59523
   359
       | (true, true)  =>  dict_cond_ord elem_ord cond (xs, ys) );
wneuper@59523
   360
wneuper@59523
   361
(* Gesamtgradordnung zum Vergleich von Monomen (Liste von Variablen/Potenzen):
wneuper@59523
   362
   zuerst nach Gesamtgrad, bei gleichem Gesamtgrad lexikographisch ordnen - 
walther@60260
   363
   dabei werden Koeffizienten ignoriert (2*3*a \<up> 2*4*b gilt wie a \<up> 2*b) *)
wneuper@59523
   364
fun degree_ord (xs, ys) =
wneuper@59523
   365
	    prod_ord int_ord (dict_cond_ord var_ord_revPow is_nums) 
wneuper@59523
   366
	    ((monom_degree xs, xs), (monom_degree ys, ys));
wneuper@59523
   367
wneuper@59523
   368
fun hd_str str = substring (str, 0, 1);
wneuper@59523
   369
fun tl_str str = substring (str, 1, (size str) - 1);
wneuper@59523
   370
wneuper@59523
   371
(* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
walther@59962
   372
fun get_koeff_of_mon [] =  raise ERROR("get_koeff_of_mon: called with l = []")
wneuper@59523
   373
  | get_koeff_of_mon (x::_) = if is_nums x then SOME x else NONE;
wneuper@59523
   374
wneuper@59523
   375
(* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
wneuper@59523
   376
fun koeff2ordStr (SOME x) = (case x of 
wneuper@59523
   377
				 (Free (str, _)) => 
wneuper@59523
   378
				     if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
wneuper@59523
   379
				     else str
wneuper@59523
   380
			       | _ => "aaa") (* "num.Ausdruck" --> gross *)
wneuper@59523
   381
  | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
wneuper@59523
   382
wneuper@59523
   383
(* Order zum Vergleich von Koeffizienten (strings): 
wneuper@59523
   384
   "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
wneuper@59523
   385
fun compare_koeff_ord (xs, ys) = 
wneuper@59523
   386
    string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
wneuper@59523
   387
		(koeff2ordStr o get_koeff_of_mon) ys);
wneuper@59523
   388
wneuper@59523
   389
(* Gesamtgradordnung degree_ord + Ordnen nach Koeffizienten falls EQUAL *)
wneuper@59523
   390
fun koeff_degree_ord (xs, ys) =
wneuper@59523
   391
	    prod_ord degree_ord compare_koeff_ord ((xs, xs), (ys, ys));
wneuper@59523
   392
wneuper@59523
   393
(* Ordnet ein Liste von Monomen (Monom = Liste von Variablen) mittels 
wneuper@59523
   394
   Gesamtgradordnung *)
wneuper@59523
   395
val sort_monList = sort koeff_degree_ord;
wneuper@59523
   396
wneuper@59523
   397
(* Alternativ zu degree_ord koennte auch die viel einfachere und 
wneuper@59523
   398
   kuerzere Ordnung simple_ord verwendet werden - ist aber nicht 
wneuper@59523
   399
   fuer unsere Zwecke geeignet!
wneuper@59523
   400
wneuper@59523
   401
fun simple_ord (al,bl: term list) = dict_ord string_ord 
wneuper@59523
   402
	 (map get_basStr al, map get_basStr bl); 
wneuper@59523
   403
wneuper@59523
   404
val sort_monList = sort simple_ord; *)
wneuper@59523
   405
wneuper@59523
   406
(* aus 2 Variablen wird eine Summe bzw ein Produkt erzeugt 
wneuper@59523
   407
   (mit gewuenschtem Typen T) *)
wenzelm@60309
   408
fun plus T = Const (\<^const_name>\<open>plus\<close>, [T,T] ---> T);
wenzelm@60309
   409
fun mult T = Const (\<^const_name>\<open>times\<close>, [T,T] ---> T);
wneuper@59523
   410
fun binop op_ t1 t2 = op_ $ t1 $ t2;
wneuper@59523
   411
fun create_prod T (a,b) = binop (mult T) a b;
wneuper@59523
   412
fun create_sum T (a,b) = binop (plus T) a b;
wneuper@59523
   413
wneuper@59523
   414
(* löscht letztes Element einer Liste *)
wneuper@59523
   415
fun drop_last l = take ((length l)-1,l);
wneuper@59523
   416
wneuper@59523
   417
(* Liste von Variablen --> Monom *)
wneuper@59523
   418
fun create_monom T vl = foldr (create_prod T) (drop_last vl, last_elem vl);
wneuper@59523
   419
(* Bemerkung: 
wneuper@59523
   420
   foldr bewirkt rechtslastige Klammerung des Monoms - ist notwendig, damit zwei 
wneuper@59523
   421
   gleiche Monome zusammengefasst werden können (collect_numerals)! 
wneuper@59523
   422
   zB: 2*(x*(y*z)) + 3*(x*(y*z)) --> (2+3)*(x*(y*z))*)
wneuper@59523
   423
wneuper@59523
   424
(* Liste von Monomen --> Polynom *)	
wneuper@59523
   425
fun create_polynom T ml = foldl (create_sum T) (hd ml, tl ml);
wneuper@59523
   426
(* Bemerkung: 
wneuper@59523
   427
   foldl bewirkt linkslastige Klammerung des Polynoms (der Summanten) - 
wneuper@59523
   428
   bessere Darstellung, da keine Klammern sichtbar! 
wneuper@59523
   429
   (und discard_parentheses in make_polynomial hat weniger zu tun) *)
wneuper@59523
   430
wneuper@59523
   431
(* sorts the variables (faktors) of an expanded polynomial lexicographical *)
wneuper@59523
   432
fun sort_variables t = 
wneuper@59523
   433
    let
wneuper@59523
   434
	val ll =  map monom2list (poly2list t);
wneuper@59523
   435
	val lls = map sort_varList ll; 
wneuper@59523
   436
	val T = type_of t;
wneuper@59523
   437
	val ls = map (create_monom T) lls;
wneuper@59523
   438
    in create_polynom T ls end;
wneuper@59523
   439
wneuper@59523
   440
(* sorts the monoms of an expanded and variable-sorted polynomial 
wneuper@59523
   441
   by total_degree *)
wneuper@59523
   442
fun sort_monoms t = 
wneuper@59523
   443
    let
wneuper@59523
   444
	val ll =  map monom2list (poly2list t);
wneuper@59523
   445
	val lls = sort_monList ll;
wneuper@59523
   446
	val T = type_of t;
wneuper@59523
   447
	val ls = map (create_monom T) lls;
wneuper@59523
   448
    in create_polynom T ls end;
wneuper@59523
   449
\<close>
wneuper@59523
   450
wneuper@59523
   451
subsubsection \<open>rewrite order for hard-coded AC rewriting\<close>
wneuper@59523
   452
ML \<open>
neuper@37950
   453
local (*. for make_polynomial .*)
neuper@37950
   454
neuper@37950
   455
open Term;  (* for type order = EQUAL | LESS | GREATER *)
neuper@37950
   456
neuper@37950
   457
fun pr_ord EQUAL = "EQUAL"
neuper@37950
   458
  | pr_ord LESS  = "LESS"
neuper@37950
   459
  | pr_ord GREATER = "GREATER";
neuper@37950
   460
neuper@37950
   461
fun dest_hd' (Const (a, T)) =                          (* ~ term.ML *)
neuper@37950
   462
  (case a of
wenzelm@60309
   463
     \<^const_name>\<open>powr\<close> => ((("|||||||||||||", 0), T), 0)    (*WN greatest string*)
neuper@37950
   464
   | _ => (((a, 0), T), 0))
neuper@37950
   465
  | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
neuper@37950
   466
  | dest_hd' (Var v) = (v, 2)
neuper@37950
   467
  | dest_hd' (Bound i) = ((("", i), dummyT), 3)
wneuper@59523
   468
  | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4)
wneuper@59523
   469
  | dest_hd' t = raise TERM ("dest_hd'", [t]);
neuper@37950
   470
neuper@37950
   471
fun size_of_term' (Const(str,_) $ t) =
wenzelm@60309
   472
  if \<^const_name>\<open>powr\<close>= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
neuper@37950
   473
  | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
neuper@37950
   474
  | size_of_term' (f$t) = size_of_term' f  +  size_of_term' t
neuper@37950
   475
  | size_of_term' _ = 1;
neuper@37950
   476
neuper@37950
   477
fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
neuper@52070
   478
    (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
neuper@37950
   479
  | term_ord' pr thy (t, u) =
neuper@52070
   480
    (if pr then 
neuper@52070
   481
	   let
neuper@52070
   482
       val (f, ts) = strip_comb t and (g, us) = strip_comb u;
walther@59870
   483
       val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
walther@59870
   484
         commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
walther@59870
   485
       val _ = tracing("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
walther@59870
   486
         commas (map (UnparseC.term_in_thy thy) us) ^ "]\"");
neuper@52070
   487
       val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
neuper@52070
   488
         string_of_int (size_of_term' u) ^ ")");
neuper@52070
   489
       val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o hd_ord) (f,g));
neuper@52070
   490
       val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o terms_ord str false) (ts, us));
neuper@52070
   491
       val _ = tracing ("-------");
neuper@52070
   492
     in () end
neuper@37950
   493
       else ();
neuper@37950
   494
	 case int_ord (size_of_term' t, size_of_term' u) of
neuper@37950
   495
	   EQUAL =>
neuper@37950
   496
	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
neuper@37950
   497
	       (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us) 
neuper@37950
   498
	     | ord => ord)
neuper@37950
   499
	     end
neuper@37950
   500
	 | ord => ord)
neuper@37950
   501
and hd_ord (f, g) =                                        (* ~ term.ML *)
neuper@37974
   502
  prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
wneuper@59523
   503
and terms_ord _ pr (ts, us) = 
walther@59881
   504
    list_ord (term_ord' pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
neuper@52070
   505
neuper@37950
   506
in
neuper@37950
   507
walther@59910
   508
fun ord_make_polynomial (pr:bool) thy (_: subst) tu = 
neuper@37950
   509
    (term_ord' pr thy(***) tu = LESS );
neuper@37950
   510
neuper@37950
   511
end;(*local*)
neuper@37950
   512
walther@59857
   513
Rewrite_Ord.rew_ord' := overwritel (! Rewrite_Ord.rew_ord', (* TODO: make analogous to KEStore_Elems.add_mets *)
wenzelm@60291
   514
[("termlessI", termlessI), ("ord_make_polynomial", ord_make_polynomial false \<^theory>)]);
wneuper@59523
   515
\<close>
neuper@37950
   516
wneuper@59523
   517
subsection \<open>predicates\<close>
wneuper@59523
   518
subsubsection \<open>in specifications\<close>
wneuper@59523
   519
ML \<open>
wneuper@59523
   520
(* is_polyrat_in becomes true, if no bdv is in the denominator of a fraction*)
wneuper@59523
   521
fun is_polyrat_in t v = 
wneuper@59524
   522
  let
walther@59962
   523
   	fun finddivide (_ $ _ $ _ $ _) _ = raise ERROR("is_polyrat_in:")
wneuper@59523
   524
	    (* at the moment there is no term like this, but ....*)
wenzelm@60309
   525
	  | finddivide (Const (\<^const_name>\<open>divide\<close>,_) $ _ $ b) v = not (Prog_Expr.occurs_in v b)
wneuper@59524
   526
	  | finddivide (_ $ t1 $ t2) v = finddivide t1 v orelse finddivide t2 v
wneuper@59524
   527
	  | finddivide (_ $ t1) v = finddivide t1 v
wneuper@59523
   528
	  | finddivide _ _ = false;
wneuper@59524
   529
  in finddivide t v end;
wneuper@59523
   530
    
wneuper@59524
   531
fun is_expanded_in t v = case expand_deg_in t v of SOME _ => true | NONE => false;
wneuper@59524
   532
fun is_poly_in t v =     case poly_deg_in t v of SOME _ => true | NONE => false;
wneuper@59524
   533
fun has_degree_in t v =  case expand_deg_in t v of SOME d => d | NONE => ~1;
neuper@37950
   534
wneuper@59523
   535
(*.the expression contains + - * ^ only ?
wneuper@59523
   536
   this is weaker than 'is_polynomial' !.*)
wneuper@59523
   537
fun is_polyexp (Free _) = true
wneuper@59529
   538
  | is_polyexp (Const _) = true (* potential danger: bdv is not considered *)
wenzelm@60309
   539
  | is_polyexp (Const (\<^const_name>\<open>plus\<close>,_) $ Free _ $ Free _) = true
wenzelm@60309
   540
  | is_polyexp (Const (\<^const_name>\<open>minus\<close>,_) $ Free _ $ Free _) = true
wenzelm@60309
   541
  | is_polyexp (Const (\<^const_name>\<open>times\<close>,_) $ Free _ $ Free _) = true
wenzelm@60309
   542
  | is_polyexp (Const (\<^const_name>\<open>powr\<close>,_) $ Free _ $ Free _) = true
wenzelm@60309
   543
  | is_polyexp (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) = 
wneuper@59523
   544
               ((is_polyexp t1) andalso (is_polyexp t2))
wenzelm@60309
   545
  | is_polyexp (Const (\<^const_name>\<open>minus\<close>,_) $ t1 $ t2) = 
wneuper@59523
   546
               ((is_polyexp t1) andalso (is_polyexp t2))
wenzelm@60309
   547
  | is_polyexp (Const (\<^const_name>\<open>times\<close>,_) $ t1 $ t2) = 
wneuper@59523
   548
               ((is_polyexp t1) andalso (is_polyexp t2))
wenzelm@60309
   549
  | is_polyexp (Const (\<^const_name>\<open>powr\<close>,_) $ t1 $ t2) = 
wneuper@59523
   550
               ((is_polyexp t1) andalso (is_polyexp t2))
wneuper@59523
   551
  | is_polyexp _ = false;
wneuper@59523
   552
\<close>
neuper@37950
   553
wneuper@59523
   554
subsubsection \<open>for hard-coded AC rewriting\<close>
wneuper@59523
   555
ML \<open>
wneuper@59523
   556
(* auch Klammerung muss übereinstimmen;
wneuper@59523
   557
   sort_variables klammert Produkte rechtslastig*)
wneuper@59523
   558
fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
wneuper@59523
   559
wneuper@59523
   560
fun is_addUnordered t = ((is_polyexp t) andalso not (t = sort_monoms t));
wneuper@59523
   561
\<close>
wneuper@59523
   562
wneuper@59523
   563
subsection \<open>evaluations functions\<close>
wneuper@59523
   564
subsubsection \<open>for predicates\<close>
wneuper@59523
   565
ML \<open>
walther@60278
   566
fun eval_is_polyrat_in _ _(p as (Const ("Poly.is_polyrat_in",_) $ t $ v)) _  =
wneuper@59523
   567
    if is_polyrat_in t v 
walther@59868
   568
    then SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   569
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
walther@59868
   570
    else SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   571
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
wneuper@59523
   572
  | eval_is_polyrat_in _ _ _ _ = ((*tracing"### no matches";*) NONE);
wneuper@59523
   573
walther@60278
   574
(*("is_expanded_in", ("Poly.is_expanded_in", eval_is_expanded_in ""))*)
wneuper@59523
   575
fun eval_is_expanded_in _ _ 
walther@60278
   576
       (p as (Const ("Poly.is_expanded_in",_) $ t $ v)) _ =
wneuper@59523
   577
    if is_expanded_in t v
walther@59868
   578
    then SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   579
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
walther@59868
   580
    else SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   581
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
wneuper@59523
   582
  | eval_is_expanded_in _ _ _ _ = NONE;
wneuper@59523
   583
walther@60278
   584
(*("is_poly_in", ("Poly.is_poly_in", eval_is_poly_in ""))*)
wneuper@59523
   585
fun eval_is_poly_in _ _ 
walther@60278
   586
       (p as (Const ("Poly.is_poly_in",_) $ t $ v)) _ =
wneuper@59523
   587
    if is_poly_in t v
walther@59868
   588
    then SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   589
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
walther@59868
   590
    else SOME ((UnparseC.term p) ^ " = True",
wneuper@59523
   591
	        HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
wneuper@59523
   592
  | eval_is_poly_in _ _ _ _ = NONE;
wneuper@59523
   593
walther@60278
   594
(*("has_degree_in", ("Poly.has_degree_in", eval_has_degree_in ""))*)
wneuper@59523
   595
fun eval_has_degree_in _ _ 
walther@60278
   596
	     (p as (Const ("Poly.has_degree_in",_) $ t $ v)) _ =
wneuper@59523
   597
    let val d = has_degree_in t v
wneuper@59523
   598
	val d' = TermC.term_of_num HOLogic.realT d
walther@59868
   599
    in SOME ((UnparseC.term p) ^ " = " ^ (string_of_int d),
wneuper@59523
   600
	      HOLogic.Trueprop $ (TermC.mk_equality (p, d')))
wneuper@59523
   601
    end
wneuper@59523
   602
  | eval_has_degree_in _ _ _ _ = NONE;
wneuper@59523
   603
walther@60278
   604
(*("is_polyexp", ("Poly.is_polyexp", eval_is_polyexp ""))*)
wneuper@59523
   605
fun eval_is_polyexp (thmid:string) _ 
walther@60278
   606
		       (t as (Const("Poly.is_polyexp", _) $ arg)) thy = 
wneuper@59523
   607
    if is_polyexp arg
walther@59870
   608
    then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   609
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
   610
    else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   611
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
wneuper@59523
   612
  | eval_is_polyexp _ _ _ _ = NONE; 
wneuper@59523
   613
\<close>
wneuper@59523
   614
wneuper@59523
   615
subsubsection \<open>for hard-coded AC rewriting\<close>
wneuper@59523
   616
ML \<open>
wneuper@59523
   617
(*WN.18.6.03 *)
walther@60278
   618
(*("is_addUnordered", ("Poly.is_addUnordered", eval_is_addUnordered ""))*)
wneuper@59523
   619
fun eval_is_addUnordered (thmid:string) _ 
walther@60278
   620
		       (t as (Const("Poly.is_addUnordered", _) $ arg)) thy = 
wneuper@59523
   621
    if is_addUnordered arg
walther@59870
   622
    then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   623
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
   624
    else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   625
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
wneuper@59523
   626
  | eval_is_addUnordered _ _ _ _ = NONE; 
wneuper@59523
   627
wneuper@59523
   628
fun eval_is_multUnordered (thmid:string) _ 
walther@60278
   629
		       (t as (Const("Poly.is_multUnordered", _) $ arg)) thy = 
wneuper@59523
   630
    if is_multUnordered arg
walther@59870
   631
    then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   632
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
walther@59870
   633
    else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg) "", 
wneuper@59523
   634
	         HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
wneuper@59523
   635
  | eval_is_multUnordered _ _ _ _ = NONE; 
wneuper@59523
   636
\<close>
wenzelm@60313
   637
calculation is_polyrat_in = \<open>eval_is_polyrat_in "#eval_is_polyrat_in"\<close>
wenzelm@60313
   638
calculation is_expanded_in = \<open>eval_is_expanded_in ""\<close>
wenzelm@60313
   639
calculation is_poly_in = \<open>eval_is_poly_in ""\<close>
wenzelm@60313
   640
calculation has_degree_in = \<open>eval_has_degree_in ""\<close>
wenzelm@60313
   641
calculation is_polyexp = \<open>eval_is_polyexp ""\<close>
wenzelm@60313
   642
calculation is_multUnordered = \<open>eval_is_multUnordered ""\<close>
wenzelm@60313
   643
calculation is_addUnordered = \<open>eval_is_addUnordered ""\<close>
wneuper@59523
   644
wneuper@59523
   645
subsection \<open>rule-sets\<close>
wneuper@59523
   646
subsubsection \<open>without specific order\<close>
wneuper@59523
   647
ML \<open>
wneuper@59523
   648
(* used only for merge *)
walther@59852
   649
val calculate_Poly = Rule_Set.append_rules "calculate_PolyFIXXXME.not.impl." Rule_Set.empty [];
wneuper@59523
   650
wneuper@59523
   651
(*.for evaluation of conditions in rewrite rules.*)
walther@59852
   652
val Poly_erls = Rule_Set.append_rules "Poly_erls" Atools_erls
wenzelm@60294
   653
  [\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
wenzelm@60297
   654
  \<^rule_thm>\<open>real_unari_minus\<close>,
wenzelm@60294
   655
  \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
wenzelm@60294
   656
  \<^rule_eval>\<open>minus\<close> (eval_binop "#sub_"),
wenzelm@60294
   657
  \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
   658
  \<^rule_eval>\<open>powr\<close> (eval_binop "#power_")];
wneuper@59523
   659
walther@59852
   660
val poly_crls = Rule_Set.append_rules "poly_crls" Atools_crls
wenzelm@60294
   661
  [\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
wenzelm@60297
   662
  \<^rule_thm>\<open>real_unari_minus\<close>,
wenzelm@60294
   663
  \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
wenzelm@60294
   664
  \<^rule_eval>\<open>minus\<close> (eval_binop "#sub_"),
wenzelm@60294
   665
  \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
   666
  \<^rule_eval>\<open>powr\<close> (eval_binop "#power_")];
wneuper@59523
   667
\<close>
wneuper@59523
   668
ML \<open>
neuper@37950
   669
val expand =
walther@59857
   670
  Rule_Def.Repeat {id = "expand", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   671
      erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
wenzelm@60297
   672
      rules = [\<^rule_thm>\<open>distrib_right\<close>,
neuper@37950
   673
	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60297
   674
	       \<^rule_thm>\<open>distrib_left\<close>
neuper@37950
   675
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
walther@59878
   676
	       ], scr = Rule.Empty_Prog};
neuper@37950
   677
neuper@37980
   678
val discard_minus =
walther@59857
   679
  Rule_Def.Repeat {id = "discard_minus", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   680
      erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
neuper@42407
   681
      rules =
wenzelm@60297
   682
       [\<^rule_thm>\<open>real_diff_minus\<close>,
neuper@42407
   683
          (*"a - b = a + -1 * b"*)
wenzelm@60296
   684
	        \<^rule_thm_sym>\<open>real_mult_minus1\<close>
neuper@42407
   685
	          (*- ?z = "-1 * ?z"*)],
walther@59878
   686
	      scr = Rule.Empty_Prog};
neuper@37980
   687
neuper@37950
   688
val expand_poly_ = 
walther@59851
   689
  Rule_Def.Repeat{id = "expand_poly_", preconds = [], 
walther@59857
   690
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   691
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
   692
      calc = [], errpatts = [],
neuper@42407
   693
      rules =
wenzelm@60297
   694
        [\<^rule_thm>\<open>real_plus_binom_pow4\<close>,
walther@60260
   695
	           (*"(a + b) \<up> 4 = ... "*)
wenzelm@60297
   696
	         \<^rule_thm>\<open>real_plus_binom_pow5\<close>,
walther@60260
   697
	           (*"(a + b) \<up> 5 = ... "*)
wenzelm@60297
   698
	         \<^rule_thm>\<open>real_plus_binom_pow3\<close>,
walther@60260
   699
	           (*"(a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" *)
neuper@42407
   700
	         (*WN071229 changed/removed for Schaerding -----vvv*)
wenzelm@60297
   701
	         (*\<^rule_thm>\<open>real_plus_binom_pow2\<close>,*)
walther@60260
   702
	           (*"(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
wenzelm@60297
   703
	         \<^rule_thm>\<open>real_plus_binom_pow2\<close>,
walther@60260
   704
	           (*"(a + b) \<up> 2 = (a + b) * (a + b)"*)
wenzelm@60297
   705
	         (*\<^rule_thm>\<open>real_plus_minus_binom1_p_p\<close>,*)
walther@60260
   706
	           (*"(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2"*)
wenzelm@60297
   707
	         (*\<^rule_thm>\<open>real_plus_minus_binom2_p_p\<close>,*)
walther@60260
   708
	           (*"(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
walther@60242
   709
	         (*WN071229 changed/removed for Schaerding -----\<up>*)
neuper@37950
   710
	      
wenzelm@60297
   711
	         \<^rule_thm>\<open>distrib_right\<close>,
neuper@42407
   712
	           (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60297
   713
	         \<^rule_thm>\<open>distrib_left\<close>,
neuper@42407
   714
	           (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
   715
	       
wenzelm@60297
   716
	         \<^rule_thm>\<open>realpow_multI\<close>,
walther@60242
   717
	           (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
wenzelm@60297
   718
	         \<^rule_thm>\<open>realpow_pow\<close>
walther@60242
   719
	           (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
walther@59878
   720
	       ], scr = Rule.Empty_Prog};
neuper@37950
   721
neuper@37950
   722
val expand_poly_rat_ = 
walther@59851
   723
  Rule_Def.Repeat{id = "expand_poly_rat_", preconds = [], 
walther@59857
   724
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   725
      erls =  Rule_Set.append_rules "Rule_Set.empty-is_polyexp" Rule_Set.empty
wenzelm@60294
   726
	        [\<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp "")
neuper@37950
   727
		 ],
walther@59851
   728
      srls = Rule_Set.Empty,
neuper@42451
   729
      calc = [], errpatts = [],
neuper@37950
   730
      rules = 
wenzelm@60297
   731
        [\<^rule_thm>\<open>real_plus_binom_pow4_poly\<close>,
walther@60260
   732
	     (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 4 = ... "*)
wenzelm@60297
   733
	 \<^rule_thm>\<open>real_plus_binom_pow5_poly\<close>,
walther@60260
   734
	     (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 5 = ... "*)
wenzelm@60297
   735
	 \<^rule_thm>\<open>real_plus_binom_pow2_poly\<close>,
neuper@37950
   736
	     (*"[| a is_polyexp; b is_polyexp |] ==>
walther@60260
   737
		            (a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
wenzelm@60297
   738
	 \<^rule_thm>\<open>real_plus_binom_pow3_poly\<close>,
neuper@37950
   739
	     (*"[| a is_polyexp; b is_polyexp |] ==> 
walther@60260
   740
			(a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" *)
wenzelm@60297
   741
	 \<^rule_thm>\<open>real_plus_minus_binom1_p_p\<close>,
walther@60260
   742
	     (*"(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2"*)
wenzelm@60297
   743
	 \<^rule_thm>\<open>real_plus_minus_binom2_p_p\<close>,
walther@60260
   744
	     (*"(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
neuper@37950
   745
	      
wenzelm@60298
   746
	 \<^rule_thm>\<open>real_add_mult_distrib_poly\<close>,
neuper@37950
   747
	       (*"w is_polyexp ==> (z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60298
   748
	 \<^rule_thm>\<open>real_add_mult_distrib2_poly\<close>,
neuper@37950
   749
	     (*"w is_polyexp ==> w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
   750
	       
wenzelm@60297
   751
	 \<^rule_thm>\<open>realpow_multI_poly\<close>,
neuper@37950
   752
	     (*"[| r is_polyexp; s is_polyexp |] ==> 
walther@60242
   753
		            (r * s) \<up> n = r \<up> n * s \<up> n"*)
wenzelm@60297
   754
	  \<^rule_thm>\<open>realpow_pow\<close>
walther@60242
   755
	      (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
walther@59878
   756
	 ], scr = Rule.Empty_Prog};
neuper@37950
   757
neuper@37950
   758
val simplify_power_ = 
walther@59851
   759
  Rule_Def.Repeat{id = "simplify_power_", preconds = [], 
walther@59857
   760
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   761
      erls = Rule_Set.empty, srls = Rule_Set.Empty,
neuper@42451
   762
      calc = [], errpatts = [],
wneuper@59416
   763
      rules = [(*MG: Reihenfolge der folgenden 2 Rule.Thm muss so bleiben, wegen
walther@60260
   764
		a*(a*a) --> a*a \<up> 2 und nicht a*(a*a) --> a \<up> 2*a *)
wenzelm@60296
   765
	       \<^rule_thm_sym>\<open>realpow_twoI\<close>,	
walther@60242
   766
	       (*"r * r = r \<up> 2"*)
wenzelm@60297
   767
	       \<^rule_thm>\<open>realpow_twoI_assoc_l\<close>,
walther@60242
   768
	       (*"r * (r * s) = r \<up> 2 * s"*)
neuper@37950
   769
wenzelm@60297
   770
	       \<^rule_thm>\<open>realpow_plus_1\<close>,		
walther@60242
   771
	       (*"r * r \<up> n = r \<up> (n + 1)"*)
wenzelm@60298
   772
	       \<^rule_thm>\<open>realpow_plus_1_assoc_l\<close>,
walther@60242
   773
	       (*"r * (r \<up> m * s) = r \<up> (1 + m) * s"*)
walther@60260
   774
	       (*MG 9.7.03: neues Rule.Thm wegen a*(a*(a*b)) --> a \<up> 2*(a*b) *)
wenzelm@60298
   775
	       \<^rule_thm>\<open>realpow_plus_1_assoc_l2\<close>,
walther@60242
   776
	       (*"r \<up> m * (r * s) = r \<up> (1 + m) * s"*)
neuper@37950
   777
wenzelm@60296
   778
	       \<^rule_thm_sym>\<open>realpow_addI\<close>,
walther@60242
   779
	       (*"r \<up> n * r \<up> m = r \<up> (n + m)"*)
wenzelm@60297
   780
	       \<^rule_thm>\<open>realpow_addI_assoc_l\<close>,
walther@60242
   781
	       (*"r \<up> n * (r \<up> m * s) = r \<up> (n + m) * s"*)
neuper@37950
   782
	       
neuper@37950
   783
	       (* ist in expand_poly - wird hier aber auch gebraucht, wegen: 
walther@60260
   784
		  "r * r = r \<up> 2" wenn r=a \<up> b*)
wenzelm@60297
   785
	       \<^rule_thm>\<open>realpow_pow\<close>
walther@60242
   786
	       (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
walther@59878
   787
	       ], scr = Rule.Empty_Prog};
neuper@37950
   788
neuper@37950
   789
val calc_add_mult_pow_ = 
walther@59851
   790
  Rule_Def.Repeat{id = "calc_add_mult_pow_", preconds = [], 
walther@59857
   791
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
   792
      erls = Atools_erls(*erls3.4.03*),srls = Rule_Set.Empty,
wenzelm@60309
   793
      calc = [("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")), 
wenzelm@60309
   794
	      ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
   795
	      ("POWER", (\<^const_name>\<open>powr\<close>, eval_binop "#power_"))
neuper@37950
   796
	      ],
neuper@42451
   797
      errpatts = [],
wenzelm@60294
   798
      rules = [\<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
wenzelm@60294
   799
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
   800
	       \<^rule_eval>\<open>powr\<close> (eval_binop "#power_")
walther@59878
   801
	       ], scr = Rule.Empty_Prog};
neuper@37950
   802
neuper@37950
   803
val reduce_012_mult_ = 
walther@59851
   804
  Rule_Def.Repeat{id = "reduce_012_mult_", preconds = [], 
walther@59857
   805
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   806
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
   807
      calc = [], errpatts = [],
wneuper@59416
   808
      rules = [(* MG: folgende Rule.Thm müssen hier stehen bleiben: *)
wenzelm@60297
   809
               \<^rule_thm>\<open>mult_1_right\<close>,
walther@60260
   810
	       (*"z * 1 = z"*) (*wegen "a * b * b \<up> (-1) + a"*) 
wenzelm@60297
   811
	       \<^rule_thm>\<open>realpow_zeroI\<close>,
walther@60260
   812
	       (*"r \<up> 0 = 1"*) (*wegen "a*a \<up> (-1)*c + b + c"*)
wenzelm@60297
   813
	       \<^rule_thm>\<open>realpow_oneI\<close>,
walther@60242
   814
	       (*"r \<up> 1 = r"*)
wenzelm@60297
   815
	       \<^rule_thm>\<open>realpow_eq_oneI\<close>
walther@60242
   816
	       (*"1 \<up> n = 1"*)
walther@59878
   817
	       ], scr = Rule.Empty_Prog};
neuper@37950
   818
neuper@37950
   819
val collect_numerals_ = 
walther@59851
   820
  Rule_Def.Repeat{id = "collect_numerals_", preconds = [], 
walther@59857
   821
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
   822
      erls = Atools_erls, srls = Rule_Set.Empty,
wenzelm@60309
   823
      calc = [("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_"))
neuper@42451
   824
	      ], errpatts = [],
neuper@37950
   825
      rules = 
wenzelm@60297
   826
        [\<^rule_thm>\<open>real_num_collect\<close>, 
neuper@37950
   827
	     (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
wenzelm@60297
   828
	 \<^rule_thm>\<open>real_num_collect_assoc_r\<close>,
neuper@37950
   829
	     (*"[| l is_const; m is_const |] ==>  \
neuper@37950
   830
					\(k + m * n) + l * n = k + (l + m)*n"*)
wenzelm@60297
   831
	 \<^rule_thm>\<open>real_one_collect\<close>,	
neuper@37950
   832
	     (*"m is_const ==> n + m * n = (1 + m) * n"*)
wenzelm@60297
   833
	 \<^rule_thm>\<open>real_one_collect_assoc_r\<close>, 
neuper@37950
   834
	     (*"m is_const ==> (k + n) + m * n = k + (m + 1) * n"*)
neuper@37950
   835
wenzelm@60294
   836
         \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
neuper@37950
   837
wneuper@59416
   838
	 (*MG: Reihenfolge der folgenden 2 Rule.Thm muss so bleiben, wegen
neuper@37950
   839
		     (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
wenzelm@60297
   840
         \<^rule_thm>\<open>real_mult_2_assoc_r\<close>,
neuper@37950
   841
	     (*"(k + z1) + z1 = k + 2 * z1"*)
wenzelm@60296
   842
	 \<^rule_thm_sym>\<open>real_mult_2\<close>
neuper@37950
   843
	     (*"z1 + z1 = 2 * z1"*)
walther@59878
   844
	], scr = Rule.Empty_Prog};
neuper@37950
   845
neuper@37950
   846
val reduce_012_ = 
walther@59851
   847
  Rule_Def.Repeat{id = "reduce_012_", preconds = [], 
walther@59857
   848
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   849
      erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
wenzelm@60297
   850
      rules = [\<^rule_thm>\<open>mult_1_left\<close>,                 
neuper@37950
   851
	       (*"1 * z = z"*)
wenzelm@60297
   852
	       \<^rule_thm>\<open>mult_zero_left\<close>,        
neuper@37950
   853
	       (*"0 * z = 0"*)
wenzelm@60297
   854
	       \<^rule_thm>\<open>mult_zero_right\<close>,
neuper@37950
   855
	       (*"z * 0 = 0"*)
wenzelm@60297
   856
	       \<^rule_thm>\<open>add_0_left\<close>,
neuper@37950
   857
	       (*"0 + z = z"*)
wenzelm@60297
   858
	       \<^rule_thm>\<open>add_0_right\<close>,
neuper@37950
   859
	       (*"z + 0 = z"*) (*wegen a+b-b --> a+(1-1)*b --> a+0 --> a*)
neuper@37950
   860
wenzelm@60297
   861
	       (*\<^rule_thm>\<open>realpow_oneI\<close>*)
walther@60242
   862
	       (*"?r \<up> 1 = ?r"*)
wenzelm@60297
   863
	       \<^rule_thm>\<open>division_ring_divide_zero\<close>
neuper@37950
   864
	       (*"0 / ?x = 0"*)
walther@59878
   865
	       ], scr = Rule.Empty_Prog};
neuper@37950
   866
neuper@37979
   867
val discard_parentheses1 = 
walther@59852
   868
    Rule_Set.append_rules "discard_parentheses1" Rule_Set.empty 
wenzelm@60296
   869
	       [\<^rule_thm_sym>\<open>mult.assoc\<close>
neuper@37950
   870
		(*"?z1.1 * (?z2.1 * ?z3.1) = ?z1.1 * ?z2.1 * ?z3.1"*)
wenzelm@60296
   871
		(*\<^rule_thm_sym>\<open>add.assoc\<close>*)
neuper@37950
   872
		(*"?z1.1 + (?z2.1 + ?z3.1) = ?z1.1 + ?z2.1 + ?z3.1"*)
neuper@37950
   873
		 ];
neuper@37950
   874
wneuper@59523
   875
val expand_poly =
walther@59851
   876
  Rule_Def.Repeat{id = "expand_poly", preconds = [], 
walther@59857
   877
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   878
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
   879
      calc = [], errpatts = [],
neuper@37950
   880
      (*asm_thm = [],*)
wenzelm@60297
   881
      rules = [\<^rule_thm>\<open>distrib_right\<close>,
neuper@37950
   882
	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60297
   883
	       \<^rule_thm>\<open>distrib_left\<close>,
neuper@37950
   884
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
walther@59871
   885
	       (*Rule.Thm ("distrib_right1",ThmC.numerals_to_Free @{thm distrib_right}1),
neuper@37950
   886
		....... 18.3.03 undefined???*)
neuper@37950
   887
wenzelm@60297
   888
	       \<^rule_thm>\<open>real_plus_binom_pow2\<close>,
walther@60260
   889
	       (*"(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
wenzelm@60297
   890
	       \<^rule_thm>\<open>real_minus_binom_pow2_p\<close>,
walther@60260
   891
	       (*"(a - b) \<up> 2 = a \<up> 2 + -2*a*b + b \<up> 2"*)
wenzelm@60298
   892
	       \<^rule_thm>\<open>real_plus_minus_binom1_p\<close>,
walther@60260
   893
	       (*"(a + b)*(a - b) = a \<up> 2 + -1*b \<up> 2"*)
wenzelm@60298
   894
	       \<^rule_thm>\<open>real_plus_minus_binom2_p\<close>,
walther@60260
   895
	       (*"(a - b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
neuper@37950
   896
wenzelm@60297
   897
	       \<^rule_thm>\<open>minus_minus\<close>,
neuper@37950
   898
	       (*"- (- ?z) = ?z"*)
wenzelm@60297
   899
	       \<^rule_thm>\<open>real_diff_minus\<close>,
neuper@37950
   900
	       (*"a - b = a + -1 * b"*)
wenzelm@60296
   901
	       \<^rule_thm_sym>\<open>real_mult_minus1\<close>
neuper@37950
   902
	       (*- ?z = "-1 * ?z"*)
neuper@37950
   903
wenzelm@60298
   904
	       (*\<^rule_thm>\<open>real_minus_add_distrib\<close>,*)
neuper@37950
   905
	       (*"- (?x + ?y) = - ?x + - ?y"*)
wenzelm@60297
   906
	       (*\<^rule_thm>\<open>real_diff_plus\<close>*)
neuper@37950
   907
	       (*"a - b = a + -b"*)
walther@59878
   908
	       ], scr = Rule.Empty_Prog};
neuper@37950
   909
neuper@37950
   910
val simplify_power = 
walther@59851
   911
  Rule_Def.Repeat{id = "simplify_power", preconds = [], 
walther@59857
   912
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   913
      erls = Rule_Set.empty, srls = Rule_Set.Empty,
neuper@42451
   914
      calc = [], errpatts = [],
wenzelm@60297
   915
      rules = [\<^rule_thm>\<open>realpow_multI\<close>,
walther@60242
   916
	       (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
neuper@37950
   917
	       
wenzelm@60296
   918
	       \<^rule_thm_sym>\<open>realpow_twoI\<close>,	
walther@60242
   919
	       (*"r1 * r1 = r1 \<up> 2"*)
wenzelm@60297
   920
	       \<^rule_thm>\<open>realpow_plus_1\<close>,		
walther@60242
   921
	       (*"r * r \<up> n = r \<up> (n + 1)"*)
wenzelm@60297
   922
	       \<^rule_thm>\<open>realpow_pow\<close>,
walther@60242
   923
	       (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
wenzelm@60296
   924
	       \<^rule_thm_sym>\<open>realpow_addI\<close>,
walther@60242
   925
	       (*"r \<up> n * r \<up> m = r \<up> (n + m)"*)
wenzelm@60297
   926
	       \<^rule_thm>\<open>realpow_oneI\<close>,
walther@60242
   927
	       (*"r \<up> 1 = r"*)
wenzelm@60297
   928
	       \<^rule_thm>\<open>realpow_eq_oneI\<close>
walther@60242
   929
	       (*"1 \<up> n = 1"*)
walther@59878
   930
	       ], scr = Rule.Empty_Prog};
neuper@42451
   931
neuper@37950
   932
val collect_numerals = 
walther@59851
   933
  Rule_Def.Repeat{id = "collect_numerals", preconds = [], 
walther@59857
   934
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
   935
      erls = Atools_erls(*erls3.4.03*),srls = Rule_Set.Empty,
wenzelm@60309
   936
      calc = [("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")), 
wenzelm@60309
   937
	      ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
   938
	      ("POWER", (\<^const_name>\<open>powr\<close>, eval_binop "#power_"))
neuper@42451
   939
	      ], errpatts = [],
wenzelm@60297
   940
      rules = [\<^rule_thm>\<open>real_num_collect\<close>, 
neuper@37950
   941
	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
wenzelm@60297
   942
	       \<^rule_thm>\<open>real_num_collect_assoc\<close>,
neuper@37950
   943
	       (*"[| l is_const; m is_const |] ==>  
neuper@37950
   944
				l * n + (m * n + k) =  (l + m) * n + k"*)
wenzelm@60297
   945
	       \<^rule_thm>\<open>real_one_collect\<close>,	
neuper@37950
   946
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
wenzelm@60297
   947
	       \<^rule_thm>\<open>real_one_collect_assoc\<close>, 
neuper@37950
   948
	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
wenzelm@60294
   949
	       \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"), 
wenzelm@60294
   950
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
   951
	       \<^rule_eval>\<open>powr\<close> (eval_binop "#power_")
walther@59878
   952
	       ], scr = Rule.Empty_Prog};
neuper@37950
   953
val reduce_012 = 
walther@59851
   954
  Rule_Def.Repeat{id = "reduce_012", preconds = [], 
walther@59857
   955
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
   956
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
   957
      calc = [], errpatts = [],
wenzelm@60297
   958
      rules = [\<^rule_thm>\<open>mult_1_left\<close>,                 
neuper@37950
   959
	       (*"1 * z = z"*)
wenzelm@60297
   960
	       (*\<^rule_thm>\<open>real_mult_minus1\<close>,14.3.03*)
neuper@37950
   961
	       (*"-1 * z = - z"*)
wenzelm@60298
   962
	       Rule.Thm ("minus_mult_left", ThmC.numerals_to_Free (@{thm minus_mult_left} RS @{thm sym})),
neuper@37950
   963
	       (*- (?x * ?y) = "- ?x * ?y"*)
wenzelm@60298
   964
	       (*\<^rule_thm>\<open>real_minus_mult_cancel\<close>,
neuper@37950
   965
	       (*"- ?x * - ?y = ?x * ?y"*)---*)
wenzelm@60297
   966
	       \<^rule_thm>\<open>mult_zero_left\<close>,        
neuper@37950
   967
	       (*"0 * z = 0"*)
wenzelm@60297
   968
	       \<^rule_thm>\<open>add_0_left\<close>,
neuper@37950
   969
	       (*"0 + z = z"*)
wenzelm@60297
   970
	       \<^rule_thm>\<open>right_minus\<close>,
neuper@37950
   971
	       (*"?z + - ?z = 0"*)
wenzelm@60296
   972
	       \<^rule_thm_sym>\<open>real_mult_2\<close>,	
neuper@37950
   973
	       (*"z1 + z1 = 2 * z1"*)
wenzelm@60297
   974
	       \<^rule_thm>\<open>real_mult_2_assoc\<close>
neuper@37950
   975
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
walther@59878
   976
	       ], scr = Rule.Empty_Prog};
neuper@52139
   977
neuper@37950
   978
val discard_parentheses = 
walther@59852
   979
    Rule_Set.append_rules "discard_parentheses" Rule_Set.empty 
wenzelm@60296
   980
	       [\<^rule_thm_sym>\<open>mult.assoc\<close>,	\<^rule_thm_sym>\<open>add.assoc\<close>];
wneuper@59523
   981
\<close>
neuper@37950
   982
wneuper@59523
   983
subsubsection \<open>hard-coded AC rewriting\<close>
wneuper@59523
   984
ML \<open>
wneuper@59523
   985
(*MG.0401: termorders for multivariate polys dropped due to principal problems:
wneuper@59523
   986
  (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
wneuper@59523
   987
val order_add_mult = 
walther@59851
   988
  Rule_Def.Repeat{id = "order_add_mult", preconds = [], 
wenzelm@60291
   989
      rew_ord = ("ord_make_polynomial",ord_make_polynomial false \<^theory>),
walther@59852
   990
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
   991
      calc = [], errpatts = [],
wenzelm@60297
   992
      rules = [\<^rule_thm>\<open>mult.commute\<close>,
wneuper@59523
   993
	       (* z * w = w * z *)
wenzelm@60297
   994
	       \<^rule_thm>\<open>real_mult_left_commute\<close>,
wneuper@59523
   995
	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
wenzelm@60297
   996
	       \<^rule_thm>\<open>mult.assoc\<close>,		
wneuper@59523
   997
	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
wenzelm@60297
   998
	       \<^rule_thm>\<open>add.commute\<close>,	
wneuper@59523
   999
	       (*z + w = w + z*)
wenzelm@60297
  1000
	       \<^rule_thm>\<open>add.left_commute\<close>,
wneuper@59523
  1001
	       (*x + (y + z) = y + (x + z)*)
wenzelm@60297
  1002
	       \<^rule_thm>\<open>add.assoc\<close>	               
wneuper@59523
  1003
	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
walther@59878
  1004
	       ], scr = Rule.Empty_Prog};
wneuper@59523
  1005
(*MG.0401: termorders for multivariate polys dropped due to principal problems:
wneuper@59523
  1006
  (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
wneuper@59523
  1007
val order_mult = 
walther@59851
  1008
  Rule_Def.Repeat{id = "order_mult", preconds = [], 
wenzelm@60291
  1009
      rew_ord = ("ord_make_polynomial",ord_make_polynomial false \<^theory>),
walther@59852
  1010
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
wneuper@59523
  1011
      calc = [], errpatts = [],
wenzelm@60297
  1012
      rules = [\<^rule_thm>\<open>mult.commute\<close>,
wneuper@59523
  1013
	       (* z * w = w * z *)
wenzelm@60297
  1014
	       \<^rule_thm>\<open>real_mult_left_commute\<close>,
wneuper@59523
  1015
	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
wenzelm@60297
  1016
	       \<^rule_thm>\<open>mult.assoc\<close>	
wneuper@59523
  1017
	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
walther@59878
  1018
	       ], scr = Rule.Empty_Prog};
wneuper@59472
  1019
\<close>
wneuper@59472
  1020
ML \<open>
wneuper@59416
  1021
fun attach_form (_: Rule.rule list list) (_: term) (_: term) = (*still missing*)
wneuper@59416
  1022
    []:(Rule.rule * (term * term list)) list;
walther@59850
  1023
fun init_state (_: term) = Rule_Set.e_rrlsstate;
wneuper@59416
  1024
fun locate_rule (_: Rule.rule list list) (_: term) (_: Rule.rule) =
wneuper@59416
  1025
    ([]:(Rule.rule * (term * term list)) list);
wneuper@59416
  1026
fun next_rule (_: Rule.rule list list) (_: term) = (NONE: Rule.rule option);
wneuper@59406
  1027
fun normal_form t = SOME (sort_variables t, []: term list);
neuper@37950
  1028
neuper@37950
  1029
val order_mult_ =
walther@59850
  1030
    Rule_Set.Rrls {id = "order_mult_", 
neuper@37950
  1031
	  prepat = 
neuper@38036
  1032
          (* ?p matched with the current term gives an environment,
neuper@38037
  1033
             which evaluates (the instantiated) "?p is_multUnordered" to true *)
wenzelm@60291
  1034
	  [([TermC.parse_patt \<^theory> "?p is_multUnordered"], 
wenzelm@60291
  1035
             TermC.parse_patt \<^theory> "?p :: real")],
walther@59857
  1036
	  rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
  1037
	  erls = Rule_Set.append_rules "Rule_Set.empty-is_multUnordered" Rule_Set.empty
wenzelm@60294
  1038
			    [\<^rule_eval>\<open>is_multUnordered\<close> (eval_is_multUnordered "")],
wenzelm@60309
  1039
	  calc = [("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
wenzelm@60309
  1040
		  ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
  1041
		  ("DIVIDE", (\<^const_name>\<open>divide\<close>, Prog_Expr.eval_cancel "#divide_e")),
wenzelm@60309
  1042
		  ("POWER" , (\<^const_name>\<open>powr\<close>, eval_binop "#power_"))],
wneuper@59406
  1043
    errpatts = [],
wneuper@59416
  1044
	  scr = Rule.Rfuns {init_state  = init_state,
neuper@37950
  1045
		     normal_form = normal_form,
neuper@37950
  1046
		     locate_rule = locate_rule,
neuper@37950
  1047
		     next_rule   = next_rule,
neuper@37950
  1048
		     attach_form = attach_form}};
neuper@37950
  1049
val order_mult_rls_ = 
walther@59851
  1050
  Rule_Def.Repeat {id = "order_mult_rls_", preconds = [], 
walther@59857
  1051
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
  1052
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
  1053
      calc = [], errpatts = [],
wneuper@59416
  1054
      rules = [Rule.Rls_ order_mult_
walther@59878
  1055
	       ], scr = Rule.Empty_Prog};
neuper@37950
  1056
wneuper@59523
  1057
\<close> ML \<open>
neuper@37950
  1058
wneuper@59416
  1059
fun attach_form (_: Rule.rule list list) (_: term) (_: term) = (*still missing*)
wneuper@59416
  1060
    []: (Rule.rule * (term * term list)) list;
walther@59850
  1061
fun init_state (_: term) = Rule_Set.e_rrlsstate;
wneuper@59416
  1062
fun locate_rule (_: Rule.rule list list) (_: term) (_: Rule.rule) =
wneuper@59416
  1063
    ([]: (Rule.rule * (term * term list)) list);
wneuper@59416
  1064
fun next_rule (_: Rule.rule list list) (_: term) = (NONE: Rule.rule option);
wneuper@59406
  1065
fun normal_form t = SOME (sort_monoms t,[]: term list);
wneuper@59472
  1066
\<close> ML \<open>
neuper@37950
  1067
val order_add_ =
walther@59850
  1068
    Rule_Set.Rrls {id = "order_add_", 
neuper@37950
  1069
	  prepat = (*WN.18.6.03 Preconditions und Pattern,
walther@59850
  1070
		    die beide passen muessen, damit das Rule_Set.Rrls angewandt wird*)
wneuper@59389
  1071
	  [([TermC.parse_patt @{theory} "?p is_addUnordered"], 
wneuper@59389
  1072
	     TermC.parse_patt @{theory} "?p :: real" 
neuper@37950
  1073
	    (*WN.18.6.03 also KEIN pattern, dieses erzeugt nur das Environment 
neuper@37950
  1074
	      fuer die Evaluation der Precondition "p is_addUnordered"*))],
walther@59857
  1075
	  rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
  1076
	  erls = Rule_Set.append_rules "Rule_Set.empty-is_addUnordered" Rule_Set.empty(*MG: poly_erls*)
wenzelm@60294
  1077
			    [\<^rule_eval>\<open>is_addUnordered\<close> (eval_is_addUnordered "")],
wenzelm@60309
  1078
	  calc = [("PLUS"  ,(\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
wenzelm@60309
  1079
		  ("TIMES" ,(\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
  1080
		  ("DIVIDE",(\<^const_name>\<open>divide\<close>, Prog_Expr.eval_cancel "#divide_e")),
wenzelm@60309
  1081
		  ("POWER" ,(\<^const_name>\<open>powr\<close>  , eval_binop "#power_"))],
neuper@42451
  1082
	  errpatts = [],
wneuper@59416
  1083
	  scr = Rule.Rfuns {init_state  = init_state,
neuper@37950
  1084
		     normal_form = normal_form,
neuper@37950
  1085
		     locate_rule = locate_rule,
neuper@37950
  1086
		     next_rule   = next_rule,
neuper@37950
  1087
		     attach_form = attach_form}};
neuper@37950
  1088
wneuper@59406
  1089
val order_add_rls_ =
walther@59851
  1090
  Rule_Def.Repeat {id = "order_add_rls_", preconds = [], 
walther@59857
  1091
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59852
  1092
      erls = Rule_Set.empty,srls = Rule_Set.Empty,
neuper@42451
  1093
      calc = [], errpatts = [],
wneuper@59416
  1094
      rules = [Rule.Rls_ order_add_
walther@59878
  1095
	       ], scr = Rule.Empty_Prog};
wneuper@59472
  1096
\<close>
neuper@37950
  1097
wneuper@59472
  1098
text \<open>rule-set make_polynomial also named norm_Poly:
neuper@42398
  1099
  Rewrite order has not been implemented properly; the order is better in 
neuper@42398
  1100
  make_polynomial_in (coded in SML).
neuper@42398
  1101
  Notes on state of development:
neuper@42398
  1102
  \# surprise 2006: test --- norm_Poly NOT COMPLETE ---
neuper@42398
  1103
  \# migration Isabelle2002 --> 2011 weakened the rule set, see test
walther@59962
  1104
  --- Matthias Goldgruber 2003 rewrite orders ---, raise ERROR "ord_make_polynomial_in #16b"
wneuper@59472
  1105
\<close>
wneuper@59472
  1106
ML \<open>
neuper@37950
  1107
(*. see MG-DA.p.52ff .*)
neuper@37950
  1108
val make_polynomial(*MG.03, overwrites version from above, 
neuper@37950
  1109
    previously 'make_polynomial_'*) =
walther@59878
  1110
  Rule_Set.Sequence {id = "make_polynomial", preconds = []:term list, 
walther@59857
  1111
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
  1112
      erls = Atools_erls, srls = Rule_Set.Empty,calc = [], errpatts = [],
wneuper@59416
  1113
      rules = [Rule.Rls_ discard_minus,
wneuper@59416
  1114
	       Rule.Rls_ expand_poly_,
wenzelm@60294
  1115
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wneuper@59416
  1116
	       Rule.Rls_ order_mult_rls_,
wneuper@59416
  1117
	       Rule.Rls_ simplify_power_, 
wneuper@59416
  1118
	       Rule.Rls_ calc_add_mult_pow_, 
wneuper@59416
  1119
	       Rule.Rls_ reduce_012_mult_,
wneuper@59416
  1120
	       Rule.Rls_ order_add_rls_,
wneuper@59416
  1121
	       Rule.Rls_ collect_numerals_, 
wneuper@59416
  1122
	       Rule.Rls_ reduce_012_,
wneuper@59416
  1123
	       Rule.Rls_ discard_parentheses1
neuper@37950
  1124
	       ],
walther@59878
  1125
      scr = Rule.Empty_Prog
wneuper@59406
  1126
      };
wneuper@59472
  1127
\<close>
wneuper@59472
  1128
ML \<open>
neuper@37950
  1129
val norm_Poly(*=make_polynomial*) = 
walther@59878
  1130
  Rule_Set.Sequence {id = "norm_Poly", preconds = []:term list, 
walther@59857
  1131
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
  1132
      erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
  1133
      rules = [Rule.Rls_ discard_minus,
wneuper@59416
  1134
	       Rule.Rls_ expand_poly_,
wenzelm@60294
  1135
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wneuper@59416
  1136
	       Rule.Rls_ order_mult_rls_,
wneuper@59416
  1137
	       Rule.Rls_ simplify_power_, 
wneuper@59416
  1138
	       Rule.Rls_ calc_add_mult_pow_, 
wneuper@59416
  1139
	       Rule.Rls_ reduce_012_mult_,
wneuper@59416
  1140
	       Rule.Rls_ order_add_rls_,
wneuper@59416
  1141
	       Rule.Rls_ collect_numerals_, 
wneuper@59416
  1142
	       Rule.Rls_ reduce_012_,
wneuper@59416
  1143
	       Rule.Rls_ discard_parentheses1
neuper@37950
  1144
	       ],
walther@59878
  1145
      scr = Rule.Empty_Prog
wneuper@59406
  1146
      };
wneuper@59472
  1147
\<close>
wneuper@59472
  1148
ML \<open>
wneuper@59416
  1149
(* MG:03 Like make_polynomial_ but without Rule.Rls_ discard_parentheses1 
neuper@37950
  1150
   and expand_poly_rat_ instead of expand_poly_, see MG-DA.p.56ff*)
neuper@37950
  1151
(* MG necessary  for termination of norm_Rational(*_mg*) in Rational.ML*)
neuper@37950
  1152
val make_rat_poly_with_parentheses =
walther@59878
  1153
  Rule_Set.Sequence{id = "make_rat_poly_with_parentheses", preconds = []:term list, 
walther@59857
  1154
      rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
walther@59851
  1155
      erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
wneuper@59416
  1156
      rules = [Rule.Rls_ discard_minus,
wneuper@59416
  1157
	       Rule.Rls_ expand_poly_rat_,(*ignors rationals*)
wenzelm@60294
  1158
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wneuper@59416
  1159
	       Rule.Rls_ order_mult_rls_,
wneuper@59416
  1160
	       Rule.Rls_ simplify_power_, 
wneuper@59416
  1161
	       Rule.Rls_ calc_add_mult_pow_, 
wneuper@59416
  1162
	       Rule.Rls_ reduce_012_mult_,
wneuper@59416
  1163
	       Rule.Rls_ order_add_rls_,
wneuper@59416
  1164
	       Rule.Rls_ collect_numerals_, 
wneuper@59416
  1165
	       Rule.Rls_ reduce_012_
wneuper@59416
  1166
	       (*Rule.Rls_ discard_parentheses1 *)
neuper@37950
  1167
	       ],
walther@59878
  1168
      scr = Rule.Empty_Prog
wneuper@59406
  1169
      };
wneuper@59472
  1170
\<close>
wneuper@59472
  1171
ML \<open>
neuper@37950
  1172
(*.a minimal ruleset for reverse rewriting of factions [2];
neuper@37950
  1173
   compare expand_binoms.*)
neuper@37950
  1174
val rev_rew_p = 
walther@59878
  1175
Rule_Set.Sequence{id = "rev_rew_p", preconds = [], rew_ord = ("termlessI",termlessI),
walther@59851
  1176
    erls = Atools_erls, srls = Rule_Set.Empty,
wenzelm@60309
  1177
    calc = [(*("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")), 
wenzelm@60309
  1178
	    ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
  1179
	    ("POWER", (\<^const_name>\<open>powr\<close>, eval_binop "#power_"))*)
neuper@42451
  1180
	    ], errpatts = [],
wenzelm@60297
  1181
    rules = [\<^rule_thm>\<open>real_plus_binom_times\<close>,
neuper@37950
  1182
	     (*"(a + b)*(a + b) = a ^ 2 + 2 * a * b + b ^ 2*)
wenzelm@60297
  1183
	     \<^rule_thm>\<open>real_plus_binom_times1\<close>,
walther@60260
  1184
	     (*"(a +  1*b)*(a + -1*b) = a \<up> 2 + -1*b \<up> 2"*)
wenzelm@60297
  1185
	     \<^rule_thm>\<open>real_plus_binom_times2\<close>,
walther@60260
  1186
	     (*"(a + -1*b)*(a +  1*b) = a \<up> 2 + -1*b \<up> 2"*)
neuper@37950
  1187
wenzelm@60297
  1188
	     \<^rule_thm>\<open>mult_1_left\<close>,(*"1 * z = z"*)
neuper@37950
  1189
wenzelm@60297
  1190
             \<^rule_thm>\<open>distrib_right\<close>,
neuper@37950
  1191
	     (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60297
  1192
	     \<^rule_thm>\<open>distrib_left\<close>,
neuper@37950
  1193
	     (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
  1194
	       
wenzelm@60297
  1195
	     \<^rule_thm>\<open>mult.assoc\<close>,
neuper@37950
  1196
	     (*"?z1.1 * ?z2.1 * ?z3. =1 ?z1.1 * (?z2.1 * ?z3.1)"*)
wneuper@59416
  1197
	     Rule.Rls_ order_mult_rls_,
wneuper@59416
  1198
	     (*Rule.Rls_ order_add_rls_,*)
neuper@37950
  1199
wenzelm@60294
  1200
	     \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"), 
wenzelm@60294
  1201
	     \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
  1202
	     \<^rule_eval>\<open>powr\<close> (eval_binop "#power_"),
neuper@37950
  1203
	     
wenzelm@60296
  1204
	     \<^rule_thm_sym>\<open>realpow_twoI\<close>,
walther@60242
  1205
	     (*"r1 * r1 = r1 \<up> 2"*)
wenzelm@60296
  1206
	     \<^rule_thm_sym>\<open>real_mult_2\<close>,
neuper@37950
  1207
	     (*"z1 + z1 = 2 * z1"*)
wenzelm@60297
  1208
	     \<^rule_thm>\<open>real_mult_2_assoc\<close>,
neuper@37950
  1209
	     (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
  1210
wenzelm@60297
  1211
	     \<^rule_thm>\<open>real_num_collect\<close>, 
neuper@37950
  1212
	     (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
wenzelm@60297
  1213
	     \<^rule_thm>\<open>real_num_collect_assoc\<close>,
neuper@37950
  1214
	     (*"[| l is_const; m is_const |] ==>  
neuper@37950
  1215
                                     l * n + (m * n + k) =  (l + m) * n + k"*)
wenzelm@60297
  1216
	     \<^rule_thm>\<open>real_one_collect\<close>,
neuper@37950
  1217
	     (*"m is_const ==> n + m * n = (1 + m) * n"*)
wenzelm@60297
  1218
	     \<^rule_thm>\<open>real_one_collect_assoc\<close>, 
neuper@37950
  1219
	     (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@37950
  1220
wenzelm@60297
  1221
	     \<^rule_thm>\<open>realpow_multI\<close>,
walther@60242
  1222
	     (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
neuper@37950
  1223
wenzelm@60294
  1224
	     \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
wenzelm@60294
  1225
	     \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
  1226
	     \<^rule_eval>\<open>powr\<close> (eval_binop "#power_"),
neuper@37950
  1227
wenzelm@60297
  1228
	     \<^rule_thm>\<open>mult_1_left\<close>,(*"1 * z = z"*)
wenzelm@60297
  1229
	     \<^rule_thm>\<open>mult_zero_left\<close>,(*"0 * z = 0"*)
wenzelm@60297
  1230
	     \<^rule_thm>\<open>add_0_left\<close>(*0 + z = z*)
neuper@37950
  1231
wneuper@59416
  1232
	     (*Rule.Rls_ order_add_rls_*)
neuper@37950
  1233
	     ],
neuper@37950
  1234
walther@59878
  1235
    scr = Rule.Empty_Prog};      
wneuper@59472
  1236
\<close>
neuper@52125
  1237
wneuper@59523
  1238
subsection \<open>rule-sets with explicit program for intermediate steps\<close>
wneuper@59523
  1239
partial_function (tailrec) expand_binoms_2 :: "real \<Rightarrow> real"
wneuper@59523
  1240
  where
walther@59635
  1241
"expand_binoms_2 term = (
walther@59635
  1242
  Repeat (
walther@59637
  1243
    (Try (Repeat (Rewrite ''real_plus_binom_pow2''))) #>
walther@59637
  1244
    (Try (Repeat (Rewrite ''real_plus_binom_times''))) #>
walther@59637
  1245
    (Try (Repeat (Rewrite ''real_minus_binom_pow2''))) #>
walther@59637
  1246
    (Try (Repeat (Rewrite ''real_minus_binom_times''))) #>
walther@59637
  1247
    (Try (Repeat (Rewrite ''real_plus_minus_binom1''))) #>
walther@59637
  1248
    (Try (Repeat (Rewrite ''real_plus_minus_binom2''))) #>
walther@59635
  1249
   
walther@59637
  1250
    (Try (Repeat (Rewrite ''mult_1_left''))) #>
walther@59637
  1251
    (Try (Repeat (Rewrite ''mult_zero_left''))) #>
walther@59637
  1252
    (Try (Repeat (Rewrite ''add_0_left''))) #>
walther@59635
  1253
   
walther@59637
  1254
    (Try (Repeat (Calculate ''PLUS''))) #>
walther@59637
  1255
    (Try (Repeat (Calculate ''TIMES''))) #>
walther@59637
  1256
    (Try (Repeat (Calculate ''POWER''))) #>
walther@59635
  1257
   
walther@59637
  1258
    (Try (Repeat (Rewrite ''sym_realpow_twoI''))) #>
walther@59637
  1259
    (Try (Repeat (Rewrite ''realpow_plus_1''))) #>
walther@59637
  1260
    (Try (Repeat (Rewrite ''sym_real_mult_2''))) #>
walther@59637
  1261
    (Try (Repeat (Rewrite ''real_mult_2_assoc''))) #>
walther@59635
  1262
   
walther@59637
  1263
    (Try (Repeat (Rewrite ''real_num_collect''))) #>
walther@59637
  1264
    (Try (Repeat (Rewrite ''real_num_collect_assoc''))) #>
walther@59635
  1265
   
walther@59637
  1266
    (Try (Repeat (Rewrite ''real_one_collect''))) #>
walther@59637
  1267
    (Try (Repeat (Rewrite ''real_one_collect_assoc''))) #>
walther@59635
  1268
   
walther@59637
  1269
    (Try (Repeat (Calculate ''PLUS''))) #>
walther@59637
  1270
    (Try (Repeat (Calculate ''TIMES''))) #>
walther@59635
  1271
    (Try (Repeat (Calculate ''POWER''))))
walther@59635
  1272
  term)"
wneuper@59523
  1273
ML \<open>
wneuper@59523
  1274
val expand_binoms = 
walther@59851
  1275
  Rule_Def.Repeat{id = "expand_binoms", preconds = [], rew_ord = ("termlessI",termlessI),
walther@59851
  1276
      erls = Atools_erls, srls = Rule_Set.Empty,
wenzelm@60309
  1277
      calc = [("PLUS"  , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")), 
wenzelm@60309
  1278
	      ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
wenzelm@60309
  1279
	      ("POWER", (\<^const_name>\<open>powr\<close>, eval_binop "#power_"))
wneuper@59523
  1280
	      ], errpatts = [],
wenzelm@60298
  1281
      rules = [\<^rule_thm>\<open>real_plus_binom_pow2\<close>,     
walther@60242
  1282
	       (*"(a + b) \<up> 2 = a \<up> 2 + 2 * a * b + b \<up> 2"*)
wenzelm@60298
  1283
	       \<^rule_thm>\<open>real_plus_binom_times\<close>,    
wneuper@59523
  1284
	      (*"(a + b)*(a + b) = ...*)
wenzelm@60298
  1285
	       \<^rule_thm>\<open>real_minus_binom_pow2\<close>,   
walther@60242
  1286
	       (*"(a - b) \<up> 2 = a \<up> 2 - 2 * a * b + b \<up> 2"*)
wenzelm@60298
  1287
	       \<^rule_thm>\<open>real_minus_binom_times\<close>,   
wneuper@59523
  1288
	       (*"(a - b)*(a - b) = ...*)
wenzelm@60298
  1289
	       \<^rule_thm>\<open>real_plus_minus_binom1\<close>,   
walther@60242
  1290
		(*"(a + b) * (a - b) = a \<up> 2 - b \<up> 2"*)
wenzelm@60298
  1291
	       \<^rule_thm>\<open>real_plus_minus_binom2\<close>,   
walther@60242
  1292
		(*"(a - b) * (a + b) = a \<up> 2 - b \<up> 2"*)
wneuper@59523
  1293
	       (*RL 020915*)
wenzelm@60297
  1294
	       \<^rule_thm>\<open>real_pp_binom_times\<close>, 
wneuper@59523
  1295
		(*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
wenzelm@60297
  1296
               \<^rule_thm>\<open>real_pm_binom_times\<close>, 
wneuper@59523
  1297
		(*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
wenzelm@60297
  1298
               \<^rule_thm>\<open>real_mp_binom_times\<close>, 
wneuper@59523
  1299
		(*(a - b)*(c + d) = a*c + a*d - b*c - b*d*)
wenzelm@60297
  1300
               \<^rule_thm>\<open>real_mm_binom_times\<close>, 
wneuper@59523
  1301
		(*(a - b)*(c - d) = a*c - a*d - b*c + b*d*)
wenzelm@60297
  1302
	       \<^rule_thm>\<open>realpow_multI\<close>,
walther@60260
  1303
		(*(a*b) \<up> n = a \<up> n * b \<up> n*)
wenzelm@60297
  1304
	       \<^rule_thm>\<open>real_plus_binom_pow3\<close>,
walther@60260
  1305
	        (* (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3 *)
wenzelm@60298
  1306
	       \<^rule_thm>\<open>real_minus_binom_pow3\<close>,
walther@60260
  1307
	        (* (a - b) \<up> 3 = a \<up> 3 - 3*a \<up> 2*b + 3*a*b \<up> 2 - b \<up> 3 *)
wneuper@59523
  1308
wneuper@59523
  1309
wenzelm@60297
  1310
              (*\<^rule_thm>\<open>distrib_right\<close>,	
wneuper@59523
  1311
		(*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
wenzelm@60297
  1312
	       \<^rule_thm>\<open>distrib_left\<close>,	
wneuper@59523
  1313
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
wenzelm@60297
  1314
	       \<^rule_thm>\<open>left_diff_distrib\<close>,	
wneuper@59523
  1315
	       (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
wenzelm@60297
  1316
	       \<^rule_thm>\<open>right_diff_distrib\<close>,	
wneuper@59523
  1317
	       (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
wneuper@59523
  1318
	      *)
wenzelm@60297
  1319
	       \<^rule_thm>\<open>mult_1_left\<close>,
wneuper@59523
  1320
               (*"1 * z = z"*)
wenzelm@60297
  1321
	       \<^rule_thm>\<open>mult_zero_left\<close>,
wneuper@59523
  1322
               (*"0 * z = 0"*)
wenzelm@60297
  1323
	       \<^rule_thm>\<open>add_0_left\<close>,(*"0 + z = z"*)
wneuper@59523
  1324
wenzelm@60294
  1325
	       \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"), 
wenzelm@60294
  1326
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
  1327
	       \<^rule_eval>\<open>powr\<close> (eval_binop "#power_"),
wenzelm@60297
  1328
              (*\<^rule_thm>\<open>mult.commute\<close>,
wneuper@59523
  1329
		(*AC-rewriting*)
wenzelm@60298
  1330
	       \<^rule_thm>\<open>real_mult_left_commute\<close>,
wenzelm@60297
  1331
	       \<^rule_thm>\<open>mult.assoc\<close>,
wenzelm@60297
  1332
	       \<^rule_thm>\<open>add.commute\<close>,
wenzelm@60297
  1333
	       \<^rule_thm>\<open>add.left_commute\<close>,
wenzelm@60297
  1334
	       \<^rule_thm>\<open>add.assoc\<close>,
wneuper@59523
  1335
	      *)
wenzelm@60296
  1336
	       \<^rule_thm_sym>\<open>realpow_twoI\<close>,
walther@60242
  1337
	       (*"r1 * r1 = r1 \<up> 2"*)
wenzelm@60297
  1338
	       \<^rule_thm>\<open>realpow_plus_1\<close>,			
walther@60242
  1339
	       (*"r * r \<up> n = r \<up> (n + 1)"*)
wenzelm@60296
  1340
	       (*\<^rule_thm_sym>\<open>real_mult_2\<close>,		
wneuper@59523
  1341
	       (*"z1 + z1 = 2 * z1"*)*)
wenzelm@60297
  1342
	       \<^rule_thm>\<open>real_mult_2_assoc\<close>,		
wneuper@59523
  1343
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
wneuper@59523
  1344
wenzelm@60297
  1345
	       \<^rule_thm>\<open>real_num_collect\<close>, 
wneuper@59523
  1346
	       (*"[| l is_const; m is_const |] ==>l * n + m * n = (l + m) * n"*)
wenzelm@60298
  1347
	       \<^rule_thm>\<open>real_num_collect_assoc\<close>,	
wneuper@59523
  1348
	       (*"[| l is_const; m is_const |] ==>  
wneuper@59523
  1349
                                       l * n + (m * n + k) =  (l + m) * n + k"*)
wenzelm@60297
  1350
	       \<^rule_thm>\<open>real_one_collect\<close>,
wneuper@59523
  1351
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
wenzelm@60298
  1352
	       \<^rule_thm>\<open>real_one_collect_assoc\<close>, 
wneuper@59523
  1353
	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
wneuper@59523
  1354
wenzelm@60294
  1355
	       \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"), 
wenzelm@60294
  1356
	       \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
wenzelm@60294
  1357
	       \<^rule_eval>\<open>powr\<close> (eval_binop "#power_")
wneuper@59523
  1358
	       ],
walther@59618
  1359
      scr = Rule.Prog (Program.prep_program @{thm expand_binoms_2.simps})
wneuper@59523
  1360
      };      
wneuper@59523
  1361
\<close>
wneuper@59523
  1362
walther@59887
  1363
subsection \<open>add to Know_Store\<close>
wneuper@59523
  1364
subsubsection \<open>rule-sets\<close>
walther@59618
  1365
ML \<open>val prep_rls' = Auto_Prog.prep_rls @{theory}\<close>
s1210629013@55444
  1366
wenzelm@60289
  1367
rule_set_knowledge
wenzelm@60286
  1368
  norm_Poly = \<open>prep_rls' norm_Poly\<close> and
wenzelm@60286
  1369
  Poly_erls = \<open>prep_rls' Poly_erls\<close> (*FIXXXME:del with rls.rls'*) and
wenzelm@60286
  1370
  expand = \<open>prep_rls' expand\<close> and
wenzelm@60286
  1371
  expand_poly = \<open>prep_rls' expand_poly\<close> and
wenzelm@60286
  1372
  simplify_power = \<open>prep_rls' simplify_power\<close> and
neuper@52125
  1373
wenzelm@60286
  1374
  order_add_mult = \<open>prep_rls' order_add_mult\<close> and
wenzelm@60286
  1375
  collect_numerals = \<open>prep_rls' collect_numerals\<close> and
wenzelm@60286
  1376
  collect_numerals_= \<open>prep_rls' collect_numerals_\<close> and
wenzelm@60286
  1377
  reduce_012 = \<open>prep_rls' reduce_012\<close> and
wenzelm@60286
  1378
  discard_parentheses = \<open>prep_rls' discard_parentheses\<close> and
neuper@52125
  1379
 
wenzelm@60286
  1380
  make_polynomial = \<open>prep_rls' make_polynomial\<close> and
wenzelm@60286
  1381
  expand_binoms = \<open>prep_rls' expand_binoms\<close> and
wenzelm@60286
  1382
  rev_rew_p = \<open>prep_rls' rev_rew_p\<close> and
wenzelm@60286
  1383
  discard_minus = \<open>prep_rls' discard_minus\<close> and
wenzelm@60286
  1384
  expand_poly_ = \<open>prep_rls' expand_poly_\<close> and
neuper@52125
  1385
 
wenzelm@60286
  1386
  expand_poly_rat_ = \<open>prep_rls' expand_poly_rat_\<close> and
wenzelm@60286
  1387
  simplify_power_ = \<open>prep_rls' simplify_power_\<close> and
wenzelm@60286
  1388
  calc_add_mult_pow_ = \<open>prep_rls' calc_add_mult_pow_\<close> and
wenzelm@60286
  1389
  reduce_012_mult_ = \<open>prep_rls' reduce_012_mult_\<close> and
wenzelm@60286
  1390
  reduce_012_ = \<open>prep_rls' reduce_012_\<close> and
neuper@52125
  1391
 
wenzelm@60286
  1392
  discard_parentheses1 = \<open>prep_rls' discard_parentheses1\<close> and
wenzelm@60286
  1393
  order_mult_rls_ = \<open>prep_rls' order_mult_rls_\<close> and
wenzelm@60286
  1394
  order_add_rls_ = \<open>prep_rls' order_add_rls_\<close> and
wenzelm@60286
  1395
  make_rat_poly_with_parentheses = \<open>prep_rls' make_rat_poly_with_parentheses\<close>
wneuper@59523
  1396
wneuper@59526
  1397
subsection \<open>problems\<close>
wenzelm@60306
  1398
wenzelm@60306
  1399
problem pbl_simp_poly : "polynomial/simplification" =
wenzelm@60306
  1400
  \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)
wenzelm@60306
  1401
    \<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp "")]\<close>
wenzelm@60306
  1402
  Method: "simplification/for_polynomials"
wenzelm@60306
  1403
  CAS: "Simplify t_t"
wenzelm@60306
  1404
  Given: "Term t_t"
wenzelm@60306
  1405
  Where: "t_t is_polyexp"
wenzelm@60306
  1406
  Find: "normalform n_n"
wneuper@59429
  1407
wneuper@59526
  1408
subsection \<open>methods\<close>
wneuper@59545
  1409
wneuper@59429
  1410
partial_function (tailrec) simplify :: "real \<Rightarrow> real"
wneuper@59429
  1411
  where
walther@59635
  1412
"simplify term = ((Rewrite_Set ''norm_Poly'') term)"
wenzelm@60303
  1413
wenzelm@60303
  1414
method met_simp_poly : "simplification/for_polynomials" =
wenzelm@60303
  1415
  \<open>{rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
wenzelm@60303
  1416
    prls = Rule_Set.append_rules "simplification_for_polynomials_prls" Rule_Set.empty
wenzelm@60303
  1417
      [(*for preds in where_*) \<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp"")],
wenzelm@60303
  1418
    crls = Rule_Set.empty, errpats = [], nrls = norm_Poly}\<close>
wenzelm@60303
  1419
  Program: simplify.simps
wenzelm@60303
  1420
  Given: "Term t_t"
wenzelm@60303
  1421
  Where: "t_t is_polyexp"
wenzelm@60303
  1422
  Find: "normalform n_n"
wenzelm@60303
  1423
wneuper@59472
  1424
ML \<open>
wneuper@59472
  1425
\<close> ML \<open>
wneuper@59472
  1426
\<close> 
neuper@37906
  1427
end