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