1 (* WN.020812: theorems in the Reals,
2 necessary for special rule sets, in addition to Isabelle2002.
3 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
4 !!! THIS IS THE _least_ NUMBER OF ADDITIONAL THEOREMS !!!
5 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6 xxxI contain ^^^ instead of ^ in the respective theorem xxx in 2002
7 changed by: Richard Lang 020912
10 theory Poly imports Simplify begin
14 is'_expanded'_in :: "[real, real] => bool" ("_ is'_expanded'_in _")
15 is'_poly'_in :: "[real, real] => bool" ("_ is'_poly'_in _") (*RL DA *)
16 has'_degree'_in :: "[real, real] => real" ("_ has'_degree'_in _")(*RL DA *)
17 is'_polyrat'_in :: "[real, real] => bool" ("_ is'_polyrat'_in _")(*RL030626*)
19 is'_multUnordered:: "real => bool" ("_ is'_multUnordered")
20 is'_addUnordered :: "real => bool" ("_ is'_addUnordered") (*WN030618*)
21 is'_polyexp :: "real => bool" ("_ is'_polyexp")
26 ("((Script Expand'_binoms (_ =))//
29 (*-------------------- rules------------------------------------------------*)
30 axioms (*.not contained in Isabelle2002,
31 stated as axioms, TODO: prove as theorems;
32 theorem-IDs 'xxxI' with ^^^ instead of ^ in 'xxx' in Isabelle2002.*)
34 realpow_pow: "(a ^^^ b) ^^^ c = a ^^^ (b * c)"
35 realpow_addI: "r ^^^ (n + m) = r ^^^ n * r ^^^ m"
36 realpow_addI_assoc_l: "r ^^^ n * (r ^^^ m * s) = r ^^^ (n + m) * s"
37 realpow_addI_assoc_r: "s * r ^^^ n * r ^^^ m = s * r ^^^ (n + m)"
39 realpow_oneI: "r ^^^ 1 = r"
40 realpow_zeroI: "r ^^^ 0 = 1"
41 realpow_eq_oneI: "1 ^^^ n = 1"
42 realpow_multI: "(r * s) ^^^ n = r ^^^ n * s ^^^ n"
43 realpow_multI_poly: "[| r is_polyexp; s is_polyexp |] ==>
44 (r * s) ^^^ n = r ^^^ n * s ^^^ n"
45 realpow_minus_oneI: "-1 ^^^ (2 * n) = 1"
47 realpow_twoI: "r ^^^ 2 = r * r"
48 realpow_twoI_assoc_l: "r * (r * s) = r ^^^ 2 * s"
49 realpow_twoI_assoc_r: "s * r * r = s * r ^^^ 2"
50 realpow_two_atom: "r is_atom ==> r * r = r ^^^ 2"
51 realpow_plus_1: "r * r ^^^ n = r ^^^ (n + 1)"
52 realpow_plus_1_assoc_l: "r * (r ^^^ m * s) = r ^^^ (1 + m) * s"
53 realpow_plus_1_assoc_l2: "r ^^^ m * (r * s) = r ^^^ (1 + m) * s"
54 realpow_plus_1_assoc_r: "s * r * r ^^^ m = s * r ^^^ (1 + m)"
55 realpow_plus_1_atom: "r is_atom ==> r * r ^^^ n = r ^^^ (1 + n)"
56 realpow_def_atom: "[| Not (r is_atom); 1 < n |]
57 ==> r ^^^ n = r * r ^^^ (n + -1)"
58 realpow_addI_atom: "r is_atom ==> r ^^^ n * r ^^^ m = r ^^^ (n + m)"
61 realpow_minus_even: "n is_even ==> (- r) ^^^ n = r ^^^ n"
62 realpow_minus_odd: "Not (n is_even) ==> (- r) ^^^ n = -1 * r ^^^ n"
66 real_pp_binom_times: "(a + b)*(c + d) = a*c + a*d + b*c + b*d"
67 real_pm_binom_times: "(a + b)*(c - d) = a*c - a*d + b*c - b*d"
68 real_mp_binom_times: "(a - b)*(c + d) = a*c + a*d - b*c - b*d"
69 real_mm_binom_times: "(a - b)*(c - d) = a*c - a*d - b*c + b*d"
70 real_plus_binom_pow3: "(a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3"
71 real_plus_binom_pow3_poly: "[| a is_polyexp; b is_polyexp |] ==>
72 (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3"
73 real_minus_binom_pow3: "(a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3"
74 real_minus_binom_pow3_p: "(a + -1 * b)^^^3 = a^^^3 + -3*a^^^2*b + 3*a*b^^^2 +
76 (* real_plus_binom_pow: "[| n is_const; 3 < n |] ==>
77 (a + b)^^^n = (a + b) * (a + b)^^^(n - 1)" *)
78 real_plus_binom_pow4: "(a + b)^^^4 = (a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3)
80 real_plus_binom_pow4_poly: "[| a is_polyexp; b is_polyexp |] ==>
81 (a + b)^^^4 = (a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3)
83 real_plus_binom_pow5: "(a + b)^^^5 = (a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3)
84 *(a^^^2 + 2*a*b + b^^^2)"
85 real_plus_binom_pow5_poly: "[| a is_polyexp; b is_polyexp |] ==>
86 (a + b)^^^5 = (a^^^3 + 3*a^^^2*b + 3*a*b^^^2
87 + b^^^3)*(a^^^2 + 2*a*b + b^^^2)"
88 real_diff_plus: "a - b = a + -b" (*17.3.03: do_NOT_use*)
89 real_diff_minus: "a - b = a + -1 * b"
90 real_plus_binom_times: "(a + b)*(a + b) = a^^^2 + 2*a*b + b^^^2"
91 real_minus_binom_times: "(a - b)*(a - b) = a^^^2 - 2*a*b + b^^^2"
92 (*WN071229 changed for Schaerding -----vvv*)
93 (*real_plus_binom_pow2: "(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
94 real_plus_binom_pow2: "(a + b)^^^2 = (a + b) * (a + b)"
95 (*WN071229 changed for Schaerding -----^^^*)
96 real_plus_binom_pow2_poly: "[| a is_polyexp; b is_polyexp |] ==>
97 (a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"
98 real_minus_binom_pow2: "(a - b)^^^2 = a^^^2 - 2*a*b + b^^^2"
99 real_minus_binom_pow2_p: "(a - b)^^^2 = a^^^2 + -2*a*b + b^^^2"
100 real_plus_minus_binom1: "(a + b)*(a - b) = a^^^2 - b^^^2"
101 real_plus_minus_binom1_p: "(a + b)*(a - b) = a^^^2 + -1*b^^^2"
102 real_plus_minus_binom1_p_p: "(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"
103 real_plus_minus_binom2: "(a - b)*(a + b) = a^^^2 - b^^^2"
104 real_plus_minus_binom2_p: "(a - b)*(a + b) = a^^^2 + -1*b^^^2"
105 real_plus_minus_binom2_p_p: "(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"
106 real_plus_binom_times1: "(a + 1*b)*(a + -1*b) = a^^^2 + -1*b^^^2"
107 real_plus_binom_times2: "(a + -1*b)*(a + 1*b) = a^^^2 + -1*b^^^2"
109 real_num_collect: "[| l is_const; m is_const |] ==>
110 l * n + m * n = (l + m) * n"
111 (* FIXME.MG.0401: replace 'real_num_collect_assoc'
112 by 'real_num_collect_assoc_l' ... are equal, introduced by MG ! *)
113 real_num_collect_assoc: "[| l is_const; m is_const |] ==>
114 l * n + (m * n + k) = (l + m) * n + k"
115 real_num_collect_assoc_l: "[| l is_const; m is_const |] ==>
116 l * n + (m * n + k) = (l + m)
118 real_num_collect_assoc_r: "[| l is_const; m is_const |] ==>
119 (k + m * n) + l * n = k + (l + m) * n"
120 real_one_collect: "m is_const ==> n + m * n = (1 + m) * n"
121 (* FIXME.MG.0401: replace 'real_one_collect_assoc'
122 by 'real_one_collect_assoc_l' ... are equal, introduced by MG ! *)
123 real_one_collect_assoc: "m is_const ==> n + (m * n + k) = (1 + m)* n + k"
125 real_one_collect_assoc_l: "m is_const ==> n + (m * n + k) = (1 + m) * n + k"
126 real_one_collect_assoc_r: "m is_const ==> (k + n) + m * n = k + (1 + m) * n"
128 (* FIXME.MG.0401: replace 'real_mult_2_assoc'
129 by 'real_mult_2_assoc_l' ... are equal, introduced by MG ! *)
130 real_mult_2_assoc: "z1 + (z1 + k) = 2 * z1 + k"
131 real_mult_2_assoc_l: "z1 + (z1 + k) = 2 * z1 + k"
132 real_mult_2_assoc_r: "(k + z1) + z1 = k + 2 * z1"
134 real_add_mult_distrib_poly: "w is_polyexp ==> (z1 + z2) * w = z1 * w + z2 * w"
135 real_add_mult_distrib2_poly:"w is_polyexp ==> w * (z1 + z2) = w * z1 + w * z2"
137 text {* remark on 'polynomials'
139 *** there are 5 kinds of expanded normalforms ***
141 [1] 'complete polynomial' (Komplettes Polynom), univariate
142 a_0 + a_1.x^1 +...+ a_n.x^n not (a_n = 0)
143 not (a_n = 0), some a_i may be zero (DON'T disappear),
144 variables in monomials lexicographically ordered and complete,
145 x written as 1*x^1, ...
146 [2] 'polynomial' (Polynom), univariate and multivariate
147 a_0 + a_1.x +...+ a_n.x^n not (a_n = 0)
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
149 not (a_n = 0), some a_i may be zero (ie. monomials disappear),
150 exponents and coefficients equal 1 are not (WN060904.TODO in cancel_p_)shown,
151 and variables in monomials are lexicographically ordered
152 examples: [1]: "1 + (-10) * x ^^^ 1 + 25 * x ^^^ 2"
153 [1]: "11 + 0 * x ^^^ 1 + 1 * x ^^^ 2"
154 [2]: "x + (-50) * x ^^^ 3"
155 [2]: "(-1) * x * y ^^^ 2 + 7 * x ^^^ 3"
157 [3] 'expanded_term' (Ausmultiplizierter Term):
158 pull out unary minus to binary minus,
159 as frequently exercised in schools; other conditions for [2] hold however
160 examples: "a ^^^ 2 - 2 * a * b + b ^^^ 2"
161 "4 * x ^^^ 2 - 9 * y ^^^ 2"
162 [4] 'polynomial_in' (Polynom in):
163 polynomial in 1 variable with arbitrary coefficients
164 examples: "2 * x + (-50) * x ^^^ 3" (poly in x)
165 "(u + v) + (2 * u ^^^ 2) * a + (-u) * a ^^^ 2 (poly in a)
166 [5] 'expanded_in' (Ausmultiplizierter Termin in):
167 analoguous to [3] with binary minus like [3]
168 examples: "2 * x - 50 * x ^^^ 3" (expanded in x)
169 "(u + v) + (2 * u ^^^ 2) * a - u * a ^^^ 2 (expanded in a)
175 (* is_polyrat_in becomes true, if no bdv is in the denominator of a fraction*)
176 fun is_polyrat_in t v =
177 let fun coeff_in c v = member op = (vars c) v;
178 fun finddivide (_ $ _ $ _ $ _) v = raise error("is_polyrat_in:")
179 (* at the moment there is no term like this, but ....*)
180 | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v =
182 | finddivide (_ $ t1 $ t2) v =
183 (finddivide t1 v) orelse (finddivide t2 v)
184 | finddivide (_ $ t1) v = (finddivide t1 v)
185 | finddivide _ _ = false;
186 in finddivide t v end;
188 fun eval_is_polyrat_in _ _(p as (Const ("Poly.is'_polyrat'_in",_) $ t $ v)) _ =
190 then SOME ((term2str p) ^ " = True",
191 Trueprop $ (mk_equality (p, HOLogic.true_const)))
192 else SOME ((term2str p) ^ " = True",
193 Trueprop $ (mk_equality (p, HOLogic.false_const)))
194 | eval_is_polyrat_in _ _ _ _ = ((*writeln"### no matches";*) NONE);
197 (*.a 'c is coefficient of v' if v does NOT occur in c.*)
198 fun coeff_in c v = not (member op = (vars c) v);
199 (* FIXME.WN100826 shift this into test--------------
200 val v = (term_of o the o (parse thy)) "x";
201 val t = (term_of o the o (parse thy)) "1";
203 (*val it = true : bool*)
204 val t = (term_of o the o (parse thy)) "a*b+c";
206 (*val it = true : bool*)
207 val t = (term_of o the o (parse thy)) "a*x+c";
209 (*val it = false : bool*)
210 ----------------------------------------------------*)
211 (*. a 'monomial t in variable v' is a term t with
212 either (1) v NOT existent in t, or (2) v contained in t,
214 if (2) then v is a factor on the very right, ev. with exponent.*)
215 fun factor_right_deg (*case 2*)
216 (t as Const ("op *",_) $ t1 $
217 (Const ("Atools.pow",_) $ vv $ Free (d,_))) v =
218 if ((vv = v) andalso (coeff_in t1 v)) then SOME (int_of_str' d) else NONE
219 | factor_right_deg (t as Const ("Atools.pow",_) $ vv $ Free (d,_)) v =
220 if (vv = v) then SOME (int_of_str' d) else NONE
221 | factor_right_deg (t as Const ("op *",_) $ t1 $ vv) v =
222 if ((vv = v) andalso (coeff_in t1 v))then SOME 1 else NONE
223 | factor_right_deg vv v =
224 if (vv = v) then SOME 1 else NONE;
225 fun mono_deg_in m v =
226 if coeff_in m v then (*case 1*) SOME 0
227 else factor_right_deg m v;
228 (* FIXME.WN100826 shift this into test-----------------------------
229 val v = (term_of o the o (parse thy)) "x";
230 val t = (term_of o the o (parse thy)) "(a*b+c)*x^^^7";
233 val t = (term_of o the o (parse thy)) "x^^^7";
236 val t = (term_of o the o (parse thy)) "(a*b+c)*x";
239 val t = (term_of o the o (parse thy)) "(a*b+x)*x";
242 val t = (term_of o the o (parse thy)) "x";
245 val t = (term_of o the o (parse thy)) "(a*b+c)";
248 val t = (term_of o the o (parse thy)) "ab - (a*b)*x";
251 ------------------------------------------------------------------*)
252 fun expand_deg_in t v =
253 let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
254 (case mono_deg_in t2 v of (* $ is left associative*)
255 SOME d' => edi d' d' t1
257 | edi ~1 ~1 (Const ("op -",_) $ t1 $ t2) =
258 (case mono_deg_in t2 v of
259 SOME d' => edi d' d' t1
261 | edi d dmax (Const ("op -",_) $ t1 $ t2) =
262 (case mono_deg_in t2 v of
263 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
264 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
265 then edi d' dmax t1 else NONE
267 | edi d dmax (Const ("op +",_) $ t1 $ t2) =
268 (case mono_deg_in t2 v of
269 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
270 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
271 then edi d' dmax t1 else NONE
273 | edi ~1 ~1 t = (case mono_deg_in t v of
276 | edi d dmax t = (*basecase last*)
277 (case mono_deg_in t v of
278 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
279 then SOME dmax else NONE
282 (* FIXME.WN100826 shift this into test-----------------------------
283 val v = (term_of o the o (parse thy)) "x";
284 val t = (term_of o the o (parse thy)) "a+b";
287 val t = (term_of o the o (parse thy)) "(a+b)*x";
290 val t = (term_of o the o (parse thy)) "a*b - (a+b)*x";
293 val t = (term_of o the o (parse thy)) "a*b + (a-b)*x";
296 val t = (term_of o the o (parse thy)) "a*b + (a+b)*x + x^^^2";
298 -------------------------------------------------------------------*)
299 fun poly_deg_in t v =
300 let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
301 (case mono_deg_in t2 v of (* $ is left associative*)
302 SOME d' => edi d' d' t1
304 | edi d dmax (Const ("op +",_) $ t1 $ t2) =
305 (case mono_deg_in t2 v of
306 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
307 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
308 then edi d' dmax t1 else NONE
310 | edi ~1 ~1 t = (case mono_deg_in t v of
313 | edi d dmax t = (*basecase last*)
314 (case mono_deg_in t v of
315 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
316 then SOME dmax else NONE
321 fun is_expanded_in t v =
322 case expand_deg_in t v of SOME _ => true | NONE => false;
324 case poly_deg_in t v of SOME _ => true | NONE => false;
325 fun has_degree_in t v =
326 case expand_deg_in t v of SOME d => d | NONE => ~1;
328 (* FIXME.WN100826 shift this into test-----------------------------
329 val v = (term_of o the o (parse thy)) "x";
330 val t = (term_of o the o (parse thy)) "a*b - (a+b)*x + x^^^2";
333 val t = (term_of o the o (parse thy)) "-8 - 2*x + x^^^2";
336 val t = (term_of o the o (parse thy)) "6 + 13*x + 6*x^^^2";
339 -------------------------------------------------------------------*)
341 (*("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in ""))*)
342 fun eval_is_expanded_in _ _
343 (p as (Const ("Poly.is'_expanded'_in",_) $ t $ v)) _ =
344 if is_expanded_in t v
345 then SOME ((term2str p) ^ " = True",
346 Trueprop $ (mk_equality (p, HOLogic.true_const)))
347 else SOME ((term2str p) ^ " = True",
348 Trueprop $ (mk_equality (p, HOLogic.false_const)))
349 | eval_is_expanded_in _ _ _ _ = NONE;
351 val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) is_expanded_in x";
352 val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
353 (*val id = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
355 (*val it = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
358 (*("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in ""))*)
359 fun eval_is_poly_in _ _
360 (p as (Const ("Poly.is'_poly'_in",_) $ t $ v)) _ =
362 then SOME ((term2str p) ^ " = True",
363 Trueprop $ (mk_equality (p, HOLogic.true_const)))
364 else SOME ((term2str p) ^ " = True",
365 Trueprop $ (mk_equality (p, HOLogic.false_const)))
366 | eval_is_poly_in _ _ _ _ = NONE;
368 val t = (term_of o the o (parse thy)) "(8 + 2*x + x^^^2) is_poly_in x";
369 val SOME (id, t') = eval_is_poly_in 0 0 t 0;
370 (*val id = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
372 (*val it = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
375 (*("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in ""))*)
376 fun eval_has_degree_in _ _
377 (p as (Const ("Poly.has'_degree'_in",_) $ t $ v)) _ =
378 let val d = has_degree_in t v
379 val d' = term_of_num HOLogic.realT d
380 in SOME ((term2str p) ^ " = " ^ (string_of_int d),
381 Trueprop $ (mk_equality (p, d')))
383 | eval_has_degree_in _ _ _ _ = NONE;
385 > val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) has_degree_in x";
386 > val SOME (id, t') = eval_has_degree_in 0 0 t 0;
387 val id = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
389 val it = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
392 (*.for evaluation of conditions in rewrite rules.*)
394 append_rls "Poly_erls" Atools_erls
395 [ Calc ("op =",eval_equal "#equal_"),
396 Thm ("real_unari_minus",num_str @{thm real_unari_minus}),
397 Calc ("op +",eval_binop "#add_"),
398 Calc ("op -",eval_binop "#sub_"),
399 Calc ("op *",eval_binop "#mult_"),
400 Calc ("Atools.pow" ,eval_binop "#power_")
404 append_rls "poly_crls" Atools_crls
405 [ Calc ("op =",eval_equal "#equal_"),
406 Thm ("real_unari_minus",num_str @{thm real_unari_minus}),
407 Calc ("op +",eval_binop "#add_"),
408 Calc ("op -",eval_binop "#sub_"),
409 Calc ("op *",eval_binop "#mult_"),
410 Calc ("Atools.pow" ,eval_binop "#power_")
413 local (*. for make_polynomial .*)
415 open Term; (* for type order = EQUAL | LESS | GREATER *)
417 fun pr_ord EQUAL = "EQUAL"
418 | pr_ord LESS = "LESS"
419 | pr_ord GREATER = "GREATER";
421 fun dest_hd' (Const (a, T)) = (* ~ term.ML *)
423 "Atools.pow" => ((("|||||||||||||", 0), T), 0) (*WN greatest string*)
424 | _ => (((a, 0), T), 0))
425 | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
426 | dest_hd' (Var v) = (v, 2)
427 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
428 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
430 fun get_order_pow (t $ (Free(order,_))) = (* RL FIXXXME:geht zufaellig?WN*)
431 (case int_of_str (order) of
434 | get_order_pow _ = 0;
436 fun size_of_term' (Const(str,_) $ t) =
437 if "Atools.pow"= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
438 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
439 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
440 | size_of_term' _ = 1;
442 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
443 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
444 | term_ord' pr thy (t, u) =
447 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
448 val _=writeln("t= f@ts= \""^
449 ((Syntax.string_of_term (thy2ctxt thy)) f)^"\" @ \"["^
450 (commas(map(Syntax.string_of_term (thy2ctxt thy))ts))^"]\"");
451 val _=writeln("u= g@us= \""^
452 ((Syntax.string_of_term (thy2ctxt thy)) g)^"\" @ \"["^
453 (commas(map(Syntax.string_of_term (thy2ctxt thy))us))^"]\"");
454 val _=writeln("size_of_term(t,u)= ("^
455 (string_of_int(size_of_term' t))^", "^
456 (string_of_int(size_of_term' u))^")");
457 val _=writeln("hd_ord(f,g) = "^((pr_ord o hd_ord)(f,g)));
458 val _=writeln("terms_ord(ts,us) = "^
459 ((pr_ord o terms_ord str false)(ts,us)));
460 val _=writeln("-------");
463 case int_ord (size_of_term' t, size_of_term' u) of
465 let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
466 (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us)
470 and hd_ord (f, g) = (* ~ term.ML *)
471 prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
472 and terms_ord str pr (ts, us) =
473 list_ord (term_ord' pr (assoc_thy "Isac.thy"))(ts, us);
476 fun ord_make_polynomial (pr:bool) thy (_:subst) tu =
477 (term_ord' pr thy(***) tu = LESS );
482 rew_ord' := overwritel (!rew_ord',
483 [("termlessI", termlessI),
484 ("ord_make_polynomial", ord_make_polynomial false thy)
489 Rls{id = "expand", preconds = [], rew_ord = ("dummy_ord", dummy_ord),
490 erls = e_rls,srls = Erls, calc = [],
491 rules = [Thm ("left_distrib" ,num_str @{thm left_distrib}),
492 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
493 Thm ("right_distrib",num_str @{thm right_distrib})
494 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
495 ], scr = EmptyScr}:rls;
497 (*----------------- Begin: rulesets for make_polynomial_ -----------------
498 'rlsIDs' redefined by MG as 'rlsIDs_'
502 Rls{id = "discard_minus_", preconds = [],
503 rew_ord = ("dummy_ord", dummy_ord),
504 erls = e_rls,srls = Erls,
507 rules = [Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
508 (*"a - b = a + -1 * b"*)
509 Thm ("sym_real_mult_minus1",
510 num_str (@{thm real_mult_minus1} RS @{thm sym}))
512 ], scr = EmptyScr}:rls;
514 Rls{id = "expand_poly_", preconds = [],
515 rew_ord = ("dummy_ord", dummy_ord),
516 erls = e_rls,srls = Erls,
519 rules = [Thm ("real_plus_binom_pow4",num_str @{thm real_plus_binom_pow4}),
520 (*"(a + b)^^^4 = ... "*)
521 Thm ("real_plus_binom_pow5",num_str @{thm real_plus_binom_pow5}),
522 (*"(a + b)^^^5 = ... "*)
523 Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
524 (*"(a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
525 (*WN071229 changed/removed for Schaerding -----vvv*)
526 (*Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),*)
527 (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
528 Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),
529 (*"(a + b)^^^2 = (a + b) * (a + b)"*)
530 (*Thm ("real_plus_minus_binom1_p_p",
531 num_str @{thm real_plus_minus_binom1_p_p}),*)
532 (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
533 (*Thm ("real_plus_minus_binom2_p_p",
534 num_str @{thm real_plus_minus_binom2_p_p}),*)
535 (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
536 (*WN071229 changed/removed for Schaerding -----^^^*)
538 Thm ("left_distrib" ,num_str @{thm left_distrib}),
539 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
540 Thm ("right_distrib",num_str @{thm right_distrib}),
541 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
543 Thm ("realpow_multI", num_str @{thm realpow_multI}),
544 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
545 Thm ("realpow_pow",num_str @{thm realpow_pow})
546 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
547 ], scr = EmptyScr}:rls;
549 (*.the expression contains + - * ^ only ?
550 this is weaker than 'is_polynomial' !.*)
551 fun is_polyexp (Free _) = true
552 | is_polyexp (Const ("op +",_) $ Free _ $ Free _) = true
553 | is_polyexp (Const ("op -",_) $ Free _ $ Free _) = true
554 | is_polyexp (Const ("op *",_) $ Free _ $ Free _) = true
555 | is_polyexp (Const ("Atools.pow",_) $ Free _ $ Free _) = true
556 | is_polyexp (Const ("op +",_) $ t1 $ t2) =
557 ((is_polyexp t1) andalso (is_polyexp t2))
558 | is_polyexp (Const ("op -",_) $ t1 $ t2) =
559 ((is_polyexp t1) andalso (is_polyexp t2))
560 | is_polyexp (Const ("op *",_) $ t1 $ t2) =
561 ((is_polyexp t1) andalso (is_polyexp t2))
562 | is_polyexp (Const ("Atools.pow",_) $ t1 $ t2) =
563 ((is_polyexp t1) andalso (is_polyexp t2))
564 | is_polyexp _ = false;
566 (*("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp ""))*)
567 fun eval_is_polyexp (thmid:string) _
568 (t as (Const("Poly.is'_polyexp", _) $ arg)) thy =
570 then SOME (mk_thmid thmid ""
571 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
572 Trueprop $ (mk_equality (t, HOLogic.true_const)))
573 else SOME (mk_thmid thmid ""
574 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
575 Trueprop $ (mk_equality (t, HOLogic.false_const)))
576 | eval_is_polyexp _ _ _ _ = NONE;
578 val expand_poly_rat_ =
579 Rls{id = "expand_poly_rat_", preconds = [],
580 rew_ord = ("dummy_ord", dummy_ord),
581 erls = append_rls "e_rls-is_polyexp" e_rls
582 [Calc ("Poly.is'_polyexp", eval_is_polyexp "")
588 [Thm ("real_plus_binom_pow4_poly", num_str @{thm real_plus_binom_pow4_poly}),
589 (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^4 = ... "*)
590 Thm ("real_plus_binom_pow5_poly", num_str @{thm real_plus_binom_pow5_poly}),
591 (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^5 = ... "*)
592 Thm ("real_plus_binom_pow2_poly",num_str @{thm real_plus_binom_pow2_poly}),
593 (*"[| a is_polyexp; b is_polyexp |] ==>
594 (a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
595 Thm ("real_plus_binom_pow3_poly",num_str @{thm real_plus_binom_pow3_poly}),
596 (*"[| a is_polyexp; b is_polyexp |] ==>
597 (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
598 Thm ("real_plus_minus_binom1_p_p",num_str @{thm real_plus_minus_binom1_p_p}),
599 (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
600 Thm ("real_plus_minus_binom2_p_p",num_str @{thm real_plus_minus_binom2_p_p}),
601 (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
603 Thm ("real_add_mult_distrib_poly",
604 num_str @{thm real_add_mult_distrib_poly}),
605 (*"w is_polyexp ==> (z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
606 Thm("real_add_mult_distrib2_poly",
607 num_str @{thm real_add_mult_distrib2_poly}),
608 (*"w is_polyexp ==> w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
610 Thm ("realpow_multI_poly", num_str @{thm realpow_multI_poly}),
611 (*"[| r is_polyexp; s is_polyexp |] ==>
612 (r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
613 Thm ("realpow_pow",num_str @{thm realpow_pow})
614 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
615 ], scr = EmptyScr}:rls;
617 val simplify_power_ =
618 Rls{id = "simplify_power_", preconds = [],
619 rew_ord = ("dummy_ord", dummy_ord),
620 erls = e_rls, srls = Erls,
623 rules = [(*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
624 a*(a*a) --> a*a^^^2 und nicht a*(a*a) --> a^^^2*a *)
625 Thm ("sym_realpow_twoI",
626 num_str (@{thm realpow_twoI} RS @{thm sym})),
627 (*"r * r = r ^^^ 2"*)
628 Thm ("realpow_twoI_assoc_l",num_str @{thm realpow_twoI_assoc_l}),
629 (*"r * (r * s) = r ^^^ 2 * s"*)
631 Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),
632 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
633 Thm ("realpow_plus_1_assoc_l",
634 num_str @{thm realpow_plus_1_assoc_l}),
635 (*"r * (r ^^^ m * s) = r ^^^ (1 + m) * s"*)
636 (*MG 9.7.03: neues Thm wegen a*(a*(a*b)) --> a^^^2*(a*b) *)
637 Thm ("realpow_plus_1_assoc_l2",
638 num_str @{thm realpow_plus_1_assoc_l2}),
639 (*"r ^^^ m * (r * s) = r ^^^ (1 + m) * s"*)
641 Thm ("sym_realpow_addI",
642 num_str (@{thm realpow_addI} RS @{thm sym})),
643 (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
644 Thm ("realpow_addI_assoc_l",num_str @{thm realpow_addI_assoc_l}),
645 (*"r ^^^ n * (r ^^^ m * s) = r ^^^ (n + m) * s"*)
647 (* ist in expand_poly - wird hier aber auch gebraucht, wegen:
648 "r * r = r ^^^ 2" wenn r=a^^^b*)
649 Thm ("realpow_pow",num_str @{thm realpow_pow})
650 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
651 ], scr = EmptyScr}:rls;
653 val calc_add_mult_pow_ =
654 Rls{id = "calc_add_mult_pow_", preconds = [],
655 rew_ord = ("dummy_ord", dummy_ord),
656 erls = Atools_erls(*erls3.4.03*),srls = Erls,
657 calc = [("PLUS" , ("op +", eval_binop "#add_")),
658 ("TIMES" , ("op *", eval_binop "#mult_")),
659 ("POWER", ("Atools.pow", eval_binop "#power_"))
662 rules = [Calc ("op +", eval_binop "#add_"),
663 Calc ("op *", eval_binop "#mult_"),
664 Calc ("Atools.pow", eval_binop "#power_")
665 ], scr = EmptyScr}:rls;
667 val reduce_012_mult_ =
668 Rls{id = "reduce_012_mult_", preconds = [],
669 rew_ord = ("dummy_ord", dummy_ord),
670 erls = e_rls,srls = Erls,
673 rules = [(* MG: folgende Thm müssen hier stehen bleiben: *)
674 Thm ("mult_1_right",num_str @{thm mult_1_right}),
675 (*"z * 1 = z"*) (*wegen "a * b * b^^^(-1) + a"*)
676 Thm ("realpow_zeroI",num_str @{thm realpow_zeroI}),
677 (*"r ^^^ 0 = 1"*) (*wegen "a*a^^^(-1)*c + b + c"*)
678 Thm ("realpow_oneI",num_str @{thm realpow_oneI}),
680 Thm ("realpow_eq_oneI",num_str @{thm realpow_eq_oneI})
682 ], scr = EmptyScr}:rls;
684 val collect_numerals_ =
685 Rls{id = "collect_numerals_", preconds = [],
686 rew_ord = ("dummy_ord", dummy_ord),
687 erls = Atools_erls, srls = Erls,
688 calc = [("PLUS" , ("op +", eval_binop "#add_"))
691 [Thm ("real_num_collect",num_str @{thm real_num_collect}),
692 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
693 Thm ("real_num_collect_assoc_r",num_str @{thm real_num_collect_assoc_r}),
694 (*"[| l is_const; m is_const |] ==> \
695 \(k + m * n) + l * n = k + (l + m)*n"*)
696 Thm ("real_one_collect",num_str @{thm real_one_collect}),
697 (*"m is_const ==> n + m * n = (1 + m) * n"*)
698 Thm ("real_one_collect_assoc_r",num_str @{thm real_one_collect_assoc_r}),
699 (*"m is_const ==> (k + n) + m * n = k + (m + 1) * n"*)
701 Calc ("op +", eval_binop "#add_"),
703 (*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
704 (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
705 Thm ("real_mult_2_assoc_r",num_str @{thm real_mult_2_assoc_r}),
706 (*"(k + z1) + z1 = k + 2 * z1"*)
707 Thm ("sym_real_mult_2",num_str (@{thm real_mult_2} RS @{thm sym}))
708 (*"z1 + z1 = 2 * z1"*)
709 ], scr = EmptyScr}:rls;
712 Rls{id = "reduce_012_", preconds = [],
713 rew_ord = ("dummy_ord", dummy_ord),
714 erls = e_rls,srls = Erls, calc = [],
715 rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),
717 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
719 Thm ("mult_zero_right",num_str @{thm mult_zero_right}),
721 Thm ("add_0_left",num_str @{thm add_0_left}),
723 Thm ("add_0_right",num_str @{thm add_0_right}),
724 (*"z + 0 = z"*) (*wegen a+b-b --> a+(1-1)*b --> a+0 --> a*)
726 (*Thm ("realpow_oneI",num_str @{thm realpow_oneI})*)
728 Thm ("divide_zero_left",num_str @{thm divide_zero_left})(*WN060914*)
730 ], scr = EmptyScr}:rls;
732 (*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
733 val discard_parentheses_ =
734 append_rls "discard_parentheses_" e_rls
735 [Thm ("sym_real_mult_assoc",
736 num_str (@{thm real_mult_assoc} RS @{thm sym}))
737 (*"?z1.1 * (?z2.1 * ?z3.1) = ?z1.1 * ?z2.1 * ?z3.1"*)
738 (*Thm ("sym_add_assoc",
739 num_str (@{thm add_assoc} RS @{thm sym}))*)
740 (*"?z1.1 + (?z2.1 + ?z3.1) = ?z1.1 + ?z2.1 + ?z3.1"*)
743 (*----------------- End: rulesets for make_polynomial_ -----------------*)
745 (*MG.0401 ev. for use in rls with ordered rewriting ?
746 val collect_numerals_left =
747 Rls{id = "collect_numerals", preconds = [],
748 rew_ord = ("dummy_ord", dummy_ord),
749 erls = Atools_erls(*erls3.4.03*),srls = Erls,
750 calc = [("PLUS" , ("op +", eval_binop "#add_")),
751 ("TIMES" , ("op *", eval_binop "#mult_")),
752 ("POWER", ("Atools.pow", eval_binop "#power_"))
755 rules = [Thm ("real_num_collect",num_str @{thm real_num_collect}),
756 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
757 Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
758 (*"[| l is_const; m is_const |] ==>
759 l * n + (m * n + k) = (l + m) * n + k"*)
760 Thm ("real_one_collect",num_str @{thm real_one_collect}),
761 (*"m is_const ==> n + m * n = (1 + m) * n"*)
762 Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}),
763 (*"m is_const ==> n + (m * n + k) = (1 + m) * n + k"*)
765 Calc ("op +", eval_binop "#add_"),
767 (*MG am 2.5.03: 2 Theoreme aus reduce_012 hierher verschoben*)
768 Thm ("sym_real_mult_2",
769 num_str (@{thm real_mult_2} RS @{thm sym})),
770 (*"z1 + z1 = 2 * z1"*)
771 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc})
772 (*"z1 + (z1 + k) = 2 * z1 + k"*)
773 ], scr = EmptyScr}:rls;*)
776 Rls{id = "expand_poly", preconds = [],
777 rew_ord = ("dummy_ord", dummy_ord),
778 erls = e_rls,srls = Erls,
781 rules = [Thm ("left_distrib" ,num_str @{thm left_distrib}),
782 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
783 Thm ("right_distrib",num_str @{thm right_distrib}),
784 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
785 (*Thm ("left_distrib1",num_str @{thm left_distrib}1),
786 ....... 18.3.03 undefined???*)
788 Thm ("real_plus_binom_pow2",num_str @{thm real_plus_binom_pow2}),
789 (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
790 Thm ("real_minus_binom_pow2_p",num_str @{thm real_minus_binom_pow2_p}),
791 (*"(a - b)^^^2 = a^^^2 + -2*a*b + b^^^2"*)
792 Thm ("real_plus_minus_binom1_p",
793 num_str @{thm real_plus_minus_binom1_p}),
794 (*"(a + b)*(a - b) = a^^^2 + -1*b^^^2"*)
795 Thm ("real_plus_minus_binom2_p",
796 num_str @{thm real_plus_minus_binom2_p}),
797 (*"(a - b)*(a + b) = a^^^2 + -1*b^^^2"*)
799 Thm ("minus_minus",num_str @{thm minus_minus}),
801 Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
802 (*"a - b = a + -1 * b"*)
803 Thm ("sym_real_mult_minus1",
804 num_str (@{thm real_mult_minus1} RS @{thm sym}))
807 (*Thm ("real_minus_add_distrib",
808 num_str @{thm real_minus_add_distrib}),*)
809 (*"- (?x + ?y) = - ?x + - ?y"*)
810 (*Thm ("real_diff_plus",num_str @{thm real_diff_plus})*)
812 ], scr = EmptyScr}:rls;
815 Rls{id = "simplify_power", preconds = [],
816 rew_ord = ("dummy_ord", dummy_ord),
817 erls = e_rls, srls = Erls,
820 rules = [Thm ("realpow_multI", num_str @{thm realpow_multI}),
821 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
823 Thm ("sym_realpow_twoI",
824 num_str( @{thm realpow_twoI} RS @{thm sym})),
825 (*"r1 * r1 = r1 ^^^ 2"*)
826 Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),
827 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
828 Thm ("realpow_pow",num_str @{thm realpow_pow}),
829 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
830 Thm ("sym_realpow_addI",
831 num_str (@{thm realpow_addI} RS @{thm sym})),
832 (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
833 Thm ("realpow_oneI",num_str @{thm realpow_oneI}),
835 Thm ("realpow_eq_oneI",num_str @{thm realpow_eq_oneI})
837 ], scr = EmptyScr}:rls;
838 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
839 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
841 Rls{id = "order_add_mult", preconds = [],
842 rew_ord = ("ord_make_polynomial",ord_make_polynomial false thy),
843 erls = e_rls,srls = Erls,
846 rules = [Thm ("real_mult_commute",num_str @{thm real_mult_commute}),
848 Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
849 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
850 Thm ("real_mult_assoc",num_str @{thm real_mult_assoc}),
851 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
852 Thm ("add_commute",num_str @{thm add_commute}),
854 Thm ("add_left_commute",num_str @{thm add_left_commute}),
855 (*x + (y + z) = y + (x + z)*)
856 Thm ("add_assoc",num_str @{thm add_assoc})
857 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
858 ], scr = EmptyScr}:rls;
859 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
860 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
862 Rls{id = "order_mult", preconds = [],
863 rew_ord = ("ord_make_polynomial",ord_make_polynomial false thy),
864 erls = e_rls,srls = Erls,
867 rules = [Thm ("real_mult_commute",num_str @{thm real_mult_commute}),
869 Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
870 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
871 Thm ("real_mult_assoc",num_str @{thm real_mult_assoc})
872 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
873 ], scr = EmptyScr}:rls;
874 val collect_numerals =
875 Rls{id = "collect_numerals", preconds = [],
876 rew_ord = ("dummy_ord", dummy_ord),
877 erls = Atools_erls(*erls3.4.03*),srls = Erls,
878 calc = [("PLUS" , ("op +", eval_binop "#add_")),
879 ("TIMES" , ("op *", eval_binop "#mult_")),
880 ("POWER", ("Atools.pow", eval_binop "#power_"))
883 rules = [Thm ("real_num_collect",num_str @{thm real_num_collect}),
884 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
885 Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
886 (*"[| l is_const; m is_const |] ==>
887 l * n + (m * n + k) = (l + m) * n + k"*)
888 Thm ("real_one_collect",num_str @{thm real_one_collect}),
889 (*"m is_const ==> n + m * n = (1 + m) * n"*)
890 Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}),
891 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
892 Calc ("op +", eval_binop "#add_"),
893 Calc ("op *", eval_binop "#mult_"),
894 Calc ("Atools.pow", eval_binop "#power_")
895 ], scr = EmptyScr}:rls;
897 Rls{id = "reduce_012", preconds = [],
898 rew_ord = ("dummy_ord", dummy_ord),
899 erls = e_rls,srls = Erls,
902 rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),
904 (*Thm ("real_mult_minus1",num_str @{thm real_mult_minus1}),14.3.03*)
906 Thm ("minus_mult_left",
907 num_str (@{thm minus_mult_left} RS @{thm sym})),
908 (*- (?x * ?y) = "- ?x * ?y"*)
909 (*Thm ("real_minus_mult_cancel",
910 num_str @{thm real_minus_mult_cancel}),
911 (*"- ?x * - ?y = ?x * ?y"*)---*)
912 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
914 Thm ("add_0_left",num_str @{thm add_0_left}),
916 Thm ("right_minus",num_str @{thm right_minus}),
918 Thm ("sym_real_mult_2",
919 num_str (@{thm real_mult_2} RS @{thm sym})),
920 (*"z1 + z1 = 2 * z1"*)
921 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc})
922 (*"z1 + (z1 + k) = 2 * z1 + k"*)
923 ], scr = EmptyScr}:rls;
924 (*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
925 val discard_parentheses =
926 append_rls "discard_parentheses" e_rls
927 [Thm ("sym_real_mult_assoc",
928 num_str (@{thm real_mult_assoc} RS @{thm sym})),
929 Thm ("sym_add_assoc",
930 num_str (@{thm add_assoc} RS @{thm sym}))];
932 val scr_make_polynomial =
933 "Script Expand_binoms t_t = " ^
935 "((Try (Repeat (Rewrite real_diff_minus False))) @@ " ^
937 " (Try (Repeat (Rewrite left_distrib False))) @@ " ^
938 " (Try (Repeat (Rewrite right_distrib False))) @@ " ^
939 " (Try (Repeat (Rewrite left_diff_distrib False))) @@ " ^
940 " (Try (Repeat (Rewrite right_diff_distrib False))) @@ " ^
942 " (Try (Repeat (Rewrite mult_1_left False))) @@ " ^
943 " (Try (Repeat (Rewrite mult_zero_left False))) @@ " ^
944 " (Try (Repeat (Rewrite add_0_left False))) @@ " ^
946 " (Try (Repeat (Rewrite real_mult_commute False))) @@ " ^
947 " (Try (Repeat (Rewrite real_mult_left_commute False))) @@ " ^
948 " (Try (Repeat (Rewrite real_mult_assoc False))) @@ " ^
949 " (Try (Repeat (Rewrite add_commute False))) @@ " ^
950 " (Try (Repeat (Rewrite add_left_commute False))) @@ " ^
951 " (Try (Repeat (Rewrite add_assoc False))) @@ " ^
953 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
954 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
955 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
956 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
958 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
959 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
961 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
962 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
964 " (Try (Repeat (Calculate PLUS ))) @@ " ^
965 " (Try (Repeat (Calculate TIMES ))) @@ " ^
966 " (Try (Repeat (Calculate POWER)))) " ^
969 (*version used by MG.02/03, overwritten by version AG in 04 below
970 val make_polynomial = prep_rls(
971 Seq{id = "make_polynomial", preconds = []:term list,
972 rew_ord = ("dummy_ord", dummy_ord),
973 erls = Atools_erls, srls = Erls,
974 calc = [],(*asm_thm = [],*)
975 rules = [Rls_ expand_poly,
977 Rls_ simplify_power, (*realpow_eq_oneI, eg. x^1 --> x *)
978 Rls_ collect_numerals, (*eg. x^(2+ -1) --> x^1 *)
980 Thm ("realpow_oneI",num_str @{thm realpow_oneI}),(*in --^*)
981 Rls_ discard_parentheses
986 val scr_expand_binoms =
987 "Script Expand_binoms t_t =" ^
989 "((Try (Repeat (Rewrite real_plus_binom_pow2 False))) @@ " ^
990 " (Try (Repeat (Rewrite real_plus_binom_times False))) @@ " ^
991 " (Try (Repeat (Rewrite real_minus_binom_pow2 False))) @@ " ^
992 " (Try (Repeat (Rewrite real_minus_binom_times False))) @@ " ^
993 " (Try (Repeat (Rewrite real_plus_minus_binom1 False))) @@ " ^
994 " (Try (Repeat (Rewrite real_plus_minus_binom2 False))) @@ " ^
996 " (Try (Repeat (Rewrite mult_1_left False))) @@ " ^
997 " (Try (Repeat (Rewrite mult_zero_left False))) @@ " ^
998 " (Try (Repeat (Rewrite add_0_left False))) @@ " ^
1000 " (Try (Repeat (Calculate PLUS ))) @@ " ^
1001 " (Try (Repeat (Calculate TIMES ))) @@ " ^
1002 " (Try (Repeat (Calculate POWER))) @@ " ^
1004 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
1005 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
1006 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
1007 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
1009 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
1010 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
1012 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
1013 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
1015 " (Try (Repeat (Calculate PLUS ))) @@ " ^
1016 " (Try (Repeat (Calculate TIMES ))) @@ " ^
1017 " (Try (Repeat (Calculate POWER)))) " ^
1021 Rls{id = "expand_binoms", preconds = [], rew_ord = ("termlessI",termlessI),
1022 erls = Atools_erls, srls = Erls,
1023 calc = [("PLUS" , ("op +", eval_binop "#add_")),
1024 ("TIMES" , ("op *", eval_binop "#mult_")),
1025 ("POWER", ("Atools.pow", eval_binop "#power_"))
1027 rules = [Thm ("real_plus_binom_pow2",
1028 num_str @{thm real_plus_binom_pow2}),
1029 (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
1030 Thm ("real_plus_binom_times",
1031 num_str @{thm real_plus_binom_times}),
1032 (*"(a + b)*(a + b) = ...*)
1033 Thm ("real_minus_binom_pow2",
1034 num_str @{thm real_minus_binom_pow2}),
1035 (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
1036 Thm ("real_minus_binom_times",
1037 num_str @{thm real_minus_binom_times}),
1038 (*"(a - b)*(a - b) = ...*)
1039 Thm ("real_plus_minus_binom1",
1040 num_str @{thm real_plus_minus_binom1}),
1041 (*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
1042 Thm ("real_plus_minus_binom2",
1043 num_str @{thm real_plus_minus_binom2}),
1044 (*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
1046 Thm ("real_pp_binom_times",num_str @{thm real_pp_binom_times}),
1047 (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
1048 Thm ("real_pm_binom_times",num_str @{thm real_pm_binom_times}),
1049 (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
1050 Thm ("real_mp_binom_times",num_str @{thm real_mp_binom_times}),
1051 (*(a - b)*(c + d) = a*c + a*d - b*c - b*d*)
1052 Thm ("real_mm_binom_times",num_str @{thm real_mm_binom_times}),
1053 (*(a - b)*(c - d) = a*c - a*d - b*c + b*d*)
1054 Thm ("realpow_multI",num_str @{thm realpow_multI}),
1055 (*(a*b)^^^n = a^^^n * b^^^n*)
1056 Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
1057 (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
1058 Thm ("real_minus_binom_pow3",
1059 num_str @{thm real_minus_binom_pow3}),
1060 (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
1063 (*Thm ("left_distrib" ,num_str @{thm left_distrib}),
1064 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1065 Thm ("right_distrib",num_str @{thm right_distrib}),
1066 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1067 Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),
1068 (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
1069 Thm ("left_diff_distrib2",num_str @{thm left_diff_distrib2}),
1070 (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
1072 Thm ("mult_1_left",num_str @{thm mult_1_left}),
1074 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
1076 Thm ("add_0_left",num_str @{thm add_0_left}),(*"0 + z = z"*)
1078 Calc ("op +", eval_binop "#add_"),
1079 Calc ("op *", eval_binop "#mult_"),
1080 Calc ("Atools.pow", eval_binop "#power_"),
1081 (*Thm ("real_mult_commute",num_str @{thm real_mult_commute}),
1083 Thm ("real_mult_left_commute",
1084 num_str @{thm real_mult_left_commute}),
1085 Thm ("real_mult_assoc",num_str @{thm real_mult_assoc}),
1086 Thm ("add_commute",num_str @{thm add_commute}),
1087 Thm ("add_left_commute",num_str @{thm add_left_commute}),
1088 Thm ("add_assoc",num_str @{thm add_assoc}),
1090 Thm ("sym_realpow_twoI",
1091 num_str (@{thm realpow_twoI} RS @{thm sym})),
1092 (*"r1 * r1 = r1 ^^^ 2"*)
1093 Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),
1094 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
1095 (*Thm ("sym_real_mult_2",
1096 num_str (@{thm real_mult_2} RS @{thm sym})),
1097 (*"z1 + z1 = 2 * z1"*)*)
1098 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),
1099 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1101 Thm ("real_num_collect",num_str @{thm real_num_collect}),
1102 (*"[| l is_const; m is_const |] ==>l * n + m * n = (l + m) * n"*)
1103 Thm ("real_num_collect_assoc",
1104 num_str @{thm real_num_collect_assoc}),
1105 (*"[| l is_const; m is_const |] ==>
1106 l * n + (m * n + k) = (l + m) * n + k"*)
1107 Thm ("real_one_collect",num_str @{thm real_one_collect}),
1108 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1109 Thm ("real_one_collect_assoc",
1110 num_str @{thm real_one_collect_assoc}),
1111 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1113 Calc ("op +", eval_binop "#add_"),
1114 Calc ("op *", eval_binop "#mult_"),
1115 Calc ("Atools.pow", eval_binop "#power_")
1117 scr = Script ((term_of o the o (parse thy)) scr_expand_binoms)
1121 (**. MG.03: make_polynomial_ ... uses SML-fun for ordering .**)
1123 (*FIXME.0401: make SML-order local to make_polynomial(_) *)
1124 (*FIXME.0401: replace 'make_polynomial'(old) by 'make_polynomial_'(MG) *)
1125 (* Polynom --> List von Monomen *)
1126 fun poly2list (Const ("op +",_) $ t1 $ t2) =
1127 (poly2list t1) @ (poly2list t2)
1128 | poly2list t = [t];
1130 (* Monom --> Liste von Variablen *)
1131 fun monom2list (Const ("op *",_) $ t1 $ t2) =
1132 (monom2list t1) @ (monom2list t2)
1133 | monom2list t = [t];
1135 (* liefert Variablenname (String) einer Variablen und Basis bei Potenz *)
1136 fun get_basStr (Const ("Atools.pow",_) $ Free (str, _) $ _) = str
1137 | get_basStr (Free (str, _)) = str
1138 | get_basStr t = "|||"; (* gross gewichtet; für Brüch ect. *)
1140 raise error("get_basStr: called with t= "^(term2str t));*)
1142 (* liefert Hochzahl (String) einer Variablen bzw Gewichtstring (zum Sortieren) *)
1143 fun get_potStr (Const ("Atools.pow",_) $ Free _ $ Free (str, _)) = str
1144 | get_potStr (Const ("Atools.pow",_) $ Free _ $ _ ) = "|||" (* gross gewichtet *)
1145 | get_potStr (Free (str, _)) = "---" (* keine Hochzahl --> kleinst gewichtet *)
1146 | get_potStr t = "||||||"; (* gross gewichtet; für Brüch ect. *)
1148 raise error("get_potStr: called with t= "^(term2str t));*)
1150 (* Umgekehrte string_ord *)
1151 val string_ord_rev = rev_order o string_ord;
1153 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen)
1154 innerhalb eines Monomes:
1155 - zuerst lexikographisch nach Variablenname
1156 - wenn gleich: nach steigender Potenz *)
1157 fun var_ord (a,b: term) = prod_ord string_ord string_ord
1158 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
1160 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen);
1161 verwendet zum Sortieren von Monomen mittels Gesamtgradordnung:
1162 - zuerst lexikographisch nach Variablenname
1163 - wenn gleich: nach sinkender Potenz*)
1164 fun var_ord_revPow (a,b: term) = prod_ord string_ord string_ord_rev
1165 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
1168 (* Ordnet ein Liste von Variablen (und Potenzen) lexikographisch *)
1169 val sort_varList = sort var_ord;
1171 (* Entfernet aeussersten Operator (Wurzel) aus einem Term und schreibt
1172 Argumente in eine Liste *)
1173 fun args u : term list =
1174 let fun stripc (f$t, ts) = stripc (f, t::ts)
1175 | stripc (t as Free _, ts) = (t::ts)
1176 | stripc (_, ts) = ts
1177 in stripc (u, []) end;
1179 (* liefert True, falls der Term (Liste von Termen) nur Zahlen
1180 (keine Variablen) enthaelt *)
1181 fun filter_num [] = true
1182 | filter_num [Free x] = if (is_num (Free x)) then true
1184 | filter_num ((Free _)::_) = false
1186 (filter_num o (filter_out is_num) o flat o (map args)) ts;
1188 (* liefert True, falls der Term nur Zahlen (keine Variablen) enthaelt
1189 dh. er ist ein numerischer Wert und entspricht einem Koeffizienten *)
1190 fun is_nums t = filter_num [t];
1192 (* Berechnet den Gesamtgrad eines Monoms *)
1194 fun counter (n, []) = n
1195 | counter (n, x :: xs) =
1200 (Const ("Atools.pow", _) $ Free (str_b, _) $ Free (str_h, T)) =>
1201 if (is_nums (Free (str_h, T))) then
1202 counter (n + (the (int_of_str str_h)), xs)
1203 else counter (n + 1000, xs) (*FIXME.MG?!*)
1204 | (Const ("Atools.pow", _) $ Free (str_b, _) $ _ ) =>
1205 counter (n + 1000, xs) (*FIXME.MG?!*)
1206 | (Free (str, _)) => counter (n + 1, xs)
1207 (*| _ => raise error("monom_degree: called with factor: "^(term2str x)))*)
1208 | _ => counter (n + 10000, xs)) (*FIXME.MG?! ... Brüche ect.*)
1210 fun monom_degree l = counter (0, l)
1213 (* wie Ordnung dict_ord (lexicographische Ordnung zweier Listen, mit Vergleich
1214 der Listen-Elemente mit elem_ord) - Elemente die Bedingung cond erfuellen,
1215 werden jedoch dabei ignoriert (uebersprungen) *)
1216 fun dict_cond_ord _ _ ([], []) = EQUAL
1217 | dict_cond_ord _ _ ([], _ :: _) = LESS
1218 | dict_cond_ord _ _ (_ :: _, []) = GREATER
1219 | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
1220 (case (cond x, cond y) of
1221 (false, false) => (case elem_ord (x, y) of
1222 EQUAL => dict_cond_ord elem_ord cond (xs, ys)
1224 | (false, true) => dict_cond_ord elem_ord cond (x :: xs, ys)
1225 | (true, false) => dict_cond_ord elem_ord cond (xs, y :: ys)
1226 | (true, true) => dict_cond_ord elem_ord cond (xs, ys) );
1228 (* Gesamtgradordnung zum Vergleich von Monomen (Liste von Variablen/Potenzen):
1229 zuerst nach Gesamtgrad, bei gleichem Gesamtgrad lexikographisch ordnen -
1230 dabei werden Koeffizienten ignoriert (2*3*a^^^2*4*b gilt wie a^^^2*b) *)
1231 fun degree_ord (xs, ys) =
1232 prod_ord int_ord (dict_cond_ord var_ord_revPow is_nums)
1233 ((monom_degree xs, xs), (monom_degree ys, ys));
1235 fun hd_str str = substring (str, 0, 1);
1236 fun tl_str str = substring (str, 1, (size str) - 1);
1238 (* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
1239 fun get_koeff_of_mon [] = raise error("get_koeff_of_mon: called with l = []")
1240 | get_koeff_of_mon (l as x::xs) = if is_nums x then SOME x
1243 (* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
1244 fun koeff2ordStr (SOME x) = (case x of
1246 if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
1248 | _ => "aaa") (* "num.Ausdruck" --> gross *)
1249 | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
1251 (* Order zum Vergleich von Koeffizienten (strings):
1252 "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
1253 fun compare_koeff_ord (xs, ys) =
1254 string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
1255 (koeff2ordStr o get_koeff_of_mon) ys);
1257 (* Gesamtgradordnung degree_ord + Ordnen nach Koeffizienten falls EQUAL *)
1258 fun koeff_degree_ord (xs, ys) =
1259 prod_ord degree_ord compare_koeff_ord ((xs, xs), (ys, ys));
1261 (* Ordnet ein Liste von Monomen (Monom = Liste von Variablen) mittels
1262 Gesamtgradordnung *)
1263 val sort_monList = sort koeff_degree_ord;
1265 (* Alternativ zu degree_ord koennte auch die viel einfachere und
1266 kuerzere Ordnung simple_ord verwendet werden - ist aber nicht
1267 fuer unsere Zwecke geeignet!
1269 fun simple_ord (al,bl: term list) = dict_ord string_ord
1270 (map get_basStr al, map get_basStr bl);
1272 val sort_monList = sort simple_ord; *)
1274 (* aus 2 Variablen wird eine Summe bzw ein Produkt erzeugt
1275 (mit gewuenschtem Typen T) *)
1276 fun plus T = Const ("op +", [T,T] ---> T);
1277 fun mult T = Const ("op *", [T,T] ---> T);
1278 fun binop op_ t1 t2 = op_ $ t1 $ t2;
1279 fun create_prod T (a,b) = binop (mult T) a b;
1280 fun create_sum T (a,b) = binop (plus T) a b;
1282 (* löscht letztes Element einer Liste *)
1283 fun drop_last l = take ((length l)-1,l);
1285 (* Liste von Variablen --> Monom *)
1286 fun create_monom T vl = foldr (create_prod T) (drop_last vl, last_elem vl);
1288 foldr bewirkt rechtslastige Klammerung des Monoms - ist notwendig, damit zwei
1289 gleiche Monome zusammengefasst werden können (collect_numerals)!
1290 zB: 2*(x*(y*z)) + 3*(x*(y*z)) --> (2+3)*(x*(y*z))*)
1292 (* Liste von Monomen --> Polynom *)
1293 fun create_polynom T ml = foldl (create_sum T) (hd ml, tl ml);
1295 foldl bewirkt linkslastige Klammerung des Polynoms (der Summanten) -
1296 bessere Darstellung, da keine Klammern sichtbar!
1297 (und discard_parentheses in make_polynomial hat weniger zu tun) *)
1299 (* sorts the variables (faktors) of an expanded polynomial lexicographical *)
1300 fun sort_variables t =
1302 val ll = map monom2list (poly2list t);
1303 val lls = map sort_varList ll;
1305 val ls = map (create_monom T) lls;
1306 in create_polynom T ls end;
1308 (* sorts the monoms of an expanded and variable-sorted polynomial
1312 val ll = map monom2list (poly2list t);
1313 val lls = sort_monList ll;
1315 val ls = map (create_monom T) lls;
1316 in create_polynom T ls end;
1318 (* auch Klammerung muss übereinstimmen;
1319 sort_variables klammert Produkte rechtslastig*)
1320 fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
1322 fun eval_is_multUnordered (thmid:string) _
1323 (t as (Const("Poly.is'_multUnordered", _) $ arg)) thy =
1324 if is_multUnordered arg
1325 then SOME (mk_thmid thmid ""
1326 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1327 Trueprop $ (mk_equality (t, HOLogic.true_const)))
1328 else SOME (mk_thmid thmid ""
1329 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1330 Trueprop $ (mk_equality (t, HOLogic.false_const)))
1331 | eval_is_multUnordered _ _ _ _ = NONE;
1334 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
1335 []:(rule * (term * term list)) list;
1336 fun init_state (_:term) = e_rrlsstate;
1337 fun locate_rule (_:rule list list) (_:term) (_:rule) =
1338 ([]:(rule * (term * term list)) list);
1339 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
1340 fun normal_form t = SOME (sort_variables t,[]:term list);
1343 Rrls {id = "order_mult_",
1345 [([(term_of o the o (parse thy)) "p is_multUnordered"],
1346 parse_patt thy "?p" )],
1347 rew_ord = ("dummy_ord", dummy_ord),
1348 erls = append_rls "e_rls-is_multUnordered" e_rls(*MG: poly_erls*)
1349 [Calc ("Poly.is'_multUnordered",
1350 eval_is_multUnordered "")],
1351 calc = [("PLUS" , ("op +" , eval_binop "#add_")),
1352 ("TIMES" , ("op *" , eval_binop "#mult_")),
1353 ("DIVIDE", ("HOL.divide", eval_cancel "#divide_")),
1354 ("POWER" , ("Atools.pow", eval_binop "#power_"))],
1355 scr=Rfuns {init_state = init_state,
1356 normal_form = normal_form,
1357 locate_rule = locate_rule,
1358 next_rule = next_rule,
1359 attach_form = attach_form}};
1360 val order_mult_rls_ =
1361 Rls{id = "order_mult_rls_", preconds = [],
1362 rew_ord = ("dummy_ord", dummy_ord),
1363 erls = e_rls,srls = Erls,
1365 rules = [Rls_ order_mult_
1366 ], scr = EmptyScr}:rls;
1368 fun is_addUnordered t = ((is_polyexp t) andalso not (t = sort_monoms t));
1371 (*("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))*)
1372 fun eval_is_addUnordered (thmid:string) _
1373 (t as (Const("Poly.is'_addUnordered", _) $ arg)) thy =
1374 if is_addUnordered arg
1375 then SOME (mk_thmid thmid ""
1376 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1377 Trueprop $ (mk_equality (t, HOLogic.true_const)))
1378 else SOME (mk_thmid thmid ""
1379 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1380 Trueprop $ (mk_equality (t, HOLogic.false_const)))
1381 | eval_is_addUnordered _ _ _ _ = NONE;
1383 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
1384 []:(rule * (term * term list)) list;
1385 fun init_state (_:term) = e_rrlsstate;
1386 fun locate_rule (_:rule list list) (_:term) (_:rule) =
1387 ([]:(rule * (term * term list)) list);
1388 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
1389 fun normal_form t = SOME (sort_monoms t,[]:term list);
1392 Rrls {id = "order_add_",
1393 prepat = (*WN.18.6.03 Preconditions und Pattern,
1394 die beide passen muessen, damit das Rrls angewandt wird*)
1395 [([(term_of o the o (parse thy)) "p is_addUnordered"],
1397 (*WN.18.6.03 also KEIN pattern, dieses erzeugt nur das Environment
1398 fuer die Evaluation der Precondition "p is_addUnordered"*))],
1399 rew_ord = ("dummy_ord", dummy_ord),
1400 erls = append_rls "e_rls-is_addUnordered" e_rls(*MG: poly_erls*)
1401 [Calc ("Poly.is'_addUnordered", eval_is_addUnordered "")
1402 (*WN.18.6.03 definiert in thy,
1403 evaluiert prepat*)],
1404 calc = [("PLUS" ,("op +" ,eval_binop "#add_")),
1405 ("TIMES" ,("op *" ,eval_binop "#mult_")),
1406 ("DIVIDE" ,("HOL.divide" ,eval_cancel "#divide_")),
1407 ("POWER" ,("Atools.pow" ,eval_binop "#power_"))],
1409 scr=Rfuns {init_state = init_state,
1410 normal_form = normal_form,
1411 locate_rule = locate_rule,
1412 next_rule = next_rule,
1413 attach_form = attach_form}};
1415 val order_add_rls_ =
1416 Rls{id = "order_add_rls_", preconds = [],
1417 rew_ord = ("dummy_ord", dummy_ord),
1418 erls = e_rls,srls = Erls,
1421 rules = [Rls_ order_add_
1422 ], scr = EmptyScr}:rls;
1424 (*. see MG-DA.p.52ff .*)
1425 val make_polynomial(*MG.03, overwrites version from above,
1426 previously 'make_polynomial_'*) =
1427 Seq {id = "make_polynomial", preconds = []:term list,
1428 rew_ord = ("dummy_ord", dummy_ord),
1429 erls = Atools_erls, srls = Erls,calc = [],
1430 rules = [Rls_ discard_minus_,
1432 Calc ("op *", eval_binop "#mult_"),
1433 Rls_ order_mult_rls_,
1434 Rls_ simplify_power_,
1435 Rls_ calc_add_mult_pow_,
1436 Rls_ reduce_012_mult_,
1437 Rls_ order_add_rls_,
1438 Rls_ collect_numerals_,
1440 Rls_ discard_parentheses_
1444 val norm_Poly(*=make_polynomial*) =
1445 Seq {id = "norm_Poly", preconds = []:term list,
1446 rew_ord = ("dummy_ord", dummy_ord),
1447 erls = Atools_erls, srls = Erls, calc = [],
1448 rules = [Rls_ discard_minus_,
1450 Calc ("op *", eval_binop "#mult_"),
1451 Rls_ order_mult_rls_,
1452 Rls_ simplify_power_,
1453 Rls_ calc_add_mult_pow_,
1454 Rls_ reduce_012_mult_,
1455 Rls_ order_add_rls_,
1456 Rls_ collect_numerals_,
1458 Rls_ discard_parentheses_
1463 (* MG:03 Like make_polynomial_ but without Rls_ discard_parentheses_
1464 and expand_poly_rat_ instead of expand_poly_, see MG-DA.p.56ff*)
1465 (* MG necessary for termination of norm_Rational(*_mg*) in Rational.ML*)
1466 val make_rat_poly_with_parentheses =
1467 Seq{id = "make_rat_poly_with_parentheses", preconds = []:term list,
1468 rew_ord = ("dummy_ord", dummy_ord),
1469 erls = Atools_erls, srls = Erls, calc = [],
1470 rules = [Rls_ discard_minus_,
1471 Rls_ expand_poly_rat_,(*ignors rationals*)
1472 Calc ("op *", eval_binop "#mult_"),
1473 Rls_ order_mult_rls_,
1474 Rls_ simplify_power_,
1475 Rls_ calc_add_mult_pow_,
1476 Rls_ reduce_012_mult_,
1477 Rls_ order_add_rls_,
1478 Rls_ collect_numerals_,
1480 (*Rls_ discard_parentheses_ *)
1485 (*.a minimal ruleset for reverse rewriting of factions [2];
1486 compare expand_binoms.*)
1488 Seq{id = "reverse_rewriting", preconds = [], rew_ord = ("termlessI",termlessI),
1489 erls = Atools_erls, srls = Erls,
1490 calc = [(*("PLUS" , ("op +", eval_binop "#add_")),
1491 ("TIMES" , ("op *", eval_binop "#mult_")),
1492 ("POWER", ("Atools.pow", eval_binop "#power_"))*)
1494 rules = [Thm ("real_plus_binom_times" ,num_str @{thm real_plus_binom_times}),
1495 (*"(a + b)*(a + b) = a ^ 2 + 2 * a * b + b ^ 2*)
1496 Thm ("real_plus_binom_times1" ,num_str @{thm real_plus_binom_times1}),
1497 (*"(a + 1*b)*(a + -1*b) = a^^^2 + -1*b^^^2"*)
1498 Thm ("real_plus_binom_times2" ,num_str @{thm real_plus_binom_times2}),
1499 (*"(a + -1*b)*(a + 1*b) = a^^^2 + -1*b^^^2"*)
1501 Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
1503 Thm ("left_distrib" ,num_str @{thm left_distrib}),
1504 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1505 Thm ("right_distrib",num_str @{thm right_distrib}),
1506 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1508 Thm ("real_mult_assoc", num_str @{thm real_mult_assoc}),
1509 (*"?z1.1 * ?z2.1 * ?z3. =1 ?z1.1 * (?z2.1 * ?z3.1)"*)
1510 Rls_ order_mult_rls_,
1511 (*Rls_ order_add_rls_,*)
1513 Calc ("op +", eval_binop "#add_"),
1514 Calc ("op *", eval_binop "#mult_"),
1515 Calc ("Atools.pow", eval_binop "#power_"),
1517 Thm ("sym_realpow_twoI",
1518 num_str (@{thm realpow_twoI} RS @{thm sym})),
1519 (*"r1 * r1 = r1 ^^^ 2"*)
1520 Thm ("sym_real_mult_2",
1521 num_str (@{thm real_mult_2} RS @{thm sym})),
1522 (*"z1 + z1 = 2 * z1"*)
1523 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),
1524 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1526 Thm ("real_num_collect",num_str @{thm real_num_collect}),
1527 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
1528 Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
1529 (*"[| l is_const; m is_const |] ==>
1530 l * n + (m * n + k) = (l + m) * n + k"*)
1531 Thm ("real_one_collect",num_str @{thm real_one_collect}),
1532 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1533 Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}),
1534 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1536 Thm ("realpow_multI", num_str @{thm realpow_multI}),
1537 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
1539 Calc ("op +", eval_binop "#add_"),
1540 Calc ("op *", eval_binop "#mult_"),
1541 Calc ("Atools.pow", eval_binop "#power_"),
1543 Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
1544 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),(*"0 * z = 0"*)
1545 Thm ("add_0_left",num_str @{thm add_0_left})(*0 + z = z*)
1547 (*Rls_ order_add_rls_*)
1550 scr = EmptyScr}:rls;
1553 overwritelthy @{theory} (!ruleset',
1554 [("norm_Poly", prep_rls norm_Poly),
1555 ("Poly_erls",Poly_erls)(*FIXXXME:del with rls.rls'*),
1556 ("expand", prep_rls expand),
1557 ("expand_poly", prep_rls expand_poly),
1558 ("simplify_power", prep_rls simplify_power),
1559 ("order_add_mult", prep_rls order_add_mult),
1560 ("collect_numerals", prep_rls collect_numerals),
1561 ("collect_numerals_", prep_rls collect_numerals_),
1562 ("reduce_012", prep_rls reduce_012),
1563 ("discard_parentheses", prep_rls discard_parentheses),
1564 ("make_polynomial", prep_rls make_polynomial),
1565 ("expand_binoms", prep_rls expand_binoms),
1566 ("rev_rew_p", prep_rls rev_rew_p),
1567 ("discard_minus_", prep_rls discard_minus_),
1568 ("expand_poly_", prep_rls expand_poly_),
1569 ("expand_poly_rat_", prep_rls expand_poly_rat_),
1570 ("simplify_power_", prep_rls simplify_power_),
1571 ("calc_add_mult_pow_", prep_rls calc_add_mult_pow_),
1572 ("reduce_012_mult_", prep_rls reduce_012_mult_),
1573 ("reduce_012_", prep_rls reduce_012_),
1574 ("discard_parentheses_",prep_rls discard_parentheses_),
1575 ("order_mult_rls_", prep_rls order_mult_rls_),
1576 ("order_add_rls_", prep_rls order_add_rls_),
1577 ("make_rat_poly_with_parentheses",
1578 prep_rls make_rat_poly_with_parentheses)
1581 calclist':= overwritel (!calclist',
1582 [("is_polyrat_in", ("Poly.is'_polyrat'_in",
1583 eval_is_polyrat_in "#eval_is_polyrat_in")),
1584 ("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in "")),
1585 ("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in "")),
1586 ("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in "")),
1587 ("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp "")),
1588 ("is_multUnordered", ("Poly.is'_multUnordered", eval_is_multUnordered"")),
1589 ("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))
1592 val ------------------------------------------------------ = "11111";
1597 (prep_pbt thy "pbl_simp_poly" [] e_pblID
1598 (["polynomial","simplification"],
1599 [("#Given" ,["TERM t_t"]),
1600 ("#Where" ,["t_t is_polyexp"]),
1601 ("#Find" ,["normalform n_n"])
1603 append_rls "e_rls" e_rls [(*for preds in where_*)
1604 Calc ("Poly.is'_polyexp", eval_is_polyexp "")],
1605 SOME "Simplify t_t",
1606 [["simplification","for_polynomials"]]));
1611 (prep_met thy "met_simp_poly" [] e_metID
1612 (["simplification","for_polynomials"],
1613 [("#Given" ,["TERM t_t"]),
1614 ("#Where" ,["t_t is_polyexp"]),
1615 ("#Find" ,["normalform n_n"])
1617 {rew_ord'="tless_true",
1621 prls = append_rls "simplification_for_polynomials_prls" e_rls
1622 [(*for preds in where_*)
1623 Calc ("Poly.is'_polyexp",eval_is_polyexp"")],
1624 crls = e_rls, nrls = norm_Poly},
1625 "Script SimplifyScript (t_t::real) = " ^
1626 " ((Rewrite_Set norm_Poly False) t_t)"