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 = 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),
60 Thm ("and_commute",num_str and_commute),
61 Thm ("or_commute",num_str or_commute)
64 (*rls = merge_rls erls poly_erls *)
65 remove_rls "no_commute" (*ein Hack*)
66 remove_rls "rateq_erls" (*WN: ein Hack*)
67 (merge_rls "is_ratequation_in" calculate_Rational
68 (append_rls "is_ratequation_in"
70 [(*Calc ("HOL.divide", eval_cancel "#divide_"),*)
71 Calc ("RatEq.is'_ratequation'_in",
72 eval_is_ratequation_in "")
73 [Thm ("and_commute",num_str and_commute), (*ein Hack*)
74 Thm ("or_commute",num_str or_commute) (*ein Hack*)
75 Thm ("or_commute",num_str or_commute) (*WN: ein Hack*)
77 ruleset' := overwritel (!ruleset',
78 [("rateq_erls",rateq_erls)(*FIXXXME:del with rls.rls'*)
82 erls = rateq_erls, srls = Erls, calc = [], asm_thm = [],
83 ("rat_mult_denominator_right","")],
85 Thm("rat_mult_denominator_both",num_str rat_mult_denominator_both),
86 (* a/b=c/d -> ad=cb *)
87 Thm("rat_mult_denominator_left",num_str rat_mult_denominator_left),
89 Thm("rat_mult_denominator_right",num_str rat_mult_denominator_right)
92 scr = Script ((term_of o the o (parse thy)) "empty_script")
94 ruleset' := overwritel (!ruleset',
95 [("rat_eliminate",rat_eliminate)
101 erls = rateq_erls, srls = Erls, calc = [], asm_thm = [],
102 ("rat_double_rat_3","")],
104 Thm("real_rat_mult_1",num_str real_rat_mult_1),
105 (*a*(b/c) = (a*b)/c*)
106 Thm("real_rat_mult_2",num_str real_rat_mult_2),
107 (*(a/b)*(c/d) = (a*c)/(b*d)*)
108 Thm("real_rat_mult_3",num_str real_rat_mult_3),
109 (* (a/b)*c = (a*c)/b*)
110 Thm("real_rat_pow",num_str real_rat_pow),
111 (*(a/b)^^^2 = a^^^2/b^^^2*)
112 Thm("real_diff_minus",num_str real_diff_minus),
113 (* a - b = a + (-1) * b *)
114 Thm("rat_double_rat_1",num_str rat_double_rat_1),
115 (* (a / (c/d) = (a*d) / c) *)
116 Thm("rat_double_rat_2",num_str rat_double_rat_2),
117 (* ((a/b) / (c/d) = (a*d) / (b*c)) *)
118 Thm("rat_double_rat_3",num_str rat_double_rat_3)
119 (* ((a/b) / c = a / (b*c) ) *)
121 scr = Script ((term_of o the o (parse thy)) "empty_script")
123 ruleset' := overwritel (!ruleset',
124 [("rat_simplify",rat_simplify)
127 (*-------------------------Problem-----------------------*)
129 (get_pbt ["rational","univariate","equation"]);
134 (["rational","univariate","equation"],
135 [("#Given" ,["equality e_","solveFor v_"]),
136 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
137 ("#Find" ,["solutions v_i_"])
139 [("RatEq.thy","solve_rat_equation")]));
140 [["RatEq","solve_rat_equation"]]));
142 methods:= overwritel (!methods,
145 (("RatEq.thy","solve_rat_equation"),
146 (["RatEq","solve_rat_equation"],
147 [("#Given" ,["equality e_","solveFor v_"]),
148 ("#Where" ,["(e_::bool) is_ratequation_in (v_::real)"]),
149 ("#Find" ,["solutions v_i_"])
151 {rew_ord'="termlessI",
155 asm_rls=["rat_simplify","rat_eliminate"],
157 asm_thm=[("rat_double_rat_1",""),("rat_double_rat_2",""),("rat_double_rat_3",""),
158 ("rat_mult_denominator_both",""),("rat_mult_denominator_left",""),
159 ("rat_mult_denominator_right","")]},
160 "Script Solve_rat_equation (e_::bool) (v_::real) = \
161 \(let e_ = ((Repeat(Try (Rewrite_Set rat_simplify True))) @@ \
162 \ (Repeat(Try (Rewrite_Set make_polynomial False))) @@ \
163 \ (Repeat(Try (Rewrite_Set common_nominator_p False))) @@ \
164 \ (Repeat(Try (Rewrite_Set rat_eliminate True)))) e_;\
165 \ (RatEq_,no_met)) [bool_ e_, real_ v_]) \
166 \ [no_met]) [bool_ e_, real_ v_]) \
170 "******* RatEq.ML end *******";