1 (* tools for integration over the reals
4 (c) due to copyright terms
6 use"~/proto2/isac/src/sml/IsacKnowledge/Integrate.ML";
9 (** interface isabelle -- isac **)
11 theory' := overwritel (!theory', [("Integrate.thy",Integrate.thy)]);
13 theorem' := overwritel (!theorem',
14 [("integral_const",num_str integral_const),
15 ("integral_var",num_str integral_var),
16 ("integral_add",num_str integral_add),
17 ("integral_mult",num_str integral_mult),
18 ("call_for_new_c",num_str call_for_new_c),
19 ("integral_pow",num_str integral_pow)
22 (** eval functions **)
24 val c = Free ("c", HOLogic.realT);
25 (*.create a new unique variable 'c..' in a term.*)
28 case (explode o id_of) var of
30 | "c"::"_"::is => (case (int_of_str o implode) is of
34 fun get_coeff c = case (explode o id_of) c of
35 "c"::"_"::is => (the o int_of_str o implode) is
37 val cs = filter selc (vars term);
41 | [c] => Free ("c_2", HOLogic.realT)
43 let val max_coeff = maxl (map get_coeff cs)
44 in Free ("c_"^string_of_int (max_coeff + 1), HOLogic.realT) end
47 (*("new_c", ("Integrate.new'_c", eval_new_c "new_c_"))*)
48 fun eval_new_c _ _ (p as (Const ("Integrate.new'_c",_) $ t)) _ =
49 Some ((term2str p) ^ " = " ^ term2str (new_c p),
50 Trueprop $ (mk_equality (p, new_c p)))
51 | eval_new_c _ _ _ _ = None;
53 (*("is_f_x", ("Integrate.is'_f'_x", eval_is_f_x "is_f_x_"))*)
54 fun eval_is_f_x _ _(p as (Const ("Integrate.is'_f'_x", _)
57 then Some ((term2str p) ^ " = True",
58 Trueprop $ (mk_equality (p, HOLogic.true_const)))
59 else Some ((term2str p) ^ " = False",
60 Trueprop $ (mk_equality (p, HOLogic.false_const)))
61 | eval_is_f_x _ _ _ _ = None;
63 calclist':= overwritel (!calclist',
64 [("new_c", ("Integrate.new'_c", eval_new_c "new_c_")),
65 ("is_f_x", ("Integrate.is'_f'_x", eval_is_f_x "is_f_idextifier_"))
70 val integration_rules =
71 prep_rls (Rls {id="integration_rules", preconds = [],
72 rew_ord = ("termlessI",termlessI),
73 erls = Rls {id="conditions_in_integration_rules",
75 rew_ord = ("termlessI",termlessI),
77 srls = Erls, calc = [],
78 rules = [(*for rewriting conditions in Thm's*)
79 Calc ("Atools.occurs'_in",
80 eval_occurs_in "#occurs_in_"),
81 Thm ("not_true",num_str not_true),
82 Thm ("not_false",not_false)
85 srls = Erls, calc = [],
87 Thm ("integral_const",num_str integral_const),
88 Thm ("integral_var",num_str integral_var),
89 Thm ("integral_add",num_str integral_add),
90 Thm ("integral_mult",num_str integral_mult),
91 Thm ("integral_pow",num_str integral_pow),
92 Calc ("op +", eval_binop "#add_")(*for n+1*)
96 prep_rls (Seq {id="add_new_c", preconds = [],
97 rew_ord = ("termlessI",termlessI),
98 erls = Rls {id="conditions_in_add_new_c",
100 rew_ord = ("termlessI",termlessI),
102 srls = Erls, calc = [],
103 rules = [Calc ("Tools.matches", eval_matches""),
104 Calc ("Integrate.is'_f'_x",
105 eval_is_f_x "is_f_x_"),
106 Thm ("not_true",num_str not_true),
107 Thm ("not_false",num_str not_false)
110 srls = Erls, calc = [],
111 rules = [ Thm ("call_for_new_c", num_str call_for_new_c),
112 Calc("Integrate.new'_c", eval_new_c "new_c_")
116 prep_rls (Seq {id="integration", preconds = [],
117 rew_ord = ("termlessI",termlessI),
118 erls = Rls {id="conditions_in_integration",
120 rew_ord = ("termlessI",termlessI),
122 srls = Erls, calc = [],
125 srls = Erls, calc = [],
126 rules = [ Rls_ integration_rules,
131 ruleset' := overwritel (!ruleset', [("integration_rules", integration_rules),
132 ("add_new_c", add_new_c),
133 ("integration", integration)]);
138 (prep_pbt Integrate.thy
139 (["integrate","function"],
140 [("#Given" ,["functionTerm f_", "integrateBy v_"]),
141 ("#Find" ,["antiDerivative F_"])
143 append_rls "e_rls" e_rls [(*for preds in where_*)],
144 Some "Integrate (f_, v_)",
145 [["Diff","integration"]]));
148 (prep_pbt Integrate.thy
149 (["named","integrate","function"],
150 [("#Given" ,["functionTerm f_", "integrateBy v_"]),
151 ("#Find" ,["antiDerivativeName F_"])
153 append_rls "e_rls" e_rls [(*for preds in where_*)],
154 Some "Integrate (f_, v_)",
155 [["Diff","integration","named"]]));
160 (prep_met Integrate.thy
161 (["Diff","integration"],
162 [("#Given" ,["functionTerm f_", "integrateBy v_"]),
163 ("#Find" ,["antiDerivative F_"])
165 {rew_ord'="tless_true", rls'=Atools_erls, calc = [],
168 crls = Atools_erls, nrls = e_rls},
169 "Script IntegrationScript (f_::real) (v_::real) = \
170 \ (let t_ = Take (Integral f_ D v_) \
171 \ in (Rewrite_Set_Inst [(bdv,v_)] integration False) (t_::real))"
175 (prep_met Integrate.thy
176 (["Diff","integration","named"],
177 [("#Given" ,["functionTerm f_", "integrateBy v_"]),
178 ("#Find" ,["antiDerivativeName F_"])
180 {rew_ord'="tless_true", rls'=Atools_erls, calc = [],
183 crls = Atools_erls, nrls = e_rls},
184 "Script NamedIntegrationScript (f_::real) (v_::real) (F_::real=>real) = \
185 \ (let t_ = Take (F_ v_ = Integral f_ D v_) \
186 \ in (Rewrite_Set_Inst [(bdv,v_)] integration False) t_)"