1 (*.(c) by Richard Lang, 2003 .*)
2 (* collecting all knowledge for RationalEquations
10 (* use"Knowledge/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 = member op = (vars c) v;
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)
31 orelse (finddivide t2 v)
32 | finddivide (_ $ t1) v = (finddivide t1 v)
33 | finddivide _ _ = false;
38 fun eval_is_ratequation_in _ _
39 (p as (Const ("RatEq.is'_ratequation'_in",_) $ t $ v)) _ =
40 if is_rateqation_in t v then
41 SOME ((term2str p) ^ " = True",
42 Trueprop $ (mk_equality (p, HOLogic.true_const)))
43 else SOME ((term2str p) ^ " = True",
44 Trueprop $ (mk_equality (p, HOLogic.false_const)))
45 | eval_is_ratequation_in _ _ _ _ = ((*writeln"### nichts matcht";*) NONE);
47 (*-------------------------rulse-----------------------*)
48 val RatEq_prls = (*15.10.02:just the following order due to subterm evaluation*)
49 append_rls "RatEq_prls" e_rls
50 [Calc ("Atools.ident",eval_ident "#ident_"),
51 Calc ("Tools.matches",eval_matches ""),
52 Calc ("Tools.lhs" ,eval_lhs ""),
53 Calc ("Tools.rhs" ,eval_rhs ""),
54 Calc ("RatEq.is'_ratequation'_in",eval_is_ratequation_in ""),
55 Calc ("op =",eval_equal "#equal_"),
56 Thm ("not_true",num_str not_true),
57 Thm ("not_false",num_str not_false),
58 Thm ("and_true",num_str and_true),
59 Thm ("and_false",num_str and_false),
60 Thm ("or_true",num_str or_true),
61 Thm ("or_false",num_str or_false)
65 (*rls = merge_rls erls Poly_erls *)
67 remove_rls "rateq_erls" (*WN: ein Hack*)
68 (merge_rls "is_ratequation_in" calculate_Rational
69 (append_rls "is_ratequation_in"
71 [(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
72 Calc ("RatEq.is'_ratequation'_in",
73 eval_is_ratequation_in "")
76 [Thm ("and_commute",num_str and_commute), (*WN: ein Hack*)
77 Thm ("or_commute",num_str or_commute) (*WN: ein Hack*)
79 ruleset' := overwritelthy thy (!ruleset',
80 [("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
85 remove_rls "RatEq_crls" (*WN: ein Hack*)
86 (merge_rls "is_ratequation_in" calculate_Rational
87 (append_rls "is_ratequation_in"
89 [(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
90 Calc ("RatEq.is'_ratequation'_in",
91 eval_is_ratequation_in "")
93 [Thm ("and_commute",num_str and_commute), (*WN: ein Hack*)
94 Thm ("or_commute",num_str or_commute) (*WN: ein Hack*)
97 val RatEq_eliminate = prep_rls(
98 Rls {id = "RatEq_eliminate", preconds = [],
99 rew_ord = ("termlessI", termlessI), erls = rateq_erls, srls = Erls,
102 Thm("rat_mult_denominator_both",num_str rat_mult_denominator_both),
103 (* a/b=c/d -> ad=cb *)
104 Thm("rat_mult_denominator_left",num_str rat_mult_denominator_left),
106 Thm("rat_mult_denominator_right",num_str rat_mult_denominator_right)
109 scr = Script ((term_of o the o (parse thy)) "empty_script")
111 ruleset' := overwritelthy thy (!ruleset',
112 [("RatEq_eliminate",RatEq_eliminate)
115 val RatEq_simplify = prep_rls(
116 Rls {id = "RatEq_simplify", preconds = [], rew_ord = ("termlessI", termlessI),
117 erls = rateq_erls, srls = Erls, calc = [],
119 Thm("real_rat_mult_1",num_str real_rat_mult_1),
120 (*a*(b/c) = (a*b)/c*)
121 Thm("real_rat_mult_2",num_str real_rat_mult_2),
122 (*(a/b)*(c/d) = (a*c)/(b*d)*)
123 Thm("real_rat_mult_3",num_str real_rat_mult_3),
124 (* (a/b)*c = (a*c)/b*)
125 Thm("real_rat_pow",num_str real_rat_pow),
126 (*(a/b)^^^2 = a^^^2/b^^^2*)
127 Thm("real_diff_minus",num_str real_diff_minus),
128 (* a - b = a + (-1) * b *)
129 Thm("rat_double_rat_1",num_str rat_double_rat_1),
130 (* (a / (c/d) = (a*d) / c) *)
131 Thm("rat_double_rat_2",num_str rat_double_rat_2),
132 (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
133 Thm("rat_double_rat_3",num_str rat_double_rat_3)
134 (* ((a/b) / c = a / (b*c) ) *)
136 scr = Script ((term_of o the o (parse thy)) "empty_script")
138 ruleset' := overwritelthy thy (!ruleset',
139 [("RatEq_simplify",RatEq_simplify)
142 (*-------------------------Problem-----------------------*)
144 (get_pbt ["rational","univariate","equation"]);
148 (prep_pbt (theory "RatEq") "pbl_equ_univ_rat" [] e_pblID
149 (["rational","univariate","equation"],
150 [("#Given" ,["equality e_","solveFor v_"]),
151 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
152 ("#Find" ,["solutions v_i_"])
155 RatEq_prls, SOME "solve (e_::bool, v_)",
156 [["RatEq","solve_rat_equation"]]));
159 (*-------------------------methods-----------------------*)
161 (prep_met (theory "RatEq") "met_rateq" [] e_metID
164 {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = e_rls, prls=e_rls,
165 crls=RatEq_crls, nrls=norm_Rational
166 (*, asm_rls=[],asm_thm=[]*)}, "empty_script"));
168 (prep_met (theory "RatEq") "met_rat_eq" [] e_metID
169 (["RatEq","solve_rat_equation"],
170 [("#Given" ,["equality e_","solveFor v_"]),
171 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
172 ("#Find" ,["solutions v_i_"])
174 {rew_ord'="termlessI",
179 crls=RatEq_crls, nrls=norm_Rational},
180 "Script Solve_rat_equation (e_::bool) (v_::real) = " ^
181 "(let e_ = ((Repeat(Try (Rewrite_Set RatEq_simplify True))) @@ " ^
182 " (Repeat(Try (Rewrite_Set norm_Rational False))) @@ " ^
183 " (Repeat(Try (Rewrite_Set common_nominator_p False))) @@ " ^
184 " (Repeat(Try (Rewrite_Set RatEq_eliminate True)))) e_;" ^
185 " (L_::bool list) = (SubProblem (RatEq_,[univariate,equation], " ^
186 " [no_met]) [bool_ e_, real_ v_]) " ^
187 " in Check_elementwise L_ {(v_::real). Assumptions})"
190 calclist':= overwritel (!calclist',
191 [("is_ratequation_in", ("RatEq.is_ratequation_in",
192 eval_is_ratequation_in ""))
194 "******* RatEq.ML end *******";