src/Tools/isac/Interpret/appl.sml
author Walther Neuper <wneuper@ist.tugraz.at>
Tue, 18 Oct 2016 12:05:03 +0200
changeset 59252 7d3dbc1171ff
parent 59250 727dff4f6b2c
child 59253 f0bb15a046ae
permissions -rw-r--r--
back-track after desing error in previous changeset

notes (the latter of 2 desastrous changesets):
# error was: in Isac thm must be accompanied with thmID,
because Thm.get_name_hint reports "unknown" after ".. RS sym"
# improved design will be: Rewrite* and Rewrite'* take arg. (thmID, thm)
# previous changeset also destroyed "fun pbl2xml"
neuper@37906
     1
(* use"ME/appl.sml";
neuper@37906
     2
   use"appl.sml";
neuper@37936
     3
neuper@37936
     4
12345678901234567890123456789012345678901234567890123456789012345678901234567890
neuper@37936
     5
        10        20        30        40        50        60        70        80
neuper@37936
     6
*)
neuper@37906
     7
val e_cterm' = empty_cterm';
neuper@37906
     8
neuper@37906
     9
neuper@37906
    10
fun rew_info (Rls {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
neuper@37906
    11
    (rew_ord':rew_ord',erls,ca)
neuper@37906
    12
  | rew_info (Seq {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
neuper@37906
    13
    (rew_ord',erls,ca)
neuper@37906
    14
  | rew_info (Rrls {erls,rew_ord=(rew_ord',_),calc=ca, ...}) =
neuper@37906
    15
    (rew_ord',erls, ca)
neuper@38031
    16
  | rew_info rls = error ("rew_info called with '"^rls2str rls^"'");
neuper@37906
    17
neuper@37906
    18
(*FIXME.3.4.03:re-organize from_pblobj_or_detail_thm after rls' --> rls*)
neuper@37906
    19
fun from_pblobj_or_detail_thm thm' p pt = 
neuper@52155
    20
  let 
neuper@52155
    21
    val (pbl, p', rls') = par_pbl_det pt p
neuper@52155
    22
  in 
neuper@52155
    23
    if pbl
neuper@52155
    24
    then 
neuper@52155
    25
      let 
neuper@52155
    26
        val thy' = get_obj g_domID pt p'
neuper@52156
    27
        val {rew_ord', erls, ...} = get_met (get_obj g_metID pt p')              
neuper@52155
    28
	    in ("OK", thy', rew_ord', erls, false) end
neuper@52155
    29
     else 
neuper@52155
    30
      let
neuper@52155
    31
        val thy' = get_obj g_domID pt (par_pblobj pt p)
neuper@52155
    32
		    val (rew_ord', erls, _) = rew_info rls'
neuper@52155
    33
		  in ("OK",thy',rew_ord',erls,false) end
neuper@52155
    34
  end;
neuper@37906
    35
(*FIXME.3.4.03:re-organize from_pblobj_or_detail_calc after rls' --> rls*)
neuper@37906
    36
fun from_pblobj_or_detail_calc scrop p pt = 
neuper@52155
    37
  let
neuper@52155
    38
    val (pbl,p',rls') = par_pbl_det pt p
neuper@52155
    39
  in
neuper@52155
    40
    if pbl
neuper@52155
    41
    then
neuper@52155
    42
      let
neuper@52155
    43
        val thy' = get_obj g_domID pt p'
neuper@52155
    44
        val {calc = scr_isa_fns,...} = get_met (get_obj g_metID pt p')
neuper@52155
    45
        val opt = assoc (scr_isa_fns, scrop)
neuper@52155
    46
	    in
neuper@52155
    47
	      case opt of
neuper@52155
    48
	        SOME isa_fn => ("OK",thy',isa_fn)
neuper@52155
    49
	      | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", e_evalfn))
neuper@52155
    50
	    end
neuper@52155
    51
    else 
neuper@52155
    52
		  let
neuper@52155
    53
		    val thy' = get_obj g_domID pt (par_pblobj pt p);
neuper@37906
    54
		    val (_,_,(*_,*)scr_isa_fns) = rew_info rls'(*rls*)
neuper@52155
    55
		  in
neuper@52155
    56
		    case assoc (scr_isa_fns, scrop) of
neuper@52155
    57
		      SOME isa_fn => ("OK",thy',isa_fn)
neuper@52155
    58
		    | NONE => ("applicable_in Calculate: unknown '" ^ scrop ^ "'", "", ("", e_evalfn))
neuper@52155
    59
		  end
neuper@52155
    60
  end;
neuper@37906
    61
neuper@37906
    62
val op_and = Const ("op &", [bool, bool] ---> bool);
wneuper@59184
    63
(*> (Thm.global_cterm_of thy) (op_and $ Free("a",bool) $ Free("b",bool));
neuper@37906
    64
val it = "a & b" : cterm
neuper@37906
    65
*)
neuper@37906
    66
fun mk_and a b = op_and $ a $ b;
wneuper@59184
    67
(*> (Thm.global_cterm_of thy) 
neuper@37906
    68
     (mk_and (Free("a",bool)) (Free("b",bool)));
neuper@37906
    69
val it = "a & b" : cterm*)
neuper@37906
    70
neuper@48760
    71
fun mk_and [] = @{term True}
neuper@37906
    72
  | mk_and (t::[]) = t
neuper@37906
    73
  | mk_and (t::ts) = 
neuper@37906
    74
    let fun mk t' (t::[]) = op_and $ t' $ t
neuper@37906
    75
	  | mk t' (t::ts) = mk (op_and $ t' $ t) ts
neuper@37906
    76
    in mk t ts end;
wneuper@59186
    77
(*> val pred = map (Thm.term_of o the o (parse thy)) 
neuper@37906
    78
             ["#0 <= #9 + #4 * x","#0 <= sqrt x + sqrt (#-3 + x)"];
wneuper@59184
    79
> (Thm.global_cterm_of thy) (mk_and pred);
neuper@37906
    80
val it = "#0 <= #9 + #4 * x & #0 <= sqrt x + sqrt (#-3 + x)" : cterm*)
neuper@37906
    81
neuper@37906
    82
neuper@37906
    83
neuper@37906
    84
neuper@37906
    85
(*for Check_elementwise in applicable_in: [x=1,..] Assumptions -> (x,0<=x&..)*)
neuper@37906
    86
fun mk_set thy pt p (Const ("List.list.Nil",_)) pred = (e_term, [])
neuper@37906
    87
neuper@37906
    88
  | mk_set thy pt p (Const ("Tools.UniversalList",_)) pred =
neuper@37906
    89
    (e_term, if pred <> Const ("Script.Assumptions",bool)
neuper@37906
    90
	     then [pred] 
e0726734@41957
    91
	     else get_assumptions_ pt (p,Res))
neuper@37906
    92
wneuper@59186
    93
(* val pred = (Thm.term_of o the o (parse thy)) pred;
neuper@37906
    94
   val consts as Const ("List.list.Cons",_) $ eq $ _ = ft;
neuper@37906
    95
   mk_set thy pt p consts pred;
neuper@37906
    96
   *)
neuper@37906
    97
  | mk_set thy pt p (consts as Const ("List.list.Cons",_) $ eq $ _) pred =
neuper@37906
    98
  let val (bdv,_) = HOLogic.dest_eq eq;
neuper@37906
    99
    val pred = if pred <> Const ("Script.Assumptions",bool)
neuper@37906
   100
		 then [pred] 
e0726734@41957
   101
	       else get_assumptions_ pt (p,Res)
neuper@37906
   102
  in (bdv, pred) end
neuper@37906
   103
neuper@37906
   104
  | mk_set thy _ _ l _ = 
neuper@38053
   105
    error ("check_elementwise: no set " ^ term2str l);
neuper@37906
   106
(*> val consts = str2term "[x=#4]";
neuper@37906
   107
> val pred = str2term "Assumptions";
neuper@37906
   108
> val pt = union_asm pt p 
neuper@37906
   109
   [("#0 <= sqrt x + sqrt (#5 + x)",[11]),("#0 <= #9 + #4 * x",[22]),
neuper@37906
   110
   ("#0 <= x ^^^ #2 + #5 * x",[33]),("#0 <= #2 + x",[44])];
neuper@37906
   111
> val p = [];
neuper@37906
   112
> val (sss,ttt) = mk_set thy pt p consts pred;
neuper@38053
   113
> (term2str sss, term2str ttt);
neuper@37906
   114
val it = ("x","((#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x) & ...
neuper@37906
   115
neuper@37906
   116
 val consts = str2term "UniversalList";
neuper@37906
   117
 val pred = str2term "Assumptions";
neuper@37906
   118
neuper@37906
   119
*)
neuper@37906
   120
neuper@37906
   121
neuper@37906
   122
neuper@37906
   123
(*check a list (/set) of constants [c_1,..,c_n] for c_i:set (: in)*)
neuper@37906
   124
(* val (erls,consts,(bdv,pred)) = (erl,ft,vp);
neuper@37906
   125
   val (consts,(bdv,pred)) = (ft,vp);
neuper@37906
   126
   *)
neuper@37906
   127
fun check_elementwise thy erls all_results (bdv, asm) =
neuper@37906
   128
    let   (*bdv extracted from ~~~~~~~~~~~ in mk_set already*)
neuper@37906
   129
	fun check sub =
neuper@37906
   130
	    let val inst_ = map (subst_atomic [sub]) asm
neuper@37906
   131
	    in case eval__true thy 1 inst_ [] erls of
neuper@37906
   132
		   (asm', true) => ([HOLogic.mk_eq sub], asm')
neuper@37906
   133
		 | (_, false) => ([],[])
neuper@37906
   134
	    end;
neuper@38015
   135
      (*val _= tracing("### check_elementwise: res= "^(term2str all_results)^
neuper@37906
   136
		       ", bdv= "^(term2str bdv)^", asm= "^(terms2str asm));*)
neuper@37906
   137
	val c' = isalist2list all_results
neuper@37906
   138
	val c'' = map (snd o HOLogic.dest_eq) c' (*assumes [x=1,x=2,..]*)
neuper@37906
   139
	val subs = map (pair bdv) c''
neuper@37906
   140
    in if asm = [] then (all_results, [])
neuper@37906
   141
       else ((apfst ((list2isalist bool) o flat)) o 
neuper@37906
   142
	     (apsnd flat) o split_list o (map check)) subs end;
neuper@37906
   143
(* 20.5.03
neuper@37906
   144
> val all_results = str2term "[x=a+b,x=b,x=3]";
neuper@37906
   145
> val bdv = str2term "x";
neuper@37906
   146
> val asm = str2term "(x ~= a) & (x ~= b)";
neuper@37906
   147
> val erls = e_rls;
neuper@37906
   148
> val (t, ts) = check_elementwise thy erls all_results (bdv, asm);
neuper@38015
   149
> term2str t; tracing(terms2str ts);
neuper@37906
   150
val it = "[x = a + b, x = b, x = c]" : string
neuper@37906
   151
["a + b ~= a & a + b ~= b","b ~= a & b ~= b","c ~= a & c ~= b"]
neuper@37906
   152
... with appropriate erls this should be:
neuper@37906
   153
val it = "[x = a + b,       x = c]" : string
neuper@37906
   154
["b ~= 0 & a ~= 0",         "3 ~= a & 3 ~= b"]
neuper@37906
   155
                    ////// because b ~= b False*)
neuper@37906
   156
neuper@37906
   157
neuper@37906
   158
neuper@37906
   159
(*before 5.03-----
neuper@37906
   160
> val ct = "((#0 <= #18 & #0 <= sqrt (#5 + #3) + sqrt (#5 - #3)) &\
neuper@37906
   161
	   \ #0 <= #25 + #-1 * #3 ^^^ #2) & #0 <= #4";
neuper@38050
   162
> val SOME(ct',_) = rewrite_set "Isac" false "eval_rls" ct;
neuper@41928
   163
val ct' = "HOL.True" : cterm'
neuper@37906
   164
neuper@37906
   165
> val ct = "((#0 <= #18 & #0 <= sqrt (#5 + #-3) + sqrt (#5 - #-3)) &\
neuper@37906
   166
	   \ #0 <= #25 + #-1 * #-3 ^^^ #2) & #0 <= #4";
neuper@38050
   167
> val SOME(ct',_) = rewrite_set "Isac"  false "eval_rls" ct;
neuper@41928
   168
val ct' = "HOL.True" : cterm'
neuper@37906
   169
neuper@37906
   170
wneuper@59186
   171
> val const  = (Thm.term_of o the o (parse thy)) "(#3::real)";
neuper@37906
   172
> val pred' = subst_atomic [(bdv,const)] pred;
neuper@37906
   173
neuper@37906
   174
wneuper@59186
   175
> val consts = (Thm.term_of o the o (parse thy)) "[x = #-3, x = #3]";
wneuper@59186
   176
> val bdv    = (Thm.term_of o the o (parse thy)) "(x::real)";
wneuper@59186
   177
> val pred   = (Thm.term_of o the o (parse thy)) 
neuper@37906
   178
  "((#0 <= #18 & #0 <= sqrt (#5 + x) + sqrt (#5 - x)) & #0 <= #25 + #-1 * x ^^^ #2) & #0 <= #4";
neuper@37906
   179
> val ttt = check_elementwise thy consts (bdv, pred);
wneuper@59184
   180
> (Thm.global_cterm_of thy) ttt;
neuper@37906
   181
val it = "[x = #-3, x = #3]" : cterm
neuper@37906
   182
wneuper@59186
   183
> val consts = (Thm.term_of o the o (parse thy)) "[x = #4]";
wneuper@59186
   184
> val bdv    = (Thm.term_of o the o (parse thy)) "(x::real)";
wneuper@59186
   185
> val pred   = (Thm.term_of o the o (parse thy)) 
neuper@37906
   186
 "#0 <= sqrt x + sqrt (#5 + x) & #0 <= #9 + #4 * x & #0 <= x ^^^ #2 + #5 * x & #0 <= #2 + x";
neuper@37906
   187
> val ttt = check_elementwise thy consts (bdv,pred);
wneuper@59184
   188
> (Thm.global_cterm_of thy) ttt;
neuper@37906
   189
val it = "[x = #4]" : cterm
neuper@37906
   190
wneuper@59186
   191
> val consts = (Thm.term_of o the o (parse thy)) "[x = #-12 // #5]";
wneuper@59186
   192
> val bdv    = (Thm.term_of o the o (parse thy)) "(x::real)";
wneuper@59186
   193
> val pred   = (Thm.term_of o the o (parse thy))
neuper@37906
   194
 " #0 <= sqrt x + sqrt (#-3 + x) & #0 <= #9 + #4 * x & #0 <= x ^^^ #2 + #-3 * x & #0 <= #6 + x";
neuper@37906
   195
> val ttt = check_elementwise thy consts (bdv,pred);
wneuper@59184
   196
> (Thm.global_cterm_of thy) ttt;
neuper@37906
   197
val it = "[]" : cterm*)
neuper@37906
   198
neuper@37906
   199
neuper@37906
   200
(* 14.1.01: for Tac-dummies in root-equ only: skip str until "("*)
neuper@37906
   201
fun split_dummy str = 
neuper@37906
   202
let fun scan s' [] = (implode s', "")
neuper@37906
   203
      | scan s' (s::ss) = if s=" " then (implode s', implode  ss)
neuper@37906
   204
			  else scan (s'@[s]) ss;
neuper@40836
   205
in ((scan []) o Symbol.explode) str end;
neuper@37906
   206
(* split_dummy "subproblem_equation_dummy (x=-#5//#12)";
neuper@37906
   207
val it = ("subproblem_equation_dummy","(x=-#5//#12)") : string * string
neuper@37906
   208
> split_dummy "x=-#5//#12";
neuper@37906
   209
val it = ("x=-#5//#12","") : string * string*)
neuper@37906
   210
neuper@37906
   211
neuper@37906
   212
neuper@37906
   213
neuper@37906
   214
(*.applicability of a tacic wrt. a calc-state (ptree,pos').
neuper@41980
   215
   additionally used by next_tac in the script-interpreter for script-tacs.
neuper@37906
   216
   tests for applicability are so expensive, that results (rewrites!)
neuper@37906
   217
   are kept in the return-value of 'type tac_'.
neuper@37906
   218
.*)
neuper@41975
   219
fun applicable_in (_:pos') _ (Init_Proof (ct', spec)) = Appl (Init_Proof' (ct', spec))
neuper@37906
   220
neuper@37906
   221
  | applicable_in (p,p_) pt Model_Problem = 
neuper@41975
   222
      if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
neuper@41975
   223
      then Notappl ((tac2str Model_Problem) ^ " not for pos " ^ (pos'2str (p,p_)))
neuper@41975
   224
      else 
neuper@41975
   225
        let 
neuper@41975
   226
          val (PblObj{origin=(_,(_,pI',_),_),...}) = get_obj I pt p
neuper@41975
   227
	        val {ppc,...} = get_pbt pI'
neuper@41975
   228
	        val pbl = init_pbl ppc
neuper@41975
   229
        in Appl (Model_Problem' (pI', pbl, [])) end
neuper@41975
   230
neuper@37906
   231
  | applicable_in (p,p_) pt (Refine_Tacitly pI) = 
neuper@41975
   232
      if not (is_pblobj (get_obj I pt p)) orelse p_ = Res
neuper@41975
   233
      then Notappl ((tac2str (Refine_Tacitly pI)) ^ " not for pos " ^ (pos'2str (p,p_)))
neuper@41975
   234
      else 
neuper@41975
   235
        let 
neuper@41975
   236
          val (PblObj {origin = (oris, (dI',_,_),_), ...}) = get_obj I pt p;
neuper@41975
   237
          val opt = refine_ori oris pI;
neuper@41975
   238
        in case opt of
neuper@41975
   239
	           SOME pblID => 
neuper@41975
   240
	             Appl (Refine_Tacitly' (pI, pblID, 
neuper@41975
   241
				         e_domID, e_metID, [](*filled in specify*)))
neuper@41975
   242
	         | NONE => Notappl ((tac2str (Refine_Tacitly pI)) ^ " not applicable")
neuper@41975
   243
        end
neuper@41975
   244
neuper@37906
   245
  | applicable_in (p,p_) pt (Refine_Problem pI) = 
neuper@37906
   246
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   247
    then Notappl ((tac2str (Refine_Problem pI))^
neuper@37906
   248
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   249
  else
neuper@37906
   250
    let val (PblObj {origin=(_,(dI,_,_),_),spec=(dI',_,_),
neuper@37906
   251
		     probl=itms, ...}) = get_obj I pt p;
neuper@37906
   252
	val thy = if dI' = e_domID then dI else dI';
neuper@37906
   253
	val rfopt = refine_pbl (assoc_thy thy) pI itms;
neuper@37906
   254
    in case rfopt of
neuper@37926
   255
	   NONE => Notappl ((tac2str (Refine_Problem pI))^" not applicable")
neuper@37926
   256
	 | SOME (rf as (pI',_)) =>
neuper@37926
   257
(* val SOME (rf as (pI',_)) = rfopt;
neuper@37906
   258
   *)
neuper@37906
   259
	   if pI' = pI
neuper@37906
   260
	   then Notappl ((tac2str (Refine_Problem pI))^" not applicable")
neuper@37906
   261
	   else Appl (Refine_Problem' rf)
neuper@37906
   262
    end
neuper@37906
   263
neuper@37906
   264
  (*the specify-tacs have cterm' instead term: 
neuper@37906
   265
   parse+error here!!!: see appl_add*)  
neuper@37906
   266
  | applicable_in (p,p_) pt (Add_Given ct') = 
neuper@37906
   267
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   268
    then Notappl ((tac2str (Add_Given ct'))^
neuper@37906
   269
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   270
  else Appl (Add_Given' (ct', [(*filled in specify_additem*)]))
neuper@37906
   271
  (*Add_.. should reject (dsc //) (see fmz=[] in sqrt*)
neuper@37906
   272
neuper@37906
   273
  | applicable_in (p,p_) pt (Del_Given ct') =
neuper@37906
   274
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   275
    then Notappl ((tac2str (Del_Given ct'))^
neuper@37906
   276
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   277
  else Appl (Del_Given' ct')
neuper@37906
   278
neuper@37906
   279
  | applicable_in (p,p_) pt (Add_Find ct') =                   
neuper@37906
   280
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   281
    then Notappl ((tac2str (Add_Find ct'))^
neuper@37906
   282
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   283
  else Appl (Add_Find' (ct', [(*filled in specify_additem*)]))
neuper@37906
   284
neuper@37906
   285
  | applicable_in (p,p_) pt (Del_Find ct') =
neuper@37906
   286
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   287
    then Notappl ((tac2str (Del_Find ct'))^
neuper@37906
   288
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   289
  else Appl (Del_Find' ct')
neuper@37906
   290
neuper@37906
   291
  | applicable_in (p,p_) pt (Add_Relation ct') =               
neuper@37906
   292
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   293
    then Notappl ((tac2str (Add_Relation ct'))^
neuper@37906
   294
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   295
  else Appl (Add_Relation' (ct', [(*filled in specify_additem*)]))
neuper@37906
   296
neuper@37906
   297
  | applicable_in (p,p_) pt (Del_Relation ct') =
neuper@37906
   298
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   299
    then Notappl ((tac2str (Del_Relation ct'))^
neuper@37906
   300
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   301
  else Appl (Del_Relation' ct')
neuper@37906
   302
neuper@37906
   303
  | applicable_in (p,p_) pt (Specify_Theory dI) =              
neuper@37906
   304
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   305
    then Notappl ((tac2str (Specify_Theory dI))^
neuper@37906
   306
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   307
  else Appl (Specify_Theory' dI)
neuper@37906
   308
(* val (p,p_) = p; val Specify_Problem pID = m;
neuper@37906
   309
   val Specify_Problem pID = m;
neuper@37906
   310
   *)
neuper@37906
   311
  | applicable_in (p,p_) pt (Specify_Problem pID) = 
neuper@37906
   312
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@37906
   313
    then Notappl ((tac2str (Specify_Problem pID))^
neuper@37906
   314
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   315
  else
neuper@37906
   316
    let val (PblObj {origin=(oris,(dI,pI,_),_),spec=(dI',pI',_),
neuper@37906
   317
		     probl=itms, ...}) = get_obj I pt p;
neuper@37906
   318
	val thy = assoc_thy (if dI' = e_domID then dI else dI');
neuper@37906
   319
        val {ppc,where_,prls,...} = get_pbt pID;
neuper@37906
   320
	val pbl = if pI'=e_pblID andalso pI=e_pblID
neuper@37906
   321
		  then (false, (init_pbl ppc, []))
neuper@37906
   322
		  else match_itms_oris thy itms (ppc,where_,prls) oris;
neuper@37906
   323
    in Appl (Specify_Problem' (pID, pbl)) end
neuper@37906
   324
(* val Specify_Method mID = nxt; val (p,p_) = p; 
neuper@37906
   325
   *)
neuper@37906
   326
  | applicable_in (p,p_) pt (Specify_Method mID) =              
neuper@37906
   327
  if not (is_pblobj (get_obj I pt p)) orelse p_ = Res               
neuper@37906
   328
    then Notappl ((tac2str (Specify_Method mID))^
neuper@37906
   329
	   " not for pos "^(pos'2str (p,p_)))
neuper@37906
   330
  else Appl (Specify_Method' (mID,[(*filled in specify*)],
neuper@37906
   331
			      [(*filled in specify*)]))
neuper@37906
   332
neuper@37906
   333
  | applicable_in (p,p_) pt (Apply_Method mI) =                
neuper@41992
   334
      if not (is_pblobj (get_obj I pt p)) orelse p_ = Res                  
neuper@41992
   335
      then Notappl ((tac2str (Apply_Method mI)) ^ " not for pos " ^ (pos'2str (p,p_)))
neuper@41992
   336
      else
neuper@41992
   337
        let
neuper@41992
   338
          val (PblObj{origin = (_, (dI, pI, _), _), probl, ctxt, ...}) = get_obj I pt p;
neuper@41992
   339
          val {where_, ...} = get_pbt pI
neuper@41992
   340
          val pres = map (mk_env probl |> subst_atomic) where_
neuper@41992
   341
          val ctxt = 
neuper@41992
   342
            if is_e_ctxt ctxt
neuper@48761
   343
            then assoc_thy dI |> Proof_Context.init_global |> insert_assumptions pres
neuper@41992
   344
            else ctxt
neuper@42018
   345
         (*TODO.WN110416 here do evalprecond according to fun check_preconds'
neuper@42018
   346
         and then decide on Notappl/Appl accordingly once more.
neuper@42018
   347
         Implement after all tests are running, since this changes
neuper@42018
   348
         overall system behavior*)
neuper@42018
   349
      in Appl (Apply_Method' (mI, NONE, e_istate (*filled in solve*), ctxt)) end
neuper@37906
   350
neuper@37906
   351
  | applicable_in (p,p_) pt (Check_Postcond pI) =
neuper@42018
   352
      if member op = [Pbl,Met] p_                  
neuper@42018
   353
      then Notappl ((tac2str (Check_Postcond pI)) ^ " not for pos "^(pos'2str (p,p_)))
neuper@42023
   354
      else Appl (Check_Postcond' (pI, (e_term, [(*fun solve assignes the returnvalue of scr*)])))
neuper@37906
   355
neuper@37906
   356
  (*these are always applicable*)
neuper@37906
   357
  | applicable_in (p,p_) _ (Take str) = Appl (Take' (str2term str))
neuper@37906
   358
  | applicable_in (p,p_) _ (Free_Solve) = Appl (Free_Solve')
neuper@37906
   359
wneuper@59250
   360
  | applicable_in (p, p_) pt (m as Rewrite_Inst (subs, thm'')) = 
neuper@42394
   361
    if member op = [Pbl, Met] p_ 
neuper@37906
   362
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@42394
   363
    else
neuper@42394
   364
      let 
neuper@42394
   365
        val pp = par_pblobj pt p;
neuper@42394
   366
        val thy' = (get_obj g_domID pt pp): theory';
neuper@42394
   367
        val thy = assoc_thy thy';
neuper@42394
   368
        val {rew_ord' = ro', erls = erls, ...} = get_met (get_obj g_metID pt pp);
neuper@42394
   369
        val (f, p) = case p_ of (*p 12.4.00 unnecessary*)
neuper@42394
   370
                      Frm => (get_obj g_form pt p, p)
neuper@42394
   371
                    | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
neuper@42394
   372
                    | _ => error ("applicable_in: call by " ^ pos'2str (p,p_));
neuper@42394
   373
      in 
neuper@42394
   374
        let
neuper@42394
   375
          val subst = subs2subst thy subs;
neuper@42394
   376
          val subs' = subst2subs' subst;
wneuper@59252
   377
        in case rewrite_inst_ thy (assoc_rew_ord ro') erls false subst (assoc_thm'' thy thm'') f of
neuper@42394
   378
             SOME (f',asm) =>
wneuper@59252
   379
               Appl (Rewrite_Inst' (thy', ro', erls, false, subst, thm''_to_thm' thm'', f, (f', asm)))
wneuper@59252
   380
           | NONE => Notappl ((fst thm'')^" not applicable")
neuper@42394
   381
        end
neuper@42394
   382
        handle _ => Notappl ("syntax error in "^(subs2str subs))
neuper@42394
   383
      end
neuper@37906
   384
wneuper@59250
   385
| applicable_in (p,p_) pt (m as Rewrite thm'') = 
neuper@37935
   386
  if member op = [Pbl,Met] p_ 
neuper@37906
   387
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   388
  else
wneuper@59250
   389
  let val (msg,thy',ro,rls',(*put_asm*)_)= from_pblobj_or_detail_thm thm'' p pt;
neuper@37906
   390
    val thy = assoc_thy thy';
neuper@37906
   391
    val f = case p_ of
neuper@37906
   392
              Frm => get_obj g_form pt p
neuper@37906
   393
	    | Res => (fst o (get_obj g_result pt)) p
neuper@38031
   394
	    | _ => error ("applicable_in Rewrite: call by "^
neuper@37906
   395
				(pos'2str (p,p_)));
neuper@37906
   396
  in if msg = "OK" 
neuper@37906
   397
     then
wneuper@59252
   398
        case rewrite_ thy (assoc_rew_ord ro) rls' false (assoc_thm'' thy thm'') f of
wneuper@59252
   399
         SOME (f',asm) => Appl (Rewrite' (thy', ro, rls', false, thm''_to_thm' thm'', f, (f', asm)))
wneuper@59252
   400
       | NONE => Notappl ("'" ^ fst thm'' ^"' not applicable") 
neuper@37906
   401
     else Notappl msg
neuper@37906
   402
  end
neuper@37906
   403
wneuper@59250
   404
| applicable_in (p,p_) pt (m as Rewrite_Asm thm'') = 
neuper@37935
   405
  if member op = [Pbl,Met] p_ 
neuper@37906
   406
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   407
  else
neuper@37906
   408
  let 
neuper@37906
   409
    val pp = par_pblobj pt p; 
neuper@37906
   410
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   411
    val thy = assoc_thy thy';
neuper@37906
   412
    val {rew_ord'=ro',erls=erls,...} = 
neuper@37906
   413
      get_met (get_obj g_metID pt pp);
neuper@37906
   414
    (*val put_asm = true;*)
wneuper@59250
   415
    val (f, _) = case p_ of
neuper@37906
   416
              Frm => (get_obj g_form pt p, p)
neuper@37906
   417
	    | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
neuper@38031
   418
	    | _ => error ("applicable_in: call by "^
neuper@37906
   419
				(pos'2str (p,p_)));
wneuper@59252
   420
  in case rewrite_ thy (assoc_rew_ord ro') erls false (assoc_thm'' thy thm'') f of
neuper@37926
   421
       SOME (f',asm) => Appl (
wneuper@59252
   422
	   Rewrite' (thy', ro', erls, false, thm''_to_thm' thm'', f, (f', asm)))
wneuper@59250
   423
     | NONE => Notappl ("'" ^ fst thm'' ^ "' not applicable") end
neuper@37906
   424
neuper@37906
   425
  | applicable_in (p,p_) pt (m as Detail_Set_Inst (subs, rls)) = 
neuper@37935
   426
  if member op = [Pbl,Met] p_ 
neuper@37906
   427
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   428
  else
neuper@37906
   429
  let 
neuper@37906
   430
    val pp = par_pblobj pt p;
neuper@37906
   431
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   432
    val thy = assoc_thy thy';
neuper@37906
   433
    val {rew_ord'=ro',...} = get_met (get_obj g_metID pt pp);
neuper@37906
   434
    val f = case p_ of Frm => get_obj g_form pt p
neuper@37906
   435
		     | Res => (fst o (get_obj g_result pt)) p
neuper@38031
   436
		     | _ => error ("applicable_in: call by "^
neuper@37906
   437
					 (pos'2str (p,p_)));
neuper@37906
   438
  in 
neuper@37906
   439
      let val subst = subs2subst thy subs
neuper@37906
   440
	  val subs' = subst2subs' subst
neuper@37906
   441
      in case rewrite_set_inst_ thy false subst (assoc_rls rls) f of
neuper@37926
   442
      SOME (f',asm) => Appl (
neuper@37906
   443
	  Detail_Set_Inst' (thy',false,subst,assoc_rls rls, f, (f', asm)))
neuper@37926
   444
    | NONE => Notappl (rls^" not applicable") end
neuper@37906
   445
  handle _ => Notappl ("syntax error in "^(subs2str subs)) end
neuper@37906
   446
neuper@37906
   447
  | applicable_in (p,p_) pt (m as Rewrite_Set_Inst (subs, rls)) = 
neuper@37935
   448
  if member op = [Pbl,Met] p_ 
neuper@37906
   449
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   450
  else
neuper@37906
   451
  let 
neuper@37906
   452
    val pp = par_pblobj pt p;
neuper@37906
   453
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   454
    val thy = assoc_thy thy';
neuper@37906
   455
    val {rew_ord'=ro',(*asm_rls=asm_rls,*)...} = 
neuper@37906
   456
      get_met (get_obj g_metID pt pp);
neuper@37906
   457
    val (f,p) = case p_ of  (*p 12.4.00 unnecessary*)
neuper@37906
   458
              Frm => (get_obj g_form pt p, p)
neuper@37906
   459
	    | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
neuper@38031
   460
	    | _ => error ("applicable_in: call by "^
neuper@37906
   461
				(pos'2str (p,p_)));
neuper@37906
   462
  in 
neuper@37906
   463
    let val subst = subs2subst thy subs;
neuper@37906
   464
	val subs' = subst2subs' subst;
neuper@37906
   465
    in case rewrite_set_inst_ thy (*put_asm*)false subst (assoc_rls rls) f of
neuper@37926
   466
      SOME (f',asm) => Appl (
neuper@37906
   467
	  Rewrite_Set_Inst' (thy',(*put_asm*)false,subst,assoc_rls rls, f, (f', asm)))
neuper@37926
   468
    | NONE => Notappl (rls^" not applicable") end
neuper@37906
   469
  handle _ => Notappl ("syntax error in "^(subs2str subs)) end
neuper@37906
   470
neuper@37906
   471
  | applicable_in (p,p_) pt (m as Rewrite_Set rls) = 
neuper@37935
   472
  if member op = [Pbl,Met] p_ 
neuper@37906
   473
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   474
  else
neuper@37906
   475
  let 
neuper@37906
   476
    val pp = par_pblobj pt p; 
neuper@37906
   477
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   478
    val (f,p) = case p_ of  (*p 12.4.00 unnecessary*)
neuper@37906
   479
              Frm => (get_obj g_form pt p, p)
neuper@37906
   480
	    | Res => ((fst o (get_obj g_result pt)) p, lev_on p)
neuper@38031
   481
	    | _ => error ("applicable_in: call by "^
neuper@37906
   482
				(pos'2str (p,p_)));
neuper@37930
   483
  in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
neuper@37926
   484
       SOME (f',asm) => 
neuper@38015
   485
	((*tracing("#.# applicable_in Rewrite_Set,2f'= "^f');*)
neuper@37906
   486
	 Appl (Rewrite_Set' (thy',(*put_asm*)false,assoc_rls rls, f, (f', asm)))
neuper@37906
   487
	 )
neuper@37926
   488
     | NONE => Notappl (rls^" not applicable") end
neuper@37906
   489
neuper@37906
   490
  | applicable_in (p,p_) pt (m as Detail_Set rls) =
neuper@37935
   491
    if member op = [Pbl,Met] p_ 
neuper@37906
   492
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   493
    else
neuper@37906
   494
	let val pp = par_pblobj pt p 
neuper@37906
   495
	    val thy' = (get_obj g_domID pt pp):theory'
neuper@37906
   496
	    val f = case p_ of
neuper@37906
   497
			Frm => get_obj g_form pt p
neuper@37906
   498
		      | Res => (fst o (get_obj g_result pt)) p
neuper@38031
   499
		      | _ => error ("applicable_in: call by "^
neuper@37906
   500
					  (pos'2str (p,p_)));
neuper@37906
   501
	in case rewrite_set_ (assoc_thy thy') false (assoc_rls rls) f of
neuper@37926
   502
	       SOME (f',asm) => 
neuper@37906
   503
	       Appl (Detail_Set' (thy',false,assoc_rls rls, f, (f',asm)))
neuper@37926
   504
	     | NONE => Notappl (rls^" not applicable") end
neuper@37906
   505
neuper@37906
   506
neuper@37906
   507
  | applicable_in p pt (End_Ruleset) = 
neuper@38031
   508
  error ("applicable_in: not impl. for "^
neuper@37906
   509
	       (tac2str End_Ruleset))
neuper@37906
   510
neuper@37906
   511
(* val ((p,p_), pt, (m as Calculate op_)) = (p, pt, m);
neuper@37906
   512
   *)
neuper@37906
   513
| applicable_in (p,p_) pt (m as Calculate op_) = 
neuper@37935
   514
  if member op = [Pbl,Met] p_
neuper@37906
   515
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   516
  else
neuper@37906
   517
  let 
neuper@37906
   518
    val (msg,thy',isa_fn) = from_pblobj_or_detail_calc op_ p pt;
neuper@37906
   519
    val f = case p_ of
neuper@37906
   520
              Frm => get_obj g_form pt p
neuper@37906
   521
	    | Res => (fst o (get_obj g_result pt)) p
neuper@37906
   522
  in if msg = "OK" then
neuper@37906
   523
	 case calculate_ (assoc_thy thy') isa_fn f of
neuper@37926
   524
	     SOME (f', (id, thm)) => 
neuper@37906
   525
	     Appl (Calculate' (thy',op_, f, (f', (id, string_of_thmI thm))))
neuper@37926
   526
	   | NONE => Notappl ("'calculate "^op_^"' not applicable") 
neuper@37906
   527
     else Notappl msg
neuper@37906
   528
  end
neuper@37906
   529
neuper@37906
   530
(*Substitute combines two different kind of "substitution":
neuper@37906
   531
  (1) subst_atomic: for ?a..?z
neuper@37906
   532
  (2) Pattern.match: for solving equational systems 
neuper@37906
   533
      (which raises exn for ?a..?z)*)
neuper@37906
   534
  | applicable_in (p,p_) pt (m as Substitute sube) = 
neuper@42360
   535
      if member op = [Pbl,Met] p_ 
neuper@42360
   536
      then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@42360
   537
      else 
neuper@42360
   538
        let
neuper@42360
   539
          val pp = par_pblobj pt p
neuper@42360
   540
          val thy = assoc_thy (get_obj g_domID pt pp)
neuper@42360
   541
          val f = case p_ of
neuper@42360
   542
		        Frm => get_obj g_form pt p
neuper@42360
   543
		      | Res => (fst o (get_obj g_result pt)) p
neuper@42360
   544
		      val {rew_ord',erls,...} = get_met (get_obj g_metID pt pp)
neuper@42360
   545
		      val subte = sube2subte sube
neuper@42360
   546
		      val subst = sube2subst thy sube
neuper@42360
   547
		      val ro = assoc_rew_ord rew_ord'
neuper@42360
   548
		    in
neuper@42360
   549
		      if foldl and_ (true, map contains_Var subte)
neuper@42360
   550
		      (*1*)
neuper@42360
   551
		      then
neuper@42360
   552
		        let val f' = subst_atomic subst f
neuper@42360
   553
		        in if f = f' then Notappl (sube2str sube^" not applicable")
neuper@42360
   554
		           else Appl (Substitute' (ro, erls, subte, f, f'))
neuper@42360
   555
		        end
neuper@42360
   556
		        (*2*)
neuper@42360
   557
		      else 
neuper@42360
   558
		        case rewrite_terms_ thy ro erls subte f of
neuper@42360
   559
		            SOME (f', _) =>  Appl (Substitute' (ro, erls, subte, f, f'))
neuper@42360
   560
		          | NONE => Notappl (sube2str sube^" not applicable")
neuper@42360
   561
		    end
neuper@37906
   562
neuper@37906
   563
  | applicable_in p pt (Apply_Assumption cts') = 
neuper@41993
   564
      (error ("applicable_in: not impl. for " ^ (tac2str (Apply_Assumption cts'))))
neuper@37906
   565
  
neuper@37906
   566
  (*'logical' applicability wrt. script in locate: Inconsistent?*)
neuper@37906
   567
  | applicable_in (p,p_) pt (m as Take ct') = 
neuper@41993
   568
      if member op = [Pbl,Met] p_ 
neuper@41993
   569
      then Notappl (tac2str m ^ " not for pos " ^ pos'2str (p,p_))
neuper@41993
   570
      else
neuper@41993
   571
        let val thy' = get_obj g_domID pt (par_pblobj pt p);
neuper@41993
   572
        in (case parseNEW (assoc_thy thy' |> thy2ctxt) ct' of
neuper@41993
   573
	            SOME ct => Appl (Take' ct)
neuper@41993
   574
	          | NONE => Notappl ("syntax error in " ^ ct'))
neuper@41993
   575
        end
neuper@37906
   576
neuper@37906
   577
  | applicable_in p pt (Take_Inst ct') = 
neuper@41993
   578
      error ("applicable_in: not impl. for " ^ tac2str (Take_Inst ct'))
neuper@37906
   579
  | applicable_in p pt (Group (con, ints)) = 
neuper@41993
   580
      error ("applicable_in: not impl. for " ^ tac2str (Group (con, ints)))
neuper@37906
   581
neuper@37906
   582
  | applicable_in (p,p_) pt (m as Subproblem (domID, pblID)) = 
neuper@37935
   583
     if member op = [Pbl,Met] p_
neuper@41993
   584
     then (*maybe Apply_Method has already been done FIXME.WN150511: declare_constraints*)
neuper@41993
   585
	      case get_obj g_env pt p of
neuper@41993
   586
	        SOME is => 
neuper@41993
   587
            Appl (Subproblem' ((domID, pblID, e_metID), [], 
neuper@41993
   588
					    e_term, [], e_ctxt(*FIXME.WN150511*), subpbl domID pblID))
neuper@41993
   589
	      | NONE => Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   590
     else (*somewhere later in the script*)
neuper@37906
   591
       Appl (Subproblem' ((domID, pblID, e_metID), [], 
neuper@41993
   592
			   e_term, [], e_ctxt, subpbl domID pblID))
neuper@37906
   593
neuper@37906
   594
  | applicable_in p pt (End_Subproblem) =
neuper@41993
   595
      error ("applicable_in: not impl. for " ^ tac2str End_Subproblem)
neuper@37906
   596
  | applicable_in p pt (CAScmd ct') = 
neuper@41993
   597
      error ("applicable_in: not impl. for " ^ tac2str (CAScmd ct'))  
neuper@37906
   598
  | applicable_in p pt (Split_And) = 
neuper@41993
   599
      error ("applicable_in: not impl. for " ^ tac2str Split_And)
neuper@37906
   600
  | applicable_in p pt (Conclude_And) = 
neuper@41993
   601
      error ("applicable_in: not impl. for " ^ tac2str Conclude_And)
neuper@37906
   602
  | applicable_in p pt (Split_Or) = 
neuper@41993
   603
      error ("applicable_in: not impl. for " ^ tac2str Split_Or)
neuper@37906
   604
  | applicable_in p pt (Conclude_Or) = 
neuper@41993
   605
      error ("applicable_in: not impl. for " ^ tac2str Conclude_Or)
neuper@37906
   606
neuper@37906
   607
  | applicable_in (p,p_) pt (Begin_Trans) =
neuper@37906
   608
    let
neuper@37906
   609
      val (f,p) = case p_ of   (*p 12.4.00 unnecessary*)
neuper@37906
   610
	                             (*_____ implizit Take in gen*)
neuper@37906
   611
	Frm => (get_obj g_form pt p, (lev_on o lev_dn) p)
neuper@37906
   612
      | Res => ((fst o (get_obj g_result pt)) p, (lev_on o lev_dn o lev_on) p)
neuper@38031
   613
      | _ => error ("applicable_in: call by "^
neuper@37906
   614
				(pos'2str (p,p_)));
neuper@37906
   615
      val thy' = get_obj g_domID pt (par_pblobj pt p);
neuper@37906
   616
    in (Appl (Begin_Trans' f))
neuper@38031
   617
      handle _ => error ("applicable_in: Begin_Trans finds \
neuper@37906
   618
                               \syntaxerror in '"^(term2str f)^"'") end
neuper@37906
   619
neuper@37906
   620
    (*TODO: check parent branches*)
neuper@37906
   621
  | applicable_in (p,p_) pt (End_Trans) =
neuper@37906
   622
    let val thy' = get_obj g_domID pt (par_pblobj pt p);
neuper@37906
   623
    in if p_ = Res 
neuper@42394
   624
	     then Appl (End_Trans' (get_obj g_result pt p))
neuper@42394
   625
       else Notappl "'End_Trans' is not applicable at the beginning of a transitive sequence"
neuper@42394
   626
       (*TODO: check parent branches*)
neuper@37906
   627
    end
neuper@42394
   628
  | applicable_in p pt (Begin_Sequ) = 
neuper@42394
   629
      error ("applicable_in: not impl. for " ^ tac2str (Begin_Sequ))
neuper@42394
   630
  | applicable_in p pt (End_Sequ) = 
neuper@42394
   631
      error ("applicable_in: not impl. for " ^ tac2str (End_Sequ))
neuper@42394
   632
  | applicable_in p pt (Split_Intersect) = 
neuper@42394
   633
      error ("applicable_in: not impl. for " ^ tac2str (Split_Intersect))
neuper@42394
   634
  | applicable_in p pt (End_Intersect) = 
neuper@42394
   635
      error ("applicable_in: not impl. for " ^ tac2str (End_Intersect))
neuper@37906
   636
neuper@37906
   637
  | applicable_in (p,p_) pt (m as Check_elementwise pred) = 
neuper@42394
   638
    if member op = [Pbl,Met] p_ 
neuper@37906
   639
    then Notappl ((tac2str m)^" not for pos "^(pos'2str (p,p_)))
neuper@42394
   640
    else
neuper@42394
   641
      let 
neuper@42394
   642
        val pp = par_pblobj pt p; 
neuper@42394
   643
        val thy' = (get_obj g_domID pt pp):theory';
neuper@42394
   644
        val thy = assoc_thy thy'
neuper@42394
   645
        val metID = (get_obj g_metID pt pp)
neuper@42394
   646
        val {crls,...} =  get_met metID
neuper@42394
   647
        val (f,asm) = case p_ of Frm => (get_obj g_form pt p , [])
neuper@42394
   648
                               | Res => get_obj g_result pt p;
neuper@42394
   649
        val vp = (thy2ctxt thy, pred) |-> parseNEW |> the |> mk_set thy pt p f;
neuper@42394
   650
      in case f of
neuper@42394
   651
           Const ("List.list.Cons",_) $ _ $ _ =>
neuper@42394
   652
             Appl (Check_elementwise' (f, pred, check_elementwise thy crls f vp))
neuper@42394
   653
         | Const ("Tools.UniversalList",_) => 
neuper@42394
   654
             Appl (Check_elementwise' (f, pred, (f,asm)))
neuper@42394
   655
         | Const ("List.list.Nil",_) => 
neuper@42394
   656
             Appl (Check_elementwise' (f, pred, (f, asm)))
neuper@42394
   657
         | _ => Notappl ("Check_elementwise not applicable: "^(term2str f)^" should be constants")
neuper@42394
   658
      end
neuper@37906
   659
neuper@37906
   660
  | applicable_in (p,p_) pt Or_to_List = 
neuper@37935
   661
  if member op = [Pbl,Met] p_ 
neuper@37906
   662
    then Notappl ((tac2str Or_to_List)^" not for pos "^(pos'2str (p,p_)))
neuper@37906
   663
  else
neuper@37906
   664
  let 
neuper@37906
   665
    val pp = par_pblobj pt p; 
neuper@37906
   666
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   667
    val thy = assoc_thy thy';
neuper@37906
   668
    val f = case p_ of
neuper@37906
   669
              Frm => get_obj g_form pt p
neuper@37906
   670
	    | Res => (fst o (get_obj g_result pt)) p;
neuper@37906
   671
  in (let val ls = or2list f
neuper@37906
   672
      in Appl (Or_to_List' (f, ls)) end) 
neuper@37906
   673
     handle _ => Notappl ("'Or_to_List' not applicable to "^(term2str f))
neuper@37906
   674
  end
neuper@37906
   675
neuper@37906
   676
  | applicable_in p pt (Collect_Trues) = 
neuper@38031
   677
  error ("applicable_in: not impl. for "^
neuper@37906
   678
	       (tac2str (Collect_Trues)))
neuper@37906
   679
neuper@37906
   680
  | applicable_in p pt (Empty_Tac) = 
neuper@37906
   681
  Notappl "Empty_Tac is not applicable"
neuper@37906
   682
neuper@41933
   683
  | applicable_in (p,p_) pt (Tac id) =
neuper@37906
   684
  let 
neuper@37906
   685
    val pp = par_pblobj pt p; 
neuper@37906
   686
    val thy' = (get_obj g_domID pt pp):theory';
neuper@37906
   687
    val thy = assoc_thy thy';
neuper@37906
   688
    val f = case p_ of
neuper@37906
   689
              Frm => get_obj g_form pt p
neuper@41933
   690
            | Pbl => error "applicable_in (p,Pbl) pt (Tac id): not at Pbl"
neuper@37906
   691
	    | Res => (fst o (get_obj g_result pt)) p;
neuper@37906
   692
  in case id of
neuper@37906
   693
      "subproblem_equation_dummy" =>
neuper@37906
   694
	  if is_expliceq f
neuper@37906
   695
	  then Appl (Tac_ (thy, term2str f, id,
neuper@37906
   696
			     "subproblem_equation_dummy ("^(term2str f)^")"))
neuper@37906
   697
	  else Notappl "applicable only to equations made explicit"
neuper@37906
   698
    | "solve_equation_dummy" =>
neuper@38015
   699
	  let (*val _= tracing("### applicable_in: solve_equation_dummy: f= "
neuper@37906
   700
				 ^f);*)
neuper@37906
   701
	    val (id',f') = split_dummy (term2str f);
neuper@38015
   702
	    (*val _= tracing("### applicable_in: f'= "^f');*)
wneuper@59186
   703
	    (*val _= (Thm.term_of o the o (parse thy)) f';*)
neuper@38015
   704
	    (*val _= tracing"### applicable_in: solve_equation_dummy";*)
neuper@37906
   705
	  in if id' <> "subproblem_equation_dummy" then Notappl "no subproblem"
bonzai@41952
   706
	     else if (thy2ctxt thy, f') |-> parseNEW |> the |> is_expliceq
neuper@37906
   707
		      then Appl (Tac_ (thy, term2str f, id, "[" ^ f' ^ "]"))
neuper@37906
   708
		  else error ("applicable_in: f= " ^ f') end
neuper@37906
   709
    | _ => Appl (Tac_ (thy, term2str f, id, term2str f)) end
neuper@37906
   710
neuper@37906
   711
  | applicable_in p pt End_Proof' = Appl End_Proof''
neuper@37906
   712
neuper@37906
   713
  | applicable_in _ _ m = 
neuper@38031
   714
  error ("applicable_in called for "^(tac2str m));
neuper@37906
   715
neuper@37906
   716
(*WN060614 unused*)
neuper@37906
   717
fun tac2tac_ pt p m = 
neuper@37906
   718
    case applicable_in p pt m of
neuper@37906
   719
	Appl (m') => m' 
neuper@38031
   720
      | Notappl _ => error ("tac2mstp': fails with"^
neuper@37906
   721
				  (tac2str m));
neuper@37906
   722