neuper@37906
|
1 |
(* collecting all knowledge for Root and Rational Equations
|
neuper@37906
|
2 |
created by: rlang
|
neuper@37906
|
3 |
date: 02.10
|
neuper@37906
|
4 |
changed by: rlang
|
neuper@37906
|
5 |
last change by: rlang
|
neuper@37906
|
6 |
date: 02.11.04
|
neuper@37954
|
7 |
(c) by Richard Lang, 2003
|
neuper@37906
|
8 |
*)
|
neuper@37906
|
9 |
|
neuper@38010
|
10 |
theory RootRatEq imports LinEq RootEq RatEq RootRat begin
|
neuper@37906
|
11 |
|
wneuper@59472
|
12 |
text \<open>univariate equations over rational terms containing real square roots:
|
neuper@42398
|
13 |
In 2003 this type has been developed as part of ISAC's equation solver
|
neuper@42398
|
14 |
by Richard Lang in 2003.
|
neuper@42398
|
15 |
The migration Isabelle2002 --> 2011 dropped this type of equation, see RootEq.thy.
|
wneuper@59472
|
16 |
\<close>
|
neuper@42398
|
17 |
|
wneuper@59526
|
18 |
subsection \<open>consts definition for predicates\<close>
|
neuper@37906
|
19 |
consts
|
walther@60278
|
20 |
is_rootRatAddTerm_in :: "[real, real] => bool" ("_ is'_rootRatAddTerm'_in _") (*RL*)
|
wneuper@59526
|
21 |
|
wneuper@59526
|
22 |
subsection \<open>theorems not yet adopted from Isabelle\<close>
|
neuper@52148
|
23 |
axiomatization where
|
neuper@37906
|
24 |
(* eliminate ratRootTerm *)
|
neuper@37983
|
25 |
rootrat_equation_left_1:
|
neuper@52148
|
26 |
"[|c is_rootTerm_in bdv|] ==> ( (a + b/c = d) = ( b = (d - a) * c ))" and
|
neuper@37983
|
27 |
rootrat_equation_left_2:
|
neuper@52148
|
28 |
"[|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c ))" and
|
neuper@37983
|
29 |
rootrat_equation_right_2:
|
neuper@52148
|
30 |
"[|f is_rootTerm_in bdv|] ==> ( (a = d + e/f) = ( (a - d) * f = e ))" and
|
neuper@37983
|
31 |
rootrat_equation_right_1:
|
neuper@37906
|
32 |
"[|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))"
|
neuper@37906
|
33 |
|
wneuper@59526
|
34 |
subsection \<open>predicates\<close>
|
wneuper@59472
|
35 |
ML \<open>
|
wneuper@59526
|
36 |
(* true if denominator contains (sq)root in + or - term
|
neuper@37954
|
37 |
1/(sqrt(x+3)*(x+4)) -> false; 1/(sqrt(x)+2) -> true
|
neuper@37954
|
38 |
if false then (term)^2 contains no (sq)root *)
|
neuper@37954
|
39 |
fun is_rootRatAddTerm_in t v =
|
wneuper@59526
|
40 |
let
|
wenzelm@60309
|
41 |
fun rootadd (Const (\<^const_name>\<open>plus\<close>, _) $ t2 $ t3) v =
|
wneuper@59526
|
42 |
is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
|
wenzelm@60309
|
43 |
| rootadd (Const (\<^const_name>\<open>minus\<close>,_) $ t2 $ t3) v =
|
wneuper@59526
|
44 |
is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
|
wneuper@59526
|
45 |
| rootadd _ _ = false;
|
wneuper@59526
|
46 |
fun findrootrat (t as (_ $ _ $ _ $ _)) _ = raise TERM ("is_rootRatAddTerm_in", [t])
|
wneuper@59526
|
47 |
(* at the moment there is no term like this, but ....*)
|
wenzelm@60309
|
48 |
| findrootrat (Const (\<^const_name>\<open>divide\<close>,_) $ _ $ t3) v =
|
wneuper@59526
|
49 |
if (is_rootTerm_in t3 v) then rootadd t3 v else false
|
wneuper@59526
|
50 |
| findrootrat (_ $ t1 $ t2) v =
|
wneuper@59526
|
51 |
findrootrat t1 v orelse findrootrat t2 v
|
wneuper@59526
|
52 |
| findrootrat (_ $ t1) v = findrootrat t1 v
|
wneuper@59526
|
53 |
| findrootrat _ _ = false;
|
wneuper@59526
|
54 |
in
|
wneuper@59526
|
55 |
findrootrat t v
|
wneuper@59526
|
56 |
end;
|
neuper@37906
|
57 |
|
walther@60335
|
58 |
fun eval_is_rootRatAddTerm_in _ _ (p as (Const (\<^const_name>\<open>is_rootRatAddTerm_in\<close>,_) $ t $ v)) _ =
|
wneuper@59526
|
59 |
if is_rootRatAddTerm_in t v
|
walther@59868
|
60 |
then SOME ((UnparseC.term p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
|
walther@59868
|
61 |
else SOME ((UnparseC.term p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
|
neuper@38015
|
62 |
| eval_is_rootRatAddTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
|
wneuper@59472
|
63 |
\<close>
|
wenzelm@60313
|
64 |
calculation is_rootRatAddTerm_in = \<open>eval_is_rootRatAddTerm_in ""\<close>
|
wneuper@59526
|
65 |
|
wneuper@59526
|
66 |
subsection \<open>rule-sets\<close>
|
wneuper@59472
|
67 |
ML \<open>
|
neuper@37954
|
68 |
val RootRatEq_prls =
|
walther@59852
|
69 |
Rule_Set.append_rules "RootRatEq_prls" Rule_Set.empty
|
wenzelm@60294
|
70 |
[\<^rule_eval>\<open>Prog_Expr.ident\<close> (Prog_Expr.eval_ident "#ident_"),
|
wenzelm@60294
|
71 |
\<^rule_eval>\<open>Prog_Expr.matches\<close> (Prog_Expr.eval_matches ""),
|
wenzelm@60294
|
72 |
\<^rule_eval>\<open>Prog_Expr.lhs\<close> (Prog_Expr.eval_lhs ""),
|
wenzelm@60294
|
73 |
\<^rule_eval>\<open>Prog_Expr.rhs\<close> (Prog_Expr.eval_rhs ""),
|
wenzelm@60294
|
74 |
\<^rule_eval>\<open>is_rootTerm_in\<close> (eval_is_rootTerm_in ""),
|
wenzelm@60294
|
75 |
\<^rule_eval>\<open>is_rootRatAddTerm_in\<close> (eval_is_rootRatAddTerm_in ""),
|
wenzelm@60294
|
76 |
\<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
|
wenzelm@60297
|
77 |
\<^rule_thm>\<open>not_true\<close>,
|
wenzelm@60297
|
78 |
\<^rule_thm>\<open>not_false\<close>,
|
wenzelm@60297
|
79 |
\<^rule_thm>\<open>and_true\<close>,
|
wenzelm@60297
|
80 |
\<^rule_thm>\<open>and_false\<close>,
|
wenzelm@60297
|
81 |
\<^rule_thm>\<open>or_true\<close>,
|
wenzelm@60297
|
82 |
\<^rule_thm>\<open>or_false\<close>];
|
neuper@37954
|
83 |
|
neuper@37954
|
84 |
val RooRatEq_erls =
|
walther@59852
|
85 |
Rule_Set.merge "RooRatEq_erls" rootrat_erls
|
walther@59852
|
86 |
(Rule_Set.merge "" RootEq_erls
|
walther@59852
|
87 |
(Rule_Set.merge "" rateq_erls
|
walther@59852
|
88 |
(Rule_Set.append_rules "" Rule_Set.empty
|
neuper@37954
|
89 |
[])));
|
neuper@37954
|
90 |
|
neuper@37954
|
91 |
val RootRatEq_crls =
|
walther@59852
|
92 |
Rule_Set.merge "RootRatEq_crls" rootrat_erls
|
walther@59852
|
93 |
(Rule_Set.merge "" RootEq_erls
|
walther@59852
|
94 |
(Rule_Set.merge "" rateq_erls
|
walther@59852
|
95 |
(Rule_Set.append_rules "" Rule_Set.empty
|
neuper@37954
|
96 |
[])));
|
wneuper@59526
|
97 |
\<close> ML \<open>
|
wneuper@59526
|
98 |
(* Solves a rootrat Equation *)
|
wneuper@59526
|
99 |
val rootrat_solve = prep_rls'(
|
walther@59851
|
100 |
Rule_Def.Repeat {id = "rootrat_solve", preconds = [],
|
wneuper@59526
|
101 |
rew_ord = ("termlessI",termlessI),
|
walther@59852
|
102 |
erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
|
wneuper@59526
|
103 |
rules =
|
wenzelm@60297
|
104 |
[\<^rule_thm>\<open>rootrat_equation_left_1\<close>,
|
wneuper@59526
|
105 |
(* [|c is_rootTerm_in bdv|] ==>
|
wneuper@59526
|
106 |
( (a + b/c = d) = ( b = (d - a) * c )) *)
|
wenzelm@60297
|
107 |
\<^rule_thm>\<open>rootrat_equation_left_2\<close>,
|
wneuper@59526
|
108 |
(* [|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c )) *)
|
wenzelm@60297
|
109 |
\<^rule_thm>\<open>rootrat_equation_right_1\<close>,
|
wneuper@59526
|
110 |
(* [|f is_rootTerm_in bdv|] ==>
|
wneuper@59526
|
111 |
( (a = d + e/f) = ( (a - d) * f = e )) *)
|
wenzelm@60297
|
112 |
\<^rule_thm>\<open>rootrat_equation_right_2\<close>
|
wneuper@59526
|
113 |
(* [|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))*)
|
walther@59878
|
114 |
], scr = Rule.Empty_Prog});
|
wneuper@59472
|
115 |
\<close>
|
wenzelm@60289
|
116 |
rule_set_knowledge
|
wenzelm@60286
|
117 |
RooRatEq_erls = RooRatEq_erls and
|
wenzelm@60286
|
118 |
rootrat_solve = rootrat_solve
|
wneuper@59526
|
119 |
|
wneuper@59526
|
120 |
subsection \<open>problems\<close>
|
walther@60258
|
121 |
|
wenzelm@60306
|
122 |
problem pbl_equ_univ_root_sq_rat : "rat/sq/rootX/univariate/equation" =
|
wenzelm@60306
|
123 |
\<open>RootRatEq_prls\<close>
|
wenzelm@60306
|
124 |
Method: "RootRatEq/elim_rootrat_equation"
|
wenzelm@60306
|
125 |
CAS: "solve (e_e::bool, v_v)"
|
wenzelm@60306
|
126 |
Given: "equality e_e" "solveFor v_v"
|
wenzelm@60306
|
127 |
Where: "( (lhs e_e) is_rootRatAddTerm_in (v_v::real) ) |
|
wenzelm@60306
|
128 |
( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"
|
wenzelm@60306
|
129 |
Find: "solutions v_v'i'"
|
s1210629013@55380
|
130 |
|
wneuper@59526
|
131 |
subsection \<open>methods\<close>
|
wenzelm@60303
|
132 |
|
wneuper@59472
|
133 |
setup \<open>KEStore_Elems.add_mets
|
walther@60154
|
134 |
[MethodC.prep_input @{theory LinEq} "met_rootrateq" [] MethodC.id_empty
|
s1210629013@55373
|
135 |
(["RootRatEq"], [],
|
walther@59852
|
136 |
{rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
|
wneuper@59545
|
137 |
crls=Atools_erls, errpats = [], nrls = norm_Rational}, @{thm refl})]
|
wneuper@59473
|
138 |
\<close>
|
s1210629013@55373
|
139 |
(*-- left 20.10.02 --*)
|
wneuper@59504
|
140 |
partial_function (tailrec) solve_rootrat_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
|
wneuper@59504
|
141 |
where
|
wneuper@59504
|
142 |
"solve_rootrat_equ e_e v_v =
|
walther@59635
|
143 |
(let
|
walther@59635
|
144 |
e_e = (
|
walther@59637
|
145 |
(Try (Rewrite_Set ''expand_rootbinoms'')) #>
|
walther@59637
|
146 |
(Try (Rewrite_Set ''rooteq_simplify'')) #>
|
walther@59637
|
147 |
(Try (Rewrite_Set ''make_rooteq'')) #>
|
walther@59637
|
148 |
(Try (Rewrite_Set ''rooteq_simplify'')) #>
|
walther@59635
|
149 |
(Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''rootrat_solve'')) ) e_e
|
walther@59635
|
150 |
in SubProblem (''RootEq'', [''univariate'', ''equation''], [''no_met'']) [BOOL e_e, REAL v_v])"
|
wenzelm@60303
|
151 |
|
wenzelm@60303
|
152 |
method met_rootrateq_elim : "RootRatEq/elim_rootrat_equation" =
|
wenzelm@60303
|
153 |
\<open>{rew_ord'="termlessI", rls'=RooRatEq_erls, srls=Rule_Set.empty, prls=RootRatEq_prls, calc=[],
|
wenzelm@60303
|
154 |
crls=RootRatEq_crls, errpats = [], nrls = norm_Rational}\<close>
|
wenzelm@60303
|
155 |
Program: solve_rootrat_equ.simps
|
wenzelm@60303
|
156 |
Given: "equality e_e" "solveFor v_v"
|
wenzelm@60303
|
157 |
Where: "( (lhs e_e) is_rootRatAddTerm_in (v_v::real) ) |
|
wenzelm@60303
|
158 |
( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"
|
wenzelm@60303
|
159 |
Find: "solutions v_v'i'"
|
wenzelm@60303
|
160 |
|
wenzelm@60303
|
161 |
ML \<open>
|
walther@60278
|
162 |
\<close> ML \<open>
|
wneuper@59472
|
163 |
\<close>
|
neuper@37906
|
164 |
end
|