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, ...} = et_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 (*> (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;
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 (term_of o the o (parse thy))
78 ["#0 <= #9 + #4 * x","#0 <= sqrt x + sqrt (#-3 + x)"];
79 > (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 = (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 = (term_of o the o (parse thy)) "(#3::real)";
172 > val pred' = subst_atomic [(bdv,const)] pred;
175 > val consts = (term_of o the o (parse thy)) "[x = #-3, x = #3]";
176 > val bdv = (term_of o the o (parse thy)) "(x::real)";
177 > val pred = (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 > (cterm_of thy) ttt;
181 val it = "[x = #-3, x = #3]" : cterm
183 > val consts = (term_of o the o (parse thy)) "[x = #4]";
184 > val bdv = (term_of o the o (parse thy)) "(x::real)";
185 > val pred = (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 > (cterm_of thy) ttt;
189 val it = "[x = #4]" : cterm
191 > val consts = (term_of o the o (parse thy)) "[x = #-12 // #5]";
192 > val bdv = (term_of o the o (parse thy)) "(x::real)";
193 > val pred = (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 > (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)) = 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 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 = init_pbl ppc
229 in 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 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 Appl (Refine_Tacitly' (pI, pblID,
241 e_domID, e_metID, [](*filled in specify*)))
242 | NONE => 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 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 => Notappl ((tac2str (Refine_Problem pI))^" not applicable")
256 | SOME (rf as (pI',_)) =>
257 (* val SOME (rf as (pI',_)) = rfopt;
260 then Notappl ((tac2str (Refine_Problem pI))^" not applicable")
261 else 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 Notappl ((tac2str (Add_Given ct'))^
269 " not for pos "^(pos'2str (p,p_)))
270 else 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 Notappl ((tac2str (Del_Given ct'))^
276 " not for pos "^(pos'2str (p,p_)))
277 else 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 Notappl ((tac2str (Add_Find ct'))^
282 " not for pos "^(pos'2str (p,p_)))
283 else 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 Notappl ((tac2str (Del_Find ct'))^
288 " not for pos "^(pos'2str (p,p_)))
289 else 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 Notappl ((tac2str (Add_Relation ct'))^
294 " not for pos "^(pos'2str (p,p_)))
295 else 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 Notappl ((tac2str (Del_Relation ct'))^
300 " not for pos "^(pos'2str (p,p_)))
301 else 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 Notappl ((tac2str (Specify_Theory dI))^
306 " not for pos "^(pos'2str (p,p_)))
307 else 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 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, (init_pbl ppc, []))
322 else match_itms_oris thy itms (ppc,where_,prls) oris;
323 in 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 Notappl ((tac2str (Specify_Method mID))^
329 " not for pos "^(pos'2str (p,p_)))
330 else 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 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 Notappl/Appl accordingly once more.
347 Implement after all tests are running, since this changes
348 overall system behavior*)
349 in 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 Notappl ((tac2str (Check_Postcond pI)) ^ " not for pos "^(pos'2str (p,p_)))
354 else 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) = Appl (Take' (str2term str))
358 | applicable_in (p,p_) _ (Free_Solve) = Appl (Free_Solve')
360 | applicable_in (p, p_) pt (m as Rewrite_Inst (subs, thm')) =
361 if member op = [Pbl, Met] p_
362 then 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 (assoc_thm' thy thm') f of
379 Appl (Rewrite_Inst' (thy', ro', erls, false, subst, thm', f, (f', asm)))
380 | NONE => Notappl ((fst thm')^" not applicable")
382 handle _ => 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 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 ((*tracing("### applicable_in rls'= "^rls');*)
399 (* val SOME (f',asm)=rewrite thy' ro (id_rls rls') put_asm thm' f;
401 case rewrite_ thy (assoc_rew_ord ro)
402 rls' false (assoc_thm' thy thm') f of
403 SOME (f',asm) => Appl (
404 Rewrite' (thy',ro,rls',(*put_asm*)false,thm', f, (f', asm)))
405 | NONE => Notappl ("'"^(fst thm')^"' not applicable") )
409 | applicable_in (p,p_) pt (m as Rewrite_Asm thm') =
410 if member op = [Pbl,Met] p_
411 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
414 val pp = par_pblobj pt p;
415 val thy' = (get_obj g_domID pt pp):theory';
416 val thy = assoc_thy thy';
417 val {rew_ord'=ro',erls=erls,...} =
418 get_met (get_obj g_metID pt pp);
419 (*val put_asm = true;*)
420 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
421 Frm => (get_obj g_form pt p, p)
422 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
423 | _ => error ("applicable_in: call by "^
425 in case rewrite_ thy (assoc_rew_ord ro') erls
426 (*put_asm*)false (assoc_thm' thy thm') f of
427 SOME (f',asm) => Appl (
428 Rewrite' (thy',ro',erls,(*put_asm*)false,thm', f, (f', asm)))
429 | NONE => Notappl ("'"^(fst thm')^"' not applicable") end
431 | applicable_in (p,p_) pt (m as Detail_Set_Inst (subs, rls)) =
432 if member op = [Pbl,Met] p_
433 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
436 val pp = par_pblobj pt p;
437 val thy' = (get_obj g_domID pt pp):theory';
438 val thy = assoc_thy thy';
439 val {rew_ord'=ro',...} = get_met (get_obj g_metID pt pp);
440 val f = case p_ of Frm => get_obj g_form pt p
441 | Res => (fst o (get_obj g_result pt)) p
442 | _ => error ("applicable_in: call by "^
445 let val subst = subs2subst thy subs
446 val subs' = subst2subs' subst
447 in case rewrite_set_inst_ thy false subst (assoc_rls rls) f of
448 SOME (f',asm) => Appl (
449 Detail_Set_Inst' (thy',false,subst,assoc_rls rls, f, (f', asm)))
450 | NONE => Notappl (rls^" not applicable") end
451 handle _ => Notappl ("syntax error in "^(subs2str subs)) end
453 | applicable_in (p,p_) pt (m as Rewrite_Set_Inst (subs, rls)) =
454 if member op = [Pbl,Met] p_
455 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
458 val pp = par_pblobj pt p;
459 val thy' = (get_obj g_domID pt pp):theory';
460 val thy = assoc_thy thy';
461 val {rew_ord'=ro',(*asm_rls=asm_rls,*)...} =
462 get_met (get_obj g_metID pt pp);
463 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
464 Frm => (get_obj g_form pt p, p)
465 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
466 | _ => error ("applicable_in: call by "^
469 let val subst = subs2subst thy subs;
470 val subs' = subst2subs' subst;
471 in case rewrite_set_inst_ thy (*put_asm*)false subst (assoc_rls rls) f of
472 SOME (f',asm) => Appl (
473 Rewrite_Set_Inst' (thy',(*put_asm*)false,subst,assoc_rls rls, f, (f', asm)))
474 | NONE => Notappl (rls^" not applicable") end
475 handle _ => Notappl ("syntax error in "^(subs2str subs)) end
477 | applicable_in (p,p_) pt (m as Rewrite_Set rls) =
478 if member op = [Pbl,Met] p_
479 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
482 val pp = par_pblobj pt p;
483 val thy' = (get_obj g_domID pt pp):theory';
484 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
485 Frm => (get_obj g_form pt p, p)
486 | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
487 | _ => error ("applicable_in: call by "^
489 in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
491 ((*tracing("#.# applicable_in Rewrite_Set,2f'= "^f');*)
492 Appl (Rewrite_Set' (thy',(*put_asm*)false,assoc_rls rls, f, (f', asm)))
494 | NONE => Notappl (rls^" not applicable") end
496 | applicable_in (p,p_) pt (m as Detail_Set rls) =
497 if member op = [Pbl,Met] p_
498 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
500 let val pp = par_pblobj pt p
501 val thy' = (get_obj g_domID pt pp):theory'
503 Frm => get_obj g_form pt p
504 | Res => (fst o (get_obj g_result pt)) p
505 | _ => error ("applicable_in: call by "^
507 in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
509 Appl (Detail_Set' (thy',false,assoc_rls rls, f, (f',asm)))
510 | NONE => Notappl (rls^" not applicable") end
513 | applicable_in p pt (End_Ruleset) =
514 error ("applicable_in: not impl. for "^
515 (tac2str End_Ruleset))
517 (* val ((p,p_), pt, (m as Calculate op_)) = (p, pt, m);
519 | applicable_in (p,p_) pt (m as Calculate op_) =
520 if member op = [Pbl,Met] p_
521 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
524 val (msg,thy',isa_fn) = from_pblobj_or_detail_calc op_ p pt;
526 Frm => get_obj g_form pt p
527 | Res => (fst o (get_obj g_result pt)) p
528 in if msg = "OK" then
529 case calculate_ (assoc_thy thy') isa_fn f of
530 SOME (f', (id, thm)) =>
531 Appl (Calculate' (thy',op_, f, (f', (id, string_of_thmI thm))))
532 | NONE => Notappl ("'calculate "^op_^"' not applicable")
536 (*Substitute combines two different kind of "substitution":
537 (1) subst_atomic: for ?a..?z
538 (2) Pattern.match: for solving equational systems
539 (which raises exn for ?a..?z)*)
540 | applicable_in (p,p_) pt (m as Substitute sube) =
541 if member op = [Pbl,Met] p_
542 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
545 val pp = par_pblobj pt p
546 val thy = assoc_thy (get_obj g_domID pt pp)
548 Frm => get_obj g_form pt p
549 | Res => (fst o (get_obj g_result pt)) p
550 val {rew_ord',erls,...} = get_met (get_obj g_metID pt pp)
551 val subte = sube2subte sube
552 val subst = sube2subst thy sube
553 val ro = assoc_rew_ord rew_ord'
555 if foldl and_ (true, map contains_Var subte)
558 let val f' = subst_atomic subst f
559 in if f = f' then Notappl (sube2str sube^" not applicable")
560 else Appl (Substitute' (ro, erls, subte, f, f'))
564 case rewrite_terms_ thy ro erls subte f of
565 SOME (f', _) => Appl (Substitute' (ro, erls, subte, f, f'))
566 | NONE => Notappl (sube2str sube^" not applicable")
569 | applicable_in p pt (Apply_Assumption cts') =
570 (error ("applicable_in: not impl. for " ^ (tac2str (Apply_Assumption cts'))))
572 (*'logical' applicability wrt. script in locate: Inconsistent?*)
573 | applicable_in (p,p_) pt (m as Take ct') =
574 if member op = [Pbl,Met] p_
575 then Notappl (tac2str m ^ " not for pos " ^ pos'2str (p,p_))
577 let val thy' = get_obj g_domID pt (par_pblobj pt p);
578 in (case parseNEW (assoc_thy thy' |> thy2ctxt) ct' of
579 SOME ct => Appl (Take' ct)
580 | NONE => Notappl ("syntax error in " ^ ct'))
583 | applicable_in p pt (Take_Inst ct') =
584 error ("applicable_in: not impl. for " ^ tac2str (Take_Inst ct'))
585 | applicable_in p pt (Group (con, ints)) =
586 error ("applicable_in: not impl. for " ^ tac2str (Group (con, ints)))
588 | applicable_in (p,p_) pt (m as Subproblem (domID, pblID)) =
589 if member op = [Pbl,Met] p_
590 then (*maybe Apply_Method has already been done FIXME.WN150511: declare_constraints*)
591 case get_obj g_env pt p of
593 Appl (Subproblem' ((domID, pblID, e_metID), [],
594 e_term, [], e_ctxt(*FIXME.WN150511*), subpbl domID pblID))
595 | NONE => Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
596 else (*somewhere later in the script*)
597 Appl (Subproblem' ((domID, pblID, e_metID), [],
598 e_term, [], e_ctxt, subpbl domID pblID))
600 | applicable_in p pt (End_Subproblem) =
601 error ("applicable_in: not impl. for " ^ tac2str End_Subproblem)
602 | applicable_in p pt (CAScmd ct') =
603 error ("applicable_in: not impl. for " ^ tac2str (CAScmd ct'))
604 | applicable_in p pt (Split_And) =
605 error ("applicable_in: not impl. for " ^ tac2str Split_And)
606 | applicable_in p pt (Conclude_And) =
607 error ("applicable_in: not impl. for " ^ tac2str Conclude_And)
608 | applicable_in p pt (Split_Or) =
609 error ("applicable_in: not impl. for " ^ tac2str Split_Or)
610 | applicable_in p pt (Conclude_Or) =
611 error ("applicable_in: not impl. for " ^ tac2str Conclude_Or)
613 | applicable_in (p,p_) pt (Begin_Trans) =
615 val (f,p) = case p_ of (*p 12.4.00 unnecessary*)
616 (*_____ implizit Take in gen*)
617 Frm => (get_obj g_form pt p, (lev_on o lev_dn) p)
618 | Res => ((fst o (get_obj g_result pt)) p, (lev_on o lev_dn o lev_on) p)
619 | _ => error ("applicable_in: call by "^
621 val thy' = get_obj g_domID pt (par_pblobj pt p);
622 in (Appl (Begin_Trans' f))
623 handle _ => error ("applicable_in: Begin_Trans finds \
624 \syntaxerror in '"^(term2str f)^"'") end
626 (*TODO: check parent branches*)
627 | applicable_in (p,p_) pt (End_Trans) =
628 let val thy' = get_obj g_domID pt (par_pblobj pt p);
630 then Appl (End_Trans' (get_obj g_result pt p))
631 else Notappl "'End_Trans' is not applicable at the beginning of a transitive sequence"
632 (*TODO: check parent branches*)
634 | applicable_in p pt (Begin_Sequ) =
635 error ("applicable_in: not impl. for " ^ tac2str (Begin_Sequ))
636 | applicable_in p pt (End_Sequ) =
637 error ("applicable_in: not impl. for " ^ tac2str (End_Sequ))
638 | applicable_in p pt (Split_Intersect) =
639 error ("applicable_in: not impl. for " ^ tac2str (Split_Intersect))
640 | applicable_in p pt (End_Intersect) =
641 error ("applicable_in: not impl. for " ^ tac2str (End_Intersect))
643 | applicable_in (p,p_) pt (m as Check_elementwise pred) =
644 if member op = [Pbl,Met] p_
645 then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
648 val pp = par_pblobj pt p;
649 val thy' = (get_obj g_domID pt pp):theory';
650 val thy = assoc_thy thy'
651 val metID = (get_obj g_metID pt pp)
652 val {crls,...} = get_met metID
653 val (f,asm) = case p_ of Frm => (get_obj g_form pt p , [])
654 | Res => get_obj g_result pt p;
655 val vp = (thy2ctxt thy, pred) |-> parseNEW |> the |> mk_set thy pt p f;
657 Const ("List.list.Cons",_) $ _ $ _ =>
658 Appl (Check_elementwise' (f, pred, check_elementwise thy crls f vp))
659 | Const ("Tools.UniversalList",_) =>
660 Appl (Check_elementwise' (f, pred, (f,asm)))
661 | Const ("List.list.Nil",_) =>
662 Appl (Check_elementwise' (f, pred, (f, asm)))
663 | _ => Notappl ("Check_elementwise not applicable: "^(term2str f)^" should be constants")
666 | applicable_in (p,p_) pt Or_to_List =
667 if member op = [Pbl,Met] p_
668 then Notappl ((tac2str Or_to_List)^" not for pos "^(pos'2str (p,p_)))
671 val pp = par_pblobj pt p;
672 val thy' = (get_obj g_domID pt pp):theory';
673 val thy = assoc_thy thy';
675 Frm => get_obj g_form pt p
676 | Res => (fst o (get_obj g_result pt)) p;
677 in (let val ls = or2list f
678 in Appl (Or_to_List' (f, ls)) end)
679 handle _ => Notappl ("'Or_to_List' not applicable to "^(term2str f))
682 | applicable_in p pt (Collect_Trues) =
683 error ("applicable_in: not impl. for "^
684 (tac2str (Collect_Trues)))
686 | applicable_in p pt (Empty_Tac) =
687 Notappl "Empty_Tac is not applicable"
689 | applicable_in (p,p_) pt (Tac id) =
691 val pp = par_pblobj pt p;
692 val thy' = (get_obj g_domID pt pp):theory';
693 val thy = assoc_thy thy';
695 Frm => get_obj g_form pt p
696 | Pbl => error "applicable_in (p,Pbl) pt (Tac id): not at Pbl"
697 | Res => (fst o (get_obj g_result pt)) p;
699 "subproblem_equation_dummy" =>
701 then Appl (Tac_ (thy, term2str f, id,
702 "subproblem_equation_dummy ("^(term2str f)^")"))
703 else Notappl "applicable only to equations made explicit"
704 | "solve_equation_dummy" =>
705 let (*val _= tracing("### applicable_in: solve_equation_dummy: f= "
707 val (id',f') = split_dummy (term2str f);
708 (*val _= tracing("### applicable_in: f'= "^f');*)
709 (*val _= (term_of o the o (parse thy)) f';*)
710 (*val _= tracing"### applicable_in: solve_equation_dummy";*)
711 in if id' <> "subproblem_equation_dummy" then Notappl "no subproblem"
712 else if (thy2ctxt thy, f') |-> parseNEW |> the |> is_expliceq
713 then Appl (Tac_ (thy, term2str f, id, "[" ^ f' ^ "]"))
714 else error ("applicable_in: f= " ^ f') end
715 | _ => Appl (Tac_ (thy, term2str f, id, term2str f)) end
717 | applicable_in p pt End_Proof' = Appl End_Proof''
719 | applicable_in _ _ m =
720 error ("applicable_in called for "^(tac2str m));
723 fun tac2tac_ pt p m =
724 case applicable_in p pt m of
726 | Notappl _ => error ("tac2mstp': fails with"^