1 (*. (c) by Richard Lang, 2003 .*)
2 (* theory collecting all knowledge for LinearEquations
10 theory LinEq imports Poly Equation begin
13 Solve'_lineq'_equation
15 bool list] => bool list"
16 ("((Script Solve'_lineq'_equation (_ _ =))// (_))" 9)
20 (*WN0509 compare PolyEq.all_left "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)"*)
21 all_left: "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)" and
22 makex1_x: "a^^^1 = a" and
23 real_assoc_1: "a+(b+c) = a+b+c" and
24 real_assoc_2: "a*(b*c) = a*b*c" and
27 lin_isolate_add1: "(a + b*bdv = 0) = (b*bdv = (-1)*a)" and
28 lin_isolate_add2: "(a + bdv = 0) = ( bdv = (-1)*a)" and
29 lin_isolate_div: "[|Not(b=0)|] ==> (b*bdv = c) = (bdv = c / b)"
34 val LinEq_prls = (*3.10.02:just the following order due to subterm evaluation*)
35 append_rls "LinEq_prls" e_rls
36 [Calc ("HOL.eq",eval_equal "#equal_"),
37 Calc ("Tools.matches",eval_matches ""),
38 Calc ("Tools.lhs" ,eval_lhs ""),
39 Calc ("Tools.rhs" ,eval_rhs ""),
40 Calc ("Poly.has'_degree'_in",eval_has_degree_in ""),
41 Calc ("Poly.is'_polyrat'_in",eval_is_polyrat_in ""),
42 Calc ("Atools.occurs'_in",eval_occurs_in ""),
43 Calc ("Atools.ident",eval_ident "#ident_"),
44 Thm ("not_true",num_str @{thm not_true}),
45 Thm ("not_false",num_str @{thm not_false}),
46 Thm ("and_true",num_str @{thm and_true}),
47 Thm ("and_false",num_str @{thm and_false}),
48 Thm ("or_true",num_str @{thm or_true}),
49 Thm ("or_false",num_str @{thm or_false})
51 (* ----- erls ----- *)
53 append_rls "LinEq_crls" poly_crls
54 [Thm ("real_assoc_1",num_str @{thm real_assoc_1})
57 Calc ("Rings.divide_class.divide", eval_cancel "#divide_e"),
58 Calc ("Atools.pow" ,eval_binop "#power_"),
62 (* ----- crls ----- *)
64 append_rls "LinEq_erls" Poly_erls
65 [Thm ("real_assoc_1",num_str @{thm real_assoc_1})
68 Calc ("Rings.divide_class.divide", eval_cancel "#divide_e"),
69 Calc ("Atools.pow" ,eval_binop "#power_"),
73 setup {* KEStore_Elems.add_rlss
74 [("LinEq_erls", (Context.theory_name @{theory}, LinEq_erls))] *}
77 val LinPoly_simplify = prep_rls'(
78 Rls {id = "LinPoly_simplify", preconds = [],
79 rew_ord = ("termlessI",termlessI),
82 calc = [], errpatts = [],
84 Thm ("real_assoc_1",num_str @{thm real_assoc_1}),
85 Calc ("Groups.plus_class.plus",eval_binop "#add_"),
86 Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
87 Calc ("Groups.times_class.times",eval_binop "#mult_"),
89 Calc ("Rings.divide_class.divide", eval_cancel "#divide_e"),
90 Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
92 Calc ("Atools.pow" ,eval_binop "#power_")
96 setup {* KEStore_Elems.add_rlss
97 [("LinPoly_simplify", (Context.theory_name @{theory}, LinPoly_simplify))] *}
100 (*isolate the bound variable in an linear equation; 'bdv' is a meta-constant*)
101 val LinEq_simplify = prep_rls'(
102 Rls {id = "LinEq_simplify", preconds = [],
103 rew_ord = ("e_rew_ord",e_rew_ord),
106 calc = [], errpatts = [],
108 Thm("lin_isolate_add1",num_str @{thm lin_isolate_add1}),
109 (* a+bx=0 -> bx=-a *)
110 Thm("lin_isolate_add2",num_str @{thm lin_isolate_add2}),
112 Thm("lin_isolate_div",num_str @{thm lin_isolate_div})
115 scr = EmptyScr}:rls);
117 setup {* KEStore_Elems.add_rlss
118 [("LinEq_simplify", (Context.theory_name @{theory}, LinEq_simplify))] *}
120 (*----------------------------- problem types --------------------------------*)
121 (* ---------linear----------- *)
122 setup {* KEStore_Elems.add_pbts
123 [(Specify.prep_pbt thy "pbl_equ_univ_lin" [] e_pblID
124 (["LINEAR", "univariate", "equation"],
125 [("#Given" ,["equality e_e", "solveFor v_v"]),
126 ("#Where" ,["HOL.False", (*WN0509 just detected: this pbl can never be used?!?*)
127 "Not( (lhs e_e) is_polyrat_in v_v)",
128 "Not( (rhs e_e) is_polyrat_in v_v)",
129 "((lhs e_e) has_degree_in v_v)=1",
130 "((rhs e_e) has_degree_in v_v)=1"]),
131 ("#Find" ,["solutions v_v'i'"])],
132 LinEq_prls, SOME "solve (e_e::bool, v_v)", [["LinEq", "solve_lineq_equation"]]))] *}
134 (*-------------- methods------------------------------------------------------*)
135 setup {* KEStore_Elems.add_mets
136 [Specify.prep_met thy "met_eqlin" [] e_metID
138 {rew_ord' = "tless_true",rls' = Atools_erls,calc = [], srls = e_rls, prls = e_rls,
139 crls = LinEq_crls, errpats = [], nrls = norm_Poly},
141 (* ansprechen mit ["LinEq","solve_univar_equation"] *)
142 Specify.prep_met thy "met_eq_lin" [] e_metID
143 (["LinEq","solve_lineq_equation"],
144 [("#Given", ["equality e_e", "solveFor v_v"]),
145 ("#Where", ["Not ((lhs e_e) is_polyrat_in v_v)", "((lhs e_e) has_degree_in v_v) = 1"]),
146 ("#Find", ["solutions v_v'i'"])],
147 {rew_ord' = "termlessI", rls' = LinEq_erls, srls = e_rls, prls = LinEq_prls, calc = [],
148 crls = LinEq_crls, errpats = [], nrls = norm_Poly},
149 "Script Solve_lineq_equation (e_e::bool) (v_v::real) = " ^
150 "(let e_e =((Try (Rewrite all_left False)) @@ " ^
151 " (Try (Repeat (Rewrite makex1_x False))) @@ " ^
152 " (Try (Rewrite_Set expand_binoms False)) @@ " ^
153 " (Try (Repeat (Rewrite_Set_Inst [(bdv, v_v::real)] " ^
154 " make_ratpoly_in False))) @@ " ^
155 " (Try (Repeat (Rewrite_Set LinPoly_simplify False))))e_e;" ^
156 " e_e = ((Try (Rewrite_Set_Inst [(bdv, v_v::real)] " ^
157 " LinEq_simplify True)) @@ " ^
158 " (Repeat(Try (Rewrite_Set LinPoly_simplify False)))) e_e " ^
159 " in ((Or_to_List e_e)::bool list))")]
161 ML {* Specify.get_met' @{theory} ["LinEq","solve_lineq_equation"]; *}