1 (* some tests are based on specficially simple scripts etc.
2 Author: Walther Neuper 2003
3 (c) due to copyright terms
6 theory Test imports Atools + Rational + Root + Poly +
10 (*"cancel":: [real, real] => real (infixl "'/'/'/" 70) ...divide 2002*)
15 ("((Script Expand'_binomtest (_ =))//
20 bool list] => bool list"
21 ("((Script Solve'_univar'_err (_ _ _ =))//
26 bool list] => bool list"
27 ("((Script Solve'_linear (_ _ =))//
30 (*17.9.02 aus SqRoot.thy------------------------------vvv---*)
32 "is'_root'_free" :: 'a => bool ("is'_root'_free _" 10)
33 "contains'_root" :: 'a => bool ("contains'_root _" 10)
37 bool list] => bool list"
38 ("((Script Solve'_root'_equation (_ _ =))//
43 bool list] => bool list"
44 ("((Script Solve'_plain'_square (_ _ =))//
47 Norm'_univar'_equation
50 ("((Script Norm'_univar'_equation (_ _ =))//
56 ("((Script STest'_simplify (_ =))//
59 (*17.9.02 aus SqRoot.thy------------------------------^^^---*)
61 axioms (*TODO: prove as theorems*)
63 radd_mult_distrib2: "(k::real) * (m + n) = k * m + k * n"
64 rdistr_right_assoc: "(k::real) + l * n + m * n = k + (l + m) * n"
65 rdistr_right_assoc_p: "l * n + (m * n + (k::real)) = (l + m) * n + k"
66 rdistr_div_right: "((k::real) + l) / n = k / n + l / n"
68 "[| l is_const; m is_const |] ==> (l::real)*n + m*n = (l + m) * n"
70 "m is_const ==> (n::real) + m * n = (1 + m) * n"
71 rcollect_one_left_assoc:
72 "m is_const ==> (k::real) + n + m * n = k + (1 + m) * n"
73 rcollect_one_left_assoc_p:
74 "m is_const ==> n + (m * n + (k::real)) = (1 + m) * n + k"
76 rtwo_of_the_same: "a + a = 2 * a"
77 rtwo_of_the_same_assoc: "(x + a) + a = x + 2 * a"
78 rtwo_of_the_same_assoc_p:"a + (a + x) = 2 * a + x"
80 rcancel_den: "not(a=0) ==> a * (b / a) = b"
81 rcancel_const: "[| a is_const; b is_const |] ==> a*(x/b) = a/b*x"
82 rshift_nominator: "(a::real) * b / c = a / c * b"
84 exp_pow: "(a ^^^ b) ^^^ c = a ^^^ (b * c)"
85 rsqare: "(a::real) * a = a ^^^ 2"
86 power_1: "(a::real) ^^^ 1 = a"
87 rbinom_power_2: "((a::real) + b)^^^ 2 = a^^^ 2 + 2*a*b + b^^^ 2"
89 rmult_1: "1 * k = (k::real)"
90 rmult_1_right: "k * 1 = (k::real)"
91 rmult_0: "0 * k = (0::real)"
92 rmult_0_right: "k * 0 = (0::real)"
93 radd_0: "0 + k = (k::real)"
94 radd_0_right: "k + 0 = (k::real)"
97 "[| a is_const; c is_const; d is_const |] ==> a/d + c/d = (a+c)/(d::real)"
99 "[| a is_const; b is_const; c is_const; d is_const |] ==> a/b + c/d = (a*d + b*c)/(b*(d::real))"
102 radd_commute: "(m::real) + (n::real) = n + m"
103 radd_left_commute: "(x::real) + (y + z) = y + (x + z)"
104 radd_assoc: "(m::real) + n + k = m + (n + k)"
105 rmult_commute: "(m::real) * n = n * m"
106 rmult_left_commute: "(x::real) * (y * z) = y * (x * z)"
107 rmult_assoc: "(m::real) * n * k = m * (n * k)"
109 (*for equations: 'bdv' is a meta-constant*)
110 risolate_bdv_add: "((k::real) + bdv = m) = (bdv = m + (-1)*k)"
111 risolate_bdv_mult_add: "((k::real) + n*bdv = m) = (n*bdv = m + (-1)*k)"
112 risolate_bdv_mult: "((n::real) * bdv = m) = (bdv = m / n)"
115 "~(b =!= 0) ==> (a = b) = (a + (-1)*b = 0)"
117 (*17.9.02 aus SqRoot.thy------------------------------vvv---*)
118 root_ge0: "0 <= a ==> 0 <= sqrt a"
119 (*should be dropped with better simplification in eval_rls ...*)
121 "[| 0 <= a; 0 <= b |] ==> (0 <= sqrt a + sqrt b) = True"
123 "[| 0<=a; 0<=b; 0<=c |] ==> (0 <= a * sqrt b + sqrt c) = True"
125 "[| 0<=a; 0<=b; 0<=c |] ==> (0 <= sqrt a + b * sqrt c) = True"
128 rroot_square_inv: "(sqrt a)^^^ 2 = a"
129 rroot_times_root: "sqrt a * sqrt b = sqrt(a*b)"
130 rroot_times_root_assoc: "(a * sqrt b) * sqrt c = a * sqrt(b*c)"
131 rroot_times_root_assoc_p: "sqrt b * (sqrt c * a)= sqrt(b*c) * a"
134 (*for root-equations*)
135 square_equation_left:
136 "[| 0 <= a; 0 <= b |] ==> (((sqrt a)=b)=(a=(b^^^ 2)))"
137 square_equation_right:
138 "[| 0 <= a; 0 <= b |] ==> ((a=(sqrt b))=((a^^^ 2)=b))"
139 (*causes frequently non-termination:*)
141 "[| 0 <= a; 0 <= b |] ==> ((a=b)=((a^^^ 2)=b^^^ 2))"
143 risolate_root_add: "(a+ sqrt c = d) = ( sqrt c = d + (-1)*a)"
144 risolate_root_mult: "(a+b*sqrt c = d) = (b*sqrt c = d + (-1)*a)"
145 risolate_root_div: "(a * sqrt c = d) = ( sqrt c = d / a)"
147 (*for polynomial equations of degree 2; linear case in RatArith*)
148 mult_square: "(a*bdv^^^2 = b) = (bdv^^^2 = b / a)"
149 constant_square: "(a + bdv^^^2 = b) = (bdv^^^2 = b + -1*a)"
150 constant_mult_square: "(a + b*bdv^^^2 = c) = (b*bdv^^^2 = c + -1*a)"
153 "0 <= a ==> (x^^^2 = a) = ((x=sqrt a) | (x=-1*sqrt a))"
155 "(x^^^2 = 0) = (x = 0)"
157 (*isolate root on the LEFT hand side of the equation
158 otherwise shuffling from left to right would not terminate*)
161 "is_root_free a ==> (a = sqrt b) = (a + (-1)*sqrt b = 0)"
163 "is_root_free a ==> (a = c*sqrt b) = (a + (-1)*c*sqrt b = 0)"
164 rroot_to_lhs_add_mult:
165 "is_root_free a ==> (a = d+c*sqrt b) = (a + (-1)*c*sqrt b = d)"
166 (*17.9.02 aus SqRoot.thy------------------------------^^^---*)
171 (** evaluation of numerals and predicates **)
173 (*does a term contain a root ?*)
174 fun eval_root_free (thmid:string) _ (t as (Const(op0,t0) $ arg)) thy =
175 if strip_thy op0 <> "is'_root'_free"
176 then raise error ("eval_root_free: wrong "^op0)
177 else if const_in (strip_thy op0) arg
178 then SOME (mk_thmid thmid ""
179 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
180 Trueprop $ (mk_equality (t, false_as_term)))
181 else SOME (mk_thmid thmid ""
182 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
183 Trueprop $ (mk_equality (t, true_as_term)))
184 | eval_root_free _ _ _ _ = NONE;
186 (*does a term contain a root ?*)
187 fun eval_contains_root (thmid:string) _
188 (t as (Const("Test.contains'_root",t0) $ arg)) thy =
189 if member op = (ids_of arg) "sqrt"
190 then SOME (mk_thmid thmid ""
191 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
192 Trueprop $ (mk_equality (t, true_as_term)))
193 else SOME (mk_thmid thmid ""
194 ((Syntax.string_of_term (thy2ctxt thy)) arg) "",
195 Trueprop $ (mk_equality (t, false_as_term)))
196 | eval_contains_root _ _ _ _ = NONE;
198 calclist':= overwritel (!calclist',
199 [("is_root_free", ("Test.is'_root'_free",
200 eval_root_free"#is_root_free_e")),
201 ("contains_root", ("Test.contains'_root",
202 eval_contains_root"#contains_root_"))
206 fun Term_Ord.term_order (_:subst) tu = (term_ordI [] tu = LESS);
208 (** rule sets GOON **)
211 Rls {id = "testerls", preconds = [], rew_ord = ("termlessI",termlessI),
212 erls = e_rls, srls = Erls,
214 rules = [Thm ("refl",num_str @{thm refl}),
215 Thm ("real_le_refl",num_str @{thm real_le_refl}),
216 Thm ("radd_left_cancel_le",num_str @{thm radd_left_cancel_le}),
217 Thm ("not_true",num_str @{thm not_true}),
218 Thm ("not_false",num_str @{thm not_false}),
219 Thm ("and_true",num_str @{thm and_true}),
220 Thm ("and_false",num_str @{thm and_false}),
221 Thm ("or_true",num_str @{thm or_true}),
222 Thm ("or_false",num_str @{thm or_false}),
223 Thm ("and_commute",num_str @{thm and_commute}),
224 Thm ("or_commute",num_str @{thm or_commute}),
226 Calc ("Atools.is'_const",eval_const "#is_const_"),
227 Calc ("Tools.matches",eval_matches ""),
229 Calc ("op +",eval_binop "#add_"),
230 Calc ("op *",eval_binop "#mult_"),
231 Calc ("Atools.pow" ,eval_binop "#power_"),
233 Calc ("op <",eval_equ "#less_"),
234 Calc ("op <=",eval_equ "#less_equal_"),
236 Calc ("Atools.ident",eval_ident "#ident_")],
237 scr = Script ((term_of o the o (parse thy))
241 (*.for evaluation of conditions in rewrite rules.*)
242 (*FIXXXXXXME 10.8.02: handle like _simplify*)
244 Rls{id = "tval_rls", preconds = [],
245 rew_ord = ("sqrt_right",sqrt_right false (theory "Pure")),
246 erls=testerls,srls = e_rls,
248 rules = [Thm ("refl",num_str @{thm refl}),
249 Thm ("real_le_refl",num_str @{thm real_le_refl}),
250 Thm ("radd_left_cancel_le",num_str @{thm radd_left_cancel_le}),
251 Thm ("not_true",num_str @{thm not_true}),
252 Thm ("not_false",num_str @{thm not_false}),
253 Thm ("and_true",num_str @{thm and_true}),
254 Thm ("and_false",num_str @{thm and_false}),
255 Thm ("or_true",num_str @{thm or_true}),
256 Thm ("or_false",num_str @{thm or_false}),
257 Thm ("and_commute",num_str @{thm and_commute}),
258 Thm ("or_commute",num_str @{or_commute}),
260 Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
262 Thm ("root_ge0",num_str @{thm root_ge0}),
263 Thm ("root_add_ge0",num_str @{thm root_add_ge0}),
264 Thm ("root_ge0_1",num_str @{thm root_ge0_1}),
265 Thm ("root_ge0_2",num_str @{thm root_ge0_2}),
267 Calc ("Atools.is'_const",eval_const "#is_const_"),
268 Calc ("Test.is'_root'_free",eval_root_free "#is_root_free_e"),
269 Calc ("Tools.matches",eval_matches ""),
270 Calc ("Test.contains'_root",
271 eval_contains_root"#contains_root_"),
273 Calc ("op +",eval_binop "#add_"),
274 Calc ("op *",eval_binop "#mult_"),
275 Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
276 Calc ("Atools.pow" ,eval_binop "#power_"),
278 Calc ("op <",eval_equ "#less_"),
279 Calc ("op <=",eval_equ "#less_equal_"),
281 Calc ("Atools.ident",eval_ident "#ident_")],
282 scr = Script ((term_of o the o (parse thy))
287 ruleset' := overwritelthy @{theory} (!ruleset',
288 [("testerls", prep_rls testerls)
292 (*make () dissappear*)
293 val rearrange_assoc =
294 Rls{id = "rearrange_assoc", preconds = [],
295 rew_ord = ("e_rew_ord",e_rew_ord),
296 erls = e_rls, srls = e_rls, calc = [], (*asm_thm=[],*)
298 [Thm ("sym_add_assoc",num_str (@{thm add_assoc} RS @{thm sym})),
299 Thm ("sym_rmult_assoc",num_str (@{thm rmult_assoc} RS @{thm sym}))],
300 scr = Script ((term_of o the o (parse thy))
305 Rls{id = "ac_plus_times", preconds = [], rew_ord = ("term_order",term_order),
306 erls = e_rls, srls = e_rls, calc = [], (*asm_thm=[],*)
308 [Thm ("radd_commute",num_str @{thm radd_commute}),
309 Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
310 Thm ("add_assoc",num_str @{thm add_assoc}),
311 Thm ("rmult_commute",num_str @{thm rmult_commute}),
312 Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
313 Thm ("rmult_assoc",num_str @{thm rmult_assoc})],
314 scr = Script ((term_of o the o (parse thy))
318 (*todo: replace by Rewrite("rnorm_equation_add",num_str @{thm rnorm_equation_add)*)
320 Rls{id = "norm_equation", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
321 erls = tval_rls, srls = e_rls, calc = [], (*asm_thm=[],*)
322 rules = [Thm ("rnorm_equation_add",num_str @{thm rnorm_equation_add)
324 scr = Script ((term_of o the o (parse thy))
330 val STest_simplify = (* vv--- not changed to real by parse*)
331 "Script STest_simplify (t_::'z) = " ^
333 " ((Try (Repeat (Rewrite real_diff_minus False))) @@ " ^
334 " (Try (Repeat (Rewrite radd_mult_distrib2 False))) @@ " ^
335 " (Try (Repeat (Rewrite rdistr_right_assoc False))) @@ " ^
336 " (Try (Repeat (Rewrite rdistr_right_assoc_p False))) @@" ^
337 " (Try (Repeat (Rewrite rdistr_div_right False))) @@ " ^
338 " (Try (Repeat (Rewrite rbinom_power_2 False))) @@ " ^
340 " (Try (Repeat (Rewrite radd_commute False))) @@ " ^
341 " (Try (Repeat (Rewrite radd_left_commute False))) @@ " ^
342 " (Try (Repeat (Rewrite add_assoc False))) @@ " ^
343 " (Try (Repeat (Rewrite rmult_commute False))) @@ " ^
344 " (Try (Repeat (Rewrite rmult_left_commute False))) @@ " ^
345 " (Try (Repeat (Rewrite rmult_assoc False))) @@ " ^
347 " (Try (Repeat (Rewrite radd_real_const_eq False))) @@ " ^
348 " (Try (Repeat (Rewrite radd_real_const False))) @@ " ^
349 " (Try (Repeat (Calculate PLUS))) @@ " ^
350 " (Try (Repeat (Calculate TIMES))) @@ " ^
351 " (Try (Repeat (Calculate divide_))) @@" ^
352 " (Try (Repeat (Calculate POWER))) @@ " ^
354 " (Try (Repeat (Rewrite rcollect_right False))) @@ " ^
355 " (Try (Repeat (Rewrite rcollect_one_left False))) @@ " ^
356 " (Try (Repeat (Rewrite rcollect_one_left_assoc False))) @@ " ^
357 " (Try (Repeat (Rewrite rcollect_one_left_assoc_p False))) @@ " ^
359 " (Try (Repeat (Rewrite rshift_nominator False))) @@ " ^
360 " (Try (Repeat (Rewrite rcancel_den False))) @@ " ^
361 " (Try (Repeat (Rewrite rroot_square_inv False))) @@ " ^
362 " (Try (Repeat (Rewrite rroot_times_root False))) @@ " ^
363 " (Try (Repeat (Rewrite rroot_times_root_assoc_p False))) @@ " ^
364 " (Try (Repeat (Rewrite rsqare False))) @@ " ^
365 " (Try (Repeat (Rewrite power_1 False))) @@ " ^
366 " (Try (Repeat (Rewrite rtwo_of_the_same False))) @@ " ^
367 " (Try (Repeat (Rewrite rtwo_of_the_same_assoc_p False))) @@ " ^
369 " (Try (Repeat (Rewrite rmult_1 False))) @@ " ^
370 " (Try (Repeat (Rewrite rmult_1_right False))) @@ " ^
371 " (Try (Repeat (Rewrite rmult_0 False))) @@ " ^
372 " (Try (Repeat (Rewrite rmult_0_right False))) @@ " ^
373 " (Try (Repeat (Rewrite radd_0 False))) @@ " ^
374 " (Try (Repeat (Rewrite radd_0_right False)))) " ^
378 (* expects * distributed over + *)
380 Rls{id = "Test_simplify", preconds = [],
381 rew_ord = ("sqrt_right",sqrt_right false (theory "Pure")),
382 erls = tval_rls, srls = e_rls,
383 calc=[(*since 040209 filled by prep_rls*)],
386 Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
387 Thm ("radd_mult_distrib2",num_str @{thm radd_mult_distrib2}),
388 Thm ("rdistr_right_assoc",num_str @{thm rdistr_right_assoc}),
389 Thm ("rdistr_right_assoc_p",num_str @{thm rdistr_right_assoc_p}),
390 Thm ("rdistr_div_right",num_str @{thm rdistr_div_right}),
391 Thm ("rbinom_power_2",num_str @{thm rbinom_power_2}),
393 Thm ("radd_commute",num_str @{thm radd_commute}),
394 Thm ("radd_left_commute",num_str @{thm radd_left_commute}),
395 Thm ("add_assoc",num_str @{thm add_assoc}),
396 Thm ("rmult_commute",num_str @{thm rmult_commute}),
397 Thm ("rmult_left_commute",num_str @{thm rmult_left_commute}),
398 Thm ("rmult_assoc",num_str @{thm rmult_assoc}),
400 Thm ("radd_real_const_eq",num_str @{thm radd_real_const_eq}),
401 Thm ("radd_real_const",num_str @{thm radd_real_const}),
402 (* these 2 rules are invers to distr_div_right wrt. termination.
403 thus they MUST be done IMMEDIATELY before calc *)
404 Calc ("op +", eval_binop "#add_"),
405 Calc ("op *", eval_binop "#mult_"),
406 Calc ("HOL.divide", eval_cancel "#divide_e"),
407 Calc ("Atools.pow", eval_binop "#power_"),
409 Thm ("rcollect_right",num_str @{thm rcollect_right}),
410 Thm ("rcollect_one_left",num_str @{thm rcollect_one_left}),
411 Thm ("rcollect_one_left_assoc",num_str @{thm rcollect_one_left_assoc}),
412 Thm ("rcollect_one_left_assoc_p",num_str @{thm rcollect_one_left_assoc_p}),
414 Thm ("rshift_nominator",num_str @{thm rshift_nominator}),
415 Thm ("rcancel_den",num_str @{thm rcancel_den}),
416 Thm ("rroot_square_inv",num_str @{thm rroot_square_inv}),
417 Thm ("rroot_times_root",num_str @{thm rroot_times_root}),
418 Thm ("rroot_times_root_assoc_p",num_str @{thm rroot_times_root_assoc_p}),
419 Thm ("rsqare",num_str @{thm rsqare}),
420 Thm ("power_1",num_str @{power_1}),
421 Thm ("rtwo_of_the_same",num_str @{thm rtwo_of_the_same}),
422 Thm ("rtwo_of_the_same_assoc_p",num_str @{thm rtwo_of_the_same_assoc_p}),
424 Thm ("rmult_1",num_str @{thm rmult_1}),
425 Thm ("rmult_1_right",num_str @{thm rmult_1_right}),
426 Thm ("rmult_0",num_str @{thm rmult_0}),
427 Thm ("rmult_0_right",num_str @{thm rmult_0_right}),
428 Thm ("radd_0",num_str @{thm radd_0}),
429 Thm ("radd_0_right",num_str @{thm radd_0_right})
431 scr = Script ((term_of o the o (parse thy)) "empty_script")
432 (*since 040209 filled by prep_rls: STest_simplify*)
443 (*isolate the root in a root-equation*)
445 Rls{id = "isolate_root", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
446 erls=tval_rls,srls = e_rls, calc=[],(*asm_thm = [], *)
447 rules = [Thm ("rroot_to_lhs",num_str @{thm rroot_to_lhs}),
448 Thm ("rroot_to_lhs_mult",num_str @{thm rroot_to_lhs_mult}),
449 Thm ("rroot_to_lhs_add_mult",num_str @{thm rroot_to_lhs_add_mult}),
450 Thm ("risolate_root_add",num_str @{thm risolate_root_add}),
451 Thm ("risolate_root_mult",num_str @{thm risolate_root_mult}),
452 Thm ("risolate_root_div",num_str @{thm risolate_root_div}) ],
453 scr = Script ((term_of o the o (parse thy))
457 (*isolate the bound variable in an equation; 'bdv' is a meta-constant*)
459 Rls{id = "isolate_bdv", preconds = [], rew_ord = ("e_rew_ord",e_rew_ord),
460 erls=tval_rls,srls = e_rls, calc=[],(*asm_thm = [], *)
462 [Thm ("risolate_bdv_add",num_str @{thm risolate_bdv_add}),
463 Thm ("risolate_bdv_mult_add",num_str @{thm risolate_bdv_mult_add}),
464 Thm ("risolate_bdv_mult",num_str @{thm risolate_bdv_mult}),
465 Thm ("mult_square",num_str @{mult_square}),
466 Thm ("constant_square",num_str @{constant_square}),
467 Thm ("constant_mult_square",num_str @{constant_mult_square})
469 scr = Script ((term_of o the o (parse thy))
476 (* association list for calculate_, calculate
477 "op +" etc. not usable in scripts *)
481 ("Vars" ,("Tools.Vars" ,eval_var "#Vars_")),
482 ("matches",("Tools.matches",eval_matches "#matches_")),
483 ("lhs" ,("Tools.lhs" ,eval_lhs "")),
485 ("PLUS" ,("op +" ,eval_binop "#add_")),
486 ("TIMES" ,("op *" ,eval_binop "#mult_")),
487 ("DIVIDE" ,("HOL.divide" ,eval_cancel "#divide_e")),
488 ("POWER" ,("Atools.pow" ,eval_binop "#power_")),
489 ("is_const",("Atools.is'_const",eval_const "#is_const_")),
490 ("le" ,("op <" ,eval_equ "#less_")),
491 ("leq" ,("op <=" ,eval_equ "#less_equal_")),
492 ("ident" ,("Atools.ident",eval_ident "#ident_")),
493 (*von hier (ehem.SqRoot*)
494 ("sqrt" ,("NthRoot.sqrt" ,eval_sqrt "#sqrt_")),
495 ("Test.is_root_free",("is'_root'_free", eval_root_free"#is_root_free_e")),
496 ("Test.contains_root",("contains'_root",
497 eval_contains_root"#contains_root_"))
500 ruleset' := overwritelthy @{theory} (!ruleset',
501 [("Test_simplify", prep_rls Test_simplify),
502 ("tval_rls", prep_rls tval_rls),
503 ("isolate_root", prep_rls isolate_root),
504 ("isolate_bdv", prep_rls isolate_bdv),
506 prep_rls (append_rls "matches" testerls
507 [Calc ("Tools.matches",eval_matches "#matches_")]))
510 (** problem types **)
512 (prep_pbt thy "pbl_test" [] e_pblID
517 (prep_pbt thy "pbl_test_equ" [] e_pblID
518 (["equation","test"],
519 [("#Given" ,["equality e_e","solveFor v_v"]),
520 ("#Where" ,["matches (?a = ?b) e_e"]),
521 ("#Find" ,["solutions v_i"])
524 SOME "solve (e_e::bool, v_v)", []));
527 (prep_pbt thy "pbl_test_uni" [] e_pblID
528 (["univariate","equation","test"],
529 [("#Given" ,["equality e_e","solveFor v_v"]),
530 ("#Where" ,["matches (?a = ?b) e_e"]),
531 ("#Find" ,["solutions v_i"])
534 SOME "solve (e_e::bool, v_v)", []));
537 (prep_pbt thy "pbl_test_uni_lin" [] e_pblID
538 (["linear","univariate","equation","test"],
539 [("#Given" ,["equality e_e","solveFor v_v"]),
540 ("#Where" ,["(matches ( v_v = 0) e_e) | (matches ( ?b*v_ = 0) e_e) |" ^
541 "(matches (?a+v_ = 0) e_e) | (matches (?a+?b*v_ = 0) e_e) "]),
542 ("#Find" ,["solutions v_i"])
545 SOME "solve (e_e::bool, v_v)", [["Test","solve_linear"]]));
551 [("#Given" ,"boolTestGiven g_"),
552 ("#Find" ,"boolTestFind f_")
559 [("#Given" ,"boolTestGiven g_"),
560 ("#Find" ,"boolTestFind f_")
565 val ttt = (term_of o the o (parse (theory "Isac"))) "(matches ( v_v = 0) e_e)";
572 (prep_met (theory "Diff") "met_test" [] e_metID
575 {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
576 crls=Atools_erls, nrls=e_rls(*,
577 asm_rls=[],asm_thm=[]*)}, "empty_script"));
580 (prep_met (theory "Script")
581 (e_metID,(*empty method*)
583 {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,prls=e_rls,calc=[],
584 asm_rls=[],asm_thm=[]},
587 (prep_met thy "met_test_solvelin" [] e_metID
588 (["Test","solve_linear"]:metID,
589 [("#Given" ,["equality e_e","solveFor v_v"]),
590 ("#Where" ,["matches (?a = ?b) e_e"]),
591 ("#Find" ,["solutions v_i"])
593 {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,
594 prls=assoc_rls "matches",
596 crls=tval_rls, nrls=Test_simplify},
597 "Script Solve_linear (e_e::bool) (v_v::real)= " ^
600 " (((Rewrite_Set_Inst [(bdv,v_::real)] isolate_bdv False) @@" ^
601 " (Rewrite_Set Test_simplify False))) e_e" ^
604 (*, prep_met thy (*test for equations*)
605 (["Test","testeq"]:metID,
606 [("#Given" ,["boolTestGiven g_"]),
607 ("#Find" ,["boolTestFind f_"])
609 {rew_ord'="e_rew_ord",rls'="tval_rls",asm_rls=[],
610 asm_thm=[("square_equation_left","")]},
611 "Script Testeq (eq_::bool) = " ^
613 " (let e_e = Try (Repeat (Rewrite rroot_square_inv False eq_)); " ^
614 " e_e = Try (Repeat (Rewrite square_equation_left True e_e)); " ^
615 " e_e = Try (Repeat (Rewrite rmult_0 False e_e)) " ^
616 " in e_e) Until (is_root_free e_e)" (*deleted*)
624 ruleset' := overwritelthy @{theory} (!ruleset',
625 [("norm_equation", prep_rls norm_equation),
626 ("ac_plus_times", prep_rls ac_plus_times),
627 ("rearrange_assoc", prep_rls rearrange_assoc)
631 fun bin_o (Const (op_,(Type ("fun",
632 [Type (s2,[]),Type ("fun",
633 [Type (s4,tl4),Type (s5,tl5)])])))) =
634 if (s2=s4)andalso(s4=s5)then[op_]else[]
637 fun bin_op (t1 $ t2) = union op = (bin_op t1) (bin_op t2)
638 | bin_op t = bin_o t;
639 fun is_bin_op t = ((bin_op t)<>[]);
641 fun bin_op_arg1 ((Const (op_,(Type ("fun",
642 [Type (s2,[]),Type ("fun",
643 [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) =
645 fun bin_op_arg2 ((Const (op_,(Type ("fun",
646 [Type (s2,[]),Type ("fun",
647 [Type (s4,tl4),Type (s5,tl5)])]))))$ arg1 $ arg2) =
651 exception NO_EQUATION_TERM;
652 fun is_equation ((Const ("op =",(Type ("fun",
653 [Type (_,[]),Type ("fun",
654 [Type (_,[]),Type ("bool",[])])])))) $ _ $ _)
656 | is_equation _ = false;
657 fun equ_lhs ((Const ("op =",(Type ("fun",
658 [Type (_,[]),Type ("fun",
659 [Type (_,[]),Type ("bool",[])])])))) $ l $ r)
661 | equ_lhs _ = raise NO_EQUATION_TERM;
662 fun equ_rhs ((Const ("op =",(Type ("fun",
663 [Type (_,[]),Type ("fun",
664 [Type (_,[]),Type ("bool",[])])])))) $ l $ r)
666 | equ_rhs _ = raise NO_EQUATION_TERM;
669 fun atom (Const (_,Type (_,[]))) = true
670 | atom (Free (_,Type (_,[]))) = true
671 | atom (Var (_,Type (_,[]))) = true
672 (*| atom (_ (_,"?DUMMY" )) = true ..ML-error *)
673 | atom((Const ("Bin.integ_of_bin",_)) $ _) = true
676 fun varids (Const (s,Type (_,[]))) = [strip_thy s]
677 | varids (Free (s,Type (_,[]))) = if is_no s then []
679 | varids (Var((s,_),Type (_,[]))) = [strip_thy s]
680 (*| varids (_ (s,"?DUMMY" )) = ..ML-error *)
681 | varids((Const ("Bin.integ_of_bin",_)) $ _)= [](*8.01: superfluous?*)
682 | varids (Abs(a,T,t)) = union op = [a] (varids t)
683 | varids (t1 $ t2) = union op = (varids t1) (varids t2)
685 (*> val t = term_of (hd (parse Diophant.thy "x"));
686 val t = Free ("x","?DUMMY") : term
688 val it = [] : string list [] !!! *)
691 fun bin_ops_only ((Const op_) $ t1 $ t2) =
692 if(is_bin_op (Const op_))
693 then(bin_ops_only t1)andalso(bin_ops_only t2)
696 if atom t then true else bin_ops_only t;
698 fun polynomial opl t bdVar = (* bdVar TODO *)
699 subset op = (bin_op t, opl) andalso (bin_ops_only t);
701 fun poly_equ opl bdVar t = is_equation t (* bdVar TODO *)
702 andalso polynomial opl (equ_lhs t) bdVar
703 andalso polynomial opl (equ_rhs t) bdVar
704 andalso (subset op = (varids bdVar, varids (equ_lhs t)) orelse
705 subset op = (varids bdVar, varids (equ_lhs t)));
708 let fun max_ m [] = m
709 | max_ m (i::is) = if m<i then max_ i is else max_ m is;
710 in max_ (hd is) is end;
714 fun max (a,b) = if a < b then b else a;
716 fun degree addl mul bdVar t =
718 fun deg _ _ v (Const (s,Type (_,[]))) = if v=strip_thy s then 1 else 0
719 | deg _ _ v (Free (s,Type (_,[]))) = if v=strip_thy s then 1 else 0
720 | deg _ _ v (Var((s,_),Type (_,[]))) = if v=strip_thy s then 1 else 0
721 (*| deg _ _ v (_ (s,"?DUMMY" )) = ..ML-error *)
722 | deg _ _ v((Const ("Bin.integ_of_bin",_)) $ _ )= 0
723 | deg addl mul v (h $ t1 $ t2) =
724 if subset op = (bin_op h, addl)
725 then max (deg addl mul v t1 ,deg addl mul v t2)
726 else (*mul!*)(deg addl mul v t1)+(deg addl mul v t2)
727 in if polynomial (addl @ [mul]) t bdVar
728 then SOME (deg addl mul (id_of bdVar) t) else (NONE:int option)
730 fun degree_ addl mul bdVar t = (* do not export *)
731 let fun opt (SOME i)= i
733 in opt (degree addl mul bdVar t) end;
736 fun linear addl mul t bdVar = (degree_ addl mul bdVar t)<2;
738 fun linear_equ addl mul bdVar t =
740 then let val degl = degree_ addl mul bdVar (equ_lhs t);
741 val degr = degree_ addl mul bdVar (equ_rhs t)
742 in if (degl>0 orelse degr>0)andalso max(degl,degr)<2
746 (* strip_thy op_ before *)
747 fun is_div_op (dv,(Const (op_,(Type ("fun",
748 [Type (s2,[]),Type ("fun",
749 [Type (s4,tl4),Type (s5,tl5)])])))) )= (dv = strip_thy op_)
750 | is_div_op _ = false;
752 fun is_denom bdVar div_op t =
753 let fun is bool[v]dv (Const (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
754 | is bool[v]dv (Free (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
755 | is bool[v]dv (Var((s,_),Type(_,[])))= bool andalso(if v=strip_thy s then true else false)
756 | is bool[v]dv((Const ("Bin.integ_of_bin",_)) $ _) = false
757 | is bool[v]dv (h$n$d) =
759 then (is false[v]dv n)orelse(is true[v]dv d)
760 else (is bool [v]dv n)orelse(is bool[v]dv d)
761 in is false (varids bdVar) (strip_thy div_op) t end;
764 fun rational t div_op bdVar =
765 is_denom bdVar div_op t andalso bin_ops_only t;
769 (** problem types **)
772 (prep_pbt thy "pbl_test_uni_plain2" [] e_pblID
773 (["plain_square","univariate","equation","test"],
774 [("#Given" ,["equality e_e","solveFor v_v"]),
775 ("#Where" ,["(matches (?a + ?b*v_ ^^^2 = 0) e_e) |" ^
776 "(matches ( ?b*v_ ^^^2 = 0) e_e) |" ^
777 "(matches (?a + v_v ^^^2 = 0) e_e) |" ^
778 "(matches ( v_v ^^^2 = 0) e_e)"]),
779 ("#Find" ,["solutions v_i"])
782 SOME "solve (e_e::bool, v_v)", [["Test","solve_plain_square"]]));
784 val e_e = (term_of o the o (parse thy)) "e_::bool";
785 val ve = (term_of o the o (parse thy)) "4 + 3*x^^^2 = 0";
788 val pre = (term_of o the o (parse thy))
789 "(matches (a + b*v_ ^^^2 = 0, e_e::bool)) |" ^
790 "(matches ( b*v_ ^^^2 = 0, e_e::bool)) |" ^
791 "(matches (a + v_v ^^^2 = 0, e_e::bool)) |" ^
792 "(matches ( v_v ^^^2 = 0, e_e::bool))";
793 val prei = subst_atomic env pre;
794 val cpre = (cterm_of thy) prei;
796 val SOME (ct,_) = rewrite_set_ thy false tval_rls cpre;
797 val ct = "True | False | False | False" : cterm
799 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
800 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
801 > val SOME (ct,_) = rewrite_ thy sqrt_right tval_rls false or_false ct;
802 val ct = "True" : cterm
807 (prep_pbt thy "pbl_test_uni_poly" [] e_pblID
808 (["polynomial","univariate","equation","test"],
809 [("#Given" ,["equality (v_ ^^^2 + p_ * v_v + q__ = 0)","solveFor v_v"]),
810 ("#Where" ,["False"]),
811 ("#Find" ,["solutions v_i"])
813 e_rls, SOME "solve (e_e::bool, v_v)", []));
816 (prep_pbt thy "pbl_test_uni_poly_deg2" [] e_pblID
817 (["degree_two","polynomial","univariate","equation","test"],
818 [("#Given" ,["equality (v_ ^^^2 + p_ * v_v + q__ = 0)","solveFor v_v"]),
819 ("#Find" ,["solutions v_i"])
821 e_rls, SOME "solve (v_ ^^^2 + p_ * v_v + q__ = 0, v_v)", []));
824 (prep_pbt thy "pbl_test_uni_poly_deg2_pq" [] e_pblID
825 (["pq_formula","degree_two","polynomial","univariate","equation","test"],
826 [("#Given" ,["equality (v_ ^^^2 + p_ * v_v + q__ = 0)","solveFor v_v"]),
827 ("#Find" ,["solutions v_i"])
829 e_rls, SOME "solve (v_ ^^^2 + p_ * v_v + q__ = 0, v_v)", []));
832 (prep_pbt thy "pbl_test_uni_poly_deg2_abc" [] e_pblID
833 (["abc_formula","degree_two","polynomial","univariate","equation","test"],
834 [("#Given" ,["equality (a_ * x ^^^2 + b_ * x + c_ = 0)","solveFor v_v"]),
835 ("#Find" ,["solutions v_i"])
837 e_rls, SOME "solve (a_ * x ^^^2 + b_ * x + c_ = 0, v_v)", []));
840 (prep_pbt thy "pbl_test_uni_root" [] e_pblID
841 (["squareroot","univariate","equation","test"],
842 [("#Given" ,["equality e_e","solveFor v_v"]),
843 ("#Where" ,["contains_root (e_e::bool)"]),
844 ("#Find" ,["solutions v_i"])
846 append_rls "contains_root" e_rls [Calc ("Test.contains'_root",
847 eval_contains_root "#contains_root_")],
848 SOME "solve (e_e::bool, v_v)", [["Test","square_equation"]]));
851 (prep_pbt thy "pbl_test_uni_norm" [] e_pblID
852 (["normalize","univariate","equation","test"],
853 [("#Given" ,["equality e_e","solveFor v_v"]),
855 ("#Find" ,["solutions v_i"])
857 e_rls, SOME "solve (e_e::bool, v_v)", [["Test","norm_univar_equation"]]));
860 (prep_pbt thy "pbl_test_uni_roottest" [] e_pblID
861 (["sqroot-test","univariate","equation","test"],
862 [("#Given" ,["equality e_e","solveFor v_v"]),
863 (*("#Where" ,["contains_root (e_e::bool)"]),*)
864 ("#Find" ,["solutions v_i"])
866 e_rls, SOME "solve (e_e::bool, v_v)", []));
869 (#ppc o get_pbt) ["sqroot-test","univariate","equation"];
874 (prep_met thy "met_test_sqrt" [] e_metID
875 (*root-equation, version for tests before 8.01.01*)
876 (["Test","sqrt-equ-test"]:metID,
877 [("#Given" ,["equality e_e","solveFor v_v"]),
878 ("#Where" ,["contains_root (e_e::bool)"]),
879 ("#Find" ,["solutions v_i"])
881 {rew_ord'="e_rew_ord",rls'=tval_rls,
882 srls =append_rls "srls_contains_root" e_rls
883 [Calc ("Test.contains'_root",eval_contains_root "")],
884 prls =append_rls "prls_contains_root" e_rls
885 [Calc ("Test.contains'_root",eval_contains_root "")],
887 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
888 asm_thm=[("square_equation_left",""),
889 ("square_equation_right","")]*)},
890 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
892 " ((While (contains_root e_e) Do" ^
893 " ((Rewrite square_equation_left True) @@" ^
894 " (Try (Rewrite_Set Test_simplify False)) @@" ^
895 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
896 " (Try (Rewrite_Set isolate_root False)) @@" ^
897 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
898 " (Try (Rewrite_Set norm_equation False)) @@" ^
899 " (Try (Rewrite_Set Test_simplify False)) @@" ^
900 " (Rewrite_Set_Inst [(bdv,v_::real)] isolate_bdv False) @@" ^
901 " (Try (Rewrite_Set Test_simplify False)))" ^
907 (prep_met thy "met_test_sqrt2" [] e_metID
908 (*root-equation ... for test-*.sml until 8.01*)
909 (["Test","squ-equ-test2"]:metID,
910 [("#Given" ,["equality e_e","solveFor v_v"]),
911 ("#Find" ,["solutions v_i"])
913 {rew_ord'="e_rew_ord",rls'=tval_rls,
914 srls = append_rls "srls_contains_root" e_rls
915 [Calc ("Test.contains'_root",eval_contains_root"")],
917 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
918 asm_thm=[("square_equation_left",""),
919 ("square_equation_right","")]*)},
920 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
922 " ((While (contains_root e_e) Do" ^
923 " ((Rewrite square_equation_left True) @@" ^
924 " (Try (Rewrite_Set Test_simplify False)) @@" ^
925 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
926 " (Try (Rewrite_Set isolate_root False)) @@" ^
927 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
928 " (Try (Rewrite_Set norm_equation False)) @@" ^
929 " (Try (Rewrite_Set Test_simplify False)) @@" ^
930 " (Rewrite_Set_Inst [(bdv,v_::real)] isolate_bdv False) @@" ^
931 " (Try (Rewrite_Set Test_simplify False)))" ^
933 " (L_::bool list) = Tac subproblem_equation_dummy; " ^
934 " L_ = Tac solve_equation_dummy " ^
935 " in Check_elementwise L_ {(v_v::real). Assumptions})"
939 (prep_met thy "met_test_squ_sub" [] e_metID
940 (*tests subproblem fixed linear*)
941 (["Test","squ-equ-test-subpbl1"]:metID,
942 [("#Given" ,["equality e_e","solveFor v_v"]),
943 ("#Find" ,["solutions v_i"])
945 {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,prls=e_rls,calc=[],
946 crls=tval_rls, nrls=Test_simplify},
947 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
948 " (let e_e = ((Try (Rewrite_Set norm_equation False)) @@ " ^
949 " (Try (Rewrite_Set Test_simplify False))) e_; " ^
950 "(L_::bool list) = (SubProblem (Test_,[linear,univariate,equation,test]," ^
951 " [Test,solve_linear]) [bool_ e_e, real_ v_])" ^
952 "in Check_elementwise L_ {(v_v::real). Assumptions})"
956 (prep_met thy "met_test_squ_sub2" [] e_metID
957 (*tests subproblem fixed degree 2*)
958 (["Test","squ-equ-test-subpbl2"]:metID,
959 [("#Given" ,["equality e_e","solveFor v_v"]),
960 ("#Find" ,["solutions v_i"])
962 {rew_ord'="e_rew_ord",rls'=tval_rls,srls=e_rls,prls=e_rls,calc=[],
963 crls=tval_rls, nrls=e_rls(*,
964 asm_rls=[],asm_thm=[("square_equation_left",""),
965 ("square_equation_right","")]*)},
966 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
967 " (let e_e = Try (Rewrite_Set norm_equation False) e_; " ^
968 "(L_::bool list) = (SubProblem (Test_,[linear,univariate,equation,test]," ^
969 " [Test,solve_by_pq_formula]) [bool_ e_e, real_ v_])" ^
970 "in Check_elementwise L_ {(v_v::real). Assumptions})"
974 (prep_met thy "met_test_squ_nonterm" [] e_metID
975 (*root-equation: see foils..., but notTerminating*)
976 (["Test","square_equation...notTerminating"]:metID,
977 [("#Given" ,["equality e_e","solveFor v_v"]),
978 ("#Find" ,["solutions v_i"])
980 {rew_ord'="e_rew_ord",rls'=tval_rls,
981 srls = append_rls "srls_contains_root" e_rls
982 [Calc ("Test.contains'_root",eval_contains_root"")],
984 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
985 asm_thm=[("square_equation_left",""),
986 ("square_equation_right","")]*)},
987 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
989 " ((While (contains_root e_e) Do" ^
990 " ((Rewrite square_equation_left True) @@" ^
991 " (Try (Rewrite_Set Test_simplify False)) @@" ^
992 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
993 " (Try (Rewrite_Set isolate_root False)) @@" ^
994 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
995 " (Try (Rewrite_Set norm_equation False)) @@" ^
996 " (Try (Rewrite_Set Test_simplify False)))" ^
998 " (L_::bool list) = " ^
999 " (SubProblem (Test_,[linear,univariate,equation,test]," ^
1000 " [Test,solve_linear]) [bool_ e_e, real_ v_])" ^
1001 "in Check_elementwise L_ {(v_v::real). Assumptions})"
1005 (prep_met thy "met_test_eq1" [] e_metID
1007 (["Test","square_equation1"]:metID,
1008 [("#Given" ,["equality e_e","solveFor v_v"]),
1009 ("#Find" ,["solutions v_i"])
1011 {rew_ord'="e_rew_ord",rls'=tval_rls,
1012 srls = append_rls "srls_contains_root" e_rls
1013 [Calc ("Test.contains'_root",eval_contains_root"")],
1015 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
1016 asm_thm=[("square_equation_left",""),
1017 ("square_equation_right","")]*)},
1018 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
1020 " ((While (contains_root e_e) Do" ^
1021 " ((Rewrite square_equation_left True) @@" ^
1022 " (Try (Rewrite_Set Test_simplify False)) @@" ^
1023 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
1024 " (Try (Rewrite_Set isolate_root False)) @@" ^
1025 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
1026 " (Try (Rewrite_Set norm_equation False)) @@" ^
1027 " (Try (Rewrite_Set Test_simplify False)))" ^
1029 " (L_::bool list) = (SubProblem (Test_,[linear,univariate,equation,test]," ^
1030 " [Test,solve_linear]) [bool_ e_e, real_ v_])" ^
1031 " in Check_elementwise L_ {(v_v::real). Assumptions})"
1035 (prep_met thy "met_test_squ2" [] e_metID
1037 (["Test","square_equation2"]:metID,
1038 [("#Given" ,["equality e_e","solveFor v_v"]),
1039 ("#Find" ,["solutions v_i"])
1041 {rew_ord'="e_rew_ord",rls'=tval_rls,
1042 srls = append_rls "srls_contains_root" e_rls
1043 [Calc ("Test.contains'_root",eval_contains_root"")],
1045 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
1046 asm_thm=[("square_equation_left",""),
1047 ("square_equation_right","")]*)},
1048 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
1050 " ((While (contains_root e_e) Do" ^
1051 " (((Rewrite square_equation_left True) Or " ^
1052 " (Rewrite square_equation_right True)) @@" ^
1053 " (Try (Rewrite_Set Test_simplify False)) @@" ^
1054 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
1055 " (Try (Rewrite_Set isolate_root False)) @@" ^
1056 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
1057 " (Try (Rewrite_Set norm_equation False)) @@" ^
1058 " (Try (Rewrite_Set Test_simplify False)))" ^
1060 " (L_::bool list) = (SubProblem (Test_,[plain_square,univariate,equation,test]," ^
1061 " [Test,solve_plain_square]) [bool_ e_e, real_ v_])" ^
1062 " in Check_elementwise L_ {(v_v::real). Assumptions})"
1066 (prep_met thy "met_test_squeq" [] e_metID
1068 (["Test","square_equation"]:metID,
1069 [("#Given" ,["equality e_e","solveFor v_v"]),
1070 ("#Find" ,["solutions v_i"])
1072 {rew_ord'="e_rew_ord",rls'=tval_rls,
1073 srls = append_rls "srls_contains_root" e_rls
1074 [Calc ("Test.contains'_root",eval_contains_root"")],
1076 crls=tval_rls, nrls=e_rls(*,asm_rls=[],
1077 asm_thm=[("square_equation_left",""),
1078 ("square_equation_right","")]*)},
1079 "Script Solve_root_equation (e_e::bool) (v_v::real) = " ^
1081 " ((While (contains_root e_e) Do" ^
1082 " (((Rewrite square_equation_left True) Or" ^
1083 " (Rewrite square_equation_right True)) @@" ^
1084 " (Try (Rewrite_Set Test_simplify False)) @@" ^
1085 " (Try (Rewrite_Set rearrange_assoc False)) @@" ^
1086 " (Try (Rewrite_Set isolate_root False)) @@" ^
1087 " (Try (Rewrite_Set Test_simplify False)))) @@" ^
1088 " (Try (Rewrite_Set norm_equation False)) @@" ^
1089 " (Try (Rewrite_Set Test_simplify False)))" ^
1091 " (L_::bool list) = (SubProblem (Test_,[univariate,equation,test]," ^
1092 " [no_met]) [bool_ e_e, real_ v_])" ^
1093 " in Check_elementwise L_ {(v_v::real). Assumptions})"
1097 (prep_met thy "met_test_eq_plain" [] e_metID
1098 (*solve_plain_square*)
1099 (["Test","solve_plain_square"]:metID,
1100 [("#Given",["equality e_e","solveFor v_v"]),
1101 ("#Where" ,["(matches (?a + ?b*v_ ^^^2 = 0) e_e) |" ^
1102 "(matches ( ?b*v_ ^^^2 = 0) e_e) |" ^
1103 "(matches (?a + v_v ^^^2 = 0) e_e) |" ^
1104 "(matches ( v_v ^^^2 = 0) e_e)"]),
1105 ("#Find" ,["solutions v_i"])
1107 {rew_ord'="e_rew_ord",rls'=tval_rls,calc=[],srls=e_rls,
1108 prls = assoc_rls "matches",
1109 crls=tval_rls, nrls=e_rls(*,
1110 asm_rls=[],asm_thm=[]*)},
1111 "Script Solve_plain_square (e_e::bool) (v_v::real) = " ^
1112 " (let e_e = ((Try (Rewrite_Set isolate_bdv False)) @@ " ^
1113 " (Try (Rewrite_Set Test_simplify False)) @@ " ^
1114 " ((Rewrite square_equality_0 False) Or " ^
1115 " (Rewrite square_equality True)) @@ " ^
1116 " (Try (Rewrite_Set tval_rls False))) e_e " ^
1117 " in ((Or_to_List e_e)::bool list))"
1121 (prep_met thy "met_test_norm_univ" [] e_metID
1122 (["Test","norm_univar_equation"]:metID,
1123 [("#Given",["equality e_e","solveFor v_v"]),
1125 ("#Find" ,["solutions v_i"])
1127 {rew_ord'="e_rew_ord",rls'=tval_rls,srls = e_rls,prls=e_rls,
1129 crls=tval_rls, nrls=e_rls(*,asm_rls=[],asm_thm=[]*)},
1130 "Script Norm_univar_equation (e_e::bool) (v_v::real) = " ^
1131 " (let e_e = ((Try (Rewrite rnorm_equation_add False)) @@ " ^
1132 " (Try (Rewrite_Set Test_simplify False))) e_e " ^
1133 " in (SubProblem (Test_,[univariate,equation,test], " ^
1134 " [no_met]) [bool_ e_e, real_ v_]))"
1139 (*17.9.02 aus SqRoot.ML------------------------------^^^---*)
1141 (*8.4.03 aus Poly.ML--------------------------------vvv---
1142 make_polynomial ---> make_poly
1143 ^-- for user ^-- for systest _ONLY_*)
1145 local (*. for make_polytest .*)
1147 open Term; (* for type order = EQUAL | LESS | GREATER *)
1149 fun pr_ord EQUAL = "EQUAL"
1150 | pr_ord LESS = "LESS"
1151 | pr_ord GREATER = "GREATER";
1153 fun dest_hd' (Const (a, T)) = (* ~ term.ML *)
1155 "Atools.pow" => ((("|||||||||||||", 0), T), 0) (*WN greatest *)
1156 | _ => (((a, 0), T), 0))
1157 | dest_hd' (Free (a, T)) = (((a, 0), T), 1)
1158 | dest_hd' (Var v) = (v, 2)
1159 | dest_hd' (Bound i) = ((("", i), dummyT), 3)
1160 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
1162 fun get_order_pow (t $ (Free(order,_))) =
1163 (case int_of_str (order) of
1166 | get_order_pow _ = 0;
1168 fun size_of_term' (Const(str,_) $ t) =
1169 if "Atools.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*)
1170 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
1171 | size_of_term' (f$t) = size_of_term' f + size_of_term' t
1172 | size_of_term' _ = 1;
1174 fun Term_Ord.term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *)
1175 (case Term_Ord.term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) | ord => ord)
1176 | Term_Ord.term_ord' pr thy (t, u) =
1179 val (f, ts) = strip_comb t and (g, us) = strip_comb u;
1180 val _=writeln("t= f@ts= " ^ "" ^
1181 ((Syntax.string_of_term (thy2ctxt thy)) f)^ "\" @ " ^ "[" ^
1182 (commas(map(Syntax.string_of_term (thy2ctxt thy)) ts)) ^ "]""");
1183 val _=writeln("u= g@us= " ^ "" ^
1184 ((Syntax.string_of_term (thy2ctxt thy)) g) ^ "\" @ " ^ "[" ^
1185 (commas(map(Syntax.string_of_term (thy2ctxt thy)) us))^"]""");
1186 val _=writeln("size_of_term(t,u)= ("^
1187 (string_of_int(size_of_term' t)) ^ ", " ^
1188 (string_of_int(size_of_term' u)) ^ ")");
1189 val _=writeln("hd_ord(f,g) = " ^ ((pr_ord o hd_ord)(f,g)));
1190 val _=writeln("terms_ord(ts,us) = " ^
1191 ((pr_ord o terms_ord str false)(ts,us)));
1192 val _=writeln("-------");
1195 case int_ord (size_of_term' t, size_of_term' u) of
1197 let val (f, ts) = strip_comb t and (g, us) = strip_comb u in
1198 (case hd_ord (f, g) of EQUAL => (terms_ord str pr) (ts, us)
1202 and hd_ord (f, g) = (* ~ term.ML *)
1203 prod_ord (prod_ord indexname_ord Term_Ord.typ_ord) int_ord (dest_hd' f, dest_hd' g)
1204 and terms_ord str pr (ts, us) =
1205 list_ord (term_ord' pr (assoc_thy "Isac.thy"))(ts, us);
1208 fun ord_make_polytest (pr:bool) thy (_:subst) tu =
1209 (term_ord' pr thy(***) tu = LESS );
1213 rew_ord' := overwritel (!rew_ord',
1214 [("termlessI", termlessI),
1215 ("ord_make_polytest", ord_make_polytest false thy)
1218 (*WN060510 this was a preparation for prep_rls ...
1219 val scr_make_polytest =
1220 "Script Expand_binomtest t_ =" ^
1222 "((Try (Repeat (Rewrite real_diff_minus False))) @@ " ^
1224 " (Try (Repeat (Rewrite left_distrib False))) @@ " ^
1225 " (Try (Repeat (Rewrite right_distrib False))) @@ " ^
1226 " (Try (Repeat (Rewrite left_diff_distrib False))) @@ " ^
1227 " (Try (Repeat (Rewrite right_diff_distrib False))) @@ " ^
1229 " (Try (Repeat (Rewrite mult_1_left False))) @@ " ^
1230 " (Try (Repeat (Rewrite mult_zero_left False))) @@ " ^
1231 " (Try (Repeat (Rewrite add_0_left False))) @@ " ^
1233 " (Try (Repeat (Rewrite real_mult_commute False))) @@ " ^
1234 " (Try (Repeat (Rewrite real_mult_left_commute False))) @@ " ^
1235 " (Try (Repeat (Rewrite real_mult_assoc False))) @@ " ^
1236 " (Try (Repeat (Rewrite add_commute False))) @@ " ^
1237 " (Try (Repeat (Rewrite add_left_commute False))) @@ " ^
1238 " (Try (Repeat (Rewrite add_assoc False))) @@ " ^
1240 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
1241 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
1242 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
1243 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
1245 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
1246 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
1248 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
1249 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
1251 " (Try (Repeat (Calculate PLUS ))) @@ " ^
1252 " (Try (Repeat (Calculate TIMES ))) @@ " ^
1253 " (Try (Repeat (Calculate POWER)))) " ^
1255 -----------------------------------------------------*)
1258 Rls{id = "make_polytest", preconds = []:term list,
1259 rew_ord = ("ord_make_polytest", ord_make_polytest false (theory "Poly")),
1260 erls = testerls, srls = Erls,
1261 calc = [("PLUS" , ("op +", eval_binop "#add_")),
1262 ("TIMES" , ("op *", eval_binop "#mult_")),
1263 ("POWER", ("Atools.pow", eval_binop "#power_"))
1266 rules = [Thm ("real_diff_minus",num_str @{thm real_diff_minus}),
1267 (*"a - b = a + (-1) * b"*)
1268 Thm ("left_distrib" ,num_str @{thm left_distrib}),
1269 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1270 Thm ("right_distrib",num_str @{thm right_distrib}),
1271 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1272 Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}),
1273 (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
1274 Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),
1275 (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
1276 Thm ("mult_1_left",num_str @{thm mult_1_left}),
1278 Thm ("mult_zero_left",num_str @{thm mult_zero_left}),
1280 Thm ("add_0_left",num_str @{thm add_0_left}),
1284 Thm ("real_mult_commute",num_str @{thm real_mult_commute}),
1286 Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}),
1287 (*z1.0 * (z2.0 * z3.0) = z2.0 * (z1.0 * z3.0)*)
1288 Thm ("real_mult_assoc",num_str @{thm real_mult_assoc}),
1289 (*z1.0 * z2.0 * z3.0 = z1.0 * (z2.0 * z3.0)*)
1290 Thm ("add_commute",num_str @{thm add_commute}),
1292 Thm ("add_left_commute",num_str @{thm add_left_commute}),
1293 (*x + (y + z) = y + (x + z)*)
1294 Thm ("add_assoc",num_str @{thm add_assoc}),
1295 (*z1.0 + z2.0 + z3.0 = z1.0 + (z2.0 + z3.0)*)
1297 Thm ("sym_realpow_twoI",
1298 num_str (@{thm realpow_twoI} RS @{thm sym})),
1299 (*"r1 * r1 = r1 ^^^ 2"*)
1300 Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),
1301 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
1302 Thm ("sym_real_mult_2",
1303 num_str (@{thm real_mult_2} RS @{thm sym})),
1304 (*"z1 + z1 = 2 * z1"*)
1305 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),
1306 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1308 Thm ("real_num_collect",num_str @{thm real_num_collect}),
1309 (*"[| l is_const; m is_const |]==>l * n + m * n = (l + m) * n"*)
1310 Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
1311 (*"[| l is_const; m is_const |] ==>
1312 l * n + (m * n + k) = (l + m) * n + k"*)
1313 Thm ("real_one_collect",num_str @{thm real_one_collect}),
1314 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1315 Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}),
1316 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1318 Calc ("op +", eval_binop "#add_"),
1319 Calc ("op *", eval_binop "#mult_"),
1320 Calc ("Atools.pow", eval_binop "#power_")
1322 scr = EmptyScr(*Script ((term_of o the o (parse thy))
1323 scr_make_polytest)*)
1325 (*WN060510 this was done before 'fun prep_rls' ...
1326 val scr_expand_binomtest =
1327 "Script Expand_binomtest t_ =" ^
1329 "((Try (Repeat (Rewrite real_plus_binom_pow2 False))) @@ " ^
1330 " (Try (Repeat (Rewrite real_plus_binom_times False))) @@ " ^
1331 " (Try (Repeat (Rewrite real_minus_binom_pow2 False))) @@ " ^
1332 " (Try (Repeat (Rewrite real_minus_binom_times False))) @@ " ^
1333 " (Try (Repeat (Rewrite real_plus_minus_binom1 False))) @@ " ^
1334 " (Try (Repeat (Rewrite real_plus_minus_binom2 False))) @@ " ^
1336 " (Try (Repeat (Rewrite mult_1_left False))) @@ " ^
1337 " (Try (Repeat (Rewrite mult_zero_left False))) @@ " ^
1338 " (Try (Repeat (Rewrite add_0_left False))) @@ " ^
1340 " (Try (Repeat (Calculate PLUS ))) @@ " ^
1341 " (Try (Repeat (Calculate TIMES ))) @@ " ^
1342 " (Try (Repeat (Calculate POWER))) @@ " ^
1344 " (Try (Repeat (Rewrite sym_realpow_twoI False))) @@ " ^
1345 " (Try (Repeat (Rewrite realpow_plus_1 False))) @@ " ^
1346 " (Try (Repeat (Rewrite sym_real_mult_2 False))) @@ " ^
1347 " (Try (Repeat (Rewrite real_mult_2_assoc False))) @@ " ^
1349 " (Try (Repeat (Rewrite real_num_collect False))) @@ " ^
1350 " (Try (Repeat (Rewrite real_num_collect_assoc False))) @@ " ^
1352 " (Try (Repeat (Rewrite real_one_collect False))) @@ " ^
1353 " (Try (Repeat (Rewrite real_one_collect_assoc False))) @@ " ^
1355 " (Try (Repeat (Calculate PLUS ))) @@ " ^
1356 " (Try (Repeat (Calculate TIMES ))) @@ " ^
1357 " (Try (Repeat (Calculate POWER)))) " ^
1359 ------------------------------------------------------*)
1361 val expand_binomtest =
1362 Rls{id = "expand_binomtest", preconds = [],
1363 rew_ord = ("termlessI",termlessI),
1364 erls = testerls, srls = Erls,
1365 calc = [("PLUS" , ("op +", eval_binop "#add_")),
1366 ("TIMES" , ("op *", eval_binop "#mult_")),
1367 ("POWER", ("Atools.pow", eval_binop "#power_"))
1369 rules = [Thm ("real_plus_binom_pow2" ,num_str @{thm real_plus_binom_pow2}),
1370 (*"(a + b) ^^^ 2 = a ^^^ 2 + 2 * a * b + b ^^^ 2"*)
1371 Thm ("real_plus_binom_times" ,num_str @{thm real_plus_binom_times}),
1372 (*"(a + b)*(a + b) = ...*)
1373 Thm ("real_minus_binom_pow2" ,num_str @{thm real_minus_binom_pow2}),
1374 (*"(a - b) ^^^ 2 = a ^^^ 2 - 2 * a * b + b ^^^ 2"*)
1375 Thm ("real_minus_binom_times",num_str @{thm real_minus_binom_times}),
1376 (*"(a - b)*(a - b) = ...*)
1377 Thm ("real_plus_minus_binom1",num_str @{thm real_plus_minus_binom1}),
1378 (*"(a + b) * (a - b) = a ^^^ 2 - b ^^^ 2"*)
1379 Thm ("real_plus_minus_binom2",num_str @{thm real_plus_minus_binom2}),
1380 (*"(a - b) * (a + b) = a ^^^ 2 - b ^^^ 2"*)
1382 Thm ("real_pp_binom_times",num_str @{thm real_pp_binom_times}),
1383 (*(a + b)*(c + d) = a*c + a*d + b*c + b*d*)
1384 Thm ("real_pm_binom_times",num_str @{thm real_pm_binom_times}),
1385 (*(a + b)*(c - d) = a*c - a*d + b*c - b*d*)
1386 Thm ("real_mp_binom_times",num_str @{thm real_mp_binom_times}),
1387 (*(a - b)*(c p d) = a*c + a*d - b*c - b*d*)
1388 Thm ("real_mm_binom_times",num_str @{thm real_mm_binom_times}),
1389 (*(a - b)*(c p d) = a*c - a*d - b*c + b*d*)
1390 Thm ("realpow_multI",num_str @{thm realpow_multI}),
1391 (*(a*b)^^^n = a^^^n * b^^^n*)
1392 Thm ("real_plus_binom_pow3",num_str @{thm real_plus_binom_pow3}),
1393 (* (a + b)^^^3 = a^^^3 + 3*a^^^2*b + 3*a*b^^^2 + b^^^3 *)
1394 Thm ("real_minus_binom_pow3",num_str @{thm real_minus_binom_pow3}),
1395 (* (a - b)^^^3 = a^^^3 - 3*a^^^2*b + 3*a*b^^^2 - b^^^3 *)
1398 (* Thm ("left_distrib" ,num_str @{thm left_distrib}}),
1399 (*"(z1.0 + z2.0) * w = z1.0 * w + z2.0 * w"*)
1400 Thm ("right_distrib",num_str @{thm right_distrib}),
1401 (*"w * (z1.0 + z2.0) = w * z1.0 + w * z2.0"*)
1402 Thm ("left_diff_distrib" ,num_str @{thm left_diff_distrib}}),
1403 (*"(z1.0 - z2.0) * w = z1.0 * w - z2.0 * w"*)
1404 Thm ("right_diff_distrib",num_str @{thm right_diff_distrib}),
1405 (*"w * (z1.0 - z2.0) = w * z1.0 - w * z2.0"*)
1408 Thm ("mult_1_left",num_str @{thm mult_1_left}}), (*"1 * z = z"*)
1409 Thm ("mult_zero_left",num_str @{thm mult_zero_left}}), (*"0 * z = 0"*)
1410 Thm ("add_0_left",num_str @{thm add_0_left}}),(*"0 + z = z"*)
1412 Calc ("op +", eval_binop "#add_"),
1413 Calc ("op *", eval_binop "#mult_"),
1414 Calc ("Atools.pow", eval_binop "#power_"),
1416 Thm ("real_mult_commute",num_str @{thm real_mult_commute}), (*AC-rewriting*)
1417 Thm ("real_mult_left_commute",num_str @{thm real_mult_left_commute}), (**)
1418 Thm ("real_mult_assoc",num_str @{thm real_mult_assoc}), (**)
1419 Thm ("add_commute",num_str @{thm add_commute}), (**)
1420 Thm ("add_left_commute",num_str @{thm add_left_commute}), (**)
1421 Thm ("add_assoc",num_str @{thm add_assoc}), (**)
1424 Thm ("sym_realpow_twoI",
1425 num_str (@{thm realpow_twoI} RS @{thm sym})),
1426 (*"r1 * r1 = r1 ^^^ 2"*)
1427 Thm ("realpow_plus_1",num_str @{thm realpow_plus_1}),
1428 (*"r * r ^^^ n = r ^^^ (n + 1)"*)
1429 (*Thm ("sym_real_mult_2",
1430 num_str (@{thm real_mult_2} RS @{thm sym})),
1431 (*"z1 + z1 = 2 * z1"*)*)
1432 Thm ("real_mult_2_assoc",num_str @{thm real_mult_2_assoc}),
1433 (*"z1 + (z1 + k) = 2 * z1 + k"*)
1435 Thm ("real_num_collect",num_str @{thm real_num_collect}),
1436 (*"[| l is_const; m is_const |] ==> l * n + m * n = (l + m) * n"*)
1437 Thm ("real_num_collect_assoc",num_str @{thm real_num_collect_assoc}),
1438 (*"[| l is_const; m is_const |] ==> l * n + (m * n + k) = (l + m) * n + k"*)
1439 Thm ("real_one_collect",num_str @{thm real_one_collect}),
1440 (*"m is_const ==> n + m * n = (1 + m) * n"*)
1441 Thm ("real_one_collect_assoc",num_str @{thm real_one_collect_assoc}),
1442 (*"m is_const ==> k + (n + m * n) = k + (1 + m) * n"*)
1444 Calc ("op +", eval_binop "#add_"),
1445 Calc ("op *", eval_binop "#mult_"),
1446 Calc ("Atools.pow", eval_binop "#power_")
1449 (*Script ((term_of o the o (parse thy)) scr_expand_binomtest)*)
1453 ruleset' := overwritelthy @{theory} (!ruleset',
1454 [("make_polytest", prep_rls make_polytest),
1455 ("expand_binomtest", prep_rls expand_binomtest)