1 (* tests on integration over the reals
4 (c) due to copyright terms
6 use"~/proto2/isac/src/smltest/IsacKnowledge/integrate.sml";
8 val thy = Integrate.thy;
10 "-----------------------------------------------------------------";
11 "table of contents -----------------------------------------------";
12 "-----------------------------------------------------------------";
13 "----------- parsing ---------------------------------------------";
14 "----------- integrate by rewriting ------------------------------";
15 "----------- test new_c, is_f_x ----------------------------------";
16 "----------- integrate by ruleset --------------------------------";
17 "----------- check probem type -----------------------------------";
18 "----------- check Scripts ---------------------------------------";
19 "----------- me method [Diff,integration] ------------------------";
20 "----------- me method [Diff,integration,named] ------------------";
21 "-----------------------------------------------------------------";
22 "-----------------------------------------------------------------";
23 "-----------------------------------------------------------------";
25 "----------- parsing ---------------------------------------------";
26 "----------- parsing ---------------------------------------------";
27 "----------- parsing ---------------------------------------------";
28 fun str2t str = (term_of o the o (parse Integrate.thy)) str;
29 fun term2s t = Sign.string_of_term (sign_of Integrate.thy) t;
31 val t = str2t "Integral x D x";
32 val t = str2t "Integral x^^^2 D x";
35 val t = str2t "M_b x is_f_x";
36 case t of Const ("Integrate.is'_f'_x", _) $ _ => ()
37 | _ => raise error "integrate.sml: parsing: M_b x is_f_x";
39 "----------- integrate by rewriting ------------------------------";
40 "----------- integrate by rewriting ------------------------------";
41 "----------- integrate by rewriting ------------------------------";
42 val conditions_in_integration_rules =
43 Rls {id="conditions_in_integration_rules",
45 rew_ord = ("termlessI",termlessI),
47 srls = Erls, calc = [],
48 rules = [(*for rewriting conditions in Thm's*)
49 Calc ("Atools.occurs'_in",
50 eval_occurs_in "#occurs_in_"),
51 Thm ("not_true",num_str not_true),
52 Thm ("not_false",not_false)
55 val subs = [(str2t "bdv", str2t "x")];
57 fst (the (rewrite_inst_ Integrate.thy tless_true
58 conditions_in_integration_rules
60 val str = rewrit integral_const (str2t "Integral 1 D x"); term2s str;
61 val str = rewrit integral_const (str2t "Integral M'/EJ D x"); term2s str;
62 val str = (rewrit integral_const (str2t "Integral x D x"))
63 handle OPTION => str2t "no_rewrite";
65 val str = rewrit integral_var (str2t "Integral x D x"); term2s str;
66 val str = (rewrit integral_var (str2t "Integral a D x"))
67 handle OPTION => str2t "no_rewrite";
69 val str = rewrit integral_add (str2t "Integral x + 1 D x"); term2s str;
71 val str = rewrit integral_mult (str2t "Integral M'/EJ * x^^^3 D x");term2s str;
72 val str = (rewrit integral_mult (str2t "Integral x * x D x"))
73 handle OPTION => str2t "no_rewrite";
75 val str = rewrit integral_pow (str2t "Integral x^^^3 D x"); term2s str;
78 "----------- test new_c, is_f_x ----------------------------------";
79 "----------- test new_c, is_f_x ----------------------------------";
80 "----------- test new_c, is_f_x ----------------------------------";
81 val term = str2t "x^^^2*c + c_2";
83 if term2s cc = "c_3" then () else raise error "integrate.sml: new_c ???";
85 val term = str2t "new_c (c * x^^^2 + c_2)";
86 val Some (_,t') = eval_new_c 0 0 term 0;
87 if term2s t' = "new_c c * x ^^^ 2 + c_2 = c_3" then ()
88 else raise error "integrate.sml: eval_new_c ???";
90 val t = str2t "matches (?u + new_c ?v) (x ^^^ 2 / 2)";
91 val Some (_,t') = eval_matches "" "Tools.matches" t thy; term2s t';
92 if term2s t' = "matches (?u + new_c ?v) (x ^^^ 2 / 2) = False" then ()
93 else raise error "integrate.sml: matches new_c = False";
95 val t = str2t "matches (?u + new_c ?v) (x ^^^ 2 / 2 + new_c x ^^^ 2 / 2)";
96 val Some (_,t') = eval_matches "" "Tools.matches" t thy; term2s t';
97 if term2s t'="matches (?u + new_c ?v) (x ^^^ 2 / 2 + new_c x ^^^ 2 / 2) = True"
98 then () else raise error "integrate.sml: matches new_c = True";
100 val t = str2t "M_b x is_f_x";
101 val Some (_,t') = eval_is_f_x "" "" t thy; term2s t';
102 if term2s t' = "(M_b x is_f_x) = True" then ()
103 else raise error "integrate.sml: eval_is_f_x --> true";
105 val t = str2t "q_0/2 * L * x is_f_x";
106 val Some (_,t') = eval_is_f_x "" "" t thy; term2s t';
107 if term2s t' = "(q_0 / 2 * L * x is_f_x) = False" then ()
108 else raise error "integrate.sml: eval_is_f_x --> false";
110 val conditions_in_integration =
111 Rls {id="conditions_in_integration",
113 rew_ord = ("termlessI",termlessI),
115 srls = Erls, calc = [],
116 rules = [Calc ("Tools.matches",eval_matches ""),
117 Calc ("Integrate.is'_f'_x",
118 eval_is_f_x "is_f_x_"),
119 Thm ("not_true",num_str not_true),
120 Thm ("not_false",num_str not_false)
124 fst (the (rewrite_inst_ Integrate.thy tless_true
125 conditions_in_integration true subs thm t));
126 val t = rewrit call_for_new_c (str2t "x ^^^ 2 / 2"); term2s t;
127 val t = (rewrit call_for_new_c t)
128 handle OPTION => str2t "no_rewrite";
130 val t = rewrit call_for_new_c
131 (str2t "M_b x = q_0/2 *L*x"); term2s t;
132 val t = (rewrit call_for_new_c
133 (str2t "M_b x = q_0 / 2 * L * x + new_c q_0 / 2 * L * x"))
134 handle OPTION => (*NOT: + new_c ..=..!!*)str2t "no_rewrite";
137 "----------- integrate by ruleset --------------------------------";
138 "----------- integrate by ruleset --------------------------------";
139 "----------- integrate by ruleset --------------------------------";
140 fun rewrit_sinst subs rls str =
141 fst (the (rewrite_set_inst "Integrate.thy" true subs rls str));
142 val subs = [("bdv","x::real")];
143 val rls = "integration_rules";
144 val str = rewrit_sinst subs rls "Integral x D x";
145 val str = rewrit_sinst subs rls "Integral c * x ^^^ 2 + c_2 D x";
146 if str = "c * (x ^^^ 3 / 3) + c_2 * x"
147 then () else raise error "integrate.sml: diff.behav. in integration_rules";
149 val rls = "add_new_c";
150 val str = rewrit_sinst subs rls "c * (x ^^^ 3 / 3) + c_2 * x";
151 if str = "c * (x ^^^ 3 / 3) + c_2 * x + c_3" then ()
152 else raise error "integrate.sml: diff.behav. in add_new_c simpl.";
154 val str = rewrit_sinst subs rls "F x = x ^^^ 3 / 3 + x";
155 if str = "F x = x ^^^ 3 / 3 + x + c"(*not "F x + c =..."*) then ()
156 else raise error "integrate.sml: diff.behav. in add_new_c equation";
158 val rls = "integration";
159 val str = rewrit_sinst subs rls "Integral c * x ^^^ 2 + c_2 D x";
160 if str = "c * (x ^^^ 3 / 3) + c_2 * x + c_3"
161 then () else raise error "integrate.sml: diff.behav. in integration";
164 "----------- check probem type -----------------------------------";
165 "----------- check probem type -----------------------------------";
166 "----------- check probem type -----------------------------------";
167 val model = {Given =["functionTerm f_", "integrateBy v_"],
169 Find =["antiDerivative F_"],
171 Relate=[]}:string ppc;
172 val chkmodel = ((map (the o (parse Integrate.thy))) o ppc2list) model;
173 val t1 = (term_of o hd) chkmodel;
174 val t2 = (term_of o hd o tl) chkmodel;
175 val t3 = (term_of o hd o tl o tl) chkmodel;
176 case t3 of Const ("Integrate.antiDerivative", _) $ _ => ()
177 | _ => raise error "integrate.sml: Integrate.antiDerivative ???";
179 val model = {Given =["functionTerm f_", "integrateBy v_"],
181 Find =["antiDerivativeName F_"],
183 Relate=[]}:string ppc;
184 val chkmodel = ((map (the o (parse Integrate.thy))) o ppc2list) model;
185 val t1 = (term_of o hd) chkmodel;
186 val t2 = (term_of o hd o tl) chkmodel;
187 val t3 = (term_of o hd o tl o tl) chkmodel;
188 case t3 of Const ("Integrate.antiDerivativeName", _) $ _ => ()
189 | _ => raise error "integrate.sml: Integrate.antiDerivativeName";
191 "----- compare 'Find's from problem, script, formalization -------";
192 val {ppc,...} = get_pbt ["named","integrate","function"];
193 val ("#Find", (Const ("Integrate.antiDerivativeName", _),
194 F1_ as Free ("F_", F1_type))) = last_elem ppc;
195 val {scr = Script sc,... } = get_met ["Diff","integration","named"];
196 val [_,_, F2_] = formal_args sc;
197 if F1_ = F2_ then () else raise error "integrate.sml: unequal find's";
199 val ((dsc as Const ("Integrate.antiDerivativeName", _))
200 $ Free ("M_b", F3_type)) = str2t "antiDerivativeName M_b";
201 if is_dsc dsc then () else raise error "integrate.sml: no description";
202 if F1_type = F3_type then ()
203 else raise error "integrate.sml: unequal types in find's";
206 val pbl = get_pbt ["integrate","function"];
207 case #cas pbl of Some (Const ("Integrate.Integrate",_) $ _) => ()
208 | _ => raise error "integrate.sml: Integrate.Integrate ???";
211 "----------- check Scripts ---------------------------------------";
212 "----------- check Scripts ---------------------------------------";
213 "----------- check Scripts ---------------------------------------";
215 "Script IntegrationScript (f_::real) (v_::real) = \
216 \ (let t_ = Take (Integral f_ D v_) \
217 \ in (Rewrite_Set_Inst [(bdv,v_)] integration False) (t_::real))";
218 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
222 "Script NamedIntegrationScript (f_::real) (v_::real) (F_::real=>real) = \
223 \ (let t_ = Take (F_ v_ = Integral f_ D v_) \
224 \ in (Rewrite_Set_Inst [(bdv,v_)] integration False) t_)";
225 val sc = ((inst_abs thy) o term_of o the o (parse thy)) str;
230 "----------- me method [Diff,integration] ---------------------";
231 "----------- me method [Diff,integration] ---------------------";
232 "----------- me method [Diff,integration] ---------------------";
233 val fmz = ["functionTerm (x^^^2 + 1)",
234 "integrateBy x","antiDerivative FF"];
236 ("Integrate.thy",["integrate","function"],
237 ["Diff","integration"]);
238 val p = e_pos'; val c = [];
239 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
240 val (p,_,f,nxt,_,pt) = me nxt p c pt;
241 val (p,_,f,nxt,_,pt) = me nxt p c pt;
242 val (p,_,f,nxt,_,pt) = me nxt p c pt;
243 val (p,_,f,nxt,_,pt) = me nxt p c pt;
244 val (p,_,f,nxt,_,pt) = me nxt p c pt;
245 val (p,_,f,nxt,_,pt) = me nxt p c pt;
246 val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Apply_Method*);
247 val (p,_,f,nxt,_,pt) = me nxt p c pt;
248 val (p,_,f,nxt,_,pt) = me nxt p c pt;
249 val (p,_,f,nxt,_,pt) = me nxt p c pt;
250 if f=Form' (FormKF (~1, EdUndef, 0, Nundef, "x ^^^ 3 / 3 + x + c")) then ()
251 else raise error "integrate.sml: method [Diff,integration]";
254 "----------- me method [Diff,integration,named] ------------------";
255 "----------- me method [Diff,integration,named] ------------------";
256 "----------- me method [Diff,integration,named] ------------------";
257 val fmz = ["functionTerm (x^^^2 + 1)",
258 "integrateBy x","antiDerivativeName F"];
260 ("Integrate.thy",["named","integrate","function"],
261 ["Diff","integration","named"]);
262 val p = e_pos'; val c = [];
263 val (p,_,f,nxt,_,pt) = CalcTreeTEST [(fmz, (dI',pI',mI'))];
264 val (p,_,f,nxt,_,pt) = me nxt p c pt;
265 val (p,_,f,nxt,_,pt) = me nxt p c pt;
266 val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Add_Find *);
267 val (p,_,f,nxt,_,pt) = me nxt p c pt;
268 val (p,_,f,nxt,_,pt) = me nxt p c pt;
269 val (p,_,f,nxt,_,pt) = me nxt p c pt;
270 val (p,_,f,nxt,_,pt) = me nxt p c pt(*nxt <- Apply_Method*);
271 val (p,_,f,nxt,_,pt) = me nxt p c pt;
272 val (p,_,f,nxt,_,pt) = me nxt p c pt;
273 val (p,_,f,nxt,_,pt) = me nxt p c pt;
274 val Form' (FormKF (~1, EdUndef, 0, Nundef, str)) = f;
275 if str = "F x = x ^^^ 3 / 3 + x + c" then()
276 else raise error "integrate.sml: method [Diff,integration,named]";
279 use"~/proto2/isac/src/smltest/IsacKnowledge/integrate.sml";