
neuper@37906: (*. (c) by Richard Lang, 2003 .*)
neuper@37906: (* theory collecting all knowledge for LinearEquations
neuper@37906:    created by: rlang 
neuper@37906:          date: 02.10
neuper@37906:    changed by: rlang
neuper@37906:    last change by: rlang
neuper@37906:              date: 02.10.20
neuper@37906: *)
neuper@37906: 
neuper@37950: theory LinEq imports Poly Equation begin
neuper@37906: 
neuper@37906: consts
neuper@37906:    Solve'_lineq'_equation
neuper@37950:              :: "[bool,real, 
neuper@37950: 		   bool list] => bool list"
neuper@37950:                ("((Script Solve'_lineq'_equation (_ _ =))// 
neuper@37950:                   (_))" 9)
neuper@37906: 
neuper@52148: axiomatization where
neuper@37906: (*-- normalize --*)
neuper@37906:   (*WN0509 compare PolyEq.all_left "[|Not(b=!=0)|] ==> (a = b) = (a - b = 0)"*)
neuper@52148:   all_left:          "[|Not(b=!=0)|] ==> (a=b) = (a+(-1)*b=0)" and
neuper@52148:   makex1_x:          "a^^^1  = a" and
neuper@52148:   real_assoc_1:      "a+(b+c) = a+b+c" and
neuper@52148:   real_assoc_2:      "a*(b*c) = a*b*c" and
neuper@37906: 
neuper@37906: (*-- solve --*)
neuper@52148:   lin_isolate_add1:  "(a + b*bdv = 0) = (b*bdv = (-1)*a)" and
neuper@52148:   lin_isolate_add2:  "(a +   bdv = 0) = (  bdv = (-1)*a)" and
neuper@37982:   lin_isolate_div:   "[|Not(b=0)|] ==> (b*bdv = c) = (bdv = c / b)"
neuper@37950: 
neuper@37950: ML {*
neuper@37972: val thy = @{theory};
neuper@37972: 
neuper@37950: val LinEq_prls = (*3.10.02:just the following order due to subterm evaluation*)
neuper@37950:   append_rls "LinEq_prls" e_rls 
neuper@41922: 	     [Calc ("HOL.eq",eval_equal "#equal_"),
neuper@37950: 	      Calc ("Tools.matches",eval_matches ""),
neuper@37950: 	      Calc ("Tools.lhs"    ,eval_lhs ""),
neuper@37950: 	      Calc ("Tools.rhs"    ,eval_rhs ""),
neuper@37950: 	      Calc ("Poly.has'_degree'_in",eval_has_degree_in ""),
neuper@37950:  	      Calc ("Poly.is'_polyrat'_in",eval_is_polyrat_in ""),
neuper@37950: 	      Calc ("Atools.occurs'_in",eval_occurs_in ""),    
neuper@37950: 	      Calc ("Atools.ident",eval_ident "#ident_"),
neuper@37969: 	      Thm ("not_true",num_str @{thm not_true}),
neuper@37969: 	      Thm ("not_false",num_str @{thm not_false}),
neuper@37969: 	      Thm ("and_true",num_str @{thm and_true}),
neuper@37969: 	      Thm ("and_false",num_str @{thm and_false}),
neuper@37969: 	      Thm ("or_true",num_str @{thm or_true}),
neuper@37969: 	      Thm ("or_false",num_str @{thm or_false})
neuper@37950:               ];
neuper@37950: (* ----- erls ----- *)
neuper@37950: val LinEq_crls = 
neuper@37950:    append_rls "LinEq_crls" poly_crls
neuper@37969:    [Thm  ("real_assoc_1",num_str @{thm real_assoc_1})
neuper@37950:     (*		
neuper@37950:      Don't use
neuper@48789:      Calc ("Fields.inverse_class.divide", eval_cancel "#divide_e"),
neuper@37950:      Calc ("Atools.pow" ,eval_binop "#power_"),
neuper@37950:      *)
neuper@37950:     ];
neuper@37950: 
neuper@37950: (* ----- crls ----- *)
neuper@37950: val LinEq_erls = 
neuper@37950:    append_rls "LinEq_erls" Poly_erls
neuper@37969:    [Thm  ("real_assoc_1",num_str @{thm real_assoc_1})
neuper@37950:     (*		
neuper@37950:      Don't use
neuper@48789:      Calc ("Fields.inverse_class.divide", eval_cancel "#divide_e"),
neuper@37950:      Calc ("Atools.pow" ,eval_binop "#power_"),
neuper@37950:      *)
neuper@37950:     ];
neuper@52125: *}
neuper@52125: setup {* KEStore_Elems.add_rlss 
neuper@52125:   [("LinEq_erls", (Context.theory_name @{theory}, LinEq_erls))] *}
neuper@52125: ML {*
neuper@37950:     
neuper@37950: val LinPoly_simplify = prep_rls(
neuper@37950:   Rls {id = "LinPoly_simplify", preconds = [], 
neuper@37950:        rew_ord = ("termlessI",termlessI), 
neuper@37950:        erls = LinEq_erls, 
neuper@37950:        srls = Erls, 
neuper@42451:        calc = [], errpatts = [],
neuper@37950:        rules = [
neuper@37969: 		Thm  ("real_assoc_1",num_str @{thm real_assoc_1}),
neuper@38014: 		Calc ("Groups.plus_class.plus",eval_binop "#add_"),
neuper@38014: 		Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
neuper@38034: 		Calc ("Groups.times_class.times",eval_binop "#mult_"),
neuper@37950: 		(*  Dont use  
neuper@48789: 		 Calc ("Fields.inverse_class.divide", eval_cancel "#divide_e"),		
neuper@37982: 		 Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
neuper@37950: 		 *)
neuper@37950: 		Calc ("Atools.pow" ,eval_binop "#power_")
neuper@37950: 		],
neuper@37982:        scr = EmptyScr}:rls);
neuper@52125: *}
neuper@52125: setup {* KEStore_Elems.add_rlss 
neuper@52125:   [("LinPoly_simplify", (Context.theory_name @{theory}, LinPoly_simplify))] *}
neuper@52125: ML {*
neuper@37950: 
neuper@37950: (*isolate the bound variable in an linear equation; 'bdv' is a meta-constant*)
neuper@37950: val LinEq_simplify = prep_rls(
neuper@37950: Rls {id = "LinEq_simplify", preconds = [],
neuper@37950:      rew_ord = ("e_rew_ord",e_rew_ord),
neuper@37950:      erls = LinEq_erls,
neuper@37950:      srls = Erls,
neuper@42451:      calc = [], errpatts = [],
neuper@37950:      rules = [
neuper@37969: 	      Thm("lin_isolate_add1",num_str @{thm lin_isolate_add1}), 
neuper@37950: 	      (* a+bx=0 -> bx=-a *)
neuper@37969: 	      Thm("lin_isolate_add2",num_str @{thm lin_isolate_add2}), 
neuper@37950: 	      (* a+ x=0 ->  x=-a *)
neuper@37969: 	      Thm("lin_isolate_div",num_str @{thm lin_isolate_div})    
neuper@37950: 	      (*   bx=c -> x=c/b *)  
neuper@37950: 	      ],
neuper@37982:      scr = EmptyScr}:rls);
neuper@52125: *}
neuper@52125: setup {* KEStore_Elems.add_rlss 
neuper@52125:   [("LinEq_simplify", (Context.theory_name @{theory}, LinEq_simplify))] *}
neuper@37950: 
neuper@37950: (*----------------------------- problem types --------------------------------*)
neuper@37950: (* ---------linear----------- *)
s1210629013@55359: setup {* KEStore_Elems.add_pbts
s1210629013@55339:   [(prep_pbt thy "pbl_equ_univ_lin" [] e_pblID
s1210629013@55339:       (["LINEAR", "univariate", "equation"],
s1210629013@55339:         [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55339:           ("#Where" ,["HOL.False", (*WN0509 just detected: this pbl can never be used?!?*)
s1210629013@55339:               "Not( (lhs e_e) is_polyrat_in v_v)",
s1210629013@55339:               "Not( (rhs e_e) is_polyrat_in v_v)",
s1210629013@55339:               "((lhs e_e) has_degree_in v_v)=1",
s1210629013@55339: 	            "((rhs e_e) has_degree_in v_v)=1"]),
s1210629013@55339:           ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339:         LinEq_prls, SOME "solve (e_e::bool, v_v)", [["LinEq", "solve_lineq_equation"]]))] *}
neuper@37950: 
s1210629013@55373: (*-------------- methods------------------------------------------------------*)
s1210629013@55373: setup {* KEStore_Elems.add_mets
s1210629013@55373:   [prep_met thy "met_eqlin" [] e_metID
s1210629013@55373:       (["LinEq"], [],
s1210629013@55373:         {rew_ord' = "tless_true",rls' = Atools_erls,calc = [], srls = e_rls, prls = e_rls,
s1210629013@55373:           crls = LinEq_crls, errpats = [], nrls = norm_Poly},
s1210629013@55373:         "empty_script"),
s1210629013@55373:     (* ansprechen mit ["LinEq","solve_univar_equation"] *)
s1210629013@55373:     prep_met thy "met_eq_lin" [] e_metID
s1210629013@55373:       (["LinEq","solve_lineq_equation"],
s1210629013@55373:         [("#Given", ["equality e_e", "solveFor v_v"]),
s1210629013@55373:           ("#Where", ["Not ((lhs e_e) is_polyrat_in v_v)", "((lhs e_e)  has_degree_in v_v) = 1"]),
s1210629013@55373:           ("#Find",  ["solutions v_v'i'"])],
s1210629013@55373:         {rew_ord' = "termlessI", rls' = LinEq_erls, srls = e_rls, prls = LinEq_prls, calc = [],
s1210629013@55373:           crls = LinEq_crls, errpats = [], nrls = norm_Poly},
s1210629013@55373:         "Script Solve_lineq_equation (e_e::bool) (v_v::real) =                 " ^
s1210629013@55373:           "(let e_e =((Try         (Rewrite      all_left           False)) @@   " ^ 
s1210629013@55373:           "           (Try (Repeat (Rewrite     makex1_x            False))) @@  " ^ 
s1210629013@55373:           "           (Try         (Rewrite_Set expand_binoms       False)) @@   " ^ 
s1210629013@55373:           "           (Try (Repeat (Rewrite_Set_Inst [(bdv, v_v::real)]          " ^
s1210629013@55373:           "                                 make_ratpoly_in    False)))    @@    " ^
s1210629013@55373:           "           (Try (Repeat (Rewrite_Set LinPoly_simplify      False))))e_e;" ^
s1210629013@55373:           "     e_e = ((Try (Rewrite_Set_Inst [(bdv, v_v::real)]                  " ^
s1210629013@55373:           "                                     LinEq_simplify True)) @@  " ^
s1210629013@55373:           "            (Repeat(Try (Rewrite_Set LinPoly_simplify     False)))) e_e " ^
s1210629013@55373:           " in ((Or_to_List e_e)::bool list))")]
s1210629013@55373: *}
s1210629013@55373: ML {* get_met ["LinEq","solve_lineq_equation"]; *}
neuper@37950: 
neuper@37906: end
neuper@37906: 




