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"*)
27 real_rat_mult_1: "a*(b/c) = (a*b)/c"
28 real_rat_mult_2: "(a/b)*(c/d) = (a*c)/(b*d)"
29 real_rat_mult_3: "(a/b)*c = (a*c)/b"
30 real_rat_pow: "(a/b)^^^2 = a^^^2/b^^^2"
32 rat_double_rat_1: "[|Not(c=0); Not(d=0)|] ==> (a / (c/d) = (a*d) / c)"
33 rat_double_rat_2: "[|Not(b=0);Not(c=0); Not(d=0)|] ==>
34 ((a/b) / (c/d) = (a*d) / (b*c))"
35 rat_double_rat_3: "[|Not(b=0);Not(c=0)|] ==> ((a/b) / c = a / (b*c))"
37 (* equation to same denominator *)
38 rat_mult_denominator_both:
39 "[|Not(b=0); Not(d=0)|] ==> ((a::real) / b = c / d) = (a*d = c*b)"
40 rat_mult_denominator_left:
41 "[|Not(d=0)|] ==> ((a::real) = c / d) = (a*d = c)"
42 rat_mult_denominator_right:
43 "[|Not(b=0)|] ==> ((a::real) / b = c) = (a = c*b)"
48 (*-------------------------functions-----------------------*)
49 (* is_rateqation_in becomes true, if a bdv is in the denominator of a fraction*)
50 fun is_rateqation_in t v =
52 fun coeff_in c v = member op = (vars c) v;
53 fun finddivide (_ $ _ $ _ $ _) v = error("is_rateqation_in:")
54 (* at the moment there is no term like this, but ....*)
55 | finddivide (t as (Const ("Rings.inverse_class.divide",_) $ _ $ b)) v = coeff_in b v
56 | finddivide (_ $ t1 $ t2) v = (finddivide t1 v)
57 orelse (finddivide t2 v)
58 | finddivide (_ $ t1) v = (finddivide t1 v)
59 | finddivide _ _ = false;
64 fun eval_is_ratequation_in _ _
65 (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _ =
66 if is_rateqation_in t v then
67 SOME ((term2str p) ^ " = True",
68 Trueprop $ (mk_equality (p, HOLogic.true_const)))
69 else SOME ((term2str p) ^ " = True",
70 Trueprop $ (mk_equality (p, HOLogic.false_const)))
71 | eval_is_ratequation_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
73 (*-------------------------rulse-----------------------*)
74 val RatEq_prls = (*15.10.02:just the following order due to subterm evaluation*)
75 append_rls "RatEq_prls" e_rls
76 [Calc ("Atools.ident",eval_ident "#ident_"),
77 Calc ("Tools.matches",eval_matches ""),
78 Calc ("Tools.lhs" ,eval_lhs ""),
79 Calc ("Tools.rhs" ,eval_rhs ""),
80 Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
81 Calc ("op =",eval_equal "#equal_"),
82 Thm ("not_true",num_str @{thm not_true}),
83 Thm ("not_false",num_str @{thm not_false}),
84 Thm ("and_true",num_str @{thm and_true}),
85 Thm ("and_false",num_str @{thm and_false}),
86 Thm ("or_true",num_str @{thm or_true}),
87 Thm ("or_false",num_str @{thm or_false})
91 (*rls = merge_rls erls Poly_erls *)
93 remove_rls "rateq_erls" (*WN: ein Hack*)
94 (merge_rls "is_ratequation_in" calculate_Rational
95 (append_rls "is_ratequation_in"
97 [(*Calc ("Rings.inverse_class.divide", eval_cancel "#divide_e"),*)
98 Calc ("RatEq.is'_ratequation'_in",
99 eval_is_ratequation_in "")
102 [Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
103 Thm ("or_commute",num_str @{thm or_commute}) (*WN: ein Hack*)
105 ruleset' := overwritelthy @{theory} (!ruleset',
106 [("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
111 remove_rls "RatEq_crls" (*WN: ein Hack*)
112 (merge_rls "is_ratequation_in" calculate_Rational
113 (append_rls "is_ratequation_in"
115 [(*Calc ("Rings.inverse_class.divide", eval_cancel "#divide_e"),*)
116 Calc ("RatEq.is'_ratequation'_in",
117 eval_is_ratequation_in "")
119 [Thm ("and_commute",num_str @{thm and_commute}), (*WN: ein Hack*)
120 Thm ("or_commute",num_str @{thm or_commute}) (*WN: ein Hack*)
123 val RatEq_eliminate = prep_rls(
124 Rls {id = "RatEq_eliminate", preconds = [],
125 rew_ord = ("termlessI", termlessI), erls = rateq_erls, srls = Erls,
128 Thm("rat_mult_denominator_both",num_str @{thm rat_mult_denominator_both}),
129 (* a/b=c/d -> ad=cb *)
130 Thm("rat_mult_denominator_left",num_str @{thm rat_mult_denominator_left}),
132 Thm("rat_mult_denominator_right",num_str @{thm rat_mult_denominator_right})
135 scr = Script ((term_of o the o (parse thy)) "empty_script")
137 ruleset' := overwritelthy @{theory} (!ruleset',
138 [("RatEq_eliminate",RatEq_eliminate)
141 val RatEq_simplify = prep_rls(
142 Rls {id = "RatEq_simplify", preconds = [], rew_ord = ("termlessI", termlessI),
143 erls = rateq_erls, srls = Erls, calc = [],
145 Thm("real_rat_mult_1",num_str @{thm real_rat_mult_1}),
146 (*a*(b/c) = (a*b)/c*)
147 Thm("real_rat_mult_2",num_str @{thm real_rat_mult_2}),
148 (*(a/b)*(c/d) = (a*c)/(b*d)*)
149 Thm("real_rat_mult_3",num_str @{thm real_rat_mult_3}),
150 (* (a/b)*c = (a*c)/b*)
151 Thm("real_rat_pow",num_str @{thm real_rat_pow}),
152 (*(a/b)^^^2 = a^^^2/b^^^2*)
153 Thm("real_diff_minus",num_str @{thm real_diff_minus}),
154 (* a - b = a + (-1) * b *)
155 Thm("rat_double_rat_1",num_str @{thm rat_double_rat_1}),
156 (* (a / (c/d) = (a*d) / c) *)
157 Thm("rat_double_rat_2",num_str @{thm rat_double_rat_2}),
158 (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
159 Thm("rat_double_rat_3",num_str @{thm rat_double_rat_3})
160 (* ((a/b) / c = a / (b*c) ) *)
162 scr = Script ((term_of o the o (parse thy)) "empty_script")
164 ruleset' := overwritelthy @{theory} (!ruleset',
165 [("RatEq_simplify",RatEq_simplify)
168 (*-------------------------Problem-----------------------*)
170 (get_pbt ["rational","univariate","equation"]);
174 (prep_pbt thy "pbl_equ_univ_rat" [] e_pblID
175 (["rational","univariate","equation"],
176 [("#Given" ,["equality e_e","solveFor v_v"]),
177 ("#Where" ,["(e_e::bool) is_ratequation_in (v_v::real)"]),
178 ("#Find" ,["solutions v_v'i'"])
181 RatEq_prls, SOME "solve (e_e::bool, v_v)",
182 [["RatEq","solve_rat_equation"]]));
186 (*-------------------------methods-----------------------*)
188 (prep_met thy "met_rateq" [] e_metID
191 {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
192 crls=RatEq_crls, nrls=norm_Rational
193 (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
198 (prep_met thy "met_rat_eq" [] e_metID
199 (["RatEq","solve_rat_equation"],
200 [("#Given" ,["equality e_e","solveFor v_v"]),
201 ("#Where" ,["(e_e::bool) is_ratequation_in (v_v::real)"]),
202 ("#Find" ,["solutions v_v'i'"])
204 {rew_ord'="termlessI",
209 crls=RatEq_crls, nrls=norm_Rational},
210 "Script Solve_rat_equation (e_e::bool) (v_v::real) = " ^
211 "(let e_e = ((Repeat(Try (Rewrite_Set RatEq_simplify True))) @@ " ^
212 " (Repeat(Try (Rewrite_Set norm_Rational False))) @@ " ^
213 " (Repeat(Try (Rewrite_Set common_nominator_p False))) @@ " ^
214 " (Repeat(Try (Rewrite_Set RatEq_eliminate True)))) e_e;" ^
215 " (L_L::bool list) = (SubProblem (RatEq',[univariate,equation], [no_met])" ^
216 " [BOOL e_e, REAL v_v]) " ^
217 " in Check_elementwise L_LL {(v_v::real). Assumptions})"
222 calclist':= overwritel (!calclist',
223 [("is_ratequation_in", ("RatEq.is_ratequation_in",
224 eval_is_ratequation_in ""))