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)
173 (* is_polyrat_in becomes true, if no bdv is in the denominator of a fraction*)
174 fun is_polyrat_in t v =
175 let fun coeff_in c v = member op = (vars c) v;
176 fun finddivide (_ $ _ $ _ $ _) v = raise error("is_polyrat_in:")
177 (* at the moment there is no term like this, but ....*)
178 | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v =
180 | finddivide (_ $ t1 $ t2) v =
181 (finddivide t1 v) orelse (finddivide t2 v)
182 | finddivide (_ $ t1) v = (finddivide t1 v)
183 | finddivide _ _ = false;
184 in finddivide t v end;
186 fun eval_is_polyrat_in _ _(p as (Const ("Poly.is'_polyrat'_in",_) $ t $ v)) _ =
188 then SOME ((term2str p) ^ " = True",
189 Trueprop $ (mk_equality (p, HOLogic.true_const)))
190 else SOME ((term2str p) ^ " = True",
191 Trueprop $ (mk_equality (p, HOLogic.false_const)))
192 | eval_is_polyrat_in _ _ _ _ = ((*writeln"### no matches";*) NONE);
195 (*.a 'c is coefficient of v' if v does NOT occur in c.*)
196 fun coeff_in c v = not (member op = (vars c) v);
197 (* FIXME.WN100826 shift this into test--------------
198 val v = (term_of o the o (parse thy)) "x";
199 val t = (term_of o the o (parse thy)) "1";
201 (*val it = true : bool*)
202 val t = (term_of o the o (parse thy)) "a*b+c";
204 (*val it = true : bool*)
205 val t = (term_of o the o (parse thy)) "a*x+c";
207 (*val it = false : bool*)
208 ----------------------------------------------------*)
209 (*. a 'monomial t in variable v' is a term t with
210 either (1) v NOT existent in t, or (2) v contained in t,
212 if (2) then v is a factor on the very right, ev. with exponent.*)
213 fun factor_right_deg (*case 2*)
214 (t as Const ("op *",_) $ t1 $
215 (Const ("Atools.pow",_) $ vv $ Free (d,_))) v =
216 if ((vv = v) andalso (coeff_in t1 v)) then SOME (int_of_str' d) else NONE
217 | factor_right_deg (t as Const ("Atools.pow",_) $ vv $ Free (d,_)) v =
218 if (vv = v) then SOME (int_of_str' d) else NONE
219 | factor_right_deg (t as Const ("op *",_) $ t1 $ vv) v =
220 if ((vv = v) andalso (coeff_in t1 v))then SOME 1 else NONE
221 | factor_right_deg vv v =
222 if (vv = v) then SOME 1 else NONE;
223 fun mono_deg_in m v =
224 if coeff_in m v then (*case 1*) SOME 0
225 else factor_right_deg m v;
226 (* FIXME.WN100826 shift this into test-----------------------------
227 val v = (term_of o the o (parse thy)) "x";
228 val t = (term_of o the o (parse thy)) "(a*b+c)*x^^^7";
231 val t = (term_of o the o (parse thy)) "x^^^7";
234 val t = (term_of o the o (parse thy)) "(a*b+c)*x";
237 val t = (term_of o the o (parse thy)) "(a*b+x)*x";
240 val t = (term_of o the o (parse thy)) "x";
243 val t = (term_of o the o (parse thy)) "(a*b+c)";
246 val t = (term_of o the o (parse thy)) "ab - (a*b)*x";
249 ------------------------------------------------------------------*)
250 fun expand_deg_in t v =
251 let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
252 (case mono_deg_in t2 v of (* $ is left associative*)
253 SOME d' => edi d' d' t1
255 | edi ~1 ~1 (Const ("op -",_) $ t1 $ t2) =
256 (case mono_deg_in t2 v of
257 SOME d' => edi d' d' t1
259 | edi d dmax (Const ("op -",_) $ t1 $ t2) =
260 (case mono_deg_in t2 v of
261 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
262 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
263 then edi d' dmax t1 else NONE
265 | edi d dmax (Const ("op +",_) $ t1 $ t2) =
266 (case mono_deg_in t2 v of
267 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
268 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
269 then edi d' dmax t1 else NONE
271 | edi ~1 ~1 t = (case mono_deg_in t v of
274 | edi d dmax t = (*basecase last*)
275 (case mono_deg_in t v of
276 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
277 then SOME dmax else NONE
280 (* FIXME.WN100826 shift this into test-----------------------------
281 val v = (term_of o the o (parse thy)) "x";
282 val t = (term_of o the o (parse thy)) "a+b";
285 val t = (term_of o the o (parse thy)) "(a+b)*x";
288 val t = (term_of o the o (parse thy)) "a*b - (a+b)*x";
291 val t = (term_of o the o (parse thy)) "a*b + (a-b)*x";
294 val t = (term_of o the o (parse thy)) "a*b + (a+b)*x + x^^^2";
296 -------------------------------------------------------------------*)
297 fun poly_deg_in t v =
298 let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
299 (case mono_deg_in t2 v of (* $ is left associative*)
300 SOME d' => edi d' d' t1
302 | edi d dmax (Const ("op +",_) $ t1 $ t2) =
303 (case mono_deg_in t2 v of
304 (*RL orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4 +x*)
305 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
306 then edi d' dmax t1 else NONE
308 | edi ~1 ~1 t = (case mono_deg_in t v of
311 | edi d dmax t = (*basecase last*)
312 (case mono_deg_in t v of
313 SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))
314 then SOME dmax else NONE
319 fun is_expanded_in t v =
320 case expand_deg_in t v of SOME _ => true | NONE => false;
322 case poly_deg_in t v of SOME _ => true | NONE => false;
323 fun has_degree_in t v =
324 case expand_deg_in t v of SOME d => d | NONE => ~1;
326 (* FIXME.WN100826 shift this into test-----------------------------
327 val v = (term_of o the o (parse thy)) "x";
328 val t = (term_of o the o (parse thy)) "a*b - (a+b)*x + x^^^2";
331 val t = (term_of o the o (parse thy)) "-8 - 2*x + x^^^2";
334 val t = (term_of o the o (parse thy)) "6 + 13*x + 6*x^^^2";
337 -------------------------------------------------------------------*)
339 (*("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in ""))*)
340 fun eval_is_expanded_in _ _
341 (p as (Const ("Poly.is'_expanded'_in",_) $ t $ v)) _ =
342 if is_expanded_in t v
343 then SOME ((term2str p) ^ " = True",
344 Trueprop $ (mk_equality (p, HOLogic.true_const)))
345 else SOME ((term2str p) ^ " = True",
346 Trueprop $ (mk_equality (p, HOLogic.false_const)))
347 | eval_is_expanded_in _ _ _ _ = NONE;
349 val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) is_expanded_in x";
350 val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
351 (*val id = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
353 (*val it = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
356 (*("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in ""))*)
357 fun eval_is_poly_in _ _
358 (p as (Const ("Poly.is'_poly'_in",_) $ t $ v)) _ =
360 then SOME ((term2str p) ^ " = True",
361 Trueprop $ (mk_equality (p, HOLogic.true_const)))
362 else SOME ((term2str p) ^ " = True",
363 Trueprop $ (mk_equality (p, HOLogic.false_const)))
364 | eval_is_poly_in _ _ _ _ = NONE;
366 val t = (term_of o the o (parse thy)) "(8 + 2*x + x^^^2) is_poly_in x";
367 val SOME (id, t') = eval_is_poly_in 0 0 t 0;
368 (*val id = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
370 (*val it = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
373 (*("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in ""))*)
374 fun eval_has_degree_in _ _
375 (p as (Const ("Poly.has'_degree'_in",_) $ t $ v)) _ =
376 let val d = has_degree_in t v
377 val d' = term_of_num HOLogic.realT d
378 in SOME ((term2str p) ^ " = " ^ (string_of_int d),
379 Trueprop $ (mk_equality (p, d')))
381 | eval_has_degree_in _ _ _ _ = NONE;
383 > val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) has_degree_in x";
384 > val SOME (id, t') = eval_has_degree_in 0 0 t 0;
385 val id = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
387 val it = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
390 (*.for evaluation of conditions in rewrite rules.*)
392 append_rls "Poly_erls" Atools_erls
393 [ Calc ("op =",eval_equal "#equal_"),
394 Thm ("real_unari_minus",num_str @{real_unari_minus),
395 Calc ("op +",eval_binop "#add_"),
396 Calc ("op -",eval_binop "#sub_"),
397 Calc ("op *",eval_binop "#mult_"),
398 Calc ("Atools.pow" ,eval_binop "#power_")
402 append_rls "poly_crls" Atools_crls
403 [ Calc ("op =",eval_equal "#equal_"),
404 Thm ("real_unari_minus",num_str @{real_unari_minus),
405 Calc ("op +",eval_binop "#add_"),
406 Calc ("op -",eval_binop "#sub_"),
407 Calc ("op *",eval_binop "#mult_"),
408 Calc ("Atools.pow" ,eval_binop "#power_")
411 local (*. for make_polynomial .*)
413 open Term; (* for type order = EQUAL | LESS | GREATER *)
415 fun pr_ord EQUAL = "EQUAL"
416 | pr_ord LESS = "LESS"
417 | pr_ord GREATER = "GREATER";
419 fun dest_hd' (Const (a, T)) = (* ~ term.ML *)
421 "Atools.pow" => ((("|||||||||||||", 0), T), 0) (*WN greatest string*)
422 | _ => (((a, 0), T), 0))
423 | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
424 | dest_hd' (Var v) = (v, 2)
425 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
426 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
428 fun get_order_pow (t $ (Free(order,_))) = (* RL FIXXXME:geht zufaellig?WN*)
429 (case int_of_str (order) of
432 | get_order_pow _ = 0;
434 fun size_of_term' (Const(str,_) $ t) =
435 if "Atools.pow"= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
436 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
437 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
438 | size_of_term' _ = 1;
440 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
441 (case term_ord' pr thy (t, u) of EQUAL => typ_ord (T, U) | ord => ord)
442 | term_ord' pr thy (t, u) =
445 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
446 val _=writeln("t= f@ts= \""^
447 ((Syntax.string_of_term (thy2ctxt thy)) f)^"\" @ \"["^
448 (commas(map(Syntax.string_of_term (thy2ctxt thy))ts))^"]\"");
449 val _=writeln("u= g@us= \""^
450 ((Syntax.string_of_term (thy2ctxt thy)) g)^"\" @ \"["^
451 (commas(map(Syntax.string_of_term (thy2ctxt thy))us))^"]\"");
452 val _=writeln("size_of_term(t,u)= ("^
453 (string_of_int(size_of_term' t))^", "^
454 (string_of_int(size_of_term' u))^")");
455 val _=writeln("hd_ord(f,g) = "^((pr_ord o hd_ord)(f,g)));
456 val _=writeln("terms_ord(ts,us) = "^
457 ((pr_ord o terms_ord str false)(ts,us)));
458 val _=writeln("-------");
461 case int_ord (size_of_term' t, size_of_term' u) of
463 let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
464 (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us)
468 and hd_ord (f, g) = (* ~ term.ML *)
469 prod_ord (prod_ord indexname_ord typ_ord) int_ord (dest_hd' f, dest_hd' g)
470 and terms_ord str pr (ts, us) =
471 list_ord (term_ord' pr (assoc_thy "Isac.thy"))(ts, us);
474 fun ord_make_polynomial (pr:bool) thy (_:subst) tu =
475 (term_ord' pr thy(***) tu = LESS );
480 rew_ord' := overwritel (!rew_ord',
481 [("termlessI", termlessI),
482 ("ord_make_polynomial", ord_make_polynomial false thy)
487 Rls{id = "expand", preconds = [],
488 rew_ord = ("dummy_ord", dummy_ord),
489 erls = e_rls,srls = Erls,
492 rules = [Thm ("left_distrib" ,num_str @{thm left_distrib}),
493 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
494 Thm ("left_distrib2",num_str @{thm left_distrib}2)
495 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
496 ], scr = EmptyScr}:rls;
498 (*----------------- Begin: rulesets for make_polynomial_ -----------------
499 'rlsIDs' redefined by MG as 'rlsIDs_'
503 Rls{id = "discard_minus_", preconds = [],
504 rew_ord = ("dummy_ord", dummy_ord),
505 erls = e_rls,srls = Erls,
508 rules = [Thm ("real_diff_minus",num_str @{real_diff_minus),
509 (*"a - b = a + -1 * b"*)
510 Thm ("sym_real_mult_minus1",num_str @{(real_mult_minus1 RS 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 @{real_plus_binom_pow4),
520 (*"(a + b)^^^4 = ... "*)
521 Thm ("real_plus_binom_pow5",num_str @{real_plus_binom_pow5),
522 (*"(a + b)^^^5 = ... "*)
523 Thm ("real_plus_binom_pow3",num_str @{real_plus_binom_pow3),
524 (*"(a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
526 (*WN071229 changed/removed for Schaerding -----vvv*)
527 (*Thm ("real_plus_binom_pow2",num_str @{real_plus_binom_pow2),*)
528 (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
529 Thm ("real_plus_binom_pow2",num_str @{real_plus_binom_pow2),
530 (*"(a + b)^^^2 = (a + b) * (a + b)"*)
531 (*Thm ("real_plus_minus_binom1_p_p",
532 num_str @{real_plus_minus_binom1_p_p),*)
533 (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
534 (*Thm ("real_plus_minus_binom2_p_p",
535 num_str @{real_plus_minus_binom2_p_p),*)
536 (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
537 (*WN071229 changed/removed for Schaerding -----^^^*)
539 Thm ("left_distrib" ,num_str @{thm left_distrib}),
540 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
541 Thm ("left_distrib2",num_str @{thm left_distrib}2),
542 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
544 Thm ("realpow_multI", num_str @{realpow_multI),
545 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
546 Thm ("realpow_pow",num_str @{realpow_pow)
547 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
548 ], scr = EmptyScr}:rls;
550 (*.the expression contains + - * ^ only ?
551 this is weaker than 'is_polynomial' !.*)
552 fun is_polyexp (Free _) = true
553 | is_polyexp (Const ("op +",_) $ Free _ $ Free _) = true
554 | is_polyexp (Const ("op -",_) $ Free _ $ Free _) = true
555 | is_polyexp (Const ("op *",_) $ Free _ $ Free _) = true
556 | is_polyexp (Const ("Atools.pow",_) $ Free _ $ Free _) = true
557 | is_polyexp (Const ("op +",_) $ t1 $ t2) =
558 ((is_polyexp t1) andalso (is_polyexp t2))
559 | is_polyexp (Const ("op -",_) $ t1 $ t2) =
560 ((is_polyexp t1) andalso (is_polyexp t2))
561 | is_polyexp (Const ("op *",_) $ t1 $ t2) =
562 ((is_polyexp t1) andalso (is_polyexp t2))
563 | is_polyexp (Const ("Atools.pow",_) $ t1 $ t2) =
564 ((is_polyexp t1) andalso (is_polyexp t2))
565 | is_polyexp _ = false;
567 (*("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp ""))*)
568 fun eval_is_polyexp (thmid:string) _
569 (t as (Const("Poly.is'_polyexp", _) $ arg)) thy =
571 then SOME (mk_thmid thmid ""
572 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
573 Trueprop $ (mk_equality (t, HOLogic.true_const)))
574 else SOME (mk_thmid thmid ""
575 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
576 Trueprop $ (mk_equality (t, HOLogic.false_const)))
577 | eval_is_polyexp _ _ _ _ = NONE;
579 val expand_poly_rat_ =
580 Rls{id = "expand_poly_rat_", preconds = [],
581 rew_ord = ("dummy_ord", dummy_ord),
582 erls = append_rls "e_rls-is_polyexp" e_rls
583 [Calc ("Poly.is'_polyexp", eval_is_polyexp "")
589 [Thm ("real_plus_binom_pow4_poly", num_str @{real_plus_binom_pow4_poly),
590 (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^4 = ... "*)
591 Thm ("real_plus_binom_pow5_poly", num_str @{real_plus_binom_pow5_poly),
592 (*"[| a is_polyexp; b is_polyexp |] ==> (a + b)^^^5 = ... "*)
593 Thm ("real_plus_binom_pow2_poly",num_str @{real_plus_binom_pow2_poly),
594 (*"[| a is_polyexp; b is_polyexp |] ==>
595 (a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
596 Thm ("real_plus_binom_pow3_poly",num_str @{real_plus_binom_pow3_poly),
597 (*"[| a is_polyexp; b is_polyexp |] ==>
598 (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3" *)
599 Thm ("real_plus_minus_binom1_p_p",num_str @{real_plus_minus_binom1_p_p),
600 (*"(a + b)*(a + -1 * b) = a^^^2 + -1*b^^^2"*)
601 Thm ("real_plus_minus_binom2_p_p",num_str @{real_plus_minus_binom2_p_p),
602 (*"(a + -1 * b)*(a + b) = a^^^2 + -1*b^^^2"*)
604 Thm ("left_distrib_poly" ,num_str @{thm left_distrib}_poly),
605 (*"w is_polyexp ==> (z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
606 Thm("left_distrib2_poly",num_str @{thm left_distrib}2_poly),
607 (*"w is_polyexp ==> w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
609 Thm ("realpow_multI_poly", num_str @{realpow_multI_poly),
610 (*"[| r is_polyexp; s is_polyexp |] ==>
611 (r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
612 Thm ("realpow_pow",num_str @{realpow_pow)
613 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
614 ], scr = EmptyScr}:rls;
616 val simplify_power_ =
617 Rls{id = "simplify_power_", preconds = [],
618 rew_ord = ("dummy_ord", dummy_ord),
619 erls = e_rls, srls = Erls,
622 rules = [(*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
623 a*(a*a) --> a*a^^^2 und nicht a*(a*a) --> a^^^2*a *)
624 Thm ("sym_realpow_twoI",num_str @{(realpow_twoI RS sym)),
625 (*"r * r = r ^^^ 2"*)
626 Thm ("realpow_twoI_assoc_l",num_str @{realpow_twoI_assoc_l),
627 (*"r * (r * s) = r ^^^ 2 * s"*)
629 Thm ("realpow_plus_1",num_str @{realpow_plus_1),
630 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
631 Thm ("realpow_plus_1_assoc_l", num_str @{realpow_plus_1_assoc_l),
632 (*"r * (r ^^^ m * s) = r ^^^ (1 + m) * s"*)
633 (*MG 9.7.03: neues Thm wegen a*(a*(a*b)) --> a^^^2*(a*b) *)
634 Thm ("realpow_plus_1_assoc_l2", num_str @{realpow_plus_1_assoc_l2),
635 (*"r ^^^ m * (r * s) = r ^^^ (1 + m) * s"*)
637 Thm ("sym_realpow_addI",num_str @{(realpow_addI RS sym)),
638 (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
639 Thm ("realpow_addI_assoc_l", num_str @{realpow_addI_assoc_l),
640 (*"r ^^^ n * (r ^^^ m * s) = r ^^^ (n + m) * s"*)
642 (* ist in expand_poly - wird hier aber auch gebraucht, wegen:
643 "r * r = r ^^^ 2" wenn r=a^^^b*)
644 Thm ("realpow_pow",num_str @{realpow_pow)
645 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
646 ], scr = EmptyScr}:rls;
648 val calc_add_mult_pow_ =
649 Rls{id = "calc_add_mult_pow_", preconds = [],
650 rew_ord = ("dummy_ord", dummy_ord),
651 erls = Atools_erls(*erls3.4.03*),srls = Erls,
652 calc = [("PLUS" , ("op +", eval_binop "#add_")),
653 ("TIMES" , ("op *", eval_binop "#mult_")),
654 ("POWER", ("Atools.pow", eval_binop "#power_"))
657 rules = [Calc ("op +", eval_binop "#add_"),
658 Calc ("op *", eval_binop "#mult_"),
659 Calc ("Atools.pow", eval_binop "#power_")
660 ], scr = EmptyScr}:rls;
662 val reduce_012_mult_ =
663 Rls{id = "reduce_012_mult_", preconds = [],
664 rew_ord = ("dummy_ord", dummy_ord),
665 erls = e_rls,srls = Erls,
668 rules = [(* MG: folgende Thm müssen hier stehen bleiben: *)
669 Thm ("mult_1_right",num_str @{thm mult_1_right}),
670 (*"z * 1 = z"*) (*wegen "a * b * b^^^(-1) + a"*)
671 Thm ("realpow_zeroI",num_str @{realpow_zeroI),
672 (*"r ^^^ 0 = 1"*) (*wegen "a*a^^^(-1)*c + b + c"*)
673 Thm ("realpow_oneI",num_str @{realpow_oneI),
675 Thm ("realpow_eq_oneI",num_str @{realpow_eq_oneI)
677 ], scr = EmptyScr}:rls;
679 val collect_numerals_ =
680 Rls{id = "collect_numerals_", preconds = [],
681 rew_ord = ("dummy_ord", dummy_ord),
682 erls = Atools_erls, srls = Erls,
683 calc = [("PLUS" , ("op +", eval_binop "#add_"))
686 [Thm ("real_num_collect",num_str @{real_num_collect),
687 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
688 Thm ("real_num_collect_assoc_r",num_str @{real_num_collect_assoc_r),
689 (*"[| l is_const; m is_const |] ==> \
690 \(k + m * n) + l * n = k + (l + m)*n"*)
691 Thm ("real_one_collect",num_str @{real_one_collect),
692 (*"m is_const ==> n + m * n = (1 + m) * n"*)
693 Thm ("real_one_collect_assoc_r",num_str @{real_one_collect_assoc_r),
694 (*"m is_const ==> (k + n) + m * n = k + (m + 1) * n"*)
696 Calc ("op +", eval_binop "#add_"),
698 (*MG: Reihenfolge der folgenden 2 Thm muss so bleiben, wegen
699 (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
700 Thm ("real_mult_2_assoc_r",num_str @{real_mult_2_assoc_r),
701 (*"(k + z1) + z1 = k + 2 * z1"*)
702 Thm ("sym_real_mult_2",num_str @{(real_mult_2 RS sym))
703 (*"z1 + z1 = 2 * z1"*)
704 ], scr = EmptyScr}:rls;
707 Rls{id = "reduce_012_", preconds = [],
708 rew_ord = ("dummy_ord", dummy_ord),
709 erls = e_rls,srls = Erls,
712 rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),
714 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
716 Thm ("mult_zero_left_right",num_str @{thm mult_zero_left}_right),
718 Thm ("add_0_left",num_str @{thm add_0_left}),
720 Thm ("add_0_right",num_str @{thm add_0_right}),
721 (*"z + 0 = z"*) (*wegen a+b-b --> a+(1-1)*b --> a+0 --> a*)
723 (*Thm ("realpow_oneI",num_str @{realpow_oneI)*)
725 Thm ("divide_zero_left",num_str @{thm divide_zero_left})(*WN060914*)
727 ], scr = EmptyScr}:rls;
729 (*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
730 val discard_parentheses_ =
731 append_rls "discard_parentheses_" e_rls
732 [Thm ("sym_real_mult_assoc", num_str @{(real_mult_assoc RS sym))
733 (*"?z1.1 * (?z2.1 * ?z3.1) = ?z1.1 * ?z2.1 * ?z3.1"*)
734 (*Thm ("sym_real_add_assoc",num_str @{(real_add_assoc RS sym))*)
735 (*"?z1.1 + (?z2.1 + ?z3.1) = ?z1.1 + ?z2.1 + ?z3.1"*)
738 (*----------------- End: rulesets for make_polynomial_ -----------------*)
740 (*MG.0401 ev. for use in rls with ordered rewriting ?
741 val collect_numerals_left =
742 Rls{id = "collect_numerals", preconds = [],
743 rew_ord = ("dummy_ord", dummy_ord),
744 erls = Atools_erls(*erls3.4.03*),srls = Erls,
745 calc = [("PLUS" , ("op +", eval_binop "#add_")),
746 ("TIMES" , ("op *", eval_binop "#mult_")),
747 ("POWER", ("Atools.pow", eval_binop "#power_"))
750 rules = [Thm ("real_num_collect",num_str @{real_num_collect),
751 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
752 Thm ("real_num_collect_assoc",num_str @{real_num_collect_assoc),
753 (*"[| l is_const; m is_const |] ==>
754 l * n + (m * n + k) = (l + m) * n + k"*)
755 Thm ("real_one_collect",num_str @{real_one_collect),
756 (*"m is_const ==> n + m * n = (1 + m) * n"*)
757 Thm ("real_one_collect_assoc",num_str @{real_one_collect_assoc),
758 (*"m is_const ==> n + (m * n + k) = (1 + m) * n + k"*)
760 Calc ("op +", eval_binop "#add_"),
762 (*MG am 2.5.03: 2 Theoreme aus reduce_012 hierher verschoben*)
763 Thm ("sym_real_mult_2",num_str @{(real_mult_2 RS sym)),
764 (*"z1 + z1 = 2 * z1"*)
765 Thm ("real_mult_2_assoc",num_str @{real_mult_2_assoc)
766 (*"z1 + (z1 + k) = 2 * z1 + k"*)
767 ], scr = EmptyScr}:rls;*)
770 Rls{id = "expand_poly", preconds = [],
771 rew_ord = ("dummy_ord", dummy_ord),
772 erls = e_rls,srls = Erls,
775 rules = [Thm ("left_distrib" ,num_str @{thm left_distrib}),
776 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
777 Thm ("left_distrib2",num_str @{thm left_distrib}2),
778 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
779 (*Thm ("left_distrib1",num_str @{thm left_distrib}1),
780 ....... 18.3.03 undefined???*)
782 Thm ("real_plus_binom_pow2",num_str @{real_plus_binom_pow2),
783 (*"(a + b)^^^2 = a^^^2 + 2*a*b + b^^^2"*)
784 Thm ("real_minus_binom_pow2_p",num_str @{real_minus_binom_pow2_p),
785 (*"(a - b)^^^2 = a^^^2 + -2*a*b + b^^^2"*)
786 Thm ("real_plus_minus_binom1_p",
787 num_str @{real_plus_minus_binom1_p),
788 (*"(a + b)*(a - b) = a^^^2 + -1*b^^^2"*)
789 Thm ("real_plus_minus_binom2_p",
790 num_str @{real_plus_minus_binom2_p),
791 (*"(a - b)*(a + b) = a^^^2 + -1*b^^^2"*)
793 Thm ("minus_minus",num_str @{thm minus_minus}),
795 Thm ("real_diff_minus",num_str @{real_diff_minus),
796 (*"a - b = a + -1 * b"*)
797 Thm ("sym_real_mult_minus1",num_str @{(real_mult_minus1 RS sym))
800 (*Thm ("",num_str @{),
802 Thm ("",num_str @{),*)
803 (*Thm ("real_minus_add_distrib",
804 num_str @{real_minus_add_distrib),*)
805 (*"- (?x + ?y) = - ?x + - ?y"*)
806 (*Thm ("real_diff_plus",num_str @{real_diff_plus)*)
808 ], scr = EmptyScr}:rls;
811 Rls{id = "simplify_power", preconds = [],
812 rew_ord = ("dummy_ord", dummy_ord),
813 erls = e_rls, srls = Erls,
816 rules = [Thm ("realpow_multI", num_str @{realpow_multI),
817 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
819 Thm ("sym_realpow_twoI",num_str @{(realpow_twoI RS sym)),
820 (*"r1 * r1 = r1 ^^^ 2"*)
821 Thm ("realpow_plus_1",num_str @{realpow_plus_1),
822 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
823 Thm ("realpow_pow",num_str @{realpow_pow),
824 (*"(a ^^^ b) ^^^ c = a ^^^ (b * c)"*)
825 Thm ("sym_realpow_addI",num_str @{(realpow_addI RS sym)),
826 (*"r ^^^ n * r ^^^ m = r ^^^ (n + m)"*)
827 Thm ("realpow_oneI",num_str @{realpow_oneI),
829 Thm ("realpow_eq_oneI",num_str @{realpow_eq_oneI)
831 ], scr = EmptyScr}:rls;
832 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
833 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
835 Rls{id = "order_add_mult", preconds = [],
836 rew_ord = ("ord_make_polynomial",ord_make_polynomial false (theory "Poly")),
837 erls = e_rls,srls = Erls,
840 rules = [Thm ("real_mult_commute",num_str @{real_mult_commute),
842 Thm ("real_mult_left_commute",num_str @{real_mult_left_commute),
843 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
844 Thm ("real_mult_assoc",num_str @{real_mult_assoc),
845 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
846 Thm ("add_commute",num_str @{thm add_commute}),
848 Thm ("add_left_commute",num_str @{thm add_left_commute}),
849 (*x + (y + z) = y + (x + z)*)
850 Thm ("add_assoc",num_str @{thm add_assoc})
851 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
852 ], scr = EmptyScr}:rls;
853 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
854 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
856 Rls{id = "order_mult", preconds = [],
857 rew_ord = ("ord_make_polynomial",ord_make_polynomial false (theory "Poly")),
858 erls = e_rls,srls = Erls,
861 rules = [Thm ("real_mult_commute",num_str @{real_mult_commute),
863 Thm ("real_mult_left_commute",num_str @{real_mult_left_commute),
864 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
865 Thm ("real_mult_assoc",num_str @{real_mult_assoc)
866 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
867 ], scr = EmptyScr}:rls;
868 val collect_numerals =
869 Rls{id = "collect_numerals", preconds = [],
870 rew_ord = ("dummy_ord", dummy_ord),
871 erls = Atools_erls(*erls3.4.03*),srls = Erls,
872 calc = [("PLUS" , ("op +", eval_binop "#add_")),
873 ("TIMES" , ("op *", eval_binop "#mult_")),
874 ("POWER", ("Atools.pow", eval_binop "#power_"))
877 rules = [Thm ("real_num_collect",num_str @{real_num_collect),
878 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
879 Thm ("real_num_collect_assoc",num_str @{real_num_collect_assoc),
880 (*"[| l is_const; m is_const |] ==>
881 l * n + (m * n + k) = (l + m) * n + k"*)
882 Thm ("real_one_collect",num_str @{real_one_collect),
883 (*"m is_const ==> n + m * n = (1 + m) * n"*)
884 Thm ("real_one_collect_assoc",num_str @{real_one_collect_assoc),
885 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
886 Calc ("op +", eval_binop "#add_"),
887 Calc ("op *", eval_binop "#mult_"),
888 Calc ("Atools.pow", eval_binop "#power_")
889 ], scr = EmptyScr}:rls;
891 Rls{id = "reduce_012", preconds = [],
892 rew_ord = ("dummy_ord", dummy_ord),
893 erls = e_rls,srls = Erls,
896 rules = [Thm ("mult_1_left",num_str @{thm mult_1_left}),
898 (*Thm ("real_mult_minus1",num_str @{real_mult_minus1),14.3.03*)
900 Thm ("minus_mult_left",
901 num_str @{(real_mult_minus_eq1 RS sym)),
902 (*- (?x * ?y) = "- ?x * ?y"*)
903 (*Thm ("real_minus_mult_cancel",num_str @{real_minus_mult_cancel),
904 (*"- ?x * - ?y = ?x * ?y"*)---*)
905 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
907 Thm ("add_0_left",num_str @{thm add_0_left}),
909 Thm ("right_minus",num_str @{thm right_minus}),
911 Thm ("sym_real_mult_2",num_str @{(real_mult_2 RS sym)),
912 (*"z1 + z1 = 2 * z1"*)
913 Thm ("real_mult_2_assoc",num_str @{real_mult_2_assoc)
914 (*"z1 + (z1 + k) = 2 * z1 + k"*)
915 ], scr = EmptyScr}:rls;
916 (*ein Hilfs-'ruleset' (benutzt das leere 'ruleset')*)
917 val discard_parentheses =
918 append_rls "discard_parentheses" e_rls
919 [Thm ("sym_real_mult_assoc", num_str @{(real_mult_assoc RS sym)),
920 Thm ("sym_real_add_assoc",num_str @{(real_add_assoc RS sym))];
922 val scr_make_polynomial =
923 "Script Expand_binoms t_ = " ^
925 "((Try (Repeat (Rewrite real_diff_minus False))) @@ " ^
927 " (Try (Repeat (Rewrite real_add_mult_distrib False))) @@ " ^
928 " (Try (Repeat (Rewrite real_add_mult_distrib2 False))) @@ " ^
929 " (Try (Repeat (Rewrite real_diff_mult_distrib False))) @@ " ^
930 " (Try (Repeat (Rewrite real_diff_mult_distrib2 False))) @@ " ^
932 " (Try (Repeat (Rewrite real_mult_1 False))) @@ " ^
933 " (Try (Repeat (Rewrite real_mult_0 False))) @@ " ^
934 " (Try (Repeat (Rewrite real_add_zero_left False))) @@ " ^
936 " (Try (Repeat (Rewrite real_mult_commute False))) @@ " ^
937 " (Try (Repeat (Rewrite real_mult_left_commute False))) @@ " ^
938 " (Try (Repeat (Rewrite real_mult_assoc False))) @@ " ^
939 " (Try (Repeat (Rewrite real_add_commute False))) @@ " ^
940 " (Try (Repeat (Rewrite real_add_left_commute False))) @@ " ^
941 " (Try (Repeat (Rewrite real_add_assoc False))) @@ " ^
943 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
944 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
945 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
946 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
948 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
949 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
951 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
952 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
954 " (Try (Repeat (Calculate plus ))) @@ " ^
955 " (Try (Repeat (Calculate times ))) @@ " ^
956 " (Try (Repeat (Calculate power_)))) " ^
959 (*version used by MG.02/03, overwritten by version AG in 04 below
960 val make_polynomial = prep_rls(
961 Seq{id = "make_polynomial", preconds = []:term list,
962 rew_ord = ("dummy_ord", dummy_ord),
963 erls = Atools_erls, srls = Erls,
964 calc = [],(*asm_thm = [],*)
965 rules = [Rls_ expand_poly,
967 Rls_ simplify_power, (*realpow_eq_oneI, eg. x^1 --> x *)
968 Rls_ collect_numerals, (*eg. x^(2+ -1) --> x^1 *)
970 Thm ("realpow_oneI",num_str @{realpow_oneI),(*in --^*)
971 Rls_ discard_parentheses
976 val scr_expand_binoms =
977 "Script Expand_binoms t_ =" ^
979 "((Try (Repeat (Rewrite real_plus_binom_pow2 False))) @@ " ^
980 " (Try (Repeat (Rewrite real_plus_binom_times False))) @@ " ^
981 " (Try (Repeat (Rewrite real_minus_binom_pow2 False))) @@ " ^
982 " (Try (Repeat (Rewrite real_minus_binom_times False))) @@ " ^
983 " (Try (Repeat (Rewrite real_plus_minus_binom1 False))) @@ " ^
984 " (Try (Repeat (Rewrite real_plus_minus_binom2 False))) @@ " ^
986 " (Try (Repeat (Rewrite real_mult_1 False))) @@ " ^
987 " (Try (Repeat (Rewrite real_mult_0 False))) @@ " ^
988 " (Try (Repeat (Rewrite real_add_zero_left False))) @@ " ^
990 " (Try (Repeat (Calculate plus ))) @@ " ^
991 " (Try (Repeat (Calculate times ))) @@ " ^
992 " (Try (Repeat (Calculate power_))) @@ " ^
994 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
995 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
996 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
997 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
999 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
1000 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
1002 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
1003 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
1005 " (Try (Repeat (Calculate plus ))) @@ " ^
1006 " (Try (Repeat (Calculate times ))) @@ " ^
1007 " (Try (Repeat (Calculate power_)))) " ^
1011 Rls{id = "expand_binoms", preconds = [], rew_ord = ("termlessI",termlessI),
1012 erls = Atools_erls, srls = Erls,
1013 calc = [("PLUS" , ("op +", eval_binop "#add_")),
1014 ("TIMES" , ("op *", eval_binop "#mult_")),
1015 ("POWER", ("Atools.pow", eval_binop "#power_"))
1018 rules = [Thm ("real_plus_binom_pow2" ,num_str @{real_plus_binom_pow2),
1019 (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
1020 Thm ("real_plus_binom_times" ,num_str @{real_plus_binom_times),
1021 (*"(a + b)*(a + b) = ...*)
1022 Thm ("real_minus_binom_pow2" ,num_str @{real_minus_binom_pow2),
1023 (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
1024 Thm ("real_minus_binom_times",num_str @{real_minus_binom_times),
1025 (*"(a - b)*(a - b) = ...*)
1026 Thm ("real_plus_minus_binom1",num_str @{real_plus_minus_binom1),
1027 (*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
1028 Thm ("real_plus_minus_binom2",num_str @{real_plus_minus_binom2),
1029 (*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
1031 Thm ("real_pp_binom_times",num_str @{real_pp_binom_times),
1032 (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
1033 Thm ("real_pm_binom_times",num_str @{real_pm_binom_times),
1034 (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
1035 Thm ("real_mp_binom_times",num_str @{real_mp_binom_times),
1036 (*(a - b)*(c + d) = a*c + a*d - b*c - b*d*)
1037 Thm ("real_mm_binom_times",num_str @{real_mm_binom_times),
1038 (*(a - b)*(c - d) = a*c - a*d - b*c + b*d*)
1039 Thm ("realpow_multI",num_str @{realpow_multI),
1040 (*(a*b)^^^n = a^^^n * b^^^n*)
1041 Thm ("real_plus_binom_pow3",num_str @{real_plus_binom_pow3),
1042 (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
1043 Thm ("real_minus_binom_pow3",num_str @{real_minus_binom_pow3),
1044 (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
1047 (* Thm ("left_distrib" ,num_str @{thm left_distrib}),
1048 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1049 Thm ("left_distrib2",num_str @{thm left_distrib}2),
1050 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1051 Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),
1052 (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
1053 Thm ("left_diff_distrib2",num_str @{thm left_diff_distrib}2),
1054 (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
1057 Thm ("mult_1_left",num_str @{thm mult_1_left}), (*"1 * z = z"*)
1058 Thm ("mult_zero_left",num_str @{thm mult_zero_left}), (*"0 * z = 0"*)
1059 Thm ("add_0_left",num_str @{thm add_0_left}),(*"0 + z = z"*)
1061 Calc ("op +", eval_binop "#add_"),
1062 Calc ("op *", eval_binop "#mult_"),
1063 Calc ("Atools.pow", eval_binop "#power_"),
1065 Thm ("real_mult_commute",num_str @{real_mult_commute), (*AC-rewriting*)
1066 Thm ("real_mult_left_commute",num_str @{real_mult_left_commute), (**)
1067 Thm ("real_mult_assoc",num_str @{real_mult_assoc), (**)
1068 Thm ("add_commute",num_str @{thm add_commute}), (**)
1069 Thm ("add_left_commute",num_str @{thm add_left_commute}), (**)
1070 Thm ("add_assoc",num_str @{thm add_assoc}), (**)
1073 Thm ("sym_realpow_twoI",num_str @{(realpow_twoI RS sym)),
1074 (*"r1 * r1 = r1 ^^^ 2"*)
1075 Thm ("realpow_plus_1",num_str @{realpow_plus_1),
1076 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
1077 (*Thm ("sym_real_mult_2",num_str @{(real_mult_2 RS sym)),
1078 (*"z1 + z1 = 2 * z1"*)*)
1079 Thm ("real_mult_2_assoc",num_str @{real_mult_2_assoc),
1080 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1082 Thm ("real_num_collect",num_str @{real_num_collect),
1083 (*"[| l is_const; m is_const |] ==> l * n + m * n = (l + m) * n"*)
1084 Thm ("real_num_collect_assoc",num_str @{real_num_collect_assoc),
1085 (*"[| l is_const; m is_const |] ==> l * n + (m * n + k) = (l + m) * n + k"*)
1086 Thm ("real_one_collect",num_str @{real_one_collect),
1087 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1088 Thm ("real_one_collect_assoc",num_str @{real_one_collect_assoc),
1089 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1091 Calc ("op +", eval_binop "#add_"),
1092 Calc ("op *", eval_binop "#mult_"),
1093 Calc ("Atools.pow", eval_binop "#power_")
1095 scr = Script ((term_of o the o (parse thy)) scr_expand_binoms)
1099 "******* Poly.ML end ******* ...RL";
1102 (**. MG.03: make_polynomial_ ... uses SML-fun for ordering .**)
1104 (*FIXME.0401: make SML-order local to make_polynomial(_) *)
1105 (*FIXME.0401: replace 'make_polynomial'(old) by 'make_polynomial_'(MG) *)
1106 (* Polynom --> List von Monomen *)
1107 fun poly2list (Const ("op +",_) $ t1 $ t2) =
1108 (poly2list t1) @ (poly2list t2)
1109 | poly2list t = [t];
1111 (* Monom --> Liste von Variablen *)
1112 fun monom2list (Const ("op *",_) $ t1 $ t2) =
1113 (monom2list t1) @ (monom2list t2)
1114 | monom2list t = [t];
1116 (* liefert Variablenname (String) einer Variablen und Basis bei Potenz *)
1117 fun get_basStr (Const ("Atools.pow",_) $ Free (str, _) $ _) = str
1118 | get_basStr (Free (str, _)) = str
1119 | get_basStr t = "|||"; (* gross gewichtet; für Brüch ect. *)
1121 raise error("get_basStr: called with t= "^(term2str t));*)
1123 (* liefert Hochzahl (String) einer Variablen bzw Gewichtstring (zum Sortieren) *)
1124 fun get_potStr (Const ("Atools.pow",_) $ Free _ $ Free (str, _)) = str
1125 | get_potStr (Const ("Atools.pow",_) $ Free _ $ _ ) = "|||" (* gross gewichtet *)
1126 | get_potStr (Free (str, _)) = "---" (* keine Hochzahl --> kleinst gewichtet *)
1127 | get_potStr t = "||||||"; (* gross gewichtet; für Brüch ect. *)
1129 raise error("get_potStr: called with t= "^(term2str t));*)
1131 (* Umgekehrte string_ord *)
1132 val string_ord_rev = rev_order o string_ord;
1134 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen)
1135 innerhalb eines Monomes:
1136 - zuerst lexikographisch nach Variablenname
1137 - wenn gleich: nach steigender Potenz *)
1138 fun var_ord (a,b: term) = prod_ord string_ord string_ord
1139 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
1141 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen);
1142 verwendet zum Sortieren von Monomen mittels Gesamtgradordnung:
1143 - zuerst lexikographisch nach Variablenname
1144 - wenn gleich: nach sinkender Potenz*)
1145 fun var_ord_revPow (a,b: term) = prod_ord string_ord string_ord_rev
1146 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
1149 (* Ordnet ein Liste von Variablen (und Potenzen) lexikographisch *)
1150 val sort_varList = sort var_ord;
1152 (* Entfernet aeussersten Operator (Wurzel) aus einem Term und schreibt
1153 Argumente in eine Liste *)
1154 fun args u : term list =
1155 let fun stripc (f$t, ts) = stripc (f, t::ts)
1156 | stripc (t as Free _, ts) = (t::ts)
1157 | stripc (_, ts) = ts
1158 in stripc (u, []) end;
1160 (* liefert True, falls der Term (Liste von Termen) nur Zahlen
1161 (keine Variablen) enthaelt *)
1162 fun filter_num [] = true
1163 | filter_num [Free x] = if (is_num (Free x)) then true
1165 | filter_num ((Free _)::_) = false
1167 (filter_num o (filter_out is_num) o flat o (map args)) ts;
1169 (* liefert True, falls der Term nur Zahlen (keine Variablen) enthaelt
1170 dh. er ist ein numerischer Wert und entspricht einem Koeffizienten *)
1171 fun is_nums t = filter_num [t];
1173 (* Berechnet den Gesamtgrad eines Monoms *)
1175 fun counter (n, []) = n
1176 | counter (n, x :: xs) =
1181 (Const ("Atools.pow", _) $ Free (str_b, _) $ Free (str_h, T)) =>
1182 if (is_nums (Free (str_h, T))) then
1183 counter (n + (the (int_of_str str_h)), xs)
1184 else counter (n + 1000, xs) (*FIXME.MG?!*)
1185 | (Const ("Atools.pow", _) $ Free (str_b, _) $ _ ) =>
1186 counter (n + 1000, xs) (*FIXME.MG?!*)
1187 | (Free (str, _)) => counter (n + 1, xs)
1188 (*| _ => raise error("monom_degree: called with factor: "^(term2str x)))*)
1189 | _ => counter (n + 10000, xs)) (*FIXME.MG?! ... Brüche ect.*)
1191 fun monom_degree l = counter (0, l)
1194 (* wie Ordnung dict_ord (lexicographische Ordnung zweier Listen, mit Vergleich
1195 der Listen-Elemente mit elem_ord) - Elemente die Bedingung cond erfuellen,
1196 werden jedoch dabei ignoriert (uebersprungen) *)
1197 fun dict_cond_ord _ _ ([], []) = EQUAL
1198 | dict_cond_ord _ _ ([], _ :: _) = LESS
1199 | dict_cond_ord _ _ (_ :: _, []) = GREATER
1200 | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
1201 (case (cond x, cond y) of
1202 (false, false) => (case elem_ord (x, y) of
1203 EQUAL => dict_cond_ord elem_ord cond (xs, ys)
1205 | (false, true) => dict_cond_ord elem_ord cond (x :: xs, ys)
1206 | (true, false) => dict_cond_ord elem_ord cond (xs, y :: ys)
1207 | (true, true) => dict_cond_ord elem_ord cond (xs, ys) );
1209 (* Gesamtgradordnung zum Vergleich von Monomen (Liste von Variablen/Potenzen):
1210 zuerst nach Gesamtgrad, bei gleichem Gesamtgrad lexikographisch ordnen -
1211 dabei werden Koeffizienten ignoriert (2*3*a^^^2*4*b gilt wie a^^^2*b) *)
1212 fun degree_ord (xs, ys) =
1213 prod_ord int_ord (dict_cond_ord var_ord_revPow is_nums)
1214 ((monom_degree xs, xs), (monom_degree ys, ys));
1216 fun hd_str str = substring (str, 0, 1);
1217 fun tl_str str = substring (str, 1, (size str) - 1);
1219 (* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
1220 fun get_koeff_of_mon [] = raise error("get_koeff_of_mon: called with l = []")
1221 | get_koeff_of_mon (l as x::xs) = if is_nums x then SOME x
1224 (* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
1225 fun koeff2ordStr (SOME x) = (case x of
1227 if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
1229 | _ => "aaa") (* "num.Ausdruck" --> gross *)
1230 | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
1232 (* Order zum Vergleich von Koeffizienten (strings):
1233 "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
1234 fun compare_koeff_ord (xs, ys) =
1235 string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
1236 (koeff2ordStr o get_koeff_of_mon) ys);
1238 (* Gesamtgradordnung degree_ord + Ordnen nach Koeffizienten falls EQUAL *)
1239 fun koeff_degree_ord (xs, ys) =
1240 prod_ord degree_ord compare_koeff_ord ((xs, xs), (ys, ys));
1242 (* Ordnet ein Liste von Monomen (Monom = Liste von Variablen) mittels
1243 Gesamtgradordnung *)
1244 val sort_monList = sort koeff_degree_ord;
1246 (* Alternativ zu degree_ord koennte auch die viel einfachere und
1247 kuerzere Ordnung simple_ord verwendet werden - ist aber nicht
1248 fuer unsere Zwecke geeignet!
1250 fun simple_ord (al,bl: term list) = dict_ord string_ord
1251 (map get_basStr al, map get_basStr bl);
1253 val sort_monList = sort simple_ord; *)
1255 (* aus 2 Variablen wird eine Summe bzw ein Produkt erzeugt
1256 (mit gewuenschtem Typen T) *)
1257 fun plus T = Const ("op +", [T,T] ---> T);
1258 fun mult T = Const ("op *", [T,T] ---> T);
1259 fun binop op_ t1 t2 = op_ $ t1 $ t2;
1260 fun create_prod T (a,b) = binop (mult T) a b;
1261 fun create_sum T (a,b) = binop (plus T) a b;
1263 (* löscht letztes Element einer Liste *)
1264 fun drop_last l = take ((length l)-1,l);
1266 (* Liste von Variablen --> Monom *)
1267 fun create_monom T vl = foldr (create_prod T) (drop_last vl, last_elem vl);
1269 foldr bewirkt rechtslastige Klammerung des Monoms - ist notwendig, damit zwei
1270 gleiche Monome zusammengefasst werden können (collect_numerals)!
1271 zB: 2*(x*(y*z)) + 3*(x*(y*z)) --> (2+3)*(x*(y*z))*)
1273 (* Liste von Monomen --> Polynom *)
1274 fun create_polynom T ml = foldl (create_sum T) (hd ml, tl ml);
1276 foldl bewirkt linkslastige Klammerung des Polynoms (der Summanten) -
1277 bessere Darstellung, da keine Klammern sichtbar!
1278 (und discard_parentheses in make_polynomial hat weniger zu tun) *)
1280 (* sorts the variables (faktors) of an expanded polynomial lexicographical *)
1281 fun sort_variables t =
1283 val ll = map monom2list (poly2list t);
1284 val lls = map sort_varList ll;
1286 val ls = map (create_monom T) lls;
1287 in create_polynom T ls end;
1289 (* sorts the monoms of an expanded and variable-sorted polynomial
1293 val ll = map monom2list (poly2list t);
1294 val lls = sort_monList ll;
1296 val ls = map (create_monom T) lls;
1297 in create_polynom T ls end;
1299 (* auch Klammerung muss übereinstimmen;
1300 sort_variables klammert Produkte rechtslastig*)
1301 fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
1303 fun eval_is_multUnordered (thmid:string) _
1304 (t as (Const("Poly.is'_multUnordered", _) $ arg)) thy =
1305 if is_multUnordered arg
1306 then SOME (mk_thmid thmid ""
1307 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1308 Trueprop $ (mk_equality (t, HOLogic.true_const)))
1309 else SOME (mk_thmid thmid ""
1310 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1311 Trueprop $ (mk_equality (t, HOLogic.false_const)))
1312 | eval_is_multUnordered _ _ _ _ = NONE;
1315 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
1316 []:(rule * (term * term list)) list;
1317 fun init_state (_:term) = e_rrlsstate;
1318 fun locate_rule (_:rule list list) (_:term) (_:rule) =
1319 ([]:(rule * (term * term list)) list);
1320 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
1321 fun normal_form t = SOME (sort_variables t,[]:term list);
1324 Rrls {id = "order_mult_",
1326 [([(term_of o the o (parse thy)) "p is_multUnordered"],
1327 (term_of o the o (parse thy)) "?p" )],
1328 rew_ord = ("dummy_ord", dummy_ord),
1329 erls = append_rls "e_rls-is_multUnordered" e_rls(*MG: poly_erls*)
1330 [Calc ("Poly.is'_multUnordered", eval_is_multUnordered "")
1332 calc = [("PLUS" ,("op +" ,eval_binop "#add_")),
1333 ("TIMES" ,("op *" ,eval_binop "#mult_")),
1334 ("DIVIDE" ,("HOL.divide" ,eval_cancel "#divide_")),
1335 ("POWER" ,("Atools.pow" ,eval_binop "#power_"))],
1337 scr=Rfuns {init_state = init_state,
1338 normal_form = normal_form,
1339 locate_rule = locate_rule,
1340 next_rule = next_rule,
1341 attach_form = attach_form}};
1343 val order_mult_rls_ =
1344 Rls{id = "order_mult_rls_", preconds = [],
1345 rew_ord = ("dummy_ord", dummy_ord),
1346 erls = e_rls,srls = Erls,
1349 rules = [Rls_ order_mult_
1350 ], scr = EmptyScr}:rls;
1352 fun is_addUnordered t = ((is_polyexp t) andalso not (t = sort_monoms t));
1355 (*("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))*)
1356 fun eval_is_addUnordered (thmid:string) _
1357 (t as (Const("Poly.is'_addUnordered", _) $ arg)) thy =
1358 if is_addUnordered arg
1359 then SOME (mk_thmid thmid ""
1360 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1361 Trueprop $ (mk_equality (t, HOLogic.true_const)))
1362 else SOME (mk_thmid thmid ""
1363 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
1364 Trueprop $ (mk_equality (t, HOLogic.false_const)))
1365 | eval_is_addUnordered _ _ _ _ = NONE;
1367 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
1368 []:(rule * (term * term list)) list;
1369 fun init_state (_:term) = e_rrlsstate;
1370 fun locate_rule (_:rule list list) (_:term) (_:rule) =
1371 ([]:(rule * (term * term list)) list);
1372 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
1373 fun normal_form t = SOME (sort_monoms t,[]:term list);
1376 Rrls {id = "order_add_",
1377 prepat = (*WN.18.6.03 Preconditions und Pattern,
1378 die beide passen muessen, damit das Rrls angewandt wird*)
1379 [([(term_of o the o (parse thy)) "p is_addUnordered"],
1380 (term_of o the o (parse thy)) "?p"
1381 (*WN.18.6.03 also KEIN pattern, dieses erzeugt nur das Environment
1382 fuer die Evaluation der Precondition "p is_addUnordered"*))],
1383 rew_ord = ("dummy_ord", dummy_ord),
1384 erls = append_rls "e_rls-is_addUnordered" e_rls(*MG: poly_erls*)
1385 [Calc ("Poly.is'_addUnordered", eval_is_addUnordered "")
1386 (*WN.18.6.03 definiert in (theory "Poly"),
1387 evaluiert prepat*)],
1388 calc = [("PLUS" ,("op +" ,eval_binop "#add_")),
1389 ("TIMES" ,("op *" ,eval_binop "#mult_")),
1390 ("DIVIDE" ,("HOL.divide" ,eval_cancel "#divide_")),
1391 ("POWER" ,("Atools.pow" ,eval_binop "#power_"))],
1393 scr=Rfuns {init_state = init_state,
1394 normal_form = normal_form,
1395 locate_rule = locate_rule,
1396 next_rule = next_rule,
1397 attach_form = attach_form}};
1399 val order_add_rls_ =
1400 Rls{id = "order_add_rls_", preconds = [],
1401 rew_ord = ("dummy_ord", dummy_ord),
1402 erls = e_rls,srls = Erls,
1405 rules = [Rls_ order_add_
1406 ], scr = EmptyScr}:rls;
1408 (*. see MG-DA.p.52ff .*)
1409 val make_polynomial(*MG.03, overwrites version from above,
1410 previously 'make_polynomial_'*) =
1411 Seq {id = "make_polynomial", preconds = []:term list,
1412 rew_ord = ("dummy_ord", dummy_ord),
1413 erls = Atools_erls, srls = Erls,calc = [],
1414 rules = [Rls_ discard_minus_,
1416 Calc ("op *", eval_binop "#mult_"),
1417 Rls_ order_mult_rls_,
1418 Rls_ simplify_power_,
1419 Rls_ calc_add_mult_pow_,
1420 Rls_ reduce_012_mult_,
1421 Rls_ order_add_rls_,
1422 Rls_ collect_numerals_,
1424 Rls_ discard_parentheses_
1428 val norm_Poly(*=make_polynomial*) =
1429 Seq {id = "norm_Poly", preconds = []:term list,
1430 rew_ord = ("dummy_ord", dummy_ord),
1431 erls = Atools_erls, srls = Erls, calc = [],
1432 rules = [Rls_ discard_minus_,
1434 Calc ("op *", eval_binop "#mult_"),
1435 Rls_ order_mult_rls_,
1436 Rls_ simplify_power_,
1437 Rls_ calc_add_mult_pow_,
1438 Rls_ reduce_012_mult_,
1439 Rls_ order_add_rls_,
1440 Rls_ collect_numerals_,
1442 Rls_ discard_parentheses_
1447 (* MG:03 Like make_polynomial_ but without Rls_ discard_parentheses_
1448 and expand_poly_rat_ instead of expand_poly_, see MG-DA.p.56ff*)
1449 (* MG necessary for termination of norm_Rational(*_mg*) in Rational.ML*)
1450 val make_rat_poly_with_parentheses =
1451 Seq{id = "make_rat_poly_with_parentheses", preconds = []:term list,
1452 rew_ord = ("dummy_ord", dummy_ord),
1453 erls = Atools_erls, srls = Erls, calc = [],
1454 rules = [Rls_ discard_minus_,
1455 Rls_ expand_poly_rat_,(*ignors rationals*)
1456 Calc ("op *", eval_binop "#mult_"),
1457 Rls_ order_mult_rls_,
1458 Rls_ simplify_power_,
1459 Rls_ calc_add_mult_pow_,
1460 Rls_ reduce_012_mult_,
1461 Rls_ order_add_rls_,
1462 Rls_ collect_numerals_,
1464 (*Rls_ discard_parentheses_ *)
1469 (*.a minimal ruleset for reverse rewriting of factions [2];
1470 compare expand_binoms.*)
1472 Seq{id = "reverse_rewriting", preconds = [], rew_ord = ("termlessI",termlessI),
1473 erls = Atools_erls, srls = Erls,
1474 calc = [(*("PLUS" , ("op +", eval_binop "#add_")),
1475 ("TIMES" , ("op *", eval_binop "#mult_")),
1476 ("POWER", ("Atools.pow", eval_binop "#power_"))*)
1478 rules = [Thm ("real_plus_binom_times" ,num_str @{real_plus_binom_times),
1479 (*"(a + b)*(a + b) = a ^ 2 + 2 * a * b + b ^ 2*)
1480 Thm ("real_plus_binom_times1" ,num_str @{real_plus_binom_times1),
1481 (*"(a + 1*b)*(a + -1*b) = a^^^2 + -1*b^^^2"*)
1482 Thm ("real_plus_binom_times2" ,num_str @{real_plus_binom_times2),
1483 (*"(a + -1*b)*(a + 1*b) = a^^^2 + -1*b^^^2"*)
1485 Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
1487 Thm ("left_distrib" ,num_str @{thm left_distrib}),
1488 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1489 Thm ("left_distrib2",num_str @{thm left_distrib}2),
1490 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1492 Thm ("real_mult_assoc", num_str @{real_mult_assoc),
1493 (*"?z1.1 * ?z2.1 * ?z3. =1 ?z1.1 * (?z2.1 * ?z3.1)"*)
1494 Rls_ order_mult_rls_,
1495 (*Rls_ order_add_rls_,*)
1497 Calc ("op +", eval_binop "#add_"),
1498 Calc ("op *", eval_binop "#mult_"),
1499 Calc ("Atools.pow", eval_binop "#power_"),
1501 Thm ("sym_realpow_twoI",num_str @{(realpow_twoI RS sym)),
1502 (*"r1 * r1 = r1 ^^^ 2"*)
1503 Thm ("sym_real_mult_2",num_str @{(real_mult_2 RS sym)),
1504 (*"z1 + z1 = 2 * z1"*)
1505 Thm ("real_mult_2_assoc",num_str @{real_mult_2_assoc),
1506 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1508 Thm ("real_num_collect",num_str @{real_num_collect),
1509 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
1510 Thm ("real_num_collect_assoc",num_str @{real_num_collect_assoc),
1511 (*"[| l is_const; m is_const |] ==>
1512 l * n + (m * n + k) = (l + m) * n + k"*)
1513 Thm ("real_one_collect",num_str @{real_one_collect),
1514 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1515 Thm ("real_one_collect_assoc",num_str @{real_one_collect_assoc),
1516 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1518 Thm ("realpow_multI", num_str @{realpow_multI),
1519 (*"(r * s) ^^^ n = r ^^^ n * s ^^^ n"*)
1521 Calc ("op +", eval_binop "#add_"),
1522 Calc ("op *", eval_binop "#mult_"),
1523 Calc ("Atools.pow", eval_binop "#power_"),
1525 Thm ("mult_1_left",num_str @{thm mult_1_left}),(*"1 * z = z"*)
1526 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),(*"0 * z = 0"*)
1527 Thm ("add_0_left",num_str @{thm add_0_left})(*0 + z = z*)
1529 (*Rls_ order_add_rls_*)
1532 scr = EmptyScr}:rls;
1535 overwritelthy @{theory} (!ruleset',
1536 [("norm_Poly", prep_rls norm_Poly),
1537 ("Poly_erls",Poly_erls)(*FIXXXME:del with rls.rls'*),
1538 ("expand", prep_rls expand),
1539 ("expand_poly", prep_rls expand_poly),
1540 ("simplify_power", prep_rls simplify_power),
1541 ("order_add_mult", prep_rls order_add_mult),
1542 ("collect_numerals", prep_rls collect_numerals),
1543 ("collect_numerals_", prep_rls collect_numerals_),
1544 ("reduce_012", prep_rls reduce_012),
1545 ("discard_parentheses", prep_rls discard_parentheses),
1546 ("make_polynomial", prep_rls make_polynomial),
1547 ("expand_binoms", prep_rls expand_binoms),
1548 ("rev_rew_p", prep_rls rev_rew_p),
1549 ("discard_minus_", prep_rls discard_minus_),
1550 ("expand_poly_", prep_rls expand_poly_),
1551 ("expand_poly_rat_", prep_rls expand_poly_rat_),
1552 ("simplify_power_", prep_rls simplify_power_),
1553 ("calc_add_mult_pow_", prep_rls calc_add_mult_pow_),
1554 ("reduce_012_mult_", prep_rls reduce_012_mult_),
1555 ("reduce_012_", prep_rls reduce_012_),
1556 ("discard_parentheses_",prep_rls discard_parentheses_),
1557 ("order_mult_rls_", prep_rls order_mult_rls_),
1558 ("order_add_rls_", prep_rls order_add_rls_),
1559 ("make_rat_poly_with_parentheses",
1560 prep_rls make_rat_poly_with_parentheses)
1567 calclist':= overwritel (!calclist',
1568 [("is_polyrat_in", ("Poly.is'_polyrat'_in",
1569 eval_is_polyrat_in "#eval_is_polyrat_in")),
1570 ("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in "")),
1571 ("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in "")),
1572 ("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in "")),
1573 ("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp "")),
1574 ("is_multUnordered", ("Poly.is'_multUnordered", eval_is_multUnordered"")),
1575 ("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))
1582 (prep_pbt (theory "Poly") "pbl_simp_poly" [] e_pblID
1583 (["polynomial","simplification"],
1584 [("#Given" ,["TERM t_"]),
1585 ("#Where" ,["t_ is_polyexp"]),
1586 ("#Find" ,["normalform n_"])
1588 append_rls "e_rls" e_rls [(*for preds in where_*)
1589 Calc ("Poly.is'_polyexp", eval_is_polyexp "")],
1591 [["simplification","for_polynomials"]]));
1597 (prep_met (theory "Poly") "met_simp_poly" [] e_metID
1598 (["simplification","for_polynomials"],
1599 [("#Given" ,["TERM t_"]),
1600 ("#Where" ,["t_ is_polyexp"]),
1601 ("#Find" ,["normalform n_"])
1603 {rew_ord'="tless_true",
1607 prls = append_rls "simplification_for_polynomials_prls" e_rls
1608 [(*for preds in where_*)
1609 Calc ("Poly.is'_polyexp",eval_is_polyexp"")],
1610 crls = e_rls, nrls = norm_Poly},
1611 "Script SimplifyScript (t_::real) = " ^
1612 " ((Rewrite_Set norm_Poly False) t_)"