updated Knowledge/Equation.thy, plus changes ahead.
find . -type f -exec sed -i s/' e_\"'/' e_e\"'/g {} \;
find . -type f -exec sed -i s/' e_ '/' e_e '/g {} \;
find . -type f -exec sed -i s/' e_)'/' e_e)'/g {} \;
find . -type f -exec sed -i s/' e_,'/' e_e,'/g {} \;
find . -type f -exec sed -i s/' e_:'/' e_e:'/g {} \;
find . -type f -exec sed -i s/'(e_:'/'(e_e:'/g {} \;
find . -type f -exec sed -i s/' v_\"'/' v_v\"'/g {} \;
find . -type f -exec sed -i s/' v_ '/' v_v '/g {} \;
find . -type f -exec sed -i s/' v_)'/' v_v)'/g {} \;
find . -type f -exec sed -i s/' v_,'/' v_v,'/g {} \;
find . -type f -exec sed -i s/' v_:'/' v_v:'/g {} \;
find . -type f -exec sed -i s/' v_i\"'/' v_i\"'/g {} \;
1 (*.(c) by Richard Lang, 2003 .*)
2 (* theory collecting all knowledge for RationalEquations
10 theory RatEq imports Rational begin
14 is'_ratequation'_in :: "[bool, real] => bool" ("_ is'_ratequation'_in _")
16 (*----------------------scripts-----------------------*)
19 bool list] => bool list"
20 ("((Script Solve'_rat'_equation (_ _ =))//
24 (* FIXME also in Poly.thy def. --> FIXED*)
26 "a - b = a + (-1) * b"*)
30 "(a/b)*(c/d) = (a*c)/(b*d)"
34 "(a/b)^^^2 = a^^^2/b^^^2"
37 "[|Not(c=0); Not(d=0)|] ==> (a / (c/d) = (a*d) / c)"
39 "[|Not(b=0);Not(c=0); Not(d=0)|] ==> ((a/b) / (c/d) = (a*d) / (b*c))"
41 "[|Not(b=0);Not(c=0)|] ==> ((a/b) / c = a / (b*c))"
43 (* equation to same denominator *)
44 rat_mult_denominator_both
45 "[|Not(b=0); Not(d=0)|] ==> ((a::real) / b = c / d) = (a*d = c*b)"
46 rat_mult_denominator_left
47 "[|Not(d=0)|] ==> ((a::real) = c / d) = (a*d = c)"
48 rat_mult_denominator_right
49 "[|Not(b=0)|] ==> ((a::real) / b = c) = (a = c*b)"
54 (*-------------------------functions-----------------------*)
55 (* is_rateqation_in becomes true, if a bdv is in the denominator of a fraction*)
56 fun is_rateqation_in t v =
58 fun coeff_in c v = member op = (vars c) v;
59 fun finddivide (_ $ _ $ _ $ _) v = raise error("is_rateqation_in:")
60 (* at the moment there is no term like this, but ....*)
61 | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v = coeff_in b v
62 | finddivide (_ $ t1 $ t2) v = (finddivide t1 v)
63 orelse (finddivide t2 v)
64 | finddivide (_ $ t1) v = (finddivide t1 v)
65 | finddivide _ _ = false;
70 fun eval_is_ratequation_in _ _
71 (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _ =
72 if is_rateqation_in t v then
73 SOME ((term2str p) ^ " = True",
74 Trueprop $ (mk_equality (p, HOLogic.true_const)))
75 else SOME ((term2str p) ^ " = True",
76 Trueprop $ (mk_equality (p, HOLogic.false_const)))
77 | eval_is_ratequation_in _ _ _ _ = ((*writeln"### nichts matcht";*) NONE);
79 (*-------------------------rulse-----------------------*)
80 val RatEq_prls = (*15.10.02:just the following order due to subterm evaluation*)
81 append_rls "RatEq_prls" e_rls
82 [Calc ("Atools.ident",eval_ident "#ident_"),
83 Calc ("Tools.matches",eval_matches ""),
84 Calc ("Tools.lhs" ,eval_lhs ""),
85 Calc ("Tools.rhs" ,eval_rhs ""),
86 Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
87 Calc ("op =",eval_equal "#equal_"),
88 Thm ("not_true",num_str @{thm not_true}),
89 Thm ("not_false",num_str @{thm not_false}),
90 Thm ("and_true",num_str @{thm and_true}),
91 Thm ("and_false",num_str @{thm and_false}),
92 Thm ("or_true",num_str @{thm or_true}),
93 Thm ("or_false",num_str @{thm or_false})
97 (*rls = merge_rls erls Poly_erls *)
99 remove_rls "rateq_erls" (*WN: ein Hack*)
100 (merge_rls "is_ratequation_in" calculate_Rational
101 (append_rls "is_ratequation_in"
103 [(*Calc ("HOL.divide", eval_cancel "#divide_e"),*)
104 Calc ("RatEq.is'_ratequation'_in",
105 eval_is_ratequation_in "")
108 [Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
109 Thm ("or_commute",num_str @{thm or_commute}) (*WN: ein Hack*)
111 ruleset' := overwritelthy @{theory} (!ruleset',
112 [("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
117 remove_rls "RatEq_crls" (*WN: ein Hack*)
118 (merge_rls "is_ratequation_in" calculate_Rational
119 (append_rls "is_ratequation_in"
121 [(*Calc ("HOL.divide", eval_cancel "#divide_e"),*)
122 Calc ("RatEq.is'_ratequation'_in",
123 eval_is_ratequation_in "")
125 [Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
126 Thm ("or_commute",num_str @{thm or_commute}) (*WN: ein Hack*)
129 val RatEq_eliminate = prep_rls(
130 Rls {id = "RatEq_eliminate", preconds = [],
131 rew_ord = ("termlessI", termlessI), erls = rateq_erls, srls = Erls,
134 Thm("rat_mult_denominator_both",num_str @{thm rat_mult_denominator_both}),
135 (* a/b=c/d -> ad=cb *)
136 Thm("rat_mult_denominator_left",num_str @{thm rat_mult_denominator_left}),
138 Thm("rat_mult_denominator_right",num_str @{thm rat_mult_denominator_right})
141 scr = Script ((term_of o the o (parse thy)) "empty_script")
143 ruleset' := overwritelthy @{theory} (!ruleset',
144 [("RatEq_eliminate",RatEq_eliminate)
147 val RatEq_simplify = prep_rls(
148 Rls {id = "RatEq_simplify", preconds = [], rew_ord = ("termlessI", termlessI),
149 erls = rateq_erls, srls = Erls, calc = [],
151 Thm("real_rat_mult_1",num_str @{thm real_rat_mult_1}),
152 (*a*(b/c) = (a*b)/c*)
153 Thm("real_rat_mult_2",num_str @{thm real_rat_mult_2}),
154 (*(a/b)*(c/d) = (a*c)/(b*d)*)
155 Thm("real_rat_mult_3",num_str @{thm real_rat_mult_3}),
156 (* (a/b)*c = (a*c)/b*)
157 Thm("real_rat_pow",num_str @{thm real_rat_pow}),
158 (*(a/b)^^^2 = a^^^2/b^^^2*)
159 Thm("real_diff_minus",num_str @{thm real_diff_minus}),
160 (* a - b = a + (-1) * b *)
161 Thm("rat_double_rat_1",num_str @{thm rat_double_rat_1}),
162 (* (a / (c/d) = (a*d) / c) *)
163 Thm("rat_double_rat_2",num_str @{thm rat_double_rat_2}),
164 (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
165 Thm("rat_double_rat_3",num_str @{thm rat_double_rat_3})
166 (* ((a/b) / c = a / (b*c) ) *)
168 scr = Script ((term_of o the o (parse thy)) "empty_script")
170 ruleset' := overwritelthy @{theory} (!ruleset',
171 [("RatEq_simplify",RatEq_simplify)
174 (*-------------------------Problem-----------------------*)
176 (get_pbt ["rational","univariate","equation"]);
180 (prep_pbt thy "pbl_equ_univ_rat" [] e_pblID
181 (["rational","univariate","equation"],
182 [("#Given" ,["equality e_e","solveFor v_v"]),
183 ("#Where" ,["(e_e::bool) is_ratequation_in (v_::real)"]),
184 ("#Find" ,["solutions v_i"])
187 RatEq_prls, SOME "solve (e_e::bool, v_v)",
188 [["RatEq","solve_rat_equation"]]));
191 (*-------------------------methods-----------------------*)
193 (prep_met thy "met_rateq" [] e_metID
196 {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
197 crls=RatEq_crls, nrls=norm_Rational
198 (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
200 (prep_met thy "met_rat_eq" [] e_metID
201 (["RatEq","solve_rat_equation"],
202 [("#Given" ,["equality e_e","solveFor v_v"]),
203 ("#Where" ,["(e_e::bool) is_ratequation_in (v_::real)"]),
204 ("#Find" ,["solutions v_i"])
206 {rew_ord'="termlessI",
211 crls=RatEq_crls, nrls=norm_Rational},
212 "Script Solve_rat_equation (e_e::bool) (v_::real) = " ^
213 "(let e_e = ((Repeat(Try (Rewrite_Set RatEq_simplify True))) @@ " ^
214 " (Repeat(Try (Rewrite_Set norm_Rational False))) @@ " ^
215 " (Repeat(Try (Rewrite_Set common_nominator_p False))) @@ " ^
216 " (Repeat(Try (Rewrite_Set RatEq_eliminate True)))) e_;" ^
217 " (L_::bool list) = (SubProblem (RatEq_,[univariate,equation], " ^
218 " [no_met]) [bool_ e_e, real_ v_]) " ^
219 " in Check_elementwise L_ {(v_::real). Assumptions})"
222 calclist':= overwritel (!calclist',
223 [("is_ratequation_in", ("RatEq.is_ratequation_in",
224 eval_is_ratequation_in ""))