src/Tools/isac/ProgLang/term.sml
branchisac-update-Isa09-2
changeset 38025 67a110289e4e
parent 38024 20231cdf39e7
child 38029 bd062a85ec67
     1.1 --- a/src/Tools/isac/ProgLang/term.sml	Mon Sep 27 13:35:06 2010 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1219 +0,0 @@
     1.4 -(* extends Isabelle/src/Pure/term.ML
     1.5 -   (c) Walther Neuper 1999
     1.6 -
     1.7 -use"ProgLang/term.sml";
     1.8 -use"term.sml";
     1.9 -*)
    1.10 -
    1.11 -(*
    1.12 -> (cterm_of thy) a_term;
    1.13 -val it = "empty" : cterm        *)
    1.14 -
    1.15 -(*2003 fun match thy t pat =
    1.16 -    (snd (Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t)))
    1.17 -    handle _ => [];
    1.18 -fn : theory ->
    1.19 -     Term.term -> Term.term -> (Term.indexname * Term.term) list*)
    1.20 -(*see src/Tools/eqsubst.ML fun clean_match*)
    1.21 -(*2003 fun matches thy tm pa = if match thy tm pa = [] then false else true;*)
    1.22 -fun matches thy tm pa = 
    1.23 -    (Pattern.match thy (pa, tm) (Vartab.empty, Vartab.empty); true)
    1.24 -    handle _ => false
    1.25 -
    1.26 -fun atomtyp t = (*WN10 see raw_pp_typ*)
    1.27 -  let
    1.28 -    fun ato n (Type (s,[])) = 
    1.29 -      ("\n*** "^indent n^"Type ("^s^",[])")
    1.30 -      | ato n (Type (s,Ts)) =
    1.31 -      ("\n*** "^indent n^"Type ("^s^",["^ atol (n+1) Ts)
    1.32 -
    1.33 -      | ato n (TFree (s,sort)) =
    1.34 -      ("\n*** "^indent n^"TFree ("^s^",["^ strs2str' sort)
    1.35 -
    1.36 -      | ato n (TVar ((s,i),sort)) =
    1.37 -      ("\n*** "^indent n^"TVar (("^s^","^ 
    1.38 -       string_of_int i ^ strs2str' sort)
    1.39 -    and atol n [] = 
    1.40 -      ("\n*** "^indent n^"]")
    1.41 -      | atol n (T::Ts) = (ato n T ^ atol n Ts)
    1.42 -(*in print (ato 0 t ^ "\n") end;  TODO TUM10*)
    1.43 -in tracing (ato 0 t) end;
    1.44 -(*
    1.45 -> val T = (type_of o term_of o the o (parse thy)) "a::[real,int] => nat";
    1.46 -> atomtyp T;
    1.47 -*** Type (fun,[
    1.48 -***   Type (RealDef.real,[])
    1.49 -***   Type (fun,[
    1.50 -***     Type (IntDef.int,[])
    1.51 -***     Type (nat,[])
    1.52 -***     ]
    1.53 -***   ]
    1.54 -*)
    1.55 -
    1.56 -(*Prog.Tutorial.p.34, Makarius 1005 does the above like this..*)
    1.57 -local
    1.58 -   fun pp_pair (x, y) = Pretty.list "(" ")" [x, y]
    1.59 -   fun pp_list xs = Pretty.list "[" "]" xs
    1.60 -   fun pp_str s   = Pretty.str s
    1.61 -   fun pp_qstr s = Pretty.quote (pp_str s)
    1.62 -   fun pp_int i   = pp_str (string_of_int i)
    1.63 -   fun pp_sort S = pp_list (map pp_qstr S)
    1.64 -   fun pp_constr a args = Pretty.block [pp_str a, Pretty.brk 1, args]
    1.65 -in
    1.66 -fun raw_pp_typ (TVar ((a, i), S)) =
    1.67 -       pp_constr "TVar" (pp_pair (pp_pair (pp_qstr a, pp_int i), pp_sort S))
    1.68 -   | raw_pp_typ (TFree (a, S)) =
    1.69 -       pp_constr "TFree" (pp_pair (pp_qstr a, pp_sort S))
    1.70 -   | raw_pp_typ (Type (a, tys)) =
    1.71 -       pp_constr "Type" (pp_pair (pp_qstr a, pp_list (map raw_pp_typ tys)))
    1.72 -end
    1.73 -(* install
    1.74 -PolyML.addPrettyPrinter
    1.75 -  (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ);
    1.76 -de-install
    1.77 -PolyML.addPrettyPrinter
    1.78 -  (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy);
    1.79 -*)
    1.80 -
    1.81 -fun atomt t =
    1.82 -    let fun ato (Const (a, _)) n = 
    1.83 -	           "\n*** " ^ indent n ^ "Const (" ^ a ^ ", _)"
    1.84 -	  | ato (Free (a, _)) n =  
    1.85 -	           "\n*** " ^ indent n ^ "Free (" ^ a ^ ", _)"
    1.86 -	  | ato (Var ((a, i), _)) n =
    1.87 -	           "\n*** " ^ indent n ^ "Var (" ^ a ^ ", " ^ 
    1.88 -                                               string_of_int i ^ "), _)"
    1.89 -	  | ato (Bound i) n = 
    1.90 -	           "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
    1.91 -	  | ato (Abs (a, _, body)) n = 
    1.92 -	           "\n*** " ^ indent n ^ "Abs(" ^ a ^ ", _" ^ ato body (n+1)
    1.93 -	  | ato (f $ t) n = (ato f n ^ ato t (n + 1))
    1.94 -    in tracing ("\n*** -------------" ^ ato t 0 ^ "\n***") end;
    1.95 -
    1.96 -fun term_detail2str t =
    1.97 -    let fun ato (Const (a, T)) n = 
    1.98 -	    "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ T ^ ")"
    1.99 -	  | ato (Free (a, T)) n =  
   1.100 -	    "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ T ^ ")"
   1.101 -	  | ato (Var ((a, i), T)) n =
   1.102 -	    "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^
   1.103 -	    string_of_typ T ^ ")"
   1.104 -	  | ato (Bound i) n = 
   1.105 -	    "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
   1.106 -	  | ato (Abs(a, T, body))  n = 
   1.107 -	    "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ T ^ ",.."
   1.108 -	    ^ ato body (n + 1)
   1.109 -	  | ato (f $ t) n = ato f n ^ ato t (n + 1)
   1.110 -    in "\n*** " ^ ato t 0 ^ "\n***" end;
   1.111 -fun atomty t = (tracing o term_detail2str) t; (*WN100907 broken*)
   1.112 -
   1.113 -fun term_str thy (Const(s,_)) = s
   1.114 -  | term_str thy (Free(s,_)) = s
   1.115 -  | term_str thy (Var((s,i),_)) = s^(string_of_int i)
   1.116 -  | term_str thy (Bound i) = "B."^(string_of_int i)
   1.117 -  | term_str thy (Abs(s,_,_)) = s
   1.118 -  | term_str thy t = raise error("term_str not for "^term2str t);
   1.119 -
   1.120 -(*.contains the fst argument the second argument (a leave! of term).*)
   1.121 -fun contains_term (Abs(_,_,body)) t = contains_term body t 
   1.122 -  | contains_term (f $ f') t = 
   1.123 -    contains_term f t orelse contains_term f' t
   1.124 -  | contains_term s t = t = s;
   1.125 -(*.contains the term a VAR(("*",_),_) ?.*)
   1.126 -fun contains_Var (Abs(_,_,body)) = contains_Var body
   1.127 -  | contains_Var (f $ f') = contains_Var f orelse contains_Var f'
   1.128 -  | contains_Var (Var _) = true
   1.129 -  | contains_Var _ = false;
   1.130 -(* contains_Var (str2term "?z = 3") (*true*);
   1.131 -   contains_Var (str2term "z = 3")  (*false*);
   1.132 -   *)
   1.133 -
   1.134 -(*fun int_of_str str =
   1.135 -    let val ss = explode str
   1.136 -	val str' = case ss of
   1.137 -	   "("::s => drop_last s | _ => ss
   1.138 -    in case BasisLibrary.Int.fromString (implode str') of
   1.139 -	     SOME i => SOME i
   1.140 -	   | NONE => NONE end;*)
   1.141 -fun int_of_str str =
   1.142 -    let val ss = explode str
   1.143 -	val str' = case ss of
   1.144 -	   "("::s => drop_last s | _ => ss
   1.145 -    in (SOME (Thy_Output.integer (implode str'))) handle _ => NONE end;
   1.146 -(*
   1.147 -> int_of_str "123";
   1.148 -val it = SOME 123 : int option
   1.149 -> int_of_str "(-123)";
   1.150 -val it = SOME 123 : int option
   1.151 -> int_of_str "#123";
   1.152 -val it = NONE : int option
   1.153 -> int_of_str "-123";
   1.154 -val it = SOME ~123 : int option
   1.155 -*)
   1.156 -fun int_of_str' str = 
   1.157 -    case int_of_str str of
   1.158 -	SOME i => i
   1.159 -      | NONE => raise TERM ("int_of_string: no int-string",[]);
   1.160 -val str2int = int_of_str';
   1.161 -    
   1.162 -fun is_numeral str = case int_of_str str of
   1.163 -			 SOME _ => true
   1.164 -		       | NONE => false;
   1.165 -val is_no = is_numeral;
   1.166 -fun is_num (Free (s,_)) = if is_numeral s then true else false
   1.167 -  | is_num _ = false;
   1.168 -(*>
   1.169 -> is_num ((term_of o the o (parse thy)) "#1");
   1.170 -val it = true : bool
   1.171 -> is_num ((term_of o the o (parse thy)) "#-1");
   1.172 -val it = true : bool
   1.173 -> is_num ((term_of o the o (parse thy)) "a123");
   1.174 -val it = false : bool
   1.175 -*)
   1.176 -
   1.177 -(*fun int_of_Free (Free (intstr, _)) =
   1.178 -    (case BasisLibrary.Int.fromString intstr of
   1.179 -	     SOME i => i
   1.180 -	   | NONE => raise error ("int_of_Free ( "^ intstr ^", _)"))
   1.181 -  | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");*)
   1.182 -fun int_of_Free (Free (intstr, _)) = (Thy_Output.integer intstr
   1.183 -    handle _ => raise error ("int_of_Free ( "^ intstr ^", _)"))
   1.184 -  | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");
   1.185 -
   1.186 -fun vars t =
   1.187 -  let
   1.188 -    fun scan vs (Const(s,T)) = vs
   1.189 -      | scan vs (t as Free(s,T)) = if is_no s then vs else t::vs
   1.190 -      | scan vs (t as Var((s,i),T)) = t::vs
   1.191 -      | scan vs (Bound i) = vs 
   1.192 -      | scan vs (Abs(s,T,t)) = scan vs t
   1.193 -      | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
   1.194 -  in (distinct o (scan [])) t end;
   1.195 -
   1.196 -fun is_Free (Free _) = true
   1.197 -  | is_Free _ = false;
   1.198 -fun is_fun_id (Const _) = true
   1.199 -  | is_fun_id (Free _) = true
   1.200 -  | is_fun_id _ = false;
   1.201 -fun is_f_x (f $ x) = is_fun_id f andalso is_Free x
   1.202 -  | is_f_x _ = false;
   1.203 -(* is_f_x (str2term "q_0/2 * L * x") (*false*);
   1.204 -   is_f_x (str2term "M_b x") (*true*);
   1.205 -  *)
   1.206 -fun vars_str t =
   1.207 -  let
   1.208 -    fun scan vs (Const(s,T)) = vs
   1.209 -      | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
   1.210 -      | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
   1.211 -      | scan vs (Bound i) = vs 
   1.212 -      | scan vs (Abs(s,T,t)) = scan vs t
   1.213 -      | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
   1.214 -  in (distinct o (scan [])) t end;
   1.215 -
   1.216 -fun ids2str t =
   1.217 -  let
   1.218 -    fun scan vs (Const(s,T)) = if is_no s then vs else s::vs
   1.219 -      | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
   1.220 -      | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
   1.221 -      | scan vs (Bound i) = vs 
   1.222 -      | scan vs (Abs(s,T,t)) = scan (s::vs) t
   1.223 -      | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
   1.224 -  in (distinct o (scan [])) t end;
   1.225 -fun is_bdv str =
   1.226 -    case explode str of
   1.227 -	"b"::"d"::"v"::_ => true
   1.228 -      | _ => false;
   1.229 -fun is_bdv_ (Free (s,_)) = is_bdv s
   1.230 -  | is_bdv_ _ = false;
   1.231 -
   1.232 -fun free2str (Free (s,_)) = s
   1.233 -  | free2str t = raise error ("free2str not for "^ term2str t);
   1.234 -fun free2int (t as Free (s, _)) = ((str2int s)
   1.235 -    handle _ => raise error ("free2int: "^term_detail2str t))
   1.236 -  | free2int t = raise error ("free2int: "^term_detail2str t);
   1.237 -
   1.238 -(*27.8.01: unused*)
   1.239 -fun var2free (t as Const(s,T)) = t
   1.240 -  | var2free (t as Free(s,T)) = t
   1.241 -  | var2free (Var((s,i),T)) = Free(s,T)
   1.242 -  | var2free (t as Bound i) = t 
   1.243 -  | var2free (Abs(s,T,t)) = Abs(s,T,var2free t)
   1.244 -  | var2free (t1 $ t2) = (var2free t1) $ (var2free t2);
   1.245 -  
   1.246 -(*27.8.01: doesn't find some subterm ???!???*)
   1.247 -(*2010 Logic.varify !!!*)
   1.248 -fun free2var (t as Const(s,T)) = t
   1.249 -  | free2var (t as Free(s,T)) = if is_no s then t else Var((s,0),T)
   1.250 -  | free2var (t as Var((s,i),T)) = t
   1.251 -  | free2var (t as Bound i) = t 
   1.252 -  | free2var (Abs(s,T,t)) = Abs(s,T,free2var t)
   1.253 -  | free2var (t1 $ t2) = (free2var t1) $ (free2var t2);
   1.254 -  
   1.255 -
   1.256 -fun mk_listT T = Type ("List.list", [T]);
   1.257 -fun list_const T = 
   1.258 -  Const("List.list.Cons", [T, mk_listT T] ---> mk_listT T);
   1.259 -(*28.8.01: TODO: get type from head of list: 1 arg less!!!*)
   1.260 -fun list2isalist T [] = Const("List.list.Nil",mk_listT T)
   1.261 -  | list2isalist T (t::ts) = (list_const T) $ t $ (list2isalist T ts);
   1.262 -(*
   1.263 -> val tt = (term_of o the o (parse thy)) "R=(R::real)";
   1.264 -> val TT = type_of tt;
   1.265 -> val ss = list2isalist TT [tt,tt,tt];
   1.266 -> (cterm_of thy) ss;
   1.267 -val it = "[R = R, R = R, R = R]" : cterm  *)
   1.268 -
   1.269 -fun isapair2pair (Const ("Pair",_) $ a $ b) = (a,b)
   1.270 -  | isapair2pair t = 
   1.271 -    raise error ("isapair2pair called with "^term2str t);
   1.272 -
   1.273 -val listType = Type ("List.list",[Type ("bool",[])]);
   1.274 -fun isalist2list ls =
   1.275 -  let
   1.276 -    fun get es (Const("List.list.Cons",_) $ t $ ls) = get (t::es) ls
   1.277 -      | get es (Const("List.list.Nil",_)) = es
   1.278 -      | get _ t = 
   1.279 -	raise error ("isalist2list applied to NON-list '"^term2str t^"'")
   1.280 -  in (rev o (get [])) ls end;
   1.281 -(*      
   1.282 -> val il = str2term "[a=b,c=d,e=f]";
   1.283 -> val l = isalist2list il;
   1.284 -> (tracing o terms2str) l;
   1.285 -["a = b","c = d","e = f"]
   1.286 -
   1.287 -> val il = str2term "ss___::bool list";
   1.288 -> val l = isalist2list il;
   1.289 -[Free ("ss___", "bool List.list")]
   1.290 -*)
   1.291 -
   1.292 -
   1.293 -(*review Isabelle2009/src/HOL/Tools/hologic.ML*)
   1.294 -val prop = Type ("prop",[]);     (* ~/Diss.99/Integers-Isa/tools.sml*)
   1.295 -val bool = Type ("bool",[]);     (* 2002 Integ.int *)
   1.296 -val Trueprop = Const("Trueprop",bool-->prop);
   1.297 -fun mk_prop t = Trueprop $ t;
   1.298 -val true_as_term = Const("True",bool);
   1.299 -val false_as_term = Const("False",bool);
   1.300 -val true_as_cterm = cterm_of (theory "HOL") true_as_term;
   1.301 -val false_as_cterm = cterm_of (theory "HOL") false_as_term;
   1.302 -
   1.303 -infixr 5 -->;                    (*2002 /Pure/term.ML *)
   1.304 -infixr --->;			 (*2002 /Pure/term.ML *)
   1.305 -fun S --> T = Type("fun",[S,T]); (*2002 /Pure/term.ML *)
   1.306 -val op ---> = foldr (op -->);    (*2002 /Pure/term.ML *)
   1.307 -fun list_implies ([], B) = B : term (*2002 /term.ML *)
   1.308 -  | list_implies (A::AS, B) = Logic.implies $ A $ list_implies(AS,B);
   1.309 -
   1.310 -
   1.311 -
   1.312 -(** substitution **)
   1.313 -
   1.314 -fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) =      (* = thm.ML *)
   1.315 -      match_bvs(s, t, if x="" orelse y="" then al
   1.316 -                                          else (x,y)::al)
   1.317 -  | match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al))
   1.318 -  | match_bvs(_,_,al) = al;
   1.319 -fun ren_inst(insts,prop,pat,obj) =              (* = thm.ML *)
   1.320 -  let val ren = match_bvs(pat,obj,[])
   1.321 -      fun renAbs(Abs(x,T,b)) =
   1.322 -            Abs(case assoc_string(ren,x) of NONE => x 
   1.323 -	  | SOME(y) => y, T, renAbs(b))
   1.324 -        | renAbs(f$t) = renAbs(f) $ renAbs(t)
   1.325 -        | renAbs(t) = t
   1.326 -  in subst_vars insts (if null(ren) then prop else renAbs(prop)) end;
   1.327 -
   1.328 -
   1.329 -
   1.330 -
   1.331 -
   1.332 -
   1.333 -fun dest_equals' (Const("op =",_) $ t $ u)  =  (t,u)(* logic.ML: Const("=="*)
   1.334 -  | dest_equals' t = raise TERM("dest_equals'", [t]);
   1.335 -val lhs_ = (fst o dest_equals');
   1.336 -val rhs_ = (snd o dest_equals');
   1.337 -
   1.338 -fun is_equality (Const("op =",_) $ t $ u)  =  true  (* logic.ML: Const("=="*)
   1.339 -  | is_equality _ = false;
   1.340 -fun mk_equality (t,u) = (Const("op =",[type_of t,type_of u]--->bool) $ t $ u); 
   1.341 -fun is_expliceq (Const("op =",_) $ (Free _) $ u)  =  true
   1.342 -  | is_expliceq _ = false;
   1.343 -fun strip_trueprop (Const("Trueprop",_) $ t) = t
   1.344 -  | strip_trueprop t = t;
   1.345 -(*  | strip_trueprop t = raise TERM("strip_trueprop", [t]);
   1.346 -*)
   1.347 -
   1.348 -(*.(A1==>...An==>B) goes to (A1==>...An==>).*)
   1.349 -fun strip_imp_prems' (Const("==>", T) $ A $ t) = 
   1.350 -    let fun coll_prems As (Const("==>", _) $ A $ t) = 
   1.351 -	    coll_prems (As $ (Logic.implies $ A)) t
   1.352 -	  | coll_prems As _ = SOME As
   1.353 -    in coll_prems (Logic.implies $ A) t end
   1.354 -  | strip_imp_prems' _ = NONE;  (* logic.ML: term -> term list*)
   1.355 -(*
   1.356 -  val thm = real_mult_div_cancel1;
   1.357 -  val prop = (#prop o rep_thm) thm;
   1.358 -  atomt prop;
   1.359 -*** -------------
   1.360 -*** Const ( ==>)
   1.361 -*** . Const ( Trueprop)
   1.362 -*** . . Const ( Not)
   1.363 -*** . . . Const ( op =)
   1.364 -*** . . . . Var ((k, 0), )
   1.365 -*** . . . . Const ( 0)
   1.366 -*** . Const ( Trueprop)
   1.367 -*** . . Const ( op =)                                                          *** .............
   1.368 -  val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
   1.369 -  atomt t;
   1.370 -*** -------------
   1.371 -*** Const ( ==>)
   1.372 -*** . Const ( Trueprop)
   1.373 -*** . . Const ( Not)
   1.374 -*** . . . Const ( op =)
   1.375 -*** . . . . Var ((k, 0), )
   1.376 -*** . . . . Const ( 0)
   1.377 -
   1.378 -  val thm = real_le_anti_sym;
   1.379 -  val prop = (#prop o rep_thm) thm;
   1.380 -  atomt prop;
   1.381 -*** -------------
   1.382 -*** Const ( ==>)
   1.383 -*** . Const ( Trueprop)
   1.384 -*** . . Const ( op <=)
   1.385 -*** . . . Var ((z, 0), )
   1.386 -*** . . . Var ((w, 0), )
   1.387 -*** . Const ( ==>)
   1.388 -*** . . Const ( Trueprop)
   1.389 -*** . . . Const ( op <=)
   1.390 -*** . . . . Var ((w, 0), )
   1.391 -*** . . . . Var ((z, 0), )
   1.392 -*** . . Const ( Trueprop)
   1.393 -*** . . . Const ( op =)
   1.394 -*** .............
   1.395 -  val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
   1.396 -  atomt t;
   1.397 -*** -------------
   1.398 -*** Const ( ==>)
   1.399 -*** . Const ( Trueprop)
   1.400 -*** . . Const ( op <=)
   1.401 -*** . . . Var ((z, 0), )
   1.402 -*** . . . Var ((w, 0), )
   1.403 -*** . Const ( ==>)
   1.404 -*** . . Const ( Trueprop)
   1.405 -*** . . . Const ( op <=)
   1.406 -*** . . . . Var ((w, 0), )
   1.407 -*** . . . . Var ((z, 0), )
   1.408 -*)
   1.409 -
   1.410 -(*. (A1==>...An==>) (B) goes to (A1==>...An==>B), where B is lowest branch.*)
   1.411 -fun ins_concl (Const("==>", T) $ A $ t) B = Logic.implies $ A $ (ins_concl t B)
   1.412 -  | ins_concl (Const("==>", T) $ A    ) B = Logic.implies $ A $ B
   1.413 -  | ins_concl t B =  raise TERM("ins_concl", [t, B]);
   1.414 -(*
   1.415 -  val thm = real_le_anti_sym;
   1.416 -  val prop = (#prop o rep_thm) thm;
   1.417 -  val concl = Logic.strip_imp_concl prop;
   1.418 -  val SOME prems = strip_imp_prems' prop;
   1.419 -  val prop' = ins_concl prems concl;
   1.420 -  prop = prop';
   1.421 -  atomt prop;
   1.422 -  atomt prop';
   1.423 -*)
   1.424 -
   1.425 -
   1.426 -fun vperm (Var _, Var _) = true  (*2002 Pure/thm.ML *)
   1.427 -  | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t)
   1.428 -  | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2)
   1.429 -  | vperm (t, u) = (t = u);
   1.430 -
   1.431 -(*2002 cp from Pure/term.ML --- since 2009 in Pure/old_term.ML*)
   1.432 -fun mem_term (_, []) = false
   1.433 -  | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts);
   1.434 -fun subset_term ([], ys) = true
   1.435 -  | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys);
   1.436 -fun eq_set_term (xs, ys) =
   1.437 -    xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs));
   1.438 -(*a total, irreflexive ordering on index names*)
   1.439 -fun xless ((a,i), (b,j): indexname) = i<j  orelse  (i=j andalso a<b);
   1.440 -(*a partial ordering (not reflexive) for atomic terms*)
   1.441 -fun atless (Const (a,_), Const (b,_))  =  a<b
   1.442 -  | atless (Free (a,_), Free (b,_)) =  a<b
   1.443 -  | atless (Var(v,_), Var(w,_))  =  xless(v,w)
   1.444 -  | atless (Bound i, Bound j)  =   i<j
   1.445 -  | atless _  =  false;
   1.446 -(*insert atomic term into partially sorted list, suppressing duplicates (?)*)
   1.447 -fun insert_aterm (t,us) =
   1.448 -  let fun inserta [] = [t]
   1.449 -        | inserta (us as u::us') =
   1.450 -              if atless(t,u) then t::us
   1.451 -              else if t=u then us (*duplicate*)
   1.452 -              else u :: inserta(us')
   1.453 -  in  inserta us  end;
   1.454 -
   1.455 -(*Accumulates the Vars in the term, suppressing duplicates*)
   1.456 -fun add_term_vars (t, vars: term list) = case t of
   1.457 -    Var   _ => insert_aterm(t,vars)
   1.458 -  | Abs (_,_,body) => add_term_vars(body,vars)
   1.459 -  | f$t =>  add_term_vars (f, add_term_vars(t, vars))
   1.460 -  | _ => vars;
   1.461 -fun term_vars t = add_term_vars(t,[]);
   1.462 -
   1.463 -
   1.464 -fun var_perm (t, u) = (*2002 Pure/thm.ML *)
   1.465 -  vperm (t, u) andalso eq_set_term (term_vars t, term_vars u);
   1.466 -    
   1.467 -(*2002 fun decomp_simp, Pure/thm.ML *)
   1.468 -fun perm lhs rhs = var_perm (lhs, rhs) andalso not (lhs aconv rhs)
   1.469 -    andalso not (is_Var lhs);
   1.470 -
   1.471 -
   1.472 -fun str_of_int n = 
   1.473 -  if n < 0 then "-"^((string_of_int o abs) n)
   1.474 -  else string_of_int n;
   1.475 -(*
   1.476 -> str_of_int 1;
   1.477 -val it = "1" : string                                                          > str_of_int ~1;
   1.478 -val it = "-1" : string
   1.479 -*)
   1.480 -
   1.481 -
   1.482 -fun power b 0 = 1
   1.483 -  | power b n = 
   1.484 -  if n>0 then b*(power b (n-1))
   1.485 -  else raise error ("power "^(str_of_int b)^" "^(str_of_int n));
   1.486 -(*
   1.487 -> power 2 3;
   1.488 -val it = 8 : int
   1.489 -> power ~2 3;
   1.490 -val it = ~8 : int
   1.491 -> power ~3 2;
   1.492 -val it = 9 : int
   1.493 -> power 3 ~2;
   1.494 -*)
   1.495 -fun gcd 0 b = b
   1.496 -  | gcd a b = if a < b then gcd (b mod a) a
   1.497 -	      else gcd (a mod b) b;
   1.498 -fun sign n = if n < 0 then ~1
   1.499 -	     else if n = 0 then 0 else 1;
   1.500 -fun sign2 n1 n2 = (sign n1) * (sign n2);
   1.501 -
   1.502 -infix dvd;
   1.503 -fun d dvd n = n mod d = 0;
   1.504 -
   1.505 -fun divisors n =
   1.506 -  let fun pdiv ds d n = 
   1.507 -    if d=n then d::ds
   1.508 -    else if d dvd n then pdiv (d::ds) d (n div d)
   1.509 -	 else pdiv ds (d+1) n
   1.510 -  in pdiv [] 2 n end;
   1.511 -
   1.512 -divisors 30;
   1.513 -divisors 32;
   1.514 -divisors 60;
   1.515 -divisors 11;
   1.516 -
   1.517 -fun doubles ds = (* ds is ordered *)
   1.518 -  let fun dbls ds [] = ds
   1.519 -	| dbls ds [i] = ds
   1.520 -	| dbls ds (i::i'::is) = if i=i' then dbls (i::ds) is
   1.521 -				else dbls ds (i'::is)
   1.522 -  in dbls [] ds end;
   1.523 -(*> doubles [2,3,4];
   1.524 -val it = [] : int list
   1.525 -> doubles [2,3,3,5,5,7];
   1.526 -val it = [5,3] : int list*)
   1.527 -
   1.528 -fun squfact 0 = 0
   1.529 -  | squfact 1 = 1
   1.530 -  | squfact n = foldl op* (1, (doubles o divisors) n);
   1.531 -(*> squfact 30;
   1.532 -val it = 1 : int
   1.533 -> squfact 32;
   1.534 -val it = 4 : int
   1.535 -> squfact 60;
   1.536 -val it = 2 : int
   1.537 -> squfact 11;
   1.538 -val it = 1 : int*)
   1.539 -
   1.540 -
   1.541 -fun dest_type (Type(T,[])) = T
   1.542 -  | dest_type T = 
   1.543 -    (atomtyp T;
   1.544 -     raise error ("... dest_type: not impl. for this type"));
   1.545 -
   1.546 -fun term_of_num ntyp n = Free (str_of_int n, ntyp);
   1.547 -
   1.548 -fun pairT T1 T2 = Type ("*", [T1, T2]);
   1.549 -(*> val t = str2term "(1,2)";
   1.550 -> type_of t = pairT HOLogic.realT HOLogic.realT;
   1.551 -val it = true : bool
   1.552 -*)
   1.553 -fun PairT T1 T2 = ([T1, T2] ---> Type ("*", [T1, T2]));
   1.554 -(*> val t = str2term "(1,2)";
   1.555 -> val Const ("Pair",pT) $ _ $ _ = t;
   1.556 -> pT = PairT HOLogic.realT HOLogic.realT;
   1.557 -val it = true : bool
   1.558 -*)
   1.559 -fun pairt t1 t2 =
   1.560 -    Const ("Pair", PairT (type_of t1) (type_of t2)) $ t1 $ t2;
   1.561 -(*> val t = str2term "(1,2)";
   1.562 -> val (t1, t2) = (str2term "1", str2term "2");
   1.563 -> t = pairt t1 t2;
   1.564 -val it = true : bool*)
   1.565 -
   1.566 -
   1.567 -fun num_of_term (t as Free (s,_)) = 
   1.568 -    (case int_of_str s of
   1.569 -	 SOME s' => s'
   1.570 -       | NONE => raise error ("num_of_term not for "^ term2str t))
   1.571 -  | num_of_term t = raise error ("num_of_term not for "^term2str t);
   1.572 -
   1.573 -fun mk_factroot op_(*=thy.sqrt*) T fact root = 
   1.574 -  Const ("op *", [T, T] ---> T) $ (term_of_num T fact) $
   1.575 -  (Const (op_, T --> T) $ term_of_num T root);
   1.576 -(*
   1.577 -val T =  (type_of o term_of o the) (parse thy "#12::real");
   1.578 -val t = mk_factroot "SqRoot.sqrt" T 2 3;
   1.579 -(cterm_of thy) t;
   1.580 -val it = "#2 * sqrt #3 " : cterm
   1.581 -*)
   1.582 -fun var_op_num v op_ optype ntyp n =
   1.583 -  Const (op_, optype) $ v $ 
   1.584 -   Free (str_of_int  n, ntyp);
   1.585 -
   1.586 -fun num_op_var v op_ optype ntyp n =
   1.587 -  Const (op_,optype) $  
   1.588 -   Free (str_of_int n, ntyp) $ v;
   1.589 -
   1.590 -fun num_op_num T1 T2 (op_,Top) n1 n2 = 
   1.591 -  Const (op_,Top) $ 
   1.592 -  Free (str_of_int n1, T1) $ Free (str_of_int n2, T2);
   1.593 -(*
   1.594 -> val t = num_op_num "Int" 3 4;
   1.595 -> atomty t;
   1.596 -> string_of_cterm ((cterm_of thy) t);
   1.597 -*)
   1.598 -
   1.599 -fun const_in str (Const _) = false
   1.600 -  | const_in str (Free (s,_)) = if strip_thy s = str then true else false
   1.601 -  | const_in str (Bound _) = false
   1.602 -  | const_in str (Var _) = false
   1.603 -  | const_in str (Abs (_,_,body)) = const_in str body
   1.604 -  | const_in str (f$u) = const_in str f orelse const_in str u;
   1.605 -(*
   1.606 -> val t = (term_of o the o (parse thy)) "6 + 5 * sqrt 4 + 3";
   1.607 -> const_in "sqrt" t;
   1.608 -val it = true : bool
   1.609 -> val t = (term_of o the o (parse thy)) "6 + 5 * 4 + 3";
   1.610 -> const_in "sqrt" t;
   1.611 -val it = false : bool
   1.612 -*)
   1.613 -
   1.614 -(*used for calculating built in binary operations in Isabelle2002->Float.ML*)
   1.615 -(*fun calc "Groups.plus_class.plus"  (n1, n2) = n1+n2
   1.616 -  | calc "Groups.minus_class.minus"  (n1, n2) = n1-n2
   1.617 -  | calc "op *"  (n1, n2) = n1*n2
   1.618 -  | calc "Rings.inverse_class.divide"(n1, n2) = n1 div n2
   1.619 -  | calc "Atools.pow"(n1, n2) = power n1 n2
   1.620 -  | calc op_ _ = raise error ("calc: operator = "^op_^" not defined");-----*)
   1.621 -fun calc_equ "op <"  (n1, n2) = n1 < n2
   1.622 -  | calc_equ "op <=" (n1, n2) = n1 <= n2
   1.623 -  | calc_equ op_ _ = 
   1.624 -  raise error ("calc_equ: operator = "^op_^" not defined");
   1.625 -fun sqrt (n:int) = if n < 0 then 0
   1.626 -    (*FIXME ~~~*)  else (trunc o Math.sqrt o Real.fromInt) n;
   1.627 -
   1.628 -fun mk_thmid thmid op_ n1 n2 = 
   1.629 -  thmid ^ (strip_thy n1) ^ "_" ^ (strip_thy n2);
   1.630 -
   1.631 -fun dest_binop_typ (Type("fun",[range,Type("fun",[arg2,arg1])])) =
   1.632 -  (arg1,arg2,range)
   1.633 -  | dest_binop_typ _ = raise error "dest_binop_typ: not binary";
   1.634 -(* -----
   1.635 -> val t = (term_of o the o (parse thy)) "#3^#4";
   1.636 -> val hT = type_of (head_of t);
   1.637 -> dest_binop_typ hT;
   1.638 -val it = ("'a","nat","'a") : typ * typ * typ
   1.639 - ----- *)
   1.640 -
   1.641 -
   1.642 -(** transform binary numeralsstrings **)
   1.643 -(*Makarius 100308, hacked by WN*)
   1.644 -val numbers_to_string =
   1.645 -  let
   1.646 -    fun dest_num t =
   1.647 -      (case try HOLogic.dest_number t of
   1.648 -        SOME (T, i) =>
   1.649 -          (*if T = @{typ int} orelse T = @{typ real} then WN*)
   1.650 -            SOME (Free (signed_string_of_int i, T))
   1.651 -          (*else NONE  WN*)
   1.652 -      | NONE => NONE);
   1.653 -
   1.654 -    fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
   1.655 -      | to_str (t as (u1 $ u2)) =
   1.656 -          (case dest_num t of
   1.657 -            SOME t' => t'
   1.658 -          | NONE => to_str u1 $ to_str u2)
   1.659 -      | to_str t = perhaps dest_num t;
   1.660 -  in to_str end
   1.661 -
   1.662 -(*.make uminus uniform: 
   1.663 -   Const ("uminus", _) $ Free ("2", "RealDef.real") --> Free ("-2", _)
   1.664 -to be used immediately before evaluation of numerals; 
   1.665 -see Scripts/calculate.sml .*)
   1.666 -(*2002 fun(*app_num_tr'2 (Const("0",T)) = Free("0",T)
   1.667 -  | app_num_tr'2 (Const("1",T)) = Free("1",T)
   1.668 -  |*)app_num_tr'2 (t as Const("uminus",_) $ Free(s,T)) = 
   1.669 -    (case int_of_str s of SOME i => 
   1.670 -			  if i > 0 then Free("-"^s,T) else Free(s,T)
   1.671 -		       | NONE => t)
   1.672 -(*| app_num_tr'2 (t as Const(s,T)) = t
   1.673 -  | app_num_tr'2 (Const("Numeral.number_of",Type ("fun", [_, T])) $ t) = 
   1.674 -    Free(NumeralSyntax.dest_bin_str t, T)
   1.675 -  | app_num_tr'2 (t as Free(s,T)) = t
   1.676 -  | app_num_tr'2 (t as Var(n,T)) = t
   1.677 -  | app_num_tr'2 (t as Bound i) = t
   1.678 -*)| app_num_tr'2 (Abs(s,T,body)) = Abs(s,T, app_num_tr'2 body)
   1.679 -  | app_num_tr'2 (t1 $ t2) = (app_num_tr'2 t1) $ (app_num_tr'2 t2)
   1.680 -  | app_num_tr'2 t = t;
   1.681 -*)
   1.682 -val uminus_to_string =
   1.683 -    let
   1.684 -	fun dest_num t =
   1.685 -	    (case t of
   1.686 -		 (Const ("HOL.uminus_class.uminus", _) $ Free (s, T)) => 
   1.687 -		 (case int_of_str s of
   1.688 -		      SOME i => 
   1.689 -		      SOME (Free (signed_string_of_int (~1 * i), T))
   1.690 -		    | NONE => NONE)
   1.691 -	       | _ => NONE);
   1.692 -	    
   1.693 -	fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
   1.694 -	  | to_str (t as (u1 $ u2)) =
   1.695 -            (case dest_num t of
   1.696 -		 SOME t' => t'
   1.697 -               | NONE => to_str u1 $ to_str u2)
   1.698 -	  | to_str t = perhaps dest_num t;
   1.699 -    in to_str end;
   1.700 -
   1.701 -
   1.702 -(*2002 fun num_str thm =
   1.703 -  let 
   1.704 -    val {sign_ref = sign_ref, der = der, maxidx = maxidx,
   1.705 -	    shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} = 
   1.706 -	rep_thm_G thm;
   1.707 -    val prop' = app_num_tr'1 prop;
   1.708 -  in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end;*)
   1.709 -fun num_str thm =
   1.710 -  let val (deriv, 
   1.711 -	   {thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps, 
   1.712 -	    hyps = hyps, tpairs = tpairs, prop = prop}) = rep_thm_G thm
   1.713 -    val prop' = numbers_to_string prop;
   1.714 -  in assbl_thm deriv thy_ref tags maxidx shyps hyps tpairs prop' end;
   1.715 -
   1.716 -fun get_thm' xstring = (*?covers 2009 Thm?!, replaces 2002 fun get_thm :
   1.717 -val it = fn : theory -> xstring -> Thm.thm*)
   1.718 -    Thm (xstring, 
   1.719 -	 num_str (ProofContext.get_thm (thy2ctxt' "Isac") xstring)); 
   1.720 -
   1.721 -(** get types of Free and Abs for parse' **)
   1.722 -(*11.1.00: not used, fix-typed +,*,-,^ instead *)
   1.723 -
   1.724 -val dummyT = Type ("dummy",[]);
   1.725 -val dummyT = TVar (("DUMMY",0),[]);
   1.726 -
   1.727 -(* assumes only 1 type for numerals 
   1.728 -   and different identifiers for Const, Free and Abs *)
   1.729 -fun get_types t = 
   1.730 -  let
   1.731 -    fun get ts  (Const(s,T)) = (s,T)::ts
   1.732 -      | get ts  (Free(s,T)) = if is_no s 
   1.733 -				then ("#",T)::ts else (s,T)::ts
   1.734 -      | get ts  (Var(n,T)) = ts
   1.735 -      | get ts  (Bound i) = ts
   1.736 -      | get ts  (Abs(s,T,body)) = get ((s,T)::ts)  body
   1.737 -      | get ts  (t1 $ t2) = (get ts  t1) @ (get ts  t2)
   1.738 -  in distinct (get [] t) end;
   1.739 -(*
   1.740 -val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
   1.741 -get_types t;
   1.742 -*)
   1.743 -
   1.744 -(*11.1.00: not used, fix-typed +,*,-,^ instead *)
   1.745 -fun set_types al (Const(s,T)) = 
   1.746 -    (case assoc (al,s) of
   1.747 -       SOME T' => Const(s,T')
   1.748 -     | NONE => (warning ("set_types: no type for "^s); Const(s,dummyT)))
   1.749 -  | set_types al (Free(s,T)) = 
   1.750 -  if is_no s then
   1.751 -    (case assoc (al,"#") of
   1.752 -      SOME T' => Free(s,T')
   1.753 -    | NONE => (warning ("set_types: no type for numerals"); Free(s,T)))
   1.754 -  else (case assoc (al,s) of
   1.755 -	       SOME T' => Free(s,T')
   1.756 -	     | NONE => (warning ("set_types: no type for "^s); Free(s,T)))
   1.757 -  | set_types al (Var(n,T)) = Var(n,T)
   1.758 -  | set_types al (Bound i) = Bound i
   1.759 -  | set_types al (Abs(s,T,body)) = 
   1.760 -		 (case assoc (al,s) of
   1.761 -		    SOME T'  => Abs(s,T', set_types al body)
   1.762 -		  | NONE => (warning ("set_types: no type for "^s);
   1.763 -			     Abs(s,T, set_types al body)))
   1.764 -  | set_types al (t1 $ t2) = (set_types al t1) $ (set_types al t2);
   1.765 -(*
   1.766 -val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
   1.767 -val al = get_types t;
   1.768 -
   1.769 -val t = (term_of o the o (parse thy)) "x = #0 + #-1 * #-4";
   1.770 -atomty t;                         (* 'a *)
   1.771 -val t' = set_types al t;
   1.772 -atomty t';                        (*real*)
   1.773 -(cterm_of thy) t';
   1.774 -val it = "x = #0 + #-1 * #-4" : cterm
   1.775 -
   1.776 -val t = (term_of o the o (parse thy)) 
   1.777 -  "#5 * x + x ^^^ #2 = (#2 + x) ^^^ #2";
   1.778 -atomty t;
   1.779 -val t' = set_types al t;
   1.780 -atomty t';
   1.781 -(cterm_of thy) t';
   1.782 -uncaught exception TYPE               (*^^^ is new, NOT in al*)
   1.783 -*)
   1.784 -      
   1.785 -
   1.786 -(** from Descript.ML **)
   1.787 -
   1.788 -(** decompose an isa-list to an ML-list 
   1.789 -    i.e. [] belong to the meta-language, too **)
   1.790 -
   1.791 -fun is_list ((Const("List.list.Cons",_)) $ _ $ _) = true
   1.792 -  | is_list _ = false;
   1.793 -(* val (SOME ct) = parse thy "lll::real list";
   1.794 -> val ty = (#t o rep_cterm) ct;
   1.795 -> is_list ty;
   1.796 -val it = false : bool
   1.797 -> val (SOME ct) = parse thy "[lll]";
   1.798 -> val ty = (#t o rep_cterm) ct;
   1.799 -> is_list ty;
   1.800 -val it = true : bool *)
   1.801 -
   1.802 -
   1.803 -
   1.804 -fun mk_Free (s,T) = Free(s,T);
   1.805 -fun mk_free T s =  Free(s,T);
   1.806 -
   1.807 -(*Special case: one argument cp from Isabelle2002/src/Pure/term.ML*)
   1.808 -fun subst_bound (arg, t) : term = (*WN100908 neglects 'raise Same.SAME'*)
   1.809 -  let fun subst (t as Bound i, lev) =
   1.810 -            if i<lev then  t    (*var is locally bound*)
   1.811 -            else  if i=lev then incr_boundvars lev arg
   1.812 -                           else Bound(i-1)  (*loose: change it*)
   1.813 -        | subst (Abs(a,T,body), lev) = Abs(a, T,  subst(body,lev+1))
   1.814 -        | subst (f$t, lev) =  subst(f,lev)  $  subst(t,lev)
   1.815 -        | subst (t,lev) = t
   1.816 -  in  subst (t,0)  end;
   1.817 -
   1.818 -(*instantiate let; necessary for ass_up*)
   1.819 -fun inst_abs thy (Const sT) = Const sT  (*TODO.WN100907 drop thy*)
   1.820 -  | inst_abs thy (Free sT) = Free sT
   1.821 -  | inst_abs thy (Bound n) = Bound n
   1.822 -  | inst_abs thy (Var iT) = Var iT
   1.823 -  | inst_abs thy (Const ("Let",T1) $ e $ (Abs (v, T2, b))) = 
   1.824 -    let val b' = subst_bound (Free (v, T2), b);
   1.825 -    (*fun variant_abs: term.ML*)
   1.826 -    in Const ("Let", T1) $ inst_abs thy e $ (Abs (v, T2, inst_abs thy b')) end
   1.827 -  | inst_abs thy (t1 $ t2) = inst_abs thy t1 $ inst_abs thy t2
   1.828 -  | inst_abs thy t = t;
   1.829 -(*val scr =    
   1.830 -   "Script Make_fun_by_explicit (f_::real) (v_::real) (eqs_::bool list) = \
   1.831 -   \ (let h_ = (hd o (filterVar f_)) eqs_;                    \
   1.832 -   \      e_1 = hd (dropWhile (ident h_) eqs_);       \
   1.833 -   \      vs_ = dropWhile (ident f_) (Vars h_);                \
   1.834 -   \      v_1 = hd (dropWhile (ident v_) vs_);                \
   1.835 -   \      (s_1::bool list)=(SubProblem(DiffApp_,[univar,equation],[no_met])\
   1.836 -   \                          [BOOL e_1, REAL v_1])\
   1.837 -   \ in Substitute [(v_1 = (rhs o hd) s_1)] h_)";
   1.838 -> val ttt = (term_of o the o (parse thy)) scr;
   1.839 -> tracing(term2str ttt);
   1.840 -> atomt ttt;
   1.841 -*** -------------
   1.842 -*** Const ( DiffApp.Make'_fun'_by'_explicit)
   1.843 -*** . Free ( f_, )
   1.844 -*** . Free ( v_, )
   1.845 -*** . Free ( eqs_, )
   1.846 -*** . Const ( Let)
   1.847 -*** . . Const ( Fun.op o)
   1.848 -*** . . . Const ( List.hd)
   1.849 -*** . . . Const ( DiffApp.filterVar)
   1.850 -*** . . . . Free ( f_, )
   1.851 -*** . . . Free ( eqs_, )
   1.852 -*** . . Abs( h_,..
   1.853 -*** . . . Const ( Let)
   1.854 -*** . . . . Const ( List.hd)
   1.855 -*** . . . . . Const ( List.dropWhile)
   1.856 -*** . . . . . . Const ( Atools.ident)
   1.857 -*** . . . . . . . Bound 0                     <---- Free ( h_, )
   1.858 -*** . . . . . . Free ( eqs_, )
   1.859 -*** . . . . Abs( e_1,..
   1.860 -*** . . . . . Const ( Let)
   1.861 -*** . . . . . . Const ( List.dropWhile)
   1.862 -*** . . . . . . . Const ( Atools.ident)
   1.863 -*** . . . . . . . . Free ( f_, )
   1.864 -*** . . . . . . . Const ( Tools.Vars)
   1.865 -*** . . . . . . . . Bound 1                       <---- Free ( h_, )
   1.866 -*** . . . . . . Abs( vs_,..
   1.867 -*** . . . . . . . Const ( Let)
   1.868 -*** . . . . . . . . Const ( List.hd)
   1.869 -*** . . . . . . . . . Const ( List.dropWhile)
   1.870 -*** . . . . . . . . . . Const ( Atools.ident)
   1.871 -*** . . . . . . . . . . . Free ( v_, )
   1.872 -*** . . . . . . . . . . Bound 0                   <---- Free ( vs_, )
   1.873 -*** . . . . . . . . Abs( v_1,..
   1.874 -*** . . . . . . . . . Const ( Let)
   1.875 -*** . . . . . . . . . . Const ( Script.SubProblem)
   1.876 -*** . . . . . . . . . . . Const ( Pair)
   1.877 -*** . . . . . . . . . . . . Free ( DiffApp_, )
   1.878 -*** . . . . . . . . . . . . Const ( Pair)
   1.879 -*** . . . . . . . . . . . . . Const ( List.list.Cons)
   1.880 -*** . . . . . . . . . . . . . . Free ( univar, )
   1.881 -*** . . . . . . . . . . . . . . Const ( List.list.Cons)
   1.882 -*** . . . . . . . . . . . . . . . Free ( equation, )
   1.883 -*** . . . . . . . . . . . . . . . Const ( List.list.Nil)
   1.884 -*** . . . . . . . . . . . . . Const ( List.list.Cons)
   1.885 -*** . . . . . . . . . . . . . . Free ( no_met, )
   1.886 -*** . . . . . . . . . . . . . . Const ( List.list.Nil)
   1.887 -*** . . . . . . . . . . . Const ( List.list.Cons)
   1.888 -*** . . . . . . . . . . . . Const ( Script.BOOL)
   1.889 -*** . . . . . . . . . . . . . Bound 2                   <----- Free ( e_1, )
   1.890 -*** . . . . . . . . . . . . Const ( List.list.Cons)
   1.891 -*** . . . . . . . . . . . . . Const ( Script.real_)
   1.892 -*** . . . . . . . . . . . . . . Bound 0                 <----- Free ( v_1, )
   1.893 -*** . . . . . . . . . . . . . Const ( List.list.Nil)
   1.894 -*** . . . . . . . . . . Abs( s_1,..
   1.895 -*** . . . . . . . . . . . Const ( Script.Substitute)
   1.896 -*** . . . . . . . . . . . . Const ( List.list.Cons)
   1.897 -*** . . . . . . . . . . . . . Const ( Pair)
   1.898 -*** . . . . . . . . . . . . . . Bound 1                 <----- Free ( v_1, )
   1.899 -*** . . . . . . . . . . . . . . Const ( Fun.op o)
   1.900 -*** . . . . . . . . . . . . . . . Const ( Tools.rhs)
   1.901 -*** . . . . . . . . . . . . . . . Const ( List.hd)
   1.902 -*** . . . . . . . . . . . . . . . Bound 0               <----- Free ( s_1, )
   1.903 -*** . . . . . . . . . . . . . Const ( List.list.Nil)
   1.904 -*** . . . . . . . . . . . . Bound 4                     <----- Free ( h_, )
   1.905 -
   1.906 -> val ttt' = inst_abs thy ttt;
   1.907 -> tracing(term2str ttt');
   1.908 -Script Make_fun_by_explicit f_ v_ eqs_ =  
   1.909 -  ... as above ...
   1.910 -> atomt ttt';
   1.911 -*** -------------
   1.912 -*** Const ( DiffApp.Make'_fun'_by'_explicit)
   1.913 -*** . Free ( f_, )
   1.914 -*** . Free ( v_, )
   1.915 -*** . Free ( eqs_, )
   1.916 -*** . Const ( Let)
   1.917 -*** . . Const ( Fun.op o)
   1.918 -*** . . . Const ( List.hd)
   1.919 -*** . . . Const ( DiffApp.filterVar)
   1.920 -*** . . . . Free ( f_, )
   1.921 -*** . . . Free ( eqs_, )
   1.922 -*** . . Abs( h_,..
   1.923 -*** . . . Const ( Let)
   1.924 -*** . . . . Const ( List.hd)
   1.925 -*** . . . . . Const ( List.dropWhile)
   1.926 -*** . . . . . . Const ( Atools.ident)
   1.927 -*** . . . . . . . Free ( h_, )                <---- Bound 0
   1.928 -*** . . . . . . Free ( eqs_, )
   1.929 -*** . . . . Abs( e_1,..
   1.930 -*** . . . . . Const ( Let)
   1.931 -*** . . . . . . Const ( List.dropWhile)
   1.932 -*** . . . . . . . Const ( Atools.ident)
   1.933 -*** . . . . . . . . Free ( f_, )
   1.934 -*** . . . . . . . Const ( Tools.Vars)
   1.935 -*** . . . . . . . . Free ( h_, )                  <---- Bound 1
   1.936 -*** . . . . . . Abs( vs_,..
   1.937 -*** . . . . . . . Const ( Let)
   1.938 -*** . . . . . . . . Const ( List.hd)
   1.939 -*** . . . . . . . . . Const ( List.dropWhile)
   1.940 -*** . . . . . . . . . . Const ( Atools.ident)
   1.941 -*** . . . . . . . . . . . Free ( v_, )
   1.942 -*** . . . . . . . . . . Free ( vs_, )             <---- Bound 0
   1.943 -*** . . . . . . . . Abs( v_1,..
   1.944 -*** . . . . . . . . . Const ( Let)
   1.945 -*** . . . . . . . . . . Const ( Script.SubProblem)
   1.946 -*** . . . . . . . . . . . Const ( Pair)
   1.947 -*** . . . . . . . . . . . . Free ( DiffApp_, )
   1.948 -*** . . . . . . . . . . . . Const ( Pair)
   1.949 -*** . . . . . . . . . . . . . Const ( List.list.Cons)
   1.950 -*** . . . . . . . . . . . . . . Free ( univar, )
   1.951 -*** . . . . . . . . . . . . . . Const ( List.list.Cons)
   1.952 -*** . . . . . . . . . . . . . . . Free ( equation, )
   1.953 -*** . . . . . . . . . . . . . . . Const ( List.list.Nil)
   1.954 -*** . . . . . . . . . . . . . Const ( List.list.Cons)
   1.955 -*** . . . . . . . . . . . . . . Free ( no_met, )
   1.956 -*** . . . . . . . . . . . . . . Const ( List.list.Nil)
   1.957 -*** . . . . . . . . . . . Const ( List.list.Cons)
   1.958 -*** . . . . . . . . . . . . Const ( Script.BOOL)
   1.959 -*** . . . . . . . . . . . . . Free ( e_1, )             <----- Bound 2
   1.960 -*** . . . . . . . . . . . . Const ( List.list.Cons)
   1.961 -*** . . . . . . . . . . . . . Const ( Script.real_)
   1.962 -*** . . . . . . . . . . . . . . Free ( v_1, )           <----- Bound 0
   1.963 -*** . . . . . . . . . . . . . Const ( List.list.Nil)
   1.964 -*** . . . . . . . . . . Abs( s_1,..
   1.965 -*** . . . . . . . . . . . Const ( Script.Substitute)
   1.966 -*** . . . . . . . . . . . . Const ( List.list.Cons)
   1.967 -*** . . . . . . . . . . . . . Const ( Pair)
   1.968 -*** . . . . . . . . . . . . . . Free ( v_1, )           <----- Bound 1
   1.969 -*** . . . . . . . . . . . . . . Const ( Fun.op o)
   1.970 -*** . . . . . . . . . . . . . . . Const ( Tools.rhs)
   1.971 -*** . . . . . . . . . . . . . . . Const ( List.hd)
   1.972 -*** . . . . . . . . . . . . . . . Free ( s_1, )         <----- Bound 0
   1.973 -*** . . . . . . . . . . . . . Const ( List.list.Nil)
   1.974 -*** . . . . . . . . . . . . Free ( h_, )                <----- Bound 4
   1.975 -
   1.976 -Note numbering of de Bruijn indexes !
   1.977 -
   1.978 -Script Make_fun_by_explicit f_ v_ eqs_ =
   1.979 - let h_ = (hd o filterVar f_) eqs_; 
   1.980 -     e_1 = hd (dropWhile (ident h_ BOUND_0) eqs_);
   1.981 -     vs_ = dropWhile (ident f_) (Vars h_ BOUND_1);
   1.982 -     v_1 = hd (dropWhile (ident v_) vs_ BOUND_0);
   1.983 -     s_1 =
   1.984 -       SubProblem (DiffApp_, [univar, equation], [no_met])
   1.985 -        [BOOL e_1 BOUND_2, REAL v_1 BOUND_0]
   1.986 - in Substitute [(v_1 BOUND_1 = (rhs o hd) s_1 BOUND_0)] h_ BOUND_4
   1.987 -*)
   1.988 -
   1.989 -
   1.990 -fun T_a2real (Type (s, [])) = 
   1.991 -    if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else Type (s, [])
   1.992 -  | T_a2real (Type (s, Ts)) = Type (s, map T_a2real Ts)
   1.993 -  | T_a2real (TFree (s, srt)) = 
   1.994 -    if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else TFree (s, srt)
   1.995 -  | T_a2real (TVar (("DUMMY",_),srt)) = HOLogic.realT;
   1.996 -
   1.997 -(*FIXME .. fixes the type (+see Typefix.thy*)
   1.998 -fun typ_a2real (Const( s, T)) = (Const( s, T_a2real T)) 
   1.999 -  | typ_a2real (Free( s, T)) = (Free( s, T_a2real T))
  1.1000 -  | typ_a2real (Var( n, T)) = (Var( n, T_a2real T))
  1.1001 -  | typ_a2real (Bound i) = (Bound i)
  1.1002 -  | typ_a2real (Abs(s,T,t)) = Abs(s, T, typ_a2real t)
  1.1003 -  | typ_a2real (t1 $ t2) = (typ_a2real t1) $ (typ_a2real t2);
  1.1004 -(*
  1.1005 -----------------6.8.02---------------------------------------------------
  1.1006 - val str = "1";
  1.1007 - val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[])));
  1.1008 - atomty (term_of t);
  1.1009 -*** -------------
  1.1010 -*** Const ( 1, 'a)
  1.1011 - val t = (app_num_tr' o term_of) t;
  1.1012 - atomty t;
  1.1013 -*** ------------- 
  1.1014 -*** Const ( 1, 'a)                                                              
  1.1015 - val t = typ_a2real t;
  1.1016 - atomty t;
  1.1017 -*** -------------   
  1.1018 -*** Const ( 1, real)                                                            
  1.1019 -
  1.1020 - val str = "2";
  1.1021 - val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[])));
  1.1022 - atomty (term_of t);
  1.1023 -*** -------------
  1.1024 -*** Const ( Numeral.number_of, bin => 'a)
  1.1025 -*** . Const ( Numeral.bin.Bit, [bin, bool] => bin)
  1.1026 -*** . . Const ( Numeral.bin.Bit, [bin, bool] => bin)
  1.1027 -*** . . . Const ( Numeral.bin.Pls, bin)
  1.1028 -*** . . . Const ( True, bool)
  1.1029 -*** . . Const ( False, bool)
  1.1030 - val t = (app_num_tr' o term_of) t;
  1.1031 - atomty t;
  1.1032 -*** -------------
  1.1033 -*** Free ( 2, 'a)
  1.1034 - val t = typ_a2real t;
  1.1035 - atomty t;
  1.1036 -*** -------------
  1.1037 -*** Free ( 2, real)
  1.1038 -----------------6.8.02---------------------------------------------------
  1.1039 -
  1.1040 -
  1.1041 -> val str = "R";
  1.1042 -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
  1.1043 -val t = Free ("R","?DUMMY") : term
  1.1044 -> val t' = typ_a2real t;
  1.1045 -> (cterm_of thy) t';
  1.1046 -val it = "R::RealDef.real" : cterm
  1.1047 -
  1.1048 -> val str = "R=R";
  1.1049 -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
  1.1050 -> atomty (typ_a2real t);
  1.1051 -*** -------------
  1.1052 -*** Const ( op =, [RealDef.real, RealDef.real] => bool)
  1.1053 -***   Free ( R, RealDef.real)
  1.1054 -***   Free ( R, RealDef.real)
  1.1055 -> val t' = typ_a2real t;
  1.1056 -> (cterm_of thy) t';
  1.1057 -val it = "(R::RealDef.real) = R" : cterm
  1.1058 -
  1.1059 -> val str = "fixed_values [R=R]";
  1.1060 -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
  1.1061 -> val t' = typ_a2real t;
  1.1062 -> (cterm_of thy) t';
  1.1063 -val it = "fixed_values [(R::RealDef.real) = R]" : cterm
  1.1064 -*)
  1.1065 -
  1.1066 -(*TODO.WN0609: parse should return a term or a string 
  1.1067 -	     (or even more comprehensive datastructure for error-messages)
  1.1068 - i.e. in wrapping with SOME term or NONE the latter is not sufficient*)
  1.1069 -(*2002 fun parseold thy str = 
  1.1070 -  (let 
  1.1071 -     val sgn = sign_of thy;
  1.1072 -     val t = ((*typ_a2real o*) app_num_tr'1 o term_of) 
  1.1073 -       (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
  1.1074 -   in SOME (cterm_of sgn t) end)
  1.1075 -     handle _ => NONE;*)
  1.1076 -
  1.1077 -
  1.1078 -
  1.1079 -fun parseold thy str = 
  1.1080 -  (let val t = ((*typ_a2real o*) numbers_to_string) 
  1.1081 -		   (Syntax.read_term_global thy str)
  1.1082 -   in SOME (cterm_of thy t) end)
  1.1083 -    handle _ => NONE;
  1.1084 -(*2002 fun parseN thy str = 
  1.1085 -  (let 
  1.1086 -     val sgn = sign_of thy;
  1.1087 -     val t = ((*typ_a2real o app_num_tr'1 o*) term_of) 
  1.1088 -       (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
  1.1089 -   in SOME (cterm_of sgn t) end)
  1.1090 -     handle _ => NONE;*)
  1.1091 -fun parseN thy str = 
  1.1092 -  (let val t = (*(typ_a2real o numbers_to_string)*) 
  1.1093 -	   (Syntax.read_term_global thy str)
  1.1094 -   in SOME (cterm_of thy t) end)
  1.1095 -    handle _ => NONE;
  1.1096 -(*2002 fun parse thy str = 
  1.1097 -  (let 
  1.1098 -     val sgn = sign_of thy;
  1.1099 -     val t = (typ_a2real o app_num_tr'1 o term_of) 
  1.1100 -       (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
  1.1101 -   in SOME (cterm_of sgn t) end) (*FIXXXXME 10.8.02: return term !!!*)
  1.1102 -     handle _ => NONE;*)
  1.1103 -(*2010 fun parse thy str = 
  1.1104 -  (let val t = (typ_a2real o app_num_tr'1) (Syntax.read_term_global thy str)
  1.1105 -   in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
  1.1106 -     handle _ => NONE;*)
  1.1107 -fun parse thy str = 
  1.1108 -  (let val t = (typ_a2real o numbers_to_string) 
  1.1109 -		   (Syntax.read_term_global thy str)
  1.1110 -   in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
  1.1111 -     handle _ => NONE;
  1.1112 -(*
  1.1113 -> val (SOME ct) = parse thy "(-#5)^^^#3"; 
  1.1114 -> atomty (term_of ct);
  1.1115 -*** -------------
  1.1116 -*** Const ( Nat.op ^, ['a, nat] => 'a)
  1.1117 -***   Const ( uminus, 'a => 'a)
  1.1118 -***     Free ( #5, 'a)
  1.1119 -***   Free ( #3, nat)                
  1.1120 -> val (SOME ct) = parse thy "R=R"; 
  1.1121 -> atomty (term_of ct);
  1.1122 -*** -------------
  1.1123 -*** Const ( op =, [real, real] => bool)
  1.1124 -***   Free ( R, real)
  1.1125 -***   Free ( R, real)
  1.1126 -
  1.1127 -THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!!
  1.1128 -*** -------------
  1.1129 -*** Const ( op =, [RealDef.real, RealDef.real] => bool)
  1.1130 -***   Free ( R, RealDef.real)
  1.1131 -***   Free ( R, RealDef.real)                  *)
  1.1132 -
  1.1133 -fun parse_patt thy str = 
  1.1134 -    ProofContext.read_term_pattern (thy2ctxt thy) str;
  1.1135 -
  1.1136 -(*version for testing local to theories*)
  1.1137 -fun str2term_ thy str = (term_of o the o (parse thy)) str;
  1.1138 -fun str2term str = (term_of o the o (parse (theory "Isac"))) str;
  1.1139 -fun strs2terms ss = map str2term ss;
  1.1140 -fun str2termN str = (term_of o the o (parseN (theory "Isac"))) str;
  1.1141 -
  1.1142 -(*+ makes a substitution from the output of Pattern.match +*)
  1.1143 -(*fun mk_subs ((id, _):indexname, t:term) = (Free (id,type_of t), t);*)
  1.1144 -fun mk_subs (subs: ((string * int) * (Term.typ * Term.term)) list) =
  1.1145 -let fun mk_sub ((id, _), (ty, tm)) = (Free (id, ty), tm) in
  1.1146 -map mk_sub subs end;
  1.1147 -
  1.1148 -val atomthm = atomt o #prop o rep_thm;
  1.1149 -
  1.1150 -(*.instantiate #prop thm with bound variables (as Free).*)
  1.1151 -fun inst_bdv [] t = t : term
  1.1152 -  | inst_bdv (instl: (term*term) list) t =
  1.1153 -      let fun subst (v as Var((s,_),T)) = 
  1.1154 -	      (case explode s of
  1.1155 -		   "b"::"d"::"v"::_ => 
  1.1156 -		   if_none (assoc(instl,Free(s,T))) (Free(s,T))
  1.1157 -		 | _ => v)
  1.1158 -            | subst (Abs(a,T,body)) = Abs(a, T, subst body)
  1.1159 -            | subst (f$t') = subst f $ subst t'
  1.1160 -            | subst t = if_none (assoc(instl,t)) t
  1.1161 -      in  subst t  end;
  1.1162 -
  1.1163 -
  1.1164 -(*WN050829 caution: is_atom (str2term"q_0/2 * L * x") = true !!!
  1.1165 -  use length (vars term) = 1 instead*)
  1.1166 -fun is_atom (Const ("Float.Float",_) $ _) = true
  1.1167 -  | is_atom (Const ("ComplexI.I'_'_",_)) = true
  1.1168 -  | is_atom (Const ("op *",_) $ t $ Const ("ComplexI.I'_'_",_)) = is_atom t
  1.1169 -  | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ Const ("ComplexI.I'_'_",_)) = is_atom t1
  1.1170 -  | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ 
  1.1171 -		   (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_))) = 
  1.1172 -    is_atom t1 andalso is_atom t2
  1.1173 -  | is_atom (Const _) = true
  1.1174 -  | is_atom (Free _) = true
  1.1175 -  | is_atom (Var _) = true
  1.1176 -  | is_atom _ = false;
  1.1177 -(* val t = str2term "q_0/2 * L * x";
  1.1178 -
  1.1179 -
  1.1180 -*)
  1.1181 -(*val t = str2term "Float ((1,2),(0,0))";
  1.1182 -> is_atom t;
  1.1183 -val it = true : bool
  1.1184 -> val t = str2term "Float ((1,2),(0,0)) * I__";
  1.1185 -> is_atom t;
  1.1186 -val it = true : bool
  1.1187 -> val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * I__";
  1.1188 -> is_atom t;
  1.1189 -val it = true : bool
  1.1190 -> val t = str2term "1 + 2*I__";
  1.1191 -> val Const ("Groups.plus_class.plus",_) $ t1 $ (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_)) = t;
  1.1192 -*)
  1.1193 -
  1.1194 -(*.adaption from Isabelle/src/Pure/term.ML; reports if ALL Free's
  1.1195 -   have found a substitution (required for evaluating the preconditions
  1.1196 -   of _incomplete_ models).*)
  1.1197 -fun subst_atomic_all [] t = (false, (*TODO may be 'true' for some terms ?*)
  1.1198 -			     t : term)
  1.1199 -  | subst_atomic_all (instl: (term*term) list) t =
  1.1200 -      let fun subst (Abs(a,T,body)) = 
  1.1201 -	      let val (all, body') = subst body
  1.1202 -	      in (all, Abs(a, T, body')) end
  1.1203 -            | subst (f$tt) = 
  1.1204 -	      let val (all1, f') = subst f
  1.1205 -		  val (all2, tt') = subst tt
  1.1206 -	      in (all1 andalso all2, f' $ tt') end
  1.1207 -            | subst (t as Free _) = 
  1.1208 -	      if is_num t then (true, t) (*numerals cannot be subst*)
  1.1209 -	      else (case assoc(instl,t) of
  1.1210 -					 SOME t' => (true, t')
  1.1211 -				       | NONE => (false, t))
  1.1212 -            | subst t = (true, if_none (assoc(instl,t)) t)
  1.1213 -      in  subst t  end;
  1.1214 -
  1.1215 -(*.add two terms with a type given.*)
  1.1216 -fun mk_add t1 t2 =
  1.1217 -    let val T1 = type_of t1
  1.1218 -	val T2 = type_of t2
  1.1219 -    in if T1 <> T2 then raise TYPE ("mk_add gets ",[T1, T2],[t1,t2])
  1.1220 -       else (Const ("Groups.plus_class.plus", [T1, T2] ---> T1) $ t1 $ t2)
  1.1221 -    end;
  1.1222 -