4 12345678901234567890123456789012345678901234567890123456789012345678901234567890
5 10 20 30 40 50 60 70 80
7 val e_cterm' = empty_cterm';
10 fun rew_info (Rls {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
11 (rew_ord':rew_ord',erls,ca)
12 | rew_info (Seq {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
14 | rew_info (Rrls {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
16 | rew_info rls = error ("rew_info called with '"^rls2str rls^"'");
18 (*FIXME.3.4.03:re-organize from_pblobj_or_detail_thm after rls' --> rls*)
19 fun from_pblobj_or_detail_thm thm' p pt =
21 val (pbl, p', rls') = par_pbl_det pt p
26 val thy' = get_obj g_domID pt p'
27 val {rew_ord', erls, ...} = get_met (get_obj g_metID pt p')
28 in ("OK", thy', rew_ord', erls, false) end
31 val thy' = get_obj g_domID pt (par_pblobj pt p)
32 val (rew_ord', erls, _) = rew_info rls'
33 in ("OK",thy',rew_ord',erls,false) end
35 (*FIXME.3.4.03:re-organize from_pblobj_or_detail_calc after rls' --> rls*)
36 fun from_pblobj_or_detail_calc scrop p pt =
38 val (pbl,p',rls') = par_pbl_det pt p
43 val thy' = get_obj g_domID pt p'
44 val {calc = scr_isa_fns,...} = get_met (get_obj g_metID pt p')
45 val opt = assoc (scr_isa_fns, scrop)
48 SOME isa_fn => ("OK",thy',isa_fn)
49 | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", e_evalfn))
53 val thy' = get_obj g_domID pt (par_pblobj pt p);
54 val (_,_,(*_,*)scr_isa_fns) = rew_info rls'(*rls*)
56 case assoc (scr_isa_fns, scrop) of
57 SOME isa_fn => ("OK",thy',isa_fn)
58 | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", e_evalfn))
62 val op_and = Const ("op &", [bool, bool] ---> bool);
63 (*> (Thm.global_cterm_of thy) (op_and $ Free("a",bool) $ Free("b",bool));
64 val it = "a & b" : cterm
66 fun mk_and a b = op_and $ a $ b;
67 (*> (Thm.global_cterm_of thy)
68 (mk_and (Free("a",bool)) (Free("b",bool)));
69 val it = "a & b" : cterm*)
71 fun mk_and [] = @{term True}
74 let fun mk t' (t::[]) = op_and $ t' $ t
75 | mk t' (t::ts) = mk (op_and $ t' $ t) ts
77 (*> val pred = map (Thm.term_of o the o (parse thy))
78 ["#0 <= #9 + #4 * x","#0 <= sqrt x + sqrt (#-3 + x)"];
79 > (Thm.global_cterm_of thy) (mk_and pred);
80 val it = "#0 <= #9 + #4 * x & #0 <= sqrt x + sqrt (#-3 + x)" : cterm*)
85 (*for Check_elementwise in applicable_in: [x=1,..] Assumptions -> (x,0<=x&..)*)
86 fun mk_set thy pt p (Const ("List.list.Nil",_)) pred = (e_term, [])
88 | mk_set thy pt p (Const ("Tools.UniversalList",_)) pred =
89 (e_term, if pred <> Const ("Script.Assumptions",bool)
91 else get_assumptions_ pt (p,Res))
93 (* val pred = (Thm.term_of o the o (parse thy)) pred;
94 val consts as Const ("List.list.Cons",_) $ eq $ _ = ft;
95 mk_set thy pt p consts pred;
97 | mk_set thy pt p (consts as Const ("List.list.Cons",_) $ eq $ _) pred =
98 let val (bdv,_) = HOLogic.dest_eq eq;
99 val pred = if pred <> Const ("Script.Assumptions",bool)
101 else get_assumptions_ pt (p,Res)
104 | mk_set thy _ _ l _ =
105 error ("check_elementwise: no set " ^ term2str l);
106 (*> val consts = str2term "[x=#4]";
107 > val pred = str2term "Assumptions";
108 > val pt = union_asm pt p
109 [("#0 <= sqrt x + sqrt (#5 + x)",[11]),("#0 <= #9 + #4 * x",[22]),
110 ("#0 <= x ^^^ #2 + #5 * x",[33]),("#0 <= #2 + x",[44])];
112 > val (sss,ttt) = mk_set thy pt p consts pred;
113 > (term2str sss, term2str ttt);
114 val it = ("x","((#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x) & ...
116 val consts = str2term "UniversalList";
117 val pred = str2term "Assumptions";
123 (*check a list (/set) of constants [c_1,..,c_n] for c_i:set (: in)*)
124 (* val (erls,consts,(bdv,pred)) = (erl,ft,vp);
125 val (consts,(bdv,pred)) = (ft,vp);
127 fun check_elementwise thy erls all_results (bdv, asm) =
128 let (*bdv extracted from ~~~~~~~~~~~ in mk_set already*)
130 let val inst_ = map (subst_atomic [sub]) asm
131 in case eval__true thy 1 inst_ [] erls of
132 (asm', true) => ([HOLogic.mk_eq sub], asm')
133 | (_, false) => ([],[])
135 (*val _= tracing("### check_elementwise: res= "^(term2str all_results)^
136 ", bdv= "^(term2str bdv)^", asm= "^(terms2str asm));*)
137 val c' = isalist2list all_results
138 val c'' = map (snd o HOLogic.dest_eq) c' (*assumes [x=1,x=2,..]*)
139 val subs = map (pair bdv) c''
140 in if asm = [] then (all_results, [])
141 else ((apfst ((list2isalist bool) o flat)) o
142 (apsnd flat) o split_list o (map check)) subs end;
144 > val all_results = str2term "[x=a+b,x=b,x=3]";
145 > val bdv = str2term "x";
146 > val asm = str2term "(x ~= a) & (x ~= b)";
148 > val (t, ts) = check_elementwise thy erls all_results (bdv, asm);
149 > term2str t; tracing(terms2str ts);
150 val it = "[x = a + b, x = b, x = c]" : string
151 ["a + b ~= a & a + b ~= b","b ~= a & b ~= b","c ~= a & c ~= b"]
152 ... with appropriate erls this should be:
153 val it = "[x = a + b, x = c]" : string
154 ["b ~= 0 & a ~= 0", "3 ~= a & 3 ~= b"]
155 ////// because b ~= b False*)
160 > val ct = "((#0 <= #18 & #0 <= sqrt (#5 + #3) + sqrt (#5 - #3)) &\
161 \ #0 <= #25 + #-1 * #3 ^^^ #2) & #0 <= #4";
162 > val SOME(ct',_) = rewrite_set "Isac" false "eval_rls" ct;
163 val ct' = "HOL.True" : cterm'
165 > val ct = "((#0 <= #18 & #0 <= sqrt (#5 + #-3) + sqrt (#5 - #-3)) &\
166 \ #0 <= #25 + #-1 * #-3 ^^^ #2) & #0 <= #4";
167 > val SOME(ct',_) = rewrite_set "Isac" false "eval_rls" ct;
168 val ct' = "HOL.True" : cterm'
171 > val const = (Thm.term_of o the o (parse thy)) "(#3::real)";
172 > val pred' = subst_atomic [(bdv,const)] pred;
175 > val consts = (Thm.term_of o the o (parse thy)) "[x = #-3, x = #3]";
176 > val bdv = (Thm.term_of o the o (parse thy)) "(x::real)";
177 > val pred = (Thm.term_of o the o (parse thy))
178 "((#0 <= #18 & #0 <= sqrt (#5 + x) + sqrt (#5 - x)) & #0 <= #25 + #-1 * x ^^^ #2) & #0 <= #4";
179 > val ttt = check_elementwise thy consts (bdv, pred);
180 > (Thm.global_cterm_of thy) ttt;
181 val it = "[x = #-3, x = #3]" : cterm
183 > val consts = (Thm.term_of o the o (parse thy)) "[x = #4]";
184 > val bdv = (Thm.term_of o the o (parse thy)) "(x::real)";
185 > val pred = (Thm.term_of o the o (parse thy))
186 "#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x & #0 <= x ^^^ #2 + #5 * x & #0 <= #2 + x";
187 > val ttt = check_elementwise thy consts (bdv,pred);
188 > (Thm.global_cterm_of thy) ttt;
189 val it = "[x = #4]" : cterm
191 > val consts = (Thm.term_of o the o (parse thy)) "[x = #-12 // #5]";
192 > val bdv = (Thm.term_of o the o (parse thy)) "(x::real)";
193 > val pred = (Thm.term_of o the o (parse thy))
194 " #0 <= sqrt x + sqrt (#-3 + x) & #0 <= #9 + #4 * x & #0 <= x ^^^ #2 + #-3 * x & #0 <= #6 + x";
195 > val ttt = check_elementwise thy consts (bdv,pred);
196 > (Thm.global_cterm_of thy) ttt;
197 val it = "[]" : cterm*)
200 (* 14.1.01: for Tac-dummies in root-equ only: skip str until "("*)
201 fun split_dummy str =
202 let fun scan s' [] = (implode s', "")
203 | scan s' (s::ss) = if s=" " then (implode s', implode ss)
204 else scan (s'@[s]) ss;
205 in ((scan []) o Symbol.explode) str end;
206 (* split_dummy "subproblem_equation_dummy (x=-#5//#12)";
207 val it = ("subproblem_equation_dummy","(x=-#5//#12)") : string * string
208 > split_dummy "x=-#5//#12";
209 val it = ("x=-#5//#12","") : string * string*)
214 (*.applicability of a tacic wrt. a calc-state (ptree,pos').
215 additionally used by next_tac in the script-interpreter for script-tacs.
216 tests for applicability are so expensive, that results (rewrites!)
217 are kept in the return-value of 'type tac_'.
219 fun applicable_in (_:pos') _ (Init_Proof (ct', spec)) = Chead.Appl (Init_Proof' (ct', spec))
221 | applicable_in (p,p_) pt Model_Problem =
222 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
223 then Chead.Notappl ((tac2str Model_Problem) ^ " not for pos " ^ (pos'2str (p,p_)))
226 val (PblObj{origin=(_,(_,pI',_),_),...}) = get_obj I pt p
227 val {ppc,...} = get_pbt pI'
228 val pbl = Ctree.init_pbl ppc
229 in Chead.Appl (Model_Problem' (pI', pbl, [])) end
231 | applicable_in (p,p_) pt (Refine_Tacitly pI) =
232 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
233 then Chead.Notappl ((tac2str (Refine_Tacitly pI)) ^ " not for pos " ^ (pos'2str (p,p_)))
236 val (PblObj {origin = (oris, (dI',_,_),_), ...}) = get_obj I pt p;
237 val opt = refine_ori oris pI;
240 Chead.Appl (Refine_Tacitly' (pI, pblID,
241 e_domID, e_metID, [](*filled in specify*)))
242 | NONE => Chead.Notappl ((tac2str (Refine_Tacitly pI)) ^ " not applicable")
245 | applicable_in (p,p_) pt (Refine_Problem pI) =
246 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
247 then Chead.Notappl ((tac2str (Refine_Problem pI))^
248 " not for pos "^(pos'2str (p,p_)))
250 let val (PblObj {origin=(_,(dI,_,_),_),spec=(dI',_,_),
251 probl=itms, ...}) = get_obj I pt p;
252 val thy = if dI' = e_domID then dI else dI';
253 val rfopt = refine_pbl (assoc_thy thy) pI itms;
255 NONE => Chead.Notappl ((tac2str (Refine_Problem pI))^" not applicable")
256 | SOME (rf as (pI',_)) =>
257 (* val SOME (rf as (pI',_)) = rfopt;
260 then Chead.Notappl ((tac2str (Refine_Problem pI))^" not applicable")
261 else Chead.Appl (Refine_Problem' rf)
264 (*the specify-tacs have cterm' instead term:
265 parse+error here!!!: see appl_add*)
266 | applicable_in (p,p_) pt (Add_Given ct') =
267 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
268 then Chead.Notappl ((tac2str (Add_Given ct'))^
269 " not for pos "^(pos'2str (p,p_)))
270 else Chead.Appl (Add_Given' (ct', [(*filled in specify_additem*)]))
271 (*Add_.. should reject (dsc //) (see fmz=[] in sqrt*)
273 | applicable_in (p,p_) pt (Del_Given ct') =
274 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
275 then Chead.Notappl ((tac2str (Del_Given ct'))^
276 " not for pos "^(pos'2str (p,p_)))
277 else Chead.Appl (Del_Given' ct')
279 | applicable_in (p,p_) pt (Add_Find ct') =
280 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
281 then Chead.Notappl ((tac2str (Add_Find ct'))^
282 " not for pos "^(pos'2str (p,p_)))
283 else Chead.Appl (Add_Find' (ct', [(*filled in specify_additem*)]))
285 | applicable_in (p,p_) pt (Del_Find ct') =
286 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
287 then Chead.Notappl ((tac2str (Del_Find ct'))^
288 " not for pos "^(pos'2str (p,p_)))
289 else Chead.Appl (Del_Find' ct')
291 | applicable_in (p,p_) pt (Add_Relation ct') =
292 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
293 then Chead.Notappl ((tac2str (Add_Relation ct'))^
294 " not for pos "^(pos'2str (p,p_)))
295 else Chead.Appl (Add_Relation' (ct', [(*filled in specify_additem*)]))
297 | applicable_in (p,p_) pt (Del_Relation ct') =
298 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
299 then Chead.Notappl ((tac2str (Del_Relation ct'))^
300 " not for pos "^(pos'2str (p,p_)))
301 else Chead.Appl (Del_Relation' ct')
303 | applicable_in (p,p_) pt (Specify_Theory dI) =
304 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
305 then Chead.Notappl ((tac2str (Specify_Theory dI))^
306 " not for pos "^(pos'2str (p,p_)))
307 else Chead.Appl (Specify_Theory' dI)
308 (* val (p,p_) = p; val Specify_Problem pID = m;
309 val Specify_Problem pID = m;
311 | applicable_in (p,p_) pt (Specify_Problem pID) =
312 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
313 then Chead.Notappl ((tac2str (Specify_Problem pID))^
314 " not for pos "^(pos'2str (p,p_)))
316 let val (PblObj {origin=(oris,(dI,pI,_),_),spec=(dI',pI',_),
317 probl=itms, ...}) = get_obj I pt p;
318 val thy = assoc_thy (if dI' = e_domID then dI else dI');
319 val {ppc,where_,prls,...} = get_pbt pID;
320 val pbl = if pI'=e_pblID andalso pI=e_pblID
321 then (false, (Ctree.init_pbl ppc, []))
322 else match_itms_oris thy itms (ppc,where_,prls) oris;
323 in Chead.Appl (Specify_Problem' (pID, pbl)) end
324 (* val Specify_Method mID = nxt; val (p,p_) = p;
326 | applicable_in (p,p_) pt (Specify_Method mID) =
327 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
328 then Chead.Notappl ((tac2str (Specify_Method mID))^
329 " not for pos "^(pos'2str (p,p_)))
330 else Chead.Appl (Specify_Method' (mID,[(*filled in specify*)],
331 [(*filled in specify*)]))
333 | applicable_in (p,p_) pt (Apply_Method mI) =
334 if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
335 then Chead.Notappl ((tac2str (Apply_Method mI)) ^ " not for pos " ^ (pos'2str (p,p_)))
338 val (PblObj{origin = (_, (dI, pI, _), _), probl, ctxt, ...}) = get_obj I pt p;
339 val {where_, ...} = get_pbt pI
340 val pres = map (mk_env probl |> subst_atomic) where_
343 then assoc_thy dI |> Proof_Context.init_global |> insert_assumptions pres
345 (*TODO.WN110416 here do evalprecond according to fun check_preconds'
346 and then decide on Chead.Notappl/Appl accordingly once more.
347 Implement after all tests are running, since this changes
348 overall system behavior*)
349 in Chead.Appl (Apply_Method' (mI, NONE, e_istate (*filled in solve*), ctxt)) end
351 | applicable_in (p,p_) pt (Check_Postcond pI) =
352 if member op = [Pbl,Met] p_
353 then Chead.Notappl ((tac2str (Check_Postcond pI)) ^ " not for pos "^(pos'2str (p,p_)))
354 else Chead.Appl (Check_Postcond' (pI, (e_term, [(*fun solve assignes the returnvalue of scr*)])))
356 (*these are always applicable*)
357 | applicable_in (p,p_) _ (Take str) = Chead.Appl (Take' (str2term str))
358 | applicable_in (p,p_) _ (Free_Solve) = Chead.Appl (Free_Solve')
360 | applicable_in (p, p_) pt (m as Rewrite_Inst (subs, thm'')) =
361 if member op = [Pbl, Met] p_
362 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
365 val pp = par_pblobj pt p;
366 val thy' = (get_obj g_domID pt pp): theory';
367 val thy = assoc_thy thy';
368 val {rew_ord' = ro', erls = erls, ...} = get_met (get_obj g_metID pt pp);
369 val (f, p) = case p_ of (*p 12.4.00 unnecessary*)
370 Frm => (get_obj g_form pt p, p)
371 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
372 | _ => error ("applicable_in: call by " ^ pos'2str (p,p_));
375 val subst = subs2subst thy subs;
376 val subs' = subst2subs' subst;
377 in case rewrite_inst_ thy (assoc_rew_ord ro') erls false subst (snd thm'') f of
379 Chead.Appl (Rewrite_Inst' (thy', ro', erls, false, subst, thm'', f, (f', asm)))
380 | NONE => Chead.Notappl ((fst thm'')^" not applicable")
382 handle _ => Chead.Notappl ("syntax error in "^(subs2str subs))
385 | applicable_in (p,p_) pt (m as Rewrite thm'') =
386 if member op = [Pbl,Met] p_
387 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
389 let val (msg,thy',ro,rls',(*put_asm*)_)= from_pblobj_or_detail_thm thm'' p pt;
390 val thy = assoc_thy thy';
392 Frm => get_obj g_form pt p
393 | Res => (fst o (get_obj g_result pt)) p
394 | _ => error ("applicable_in Rewrite: call by "^
398 case rewrite_ thy (assoc_rew_ord ro) rls' false (snd thm'') f of
399 SOME (f',asm) => Chead.Appl (Rewrite' (thy', ro, rls', false, thm'', f, (f', asm)))
400 | NONE => Chead.Notappl ("'" ^ fst thm'' ^"' not applicable")
401 else Chead.Notappl msg
404 | applicable_in (p,p_) pt (m as Rewrite_Asm thm'') =
405 if member op = [Pbl,Met] p_
406 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
409 val pp = par_pblobj pt p;
410 val thy' = (get_obj g_domID pt pp):theory';
411 val thy = assoc_thy thy';
412 val {rew_ord'=ro',erls=erls,...} =
413 get_met (get_obj g_metID pt pp);
414 (*val put_asm = true;*)
415 val (f, _) = case p_ of
416 Frm => (get_obj g_form pt p, p)
417 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
418 | _ => error ("applicable_in: call by "^
420 in case rewrite_ thy (assoc_rew_ord ro') erls false (snd thm'') f of
421 SOME (f',asm) => Chead.Appl (
422 Rewrite' (thy', ro', erls, false, thm'', f, (f', asm)))
423 | NONE => Chead.Notappl ("'" ^ fst thm'' ^ "' not applicable") end
425 | applicable_in (p,p_) pt (m as Detail_Set_Inst (subs, rls)) =
426 if member op = [Pbl,Met] p_
427 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
430 val pp = par_pblobj pt p;
431 val thy' = (get_obj g_domID pt pp):theory';
432 val thy = assoc_thy thy';
433 val {rew_ord'=ro',...} = get_met (get_obj g_metID pt pp);
434 val f = case p_ of Frm => get_obj g_form pt p
435 | Res => (fst o (get_obj g_result pt)) p
436 | _ => error ("applicable_in: call by "^
439 let val subst = subs2subst thy subs
440 val subs' = subst2subs' subst
441 in case rewrite_set_inst_ thy false subst (assoc_rls rls) f of
442 SOME (f',asm) => Chead.Appl (
443 Detail_Set_Inst' (thy',false,subst,assoc_rls rls, f, (f', asm)))
444 | NONE => Chead.Notappl (rls^" not applicable") end
445 handle _ => Chead.Notappl ("syntax error in "^(subs2str subs)) end
447 | applicable_in (p,p_) pt (m as Rewrite_Set_Inst (subs, rls)) =
448 if member op = [Pbl,Met] p_
449 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
452 val pp = par_pblobj pt p;
453 val thy' = (get_obj g_domID pt pp):theory';
454 val thy = assoc_thy thy';
455 val {rew_ord'=ro',(*asm_rls=asm_rls,*)...} =
456 get_met (get_obj g_metID pt pp);
457 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
458 Frm => (get_obj g_form pt p, p)
459 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
460 | _ => error ("applicable_in: call by "^
463 let val subst = subs2subst thy subs;
464 val subs' = subst2subs' subst;
465 in case rewrite_set_inst_ thy (*put_asm*)false subst (assoc_rls rls) f of
466 SOME (f',asm) => Chead.Appl (
467 Rewrite_Set_Inst' (thy',(*put_asm*)false,subst,assoc_rls rls, f, (f', asm)))
468 | NONE => Chead.Notappl (rls^" not applicable") end
469 handle _ => Chead.Notappl ("syntax error in "^(subs2str subs)) end
471 | applicable_in (p,p_) pt (m as Rewrite_Set rls) =
472 if member op = [Pbl,Met] p_
473 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
476 val pp = par_pblobj pt p;
477 val thy' = (get_obj g_domID pt pp):theory';
478 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
479 Frm => (get_obj g_form pt p, p)
480 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
481 | _ => error ("applicable_in: call by "^
483 in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
485 ((*tracing("#.# applicable_in Rewrite_Set,2f'= "^f');*)
486 Chead.Appl (Rewrite_Set' (thy',(*put_asm*)false,assoc_rls rls, f, (f', asm)))
488 | NONE => Chead.Notappl (rls^" not applicable") end
490 | applicable_in (p,p_) pt (m as Detail_Set rls) =
491 if member op = [Pbl,Met] p_
492 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
494 let val pp = par_pblobj pt p
495 val thy' = (get_obj g_domID pt pp):theory'
497 Frm => get_obj g_form pt p
498 | Res => (fst o (get_obj g_result pt)) p
499 | _ => error ("applicable_in: call by "^
501 in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
503 Chead.Appl (Detail_Set' (thy',false,assoc_rls rls, f, (f',asm)))
504 | NONE => Chead.Notappl (rls^" not applicable") end
507 | applicable_in p pt (End_Ruleset) =
508 error ("applicable_in: not impl. for "^
509 (tac2str End_Ruleset))
511 (* val ((p,p_), pt, (m as Calculate op_)) = (p, pt, m);
513 | applicable_in (p,p_) pt (m as Calculate op_) =
514 if member op = [Pbl,Met] p_
515 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
518 val (msg,thy',isa_fn) = from_pblobj_or_detail_calc op_ p pt;
520 Frm => get_obj g_form pt p
521 | Res => (fst o (get_obj g_result pt)) p
522 in if msg = "OK" then
523 case calculate_ (assoc_thy thy') isa_fn f of
524 SOME (f', (id, thm)) =>
525 Chead.Appl (Calculate' (thy',op_, f, (f', (id, string_of_thmI thm))))
526 | NONE => Chead.Notappl ("'calculate "^op_^"' not applicable")
527 else Chead.Notappl msg
530 (*Substitute combines two different kind of "substitution":
531 (1) subst_atomic: for ?a..?z
532 (2) Pattern.match: for solving equational systems
533 (which raises exn for ?a..?z)*)
534 | applicable_in (p,p_) pt (m as Substitute sube) =
535 if member op = [Pbl,Met] p_
536 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
539 val pp = par_pblobj pt p
540 val thy = assoc_thy (get_obj g_domID pt pp)
542 Frm => get_obj g_form pt p
543 | Res => (fst o (get_obj g_result pt)) p
544 val {rew_ord',erls,...} = get_met (get_obj g_metID pt pp)
545 val subte = sube2subte sube
546 val subst = sube2subst thy sube
547 val ro = assoc_rew_ord rew_ord'
549 if foldl and_ (true, map contains_Var subte)
552 let val f' = subst_atomic subst f
553 in if f = f' then Chead.Notappl (sube2str sube^" not applicable")
554 else Chead.Appl (Substitute' (ro, erls, subte, f, f'))
558 case rewrite_terms_ thy ro erls subte f of
559 SOME (f', _) => Chead.Appl (Substitute' (ro, erls, subte, f, f'))
560 | NONE => Chead.Notappl (sube2str sube^" not applicable")
563 | applicable_in p pt (Apply_Assumption cts') =
564 (error ("applicable_in: not impl. for " ^ (tac2str (Apply_Assumption cts'))))
566 (*'logical' applicability wrt. script in locate: Inconsistent?*)
567 | applicable_in (p,p_) pt (m as Take ct') =
568 if member op = [Pbl,Met] p_
569 then Chead.Notappl (tac2str m ^ " not for pos " ^ pos'2str (p,p_))
571 let val thy' = get_obj g_domID pt (par_pblobj pt p);
572 in (case parseNEW (assoc_thy thy' |> thy2ctxt) ct' of
573 SOME ct => Chead.Appl (Take' ct)
574 | NONE => Chead.Notappl ("syntax error in " ^ ct'))
577 | applicable_in p pt (Take_Inst ct') =
578 error ("applicable_in: not impl. for " ^ tac2str (Take_Inst ct'))
579 | applicable_in p pt (Group (con, ints)) =
580 error ("applicable_in: not impl. for " ^ tac2str (Group (con, ints)))
582 | applicable_in (p,p_) pt (m as Subproblem (domID, pblID)) =
583 if member op = [Pbl,Met] p_
584 then (*maybe Apply_Method has already been done FIXME.WN150511: declare_constraints*)
585 case get_obj g_env pt p of
587 Chead.Appl (Subproblem' ((domID, pblID, e_metID), [],
588 e_term, [], e_ctxt(*FIXME.WN150511*), subpbl domID pblID))
589 | NONE => Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
590 else (*somewhere later in the script*)
591 Chead.Appl (Subproblem' ((domID, pblID, e_metID), [],
592 e_term, [], e_ctxt, subpbl domID pblID))
594 | applicable_in p pt (End_Subproblem) =
595 error ("applicable_in: not impl. for " ^ tac2str End_Subproblem)
596 | applicable_in p pt (CAScmd ct') =
597 error ("applicable_in: not impl. for " ^ tac2str (CAScmd ct'))
598 | applicable_in p pt (Split_And) =
599 error ("applicable_in: not impl. for " ^ tac2str Split_And)
600 | applicable_in p pt (Conclude_And) =
601 error ("applicable_in: not impl. for " ^ tac2str Conclude_And)
602 | applicable_in p pt (Split_Or) =
603 error ("applicable_in: not impl. for " ^ tac2str Split_Or)
604 | applicable_in p pt (Conclude_Or) =
605 error ("applicable_in: not impl. for " ^ tac2str Conclude_Or)
607 | applicable_in (p,p_) pt (Begin_Trans) =
609 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
610 (*_____ implizit Take in gen*)
611 Frm => (get_obj g_form pt p, (lev_on o lev_dn) p)
612 | Res => ((fst o (get_obj g_result pt)) p, (lev_on o lev_dn o lev_on) p)
613 | _ => error ("applicable_in: call by "^
615 val thy' = get_obj g_domID pt (par_pblobj pt p);
616 in (Chead.Appl (Begin_Trans' f))
617 handle _ => error ("applicable_in: Begin_Trans finds \
618 \syntaxerror in '"^(term2str f)^"'") end
620 (*TODO: check parent branches*)
621 | applicable_in (p,p_) pt (End_Trans) =
622 let val thy' = get_obj g_domID pt (par_pblobj pt p);
624 then Chead.Appl (End_Trans' (get_obj g_result pt p))
625 else Chead.Notappl "'End_Trans' is not applicable at the beginning of a transitive sequence"
626 (*TODO: check parent branches*)
628 | applicable_in p pt (Begin_Sequ) =
629 error ("applicable_in: not impl. for " ^ tac2str (Begin_Sequ))
630 | applicable_in p pt (End_Sequ) =
631 error ("applicable_in: not impl. for " ^ tac2str (End_Sequ))
632 | applicable_in p pt (Split_Intersect) =
633 error ("applicable_in: not impl. for " ^ tac2str (Split_Intersect))
634 | applicable_in p pt (End_Intersect) =
635 error ("applicable_in: not impl. for " ^ tac2str (End_Intersect))
637 | applicable_in (p,p_) pt (m as Check_elementwise pred) =
638 if member op = [Pbl,Met] p_
639 then Chead.Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
642 val pp = par_pblobj pt p;
643 val thy' = (get_obj g_domID pt pp):theory';
644 val thy = assoc_thy thy'
645 val metID = (get_obj g_metID pt pp)
646 val {crls,...} = get_met metID
647 val (f,asm) = case p_ of Frm => (get_obj g_form pt p , [])
648 | Res => get_obj g_result pt p;
649 val vp = (thy2ctxt thy, pred) |-> parseNEW |> the |> mk_set thy pt p f;
651 Const ("List.list.Cons",_) $ _ $ _ =>
652 Chead.Appl (Check_elementwise' (f, pred, check_elementwise thy crls f vp))
653 | Const ("Tools.UniversalList",_) =>
654 Chead.Appl (Check_elementwise' (f, pred, (f,asm)))
655 | Const ("List.list.Nil",_) =>
656 Chead.Appl (Check_elementwise' (f, pred, (f, asm)))
657 | _ => Chead.Notappl ("Check_elementwise not applicable: "^(term2str f)^" should be constants")
660 | applicable_in (p,p_) pt Or_to_List =
661 if member op = [Pbl,Met] p_
662 then Chead.Notappl ((tac2str Or_to_List)^" not for pos "^(pos'2str (p,p_)))
665 val pp = par_pblobj pt p;
666 val thy' = (get_obj g_domID pt pp):theory';
667 val thy = assoc_thy thy';
669 Frm => get_obj g_form pt p
670 | Res => (fst o (get_obj g_result pt)) p;
671 in (let val ls = or2list f
672 in Chead.Appl (Or_to_List' (f, ls)) end)
673 handle _ => Chead.Notappl ("'Or_to_List' not applicable to "^(term2str f))
676 | applicable_in p pt (Collect_Trues) =
677 error ("applicable_in: not impl. for "^
678 (tac2str (Collect_Trues)))
680 | applicable_in p pt (Empty_Tac) =
681 Chead.Notappl "Empty_Tac is not applicable"
683 | applicable_in (p,p_) pt (Tac id) =
685 val pp = par_pblobj pt p;
686 val thy' = (get_obj g_domID pt pp):theory';
687 val thy = assoc_thy thy';
689 Frm => get_obj g_form pt p
690 | Pbl => error "applicable_in (p,Pbl) pt (Tac id): not at Pbl"
691 | Res => (fst o (get_obj g_result pt)) p;
693 "subproblem_equation_dummy" =>
695 then Chead.Appl (Tac_ (thy, term2str f, id,
696 "subproblem_equation_dummy ("^(term2str f)^")"))
697 else Chead.Notappl "applicable only to equations made explicit"
698 | "solve_equation_dummy" =>
699 let (*val _= tracing("### applicable_in: solve_equation_dummy: f= "
701 val (id',f') = split_dummy (term2str f);
702 (*val _= tracing("### applicable_in: f'= "^f');*)
703 (*val _= (Thm.term_of o the o (parse thy)) f';*)
704 (*val _= tracing"### applicable_in: solve_equation_dummy";*)
705 in if id' <> "subproblem_equation_dummy" then Chead.Notappl "no subproblem"
706 else if (thy2ctxt thy, f') |-> parseNEW |> the |> is_expliceq
707 then Chead.Appl (Tac_ (thy, term2str f, id, "[" ^ f' ^ "]"))
708 else error ("applicable_in: f= " ^ f') end
709 | _ => Chead.Appl (Tac_ (thy, term2str f, id, term2str f)) end
711 | applicable_in p pt End_Proof' = Chead.Appl End_Proof''
713 | applicable_in _ _ m =
714 error ("applicable_in called for "^(tac2str m));
717 fun tac2tac_ pt p m =
718 case applicable_in p pt m of
719 Chead.Appl (m') => m'
720 | Chead.Notappl _ => error ("tac2mstp': fails with"^