1 (* collecting all knowledge for Root and Rational Equations
7 (c) by Richard Lang, 2003
10 theory RootRatEq imports LinEq RootEq RatEq RootRat begin
12 text \<open>univariate equations over rational terms containing real square roots:
13 In 2003 this type has been developed as part of ISAC's equation solver
14 by Richard Lang in 2003.
15 The migration Isabelle2002 --> 2011 dropped this type of equation, see RootEq.thy.
18 subsection \<open>consts definition for predicates\<close>
20 is_rootRatAddTerm_in :: "[real, real] => bool" ("_ is'_rootRatAddTerm'_in _") (*RL*)
22 subsection \<open>theorems not yet adopted from Isabelle\<close>
24 (* eliminate ratRootTerm *)
25 rootrat_equation_left_1:
26 "[|c is_rootTerm_in bdv|] ==> ( (a + b/c = d) = ( b = (d - a) * c ))" and
27 rootrat_equation_left_2:
28 "[|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c ))" and
29 rootrat_equation_right_2:
30 "[|f is_rootTerm_in bdv|] ==> ( (a = d + e/f) = ( (a - d) * f = e ))" and
31 rootrat_equation_right_1:
32 "[|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))"
34 subsection \<open>predicates\<close>
36 (* true if denominator contains (sq)root in + or - term
37 1/(sqrt(x+3)*(x+4)) -> false; 1/(sqrt(x)+2) -> true
38 if false then (term)^2 contains no (sq)root *)
39 fun is_rootRatAddTerm_in t v =
41 fun rootadd (Const (\<^const_name>\<open>plus\<close>, _) $ t2 $ t3) v =
42 is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
43 | rootadd (Const (\<^const_name>\<open>minus\<close>,_) $ t2 $ t3) v =
44 is_rootTerm_in t2 v orelse is_rootTerm_in t3 v
45 | rootadd _ _ = false;
46 fun findrootrat (t as (_ $ _ $ _ $ _)) _ = raise TERM ("is_rootRatAddTerm_in", [t])
47 (* at the moment there is no term like this, but ....*)
48 | findrootrat (Const (\<^const_name>\<open>divide\<close>,_) $ _ $ t3) v =
49 if (is_rootTerm_in t3 v) then rootadd t3 v else false
50 | findrootrat (_ $ t1 $ t2) v =
51 findrootrat t1 v orelse findrootrat t2 v
52 | findrootrat (_ $ t1) v = findrootrat t1 v
53 | findrootrat _ _ = false;
58 fun eval_is_rootRatAddTerm_in _ _ (p as (Const (\<^const_name>\<open>is_rootRatAddTerm_in\<close>,_) $ t $ v)) _ =
59 if is_rootRatAddTerm_in t v
60 then SOME ((UnparseC.term @{context} p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
61 else SOME ((UnparseC.term @{context} p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
62 | eval_is_rootRatAddTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
64 calculation is_rootRatAddTerm_in = \<open>eval_is_rootRatAddTerm_in ""\<close>
66 subsection \<open>rule-sets\<close>
69 Rule_Set.append_rules "RootRatEq_prls" Rule_Set.empty [
70 \<^rule_eval>\<open>Prog_Expr.ident\<close> (Prog_Expr.eval_ident "#ident_"),
71 \<^rule_eval>\<open>Prog_Expr.matches\<close> (Prog_Expr.eval_matches ""),
72 \<^rule_eval>\<open>Prog_Expr.lhs\<close> (Prog_Expr.eval_lhs ""),
73 \<^rule_eval>\<open>Prog_Expr.rhs\<close> (Prog_Expr.eval_rhs ""),
74 \<^rule_eval>\<open>is_rootTerm_in\<close> (eval_is_rootTerm_in ""),
75 \<^rule_eval>\<open>is_rootRatAddTerm_in\<close> (eval_is_rootRatAddTerm_in ""),
76 \<^rule_eval>\<open>HOL.eq\<close> (Prog_Expr.eval_equal "#equal_"),
77 \<^rule_thm>\<open>not_true\<close>,
78 \<^rule_thm>\<open>not_false\<close>,
79 \<^rule_thm>\<open>and_true\<close>,
80 \<^rule_thm>\<open>and_false\<close>,
81 \<^rule_thm>\<open>or_true\<close>,
82 \<^rule_thm>\<open>or_false\<close>];
85 Rule_Set.merge "RooRatEq_erls" rootrat_erls
86 (Rule_Set.merge "" RootEq_erls
87 (Rule_Set.merge "" rateq_erls
88 (Rule_Set.append_rules "" Rule_Set.empty
92 Rule_Set.merge "RootRatEq_crls" rootrat_erls
93 (Rule_Set.merge "" RootEq_erls
94 (Rule_Set.merge "" rateq_erls
95 (Rule_Set.append_rules "" Rule_Set.empty
98 (* Solves a rootrat Equation *)
99 val rootrat_solve = prep_rls'(
101 id = "rootrat_solve", preconds = [], rew_ord = ("termlessI",termlessI),
102 asm_rls = Rule_Set.empty, prog_rls = Rule_Set.Empty, calc = [], errpatts = [],
104 \<^rule_thm>\<open>rootrat_equation_left_1\<close>, (* [|c is_rootTerm_in bdv|] ==> ( (a + b/c = d) = ( b = (d - a) * c )) *)
105 \<^rule_thm>\<open>rootrat_equation_left_2\<close>, (* [|c is_rootTerm_in bdv|] ==> ( (b/c = d) = ( b = d * c )) *)
106 \<^rule_thm>\<open>rootrat_equation_right_1\<close>, (* [|f is_rootTerm_in bdv|] ==> ( (a = d + e/f) = ( (a - d) * f = e )) *)
107 \<^rule_thm>\<open>rootrat_equation_right_2\<close>], (* [|f is_rootTerm_in bdv|] ==> ( (a = e/f) = ( a * f = e ))*)
108 program = Rule.Empty_Prog});
111 RooRatEq_erls = RooRatEq_erls and
112 rootrat_solve = rootrat_solve
114 subsection \<open>problems\<close>
116 problem pbl_equ_univ_root_sq_rat : "rat/sq/rootX/univariate/equation" =
117 \<open>RootRatEq_prls\<close>
118 Method_Ref: "RootRatEq/elim_rootrat_equation"
119 CAS: "solve (e_e::bool, v_v)"
120 Given: "equality e_e" "solveFor v_v"
121 Where: "( (lhs e_e) is_rootRatAddTerm_in (v_v::real) ) |
122 ( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"
123 Find: "solutions v_v'i'"
125 subsection \<open>methods\<close>
127 method "met_rootrateq" : "RootRatEq" =
128 \<open>{rew_ord="tless_true",rls'=Atools_erls,calc = [], prog_rls = Rule_Set.empty, where_rls=Rule_Set.empty,
129 errpats = [], rew_rls = norm_Rational}\<close>
131 (*-- left 20.10.02 --*)
132 partial_function (tailrec) solve_rootrat_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
134 "solve_rootrat_equ e_e v_v =
137 (Try (Rewrite_Set ''expand_rootbinoms'')) #>
138 (Try (Rewrite_Set ''rooteq_simplify'')) #>
139 (Try (Rewrite_Set ''make_rooteq'')) #>
140 (Try (Rewrite_Set ''rooteq_simplify'')) #>
141 (Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''rootrat_solve'')) ) e_e
142 in SubProblem (''RootEq'', [''univariate'', ''equation''], [''no_met'']) [BOOL e_e, REAL v_v])"
144 method met_rootrateq_elim : "RootRatEq/elim_rootrat_equation" =
145 \<open>{rew_ord="termlessI", rls'=RooRatEq_erls, prog_rls=Rule_Set.empty, where_rls=RootRatEq_prls, calc=[],
146 errpats = [], rew_rls = norm_Rational}\<close>
147 Program: solve_rootrat_equ.simps
148 Given: "equality e_e" "solveFor v_v"
149 Where: "( (lhs e_e) is_rootRatAddTerm_in (v_v::real) ) |
150 ( (rhs e_e) is_rootRatAddTerm_in (v_v::real) )"
151 Find: "solutions v_v'i'"