src/Tools/isac/Knowledge/Poly.thy
author Walther Neuper <neuper@ist.tugraz.at>
Mon, 22 Jul 2013 13:52:18 +0200
changeset 52070 77138c64f4f6
parent 52062 b3f18f0d55d9
child 52125 6f1d3415dc68
permissions -rw-r--r--
--- Test_Isac.thy runs all tests

NOTEs:
(1) inserted many "trace_rewrite := false" ...
(2) ...nevertheless needs manual interaction at "Tracing paused. Stop, or continue with next 100, 1000, 10000 messages?"
(3) state of tests see respective section in Test_Isac.thy
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------------------------------------------------*)
t@42211
    30
axioms(*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
t@42211
    34
  realpow_pow:             "(a ^^^ b) ^^^ c = a ^^^ (b * c)" (*and*)
t@42211
    35
  realpow_addI:            "r ^^^ (n + m) = r ^^^ n * r ^^^ m" (*and*)
t@42211
    36
  realpow_addI_assoc_l:    "r ^^^ n * (r ^^^ m * s) = r ^^^ (n + m) * s" (*and*)
t@42211
    37
  realpow_addI_assoc_r:    "s * r ^^^ n * r ^^^ m = s * r ^^^ (n + m)" (*and*)
neuper@37906
    38
		  
t@42211
    39
  realpow_oneI:            "r ^^^ 1 = r" (*and*)
t@42211
    40
  realpow_zeroI:            "r ^^^ 0 = 1" (*and*)
t@42211
    41
  realpow_eq_oneI:         "1 ^^^ n = 1" (*and*)
t@42211
    42
  realpow_multI:           "(r * s) ^^^ n = r ^^^ n * s ^^^ n"  (*and*)
neuper@37974
    43
  realpow_multI_poly:      "[| r is_polyexp; s is_polyexp |] ==>
t@42211
    44
			      (r * s) ^^^ n = r ^^^ n * s ^^^ n"  (*and*)
t@42211
    45
  realpow_minus_oneI:      "-1 ^^^ (2 * n) = 1"  (*and*) 
neuper@37906
    46
t@42211
    47
  realpow_twoI:            "r ^^^ 2 = r * r" (*and*)
t@42211
    48
  realpow_twoI_assoc_l:	  "r * (r * s) = r ^^^ 2 * s" (*and*)
t@42211
    49
  realpow_twoI_assoc_r:	  "s * r * r = s * r ^^^ 2" (*and*)
t@42211
    50
  realpow_two_atom:        "r is_atom ==> r * r = r ^^^ 2" (*and*)
t@42211
    51
  realpow_plus_1:          "r * r ^^^ n = r ^^^ (n + 1)"   (*and*)       
t@42211
    52
  realpow_plus_1_assoc_l:  "r * (r ^^^ m * s) = r ^^^ (1 + m) * s"  (*and*)
t@42211
    53
  realpow_plus_1_assoc_l2: "r ^^^ m * (r * s) = r ^^^ (1 + m) * s"  (*and*)
t@42211
    54
  realpow_plus_1_assoc_r:  "s * r * r ^^^ m = s * r ^^^ (1 + m)" (*and*)
t@42211
    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 |]
t@42211
    57
			   ==> r ^^^ n = r * r ^^^ (n + -1)" (*and*)
t@42211
    58
  realpow_addI_atom:       "r is_atom ==> r ^^^ n * r ^^^ m = r ^^^ (n + m)" (*and*)
neuper@37906
    59
neuper@37906
    60
t@42211
    61
  realpow_minus_even:	  "n is_even ==> (- r) ^^^ n = r ^^^ n" (*and*)
t@42211
    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 *)
t@42211
    66
  real_pp_binom_times:     "(a + b)*(c + d) = a*c + a*d + b*c + b*d" (*and*)
t@42211
    67
  real_pm_binom_times:     "(a + b)*(c - d) = a*c - a*d + b*c - b*d" (*and*)
t@42211
    68
  real_mp_binom_times:     "(a - b)*(c + d) = a*c + a*d - b*c - b*d" (*and*)
t@42211
    69
  real_mm_binom_times:     "(a - b)*(c - d) = a*c - a*d - b*c + b*d" (*and*)
t@42211
    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 |] ==> 
t@42211
    72
			    (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" (*and*)
t@42211
    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 +
t@42211
    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)
t@42211
    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)
t@42211
    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)
t@42211
    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 
t@42211
    87
                                + b^^^3)*(a^^^2 + 2*a*b + b^^^2)" (*and*)
t@42211
    88
  real_diff_plus:          "a - b = a + -b" (*17.3.03: do_NOT_use*) (*and*)
t@42211
    89
  real_diff_minus:         "a - b = a + -1 * b" (*and*)
t@42211
    90
  real_plus_binom_times:   "(a + b)*(a + b) = a^^^2 + 2*a*b + b^^^2" (*and*)
t@42211
    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"*)
t@42211
    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 |] ==>
t@42211
    97
			       (a + b)^^^2 = a^^^2 + 2*a*b + b^^^2" (*and*)
t@42211
    98
  real_minus_binom_pow2:      "(a - b)^^^2 = a^^^2 - 2*a*b + b^^^2" (*and*)
t@42211
    99
  real_minus_binom_pow2_p:    "(a - b)^^^2 = a^^^2 + -2*a*b + b^^^2" (*and*)
t@42211
   100
  real_plus_minus_binom1:     "(a + b)*(a - b) = a^^^2 - b^^^2" (*and*)
t@42211
   101
  real_plus_minus_binom1_p:   "(a + b)*(a - b) = a^^^2 + -1*b^^^2" (*and*)
t@42211
   102
  real_plus_minus_binom1_p_p: "(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2" (*and*)
t@42211
   103
  real_plus_minus_binom2:     "(a - b)*(a + b) = a^^^2 - b^^^2" (*and*)
t@42211
   104
  real_plus_minus_binom2_p:   "(a - b)*(a + b) = a^^^2 + -1*b^^^2" (*and*)
t@42211
   105
  real_plus_minus_binom2_p_p: "(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2" (*and*)
t@42211
   106
  real_plus_binom_times1:     "(a +  1*b)*(a + -1*b) = a^^^2 + -1*b^^^2" (*and*)
t@42211
   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 |] ==>
t@42211
   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 |] ==> 
t@42211
   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)
t@42211
   117
				* n + k" (*and*)
neuper@37974
   118
  real_num_collect_assoc_r:   "[| l is_const; m is_const |] ==>
t@42211
   119
			      (k + m * n) + l * n = k + (l + m) * n" (*and*)
t@42211
   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 ! *)
t@42211
   123
  real_one_collect_assoc:     "m is_const ==> n + (m * n + k) = (1 + m)* n + k" (*and*)
neuper@37906
   124
t@42211
   125
  real_one_collect_assoc_l:   "m is_const ==> n + (m * n + k) = (1 + m) * n + k" (*and*)
t@42211
   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 ! *)
t@42211
   130
  real_mult_2_assoc:          "z1 + (z1 + k) = 2 * z1 + k" (*and*)
t@42211
   131
  real_mult_2_assoc_l:        "z1 + (z1 + k) = 2 * z1 + k" (*and*)
t@42211
   132
  real_mult_2_assoc_r:        "(k + z1) + z1 = k + 2 * z1" (*and*)
neuper@37906
   133
t@42211
   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@42319
   399
  [ Calc ("HOL.eq",eval_equal "#equal_"),
neuper@42319
   400
		    Thm  ("real_unari_minus",num_str @{thm real_unari_minus}),
neuper@42319
   401
    Calc ("Groups.plus_class.plus",eval_binop "#add_"),
neuper@42319
   402
		    Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
neuper@42319
   403
		    Calc ("Groups.times_class.times",eval_binop "#mult_"),
neuper@42319
   404
		    Calc ("Atools.pow" ,eval_binop "#power_")
neuper@42319
   405
		  ];
neuper@37950
   406
neuper@37950
   407
val poly_crls = 
neuper@37950
   408
    append_rls "poly_crls" Atools_crls
neuper@41922
   409
               [ Calc ("HOL.eq",eval_equal "#equal_"),
neuper@37969
   410
		 Thm  ("real_unari_minus",num_str @{thm real_unari_minus}),
neuper@38014
   411
                 Calc ("Groups.plus_class.plus",eval_binop "#add_"),
neuper@38014
   412
		 Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
neuper@38034
   413
		 Calc ("Groups.times_class.times",eval_binop "#mult_"),
neuper@37950
   414
		 Calc ("Atools.pow" ,eval_binop "#power_")
neuper@37950
   415
		 ];
neuper@37950
   416
neuper@37950
   417
local (*. for make_polynomial .*)
neuper@37950
   418
neuper@37950
   419
open Term;  (* for type order = EQUAL | LESS | GREATER *)
neuper@37950
   420
neuper@37950
   421
fun pr_ord EQUAL = "EQUAL"
neuper@37950
   422
  | pr_ord LESS  = "LESS"
neuper@37950
   423
  | pr_ord GREATER = "GREATER";
neuper@37950
   424
neuper@37950
   425
fun dest_hd' (Const (a, T)) =                          (* ~ term.ML *)
neuper@37950
   426
  (case a of
neuper@37950
   427
     "Atools.pow" => ((("|||||||||||||", 0), T), 0)    (*WN greatest string*)
neuper@37950
   428
   | _ => (((a, 0), T), 0))
neuper@37950
   429
  | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
neuper@37950
   430
  | dest_hd' (Var v) = (v, 2)
neuper@37950
   431
  | dest_hd' (Bound i) = ((("", i), dummyT), 3)
neuper@37950
   432
  | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
neuper@37950
   433
neuper@37950
   434
fun get_order_pow (t $ (Free(order,_))) = (* RL FIXXXME:geht zufaellig?WN*)
neuper@37950
   435
    	(case int_of_str (order) of
neuper@37950
   436
	             SOME d => d
neuper@37950
   437
		   | NONE   => 0)
neuper@37950
   438
  | get_order_pow _ = 0;
neuper@37950
   439
neuper@37950
   440
fun size_of_term' (Const(str,_) $ t) =
neuper@37950
   441
  if "Atools.pow"= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
neuper@37950
   442
  | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
neuper@37950
   443
  | size_of_term' (f$t) = size_of_term' f  +  size_of_term' t
neuper@37950
   444
  | size_of_term' _ = 1;
neuper@37950
   445
neuper@37950
   446
fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) =       (* ~ term.ML *)
neuper@52070
   447
    (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
neuper@37950
   448
  | term_ord' pr thy (t, u) =
neuper@52070
   449
    (if pr then 
neuper@52070
   450
	   let
neuper@52070
   451
       val (f, ts) = strip_comb t and (g, us) = strip_comb u;
neuper@52070
   452
       val _ = tracing ("t= f@ts= \"" ^ term_to_string''' thy f ^ "\" @ \"[" ^
neuper@52070
   453
         commas (map (term_to_string''' thy) ts) ^ "]\"");
neuper@52070
   454
       val _ = tracing("u= g@us= \"" ^ term_to_string''' thy g ^ "\" @ \"[" ^
neuper@52070
   455
         commas (map (term_to_string''' thy) us) ^ "]\"");
neuper@52070
   456
       val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
neuper@52070
   457
         string_of_int (size_of_term' u) ^ ")");
neuper@52070
   458
       val _ = tracing ("hd_ord(f,g)      = " ^ (pr_ord o hd_ord) (f,g));
neuper@52070
   459
       val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o terms_ord str false) (ts, us));
neuper@52070
   460
       val _ = tracing ("-------");
neuper@52070
   461
     in () end
neuper@37950
   462
       else ();
neuper@37950
   463
	 case int_ord (size_of_term' t, size_of_term' u) of
neuper@37950
   464
	   EQUAL =>
neuper@37950
   465
	     let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
