1 (*.(c) by Richard Lang, 2003 .*)
2 (* collecting all knowledge for RationalEquations
10 (* use"IsacKnowledge/RatEq.ML";
18 "******* RatEq.ML begin *******";
20 theory' := overwritel (!theory', [("RatEq.thy",RatEq.thy)]);
22 (*-------------------------functions-----------------------*)
23 (* is_rateqation_in becomes true, if a bdv is in the denominator of a fraction*)
24 fun is_rateqation_in t v =
26 fun coeff_in c v = v mem (vars c);
27 fun finddivide (_ $ _ $ _ $ _) v = raise error("is_rateqation_in:")
28 (* at the moment there is no term like this, but ....*)
29 | finddivide (t as (Const ("HOL.divide",_) $ _ $ b)) v = coeff_in b v
30 | finddivide (_ $ t1 $ t2) v = (finddivide t1 v) orelse (finddivide t2 v)
31 | finddivide (_ $ t1) v = (finddivide t1 v)
32 | finddivide _ _ = false;
37 fun eval_is_ratequation_in _ _ (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _ =
38 if is_rateqation_in t v then
39 Some ((term2str p) ^ " = True",
40 Trueprop $ (mk_equality (p, HOLogic.true_const)))
41 else Some ((term2str p) ^ " = True",
42 Trueprop $ (mk_equality (p, HOLogic.false_const)))
43 | eval_is_ratequation_in _ _ _ _ = ((*writeln"### nichts matcht";*) None);
45 (*-------------------------rulse-----------------------*)
46 val RatEq_prls = (*15.10.02:just the following order due to subterm evaluation*)
47 append_rls "RatEq_prls" e_rls
48 [Calc ("Atools.ident",eval_ident "#ident_"),
49 Calc ("Tools.matches",eval_matches ""),
50 Calc ("Tools.lhs" ,eval_lhs ""),
51 Calc ("Tools.rhs" ,eval_rhs ""),
52 Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
53 Calc ("op =",eval_equal "#equal_"),
54 Thm ("not_true",num_str not_true),
55 Thm ("not_false",num_str not_false),
56 Thm ("and_true",num_str and_true),
57 Thm ("and_false",num_str and_false),
58 Thm ("or_true",num_str or_true),
59 Thm ("or_false",num_str or_false)
63 (*rls = merge_rls erls Poly_erls *)
65 remove_rls "rateq_erls" (*WN: ein Hack*)
66 (merge_rls "is_ratequation_in" calculate_Rational
67 (append_rls "is_ratequation_in"
69 [(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
70 Calc ("RatEq.is'_ratequation'_in",
71 eval_is_ratequation_in "")
74 [Thm ("and_commute",num_str and_commute), (*WN: ein Hack*)
75 Thm ("or_commute",num_str or_commute) (*WN: ein Hack*)
77 ruleset' := overwritelthy thy (!ruleset',
78 [("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
83 remove_rls "RatEq_crls" (*WN: ein Hack*)
84 (merge_rls "is_ratequation_in" calculate_Rational
85 (append_rls "is_ratequation_in"
87 [(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
88 Calc ("RatEq.is'_ratequation'_in",
89 eval_is_ratequation_in "")
91 [Thm ("and_commute",num_str and_commute), (*WN: ein Hack*)
92 Thm ("or_commute",num_str or_commute) (*WN: ein Hack*)
95 val RatEq_eliminate = prep_rls(
96 Rls {id = "RatEq_eliminate", preconds = [], rew_ord = ("termlessI",termlessI),
97 erls = rateq_erls, srls = Erls, calc = [],
98 (*asm_thm = [("rat_mult_denominator_both",""),("rat_mult_denominator_left",""),
99 ("rat_mult_denominator_right","")],*)
101 Thm("rat_mult_denominator_both",num_str rat_mult_denominator_both),
102 (* a/b=c/d -> ad=cb *)
103 Thm("rat_mult_denominator_left",num_str rat_mult_denominator_left),
105 Thm("rat_mult_denominator_right",num_str rat_mult_denominator_right)
108 scr = Script ((term_of o the o (parse thy)) "empty_script")
110 ruleset' := overwritelthy thy (!ruleset',
111 [("RatEq_eliminate",RatEq_eliminate)
117 val RatEq_simplify = prep_rls(
118 Rls {id = "RatEq_simplify", preconds = [], rew_ord = ("termlessI",termlessI),
119 erls = rateq_erls, srls = Erls, calc = [],
120 (*asm_thm = [("rat_double_rat_1",""),("rat_double_rat_2",""),
121 ("rat_double_rat_3","")],*)
123 Thm("real_rat_mult_1",num_str real_rat_mult_1),
124 (*a*(b/c) = (a*b)/c*)
125 Thm("real_rat_mult_2",num_str real_rat_mult_2),
126 (*(a/b)*(c/d) = (a*c)/(b*d)*)
127 Thm("real_rat_mult_3",num_str real_rat_mult_3),
128 (* (a/b)*c = (a*c)/b*)
129 Thm("real_rat_pow",num_str real_rat_pow),
130 (*(a/b)^^^2 = a^^^2/b^^^2*)
131 Thm("real_diff_minus",num_str real_diff_minus),
132 (* a - b = a + (-1) * b *)
133 Thm("rat_double_rat_1",num_str rat_double_rat_1),
134 (* (a / (c/d) = (a*d) / c) *)
135 Thm("rat_double_rat_2",num_str rat_double_rat_2),
136 (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
137 Thm("rat_double_rat_3",num_str rat_double_rat_3)
138 (* ((a/b) / c = a / (b*c) ) *)
140 scr = Script ((term_of o the o (parse thy)) "empty_script")
142 ruleset' := overwritelthy thy (!ruleset',
143 [("RatEq_simplify",RatEq_simplify)
146 (*-------------------------Problem-----------------------*)
148 (get_pbt ["rational","univariate","equation"]);
152 (prep_pbt RatEq.thy "pbl_equ_univ_rat" [] e_pblID
153 (["rational","univariate","equation"],
154 [("#Given" ,["equality e_","solveFor v_"]),
155 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
156 ("#Find" ,["solutions v_i_"])
159 RatEq_prls, Some "solve (e_::bool, v_)",
160 [["RatEq","solve_rat_equation"]]));
163 (*-------------------------methods-----------------------*)
165 (prep_met RatEq.thy "met_rateq" [] e_metID
168 {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
169 crls=RatEq_crls, nrls=norm_Rational
170 (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
172 (prep_met RatEq.thy "met_rat_eq" [] e_metID
173 (["RatEq","solve_rat_equation"],
174 [("#Given" ,["equality e_","solveFor v_"]),
175 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
176 ("#Find" ,["solutions v_i_"])
178 {rew_ord'="termlessI",
183 crls=RatEq_crls, nrls=norm_Rational(*,
185 asm_thm=[("rat_double_rat_1",""),("rat_double_rat_2",""),("rat_double_rat_3",""),
186 ("rat_mult_denominator_both",""),("rat_mult_denominator_left",""),
187 ("rat_mult_denominator_right","")]*)},
188 "Script Solve_rat_equation (e_::bool) (v_::real) = \
189 \(let e_ = ((Repeat(Try (Rewrite_Set RatEq_simplify True))) @@ \
190 \ (Repeat(Try (Rewrite_Set norm_Rational False))) @@ \
191 \ (Repeat(Try (Rewrite_Set common_nominator_p False))) @@ \
192 \ (Repeat(Try (Rewrite_Set RatEq_eliminate True)))) e_;\
193 \ (L_::bool list) = (SubProblem (RatEq_,[univariate,equation], \
194 \ [no_met]) [bool_ e_, real_ v_]) \
195 \ in Check_elementwise L_ {(v_::real). Assumptions})"
198 calclist':= overwritel (!calclist',
199 [("is_ratequation_in", ("RatEq.is_ratequation_in",
200 eval_is_ratequation_in ""))
202 "******* RatEq.ML end *******";