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 \<up> instead of ^ in the respective theorem xxx in 2002
7 changed by: Richard Lang 020912
10 theory Poly imports Simplify begin
12 subsection \<open>remark on term-structure of polynomials\<close>
15 the code below reflects missing coordination between two authors:
16 * ML: built the equation solver; simple rule-sets, programs; better predicates for specifications.
17 * MG: built simplification of polynomials with AC rewriting by ML code
20 *** there are 5 kinds of expanded normalforms ***
22 [1] 'complete polynomial' (Komplettes Polynom), univariate
23 a_0 + a_1.x^1 +...+ a_n.x^n not (a_n = 0)
24 not (a_n = 0), some a_i may be zero (DON'T disappear),
25 variables in monomials lexicographically ordered and complete,
26 x written as 1*x^1, ...
27 [2] 'polynomial' (Polynom), univariate and multivariate
28 a_0 + a_1.x +...+ a_n.x^n not (a_n = 0)
29 a_0 + a_1.x_1.x_2^n_12...x_m^n_1m +...+ a_n.x_1^n.x_2^n_n2...x_m^n_nm
30 not (a_n = 0), some a_i may be zero (ie. monomials disappear),
31 exponents and coefficients equal 1 are not (WN060904.TODO in cancel_p_)shown,
32 and variables in monomials are lexicographically ordered
33 examples: [1]: "1 + (-10) * x \<up> 1 + 25 * x \<up> 2"
34 [1]: "11 + 0 * x \<up> 1 + 1 * x \<up> 2"
35 [2]: "x + (-50) * x \<up> 3"
36 [2]: "(-1) * x * y \<up> 2 + 7 * x \<up> 3"
38 [3] 'expanded_term' (Ausmultiplizierter Term):
39 pull out unary minus to binary minus,
40 as frequently exercised in schools; other conditions for [2] hold however
41 examples: "a \<up> 2 - 2 * a * b + b \<up> 2"
42 "4 * x \<up> 2 - 9 * y \<up> 2"
43 [4] 'polynomial_in' (Polynom in):
44 polynomial in 1 variable with arbitrary coefficients
45 examples: "2 * x + (-50) * x \<up> 3" (poly in x)
46 "(u + v) + (2 * u \<up> 2) * a + (-u) * a \<up> 2 (poly in a)
47 [5] 'expanded_in' (Ausmultiplizierter Termin in):
48 analoguous to [3] with binary minus like [3]
49 examples: "2 * x - 50 * x \<up> 3" (expanded in x)
50 "(u + v) + (2 * u \<up> 2) * a - u * a \<up> 2 (expanded in a)
52 subsection \<open>consts definition for predicates in specifications\<close>
55 is_expanded_in :: "[real, real] => bool" ("_ is'_expanded'_in _")
56 is_poly_in :: "[real, real] => bool" ("_ is'_poly'_in _") (*RL DA *)
57 has_degree_in :: "[real, real] => real" ("_ has'_degree'_in _")(*RL DA *)
58 is_polyrat_in :: "[real, real] => bool" ("_ is'_polyrat'_in _")(*RL030626*)
60 is_multUnordered:: "real => bool" ("_ is'_multUnordered")
61 is_addUnordered :: "real => bool" ("_ is'_addUnordered") (*WN030618*)
62 is_polyexp :: "real => bool" ("_ is'_polyexp")
64 subsection \<open>theorems not yet adopted from Isabelle\<close>
65 axiomatization where (*.not contained in Isabelle2002,
66 stated as axioms, TODO: prove as theorems;
67 theorem-IDs 'xxxI' with \<up> instead of ^ in 'xxx' in Isabelle2002.*)
69 realpow_pow: "(a \<up> b) \<up> c = a \<up> (b * c)" and
70 realpow_addI: "r \<up> (n + m) = r \<up> n * r \<up> m" and
71 realpow_addI_assoc_l: "r \<up> n * (r \<up> m * s) = r \<up> (n + m) * s" and
72 realpow_addI_assoc_r: "s * r \<up> n * r \<up> m = s * r \<up> (n + m)" and
74 realpow_oneI: "r \<up> 1 = r" and
75 realpow_zeroI: "r \<up> 0 = 1" and
76 realpow_eq_oneI: "1 \<up> n = 1" and
77 realpow_multI: "(r * s) \<up> n = r \<up> n * s \<up> n" and
78 realpow_multI_poly: "[| r is_polyexp; s is_polyexp |] ==>
79 (r * s) \<up> n = r \<up> n * s \<up> n" and
80 realpow_minus_oneI: "(- 1) \<up> (2 * n) = 1" and
81 real_diff_0: "0 - x = - (x::real)" and
83 realpow_twoI: "r \<up> 2 = r * r" and
84 realpow_twoI_assoc_l: "r * (r * s) = r \<up> 2 * s" and
85 realpow_twoI_assoc_r: "s * r * r = s * r \<up> 2" and
86 realpow_two_atom: "r is_atom ==> r * r = r \<up> 2" and
87 realpow_plus_1: "r * r \<up> n = r \<up> (n + 1)" and
88 realpow_plus_1_assoc_l: "r * (r \<up> m * s) = r \<up> (1 + m) * s" and
89 realpow_plus_1_assoc_l2: "r \<up> m * (r * s) = r \<up> (1 + m) * s" and
90 realpow_plus_1_assoc_r: "s * r * r \<up> m = s * r \<up> (1 + m)" and
91 realpow_plus_1_atom: "r is_atom ==> r * r \<up> n = r \<up> (1 + n)" and
92 realpow_def_atom: "[| Not (r is_atom); 1 < n |]
93 ==> r \<up> n = r * r \<up> (n + -1)" and
94 realpow_addI_atom: "r is_atom ==> r \<up> n * r \<up> m = r \<up> (n + m)" and
97 realpow_minus_even: "n is_even ==> (- r) \<up> n = r \<up> n" and
98 realpow_minus_odd: "Not (n is_even) ==> (- r) \<up> n = -1 * r \<up> n" and
102 real_pp_binom_times: "(a + b)*(c + d) = a*c + a*d + b*c + b*d" and
103 real_pm_binom_times: "(a + b)*(c - d) = a*c - a*d + b*c - b*d" and
104 real_mp_binom_times: "(a - b)*(c + d) = a*c + a*d - b*c - b*d" and
105 real_mm_binom_times: "(a - b)*(c - d) = a*c - a*d - b*c + b*d" and
106 real_plus_binom_pow3: "(a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" and
107 real_plus_binom_pow3_poly: "[| a is_polyexp; b is_polyexp |] ==>
108 (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" and
109 real_minus_binom_pow3: "(a - b) \<up> 3 = a \<up> 3 - 3*a \<up> 2*b + 3*a*b \<up> 2 - b \<up> 3" and
110 real_minus_binom_pow3_p: "(a + -1 * b) \<up> 3 = a \<up> 3 + -3*a \<up> 2*b + 3*a*b \<up> 2 +
112 (* real_plus_binom_pow: "[| n is_num; 3 < n |] ==>
113 (a + b) \<up> n = (a + b) * (a + b)\<up>(n - 1)" *)
114 real_plus_binom_pow4: "(a + b) \<up> 4 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
116 real_plus_binom_pow4_poly: "[| a is_polyexp; b is_polyexp |] ==>
117 (a + b) \<up> 4 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
119 real_plus_binom_pow5: "(a + b) \<up> 5 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3)
120 *(a \<up> 2 + 2*a*b + b \<up> 2)" and
121 real_plus_binom_pow5_poly: "[| a is_polyexp; b is_polyexp |] ==>
122 (a + b) \<up> 5 = (a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2
123 + b \<up> 3)*(a \<up> 2 + 2*a*b + b \<up> 2)" and
124 real_diff_plus: "a - b = a + -b" (*17.3.03: do_NOT_use*) and
125 real_diff_minus: "a - b = a + -1 * b" and
126 real_plus_binom_times: "(a + b)*(a + b) = a \<up> 2 + 2*a*b + b \<up> 2" and
127 real_minus_binom_times: "(a - b)*(a - b) = a \<up> 2 - 2*a*b + b \<up> 2" and
128 (*WN071229 changed for Schaerding -----vvv*)
129 (*real_plus_binom_pow2: "(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
130 real_plus_binom_pow2: "(a + b) \<up> 2 = (a + b) * (a + b)" and
131 (*WN071229 changed for Schaerding -----\<up>*)
132 real_plus_binom_pow2_poly: "[| a is_polyexp; b is_polyexp |] ==>
133 (a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2" and
134 real_minus_binom_pow2: "(a - b) \<up> 2 = a \<up> 2 - 2*a*b + b \<up> 2" and
135 real_minus_binom_pow2_p: "(a - b) \<up> 2 = a \<up> 2 + -2*a*b + b \<up> 2" and
136 real_plus_minus_binom1: "(a + b)*(a - b) = a \<up> 2 - b \<up> 2" and
137 real_plus_minus_binom1_p: "(a + b)*(a - b) = a \<up> 2 + -1*b \<up> 2" and
138 real_plus_minus_binom1_p_p: "(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2" and
139 real_plus_minus_binom2: "(a - b)*(a + b) = a \<up> 2 - b \<up> 2" and
140 real_plus_minus_binom2_p: "(a - b)*(a + b) = a \<up> 2 + -1*b \<up> 2" and
141 real_plus_minus_binom2_p_p: "(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2" and
142 real_plus_binom_times1: "(a + 1*b)*(a + -1*b) = a \<up> 2 + -1*b \<up> 2" and
143 real_plus_binom_times2: "(a + -1*b)*(a + 1*b) = a \<up> 2 + -1*b \<up> 2" and
145 real_num_collect: "[| l is_num; m is_num |] ==>
146 l * n + m * n = (l + m) * n" and
147 (* FIXME.MG.0401: replace 'real_num_collect_assoc'
148 by 'real_num_collect_assoc_l' ... are equal, introduced by MG ! *)
149 real_num_collect_assoc: "[| l is_num; m is_num |] ==>
150 l * n + (m * n + k) = (l + m) * n + k" and
151 real_num_collect_assoc_l: "[| l is_num; m is_num |] ==>
152 l * n + (m * n + k) = (l + m)
154 real_num_collect_assoc_r: "[| l is_num; m is_num |] ==>
155 (k + m * n) + l * n = k + (l + m) * n" and
156 real_one_collect: "m is_num ==> n + m * n = (1 + m) * n" and
157 (* FIXME.MG.0401: replace 'real_one_collect_assoc'
158 by 'real_one_collect_assoc_l' ... are equal, introduced by MG ! *)
159 real_one_collect_assoc: "m is_num ==> n + (m * n + k) = (1 + m)* n + k" and
161 real_one_collect_assoc_l: "m is_num ==> n + (m * n + k) = (1 + m) * n + k" and
162 real_one_collect_assoc_r: "m is_num ==> (k + n) + m * n = k + (1 + m) * n" and
164 (* FIXME.MG.0401: replace 'real_mult_2_assoc'
165 by 'real_mult_2_assoc_l' ... are equal, introduced by MG ! *)
166 real_mult_2_assoc: "z1 + (z1 + k) = 2 * z1 + k" and
167 real_mult_2_assoc_l: "z1 + (z1 + k) = 2 * z1 + k" and
168 real_mult_2_assoc_r: "(k + z1) + z1 = k + 2 * z1" and
170 real_mult_left_commute: "z1 * (z2 * z3) = z2 * (z1 * z3)" and
171 real_mult_minus1: "-1 * z = - (z::real)" and
172 (*sym_real_mult_minus1 expands indefinitely without assumptions ...*)
173 real_mult_minus1_sym: "[| \<not>(matches (- 1 * x) z); \<not>(z is_num) |] ==> - (z::real) = -1 * z" and
174 real_minus_mult_left: "\<not> ((a::real) is_num) ==> (- a) * b = - (a * b)" and
175 real_mult_2: "2 * z = z + (z::real)" and
177 real_add_mult_distrib_poly: "w is_polyexp ==> (z1 + z2) * w = z1 * w + z2 * w" and
178 real_add_mult_distrib2_poly:"w is_polyexp ==> w * (z1 + z2) = w * z1 + w * z2"
181 subsection \<open>auxiliary functions\<close>
184 [\<^const_name>\<open>plus\<close>, \<^const_name>\<open>minus\<close>,
185 \<^const_name>\<open>divide\<close>, \<^const_name>\<open>times\<close>,
186 \<^const_name>\<open>realpow\<close>];
188 val int_ord_SAVE = int_ord;
189 (*for tests on rewrite orders*)
190 fun int_ord (i1, i2) =
191 (@{print} {a = "int_ord (" ^ string_of_int i1 ^ ", " ^ string_of_int i2 ^ ") = ", z = Int.compare (i1, i2)};
192 Int.compare (i1, i2));
193 (**)val int_ord = int_ord_SAVE; (*..outcomment for tests*)
195 subsubsection \<open>for predicates in specifications (ML)\<close>
197 (*--- auxiliary for is_expanded_in, is_poly_in, has_degree_in ---*)
198 (*. a "monomial t in variable v" is a term t with
199 either (1) v NOT existent in t, or (2) v contained in t,
201 if (2) then v is a factor on the very right, casually with exponent.*)
202 fun factor_right_deg (*case 2*)
203 (Const (\<^const_name>\<open>Groups.times_class.times\<close>, _) $
204 t1 $ (Const (\<^const_name>\<open>realpow\<close>,_) $ vv $ num)) v =
205 if vv = v andalso not (Prog_Expr.occurs_in v t1) then SOME (snd (HOLogic.dest_number num))
207 | factor_right_deg (Const (\<^const_name>\<open>realpow\<close>,_) $ vv $ num) v =
208 if (vv = v) then SOME (snd (HOLogic.dest_number num)) else NONE
210 | factor_right_deg (Const (\<^const_name>\<open>times\<close>,_) $ t1 $ vv) v =
211 if vv = v andalso not (Prog_Expr.occurs_in v t1) then SOME 1 else NONE
212 | factor_right_deg vv v =
213 if (vv = v) then SOME 1 else NONE;
214 fun mono_deg_in m v = (*case 1*)
215 if not (Prog_Expr.occurs_in v m) then (*case 1*) SOME 0 else factor_right_deg m v;
217 fun expand_deg_in t v =
219 fun edi ~1 ~1 (Const (\<^const_name>\<open>plus\<close>, _) $ t1 $ t2) =
220 (case mono_deg_in t2 v of (* $ is left associative*)
221 SOME d' => edi d' d' t1 | NONE => NONE)
222 | edi ~1 ~1 (Const (\<^const_name>\<open>minus\<close>, _) $ t1 $ t2) =
223 (case mono_deg_in t2 v of
224 SOME d' => edi d' d' t1 | NONE => NONE)
225 | edi d dmax (Const (\<^const_name>\<open>minus\<close>, _) $ t1 $ t2) =
226 (case mono_deg_in t2 v of (*(d = 0 andalso d' = 0) handle 3+4-...4 +x*)
227 SOME d' => if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
229 | edi d dmax (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
230 (case mono_deg_in t2 v of
231 SOME d' => (*RL (d = 0 andalso d' = 0) need to handle 3+4-...4 +x*)
232 if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
235 (case mono_deg_in t v of d as SOME _ => d | NONE => NONE)
236 | edi d dmax t = (*basecase last*)
237 (case mono_deg_in t v of
238 SOME d' => if d > d' orelse (d = 0 andalso d' = 0) then SOME dmax else NONE
242 fun poly_deg_in t v =
244 fun edi ~1 ~1 (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
245 (case mono_deg_in t2 v of (* $ is left associative *)
246 SOME d' => edi d' d' t1
248 | edi d dmax (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
249 (case mono_deg_in t2 v of
250 SOME d' => (*RL (d = 0 andalso (d' = 0)) handle 3+4-...4 +x*)
251 if d > d' orelse (d = 0 andalso d' = 0) then edi d' dmax t1 else NONE
254 (case mono_deg_in t v of
257 | edi d dmax t = (* basecase last *)
258 (case mono_deg_in t v of
260 if d > d' orelse (d = 0 andalso d' = 0) then SOME dmax else NONE
265 subsubsection \<open>for hard-coded AC rewriting (MG)\<close>
267 (**. MG.03: make_polynomial_ ... uses SML-fun for ordering .**)
269 (*FIXME.0401: make SML-order local to make_polynomial(_) *)
270 (*FIXME.0401: replace 'make_polynomial'(old) by 'make_polynomial_'(MG) *)
271 (* Polynom --> List von Monomen *)
272 fun poly2list (Const (\<^const_name>\<open>plus\<close>,_) $ t1 $ t2) =
273 (poly2list t1) @ (poly2list t2)
276 (* Monom --> Liste von Variablen *)
277 fun monom2list (Const (\<^const_name>\<open>times\<close>,_) $ t1 $ t2) =
278 (monom2list t1) @ (monom2list t2)
279 | monom2list t = [t];
281 (* liefert Variablenname (String) einer Variablen und Basis bei Potenz *)
282 fun get_basStr (Const (\<^const_name>\<open>realpow\<close>,_) $ Free (str, _) $ _) = str
283 | get_basStr (Const (\<^const_name>\<open>realpow\<close>,_) $ n $ _) = TermC.to_string n
284 | get_basStr (Free (str, _)) = str
286 if TermC.is_num t then TermC.to_string t
287 else "|||"; (* gross gewichtet; für Brüche ect. *)
289 (* liefert Hochzahl (String) einer Variablen bzw Gewichtstring (zum Sortieren) *)
290 fun get_potStr (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ Free (str, _)) = str
291 | get_potStr (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ t) =
292 if TermC.is_num t then TermC.to_string t else "|||"
293 | get_potStr (Free _) = "---" (* keine Hochzahl --> kleinst gewichtet *)
294 | get_potStr _ = "||||||"; (* gross gewichtet; für Brüch ect. *)
296 (* Umgekehrte string_ord *)
297 val string_ord_rev = rev_order o string_ord;
299 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen)
300 innerhalb eines Monomes:
301 - zuerst lexikographisch nach Variablenname
302 - wenn gleich: nach steigender Potenz *)
304 (@{print} {a = "var_ord ", a_b = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
305 sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
306 prod_ord string_ord string_ord
307 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
309 fun var_ord (a,b: term) =
310 prod_ord string_ord string_ord
311 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
313 (* Ordnung zum lexikographischen Vergleich zweier Variablen (oder Potenzen);
314 verwendet zum Sortieren von Monomen mittels Gesamtgradordnung:
315 - zuerst lexikographisch nach Variablenname
316 - wenn gleich: nach sinkender Potenz*)
317 fun var_ord_revPow (a, b: term) =
318 (@{print} {a = "var_ord_revPow ", at_bt = "(" ^ UnparseC.term a ^ ", " ^ UnparseC.term b ^ ")",
319 sort_args = "(" ^ get_basStr a ^ ", " ^ get_potStr a ^ "), (" ^ get_basStr b ^ ", " ^ get_potStr b ^ ")"};
320 prod_ord string_ord string_ord_rev
321 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b))
323 fun var_ord_revPow (a, b: term) =
324 prod_ord string_ord string_ord_rev
325 ((get_basStr a, get_potStr a), (get_basStr b, get_potStr b));
328 (* Ordnet ein Liste von Variablen (und Potenzen) lexikographisch *)
329 fun sort_varList ts =
330 (@{print} {a = "sort_varList", args = UnparseC.terms ts};
332 val sort_varList = sort var_ord;
334 (* Entfernet aeussersten Operator (Wurzel) aus einem Term und schreibt
335 Argumente in eine Liste *)
336 fun args u : term list =
338 fun stripc (f $ t, ts) = stripc (f, t::ts)
339 | stripc (t as Free _, ts) = (t::ts)
340 | stripc (_, ts) = ts
341 in stripc (u, []) end;
343 (* liefert True, falls der Term (Liste von Termen) nur Zahlen
344 (keine Variablen) enthaelt *)
345 fun filter_num ts = fold (curry and_) (map TermC.is_num ts) true
347 (* liefert True, falls der Term nur Zahlen (keine Variablen) enthaelt
348 dh. er ist ein numerischer Wert und entspricht einem Koeffizienten *)
349 fun is_nums t = filter_num [t];
351 (* Berechnet den Gesamtgrad eines Monoms *)
353 fun counter (n, []) = n
354 | counter (n, x :: xs) =
355 if (is_nums x) then counter (n, xs)
358 (Const (\<^const_name>\<open>realpow\<close>, _) $ Free _ $ t) =>
360 then counter (t |> HOLogic.dest_number |> snd |> curry op + n, xs)
361 else counter (n + 1000, xs) (*FIXME.MG?!*)
362 | (Const (\<^const_name>\<open>numeral\<close>, _) $ num) =>
363 counter (n + 1 + HOLogic.dest_numeral num, xs)
364 | _ => counter (n + 1, xs)) (*FIXME.MG?! ... Brüche ect.*)
366 fun monom_degree l = counter (0, l)
369 (* wie Ordnung dict_ord (lexicographische Ordnung zweier Listen, mit Vergleich
370 der Listen-Elemente mit elem_ord) - Elemente die Bedingung cond erfuellen,
371 werden jedoch dabei ignoriert (uebersprungen) *)
372 fun dict_cond_ord _ _ ([], []) = (@{print} {a = "dict_cond_ord ([], [])"}; EQUAL)
373 | dict_cond_ord _ _ ([], _ :: _) = (@{print} {a = "dict_cond_ord ([], _ :: _)"}; LESS)
374 | dict_cond_ord _ _ (_ :: _, []) = (@{print} {a = "dict_cond_ord (_ :: _, [])"}; GREATER)
375 | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
376 (@{print} {a = "dict_cond_ord", args = "(" ^ UnparseC.terms (x :: xs) ^ ", " ^ UnparseC.terms (y :: ys) ^ ")",
377 is_nums = "(" ^ LibraryC.bool2str (cond x) ^ ", " ^ LibraryC.bool2str (cond y) ^ ")"};
378 case (cond x, cond y) of
380 (case elem_ord (x, y) of
381 EQUAL => dict_cond_ord elem_ord cond (xs, ys)
383 | (false, true) => dict_cond_ord elem_ord cond (x :: xs, ys)
384 | (true, false) => dict_cond_ord elem_ord cond (xs, y :: ys)
385 | (true, true) => dict_cond_ord elem_ord cond (xs, ys) );
386 fun dict_cond_ord _ _ ([], []) = EQUAL
387 | dict_cond_ord _ _ ([], _ :: _) = LESS
388 | dict_cond_ord _ _ (_ :: _, []) = GREATER
389 | dict_cond_ord elem_ord cond (x :: xs, y :: ys) =
390 (case (cond x, cond y) of
392 (case elem_ord (x, y) of
393 EQUAL => dict_cond_ord elem_ord cond (xs, ys)
395 | (false, true) => dict_cond_ord elem_ord cond (x :: xs, ys)
396 | (true, false) => dict_cond_ord elem_ord cond (xs, y :: ys)
397 | (true, true) => dict_cond_ord elem_ord cond (xs, ys) );
399 (* Gesamtgradordnung zum Vergleich von Monomen (Liste von Variablen/Potenzen):
400 zuerst nach Gesamtgrad, bei gleichem Gesamtgrad lexikographisch ordnen -
401 dabei werden Koeffizienten ignoriert (2*3*a \<up> 2*4*b gilt wie a \<up> 2*b) *)
402 fun degree_ord (xs, ys) =
403 prod_ord int_ord (dict_cond_ord var_ord_revPow is_nums)
404 ((monom_degree xs, xs), (monom_degree ys, ys));
406 fun hd_str str = substring (str, 0, 1);
407 fun tl_str str = substring (str, 1, (size str) - 1);
409 (* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
410 fun get_koeff_of_mon [] = raise ERROR "get_koeff_of_mon: called with l = []"
411 | get_koeff_of_mon (x :: _) = if is_nums x then SOME x else NONE;
413 (* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
414 fun koeff2ordStr (SOME t) =
417 if (t |> HOLogic.dest_number |> snd) < 0
418 then (t |> HOLogic.dest_number |> snd |> curry op * ~1 |> string_of_int) ^ "0" (* 3 < -3 *)
419 else (t |> HOLogic.dest_number |> snd |> string_of_int)
420 else "aaa" (* "num.Ausdruck" --> gross *)
421 | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
423 (* Order zum Vergleich von Koeffizienten (strings):
424 "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
425 fun compare_koeff_ord (xs, ys) = string_ord
426 ((koeff2ordStr o get_koeff_of_mon) xs,
427 (koeff2ordStr o get_koeff_of_mon) ys);
429 (* Gesamtgradordnung degree_ord + Ordnen nach Koeffizienten falls EQUAL *)
430 fun koeff_degree_ord (xs, ys) =
431 prod_ord degree_ord compare_koeff_ord ((xs, xs), (ys, ys));
433 (* Ordnet ein Liste von Monomen (Monom = Liste von Variablen) mittels
435 val sort_monList = sort koeff_degree_ord;
437 (* Alternativ zu degree_ord koennte auch die viel einfachere und
438 kuerzere Ordnung simple_ord verwendet werden - ist aber nicht
439 fuer unsere Zwecke geeignet!
441 fun simple_ord (al,bl: term list) = dict_ord string_ord
442 (map get_basStr al, map get_basStr bl);
444 val sort_monList = sort simple_ord; *)
446 (* aus 2 Variablen wird eine Summe bzw ein Produkt erzeugt
447 (mit gewuenschtem Typen T) *)
448 fun plus T = Const (\<^const_name>\<open>plus\<close>, [T,T] ---> T);
449 fun mult T = Const (\<^const_name>\<open>times\<close>, [T,T] ---> T);
450 fun binop op_ t1 t2 = op_ $ t1 $ t2;
451 fun create_prod T (a,b) = binop (mult T) a b;
452 fun create_sum T (a,b) = binop (plus T) a b;
454 (* löscht letztes Element einer Liste *)
455 fun drop_last l = take ((length l)-1,l);
457 (* Liste von Variablen --> Monom *)
458 fun create_monom T vl = foldr (create_prod T) (drop_last vl, last_elem vl);
460 foldr bewirkt rechtslastige Klammerung des Monoms - ist notwendig, damit zwei
461 gleiche Monome zusammengefasst werden können (collect_numerals)!
462 zB: 2*(x*(y*z)) + 3*(x*(y*z)) --> (2+3)*(x*(y*z))*)
464 (* Liste von Monomen --> Polynom *)
465 fun create_polynom T ml = foldl (create_sum T) (hd ml, tl ml);
467 foldl bewirkt linkslastige Klammerung des Polynoms (der Summanten) -
468 bessere Darstellung, da keine Klammern sichtbar!
469 (und discard_parentheses in make_polynomial hat weniger zu tun) *)
471 (* sorts the variables (faktors) of an expanded polynomial lexicographical *)
472 fun sort_variables t =
474 val ll = map monom2list (poly2list t);
475 val lls = map sort_varList ll;
477 val ls = map (create_monom T) lls;
478 in create_polynom T ls end;
480 (* sorts the monoms of an expanded and variable-sorted polynomial
484 val ll = map monom2list (poly2list t);
485 val lls = sort_monList ll;
486 val T = Term.type_of t;
487 val ls = map (create_monom T) lls;
488 in create_polynom T ls end;
491 subsubsection \<open>rewrite order for hard-coded AC rewriting\<close>
493 local (*. for make_polynomial .*)
495 open Term; (* for type order = EQUAL | LESS | GREATER *)
497 fun pr_ord EQUAL = "EQUAL"
498 | pr_ord LESS = "LESS"
499 | pr_ord GREATER = "GREATER";
501 fun dest_hd' (Const (a, T)) = (* ~ term.ML *)
503 \<^const_name>\<open>realpow\<close> => ((("|||||||||||||", 0), T), 0) (*WN greatest string*)
504 | _ => (((a, 0), T), 0))
505 | dest_hd' (Free (a, T)) = (((a, 0), T), 1)(*TODOO handle this as numeral, too? see EqSystem.thy*)
506 | dest_hd' (Var v) = (v, 2)
507 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
508 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4)
509 | dest_hd' t = raise TERM ("dest_hd'", [t]);
511 fun size_of_term' (Const(str,_) $ t) =
512 if \<^const_name>\<open>realpow\<close>= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
513 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
514 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
515 | size_of_term' _ = 1;
517 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
518 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
519 | term_ord' pr thy (t, u) =
522 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
523 val _ = tracing ("t= f@ts= \"" ^ UnparseC.term_in_thy thy f ^ "\" @ \"[" ^
524 commas (map (UnparseC.term_in_thy thy) ts) ^ "]\"");
525 val _ = tracing("u= g@us= \"" ^ UnparseC.term_in_thy thy g ^ "\" @ \"[" ^
526 commas (map (UnparseC.term_in_thy thy) us) ^ "]\"");
527 val _ = tracing ("size_of_term(t,u)= (" ^ string_of_int (size_of_term' t) ^ ", " ^
528 string_of_int (size_of_term' u) ^ ")");
529 val _ = tracing ("hd_ord(f,g) = " ^ (pr_ord o hd_ord) (f,g));
530 val _ = tracing ("terms_ord(ts,us) = " ^ (pr_ord o terms_ord str false) (ts, us));
531 val _ = tracing ("-------");
534 case int_ord (size_of_term' t, size_of_term' u) of
536 let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
537 (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us)
541 and hd_ord (f, g) = (* ~ term.ML *)
542 prod_ord (prod_ord Term_Ord.indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
543 and terms_ord _ pr (ts, us) =
544 list_ord (term_ord' pr (ThyC.get_theory "Isac_Knowledge"))(ts, us);
548 fun ord_make_polynomial (pr:bool) thy (_: subst) (ts, us) =
549 (term_ord' pr thy(***) (TermC.numerals_to_Free ts, TermC.numerals_to_Free us) = LESS );
553 setup \<open>KEStore_Elems.add_rew_ord [
554 ("termlessI", termlessI),
555 ("ord_make_polynomial", ord_make_polynomial false \<^theory>)]\<close>
557 subsection \<open>predicates\<close>
558 subsubsection \<open>in specifications\<close>
560 (* is_polyrat_in becomes true, if no bdv is in the denominator of a fraction*)
561 fun is_polyrat_in t v =
563 fun finddivide (_ $ _ $ _ $ _) _ = raise ERROR("is_polyrat_in:")
564 (* at the moment there is no term like this, but ....*)
565 | finddivide (Const (\<^const_name>\<open>divide\<close>,_) $ _ $ b) v = not (Prog_Expr.occurs_in v b)
566 | finddivide (_ $ t1 $ t2) v = finddivide t1 v orelse finddivide t2 v
567 | finddivide (_ $ t1) v = finddivide t1 v
568 | finddivide _ _ = false;
569 in finddivide t v end;
571 fun is_expanded_in t v = case expand_deg_in t v of SOME _ => true | NONE => false;
572 fun is_poly_in t v = case poly_deg_in t v of SOME _ => true | NONE => false;
573 fun has_degree_in t v = case expand_deg_in t v of SOME d => d | NONE => ~1;
575 (*.the expression contains + - * ^ only ?
576 this is weaker than 'is_polynomial' !.*)
577 fun is_polyexp (Free _) = true
578 | is_polyexp (Const _) = true (* potential danger: bdv is not considered *)
579 | is_polyexp (Const (\<^const_name>\<open>plus\<close>,_) $ Free _ $ num) =
580 if TermC.is_num num then true
581 else if TermC.is_variable num then true
583 | is_polyexp (Const (\<^const_name>\<open>plus\<close>, _) $ num $ Free _) =
584 if TermC.is_num num then true
585 else if TermC.is_variable num then true
587 | is_polyexp (Const (\<^const_name>\<open>minus\<close>, _) $ Free _ $ num) =
588 if TermC.is_num num then true
589 else if TermC.is_variable num then true
591 | is_polyexp (Const (\<^const_name>\<open>times\<close>, _) $ num $ Free _) =
592 if TermC.is_num num then true
593 else if TermC.is_variable num then true
595 | is_polyexp (Const (\<^const_name>\<open>realpow\<close>,_) $ Free _ $ num) =
596 if TermC.is_num num then true
597 else if TermC.is_variable num then true
599 | is_polyexp (Const (\<^const_name>\<open>plus_class.plus\<close>,_) $ t1 $ t2) =
600 ((is_polyexp t1) andalso (is_polyexp t2))
601 | is_polyexp (Const (\<^const_name>\<open>Groups.minus_class.minus\<close>,_) $ t1 $ t2) =
602 ((is_polyexp t1) andalso (is_polyexp t2))
603 | is_polyexp (Const (\<^const_name>\<open>Groups.times_class.times\<close>,_) $ t1 $ t2) =
604 ((is_polyexp t1) andalso (is_polyexp t2))
605 | is_polyexp (Const (\<^const_name>\<open>realpow\<close>,_) $ t1 $ t2) =
606 ((is_polyexp t1) andalso (is_polyexp t2))
607 | is_polyexp num = TermC.is_num num;
610 subsubsection \<open>for hard-coded AC rewriting\<close>
612 (* auch Klammerung muss übereinstimmen;
613 sort_variables klammert Produkte rechtslastig*)
614 fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
616 fun is_addUnordered t = ((is_polyexp t) andalso not (t = sort_monoms t));
619 subsection \<open>evaluations functions\<close>
620 subsubsection \<open>for predicates\<close>
622 fun eval_is_polyrat_in _ _(p as (Const (\<^const_name>\<open>Poly.is_polyrat_in\<close>, _) $ t $ v)) _ =
624 then SOME ((UnparseC.term p) ^ " = True",
625 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
626 else SOME ((UnparseC.term p) ^ " = True",
627 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
628 | eval_is_polyrat_in _ _ _ _ = ((*tracing"### no matches";*) NONE);
630 (*("is_expanded_in", ("Poly.is_expanded_in", eval_is_expanded_in ""))*)
631 fun eval_is_expanded_in _ _
632 (p as (Const (\<^const_name>\<open>Poly.is_expanded_in\<close>, _) $ t $ v)) _ =
633 if is_expanded_in t v
634 then SOME ((UnparseC.term p) ^ " = True",
635 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
636 else SOME ((UnparseC.term p) ^ " = True",
637 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
638 | eval_is_expanded_in _ _ _ _ = NONE;
640 (*("is_poly_in", ("Poly.is_poly_in", eval_is_poly_in ""))*)
641 fun eval_is_poly_in _ _
642 (p as (Const (\<^const_name>\<open>Poly.is_poly_in\<close>, _) $ t $ v)) _ =
644 then SOME ((UnparseC.term p) ^ " = True",
645 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
646 else SOME ((UnparseC.term p) ^ " = True",
647 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
648 | eval_is_poly_in _ _ _ _ = NONE;
650 (*("has_degree_in", ("Poly.has_degree_in", eval_has_degree_in ""))*)
651 fun eval_has_degree_in _ _
652 (p as (Const (\<^const_name>\<open>Poly.has_degree_in\<close>, _) $ t $ v)) _ =
653 let val d = has_degree_in t v
654 val d' = TermC.term_of_num HOLogic.realT d
655 in SOME ((UnparseC.term p) ^ " = " ^ (string_of_int d),
656 HOLogic.Trueprop $ (TermC.mk_equality (p, d')))
658 | eval_has_degree_in _ _ _ _ = NONE;
660 (*("is_polyexp", ("Poly.is_polyexp", eval_is_polyexp ""))*)
661 fun eval_is_polyexp (thmid:string) _
662 (t as (Const (\<^const_name>\<open>is_polyexp\<close>, _) $ arg)) ctxt =
664 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
665 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
666 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
667 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
668 | eval_is_polyexp _ _ _ _ = NONE;
671 subsubsection \<open>for hard-coded AC rewriting\<close>
674 (*("is_addUnordered", ("Poly.is_addUnordered", eval_is_addUnordered ""))*)
675 fun eval_is_addUnordered (thmid:string) _
676 (t as (Const (\<^const_name>\<open>is_addUnordered\<close>, _) $ arg)) ctxt =
677 if is_addUnordered arg
678 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
679 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
680 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
681 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
682 | eval_is_addUnordered _ _ _ _ = NONE;
684 fun eval_is_multUnordered (thmid:string) _
685 (t as (Const (\<^const_name>\<open>is_multUnordered\<close>, _) $ arg)) ctxt =
686 if is_multUnordered arg
687 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
688 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True})))
689 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_ctxt ctxt arg) "",
690 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False})))
691 | eval_is_multUnordered _ _ _ _ = NONE;
693 calculation is_polyrat_in = \<open>eval_is_polyrat_in "#eval_is_polyrat_in"\<close>
694 calculation is_expanded_in = \<open>eval_is_expanded_in ""\<close>
695 calculation is_poly_in = \<open>eval_is_poly_in ""\<close>
696 calculation has_degree_in = \<open>eval_has_degree_in ""\<close>
697 calculation is_polyexp = \<open>eval_is_polyexp ""\<close>
698 calculation is_multUnordered = \<open>eval_is_multUnordered ""\<close>
699 calculation is_addUnordered = \<open>eval_is_addUnordered ""\<close>
701 subsection \<open>rule-sets\<close>
702 subsubsection \<open>without specific order\<close>
704 (* used only for merge *)
705 val calculate_Poly = Rule_Set.append_rules "calculate_PolyFIXXXME.not.impl." Rule_Set.empty [];
707 (*.for evaluation of conditions in rewrite rules.*)
708 val Poly_erls = Rule_Set.append_rules "Poly_erls" Atools_erls [
709 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
710 \<^rule_thm>\<open>real_unari_minus\<close>,
711 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
712 \<^rule_eval>\<open>minus\<close> (eval_binop "#sub_"),
713 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
714 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_")];
716 val poly_crls = Rule_Set.append_rules "poly_crls" Atools_crls [
717 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
718 \<^rule_thm>\<open>real_unari_minus\<close>,
719 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
720 \<^rule_eval>\<open>minus\<close> (eval_binop "#sub_"),
721 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
722 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_")];
726 Rule_Def.Repeat {id = "expand", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
727 erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
729 \<^rule_thm>\<open>distrib_right\<close>, (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
730 \<^rule_thm>\<open>distrib_left\<close> (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)],
731 scr = Rule.Empty_Prog};
734 \<close> ML \<open>@{term "1 is_num"}\<close>
736 (* erls for calculate_Rational + etc *)
738 Rule_Def.Repeat {id = "powers_erls", preconds = [], rew_ord = ("dummy_ord",Rewrite_Ord.function_empty),
739 erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
741 \<^rule_eval>\<open>matches\<close> (Prog_Expr.eval_matches "#matches_"),
742 \<^rule_eval>\<open>is_atom\<close> (Prog_Expr.eval_is_atom "#is_atom_"),
743 \<^rule_eval>\<open>is_num\<close> (Prog_Expr.eval_is_num "#is_num_"),
744 \<^rule_eval>\<open>is_even\<close> (Prog_Expr.eval_is_even "#is_even_"),
745 \<^rule_eval>\<open>ord_class.less\<close> (Prog_Expr.eval_equ "#less_"),
746 \<^rule_thm>\<open>not_false\<close>,
747 \<^rule_thm>\<open>not_true\<close>,
748 \<^rule_eval>\<open>plus_class.plus\<close> (eval_binop "#add_")],
749 scr = Rule.Empty_Prog};
753 Rule_Def.Repeat {id = "discard_minus", preconds = [], rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
754 erls = powers_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
756 \<^rule_thm>\<open>real_diff_minus\<close> (*"a - b = a + -1 * b"*),
757 \<^rule_thm>\<open>real_mult_minus1_sym\<close> (*"\<not>(z is_num) ==> - (z::real) = -1 * z"*)],
758 scr = Rule.Empty_Prog};
761 Rule_Def.Repeat{id = "expand_poly_", preconds = [],
762 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
763 erls = powers_erls, srls = Rule_Set.Empty,
764 calc = [], errpatts = [],
766 \<^rule_thm>\<open>real_plus_binom_pow4\<close>, (*"(a + b) \<up> 4 = ... "*)
767 \<^rule_thm>\<open>real_plus_binom_pow5\<close>, (*"(a + b) \<up> 5 = ... "*)
768 \<^rule_thm>\<open>real_plus_binom_pow3\<close>, (*"(a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" *)
769 (*WN071229 changed/removed for Schaerding -----vvv*)
770 (*\<^rule_thm>\<open>real_plus_binom_pow2\<close>,*) (*"(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
771 \<^rule_thm>\<open>real_plus_binom_pow2\<close>, (*"(a + b) \<up> 2 = (a + b) * (a + b)"*)
772 (*\<^rule_thm>\<open>real_plus_minus_binom1_p_p\<close>,*) (*"(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2"*)
773 (*\<^rule_thm>\<open>real_plus_minus_binom2_p_p\<close>,*) (*"(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
774 (*WN071229 changed/removed for Schaerding -----^^^*)
776 \<^rule_thm>\<open>distrib_right\<close>, (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
777 \<^rule_thm>\<open>distrib_left\<close>, (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
779 \<^rule_thm>\<open>realpow_multI\<close>, (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
780 \<^rule_thm>\<open>realpow_pow\<close>, (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
782 \<^rule_thm>\<open>realpow_minus_even\<close>, (*"n is_even ==> (- r) \<up> n = r \<up> n"*)
783 \<^rule_thm>\<open>realpow_minus_odd\<close> (*"Not (n is_even) ==> (- r) \<up> n = -1 * r \<up> n"*)],
784 scr = Rule.Empty_Prog};
786 val expand_poly_rat_ =
787 Rule_Def.Repeat{id = "expand_poly_rat_", preconds = [],
788 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
789 erls = Rule_Set.append_rules "Rule_Set.empty-expand_poly_rat_" Rule_Set.empty [
790 \<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp ""),
791 \<^rule_eval>\<open>is_even\<close> (Prog_Expr.eval_is_even "#is_even_"),
792 \<^rule_thm>\<open>not_false\<close>,
793 \<^rule_thm>\<open>not_true\<close> ],
794 srls = Rule_Set.Empty,
795 calc = [], errpatts = [],
797 \<^rule_thm>\<open>real_plus_binom_pow4_poly\<close>, (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 4 = ... "*)
798 \<^rule_thm>\<open>real_plus_binom_pow5_poly\<close>, (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 5 = ... "*)
799 \<^rule_thm>\<open>real_plus_binom_pow2_poly\<close>, (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
800 \<^rule_thm>\<open>real_plus_binom_pow3_poly\<close>,
801 (*"[| a is_polyexp; b is_polyexp |] ==> (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3" *)
802 \<^rule_thm>\<open>real_plus_minus_binom1_p_p\<close>, (*"(a + b)*(a + -1 * b) = a \<up> 2 + -1*b \<up> 2"*)
803 \<^rule_thm>\<open>real_plus_minus_binom2_p_p\<close>, (*"(a + -1 * b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
805 \<^rule_thm>\<open>real_add_mult_distrib_poly\<close>, (*"w is_polyexp ==> (z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
806 \<^rule_thm>\<open>real_add_mult_distrib2_poly\<close>, (*"w is_polyexp ==> w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
808 \<^rule_thm>\<open>realpow_multI_poly\<close>, (*"[| r is_polyexp; s is_polyexp |] ==> (r * s) \<up> n = r \<up> n * s \<up> n"*)
809 \<^rule_thm>\<open>realpow_pow\<close>, (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
810 \<^rule_thm>\<open>realpow_minus_even\<close>, (*"n is_even ==> (- r) \<up> n = r \<up> n"*)
811 \<^rule_thm>\<open>realpow_minus_odd\<close> (*"\<not> (n is_even) ==> (- r) \<up> n = -1 * r \<up> n"*) ],
812 scr = Rule.Empty_Prog};
814 val simplify_power_ =
815 Rule_Def.Repeat{id = "simplify_power_", preconds = [],
816 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
817 erls = Rule_Set.empty, srls = Rule_Set.Empty,
818 calc = [], errpatts = [],
820 (*MG: Reihenfolge der folgenden 2 Rule.Thm muss so bleiben, wegen
821 a*(a*a) --> a*a \<up> 2 und nicht a*(a*a) --> a \<up> 2*a *)
822 \<^rule_thm_sym>\<open>realpow_twoI\<close>, (*"r * r = r \<up> 2"*)
823 \<^rule_thm>\<open>realpow_twoI_assoc_l\<close>, (*"r * (r * s) = r \<up> 2 * s"*)
825 \<^rule_thm>\<open>realpow_plus_1\<close>, (*"r * r \<up> n = r \<up> (n + 1)"*)
826 \<^rule_thm>\<open>realpow_plus_1_assoc_l\<close>, (*"r * (r \<up> m * s) = r \<up> (1 + m) * s"*)
827 (*MG 9.7.03: neues Rule.Thm wegen a*(a*(a*b)) --> a \<up> 2*(a*b) *)
828 \<^rule_thm>\<open>realpow_plus_1_assoc_l2\<close>, (*"r \<up> m * (r * s) = r \<up> (1 + m) * s"*)
830 \<^rule_thm_sym>\<open>realpow_addI\<close>, (*"r \<up> n * r \<up> m = r \<up> (n + m)"*)
831 \<^rule_thm>\<open>realpow_addI_assoc_l\<close>, (*"r \<up> n * (r \<up> m * s) = r \<up> (n + m) * s"*)
833 (* ist in expand_poly - wird hier aber auch gebraucht, wegen: "r * r = r \<up> 2" wenn r=a \<up> b*)
834 \<^rule_thm>\<open>realpow_pow\<close> (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)],
835 scr = Rule.Empty_Prog};
837 val calc_add_mult_pow_ =
838 Rule_Def.Repeat{id = "calc_add_mult_pow_", preconds = [],
839 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
840 erls = Atools_erls(*erls3.4.03*),srls = Rule_Set.Empty,
841 calc = [("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
842 ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
843 ("POWER", (\<^const_name>\<open>realpow\<close>, eval_binop "#power_"))
847 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
848 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
849 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_")],
850 scr = Rule.Empty_Prog};
852 val reduce_012_mult_ =
853 Rule_Def.Repeat{id = "reduce_012_mult_", preconds = [],
854 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
855 erls = Rule_Set.empty,srls = Rule_Set.Empty,
856 calc = [], errpatts = [],
857 rules = [(* MG: folgende Rule.Thm müssen hier stehen bleiben: *)
858 \<^rule_thm>\<open>mult_1_right\<close>, (*"z * 1 = z"*) (*wegen "a * b * b \<up> (-1) + a"*)
859 \<^rule_thm>\<open>realpow_zeroI\<close>, (*"r \<up> 0 = 1"*) (*wegen "a*a \<up> (-1)*c + b + c"*)
860 \<^rule_thm>\<open>realpow_oneI\<close>, (*"r \<up> 1 = r"*)
861 \<^rule_thm>\<open>realpow_eq_oneI\<close> (*"1 \<up> n = 1"*)],
862 scr = Rule.Empty_Prog};
864 val collect_numerals_ =
865 Rule_Def.Repeat{id = "collect_numerals_", preconds = [],
866 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
867 erls = Atools_erls, srls = Rule_Set.Empty,
868 calc = [("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_"))
871 \<^rule_thm>\<open>real_num_collect\<close>, (*"[| l is_num; m is_num |]==>l * n + m * n = (l + m) * n"*)
872 \<^rule_thm>\<open>real_num_collect_assoc_r\<close>,
873 (*"[| l is_num; m is_num |] ==> (k + m * n) + l * n = k + (l + m)*n"*)
874 \<^rule_thm>\<open>real_one_collect\<close>, (*"m is_num ==> n + m * n = (1 + m) * n"*)
875 \<^rule_thm>\<open>real_one_collect_assoc_r\<close>, (*"m is_num ==> (k + n) + m * n = k + (m + 1) * n"*)
877 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
879 (*MG: Reihenfolge der folgenden 2 Rule.Thm muss so bleiben, wegen
880 (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
881 \<^rule_thm>\<open>real_mult_2_assoc_r\<close>, (*"(k + z1) + z1 = k + 2 * z1"*)
882 \<^rule_thm_sym>\<open>real_mult_2\<close> (*"z1 + z1 = 2 * z1"*)],
883 scr = Rule.Empty_Prog};
886 Rule_Def.Repeat{id = "reduce_012_", preconds = [],
887 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
888 erls = Rule_Set.empty,srls = Rule_Set.Empty, calc = [], errpatts = [],
890 \<^rule_thm>\<open>mult_1_left\<close>, (*"1 * z = z"*)
891 \<^rule_thm>\<open>mult_zero_left\<close>, (*"0 * z = 0"*)
892 \<^rule_thm>\<open>mult_zero_right\<close>, (*"z * 0 = 0"*)
893 \<^rule_thm>\<open>add_0_left\<close>, (*"0 + z = z"*)
894 \<^rule_thm>\<open>add_0_right\<close>, (*"z + 0 = z"*) (*wegen a+b-b --> a+(1-1)*b --> a+0 --> a*)
896 (*\<^rule_thm>\<open>realpow_oneI\<close>*) (*"?r \<up> 1 = ?r"*)
897 \<^rule_thm>\<open>division_ring_divide_zero\<close> (*"0 / ?x = 0"*)],
898 scr = Rule.Empty_Prog};
900 val discard_parentheses1 =
901 Rule_Set.append_rules "discard_parentheses1" Rule_Set.empty [
902 \<^rule_thm_sym>\<open>mult.assoc\<close> (*"?z1.1 * (?z2.1 * ?z3.1) = ?z1.1 * ?z2.1 * ?z3.1"*)
903 (*\<^rule_thm_sym>\<open>add.assoc\<close>*) (*"?z1.1 + (?z2.1 + ?z3.1) = ?z1.1 + ?z2.1 + ?z3.1"*)];
906 Rule_Def.Repeat{id = "expand_poly", preconds = [],
907 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
908 erls = powers_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
910 \<^rule_thm>\<open>distrib_right\<close>, (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
911 \<^rule_thm>\<open>distrib_left\<close>, (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
913 \<^rule_thm>\<open>real_plus_binom_pow2\<close>, (*"(a + b) \<up> 2 = a \<up> 2 + 2*a*b + b \<up> 2"*)
914 \<^rule_thm>\<open>real_minus_binom_pow2_p\<close>, (*"(a - b) \<up> 2 = a \<up> 2 + -2*a*b + b \<up> 2"*)
915 \<^rule_thm>\<open>real_plus_minus_binom1_p\<close>, (*"(a + b)*(a - b) = a \<up> 2 + -1*b \<up> 2"*)
916 \<^rule_thm>\<open>real_plus_minus_binom2_p\<close>, (*"(a - b)*(a + b) = a \<up> 2 + -1*b \<up> 2"*)
918 \<^rule_thm>\<open>minus_minus\<close> (*"- (- ?z) = ?z"*),
919 \<^rule_thm>\<open>real_diff_minus\<close> (*"a - b = a + -1 * b"*),
920 \<^rule_thm>\<open>real_mult_minus1_sym\<close> (*"\<not>(z is_num) ==> - (z::real) = -1 * z"*)
922 (*\<^rule_thm>\<open>real_minus_add_distrib\<close>,*) (*"- (?x + ?y) = - ?x + - ?y"*)
923 (*\<^rule_thm>\<open>real_diff_plus\<close>*) (*"a - b = a + -b"*)],
924 scr = Rule.Empty_Prog};
927 Rule_Def.Repeat{id = "simplify_power", preconds = [],
928 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
929 erls = Rule_Set.empty, srls = Rule_Set.Empty,
930 calc = [], errpatts = [],
932 \<^rule_thm>\<open>realpow_multI\<close>, (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
934 \<^rule_thm_sym>\<open>realpow_twoI\<close>, (*"r1 * r1 = r1 \<up> 2"*)
935 \<^rule_thm>\<open>realpow_plus_1\<close>, (*"r * r \<up> n = r \<up> (n + 1)"*)
936 \<^rule_thm>\<open>realpow_pow\<close>, (*"(a \<up> b) \<up> c = a \<up> (b * c)"*)
937 \<^rule_thm_sym>\<open>realpow_addI\<close>, (*"r \<up> n * r \<up> m = r \<up> (n + m)"*)
938 \<^rule_thm>\<open>realpow_oneI\<close>, (*"r \<up> 1 = r"*)
939 \<^rule_thm>\<open>realpow_eq_oneI\<close> (*"1 \<up> n = 1"*)],
940 scr = Rule.Empty_Prog};
942 val collect_numerals =
943 Rule_Def.Repeat{id = "collect_numerals", preconds = [],
944 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
945 erls = Atools_erls(*erls3.4.03*),srls = Rule_Set.Empty,
946 calc = [("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
947 ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
948 ("POWER", (\<^const_name>\<open>realpow\<close>, eval_binop "#power_"))
951 \<^rule_thm>\<open>real_num_collect\<close>, (*"[| l is_num; m is_num |]==>l * n + m * n = (l + m) * n"*)
952 \<^rule_thm>\<open>real_num_collect_assoc\<close>,
953 (*"[| l is_num; m is_num |] ==> l * n + (m * n + k) = (l + m) * n + k"*)
954 \<^rule_thm>\<open>real_one_collect\<close>, (*"m is_num ==> n + m * n = (1 + m) * n"*)
955 \<^rule_thm>\<open>real_one_collect_assoc\<close>, (*"m is_num ==> k + (n + m * n) = k + (1 + m) * n"*)
956 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
957 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
958 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_")],
959 scr = Rule.Empty_Prog};
961 Rule_Def.Repeat{id = "reduce_012", preconds = [],
962 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
963 erls = Rule_Set.append_rules "erls_in_reduce_012" Rule_Set.empty [
964 \<^rule_eval>\<open>is_num\<close> (Prog_Expr.eval_is_num "#is_num_"),
965 \<^rule_thm>\<open>not_false\<close>,
966 \<^rule_thm>\<open>not_true\<close>],
967 srls = Rule_Set.Empty, calc = [], errpatts = [],
969 \<^rule_thm>\<open>mult_1_left\<close>, (*"1 * z = z"*)
970 (*\<^rule_thm>\<open>real_mult_minus1\<close>,14.3.03*) (*"-1 * z = - z"*)
971 \<^rule_thm>\<open>real_minus_mult_left\<close>, (*"\<not> ((a::real) is_num) ==> (- a) * b = - (a * b)"*)
972 (*\<^rule_thm>\<open>real_minus_mult_cancel\<close>, (*"- ?x * - ?y = ?x * ?y"*)---*)
973 \<^rule_thm>\<open>mult_zero_left\<close>, (*"0 * z = 0"*)
974 \<^rule_thm>\<open>add_0_left\<close>, (*"0 + z = z"*)
975 \<^rule_thm>\<open>add_0_right\<close>, (*"a + - a = 0"*)
976 \<^rule_thm>\<open>right_minus\<close>, (*"?z + - ?z = 0"*)
977 \<^rule_thm_sym>\<open>real_mult_2\<close>, (*"z1 + z1 = 2 * z1"*)
978 \<^rule_thm>\<open>real_mult_2_assoc\<close> (*"z1 + (z1 + k) = 2 * z1 + k"*)],
979 scr = Rule.Empty_Prog};
981 val discard_parentheses =
982 Rule_Set.append_rules "discard_parentheses" Rule_Set.empty
983 [\<^rule_thm_sym>\<open>mult.assoc\<close>, \<^rule_thm_sym>\<open>add.assoc\<close>];
986 subsubsection \<open>hard-coded AC rewriting\<close>
988 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
989 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
991 Rule_Def.Repeat{id = "order_add_mult", preconds = [],
992 rew_ord = ("ord_make_polynomial", ord_make_polynomial false \<^theory>),
993 erls = Rule_Set.empty,srls = Rule_Set.Empty,
994 calc = [], errpatts = [],
996 \<^rule_thm>\<open>mult.commute\<close>, (* z * w = w * z *)
997 \<^rule_thm>\<open>real_mult_left_commute\<close>, (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
998 \<^rule_thm>\<open>mult.assoc\<close>, (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
999 \<^rule_thm>\<open>add.commute\<close>, (*z + w = w + z*)
1000 \<^rule_thm>\<open>add.left_commute\<close>, (*x + (y + z) = y + (x + z)*)
1001 \<^rule_thm>\<open>add.assoc\<close> (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)],
1002 scr = Rule.Empty_Prog};
1003 (*MG.0401: termorders for multivariate polys dropped due to principal problems:
1004 (total-degree-)ordering of monoms NOT possible with size_of_term GIVEN*)
1006 Rule_Def.Repeat{id = "order_mult", preconds = [],
1007 rew_ord = ("ord_make_polynomial",ord_make_polynomial false \<^theory>),
1008 erls = Rule_Set.empty,srls = Rule_Set.Empty,
1009 calc = [], errpatts = [],
1011 \<^rule_thm>\<open>mult.commute\<close>, (* z * w = w * z *)
1012 \<^rule_thm>\<open>real_mult_left_commute\<close>, (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
1013 \<^rule_thm>\<open>mult.assoc\<close> (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)],
1014 scr = Rule.Empty_Prog};
1017 fun attach_form (_: Rule.rule list list) (_: term) (_: term) = (*still missing*)
1018 []:(Rule.rule * (term * term list)) list;
1019 fun init_state (_: term) = Rule_Set.e_rrlsstate;
1020 fun locate_rule (_: Rule.rule list list) (_: term) (_: Rule.rule) =
1021 ([]:(Rule.rule * (term * term list)) list);
1022 fun next_rule (_: Rule.rule list list) (_: term) = (NONE: Rule.rule option);
1023 fun normal_form t = SOME (sort_variables t, []: term list);
1026 Rule_Set.Rrls {id = "order_mult_",
1028 (* ?p matched with the current term gives an environment,
1029 which evaluates (the instantiated) "?p is_multUnordered" to true *)
1030 [([TermC.parse_patt \<^theory> "?p is_multUnordered"],
1031 TermC.parse_patt \<^theory> "?p :: real")],
1032 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1033 erls = Rule_Set.append_rules "Rule_Set.empty-is_multUnordered" Rule_Set.empty
1034 [\<^rule_eval>\<open>is_multUnordered\<close> (eval_is_multUnordered "")],
1035 calc = [("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
1036 ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
1037 ("DIVIDE", (\<^const_name>\<open>divide\<close>, Prog_Expr.eval_cancel "#divide_e")),
1038 ("POWER" , (\<^const_name>\<open>realpow\<close>, eval_binop "#power_"))],
1040 scr = Rule.Rfuns {init_state = init_state,
1041 normal_form = normal_form,
1042 locate_rule = locate_rule,
1043 next_rule = next_rule,
1044 attach_form = attach_form}};
1045 val order_mult_rls_ =
1046 Rule_Def.Repeat {id = "order_mult_rls_", preconds = [],
1047 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1048 erls = Rule_Set.empty,srls = Rule_Set.Empty,
1049 calc = [], errpatts = [],
1051 Rule.Rls_ order_mult_],
1052 scr = Rule.Empty_Prog};
1056 fun attach_form (_: Rule.rule list list) (_: term) (_: term) = (*still missing*)
1057 []: (Rule.rule * (term * term list)) list;
1058 fun init_state (_: term) = Rule_Set.e_rrlsstate;
1059 fun locate_rule (_: Rule.rule list list) (_: term) (_: Rule.rule) =
1060 ([]: (Rule.rule * (term * term list)) list);
1061 fun next_rule (_: Rule.rule list list) (_: term) = (NONE: Rule.rule option);
1062 fun normal_form t = SOME (sort_monoms t,[]: term list);
1065 Rule_Set.Rrls {id = "order_add_",
1066 prepat = [(*WN.18.6.03 Preconditions und Pattern,
1067 die beide passen muessen, damit das Rule_Set.Rrls angewandt wird*)
1068 ([TermC.parse_patt @{theory} "?p is_addUnordered"],
1069 TermC.parse_patt @{theory} "?p :: real"
1070 (*WN.18.6.03 also KEIN pattern, dieses erzeugt nur das Environment
1071 fuer die Evaluation der Precondition "p is_addUnordered"*))],
1072 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1073 erls = Rule_Set.append_rules "Rule_Set.empty-is_addUnordered" Rule_Set.empty(*MG: poly_erls*)
1074 [\<^rule_eval>\<open>is_addUnordered\<close> (eval_is_addUnordered "")],
1076 ("PLUS" ,(\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
1077 ("TIMES" ,(\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
1078 ("DIVIDE",(\<^const_name>\<open>divide\<close>, Prog_Expr.eval_cancel "#divide_e")),
1079 ("POWER" ,(\<^const_name>\<open>realpow\<close> , eval_binop "#power_"))],
1082 init_state = init_state,
1083 normal_form = normal_form,
1084 locate_rule = locate_rule,
1085 next_rule = next_rule,
1086 attach_form = attach_form}};
1088 val order_add_rls_ =
1089 Rule_Def.Repeat {id = "order_add_rls_", preconds = [],
1090 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1091 erls = Rule_Set.empty, srls = Rule_Set.Empty,
1092 calc = [], errpatts = [],
1094 Rule.Rls_ order_add_],
1095 scr = Rule.Empty_Prog};
1098 text \<open>rule-set make_polynomial also named norm_Poly:
1099 Rewrite order has not been implemented properly; the order is better in
1100 make_polynomial_in (coded in SML).
1101 Notes on state of development:
1102 \# surprise 2006: test --- norm_Poly NOT COMPLETE ---
1103 \# migration Isabelle2002 --> 2011 weakened the rule set, see test
1104 --- Matthias Goldgruber 2003 rewrite orders ---, raise ERROR "ord_make_polynomial_in #16b"
1107 (*. see MG-DA.p.52ff .*)
1108 val make_polynomial(*MG.03, overwrites version from above,
1109 previously 'make_polynomial_'*) =
1110 Rule_Set.Sequence {id = "make_polynomial", preconds = []:term list,
1111 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1112 erls = Atools_erls, srls = Rule_Set.Empty,calc = [], errpatts = [],
1114 Rule.Rls_ discard_minus,
1115 Rule.Rls_ expand_poly_,
1116 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1117 Rule.Rls_ order_mult_rls_,
1118 Rule.Rls_ simplify_power_,
1119 Rule.Rls_ calc_add_mult_pow_,
1120 Rule.Rls_ reduce_012_mult_,
1121 Rule.Rls_ order_add_rls_,
1122 Rule.Rls_ collect_numerals_,
1123 Rule.Rls_ reduce_012_,
1124 Rule.Rls_ discard_parentheses1],
1125 scr = Rule.Empty_Prog};
1128 val norm_Poly(*=make_polynomial*) =
1129 Rule_Set.Sequence {id = "norm_Poly", preconds = []:term list,
1130 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1131 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
1133 Rule.Rls_ discard_minus,
1134 Rule.Rls_ expand_poly_,
1135 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1136 Rule.Rls_ order_mult_rls_,
1137 Rule.Rls_ simplify_power_,
1138 Rule.Rls_ calc_add_mult_pow_,
1139 Rule.Rls_ reduce_012_mult_,
1140 Rule.Rls_ order_add_rls_,
1141 Rule.Rls_ collect_numerals_,
1142 Rule.Rls_ reduce_012_,
1143 Rule.Rls_ discard_parentheses1],
1144 scr = Rule.Empty_Prog};
1147 (* MG:03 Like make_polynomial_ but without Rule.Rls_ discard_parentheses1
1148 and expand_poly_rat_ instead of expand_poly_, see MG-DA.p.56ff*)
1149 (* MG necessary for termination of norm_Rational(*_mg*) in Rational.ML*)
1150 val make_rat_poly_with_parentheses =
1151 Rule_Set.Sequence{id = "make_rat_poly_with_parentheses", preconds = []:term list,
1152 rew_ord = ("dummy_ord", Rewrite_Ord.function_empty),
1153 erls = Atools_erls, srls = Rule_Set.Empty, calc = [], errpatts = [],
1155 Rule.Rls_ discard_minus,
1156 Rule.Rls_ expand_poly_rat_,(*ignors rationals*)
1157 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1158 Rule.Rls_ order_mult_rls_,
1159 Rule.Rls_ simplify_power_,
1160 Rule.Rls_ calc_add_mult_pow_,
1161 Rule.Rls_ reduce_012_mult_,
1162 Rule.Rls_ order_add_rls_,
1163 Rule.Rls_ collect_numerals_,
1164 Rule.Rls_ reduce_012_
1165 (*Rule.Rls_ discard_parentheses1 *)],
1166 scr = Rule.Empty_Prog};
1169 (*.a minimal ruleset for reverse rewriting of factions [2];
1170 compare expand_binoms.*)
1172 Rule_Set.Sequence{id = "rev_rew_p", preconds = [], rew_ord = ("termlessI",termlessI),
1173 erls = Atools_erls, srls = Rule_Set.Empty,
1174 calc = [(*("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
1175 ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
1176 ("POWER", (\<^const_name>\<open>realpow\<close>, eval_binop "#power_"))*)
1179 \<^rule_thm>\<open>real_plus_binom_times\<close>, (*"(a + b)*(a + b) = a ^ 2 + 2 * a * b + b ^ 2*)
1180 \<^rule_thm>\<open>real_plus_binom_times1\<close>, (*"(a + 1*b)*(a + -1*b) = a \<up> 2 + -1*b \<up> 2"*)
1181 \<^rule_thm>\<open>real_plus_binom_times2\<close>, (*"(a + -1*b)*(a + 1*b) = a \<up> 2 + -1*b \<up> 2"*)
1183 \<^rule_thm>\<open>mult_1_left\<close>,(*"1 * z = z"*)
1185 \<^rule_thm>\<open>distrib_right\<close>, (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1186 \<^rule_thm>\<open>distrib_left\<close>, (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1188 \<^rule_thm>\<open>mult.assoc\<close>, (*"?z1.1 * ?z2.1 * ?z3. =1 ?z1.1 * (?z2.1 * ?z3.1)"*)
1189 Rule.Rls_ order_mult_rls_,
1190 (*Rule.Rls_ order_add_rls_,*)
1192 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
1193 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1194 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_"),
1196 \<^rule_thm_sym>\<open>realpow_twoI\<close>, (*"r1 * r1 = r1 \<up> 2"*)
1197 \<^rule_thm_sym>\<open>real_mult_2\<close>, (*"z1 + z1 = 2 * z1"*)
1198 \<^rule_thm>\<open>real_mult_2_assoc\<close>, (*"z1 + (z1 + k) = 2 * z1 + k"*)
1200 \<^rule_thm>\<open>real_num_collect\<close>, (*"[| l is_num; m is_num |]==>l * n + m * n = (l + m) * n"*)
1201 \<^rule_thm>\<open>real_num_collect_assoc\<close>, (*"[| l is_num; m is_num |] ==> l * n + (m * n + k) = (l + m) * n + k"*)
1202 \<^rule_thm>\<open>real_one_collect\<close>, (*"m is_num ==> n + m * n = (1 + m) * n"*)
1203 \<^rule_thm>\<open>real_one_collect_assoc\<close>, (*"m is_num ==> k + (n + m * n) = k + (1 + m) * n"*)
1205 \<^rule_thm>\<open>realpow_multI\<close>, (*"(r * s) \<up> n = r \<up> n * s \<up> n"*)
1207 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
1208 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1209 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_"),
1211 \<^rule_thm>\<open>mult_1_left\<close>, (*"1 * z = z"*)
1212 \<^rule_thm>\<open>mult_zero_left\<close>, (*"0 * z = 0"*)
1213 \<^rule_thm>\<open>add_0_left\<close> (*0 + z = z*)
1215 (*Rule.Rls_ order_add_rls_*)
1217 scr = Rule.Empty_Prog};
1220 subsection \<open>rule-sets with explicit program for intermediate steps\<close>
1221 partial_function (tailrec) expand_binoms_2 :: "real \<Rightarrow> real"
1223 "expand_binoms_2 term = (
1225 (Try (Repeat (Rewrite ''real_plus_binom_pow2''))) #>
1226 (Try (Repeat (Rewrite ''real_plus_binom_times''))) #>
1227 (Try (Repeat (Rewrite ''real_minus_binom_pow2''))) #>
1228 (Try (Repeat (Rewrite ''real_minus_binom_times''))) #>
1229 (Try (Repeat (Rewrite ''real_plus_minus_binom1''))) #>
1230 (Try (Repeat (Rewrite ''real_plus_minus_binom2''))) #>
1232 (Try (Repeat (Rewrite ''mult_1_left''))) #>
1233 (Try (Repeat (Rewrite ''mult_zero_left''))) #>
1234 (Try (Repeat (Rewrite ''add_0_left''))) #>
1236 (Try (Repeat (Calculate ''PLUS''))) #>
1237 (Try (Repeat (Calculate ''TIMES''))) #>
1238 (Try (Repeat (Calculate ''POWER''))) #>
1240 (Try (Repeat (Rewrite ''sym_realpow_twoI''))) #>
1241 (Try (Repeat (Rewrite ''realpow_plus_1''))) #>
1242 (Try (Repeat (Rewrite ''sym_real_mult_2''))) #>
1243 (Try (Repeat (Rewrite ''real_mult_2_assoc''))) #>
1245 (Try (Repeat (Rewrite ''real_num_collect''))) #>
1246 (Try (Repeat (Rewrite ''real_num_collect_assoc''))) #>
1248 (Try (Repeat (Rewrite ''real_one_collect''))) #>
1249 (Try (Repeat (Rewrite ''real_one_collect_assoc''))) #>
1251 (Try (Repeat (Calculate ''PLUS''))) #>
1252 (Try (Repeat (Calculate ''TIMES''))) #>
1253 (Try (Repeat (Calculate ''POWER''))))
1257 Rule_Def.Repeat{id = "expand_binoms", preconds = [], rew_ord = ("termlessI",termlessI),
1258 erls = Atools_erls, srls = Rule_Set.Empty,
1259 calc = [("PLUS" , (\<^const_name>\<open>plus\<close>, eval_binop "#add_")),
1260 ("TIMES" , (\<^const_name>\<open>times\<close>, eval_binop "#mult_")),
1261 ("POWER", (\<^const_name>\<open>realpow\<close>, eval_binop "#power_"))
1264 \<^rule_thm>\<open>real_plus_binom_pow2\<close>, (*"(a + b) \<up> 2 = a \<up> 2 + 2 * a * b + b \<up> 2"*)
1265 \<^rule_thm>\<open>real_plus_binom_times\<close>, (*"(a + b)*(a + b) = ...*)
1266 \<^rule_thm>\<open>real_minus_binom_pow2\<close>, (*"(a - b) \<up> 2 = a \<up> 2 - 2 * a * b + b \<up> 2"*)
1267 \<^rule_thm>\<open>real_minus_binom_times\<close>, (*"(a - b)*(a - b) = ...*)
1268 \<^rule_thm>\<open>real_plus_minus_binom1\<close>, (*"(a + b) * (a - b) = a \<up> 2 - b \<up> 2"*)
1269 \<^rule_thm>\<open>real_plus_minus_binom2\<close>, (*"(a - b) * (a + b) = a \<up> 2 - b \<up> 2"*)
1271 \<^rule_thm>\<open>real_pp_binom_times\<close>, (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
1272 \<^rule_thm>\<open>real_pm_binom_times\<close>, (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
1273 \<^rule_thm>\<open>real_mp_binom_times\<close>, (*(a - b)*(c + d) = a*c + a*d - b*c - b*d*)
1274 \<^rule_thm>\<open>real_mm_binom_times\<close>, (*(a - b)*(c - d) = a*c - a*d - b*c + b*d*)
1275 \<^rule_thm>\<open>realpow_multI\<close>, (*(a*b) \<up> n = a \<up> n * b \<up> n*)
1276 \<^rule_thm>\<open>real_plus_binom_pow3\<close>, (* (a + b) \<up> 3 = a \<up> 3 + 3*a \<up> 2*b + 3*a*b \<up> 2 + b \<up> 3 *)
1277 \<^rule_thm>\<open>real_minus_binom_pow3\<close>, (* (a - b) \<up> 3 = a \<up> 3 - 3*a \<up> 2*b + 3*a*b \<up> 2 - b \<up> 3 *)
1279 \<^rule_thm>\<open>distrib_right\<close>, (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1280 \<^rule_thm>\<open>distrib_left\<close>, (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1281 \<^rule_thm>\<open>left_diff_distrib\<close>, (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
1282 \<^rule_thm>\<open>right_diff_distrib\<close>, (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
1284 \<^rule_thm>\<open>mult_1_left\<close>, (*"1 * z = z"*)
1285 \<^rule_thm>\<open>mult_zero_left\<close>, (*"0 * z = 0"*)
1286 \<^rule_thm>\<open>add_0_left\<close>, (*"0 + z = z"*)
1288 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
1289 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1290 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_"),
1291 (*\<^rule_thm>\<open>mult.commute\<close>,
1293 \<^rule_thm>\<open>real_mult_left_commute\<close>,
1294 \<^rule_thm>\<open>mult.assoc\<close>,
1295 \<^rule_thm>\<open>add.commute\<close>,
1296 \<^rule_thm>\<open>add.left_commute\<close>,
1297 \<^rule_thm>\<open>add.assoc\<close>,
1299 \<^rule_thm_sym>\<open>realpow_twoI\<close>, (*"r1 * r1 = r1 \<up> 2"*)
1300 \<^rule_thm>\<open>realpow_plus_1\<close>, (*"r * r \<up> n = r \<up> (n + 1)"*)
1302 \<^rule_thm_sym>\<open>real_mult_2\<close>, (*"z1 + z1 = 2 * z1"*)*)
1303 \<^rule_thm>\<open>real_mult_2_assoc\<close>, (*"z1 + (z1 + k) = 2 * z1 + k"*)
1305 \<^rule_thm>\<open>real_num_collect\<close>, (*"[| l is_num; m is_num |] ==>l * n + m * n = (l + m) * n"*)
1306 \<^rule_thm>\<open>real_num_collect_assoc\<close>, (*"[| l is_num; m is_num |] ==> l * n + (m * n + k) = (l + m) * n + k"*)
1307 \<^rule_thm>\<open>real_one_collect\<close>, (*"m is_num ==> n + m * n = (1 + m) * n"*)
1308 \<^rule_thm>\<open>real_one_collect_assoc\<close>, (*"m is_num ==> k + (n + m * n) = k + (1 + m) * n"*)
1310 \<^rule_eval>\<open>plus\<close> (eval_binop "#add_"),
1311 \<^rule_eval>\<open>times\<close> (eval_binop "#mult_"),
1312 \<^rule_eval>\<open>realpow\<close> (eval_binop "#power_")],
1313 scr = Rule.Prog (Program.prep_program @{thm expand_binoms_2.simps})};
1316 subsection \<open>add to Know_Store\<close>
1317 subsubsection \<open>rule-sets\<close>
1318 ML \<open>val prep_rls' = Auto_Prog.prep_rls @{theory}\<close>
1321 norm_Poly = \<open>prep_rls' norm_Poly\<close> and
1322 Poly_erls = \<open>prep_rls' Poly_erls\<close> and
1323 expand = \<open>prep_rls' expand\<close> and
1324 expand_poly = \<open>prep_rls' expand_poly\<close> and
1325 simplify_power = \<open>prep_rls' simplify_power\<close> and
1327 order_add_mult = \<open>prep_rls' order_add_mult\<close> and
1328 collect_numerals = \<open>prep_rls' collect_numerals\<close> and
1329 collect_numerals_= \<open>prep_rls' collect_numerals_\<close> and
1330 reduce_012 = \<open>prep_rls' reduce_012\<close> and
1331 discard_parentheses = \<open>prep_rls' discard_parentheses\<close> and
1333 make_polynomial = \<open>prep_rls' make_polynomial\<close> and
1334 expand_binoms = \<open>prep_rls' expand_binoms\<close> and
1335 rev_rew_p = \<open>prep_rls' rev_rew_p\<close> and
1336 discard_minus = \<open>prep_rls' discard_minus\<close> and
1337 expand_poly_ = \<open>prep_rls' expand_poly_\<close> and
1339 expand_poly_rat_ = \<open>prep_rls' expand_poly_rat_\<close> and
1340 simplify_power_ = \<open>prep_rls' simplify_power_\<close> and
1341 calc_add_mult_pow_ = \<open>prep_rls' calc_add_mult_pow_\<close> and
1342 reduce_012_mult_ = \<open>prep_rls' reduce_012_mult_\<close> and
1343 reduce_012_ = \<open>prep_rls' reduce_012_\<close> and
1345 discard_parentheses1 = \<open>prep_rls' discard_parentheses1\<close> and
1346 order_mult_rls_ = \<open>prep_rls' order_mult_rls_\<close> and
1347 order_add_rls_ = \<open>prep_rls' order_add_rls_\<close> and
1348 make_rat_poly_with_parentheses = \<open>prep_rls' make_rat_poly_with_parentheses\<close>
1350 subsection \<open>problems\<close>
1352 problem pbl_simp_poly : "polynomial/simplification" =
1353 \<open>Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)
1354 \<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp "")]\<close>
1355 Method_Ref: "simplification/for_polynomials"
1358 Where: "t_t is_polyexp"
1359 Find: "normalform n_n"
1361 subsection \<open>methods\<close>
1363 partial_function (tailrec) simplify :: "real \<Rightarrow> real"
1365 "simplify term = ((Rewrite_Set ''norm_Poly'') term)"
1367 method met_simp_poly : "simplification/for_polynomials" =
1368 \<open>{rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
1369 prls = Rule_Set.append_rules "simplification_for_polynomials_prls" Rule_Set.empty
1370 [(*for preds in where_*) \<^rule_eval>\<open>is_polyexp\<close> (eval_is_polyexp"")],
1371 crls = Rule_Set.empty, errpats = [], nrls = norm_Poly}\<close>
1372 Program: simplify.simps
1374 Where: "t_t is_polyexp"
1375 Find: "normalform n_n"