neuper@37950
   466
	       (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us) 
neuper@37950
   467
	     | ord => ord)
neuper@37950
   468
	     end
neuper@37950
   469
	 | ord => ord)
neuper@37950
   470
and hd_ord (f, g) =                                        (* ~ term.ML *)
neuper@37974
   471
  prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
neuper@37950
   472
and terms_ord str pr (ts, us) = 
neuper@37991
   473
    list_ord (term_ord' pr (assoc_thy "Isac"))(ts, us);
neuper@52070
   474
neuper@37950
   475
in
neuper@37950
   476
neuper@37950
   477
fun ord_make_polynomial (pr:bool) thy (_:subst) tu = 
neuper@37950
   478
    (term_ord' pr thy(***) tu = LESS );
neuper@37950
   479
neuper@37950
   480
end;(*local*)
neuper@37950
   481
neuper@37950
   482
neuper@37950
   483
rew_ord' := overwritel (!rew_ord',
neuper@37950
   484
[("termlessI", termlessI),
neuper@37950
   485
 ("ord_make_polynomial", ord_make_polynomial false thy)
neuper@37950
   486
 ]);
neuper@37950
   487
neuper@37950
   488
neuper@37950
   489
val expand =
neuper@37974
   490
  Rls{id = "expand", preconds = [], rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
   491
      erls = e_rls,srls = Erls, calc = [], errpatts = [],
neuper@52062
   492
      rules = [Thm ("distrib_right" ,num_str @{thm distrib_right}),
neuper@37950
   493
	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@52062
   494
	       Thm ("distrib_left",num_str @{thm distrib_left})
neuper@37950
   495
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
   496
	       ], scr = EmptyScr}:rls;
neuper@37950
   497
neuper@37950
   498
(*----------------- Begin: rulesets for make_polynomial_ -----------------
neuper@37950
   499
  'rlsIDs' redefined by MG as 'rlsIDs_' 
neuper@37950
   500
                                    ^^^*)
neuper@37950
   501
neuper@37980
   502
val discard_minus =
neuper@42407
   503
  Rls {id = "discard_minus", preconds = [], rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
   504
      erls = e_rls, srls = Erls, calc = [], errpatts = [],
neuper@42407
   505
      rules =
neuper@42407
   506
       [Thm ("real_diff_minus", num_str @{thm real_diff_minus}),
neuper@42407
   507
          (*"a - b = a + -1 * b"*)
neuper@42407
   508
	        Thm ("sym_real_mult_minus1", num_str (@{thm real_mult_minus1} RS @{thm sym}))
neuper@42407
   509
	          (*- ?z = "-1 * ?z"*)],
neuper@42407
   510
	      scr = EmptyScr}:rls;
neuper@37980
   511
neuper@37950
   512
val expand_poly_ = 
neuper@37950
   513
  Rls{id = "expand_poly_", preconds = [], 
neuper@37950
   514
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   515
      erls = e_rls,srls = Erls,
neuper@42451
   516
      calc = [], errpatts = [],
neuper@42407
   517
      rules =
neuper@42407
   518
        [Thm ("real_plus_binom_pow4",num_str @{thm real_plus_binom_pow4}),
neuper@42407
   519
	           (*"(a + b)^^^4 = ... "*)
neuper@42407
   520
	         Thm ("real_plus_binom_pow5",num_str @{thm real_plus_binom_pow5}),
neuper@42407
   521
	           (*"(a + b)^^^5 = ... "*)
neuper@42407
   522
	         Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
neuper@42407
   523
	           (*"(a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
neuper@42407
   524
	         (*WN071229 changed/removed for Schaerding -----vvv*)
neuper@42407
   525
	         (*Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),*)
neuper@42407
   526
	           (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
neuper@42407
   527
	         Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),
neuper@42407
   528
	           (*"(a + b)^^^2 = (a + b) * (a + b)"*)
neuper@42407
   529
	         (*Thm ("real_plus_minus_binom1_p_p", num_str @{thm real_plus_minus_binom1_p_p}),*)
neuper@42407
   530
	           (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
neuper@42407
   531
	         (*Thm ("real_plus_minus_binom2_p_p", num_str @{thm real_plus_minus_binom2_p_p}),*)
neuper@42407
   532
	           (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
neuper@42407
   533
	         (*WN071229 changed/removed for Schaerding -----^^^*)
neuper@37950
   534
	      
neuper@52062
   535
	         Thm ("distrib_right" ,num_str @{thm distrib_right}),
neuper@42407
   536
	           (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@52062
   537
	         Thm ("distrib_left",num_str @{thm distrib_left}),
neuper@42407
   538
	           (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
   539
	       
neuper@42407
   540
	         Thm ("realpow_multI", num_str @{thm realpow_multI}),
neuper@42407
   541
	           (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
neuper@42407
   542
	         Thm ("realpow_pow",num_str @{thm realpow_pow})
neuper@42407
   543
	           (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
neuper@37950
   544
	       ], scr = EmptyScr}:rls;
neuper@37950
   545
neuper@37950
   546
(*.the expression contains + - * ^ only ?
neuper@37950
   547
   this is weaker than 'is_polynomial' !.*)
neuper@37950
   548
fun is_polyexp (Free _) = true
neuper@38014
   549
  | is_polyexp (Const ("Groups.plus_class.plus",_) $ Free _ $ Free _) = true
neuper@38014
   550
  | is_polyexp (Const ("Groups.minus_class.minus",_) $ Free _ $ Free _) = true
neuper@38034
   551
  | is_polyexp (Const ("Groups.times_class.times",_) $ Free _ $ Free _) = true
neuper@37950
   552
  | is_polyexp (Const ("Atools.pow",_) $ Free _ $ Free _) = true
neuper@38014
   553
  | is_polyexp (Const ("Groups.plus_class.plus",_) $ t1 $ t2) = 
neuper@37950
   554
               ((is_polyexp t1) andalso (is_polyexp t2))
neuper@38014
   555
  | is_polyexp (Const ("Groups.minus_class.minus",_) $ t1 $ t2) = 
neuper@37950
   556
               ((is_polyexp t1) andalso (is_polyexp t2))
neuper@38034
   557
  | is_polyexp (Const ("Groups.times_class.times",_) $ t1 $ t2) = 
neuper@37950
   558
               ((is_polyexp t1) andalso (is_polyexp t2))
neuper@37950
   559
  | is_polyexp (Const ("Atools.pow",_) $ t1 $ t2) = 
neuper@37950
   560
               ((is_polyexp t1) andalso (is_polyexp t2))
neuper@37950
   561
  | is_polyexp _ = false;
neuper@37950
   562
neuper@37950
   563
(*("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp ""))*)
neuper@37950
   564
fun eval_is_polyexp (thmid:string) _ 
neuper@37950
   565
		       (t as (Const("Poly.is'_polyexp", _) $ arg)) thy = 
neuper@37950
   566
    if is_polyexp arg
neuper@52070
   567
    then SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
   568
	         Trueprop $ (mk_equality (t, @{term True})))
neuper@52070
   569
    else SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
   570
	         Trueprop $ (mk_equality (t, @{term False})))
neuper@37950
   571
  | eval_is_polyexp _ _ _ _ = NONE; 
neuper@37950
   572
neuper@37950
   573
val expand_poly_rat_ = 
neuper@37950
   574
  Rls{id = "expand_poly_rat_", preconds = [], 
neuper@37950
   575
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   576
      erls =  append_rls "e_rls-is_polyexp" e_rls
neuper@37950
   577
	        [Calc ("Poly.is'_polyexp", eval_is_polyexp "")
neuper@37950
   578
		 ],
neuper@37950
   579
      srls = Erls,
neuper@42451
   580
      calc = [], errpatts = [],
neuper@37950
   581
      rules = 
neuper@37969
   582
        [Thm ("real_plus_binom_pow4_poly", num_str @{thm real_plus_binom_pow4_poly}),
neuper@37950
   583
	     (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^4 = ... "*)
neuper@37969
   584
	 Thm ("real_plus_binom_pow5_poly", num_str @{thm real_plus_binom_pow5_poly}),
neuper@37950
   585
	     (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^5 = ... "*)
neuper@37969
   586
	 Thm ("real_plus_binom_pow2_poly",num_str @{thm real_plus_binom_pow2_poly}),
neuper@37950
   587
	     (*"[| a is_polyexp; b is_polyexp |] ==>
neuper@37950
   588
		            (a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
neuper@37969
   589
	 Thm ("real_plus_binom_pow3_poly",num_str @{thm real_plus_binom_pow3_poly}),
neuper@37950
   590
	     (*"[| a is_polyexp; b is_polyexp |] ==> 
neuper@37950
   591
			(a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
neuper@37969
   592
	 Thm ("real_plus_minus_binom1_p_p",num_str @{thm real_plus_minus_binom1_p_p}),
neuper@37950
   593
	     (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
neuper@37969
   594
	 Thm ("real_plus_minus_binom2_p_p",num_str @{thm real_plus_minus_binom2_p_p}),
neuper@37950
   595
	     (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
neuper@37950
   596
	      
neuper@37974
   597
	 Thm ("real_add_mult_distrib_poly",
neuper@37974
   598
               num_str @{thm real_add_mult_distrib_poly}),
neuper@37950
   599
	       (*"w is_polyexp ==> (z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@37974
   600
	 Thm("real_add_mult_distrib2_poly",
neuper@37974
   601
              num_str @{thm real_add_mult_distrib2_poly}),
neuper@37950
   602
	     (*"w is_polyexp ==> w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
   603
	       
neuper@37969
   604
	 Thm ("realpow_multI_poly", num_str @{thm realpow_multI_poly}),
neuper@37950
   605
	     (*"[| r is_polyexp; s is_polyexp |] ==> 
neuper@37950
   606
		            (r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
neuper@37969
   607
	  Thm ("realpow_pow",num_str @{thm realpow_pow})
neuper@37950
   608
	      (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
neuper@37950
   609
	 ], scr = EmptyScr}:rls;
neuper@37950
   610
neuper@37950
   611
val simplify_power_ = 
neuper@37950
   612
  Rls{id = "simplify_power_", preconds = [], 
neuper@37950
   613
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   614
      erls = e_rls, srls = Erls,
neuper@42451
   615
      calc = [], errpatts = [],
neuper@37950
   616
      rules = [(*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
neuper@37950
   617
		a*(a*a) --> a*a^^^2 und nicht a*(a*a) --> a^^^2*a *)
neuper@37969
   618
	       Thm ("sym_realpow_twoI",
neuper@37969
   619
                     num_str (@{thm realpow_twoI} RS @{thm sym})),	
neuper@37950
   620
	       (*"r * r = r ^^^ 2"*)
neuper@37969
   621
	       Thm ("realpow_twoI_assoc_l",num_str @{thm realpow_twoI_assoc_l}),
neuper@37950
   622
	       (*"r * (r * s) = r ^^^ 2 * s"*)
neuper@37950
   623
neuper@37969
   624
	       Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),		
neuper@37950
   625
	       (*"r * r ^^^ n = r ^^^ (n + 1)"*)
neuper@37969
   626
	       Thm ("realpow_plus_1_assoc_l",
neuper@37969
   627
                     num_str @{thm realpow_plus_1_assoc_l}),
neuper@37950
   628
	       (*"r * (r ^^^ m * s) = r ^^^ (1 + m) * s"*)
neuper@37950
   629
	       (*MG 9.7.03: neues Thm wegen a*(a*(a*b)) --> a^^^2*(a*b) *)
neuper@37969
   630
	       Thm ("realpow_plus_1_assoc_l2",
neuper@37969
   631
                     num_str @{thm realpow_plus_1_assoc_l2}),
neuper@37950
   632
	       (*"r ^^^ m * (r * s) = r ^^^ (1 + m) * s"*)
neuper@37950
   633
neuper@37969
   634
	       Thm ("sym_realpow_addI",
neuper@37969
   635
               num_str (@{thm realpow_addI} RS @{thm sym})),
neuper@37950
   636
	       (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
neuper@37969
   637
	       Thm ("realpow_addI_assoc_l",num_str @{thm realpow_addI_assoc_l}),
neuper@37950
   638
	       (*"r ^^^ n * (r ^^^ m * s) = r ^^^ (n + m) * s"*)
neuper@37950
   639
	       
neuper@37950
   640
	       (* ist in expand_poly - wird hier aber auch gebraucht, wegen: 
neuper@37950
   641
		  "r * r = r ^^^ 2" wenn r=a^^^b*)
neuper@37969
   642
	       Thm ("realpow_pow",num_str @{thm realpow_pow})
neuper@37950
   643
	       (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
neuper@37950
   644
	       ], scr = EmptyScr}:rls;
neuper@37950
   645
neuper@37950
   646
val calc_add_mult_pow_ = 
neuper@37950
   647
  Rls{id = "calc_add_mult_pow_", preconds = [], 
neuper@37950
   648
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   649
      erls = Atools_erls(*erls3.4.03*),srls = Erls,
neuper@38014
   650
      calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
neuper@38034
   651
	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@37950
   652
	      ("POWER", ("Atools.pow", eval_binop "#power_"))
neuper@37950
   653
	      ],
neuper@42451
   654
      errpatts = [],
neuper@38014
   655
      rules = [Calc ("Groups.plus_class.plus", eval_binop "#add_"),
neuper@38034
   656
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
   657
	       Calc ("Atools.pow", eval_binop "#power_")
neuper@37950
   658
	       ], scr = EmptyScr}:rls;
neuper@37950
   659
neuper@37950
   660
val reduce_012_mult_ = 
neuper@37950
   661
  Rls{id = "reduce_012_mult_", preconds = [], 
neuper@37950
   662
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   663
      erls = e_rls,srls = Erls,
neuper@42451
   664
      calc = [], errpatts = [],
neuper@37950
   665
      rules = [(* MG: folgende Thm müssen hier stehen bleiben: *)
neuper@37965
   666
               Thm ("mult_1_right",num_str @{thm mult_1_right}),
neuper@37950
   667
	       (*"z * 1 = z"*) (*wegen "a * b * b^^^(-1) + a"*) 
neuper@37969
   668
	       Thm ("realpow_zeroI",num_str @{thm realpow_zeroI}),
neuper@37950
   669
	       (*"r ^^^ 0 = 1"*) (*wegen "a*a^^^(-1)*c + b + c"*)
neuper@37969
   670
	       Thm ("realpow_oneI",num_str @{thm realpow_oneI}),
neuper@37950
   671
	       (*"r ^^^ 1 = r"*)
neuper@37974
   672
	       Thm ("realpow_eq_oneI",num_str @{thm realpow_eq_oneI})
neuper@37950
   673
	       (*"1 ^^^ n = 1"*)
neuper@37950
   674
	       ], scr = EmptyScr}:rls;
neuper@37950
   675
neuper@37950
   676
val collect_numerals_ = 
neuper@37950
   677
  Rls{id = "collect_numerals_", preconds = [], 
neuper@37950
   678
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   679
      erls = Atools_erls, srls = Erls,
neuper@38014
   680
      calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_"))
neuper@42451
   681
	      ], errpatts = [],
neuper@37950
   682
      rules = 
neuper@37969
   683
        [Thm ("real_num_collect",num_str @{thm real_num_collect}), 
neuper@37950
   684
	     (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
neuper@37969
   685
	 Thm ("real_num_collect_assoc_r",num_str @{thm real_num_collect_assoc_r}),
neuper@37950
   686
	     (*"[| l is_const; m is_const |] ==>  \
neuper@37950
   687
					\(k + m * n) + l * n = k + (l + m)*n"*)
neuper@37969
   688
	 Thm ("real_one_collect",num_str @{thm real_one_collect}),	
neuper@37950
   689
	     (*"m is_const ==> n + m * n = (1 + m) * n"*)
neuper@37969
   690
	 Thm ("real_one_collect_assoc_r",num_str @{thm real_one_collect_assoc_r}), 
neuper@37950
   691
	     (*"m is_const ==> (k + n) + m * n = k + (m + 1) * n"*)
neuper@37950
   692
neuper@38014
   693
         Calc ("Groups.plus_class.plus", eval_binop "#add_"),
neuper@37950
   694
neuper@37950
   695
	 (*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
neuper@37950
   696
		     (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
neuper@37969
   697
         Thm ("real_mult_2_assoc_r",num_str @{thm real_mult_2_assoc_r}),
neuper@37950
   698
	     (*"(k + z1) + z1 = k + 2 * z1"*)
neuper@37969
   699
	 Thm ("sym_real_mult_2",num_str (@{thm real_mult_2} RS @{thm sym}))
neuper@37950
   700
	     (*"z1 + z1 = 2 * z1"*)
neuper@37950
   701
	], scr = EmptyScr}:rls;
neuper@37950
   702
neuper@37950
   703
val reduce_012_ = 
neuper@37950
   704
  Rls{id = "reduce_012_", preconds = [], 
neuper@37950
   705
      rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
   706
      erls = e_rls,srls = Erls, calc = [], errpatts = [],
neuper@37965
   707
      rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),                 
neuper@37950
   708
	       (*"1 * z = z"*)
neuper@37965
   709
	       Thm ("mult_zero_left",num_str @{thm mult_zero_left}),        
neuper@37950
   710
	       (*"0 * z = 0"*)
neuper@37974
   711
	       Thm ("mult_zero_right",num_str @{thm mult_zero_right}),
neuper@37950
   712
	       (*"z * 0 = 0"*)
neuper@37965
   713
	       Thm ("add_0_left",num_str @{thm add_0_left}),
neuper@37950
   714
	       (*"0 + z = z"*)
neuper@37965
   715
	       Thm ("add_0_right",num_str @{thm add_0_right}),
neuper@37950
   716
	       (*"z + 0 = z"*) (*wegen a+b-b --> a+(1-1)*b --> a+0 --> a*)
neuper@37950
   717
neuper@37969
   718
	       (*Thm ("realpow_oneI",num_str @{thm realpow_oneI})*)
neuper@37950
   719
	       (*"?r ^^^ 1 = ?r"*)
neuper@37965
   720
	       Thm ("divide_zero_left",num_str @{thm divide_zero_left})(*WN060914*)
neuper@37950
   721
	       (*"0 / ?x = 0"*)
neuper@37950
   722
	       ], scr = EmptyScr}:rls;
neuper@37950
   723
neuper@37950
   724
(*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
neuper@37979
   725
val discard_parentheses1 = 
neuper@37979
   726
    append_rls "discard_parentheses1" e_rls 
neuper@48763
   727
	       [Thm ("sym_mult_assoc",
neuper@48763
   728
                      num_str (@{thm mult_assoc} RS @{thm sym}))
neuper@37950
   729
		(*"?z1.1 * (?z2.1 * ?z3.1) = ?z1.1 * ?z2.1 * ?z3.1"*)
neuper@37974
   730
		(*Thm ("sym_add_assoc",
neuper@37974
   731
                        num_str (@{thm add_assoc} RS @{thm sym}))*)
neuper@37950
   732
		(*"?z1.1 + (?z2.1 + ?z3.1) = ?z1.1 + ?z2.1 + ?z3.1"*)
neuper@37950
   733
		 ];
neuper@37950
   734
neuper@37950
   735
(*----------------- End: rulesets for make_polynomial_ -----------------*)
neuper@37950
   736
neuper@37950
   737
(*MG.0401 ev. for use in rls with ordered rewriting ?
neuper@37950
   738
val collect_numerals_left = 
neuper@37950
   739
  Rls{id = "collect_numerals", preconds = [], 
neuper@37950
   740
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   741
      erls = Atools_erls(*erls3.4.03*),srls = Erls,
neuper@38014
   742
      calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
neuper@38034
   743
	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@37950
   744
	      ("POWER", ("Atools.pow", eval_binop "#power_"))
neuper@37950
   745
	      ],
neuper@42451
   746
      errpatts = [],
neuper@37969
   747
      rules = [Thm ("real_num_collect",num_str @{thm real_num_collect}), 
neuper@37950
   748
	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
neuper@37969
   749
	       Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
neuper@37950
   750
	       (*"[| l is_const; m is_const |] ==>  
neuper@37950
   751
				l * n + (m * n + k) =  (l + m) * n + k"*)
neuper@37969
   752
	       Thm ("real_one_collect",num_str @{thm real_one_collect}),	
neuper@37950
   753
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
neuper@37969
   754
	       Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
neuper@37950
   755
	       (*"m is_const ==> n + (m * n + k) = (1 + m) * n + k"*)
neuper@37950
   756
	       
neuper@38014
   757
	       Calc ("Groups.plus_class.plus", eval_binop "#add_"),
neuper@37950
   758
neuper@37950
   759
	       (*MG am 2.5.03: 2 Theoreme aus reduce_012 hierher verschoben*)
neuper@37969
   760
	       Thm ("sym_real_mult_2",
neuper@37969
   761
                     num_str (@{thm real_mult_2} RS @{thm sym})),	
neuper@37950
   762
	       (*"z1 + z1 = 2 * z1"*)
neuper@37969
   763
	       Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc})
neuper@37950
   764
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
   765
	       ], scr = EmptyScr}:rls;*)
neuper@37950
   766
neuper@37950
   767
val expand_poly = 
neuper@37950
   768
  Rls{id = "expand_poly", preconds = [], 
neuper@37950
   769
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   770
      erls = e_rls,srls = Erls,
neuper@42451
   771
      calc = [], errpatts = [],
neuper@37950
   772
      (*asm_thm = [],*)
neuper@52062
   773
      rules = [Thm ("distrib_right" ,num_str @{thm distrib_right}),
neuper@37950
   774
	       (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@52062
   775
	       Thm ("distrib_left",num_str @{thm distrib_left}),
neuper@37950
   776
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@52062
   777
	       (*Thm ("distrib_right1",num_str @{thm distrib_right}1),
neuper@37950
   778
		....... 18.3.03 undefined???*)
neuper@37950
   779
neuper@37969
   780
	       Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),
neuper@37950
   781
	       (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
neuper@37969
   782
	       Thm ("real_minus_binom_pow2_p",num_str @{thm real_minus_binom_pow2_p}),
neuper@37950
   783
	       (*"(a - b)^^^2 = a^^^2 + -2*a*b + b^^^2"*)
neuper@37950
   784
	       Thm ("real_plus_minus_binom1_p",
neuper@37969
   785
		    num_str @{thm real_plus_minus_binom1_p}),
neuper@37950
   786
	       (*"(a + b)*(a - b) = a^^^2 + -1*b^^^2"*)
neuper@37950
   787
	       Thm ("real_plus_minus_binom2_p",
neuper@37969
   788
		    num_str @{thm real_plus_minus_binom2_p}),
neuper@37950
   789
	       (*"(a - b)*(a + b) = a^^^2 + -1*b^^^2"*)
neuper@37950
   790
neuper@37965
   791
	       Thm ("minus_minus",num_str @{thm minus_minus}),
neuper@37950
   792
	       (*"- (- ?z) = ?z"*)
neuper@37969
   793
	       Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
neuper@37950
   794
	       (*"a - b = a + -1 * b"*)
neuper@37969
   795
	       Thm ("sym_real_mult_minus1",
neuper@37969
   796
                     num_str (@{thm real_mult_minus1} RS @{thm sym}))
neuper@37950
   797
	       (*- ?z = "-1 * ?z"*)
neuper@37950
   798
neuper@37950
   799
	       (*Thm ("real_minus_add_distrib",
neuper@37969
   800
		      num_str @{thm real_minus_add_distrib}),*)
neuper@37950
   801
	       (*"- (?x + ?y) = - ?x + - ?y"*)
neuper@37969
   802
	       (*Thm ("real_diff_plus",num_str @{thm real_diff_plus})*)
neuper@37950
   803
	       (*"a - b = a + -b"*)
neuper@37950
   804
	       ], scr = EmptyScr}:rls;
neuper@37950
   805
neuper@37950
   806
val simplify_power = 
neuper@37950
   807
  Rls{id = "simplify_power", preconds = [], 
neuper@37950
   808
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   809
      erls = e_rls, srls = Erls,
neuper@42451
   810
      calc = [], errpatts = [],
neuper@37969
   811
      rules = [Thm ("realpow_multI", num_str @{thm realpow_multI}),
neuper@37950
   812
	       (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
neuper@37950
   813
	       
neuper@37969
   814
	       Thm ("sym_realpow_twoI",
neuper@37969
   815
                     num_str( @{thm realpow_twoI} RS @{thm sym})),	
neuper@37950
   816
	       (*"r1 * r1 = r1 ^^^ 2"*)
neuper@37969
   817
	       Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),		
neuper@37950
   818
	       (*"r * r ^^^ n = r ^^^ (n + 1)"*)
neuper@37969
   819
	       Thm ("realpow_pow",num_str @{thm realpow_pow}),
neuper@37950
   820
	       (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
neuper@37969
   821
	       Thm ("sym_realpow_addI",
neuper@37969
   822
                     num_str (@{thm realpow_addI} RS @{thm sym})),
neuper@37950
   823
	       (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
neuper@37969
   824
	       Thm ("realpow_oneI",num_str @{thm realpow_oneI}),
neuper@37950
   825
	       (*"r ^^^ 1 = r"*)
neuper@37969
   826
	       Thm ("realpow_eq_oneI",num_str @{thm realpow_eq_oneI})
neuper@37950
   827
	       (*"1 ^^^ n = 1"*)
neuper@37950
   828
	       ], scr = EmptyScr}:rls;
neuper@37950
   829
(*MG.0401: termorders for multivariate polys dropped due to principal problems:
neuper@37950
   830
  (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
neuper@37950
   831
val order_add_mult = 
neuper@37950
   832
  Rls{id = "order_add_mult", preconds = [], 
neuper@37972
   833
      rew_ord = ("ord_make_polynomial",ord_make_polynomial false thy),
neuper@37950
   834
      erls = e_rls,srls = Erls,
neuper@42451
   835
      calc = [], errpatts = [],
neuper@48763
   836
      rules = [Thm ("mult_commute",num_str @{thm mult_commute}),
neuper@37950
   837
	       (* z * w = w * z *)
neuper@37969
   838
	       Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
neuper@37950
   839
	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
neuper@48763
   840
	       Thm ("mult_assoc",num_str @{thm mult_assoc}),		
neuper@37950
   841
	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
neuper@37965
   842
	       Thm ("add_commute",num_str @{thm add_commute}),	
neuper@37950
   843
	       (*z + w = w + z*)
neuper@37965
   844
	       Thm ("add_left_commute",num_str @{thm add_left_commute}),
neuper@37950
   845
	       (*x + (y + z) = y + (x + z)*)
neuper@37965
   846
	       Thm ("add_assoc",num_str @{thm add_assoc})	               
neuper@37950
   847
	       (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
neuper@37950
   848
	       ], scr = EmptyScr}:rls;
neuper@37950
   849
(*MG.0401: termorders for multivariate polys dropped due to principal problems:
neuper@37950
   850
  (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
neuper@37950
   851
val order_mult = 
neuper@37950
   852
  Rls{id = "order_mult", preconds = [], 
neuper@37972
   853
      rew_ord = ("ord_make_polynomial",ord_make_polynomial false thy),
neuper@37950
   854
      erls = e_rls,srls = Erls,
neuper@42451
   855
      calc = [], errpatts = [],
neuper@48763
   856
      rules = [Thm ("mult_commute",num_str @{thm mult_commute}),
neuper@37950
   857
	       (* z * w = w * z *)
neuper@37969
   858
	       Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
neuper@37950
   859
	       (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
neuper@48763
   860
	       Thm ("mult_assoc",num_str @{thm mult_assoc})	
neuper@37950
   861
	       (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
neuper@37950
   862
	       ], scr = EmptyScr}:rls;
neuper@42451
   863
*}
neuper@42451
   864
neuper@42451
   865
ML {*
neuper@37950
   866
val collect_numerals = 
neuper@37950
   867
  Rls{id = "collect_numerals", preconds = [], 
neuper@37950
   868
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   869
      erls = Atools_erls(*erls3.4.03*),srls = Erls,
neuper@38014
   870
      calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
neuper@38034
   871
	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@37950
   872
	      ("POWER", ("Atools.pow", eval_binop "#power_"))
neuper@42451
   873
	      ], errpatts = [],
neuper@37969
   874
      rules = [Thm ("real_num_collect",num_str @{thm real_num_collect}), 
neuper@37950
   875
	       (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
neuper@37969
   876
	       Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
neuper@37950
   877
	       (*"[| l is_const; m is_const |] ==>  
neuper@37950
   878
				l * n + (m * n + k) =  (l + m) * n + k"*)
neuper@37969
   879
	       Thm ("real_one_collect",num_str @{thm real_one_collect}),	
neuper@37950
   880
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
neuper@37969
   881
	       Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
neuper@37950
   882
	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@38014
   883
	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
neuper@38034
   884
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
   885
	       Calc ("Atools.pow", eval_binop "#power_")
neuper@37950
   886
	       ], scr = EmptyScr}:rls;
neuper@37950
   887
val reduce_012 = 
neuper@37950
   888
  Rls{id = "reduce_012", preconds = [], 
neuper@37950
   889
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   890
      erls = e_rls,srls = Erls,
neuper@42451
   891
      calc = [], errpatts = [],
neuper@37965
   892
      rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),                 
neuper@37950
   893
	       (*"1 * z = z"*)
neuper@37969
   894
	       (*Thm ("real_mult_minus1",num_str @{thm real_mult_minus1}),14.3.03*)
neuper@37950
   895
	       (*"-1 * z = - z"*)
neuper@37965
   896
	       Thm ("minus_mult_left", 
neuper@37974
   897
		    num_str (@{thm minus_mult_left} RS @{thm sym})),
neuper@37950
   898
	       (*- (?x * ?y) = "- ?x * ?y"*)
neuper@37969
   899
	       (*Thm ("real_minus_mult_cancel",
neuper@37969
   900
                       num_str @{thm real_minus_mult_cancel}),
neuper@37950
   901
	       (*"- ?x * - ?y = ?x * ?y"*)---*)
neuper@37965
   902
	       Thm ("mult_zero_left",num_str @{thm mult_zero_left}),        
neuper@37950
   903
	       (*"0 * z = 0"*)
neuper@37965
   904
	       Thm ("add_0_left",num_str @{thm add_0_left}),
neuper@37950
   905
	       (*"0 + z = z"*)
neuper@37965
   906
	       Thm ("right_minus",num_str @{thm right_minus}),
neuper@37950
   907
	       (*"?z + - ?z = 0"*)
neuper@37969
   908
	       Thm ("sym_real_mult_2",
neuper@37969
   909
                     num_str (@{thm real_mult_2} RS @{thm sym})),	
neuper@37950
   910
	       (*"z1 + z1 = 2 * z1"*)
neuper@37969
   911
	       Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc})
neuper@37950
   912
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
   913
	       ], scr = EmptyScr}:rls;
neuper@37950
   914
(*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
neuper@37950
   915
val discard_parentheses = 
neuper@37950
   916
    append_rls "discard_parentheses" e_rls 
neuper@48763
   917
	       [Thm ("sym_mult_assoc",
neuper@48763
   918
                      num_str (@{thm mult_assoc} RS @{thm sym})),
neuper@37974
   919
		Thm ("sym_add_assoc",
neuper@37974
   920
                      num_str (@{thm add_assoc} RS @{thm sym}))];
neuper@37950
   921
neuper@37950
   922
val scr_make_polynomial = 
neuper@37976
   923
"Script Expand_binoms t_t =                                  " ^
neuper@37950
   924
"(Repeat                                                    " ^
neuper@37950
   925
"((Try (Repeat (Rewrite real_diff_minus         False))) @@ " ^ 
neuper@37950
   926
neuper@52062
   927
" (Try (Repeat (Rewrite distrib_right   False))) @@ " ^	 
neuper@52062
   928
" (Try (Repeat (Rewrite distrib_left  False))) @@ " ^	
neuper@37971
   929
" (Try (Repeat (Rewrite left_diff_distrib  False))) @@ " ^	
neuper@37971
   930
" (Try (Repeat (Rewrite right_diff_distrib False))) @@ " ^	
neuper@37950
   931
neuper@37971
   932
" (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^		   
neuper@37971
   933
" (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^		   
neuper@37971
   934
" (Try (Repeat (Rewrite add_0_left      False))) @@ " ^	 
neuper@37950
   935
neuper@48763
   936
" (Try (Repeat (Rewrite mult_commute       False))) @@ " ^		
neuper@37950
   937
" (Try (Repeat (Rewrite real_mult_left_commute  False))) @@ " ^	
neuper@48763
   938
" (Try (Repeat (Rewrite mult_assoc         False))) @@ " ^		
neuper@37971
   939
" (Try (Repeat (Rewrite add_commute        False))) @@ " ^		
neuper@37971
   940
" (Try (Repeat (Rewrite add_left_commute   False))) @@ " ^	 
neuper@37971
   941
" (Try (Repeat (Rewrite add_assoc          False))) @@ " ^	 
neuper@37950
   942
neuper@37950
   943
" (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^	 
neuper@37950
   944
" (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^	 
neuper@37950
   945
" (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^		
neuper@37950
   946
" (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^		
neuper@37950
   947
neuper@37950
   948
" (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^		
neuper@37950
   949
" (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^	
neuper@37950
   950
neuper@37950
   951
" (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^		
neuper@37950
   952
" (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^   
neuper@37950
   953
neuper@37975
   954
" (Try (Repeat (Calculate PLUS  ))) @@                      " ^
neuper@37975
   955
" (Try (Repeat (Calculate TIMES ))) @@                      " ^
neuper@37975
   956
" (Try (Repeat (Calculate POWER))))                        " ^  
neuper@37976
   957
" t_t)";
neuper@37950
   958
neuper@37950
   959
(*version used by MG.02/03, overwritten by version AG in 04 below
neuper@37950
   960
val make_polynomial = prep_rls(
neuper@37950
   961
  Seq{id = "make_polynomial", preconds = []:term list, 
neuper@37950
   962
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
   963
      erls = Atools_erls, srls = Erls,
neuper@42451
   964
      calc = [], errpatts = [],
neuper@37950
   965
      rules = [Rls_ expand_poly,
neuper@37950
   966
	       Rls_ order_add_mult,
neuper@37950
   967
	       Rls_ simplify_power,   (*realpow_eq_oneI, eg. x^1 --> x *)
neuper@37950
   968
	       Rls_ collect_numerals, (*eg. x^(2+ -1) --> x^1          *)
neuper@37950
   969
	       Rls_ reduce_012,
neuper@37969
   970
	       Thm ("realpow_oneI",num_str @{thm realpow_oneI}),(*in --^*) 
neuper@37950
   971
	       Rls_ discard_parentheses
neuper@37950
   972
	       ],
neuper@37950
   973
      scr = EmptyScr
neuper@37950
   974
      }:rls);   *)
neuper@37950
   975
neuper@37950
   976
val scr_expand_binoms =
neuper@37974
   977
"Script Expand_binoms t_t =" ^
neuper@37950
   978
"(Repeat                       " ^
neuper@37950
   979
"((Try (Repeat (Rewrite real_plus_binom_pow2    False))) @@ " ^
neuper@37950
   980
" (Try (Repeat (Rewrite real_plus_binom_times   False))) @@ " ^
neuper@37950
   981
" (Try (Repeat (Rewrite real_minus_binom_pow2   False))) @@ " ^
neuper@37950
   982
" (Try (Repeat (Rewrite real_minus_binom_times  False))) @@ " ^
neuper@37950
   983
" (Try (Repeat (Rewrite real_plus_minus_binom1  False))) @@ " ^
neuper@37950
   984
" (Try (Repeat (Rewrite real_plus_minus_binom2  False))) @@ " ^
neuper@37950
   985
neuper@37971
   986
" (Try (Repeat (Rewrite mult_1_left             False))) @@ " ^
neuper@37971
   987
" (Try (Repeat (Rewrite mult_zero_left             False))) @@ " ^
neuper@37971
   988
" (Try (Repeat (Rewrite add_0_left      False))) @@ " ^
neuper@37950
   989
neuper@37975
   990
" (Try (Repeat (Calculate PLUS  ))) @@ " ^
neuper@37975
   991
" (Try (Repeat (Calculate TIMES ))) @@ " ^
neuper@37975
   992
" (Try (Repeat (Calculate POWER))) @@ " ^
neuper@37950
   993
neuper@37950
   994
" (Try (Repeat (Rewrite sym_realpow_twoI        False))) @@ " ^
neuper@37950
   995
" (Try (Repeat (Rewrite realpow_plus_1          False))) @@ " ^
neuper@37950
   996
" (Try (Repeat (Rewrite sym_real_mult_2         False))) @@ " ^
neuper@37950
   997
" (Try (Repeat (Rewrite real_mult_2_assoc       False))) @@ " ^
neuper@37950
   998
neuper@37950
   999
" (Try (Repeat (Rewrite real_num_collect        False))) @@ " ^
neuper@37950
  1000
" (Try (Repeat (Rewrite real_num_collect_assoc  False))) @@ " ^
neuper@37950
  1001
neuper@37950
  1002
" (Try (Repeat (Rewrite real_one_collect        False))) @@ " ^
neuper@37950
  1003
" (Try (Repeat (Rewrite real_one_collect_assoc  False))) @@ " ^ 
neuper@37950
  1004
neuper@37975
  1005
" (Try (Repeat (Calculate PLUS  ))) @@ " ^
neuper@37975
  1006
" (Try (Repeat (Calculate TIMES ))) @@ " ^
neuper@37975
  1007
" (Try (Repeat (Calculate POWER)))) " ^  
neuper@37974
  1008
" t_t)";
neuper@37974
  1009
neuper@37950
  1010
val expand_binoms = 
neuper@37950
  1011
  Rls{id = "expand_binoms", preconds = [], rew_ord = ("termlessI",termlessI),
neuper@37950
  1012
      erls = Atools_erls, srls = Erls,
neuper@38014
  1013
      calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
neuper@38034
  1014
	      ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@37950
  1015
	      ("POWER", ("Atools.pow", eval_binop "#power_"))
neuper@42451
  1016
	      ], errpatts = [],
neuper@37974
  1017
      rules = [Thm ("real_plus_binom_pow2",
neuper@37974
  1018
                     num_str @{thm real_plus_binom_pow2}),     
neuper@37950
  1019
	       (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
neuper@37974
  1020
	       Thm ("real_plus_binom_times",
neuper@37974
  1021
                     num_str @{thm real_plus_binom_times}),    
neuper@37950
  1022
	      (*"(a + b)*(a + b) = ...*)
neuper@37974
  1023
	       Thm ("real_minus_binom_pow2",
neuper@37974
  1024
                     num_str @{thm real_minus_binom_pow2}),   
neuper@37950
  1025
	       (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
neuper@37974
  1026
	       Thm ("real_minus_binom_times",
neuper@37974
  1027
                     num_str @{thm real_minus_binom_times}),   
neuper@37950
  1028
	       (*"(a - b)*(a - b) = ...*)
neuper@37974
  1029
	       Thm ("real_plus_minus_binom1",
neuper@37974
  1030
                     num_str @{thm real_plus_minus_binom1}),   
neuper@37950
  1031
		(*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
neuper@37974
  1032
	       Thm ("real_plus_minus_binom2",
neuper@37974
  1033
                     num_str @{thm real_plus_minus_binom2}),   
neuper@37950
  1034
		(*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
neuper@37950
  1035
	       (*RL 020915*)
neuper@37969
  1036
	       Thm ("real_pp_binom_times",num_str @{thm real_pp_binom_times}), 
neuper@37950
  1037
		(*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
neuper@37969
  1038
               Thm ("real_pm_binom_times",num_str @{thm real_pm_binom_times}), 
neuper@37950
  1039
		(*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
neuper@37969
  1040
               Thm ("real_mp_binom_times",num_str @{thm real_mp_binom_times}), 
neuper@37950
  1041
		(*(a - b)*(c + d) = a*c + a*d - b*c - b*d*)
neuper@37969
  1042
               Thm ("real_mm_binom_times",num_str @{thm real_mm_binom_times}), 
neuper@37950
  1043
		(*(a - b)*(c - d) = a*c - a*d - b*c + b*d*)
neuper@37974
  1044
	       Thm ("realpow_multI",num_str @{thm realpow_multI}),
neuper@37950
  1045
		(*(a*b)^^^n = a^^^n * b^^^n*)
neuper@37969
  1046
	       Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
neuper@37950
  1047
	        (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
neuper@37974
  1048
	       Thm ("real_minus_binom_pow3",
neuper@37974
  1049
                     num_str @{thm real_minus_binom_pow3}),
neuper@37950
  1050
	        (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
neuper@37950
  1051
neuper@37950
  1052
neuper@52062
  1053
              (*Thm ("distrib_right" ,num_str @{thm distrib_right}),	
neuper@37950
  1054
		(*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@52062
  1055
	       Thm ("distrib_left",num_str @{thm distrib_left}),	
neuper@37950
  1056
	       (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37965
  1057
	       Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),	
neuper@37950
  1058
	       (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
neuper@37982
  1059
	       Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),	
neuper@37950
  1060
	       (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
neuper@37974
  1061
	      *)
neuper@37974
  1062
	       Thm ("mult_1_left",num_str @{thm mult_1_left}),
neuper@37974
  1063
               (*"1 * z = z"*)
neuper@37974
  1064
	       Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
neuper@37974
  1065
               (*"0 * z = 0"*)
neuper@37965
  1066
	       Thm ("add_0_left",num_str @{thm add_0_left}),(*"0 + z = z"*)
neuper@37950
  1067
neuper@38014
  1068
	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
neuper@38034
  1069
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1070
	       Calc ("Atools.pow", eval_binop "#power_"),
neuper@48763
  1071
              (*Thm ("mult_commute",num_str @{thm mult_commute}),
neuper@37974
  1072
		(*AC-rewriting*)
neuper@37974
  1073
	       Thm ("real_mult_left_commute",
neuper@37974
  1074
                     num_str @{thm real_mult_left_commute}),
neuper@48763
  1075
	       Thm ("mult_assoc",num_str @{thm mult_assoc}),
neuper@37974
  1076
	       Thm ("add_commute",num_str @{thm add_commute}),
neuper@37974
  1077
	       Thm ("add_left_commute",num_str @{thm add_left_commute}),
neuper@37974
  1078
	       Thm ("add_assoc",num_str @{thm add_assoc}),
neuper@37974
  1079
	      *)
neuper@37969
  1080
	       Thm ("sym_realpow_twoI",
neuper@37969
  1081
                     num_str (@{thm realpow_twoI} RS @{thm sym})),
neuper@37950
  1082
	       (*"r1 * r1 = r1 ^^^ 2"*)
neuper@37969
  1083
	       Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),			
neuper@37950
  1084
	       (*"r * r ^^^ n = r ^^^ (n + 1)"*)
neuper@37974
  1085
	       (*Thm ("sym_real_mult_2",
neuper@37974
  1086
                       num_str (@{thm real_mult_2} RS @{thm sym})),		
neuper@37950
  1087
	       (*"z1 + z1 = 2 * z1"*)*)
neuper@37969
  1088
	       Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),		
neuper@37950
  1089
	       (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
  1090
neuper@37969
  1091
	       Thm ("real_num_collect",num_str @{thm real_num_collect}), 
neuper@37974
  1092
	       (*"[| l is_const; m is_const |] ==>l * n + m * n = (l + m) * n"*)
neuper@37974
  1093
	       Thm ("real_num_collect_assoc",
neuper@37974
  1094
                     num_str @{thm real_num_collect_assoc}),	
neuper@37974
  1095
	       (*"[| l is_const; m is_const |] ==>  
neuper@37974
  1096
                                       l * n + (m * n + k) =  (l + m) * n + k"*)
neuper@37974
  1097
	       Thm ("real_one_collect",num_str @{thm real_one_collect}),
neuper@37950
  1098
	       (*"m is_const ==> n + m * n = (1 + m) * n"*)
neuper@37974
  1099
	       Thm ("real_one_collect_assoc",
neuper@37974
  1100
                     num_str @{thm real_one_collect_assoc}), 
neuper@37950
  1101
	       (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@37950
  1102
neuper@38014
  1103
	       Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
neuper@38034
  1104
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1105
	       Calc ("Atools.pow", eval_binop "#power_")
neuper@37950
  1106
	       ],
neuper@48763
  1107
      scr = Prog ((term_of o the o (parse thy)) scr_expand_binoms)
neuper@37950
  1108
      }:rls;      
neuper@37950
  1109
neuper@37950
  1110
neuper@37950
  1111
(**. MG.03: make_polynomial_ ... uses SML-fun for ordering .**)
neuper@37950
  1112
neuper@37950
  1113
(*FIXME.0401: make SML-order local to make_polynomial(_) *)
neuper@37950
  1114
(*FIXME.0401: replace 'make_polynomial'(old) by 'make_polynomial_'(MG) *)
neuper@37950
  1115
(* Polynom --> List von Monomen *) 
neuper@38014
  1116
fun poly2list (Const ("Groups.plus_class.plus",_) $ t1 $ t2) = 
neuper@37950
  1117
    (poly2list t1) @ (poly2list t2)
neuper@37950
  1118
  | poly2list t = [t];
neuper@37950
  1119
neuper@37950
  1120
(* Monom --> Liste von Variablen *)
neuper@38034
  1121
fun monom2list (Const ("Groups.times_class.times",_) $ t1 $ t2) = 
neuper@37950
  1122
    (monom2list t1) @ (monom2list t2)
neuper@37950
  1123
  | monom2list t = [t];
neuper@37950
  1124
neuper@37950
  1125
(* liefert Variablenname (String) einer Variablen und Basis bei Potenz *)
neuper@37950
  1126
fun get_basStr (Const ("Atools.pow",_) $ Free (str, _) $ _) = str
neuper@37950
  1127
  | get_basStr (Free (str, _)) = str
neuper@37950
  1128
  | get_basStr t = "|||"; (* gross gewichtet; für Brüch ect. *)
neuper@37950
  1129
(*| get_basStr t = 
neuper@38031
  1130
    error("get_basStr: called with t= "^(term2str t));*)
neuper@37950
  1131
neuper@37950
  1132
(* liefert Hochzahl (String) einer Variablen bzw Gewichtstring (zum Sortieren) *)
neuper@37950
  1133
fun get_potStr (Const ("Atools.pow",_) $ Free _ $ Free (str, _)) = str
neuper@37950
  1134
  | get_potStr (Const ("Atools.pow",_) $ Free _ $ _ ) = "|||" (* gross gewichtet *)
neuper@37950
  1135
  | get_potStr (Free (str, _)) = "---" (* keine Hochzahl --> kleinst gewichtet *)
neuper@37950
  1136
  | get_potStr t = "||||||"; (* gross gewichtet; für Brüch ect. *)
neuper@37950
  1137
(*| get_potStr t = 
neuper@38031
  1138
    error("get_potStr: called with t= "^(term2str t));*)
neuper@37950
  1139
neuper@37950
  1140
(* Umgekehrte string_ord *)
neuper@37950
  1141
val string_ord_rev =  rev_order o string_ord;
neuper@37950
  1142
		
neuper@37950
  1143
 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen) 
neuper@37950
  1144
    innerhalb eines Monomes:
neuper@37950
  1145
    - zuerst lexikographisch nach Variablenname 
neuper@37950
  1146
    - wenn gleich: nach steigender Potenz *)
neuper@37950
  1147
fun var_ord (a,b: term) = prod_ord string_ord string_ord 
neuper@37950
  1148
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
neuper@37950
  1149
neuper@37950
  1150
(* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen); 
neuper@37950
  1151
   verwendet zum Sortieren von Monomen mittels Gesamtgradordnung:
neuper@37950
  1152
   - zuerst lexikographisch nach Variablenname 
neuper@37950
  1153
   - wenn gleich: nach sinkender Potenz*)
neuper@37950
  1154
fun var_ord_revPow (a,b: term) = prod_ord string_ord string_ord_rev 
neuper@37950
  1155
    ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
neuper@37950
  1156
neuper@37950
  1157
neuper@37950
  1158
(* Ordnet ein Liste von Variablen (und Potenzen) lexikographisch *)
neuper@37950
  1159
val sort_varList = sort var_ord;
neuper@37950
  1160
neuper@37950
  1161
(* Entfernet aeussersten Operator (Wurzel) aus einem Term und schreibt 
neuper@37950
  1162
   Argumente in eine Liste *)
neuper@37950
  1163
fun args u : term list =
neuper@37950
  1164
    let fun stripc (f$t, ts) = stripc (f, t::ts)
neuper@37950
  1165
	  | stripc (t as Free _, ts) = (t::ts)
neuper@37950
  1166
	  | stripc (_, ts) = ts
neuper@37950
  1167
    in stripc (u, []) end;
neuper@37950
  1168
                                    
neuper@37950
  1169
(* liefert True, falls der Term (Liste von Termen) nur Zahlen 
neuper@37950
  1170
   (keine Variablen) enthaelt *)
neuper@37950
  1171
fun filter_num [] = true
neuper@37950
  1172
  | filter_num [Free x] = if (is_num (Free x)) then true
neuper@37950
  1173
				else false
neuper@37950
  1174
  | filter_num ((Free _)::_) = false
neuper@37950
  1175
  | filter_num ts =
neuper@37950
  1176
    (filter_num o (filter_out is_num) o flat o (map args)) ts;
neuper@37950
  1177
neuper@37950
  1178
(* liefert True, falls der Term nur Zahlen (keine Variablen) enthaelt 
neuper@37950
  1179
   dh. er ist ein numerischer Wert und entspricht einem Koeffizienten *)
neuper@37950
  1180
fun is_nums t = filter_num [t];
neuper@37950
  1181
neuper@37950
  1182
(* Berechnet den Gesamtgrad eines Monoms *)
neuper@37950
  1183
local 
neuper@37950
  1184
    fun counter (n, []) = n
neuper@37950
  1185
      | counter (n, x :: xs) = 
neuper@37950
  1186
	if (is_nums x) then
neuper@37950
  1187
	    counter (n, xs) 
neuper@37950
  1188
	else 
neuper@37950
  1189
	    (case x of 
neuper@37950
  1190
		 (Const ("Atools.pow", _) $ Free (str_b, _) $ Free (str_h, T)) => 
neuper@37950
  1191
		     if (is_nums (Free (str_h, T))) then
neuper@37950
  1192
			 counter (n + (the (int_of_str str_h)), xs)
neuper@37950
  1193
		     else counter (n + 1000, xs) (*FIXME.MG?!*)
neuper@37950
  1194
	       | (Const ("Atools.pow", _) $ Free (str_b, _) $ _ ) => 
neuper@37950
  1195
		     counter (n + 1000, xs) (*FIXME.MG?!*)
neuper@37950
  1196
	       | (Free (str, _)) => counter (n + 1, xs)
neuper@38031
  1197
	     (*| _ => error("monom_degree: called with factor: "^(term2str x)))*)
neuper@37950
  1198
	       | _ => counter (n + 10000, xs)) (*FIXME.MG?! ... Brüche ect.*)
neuper@37950
  1199
in  
neuper@37950
  1200
    fun monom_degree l = counter (0, l) 
neuper@37980
  1201
end;(*local*)
neuper@37950
  1202
neuper@37950
  1203
(* wie Ordnung dict_ord (lexicographische Ordnung zweier Listen, mit Vergleich 
neuper@37950
  1204
   der Listen-Elemente mit elem_ord) - Elemente die Bedingung cond erfuellen, 
neuper@37950
  1205
   werden jedoch dabei ignoriert (uebersprungen)  *)
neuper@37950
  1206
fun dict_cond_ord _ _ ([], []) = EQUAL
neuper@37950
  1207
  | dict_cond_ord _ _ ([], _ :: _) = LESS
neuper@37950
  1208
  | dict_cond_ord _ _ (_ :: _, []) = GREATER
neuper@37950
  1209
  | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
neuper@37950
  1210
    (case (cond x, cond y) of 
neuper@37950
  1211
	 (false, false) => (case elem_ord (x, y) of 
neuper@37950
  1212
				EQUAL => dict_cond_ord elem_ord cond (xs, ys) 
neuper@37950
  1213
			      | ord => ord)
neuper@37950
  1214
       | (false, true)  => dict_cond_ord elem_ord cond (x :: xs, ys)
neuper@37950
  1215
       | (true, false)  => dict_cond_ord elem_ord cond (xs, y :: ys)
neuper@37950
  1216
       | (true, true)  =>  dict_cond_ord elem_ord cond (xs, ys) );
neuper@37950
  1217
neuper@37950
  1218
(* Gesamtgradordnung zum Vergleich von Monomen (Liste von Variablen/Potenzen):
neuper@37950
  1219
   zuerst nach Gesamtgrad, bei gleichem Gesamtgrad lexikographisch ordnen - 
neuper@37950
  1220
   dabei werden Koeffizienten ignoriert (2*3*a^^^2*4*b gilt wie a^^^2*b) *)
neuper@37950
  1221
fun degree_ord (xs, ys) =
neuper@37950
  1222
	    prod_ord int_ord (dict_cond_ord var_ord_revPow is_nums) 
neuper@37950
  1223
	    ((monom_degree xs, xs), (monom_degree ys, ys));
neuper@37950
  1224
neuper@37950
  1225
fun hd_str str = substring (str, 0, 1);
neuper@37950
  1226
fun tl_str str = substring (str, 1, (size str) - 1);
neuper@37950
  1227
neuper@37950
  1228
(* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
neuper@38031
  1229
fun get_koeff_of_mon [] =  error("get_koeff_of_mon: called with l = []")
neuper@37950
  1230
  | get_koeff_of_mon (l as x::xs) = if is_nums x then SOME x
neuper@37950
  1231
				    else NONE;
neuper@37950
  1232
neuper@37950
  1233
(* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
neuper@37950
  1234
fun koeff2ordStr (SOME x) = (case x of 
neuper@37950
  1235
				 (Free (str, T)) => 
neuper@37950
  1236
				     if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
neuper@37950
  1237
				     else str
neuper@37950
  1238
			       | _ => "aaa") (* "num.Ausdruck" --> gross *)
neuper@37950
  1239
  | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
neuper@37950
  1240
neuper@37950
  1241
(* Order zum Vergleich von Koeffizienten (strings): 
neuper@37950
  1242
   "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
neuper@37950
  1243
fun compare_koeff_ord (xs, ys) = 
neuper@37950
  1244
    string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
neuper@37950
  1245
		(koeff2ordStr o get_koeff_of_mon) ys);
neuper@37950
  1246
neuper@37950
  1247
(* Gesamtgradordnung degree_ord + Ordnen nach Koeffizienten falls EQUAL *)
neuper@37950
  1248
fun koeff_degree_ord (xs, ys) =
neuper@37950
  1249
	    prod_ord degree_ord compare_koeff_ord ((xs, xs), (ys, ys));
neuper@37950
  1250
neuper@37950
  1251
(* Ordnet ein Liste von Monomen (Monom = Liste von Variablen) mittels 
neuper@37950
  1252
   Gesamtgradordnung *)
neuper@37950
  1253
val sort_monList = sort koeff_degree_ord;
neuper@37950
  1254
neuper@37950
  1255
(* Alternativ zu degree_ord koennte auch die viel einfachere und 
neuper@37950
  1256
   kuerzere Ordnung simple_ord verwendet werden - ist aber nicht 
neuper@37950
  1257
   fuer unsere Zwecke geeignet!
neuper@37950
  1258
neuper@37950
  1259
fun simple_ord (al,bl: term list) = dict_ord string_ord 
neuper@37950
  1260
	 (map get_basStr al, map get_basStr bl); 
neuper@37950
  1261
neuper@37950
  1262
val sort_monList = sort simple_ord; *)
neuper@37950
  1263
neuper@37950
  1264
(* aus 2 Variablen wird eine Summe bzw ein Produkt erzeugt 
neuper@37950
  1265
   (mit gewuenschtem Typen T) *)
neuper@38014
  1266
fun plus T = Const ("Groups.plus_class.plus", [T,T] ---> T);
neuper@38034
  1267
fun mult T = Const ("Groups.times_class.times", [T,T] ---> T);
neuper@37950
  1268
fun binop op_ t1 t2 = op_ $ t1 $ t2;
neuper@37950
  1269
fun create_prod T (a,b) = binop (mult T) a b;
neuper@37950
  1270
fun create_sum T (a,b) = binop (plus T) a b;
neuper@37950
  1271
neuper@37950
  1272
(* löscht letztes Element einer Liste *)
neuper@37950
  1273
fun drop_last l = take ((length l)-1,l);
neuper@37950
  1274
neuper@37950
  1275
(* Liste von Variablen --> Monom *)
neuper@37950
  1276
fun create_monom T vl = foldr (create_prod T) (drop_last vl, last_elem vl);
neuper@37950
  1277
(* Bemerkung: 
neuper@37950
  1278
   foldr bewirkt rechtslastige Klammerung des Monoms - ist notwendig, damit zwei 
neuper@37950
  1279
   gleiche Monome zusammengefasst werden können (collect_numerals)! 
neuper@37950
  1280
   zB: 2*(x*(y*z)) + 3*(x*(y*z)) --> (2+3)*(x*(y*z))*)
neuper@37950
  1281
neuper@37950
  1282
(* Liste von Monomen --> Polynom *)	
neuper@37950
  1283
fun create_polynom T ml = foldl (create_sum T) (hd ml, tl ml);
neuper@37950
  1284
(* Bemerkung: 
neuper@37950
  1285
   foldl bewirkt linkslastige Klammerung des Polynoms (der Summanten) - 
neuper@37950
  1286
   bessere Darstellung, da keine Klammern sichtbar! 
neuper@37950
  1287
   (und discard_parentheses in make_polynomial hat weniger zu tun) *)
neuper@37950
  1288
neuper@37950
  1289
(* sorts the variables (faktors) of an expanded polynomial lexicographical *)
neuper@37950
  1290
fun sort_variables t = 
neuper@37950
  1291
    let
neuper@37950
  1292
	val ll =  map monom2list (poly2list t);
neuper@37950
  1293
	val lls = map sort_varList ll; 
neuper@37950
  1294
	val T = type_of t;
neuper@37950
  1295
	val ls = map (create_monom T) lls;
neuper@37950
  1296
    in create_polynom T ls end;
neuper@37950
  1297
neuper@37950
  1298
(* sorts the monoms of an expanded and variable-sorted polynomial 
neuper@37950
  1299
   by total_degree *)
neuper@37950
  1300
fun sort_monoms t = 
neuper@37950
  1301
    let
neuper@37950
  1302
	val ll =  map monom2list (poly2list t);
neuper@37950
  1303
	val lls = sort_monList ll;
neuper@37950
  1304
	val T = type_of t;
neuper@37950
  1305
	val ls = map (create_monom T) lls;
neuper@37950
  1306
    in create_polynom T ls end;
neuper@37950
  1307
neuper@37950
  1308
(* auch Klammerung muss übereinstimmen; 
neuper@37950
  1309
   sort_variables klammert Produkte rechtslastig*)
neuper@37950
  1310
fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
neuper@37950
  1311
neuper@42451
  1312
*}
neuper@42451
  1313
ML {*
neuper@37950
  1314
fun eval_is_multUnordered (thmid:string) _ 
neuper@37950
  1315
		       (t as (Const("Poly.is'_multUnordered", _) $ arg)) thy = 
neuper@37950
  1316
    if is_multUnordered arg
neuper@52070
  1317
    then SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
  1318
	         Trueprop $ (mk_equality (t, @{term True})))
neuper@52070
  1319
    else SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
  1320
	         Trueprop $ (mk_equality (t, @{term False})))
neuper@37950
  1321
  | eval_is_multUnordered _ _ _ _ = NONE; 
neuper@37950
  1322
neuper@37950
  1323
fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
neuper@37950
  1324
    []:(rule * (term * term list)) list;
neuper@37950
  1325
fun init_state (_:term) = e_rrlsstate;
neuper@37950
  1326
fun locate_rule (_:rule list list) (_:term) (_:rule) =
neuper@37950
  1327
    ([]:(rule * (term * term list)) list);
neuper@37950
  1328
fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
neuper@37950
  1329
fun normal_form t = SOME (sort_variables t,[]:term list);
neuper@37950
  1330
neuper@37950
  1331
val order_mult_ =
neuper@37950
  1332
    Rrls {id = "order_mult_", 
neuper@37950
  1333
	  prepat = 
neuper@38036
  1334
          (* ?p matched with the current term gives an environment,
neuper@38037
  1335
             which evaluates (the instantiated) "?p is_multUnordered" to true *)
neuper@38037
  1336
	  [([parse_patt thy "?p is_multUnordered"], 
neuper@38037
  1337
             parse_patt thy "?p :: real")],
neuper@37950
  1338
	  rew_ord = ("dummy_ord", dummy_ord),
neuper@38037
  1339
	  erls = append_rls "e_rls-is_multUnordered" e_rls
neuper@37976
  1340
			    [Calc ("Poly.is'_multUnordered", 
neuper@37976
  1341
                                    eval_is_multUnordered "")],
neuper@38036
  1342
	  calc = [("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")),
neuper@38036
  1343
		  ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@48789
  1344
		  ("DIVIDE", ("Fields.inverse_class.divide", 
neuper@38036
  1345
		              eval_cancel "#divide_e")),
neuper@37976
  1346
		  ("POWER" , ("Atools.pow", eval_binop "#power_"))],
neuper@42451
  1347
  errpatts = [],
neuper@37950
  1348
	  scr=Rfuns {init_state  = init_state,
neuper@37950
  1349
		     normal_form = normal_form,
neuper@37950
  1350
		     locate_rule = locate_rule,
neuper@37950
  1351
		     next_rule   = next_rule,
neuper@37950
  1352
		     attach_form = attach_form}};
neuper@37950
  1353
val order_mult_rls_ = 
neuper@37950
  1354
  Rls{id = "order_mult_rls_", preconds = [], 
neuper@37950
  1355
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
  1356
      erls = e_rls,srls = Erls,
neuper@42451
  1357
      calc = [], errpatts = [],
neuper@37950
  1358
      rules = [Rls_ order_mult_
neuper@37950
  1359
	       ], scr = EmptyScr}:rls;
neuper@42451
  1360
*}
neuper@42451
  1361
ML {*
neuper@37950
  1362
neuper@37950
  1363
fun is_addUnordered t = ((is_polyexp t) andalso not (t = sort_monoms t));
neuper@37950
  1364
neuper@37950
  1365
(*WN.18.6.03 *)
neuper@37950
  1366
(*("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))*)
neuper@37950
  1367
fun eval_is_addUnordered (thmid:string) _ 
neuper@37950
  1368
		       (t as (Const("Poly.is'_addUnordered", _) $ arg)) thy = 
neuper@37950
  1369
    if is_addUnordered arg
neuper@52070
  1370
    then SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
  1371
	         Trueprop $ (mk_equality (t, @{term True})))
neuper@52070
  1372
    else SOME (mk_thmid thmid "" (term_to_string''' thy arg) "", 
neuper@52070
  1373
	         Trueprop $ (mk_equality (t, @{term False})))
neuper@37950
  1374
  | eval_is_addUnordered _ _ _ _ = NONE; 
neuper@37950
  1375
neuper@37950
  1376
fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
neuper@37950
  1377
    []:(rule * (term * term list)) list;
neuper@37950
  1378
fun init_state (_:term) = e_rrlsstate;
neuper@37950
  1379
fun locate_rule (_:rule list list) (_:term) (_:rule) =
neuper@37950
  1380
    ([]:(rule * (term * term list)) list);
neuper@37950
  1381
fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
neuper@37950
  1382
fun normal_form t = SOME (sort_monoms t,[]:term list);
neuper@37950
  1383
neuper@37950
  1384
val order_add_ =
neuper@37950
  1385
    Rrls {id = "order_add_", 
neuper@37950
  1386
	  prepat = (*WN.18.6.03 Preconditions und Pattern,
neuper@37950
  1387
		    die beide passen muessen, damit das Rrls angewandt wird*)
neuper@38037
  1388
	  [([parse_patt @{theory} "?p is_addUnordered"], 
neuper@38037
  1389
	     parse_patt @{theory} "?p :: real" 
neuper@37950
  1390
	    (*WN.18.6.03 also KEIN pattern, dieses erzeugt nur das Environment 
neuper@37950
  1391
	      fuer die Evaluation der Precondition "p is_addUnordered"*))],
neuper@37950
  1392
	  rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
  1393
	  erls = append_rls "e_rls-is_addUnordered" e_rls(*MG: poly_erls*)
neuper@38037
  1394
			    [Calc ("Poly.is'_addUnordered",
neuper@38037
  1395
                                   eval_is_addUnordered "")],
neuper@38037
  1396
	  calc = [("PLUS"  ,("Groups.plus_class.plus", eval_binop "#add_")),
neuper@38037
  1397
		  ("TIMES" ,("Groups.times_class.times", eval_binop "#mult_")),
neuper@48789
  1398
		  ("DIVIDE",("Fields.inverse_class.divide",
neuper@38037
  1399
                              eval_cancel "#divide_e")),
neuper@38037
  1400
		  ("POWER" ,("Atools.pow"  ,eval_binop "#power_"))],
neuper@42451
  1401
	  errpatts = [],
neuper@37950
  1402
	  scr=Rfuns {init_state  = init_state,
neuper@37950
  1403
		     normal_form = normal_form,
neuper@37950
  1404
		     locate_rule = locate_rule,
neuper@37950
  1405
		     next_rule   = next_rule,
neuper@37950
  1406
		     attach_form = attach_form}};
neuper@37950
  1407
neuper@37950
  1408
val order_add_rls_ = 
neuper@37950
  1409
  Rls{id = "order_add_rls_", preconds = [], 
neuper@37950
  1410
      rew_ord = ("dummy_ord", dummy_ord),
neuper@37950
  1411
      erls = e_rls,srls = Erls,
neuper@42451
  1412
      calc = [], errpatts = [],
neuper@37950
  1413
      rules = [Rls_ order_add_
neuper@37950
  1414
	       ], scr = EmptyScr}:rls;
neuper@42398
  1415
*}
neuper@37950
  1416
neuper@42398
  1417
text {* rule-set make_polynomial also named norm_Poly:
neuper@42398
  1418
  Rewrite order has not been implemented properly; the order is better in 
neuper@42398
  1419
  make_polynomial_in (coded in SML).
neuper@42398
  1420
  Notes on state of development:
neuper@42398
  1421
  \# surprise 2006: test --- norm_Poly NOT COMPLETE ---
neuper@42398
  1422
  \# migration Isabelle2002 --> 2011 weakened the rule set, see test
neuper@42398
  1423
  --- Matthias Goldgruber 2003 rewrite orders ---, error "ord_make_polynomial_in #16b"
neuper@42398
  1424
*}
neuper@42398
  1425
ML {*
neuper@37950
  1426
(*. see MG-DA.p.52ff .*)
neuper@37950
  1427
val make_polynomial(*MG.03, overwrites version from above, 
neuper@37950
  1428
    previously 'make_polynomial_'*) =
neuper@37950
  1429
  Seq {id = "make_polynomial", preconds = []:term list, 
neuper@37950
  1430
      rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
  1431
      erls = Atools_erls, srls = Erls,calc = [], errpatts = [],
neuper@37980
  1432
      rules = [Rls_ discard_minus,
neuper@37950
  1433
	       Rls_ expand_poly_,
neuper@38034
  1434
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1435
	       Rls_ order_mult_rls_,
neuper@37950
  1436
	       Rls_ simplify_power_, 
neuper@37950
  1437
	       Rls_ calc_add_mult_pow_, 
neuper@37950
  1438
	       Rls_ reduce_012_mult_,
neuper@37950
  1439
	       Rls_ order_add_rls_,
neuper@37950
  1440
	       Rls_ collect_numerals_, 
neuper@37950
  1441
	       Rls_ reduce_012_,
neuper@37979
  1442
	       Rls_ discard_parentheses1
neuper@37950
  1443
	       ],
neuper@37950
  1444
      scr = EmptyScr
neuper@37950
  1445
      }:rls;
neuper@48763
  1446
*}
neuper@48763
  1447
ML {*
neuper@37950
  1448
val norm_Poly(*=make_polynomial*) = 
neuper@37950
  1449
  Seq {id = "norm_Poly", preconds = []:term list, 
neuper@37950
  1450
      rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
  1451
      erls = Atools_erls, srls = Erls, calc = [], errpatts = [],
neuper@37980
  1452
      rules = [Rls_ discard_minus,
neuper@37950
  1453
	       Rls_ expand_poly_,
neuper@38034
  1454
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1455
	       Rls_ order_mult_rls_,
neuper@37950
  1456
	       Rls_ simplify_power_, 
neuper@37950
  1457
	       Rls_ calc_add_mult_pow_, 
neuper@37950
  1458
	       Rls_ reduce_012_mult_,
neuper@37950
  1459
	       Rls_ order_add_rls_,
neuper@37950
  1460
	       Rls_ collect_numerals_, 
neuper@37950
  1461
	       Rls_ reduce_012_,
neuper@37979
  1462
	       Rls_ discard_parentheses1
neuper@37950
  1463
	       ],
neuper@37950
  1464
      scr = EmptyScr
neuper@37950
  1465
      }:rls;
neuper@48763
  1466
*}
neuper@48763
  1467
ML {*
neuper@37979
  1468
(* MG:03 Like make_polynomial_ but without Rls_ discard_parentheses1 
neuper@37950
  1469
   and expand_poly_rat_ instead of expand_poly_, see MG-DA.p.56ff*)
neuper@37950
  1470
(* MG necessary  for termination of norm_Rational(*_mg*) in Rational.ML*)
neuper@37950
  1471
val make_rat_poly_with_parentheses =
neuper@37950
  1472
  Seq{id = "make_rat_poly_with_parentheses", preconds = []:term list, 
neuper@37950
  1473
      rew_ord = ("dummy_ord", dummy_ord),
neuper@42451
  1474
      erls = Atools_erls, srls = Erls, calc = [], errpatts = [],
neuper@37980
  1475
      rules = [Rls_ discard_minus,
neuper@37950
  1476
	       Rls_ expand_poly_rat_,(*ignors rationals*)
neuper@38034
  1477
	       Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1478
	       Rls_ order_mult_rls_,
neuper@37950
  1479
	       Rls_ simplify_power_, 
neuper@37950
  1480
	       Rls_ calc_add_mult_pow_, 
neuper@37950
  1481
	       Rls_ reduce_012_mult_,
neuper@37950
  1482
	       Rls_ order_add_rls_,
neuper@37950
  1483
	       Rls_ collect_numerals_, 
neuper@37950
  1484
	       Rls_ reduce_012_
neuper@37979
  1485
	       (*Rls_ discard_parentheses1 *)
neuper@37950
  1486
	       ],
neuper@37950
  1487
      scr = EmptyScr
neuper@37950
  1488
      }:rls;
neuper@48763
  1489
*}
neuper@48763
  1490
ML {*
neuper@37950
  1491
(*.a minimal ruleset for reverse rewriting of factions [2];
neuper@37950
  1492
   compare expand_binoms.*)
neuper@37950
  1493
val rev_rew_p = 
neuper@42407
  1494
Seq{id = "rev_rew_p", preconds = [], rew_ord = ("termlessI",termlessI),
neuper@37950
  1495
    erls = Atools_erls, srls = Erls,
neuper@38014
  1496
    calc = [(*("PLUS"  , ("Groups.plus_class.plus", eval_binop "#add_")), 
neuper@38034
  1497
	    ("TIMES" , ("Groups.times_class.times", eval_binop "#mult_")),
neuper@37950
  1498
	    ("POWER", ("Atools.pow", eval_binop "#power_"))*)
neuper@42451
  1499
	    ], errpatts = [],
neuper@37969
  1500
    rules = [Thm ("real_plus_binom_times" ,num_str @{thm real_plus_binom_times}),
neuper@37950
  1501
	     (*"(a + b)*(a + b) = a ^ 2 + 2 * a * b + b ^ 2*)
neuper@37969
  1502
	     Thm ("real_plus_binom_times1" ,num_str @{thm real_plus_binom_times1}),
neuper@37950
  1503
	     (*"(a +  1*b)*(a + -1*b) = a^^^2 + -1*b^^^2"*)
neuper@37969
  1504
	     Thm ("real_plus_binom_times2" ,num_str @{thm real_plus_binom_times2}),
neuper@37950
  1505
	     (*"(a + -1*b)*(a +  1*b) = a^^^2 + -1*b^^^2"*)
neuper@37950
  1506
neuper@37965
  1507
	     Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
neuper@37950
  1508
neuper@52062
  1509
             Thm ("distrib_right" ,num_str @{thm distrib_right}),
neuper@37950
  1510
	     (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
neuper@52062
  1511
	     Thm ("distrib_left",num_str @{thm distrib_left}),
neuper@37950
  1512
	     (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
neuper@37950
  1513
	       
neuper@48763
  1514
	     Thm ("mult_assoc", num_str @{thm mult_assoc}),
neuper@37950
  1515
	     (*"?z1.1 * ?z2.1 * ?z3. =1 ?z1.1 * (?z2.1 * ?z3.1)"*)
neuper@37950
  1516
	     Rls_ order_mult_rls_,
neuper@37950
  1517
	     (*Rls_ order_add_rls_,*)
neuper@37950
  1518
neuper@38014
  1519
	     Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
neuper@38034
  1520
	     Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1521
	     Calc ("Atools.pow", eval_binop "#power_"),
neuper@37950
  1522
	     
neuper@37969
  1523
	     Thm ("sym_realpow_twoI",
neuper@37969
  1524
                   num_str (@{thm realpow_twoI} RS @{thm sym})),
neuper@37950
  1525
	     (*"r1 * r1 = r1 ^^^ 2"*)
neuper@37969
  1526
	     Thm ("sym_real_mult_2",
neuper@37969
  1527
                   num_str (@{thm real_mult_2} RS @{thm sym})),
neuper@37950
  1528
	     (*"z1 + z1 = 2 * z1"*)
neuper@37969
  1529
	     Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),
neuper@37950
  1530
	     (*"z1 + (z1 + k) = 2 * z1 + k"*)
neuper@37950
  1531
neuper@37969
  1532
	     Thm ("real_num_collect",num_str @{thm real_num_collect}), 
neuper@37950
  1533
	     (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
neuper@37969
  1534
	     Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
neuper@37950
  1535
	     (*"[| l is_const; m is_const |] ==>  
neuper@37950
  1536
                                     l * n + (m * n + k) =  (l + m) * n + k"*)
neuper@37969
  1537
	     Thm ("real_one_collect",num_str @{thm real_one_collect}),
neuper@37950
  1538
	     (*"m is_const ==> n + m * n = (1 + m) * n"*)
neuper@37969
  1539
	     Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}), 
neuper@37950
  1540
	     (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
neuper@37950
  1541
neuper@37969
  1542
	     Thm ("realpow_multI", num_str @{thm realpow_multI}),
neuper@37950
  1543
	     (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
neuper@37950
  1544
neuper@38014
  1545
	     Calc ("Groups.plus_class.plus", eval_binop "#add_"), 
neuper@38034
  1546
	     Calc ("Groups.times_class.times", eval_binop "#mult_"),
neuper@37950
  1547
	     Calc ("Atools.pow", eval_binop "#power_"),
neuper@37950
  1548
neuper@37965
  1549
	     Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
neuper@37965
  1550
	     Thm ("mult_zero_left",num_str @{thm mult_zero_left}),(*"0 * z = 0"*)
neuper@37965
  1551
	     Thm ("add_0_left",num_str @{thm add_0_left})(*0 + z = z*)
neuper@37950
  1552
neuper@37950
  1553
	     (*Rls_ order_add_rls_*)
neuper@37950
  1554
	     ],
neuper@37950
  1555
neuper@37950
  1556
    scr = EmptyScr}:rls;      
neuper@48763
  1557
*}
neuper@48763
  1558
ML {*
neuper@37950
  1559
ruleset' := 
neuper@37967
  1560
overwritelthy @{theory} (!ruleset',
neuper@37950
  1561
		   [("norm_Poly", prep_rls norm_Poly),
neuper@37950
  1562
		    ("Poly_erls",Poly_erls)(*FIXXXME:del with rls.rls'*),
neuper@37950
  1563
		    ("expand", prep_rls expand),
neuper@37950
  1564
		    ("expand_poly", prep_rls expand_poly),
neuper@37950
  1565
		    ("simplify_power", prep_rls simplify_power),
neuper@37950
  1566
		    ("order_add_mult", prep_rls order_add_mult),
neuper@37950
  1567
		    ("collect_numerals", prep_rls collect_numerals),
neuper@37950
  1568
		    ("collect_numerals_", prep_rls collect_numerals_),
neuper@37950
  1569
		    ("reduce_012", prep_rls reduce_012),
neuper@37950
  1570
		    ("discard_parentheses", prep_rls discard_parentheses),
neuper@37950
  1571
		    ("make_polynomial", prep_rls make_polynomial),
neuper@37950
  1572
		    ("expand_binoms", prep_rls expand_binoms),
neuper@37950
  1573
		    ("rev_rew_p", prep_rls rev_rew_p),
neuper@37980
  1574
		    ("discard_minus", prep_rls discard_minus),
neuper@37950
  1575
		    ("expand_poly_", prep_rls expand_poly_),
neuper@37950
  1576
		    ("expand_poly_rat_", prep_rls expand_poly_rat_),
neuper@37950
  1577
		    ("simplify_power_", prep_rls simplify_power_),
neuper@37950
  1578
		    ("calc_add_mult_pow_", prep_rls calc_add_mult_pow_),
neuper@37950
  1579
		    ("reduce_012_mult_", prep_rls reduce_012_mult_),
neuper@37950
  1580
		    ("reduce_012_", prep_rls reduce_012_),
neuper@37979
  1581
		    ("discard_parentheses1",prep_rls discard_parentheses1),
neuper@37950
  1582
		    ("order_mult_rls_", prep_rls order_mult_rls_),
neuper@37950
  1583
		    ("order_add_rls_", prep_rls order_add_rls_),
neuper@42407
  1584
		    ("make_rat_poly_with_parentheses", prep_rls make_rat_poly_with_parentheses)
neuper@37950
  1585
		    ]);
neuper@48763
  1586
*}
neuper@48763
  1587
ML {*
neuper@37950
  1588
calclist':= overwritel (!calclist', 
neuper@37950
  1589
   [("is_polyrat_in", ("Poly.is'_polyrat'_in", 
neuper@37950
  1590
		       eval_is_polyrat_in "#eval_is_polyrat_in")),
neuper@37950
  1591
    ("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in "")),
neuper@37950
  1592
    ("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in "")),
neuper@37950
  1593
    ("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in "")),
neuper@37950
  1594
    ("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp "")),
neuper@37950
  1595
    ("is_multUnordered", ("Poly.is'_multUnordered", eval_is_multUnordered"")),
neuper@37950
  1596
    ("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))
neuper@37950
  1597
    ]);
neuper@48763
  1598
*}
neuper@48763
  1599
ML {*
neuper@37950
  1600
neuper@37950
  1601
(** problems **)
neuper@37950
  1602
neuper@37950
  1603
store_pbt
neuper@37972
  1604
 (prep_pbt thy "pbl_simp_poly" [] e_pblID
neuper@37950
  1605
 (["polynomial","simplification"],
neuper@38083
  1606
  [("#Given" ,["Term t_t"]),
neuper@37976
  1607
   ("#Where" ,["t_t is_polyexp"]),
neuper@37976
  1608
   ("#Find"  ,["normalform n_n"])
neuper@37950
  1609
  ],
neuper@37950
  1610
  append_rls "e_rls" e_rls [(*for preds in where_*)
neuper@37950
  1611
			    Calc ("Poly.is'_polyexp", eval_is_polyexp "")], 
neuper@37976
  1612
  SOME "Simplify t_t", 
neuper@37950
  1613
  [["simplification","for_polynomials"]]));
neuper@48763
  1614
*}
neuper@48763
  1615
ML {*
neuper@37950
  1616
neuper@37950
  1617
(** methods **)
neuper@37950
  1618
neuper@37950
  1619
store_met
neuper@37972
  1620
    (prep_met thy "met_simp_poly" [] e_metID
neuper@37950
  1621
	      (["simplification","for_polynomials"],
neuper@38083
  1622
	       [("#Given" ,["Term t_t"]),
neuper@37976
  1623
		("#Where" ,["t_t is_polyexp"]),
neuper@37976
  1624
		("#Find"  ,["normalform n_n"])
neuper@37950
  1625
		],
neuper@37950
  1626
	       {rew_ord'="tless_true",
neuper@37950
  1627
		rls' = e_rls,
neuper@37950
  1628
		calc = [], 
neuper@37950
  1629
		srls = e_rls, 
neuper@37950
  1630
		prls = append_rls "simplification_for_polynomials_prls" e_rls 
neuper@37950
  1631
				  [(*for preds in where_*)
neuper@37950
  1632
				   Calc ("Poly.is'_polyexp",eval_is_polyexp"")],
neuper@42425
  1633
		crls = e_rls, errpats = [], nrls = norm_Poly},
neuper@37976
  1634
	       "Script SimplifyScript (t_t::real) =                " ^
neuper@37976
  1635
	       "  ((Rewrite_Set norm_Poly False) t_t)"
neuper@37950
  1636
	       ));
neuper@37950
  1637
*}
neuper@37950
  1638
neuper@37906
  1639
end