replace Celem. with new struct.s in BaseDefinitions/
Note: the remaining code in calcelems.sml shall be destributed to respective struct.s
1 (* attempts to perserve binary minus as wanted by Austrian teachers
3 (c) due to copyright terms
6 theory PolyMinus imports (*Poly// due to "is_ratpolyexp" in...*) Rational begin
10 (*predicates for conditions in rewriting*)
11 kleiner :: "['a, 'a] => bool" ("_ kleiner _")
12 ist'_monom :: "'a => bool" ("_ ist'_monom")
15 Probe :: "[bool, bool list] => bool"
16 (*"Probe (3*a+2*b+a = 4*a+2*b) [a=1,b=2]"*)
18 (*descriptions for the pbl and met*)
19 Pruefe :: "bool => una"
20 mitWert :: "bool list => tobooll"
21 Geprueft :: "bool => una"
25 null_minus: "0 - a = -a" and
26 vor_minus_mal: "- a * b = (-a) * b" and
28 (*commute with invariant (a.b).c -association*)
29 tausche_plus: "[| b ist_monom; a kleiner b |] ==>
30 (b + a) = (a + b)" and
31 tausche_minus: "[| b ist_monom; a kleiner b |] ==>
32 (b - a) = (-a + b)" and
33 tausche_vor_plus: "[| b ist_monom; a kleiner b |] ==>
34 (- b + a) = (a - b)" and
35 tausche_vor_minus: "[| b ist_monom; a kleiner b |] ==>
36 (- b - a) = (-a - b)" and
37 tausche_plus_plus: "b kleiner c ==> (a + c + b) = (a + b + c)" and
38 tausche_plus_minus: "b kleiner c ==> (a + c - b) = (a - b + c)" and
39 tausche_minus_plus: "b kleiner c ==> (a - c + b) = (a + b - c)" and
40 tausche_minus_minus: "b kleiner c ==> (a - c - b) = (a - b - c)" and
42 (*commute with invariant (a.b).c -association*)
43 tausche_mal: "[| b is_atom; a kleiner b |] ==>
44 (b * a) = (a * b)" and
45 tausche_vor_mal: "[| b is_atom; a kleiner b |] ==>
46 (-b * a) = (-a * b)" and
47 tausche_mal_mal: "[| c is_atom; b kleiner c |] ==>
48 (x * c * b) = (x * b * c)" and
49 x_quadrat: "(x * a) * a = x * a ^^^ 2" and
52 subtrahiere: "[| l is_const; m is_const |] ==>
53 m * v - l * v = (m - l) * v" and
54 subtrahiere_von_1: "[| l is_const |] ==>
55 v - l * v = (1 - l) * v" and
56 subtrahiere_1: "[| l is_const; m is_const |] ==>
57 m * v - v = (m - 1) * v" and
59 subtrahiere_x_plus_minus: "[| l is_const; m is_const |] ==>
60 (x + m * v) - l * v = x + (m - l) * v" and
61 subtrahiere_x_plus1_minus: "[| l is_const |] ==>
62 (x + v) - l * v = x + (1 - l) * v" and
63 subtrahiere_x_plus_minus1: "[| m is_const |] ==>
64 (x + m * v) - v = x + (m - 1) * v" and
66 subtrahiere_x_minus_plus: "[| l is_const; m is_const |] ==>
67 (x - m * v) + l * v = x + (-m + l) * v" and
68 subtrahiere_x_minus1_plus: "[| l is_const |] ==>
69 (x - v) + l * v = x + (-1 + l) * v" and
70 subtrahiere_x_minus_plus1: "[| m is_const |] ==>
71 (x - m * v) + v = x + (-m + 1) * v" and
73 subtrahiere_x_minus_minus: "[| l is_const; m is_const |] ==>
74 (x - m * v) - l * v = x + (-m - l) * v" and
75 subtrahiere_x_minus1_minus:"[| l is_const |] ==>
76 (x - v) - l * v = x + (-1 - l) * v" and
77 subtrahiere_x_minus_minus1:"[| m is_const |] ==>
78 (x - m * v) - v = x + (-m - 1) * v" and
81 addiere_vor_minus: "[| l is_const; m is_const |] ==>
82 - (l * v) + m * v = (-l + m) * v" and
83 addiere_eins_vor_minus: "[| m is_const |] ==>
84 - v + m * v = (-1 + m) * v" and
85 subtrahiere_vor_minus: "[| l is_const; m is_const |] ==>
86 - (l * v) - m * v = (-l - m) * v" and
87 subtrahiere_eins_vor_minus:"[| m is_const |] ==>
88 - v - m * v = (-1 - m) * v" and
90 vorzeichen_minus_weg1: "l kleiner 0 ==> a + l * b = a - -1*l * b" and
91 vorzeichen_minus_weg2: "l kleiner 0 ==> a - l * b = a + -1*l * b" and
92 vorzeichen_minus_weg3: "l kleiner 0 ==> k + a - l * b = k + a + -1*l * b" and
93 vorzeichen_minus_weg4: "l kleiner 0 ==> k - a - l * b = k - a + -1*l * b" and
95 (*klammer_plus_plus = (add.assoc RS sym)*)
96 klammer_plus_minus: "a + (b - c) = (a + b) - c" and
97 klammer_minus_plus: "a - (b + c) = (a - b) - c" and
98 klammer_minus_minus: "a - (b - c) = (a - b) + c" and
100 klammer_mult_minus: "a * (b - c) = a * b - a * c" and
101 klammer_minus_mult: "(b - c) * a = b * a - c * a"
106 (** eval functions **)
108 (*. get the identifier from specific monomials; see fun ist_monom .*)
111 let val s::ss = Symbol.explode str
112 in implode ((chr (ord s + 1))::ss) end;
113 fun identifier (Free (id,_)) = id (* 2, a *)
114 | identifier (Const ("Groups.times_class.times", _) $ Free (num, _) $ Free (id, _)) =
116 | identifier (Const ("Groups.times_class.times", _) $ (* 3*a*b *)
117 (Const ("Groups.times_class.times", _) $
118 Free (num, _) $ Free _) $ Free (id, _)) =
119 if TermC.is_num' num then id
121 | identifier (Const ("Prog_Expr.pow", _) $ Free (base, _) $ Free (exp, _)) =
122 if TermC.is_num' base then "|||||||||||||" (* a^2 *)
123 else (*increase*) base
124 | identifier (Const ("Groups.times_class.times", _) $ Free (num, _) $ (* 3*a^2 *)
125 (Const ("Prog_Expr.pow", _) $
126 Free (base, _) $ Free (exp, _))) =
127 if TermC.is_num' num andalso not (TermC.is_num' base) then (*increase*) base
129 | identifier _ = "|||||||||||||"(*the "largest" string*);
131 (*("kleiner", ("PolyMinus.kleiner", eval_kleiner ""))*)
132 (* order "by alphabet" w.r.t. var: num < (var | num*var) > (var*var | ..) *)
133 fun eval_kleiner _ _ (p as (Const ("PolyMinus.kleiner",_) $ a $ b)) _ =
134 if TermC.is_num b then
135 if TermC.is_num a then (*123 kleiner 32 = True !!!*)
136 if TermC.num_of_term a < TermC.num_of_term b then
137 SOME ((UnparseC.term p) ^ " = True",
138 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
139 else SOME ((UnparseC.term p) ^ " = False",
140 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
141 else (* -1 * -2 kleiner 0 *)
142 SOME ((UnparseC.term p) ^ " = False",
143 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
145 if identifier a < identifier b then
146 SOME ((UnparseC.term p) ^ " = True",
147 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
148 else SOME ((UnparseC.term p) ^ " = False",
149 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
150 | eval_kleiner _ _ _ _ = NONE;
152 fun ist_monom (Free (id,_)) = true
153 | ist_monom (Const ("Groups.times_class.times", _) $ Free (num, _) $ Free (id, _)) =
154 if TermC.is_num' num then true else false
155 | ist_monom _ = false;
156 (*. this function only accepts the most simple monoms vvvvvvvvvv .*)
157 fun ist_monom (Free (id,_)) = true (* 2, a *)
158 | ist_monom (Const ("Groups.times_class.times", _) $ Free _ $ Free (id, _)) = (* 2*a, a*b *)
159 if TermC.is_num' id then false else true
160 | ist_monom (Const ("Groups.times_class.times", _) $ (* 3*a*b *)
161 (Const ("Groups.times_class.times", _) $
162 Free (num, _) $ Free _) $ Free (id, _)) =
163 if TermC.is_num' num andalso not (TermC.is_num' id) then true else false
164 | ist_monom (Const ("Prog_Expr.pow", _) $ Free (base, _) $ Free (exp, _)) =
166 | ist_monom (Const ("Groups.times_class.times", _) $ Free (num, _) $ (* 3*a^2 *)
167 (Const ("Prog_Expr.pow", _) $
168 Free (base, _) $ Free (exp, _))) =
169 if TermC.is_num' num then true else false
170 | ist_monom _ = false;
172 (* is this a univariate monomial ? *)
173 (*("ist_monom", ("PolyMinus.ist'_monom", eval_ist_monom ""))*)
174 fun eval_ist_monom _ _ (p as (Const ("PolyMinus.ist'_monom",_) $ a)) _ =
176 SOME ((UnparseC.term p) ^ " = True",
177 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
178 else SOME ((UnparseC.term p) ^ " = False",
179 HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
180 | eval_ist_monom _ _ _ _ = NONE;
183 (** rewrite order **)
187 val erls_ordne_alphabetisch =
188 Rule_Set.append_rules "erls_ordne_alphabetisch" Rule_Set.empty
189 [Rule.Eval ("PolyMinus.kleiner", eval_kleiner ""),
190 Rule.Eval ("PolyMinus.ist'_monom", eval_ist_monom "")
193 val ordne_alphabetisch =
194 Rule_Def.Repeat{id = "ordne_alphabetisch", preconds = [],
195 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), srls = Rule_Set.Empty, calc = [], errpatts = [],
196 erls = erls_ordne_alphabetisch,
197 rules = [Rule.Thm ("tausche_plus",ThmC.numerals_to_Free @{thm tausche_plus}),
198 (*"b kleiner a ==> (b + a) = (a + b)"*)
199 Rule.Thm ("tausche_minus",ThmC.numerals_to_Free @{thm tausche_minus}),
200 (*"b kleiner a ==> (b - a) = (-a + b)"*)
201 Rule.Thm ("tausche_vor_plus",ThmC.numerals_to_Free @{thm tausche_vor_plus}),
202 (*"[| b ist_monom; a kleiner b |] ==> (- b + a) = (a - b)"*)
203 Rule.Thm ("tausche_vor_minus",ThmC.numerals_to_Free @{thm tausche_vor_minus}),
204 (*"[| b ist_monom; a kleiner b |] ==> (- b - a) = (-a - b)"*)
205 Rule.Thm ("tausche_plus_plus",ThmC.numerals_to_Free @{thm tausche_plus_plus}),
206 (*"c kleiner b ==> (a + c + b) = (a + b + c)"*)
207 Rule.Thm ("tausche_plus_minus",ThmC.numerals_to_Free @{thm tausche_plus_minus}),
208 (*"c kleiner b ==> (a + c - b) = (a - b + c)"*)
209 Rule.Thm ("tausche_minus_plus",ThmC.numerals_to_Free @{thm tausche_minus_plus}),
210 (*"c kleiner b ==> (a - c + b) = (a + b - c)"*)
211 Rule.Thm ("tausche_minus_minus",ThmC.numerals_to_Free @{thm tausche_minus_minus})
212 (*"c kleiner b ==> (a - c - b) = (a - b - c)"*)
213 ], scr = Rule.Empty_Prog};
216 Rule_Def.Repeat{id = "fasse_zusammen", preconds = [],
217 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord),
218 erls = Rule_Set.append_rules "erls_fasse_zusammen" Rule_Set.empty
219 [Rule.Eval ("Prog_Expr.is'_const", Prog_Expr.eval_const "#is_const_")],
220 srls = Rule_Set.Empty, calc = [], errpatts = [],
222 [Rule.Thm ("real_num_collect",ThmC.numerals_to_Free @{thm real_num_collect}),
223 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
224 Rule.Thm ("real_num_collect_assoc_r",ThmC.numerals_to_Free @{thm real_num_collect_assoc_r}),
225 (*"[| l is_const; m..|] ==> (k + m * n) + l * n = k + (l + m)*n"*)
226 Rule.Thm ("real_one_collect",ThmC.numerals_to_Free @{thm real_one_collect}),
227 (*"m is_const ==> n + m * n = (1 + m) * n"*)
228 Rule.Thm ("real_one_collect_assoc_r",ThmC.numerals_to_Free @{thm real_one_collect_assoc_r}),
229 (*"m is_const ==> (k + n) + m * n = k + (m + 1) * n"*)
232 Rule.Thm ("subtrahiere",ThmC.numerals_to_Free @{thm subtrahiere}),
233 (*"[| l is_const; m is_const |] ==> m * v - l * v = (m - l) * v"*)
234 Rule.Thm ("subtrahiere_von_1",ThmC.numerals_to_Free @{thm subtrahiere_von_1}),
235 (*"[| l is_const |] ==> v - l * v = (1 - l) * v"*)
236 Rule.Thm ("subtrahiere_1",ThmC.numerals_to_Free @{thm subtrahiere_1}),
237 (*"[| l is_const; m is_const |] ==> m * v - v = (m - 1) * v"*)
239 Rule.Thm ("subtrahiere_x_plus_minus",ThmC.numerals_to_Free @{thm subtrahiere_x_plus_minus}),
240 (*"[| l is_const; m..|] ==> (k + m * n) - l * n = k + ( m - l) * n"*)
241 Rule.Thm ("subtrahiere_x_plus1_minus",ThmC.numerals_to_Free @{thm subtrahiere_x_plus1_minus}),
242 (*"[| l is_const |] ==> (x + v) - l * v = x + (1 - l) * v"*)
243 Rule.Thm ("subtrahiere_x_plus_minus1",ThmC.numerals_to_Free @{thm subtrahiere_x_plus_minus1}),
244 (*"[| m is_const |] ==> (x + m * v) - v = x + (m - 1) * v"*)
246 Rule.Thm ("subtrahiere_x_minus_plus",ThmC.numerals_to_Free @{thm subtrahiere_x_minus_plus}),
247 (*"[| l is_const; m..|] ==> (k - m * n) + l * n = k + (-m + l) * n"*)
248 Rule.Thm ("subtrahiere_x_minus1_plus",ThmC.numerals_to_Free @{thm subtrahiere_x_minus1_plus}),
249 (*"[| l is_const |] ==> (x - v) + l * v = x + (-1 + l) * v"*)
250 Rule.Thm ("subtrahiere_x_minus_plus1",ThmC.numerals_to_Free @{thm subtrahiere_x_minus_plus1}),
251 (*"[| m is_const |] ==> (x - m * v) + v = x + (-m + 1) * v"*)
253 Rule.Thm ("subtrahiere_x_minus_minus",ThmC.numerals_to_Free @{thm subtrahiere_x_minus_minus}),
254 (*"[| l is_const; m..|] ==> (k - m * n) - l * n = k + (-m - l) * n"*)
255 Rule.Thm ("subtrahiere_x_minus1_minus",ThmC.numerals_to_Free @{thm subtrahiere_x_minus1_minus}),
256 (*"[| l is_const |] ==> (x - v) - l * v = x + (-1 - l) * v"*)
257 Rule.Thm ("subtrahiere_x_minus_minus1",ThmC.numerals_to_Free @{thm subtrahiere_x_minus_minus1}),
258 (*"[| m is_const |] ==> (x - m * v) - v = x + (-m - 1) * v"*)
260 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
261 Rule.Eval ("Groups.minus_class.minus", (**)eval_binop "#subtr_"),
263 (*MG: Reihenfolge der folgenden 2 Rule.Thm muss so bleiben, wegen
264 (a+a)+a --> a + 2*a --> 3*a and not (a+a)+a --> 2*a + a *)
265 Rule.Thm ("real_mult_2_assoc_r",ThmC.numerals_to_Free @{thm real_mult_2_assoc_r}),
266 (*"(k + z1) + z1 = k + 2 * z1"*)
267 Rule.Thm ("sym_real_mult_2",ThmC.numerals_to_Free (@{thm real_mult_2} RS @{thm sym})),
268 (*"z1 + z1 = 2 * z1"*)
270 Rule.Thm ("addiere_vor_minus",ThmC.numerals_to_Free @{thm addiere_vor_minus}),
271 (*"[| l is_const; m is_const |] ==> -(l * v) + m * v = (-l + m) *v"*)
272 Rule.Thm ("addiere_eins_vor_minus",ThmC.numerals_to_Free @{thm addiere_eins_vor_minus}),
273 (*"[| m is_const |] ==> - v + m * v = (-1 + m) * v"*)
274 Rule.Thm ("subtrahiere_vor_minus",ThmC.numerals_to_Free @{thm subtrahiere_vor_minus}),
275 (*"[| l is_const; m is_const |] ==> -(l * v) - m * v = (-l - m) *v"*)
276 Rule.Thm ("subtrahiere_eins_vor_minus",ThmC.numerals_to_Free @{thm subtrahiere_eins_vor_minus})
277 (*"[| m is_const |] ==> - v - m * v = (-1 - m) * v"*)
279 ], scr = Rule.Empty_Prog};
282 Rule_Def.Repeat{id = "verschoenere", preconds = [],
283 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), srls = Rule_Set.Empty, calc = [], errpatts = [],
284 erls = Rule_Set.append_rules "erls_verschoenere" Rule_Set.empty
285 [Rule.Eval ("PolyMinus.kleiner", eval_kleiner "")],
286 rules = [Rule.Thm ("vorzeichen_minus_weg1",ThmC.numerals_to_Free @{thm vorzeichen_minus_weg1}),
287 (*"l kleiner 0 ==> a + l * b = a - -l * b"*)
288 Rule.Thm ("vorzeichen_minus_weg2",ThmC.numerals_to_Free @{thm vorzeichen_minus_weg2}),
289 (*"l kleiner 0 ==> a - l * b = a + -l * b"*)
290 Rule.Thm ("vorzeichen_minus_weg3",ThmC.numerals_to_Free @{thm vorzeichen_minus_weg3}),
291 (*"l kleiner 0 ==> k + a - l * b = k + a + -l * b"*)
292 Rule.Thm ("vorzeichen_minus_weg4",ThmC.numerals_to_Free @{thm vorzeichen_minus_weg4}),
293 (*"l kleiner 0 ==> k - a - l * b = k - a + -l * b"*)
295 Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
297 Rule.Thm ("mult_zero_left",ThmC.numerals_to_Free @{thm mult_zero_left}),
299 Rule.Thm ("mult_1_left",ThmC.numerals_to_Free @{thm mult_1_left}),
301 Rule.Thm ("add_0_left",ThmC.numerals_to_Free @{thm add_0_left}),
303 Rule.Thm ("null_minus",ThmC.numerals_to_Free @{thm null_minus}),
305 Rule.Thm ("vor_minus_mal",ThmC.numerals_to_Free @{thm vor_minus_mal})
306 (*"- a * b = (-a) * b"*)
308 (*Rule.Thm ("",ThmC.numerals_to_Free @{}),*)
310 ], scr = Rule.Empty_Prog} (*end verschoenere*);
312 val klammern_aufloesen =
313 Rule_Def.Repeat{id = "klammern_aufloesen", preconds = [],
314 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), srls = Rule_Set.Empty, calc = [], errpatts = [], erls = Rule_Set.Empty,
315 rules = [Rule.Thm ("sym_add.assoc",
316 ThmC.numerals_to_Free (@{thm add.assoc} RS @{thm sym})),
317 (*"a + (b + c) = (a + b) + c"*)
318 Rule.Thm ("klammer_plus_minus",ThmC.numerals_to_Free @{thm klammer_plus_minus}),
319 (*"a + (b - c) = (a + b) - c"*)
320 Rule.Thm ("klammer_minus_plus",ThmC.numerals_to_Free @{thm klammer_minus_plus}),
321 (*"a - (b + c) = (a - b) - c"*)
322 Rule.Thm ("klammer_minus_minus",ThmC.numerals_to_Free @{thm klammer_minus_minus})
323 (*"a - (b - c) = (a - b) + c"*)
324 ], scr = Rule.Empty_Prog};
326 val klammern_ausmultiplizieren =
327 Rule_Def.Repeat{id = "klammern_ausmultiplizieren", preconds = [],
328 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), srls = Rule_Set.Empty, calc = [], errpatts = [], erls = Rule_Set.Empty,
329 rules = [Rule.Thm ("distrib_right" ,ThmC.numerals_to_Free @{thm distrib_right}),
330 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
331 Rule.Thm ("distrib_left",ThmC.numerals_to_Free @{thm distrib_left}),
332 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
334 Rule.Thm ("klammer_mult_minus",ThmC.numerals_to_Free @{thm klammer_mult_minus}),
335 (*"a * (b - c) = a * b - a * c"*)
336 Rule.Thm ("klammer_minus_mult",ThmC.numerals_to_Free @{thm klammer_minus_mult})
337 (*"(b - c) * a = b * a - c * a"*)
339 (*Rule.Thm ("",ThmC.numerals_to_Free @{}),
341 ], scr = Rule.Empty_Prog};
344 Rule_Def.Repeat{id = "ordne_monome", preconds = [],
345 rew_ord = ("dummy_ord", Rewrite_Ord.dummy_ord), srls = Rule_Set.Empty, calc = [], errpatts = [],
346 erls = Rule_Set.append_rules "erls_ordne_monome" Rule_Set.empty
347 [Rule.Eval ("PolyMinus.kleiner", eval_kleiner ""),
348 Rule.Eval ("Prog_Expr.is'_atom", Prog_Expr.eval_is_atom "")
350 rules = [Rule.Thm ("tausche_mal",ThmC.numerals_to_Free @{thm tausche_mal}),
351 (*"[| b is_atom; a kleiner b |] ==> (b * a) = (a * b)"*)
352 Rule.Thm ("tausche_vor_mal",ThmC.numerals_to_Free @{thm tausche_vor_mal}),
353 (*"[| b is_atom; a kleiner b |] ==> (-b * a) = (-a * b)"*)
354 Rule.Thm ("tausche_mal_mal",ThmC.numerals_to_Free @{thm tausche_mal_mal}),
355 (*"[| c is_atom; b kleiner c |] ==> (a * c * b) = (a * b *c)"*)
356 Rule.Thm ("x_quadrat",ThmC.numerals_to_Free @{thm x_quadrat})
357 (*"(x * a) * a = x * a ^^^ 2"*)
359 (*Rule.Thm ("",ThmC.numerals_to_Free @{}),
361 ], scr = Rule.Empty_Prog};
365 Rule_Set.append_rules "rls_p_33" Rule_Set.empty
366 [Rule.Rls_ ordne_alphabetisch,
367 Rule.Rls_ fasse_zusammen,
368 Rule.Rls_ verschoenere
371 Rule_Set.append_rules "rls_p_34" Rule_Set.empty
372 [Rule.Rls_ klammern_aufloesen,
373 Rule.Rls_ ordne_alphabetisch,
374 Rule.Rls_ fasse_zusammen,
375 Rule.Rls_ verschoenere
378 Rule_Set.append_rules "rechnen" Rule_Set.empty
379 [Rule.Eval ("Groups.times_class.times", (**)eval_binop "#mult_"),
380 Rule.Eval ("Groups.plus_class.plus", (**)eval_binop "#add_"),
381 Rule.Eval ("Groups.minus_class.minus", (**)eval_binop "#subtr_")
384 setup \<open>KEStore_Elems.add_rlss
385 [("ordne_alphabetisch", (Context.theory_name @{theory}, prep_rls' ordne_alphabetisch)),
386 ("fasse_zusammen", (Context.theory_name @{theory}, prep_rls' fasse_zusammen)),
387 ("verschoenere", (Context.theory_name @{theory}, prep_rls' verschoenere)),
388 ("ordne_monome", (Context.theory_name @{theory}, prep_rls' ordne_monome)),
389 ("klammern_aufloesen", (Context.theory_name @{theory}, prep_rls' klammern_aufloesen)),
390 ("klammern_ausmultiplizieren",
391 (Context.theory_name @{theory}, prep_rls' klammern_ausmultiplizieren))]\<close>
394 setup \<open>KEStore_Elems.add_pbts
395 [(Specify.prep_pbt thy "pbl_vereinf_poly" [] Spec.e_pblID
396 (["polynom","vereinfachen"], [], Rule_Set.Empty, NONE, [])),
397 (Specify.prep_pbt thy "pbl_vereinf_poly_minus" [] Spec.e_pblID
398 (["plus_minus","polynom","vereinfachen"],
399 [("#Given", ["Term t_t"]),
400 ("#Where", ["t_t is_polyexp",
401 "Not (matchsub (?a + (?b + ?c)) t_t | " ^
402 " matchsub (?a + (?b - ?c)) t_t | " ^
403 " matchsub (?a - (?b + ?c)) t_t | " ^
404 " matchsub (?a + (?b - ?c)) t_t )",
405 "Not (matchsub (?a * (?b + ?c)) t_t | " ^
406 " matchsub (?a * (?b - ?c)) t_t | " ^
407 " matchsub ((?b + ?c) * ?a) t_t | " ^
408 " matchsub ((?b - ?c) * ?a) t_t )"]),
409 ("#Find", ["normalform n_n"])],
410 Rule_Set.append_rules "prls_pbl_vereinf_poly" Rule_Set.empty
411 [Rule.Eval ("Poly.is'_polyexp", eval_is_polyexp ""),
412 Rule.Eval ("Prog_Expr.matchsub", Prog_Expr.eval_matchsub ""),
413 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
414 (*"(?a | True) = True"*)
415 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
416 (*"(?a | False) = ?a"*)
417 Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
418 (*"(~ True) = False"*)
419 Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
420 (*"(~ False) = True"*)],
421 SOME "Vereinfache t_t", [["simplification","for_polynomials","with_minus"]])),
422 (Specify.prep_pbt thy "pbl_vereinf_poly_klammer" [] Spec.e_pblID
423 (["klammer","polynom","vereinfachen"],
424 [("#Given" ,["Term t_t"]),
425 ("#Where" ,["t_t is_polyexp",
426 "Not (matchsub (?a * (?b + ?c)) t_t | " ^
427 " matchsub (?a * (?b - ?c)) t_t | " ^
428 " matchsub ((?b + ?c) * ?a) t_t | " ^
429 " matchsub ((?b - ?c) * ?a) t_t )"]),
430 ("#Find" ,["normalform n_n"])],
431 Rule_Set.append_rules "prls_pbl_vereinf_poly_klammer" Rule_Set.empty
432 [Rule.Eval ("Poly.is'_polyexp", eval_is_polyexp ""),
433 Rule.Eval ("Prog_Expr.matchsub", Prog_Expr.eval_matchsub ""),
434 Rule.Thm ("or_true", ThmC.numerals_to_Free @{thm or_true}),
435 (*"(?a | True) = True"*)
436 Rule.Thm ("or_false", ThmC.numerals_to_Free @{thm or_false}),
437 (*"(?a | False) = ?a"*)
438 Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
439 (*"(~ True) = False"*)
440 Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
441 (*"(~ False) = True"*)],
442 SOME "Vereinfache t_t",
443 [["simplification","for_polynomials","with_parentheses"]])),
444 (Specify.prep_pbt thy "pbl_vereinf_poly_klammer_mal" [] Spec.e_pblID
445 (["binom_klammer","polynom","vereinfachen"],
446 [("#Given", ["Term t_t"]),
447 ("#Where", ["t_t is_polyexp"]),
448 ("#Find", ["normalform n_n"])],
449 Rule_Set.append_rules "empty" Rule_Set.empty [(*for preds in where_*)
450 Rule.Eval ("Poly.is'_polyexp", eval_is_polyexp "")],
451 SOME "Vereinfache t_t",
452 [["simplification","for_polynomials","with_parentheses_mult"]])),
453 (Specify.prep_pbt thy "pbl_probe" [] Spec.e_pblID (["probe"], [], Rule_Set.Empty, NONE, [])),
454 (Specify.prep_pbt thy "pbl_probe_poly" [] Spec.e_pblID
455 (["polynom","probe"],
456 [("#Given", ["Pruefe e_e", "mitWert w_w"]),
457 ("#Where", ["e_e is_polyexp"]),
458 ("#Find", ["Geprueft p_p"])],
459 Rule_Set.append_rules "prls_pbl_probe_poly" Rule_Set.empty [(*for preds in where_*)
460 Rule.Eval ("Poly.is'_polyexp", eval_is_polyexp "")],
461 SOME "Probe e_e w_w",
462 [["probe","fuer_polynom"]])),
463 (Specify.prep_pbt thy "pbl_probe_bruch" [] Spec.e_pblID
465 [("#Given" ,["Pruefe e_e", "mitWert w_w"]),
466 ("#Where" ,["e_e is_ratpolyexp"]),
467 ("#Find" ,["Geprueft p_p"])],
468 Rule_Set.append_rules "prls_pbl_probe_bruch" Rule_Set.empty [(*for preds in where_*)
469 Rule.Eval ("Rational.is'_ratpolyexp", eval_is_ratpolyexp "")],
470 SOME "Probe e_e w_w", [["probe","fuer_bruch"]]))]\<close>
474 partial_function (tailrec) simplify :: "real \<Rightarrow> real"
478 (Try (Rewrite_Set ''ordne_alphabetisch'')) #>
479 (Try (Rewrite_Set ''fasse_zusammen'')) #>
480 (Try (Rewrite_Set ''verschoenere'')))
482 setup \<open>KEStore_Elems.add_mets
483 [Specify.prep_met thy "met_simp_poly_minus" [] Spec.e_metID
484 (["simplification","for_polynomials","with_minus"],
485 [("#Given" ,["Term t_t"]),
486 ("#Where" ,["t_t is_polyexp",
487 "Not (matchsub (?a + (?b + ?c)) t_t | " ^
488 " matchsub (?a + (?b - ?c)) t_t | " ^
489 " matchsub (?a - (?b + ?c)) t_t | " ^
490 " matchsub (?a + (?b - ?c)) t_t )"]),
491 ("#Find" ,["normalform n_n"])],
492 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
493 prls = Rule_Set.append_rules "prls_met_simp_poly_minus" Rule_Set.empty
494 [Rule.Eval ("Poly.is'_polyexp", eval_is_polyexp ""),
495 Rule.Eval ("Prog_Expr.matchsub", Prog_Expr.eval_matchsub ""),
496 Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
497 (*"(?a & True) = ?a"*)
498 Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
499 (*"(?a & False) = False"*)
500 Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
501 (*"(~ True) = False"*)
502 Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false})
503 (*"(~ False) = True"*)],
504 crls = Rule_Set.empty, errpats = [], nrls = rls_p_33},
505 @{thm simplify.simps})]
508 partial_function (tailrec) simplify2 :: "real \<Rightarrow> real"
512 (Try (Rewrite_Set ''klammern_aufloesen'')) #>
513 (Try (Rewrite_Set ''ordne_alphabetisch'')) #>
514 (Try (Rewrite_Set ''fasse_zusammen'')) #>
515 (Try (Rewrite_Set ''verschoenere'')))
517 setup \<open>KEStore_Elems.add_mets
518 [Specify.prep_met thy "met_simp_poly_parenth" [] Spec.e_metID
519 (["simplification","for_polynomials","with_parentheses"],
520 [("#Given" ,["Term t_t"]),
521 ("#Where" ,["t_t is_polyexp"]),
522 ("#Find" ,["normalform n_n"])],
523 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
524 prls = Rule_Set.append_rules "simplification_for_polynomials_prls" Rule_Set.empty
525 [(*for preds in where_*) Rule.Eval("Poly.is'_polyexp", eval_is_polyexp"")],
526 crls = Rule_Set.empty, errpats = [], nrls = rls_p_34},
527 @{thm simplify2.simps})]
530 partial_function (tailrec) simplify3 :: "real \<Rightarrow> real"
534 (Try (Rewrite_Set ''klammern_ausmultiplizieren'')) #>
535 (Try (Rewrite_Set ''discard_parentheses'')) #>
536 (Try (Rewrite_Set ''ordne_monome'')) #>
537 (Try (Rewrite_Set ''klammern_aufloesen'')) #>
538 (Try (Rewrite_Set ''ordne_alphabetisch'')) #>
539 (Try (Rewrite_Set ''fasse_zusammen'')) #>
540 (Try (Rewrite_Set ''verschoenere'')))
542 setup \<open>KEStore_Elems.add_mets
543 [Specify.prep_met thy "met_simp_poly_parenth_mult" [] Spec.e_metID
544 (["simplification","for_polynomials","with_parentheses_mult"],
545 [("#Given" ,["Term t_t"]), ("#Where" ,["t_t is_polyexp"]), ("#Find" ,["normalform n_n"])],
546 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
547 prls = Rule_Set.append_rules "simplification_for_polynomials_prls" Rule_Set.empty
548 [(*for preds in where_*) Rule.Eval("Poly.is'_polyexp", eval_is_polyexp"")],
549 crls = Rule_Set.empty, errpats = [], nrls = rls_p_34},
550 @{thm simplify3.simps})]
552 setup \<open>KEStore_Elems.add_mets
553 [Specify.prep_met thy "met_probe" [] Spec.e_metID
555 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty, prls = Rule_Set.Empty, crls = Rule_Set.empty,
556 errpats = [], nrls = Rule_Set.Empty},
560 partial_function (tailrec) mache_probe :: "bool \<Rightarrow> bool list \<Rightarrow> bool"
562 "mache_probe e_e w_w = (
565 e_e = Substitute w_w e_e
568 (Try (Repeat (Calculate ''TIMES''))) #>
569 (Try (Repeat (Calculate ''PLUS'' ))) #>
570 (Try (Repeat (Calculate ''MINUS''))))
572 setup \<open>KEStore_Elems.add_mets
573 [Specify.prep_met thy "met_probe_poly" [] Spec.e_metID
574 (["probe","fuer_polynom"],
575 [("#Given" ,["Pruefe e_e", "mitWert w_w"]),
576 ("#Where" ,["e_e is_polyexp"]),
577 ("#Find" ,["Geprueft p_p"])],
578 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
579 prls = Rule_Set.append_rules "prls_met_probe_bruch" Rule_Set.empty
580 [(*for preds in where_*) Rule.Eval ("Rational.is'_ratpolyexp", eval_is_ratpolyexp "")],
581 crls = Rule_Set.empty, errpats = [], nrls = rechnen},
582 @{thm mache_probe.simps})]
584 setup \<open>KEStore_Elems.add_mets
585 [Specify.prep_met thy "met_probe_bruch" [] Spec.e_metID
586 (["probe","fuer_bruch"],
587 [("#Given" ,["Pruefe e_e", "mitWert w_w"]),
588 ("#Where" ,["e_e is_ratpolyexp"]),
589 ("#Find" ,["Geprueft p_p"])],
590 {rew_ord'="tless_true", rls' = Rule_Set.empty, calc = [], srls = Rule_Set.empty,
591 prls = Rule_Set.append_rules "prls_met_probe_bruch" Rule_Set.empty
592 [(*for preds in where_*) Rule.Eval ("Rational.is'_ratpolyexp", eval_is_ratpolyexp "")],
593 crls = Rule_Set.empty, errpats = [], nrls = Rule_Set.Empty},