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
|
neuper@37954
|
20 |
is'_rootRatAddTerm'_in :: "[real, real] => bool"
|
wneuper@59526
|
21 |
("_ is'_rootRatAddTerm'_in _") (*RL*)
|
wneuper@59526
|
22 |
|
wneuper@59526
|
23 |
subsection \<open>theorems not yet adopted from Isabelle\<close>
|
neuper@52148
|
24 |
axiomatization where
|
neuper@37906
|
25 |
(* eliminate ratRootTerm *)
|
neuper@37983
|
26 |
rootrat_equation_left_1:
|
neuper@52148
|
27 |
"[|c is_rootTerm_in bdv|] ==> ( (a + b/c = d) = ( b = (d - a) * c ))" and
|
neuper@37983
|
28 |
rootrat_equation_left_2:
|
neuper@52148
|
29 |
"[|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c ))" and
|
neuper@37983
|
30 |
rootrat_equation_right_2:
|
neuper@52148
|
31 |
"[|f is_rootTerm_in bdv|] ==> ( (a = d + e/f) = ( (a - d) * f = e ))" and
|
neuper@37983
|
32 |
rootrat_equation_right_1:
|
neuper@37906
|
33 |
"[|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))"
|
neuper@37906
|
34 |
|
wneuper@59526
|
35 |
subsection \<open>predicates\<close>
|
wneuper@59472
|
36 |
ML \<open>
|
neuper@37972
|
37 |
val thy = @{theory};
|
neuper@37972
|
38 |
|
wneuper@59526
|
39 |
(* true if denominator contains (sq)root in + or - term
|
neuper@37954
|
40 |
1/(sqrt(x+3)*(x+4)) -> false; 1/(sqrt(x)+2) -> true
|
neuper@37954
|
41 |
if false then (term)^2 contains no (sq)root *)
|
neuper@37954
|
42 |
fun is_rootRatAddTerm_in t v =
|
wneuper@59526
|
43 |
let
|
wneuper@59526
|
44 |
fun rootadd (Const ("Groups.plus_class.plus", _) $ t2 $ t3) v =
|
wneuper@59526
|
45 |
is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
|
wneuper@59526
|
46 |
| rootadd (Const ("Groups.minus_class.minus",_) $ t2 $ t3) v =
|
wneuper@59526
|
47 |
is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
|
wneuper@59526
|
48 |
| rootadd _ _ = false;
|
wneuper@59526
|
49 |
fun findrootrat (t as (_ $ _ $ _ $ _)) _ = raise TERM ("is_rootRatAddTerm_in", [t])
|
wneuper@59526
|
50 |
(* at the moment there is no term like this, but ....*)
|
wneuper@59526
|
51 |
| findrootrat (Const ("Rings.divide_class.divide",_) $ _ $ t3) v =
|
wneuper@59526
|
52 |
if (is_rootTerm_in t3 v) then rootadd t3 v else false
|
wneuper@59526
|
53 |
| findrootrat (_ $ t1 $ t2) v =
|
wneuper@59526
|
54 |
findrootrat t1 v orelse findrootrat t2 v
|
wneuper@59526
|
55 |
| findrootrat (_ $ t1) v = findrootrat t1 v
|
wneuper@59526
|
56 |
| findrootrat _ _ = false;
|
wneuper@59526
|
57 |
in
|
wneuper@59526
|
58 |
findrootrat t v
|
wneuper@59526
|
59 |
end;
|
neuper@37906
|
60 |
|
wneuper@59526
|
61 |
fun eval_is_rootRatAddTerm_in _ _ (p as (Const ("RootRatEq.is'_rootRatAddTerm'_in",_) $ t $ v)) _ =
|
wneuper@59526
|
62 |
if is_rootRatAddTerm_in t v
|
walther@59868
|
63 |
then SOME ((UnparseC.term p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
|
walther@59868
|
64 |
else SOME ((UnparseC.term p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
|
neuper@38015
|
65 |
| eval_is_rootRatAddTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
|
wneuper@59472
|
66 |
\<close>
|
wneuper@59526
|
67 |
setup \<open>KEStore_Elems.add_calcs
|
wneuper@59526
|
68 |
[("is_rootRatAddTerm_in", ("RootRatEq.is_rootRatAddTerm_in", eval_is_rootRatAddTerm_in""))]\<close>
|
wneuper@59526
|
69 |
|
wneuper@59526
|
70 |
subsection \<open>rule-sets\<close>
|
wneuper@59472
|
71 |
ML \<open>
|
neuper@37954
|
72 |
val RootRatEq_prls =
|
walther@59852
|
73 |
Rule_Set.append_rules "RootRatEq_prls" Rule_Set.empty
|
walther@59878
|
74 |
[Rule.Eval ("Prog_Expr.ident", Prog_Expr.eval_ident "#ident_"),
|
walther@59878
|
75 |
Rule.Eval ("Prog_Expr.matches", Prog_Expr.eval_matches ""),
|
walther@59878
|
76 |
Rule.Eval ("Prog_Expr.lhs", Prog_Expr.eval_lhs ""),
|
walther@59878
|
77 |
Rule.Eval ("Prog_Expr.rhs", Prog_Expr.eval_rhs ""),
|
walther@59878
|
78 |
Rule.Eval ("RootEq.is'_rootTerm'_in", eval_is_rootTerm_in ""),
|
walther@59878
|
79 |
Rule.Eval ("RootRatEq.is'_rootRatAddTerm'_in", eval_is_rootRatAddTerm_in ""),
|
walther@59878
|
80 |
Rule.Eval ("HOL.eq", Prog_Expr.eval_equal "#equal_"),
|
walther@59871
|
81 |
Rule.Thm ("not_true",ThmC.numerals_to_Free @{thm not_true}),
|
walther@59871
|
82 |
Rule.Thm ("not_false",ThmC.numerals_to_Free @{thm not_false}),
|
walther@59871
|
83 |
Rule.Thm ("and_true",ThmC.numerals_to_Free @{thm and_true}),
|
walther@59871
|
84 |
Rule.Thm ("and_false",ThmC.numerals_to_Free @{thm and_false}),
|
walther@59871
|
85 |
Rule.Thm ("or_true",ThmC.numerals_to_Free @{thm or_true}),
|
walther@59871
|
86 |
Rule.Thm ("or_false",ThmC.numerals_to_Free @{thm or_false})];
|
neuper@37954
|
87 |
|
neuper@37954
|
88 |
val RooRatEq_erls =
|
walther@59852
|
89 |
Rule_Set.merge "RooRatEq_erls" rootrat_erls
|
walther@59852
|
90 |
(Rule_Set.merge "" RootEq_erls
|
walther@59852
|
91 |
(Rule_Set.merge "" rateq_erls
|
walther@59852
|
92 |
(Rule_Set.append_rules "" Rule_Set.empty
|
neuper@37954
|
93 |
[])));
|
neuper@37954
|
94 |
|
neuper@37954
|
95 |
val RootRatEq_crls =
|
walther@59852
|
96 |
Rule_Set.merge "RootRatEq_crls" rootrat_erls
|
walther@59852
|
97 |
(Rule_Set.merge "" RootEq_erls
|
walther@59852
|
98 |
(Rule_Set.merge "" rateq_erls
|
walther@59852
|
99 |
(Rule_Set.append_rules "" Rule_Set.empty
|
neuper@37954
|
100 |
[])));
|
wneuper@59526
|
101 |
\<close> ML \<open>
|
wneuper@59526
|
102 |
(* Solves a rootrat Equation *)
|
wneuper@59526
|
103 |
val rootrat_solve = prep_rls'(
|
walther@59851
|
104 |
Rule_Def.Repeat {id = "rootrat_solve", preconds = [],
|
wneuper@59526
|
105 |
rew_ord = ("termlessI",termlessI),
|
walther@59852
|
106 |
erls = Rule_Set.empty, srls = Rule_Set.Empty, calc = [], errpatts = [],
|
wneuper@59526
|
107 |
rules =
|
walther@59871
|
108 |
[Rule.Thm("rootrat_equation_left_1", ThmC.numerals_to_Free @{thm rootrat_equation_left_1}),
|
wneuper@59526
|
109 |
(* [|c is_rootTerm_in bdv|] ==>
|
wneuper@59526
|
110 |
( (a + b/c = d) = ( b = (d - a) * c )) *)
|
walther@59871
|
111 |
Rule.Thm("rootrat_equation_left_2",ThmC.numerals_to_Free @{thm rootrat_equation_left_2}),
|
wneuper@59526
|
112 |
(* [|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c )) *)
|
walther@59871
|
113 |
Rule.Thm("rootrat_equation_right_1",ThmC.numerals_to_Free @{thm rootrat_equation_right_1}),
|
wneuper@59526
|
114 |
(* [|f is_rootTerm_in bdv|] ==>
|
wneuper@59526
|
115 |
( (a = d + e/f) = ( (a - d) * f = e )) *)
|
walther@59871
|
116 |
Rule.Thm("rootrat_equation_right_2",ThmC.numerals_to_Free @{thm rootrat_equation_right_2})
|
wneuper@59526
|
117 |
(* [|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))*)
|
walther@59878
|
118 |
], scr = Rule.Empty_Prog});
|
wneuper@59472
|
119 |
\<close>
|
wneuper@59472
|
120 |
setup \<open>KEStore_Elems.add_rlss
|
wneuper@59526
|
121 |
[("RooRatEq_erls", (Context.theory_name @{theory}, RooRatEq_erls)),
|
wneuper@59526
|
122 |
("rootrat_solve", (Context.theory_name @{theory}, rootrat_solve))]\<close>
|
wneuper@59526
|
123 |
|
wneuper@59526
|
124 |
subsection \<open>problems\<close>
|
wneuper@59472
|
125 |
ML \<open>
|
neuper@37954
|
126 |
(*
|
walther@59997
|
127 |
(get_pbt ["rat", "rootX", "univariate", "equation"]);
|
neuper@37954
|
128 |
show_ptyps();
|
neuper@37954
|
129 |
*)
|
wneuper@59472
|
130 |
\<close>
|
wneuper@59472
|
131 |
setup \<open>KEStore_Elems.add_pbts
|
walther@59973
|
132 |
[(Problem.prep_input thy "pbl_equ_univ_root_sq_rat" [] Problem.id_empty
|
walther@59997
|
133 |
(["rat", "sq", "rootX", "univariate", "equation"],
|
walther@59997
|
134 |
[("#Given" ,["equality e_e", "solveFor v_v"]),
|
s1210629013@55339
|
135 |
("#Where" ,["( (lhs e_e) is_rootRatAddTerm_in (v_v::real) )| " ^
|
s1210629013@55339
|
136 |
"( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"]),
|
s1210629013@55339
|
137 |
("#Find" ,["solutions v_v'i'"])],
|
walther@59997
|
138 |
RootRatEq_prls, SOME "solve (e_e::bool, v_v)", [["RootRatEq", "elim_rootrat_equation"]]))]\<close>
|
s1210629013@55380
|
139 |
|
wneuper@59526
|
140 |
subsection \<open>methods\<close>
|
wneuper@59472
|
141 |
setup \<open>KEStore_Elems.add_mets
|
walther@60154
|
142 |
[MethodC.prep_input @{theory LinEq} "met_rootrateq" [] MethodC.id_empty
|
s1210629013@55373
|
143 |
(["RootRatEq"], [],
|
walther@59852
|
144 |
{rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule_Set.empty, prls=Rule_Set.empty,
|
wneuper@59545
|
145 |
crls=Atools_erls, errpats = [], nrls = norm_Rational}, @{thm refl})]
|
wneuper@59473
|
146 |
\<close>
|
s1210629013@55373
|
147 |
(*-- left 20.10.02 --*)
|
wneuper@59504
|
148 |
partial_function (tailrec) solve_rootrat_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
|
wneuper@59504
|
149 |
where
|
wneuper@59504
|
150 |
"solve_rootrat_equ e_e v_v =
|
walther@59635
|
151 |
(let
|
walther@59635
|
152 |
e_e = (
|
walther@59637
|
153 |
(Try (Rewrite_Set ''expand_rootbinoms'')) #>
|
walther@59637
|
154 |
(Try (Rewrite_Set ''rooteq_simplify'')) #>
|
walther@59637
|
155 |
(Try (Rewrite_Set ''make_rooteq'')) #>
|
walther@59637
|
156 |
(Try (Rewrite_Set ''rooteq_simplify'')) #>
|
walther@59635
|
157 |
(Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''rootrat_solve'')) ) e_e
|
walther@59635
|
158 |
in SubProblem (''RootEq'', [''univariate'', ''equation''], [''no_met'']) [BOOL e_e, REAL v_v])"
|
wneuper@59473
|
159 |
setup \<open>KEStore_Elems.add_mets
|
walther@60154
|
160 |
[MethodC.prep_input thy "met_rootrateq_elim" [] MethodC.id_empty
|
walther@59997
|
161 |
(["RootRatEq", "elim_rootrat_equation"],
|
walther@59997
|
162 |
[("#Given" ,["equality e_e", "solveFor v_v"]),
|
s1210629013@55373
|
163 |
("#Where" ,["( (lhs e_e) is_rootRatAddTerm_in (v_v::real) ) | " ^
|
s1210629013@55373
|
164 |
"( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"]),
|
s1210629013@55373
|
165 |
("#Find" ,["solutions v_v'i'"])],
|
walther@59852
|
166 |
{rew_ord'="termlessI", rls'=RooRatEq_erls, srls=Rule_Set.empty, prls=RootRatEq_prls, calc=[],
|
s1210629013@55373
|
167 |
crls=RootRatEq_crls, errpats = [], nrls = norm_Rational},
|
wneuper@59551
|
168 |
@{thm solve_rootrat_equ.simps})]
|
wneuper@59472
|
169 |
\<close>
|
neuper@37906
|
170 |
end
|