1 (* Title: extends Isabelle/src/Pure/term.ML
2 Author: Walther Neuper 1999, Mathias Lehnfeld
3 (c) due to copyright terms
7 > (cterm_of thy) a_term;
8 val it = "empty" : cterm *)
10 (*2003 fun match thy t pat =
11 (snd (Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t)))
14 Term.term -> Term.term -> (Term.indexname * Term.term) list*)
15 (*see src/Tools/eqsubst.ML fun clean_match*)
16 (*2003 fun matches thy tm pa = if match thy tm pa = [] then false else true;*)
17 fun matches thy tm pa =
18 (Pattern.match thy (pa, tm) (Vartab.empty, Vartab.empty); true)
21 fun atomtyp t = (*WN10 see raw_pp_typ*)
23 fun ato n (Type (s,[])) =
24 ("\n*** "^indent n^"Type ("^s^",[])")
25 | ato n (Type (s,Ts)) =
26 ("\n*** "^indent n^"Type ("^s^",["^ atol (n+1) Ts)
28 | ato n (TFree (s,sort)) =
29 ("\n*** "^indent n^"TFree ("^s^",["^ strs2str' sort)
31 | ato n (TVar ((s,i),sort)) =
32 ("\n*** "^indent n^"TVar (("^s^","^
33 string_of_int i ^ strs2str' sort)
35 ("\n*** "^indent n^"]")
36 | atol n (T::Ts) = (ato n T ^ atol n Ts)
37 in tracing (ato 0 t ^ "\n") end;
39 > val T = (type_of o term_of o the o (parse thy)) "a::[real,int] => nat";
42 *** Type (RealDef.real,[])
44 *** Type (IntDef.int,[])
50 (*Prog.Tutorial.p.34, Makarius 1005 does the above like this..*)
52 fun pp_pair (x, y) = Pretty.list "(" ")" [x, y]
53 fun pp_list xs = Pretty.list "[" "]" xs
54 fun pp_str s = Pretty.str s
55 fun pp_qstr s = Pretty.quote (pp_str s)
56 fun pp_int i = pp_str (string_of_int i)
57 fun pp_sort S = pp_list (map pp_qstr S)
58 fun pp_constr a args = Pretty.block [pp_str a, Pretty.brk 1, args]
60 fun raw_pp_typ (TVar ((a, i), S)) =
61 pp_constr "TVar" (pp_pair (pp_pair (pp_qstr a, pp_int i), pp_sort S))
62 | raw_pp_typ (TFree (a, S)) =
63 pp_constr "TFree" (pp_pair (pp_qstr a, pp_sort S))
64 | raw_pp_typ (Type (a, tys)) =
65 pp_constr "Type" (pp_pair (pp_qstr a, pp_list (map raw_pp_typ tys)))
68 PolyML.addPrettyPrinter
69 (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ);
71 PolyML.addPrettyPrinter
72 (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy);
76 fun ato (Const (a, _)) n =
77 "\n*** " ^ indent n ^ "Const (" ^ a ^ ", _)"
78 | ato (Free (a, _)) n =
79 "\n*** " ^ indent n ^ "Free (" ^ a ^ ", _)"
80 | ato (Var ((a, i), _)) n =
81 "\n*** " ^ indent n ^ "Var (" ^ a ^ ", " ^
82 string_of_int i ^ "), _)"
84 "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
85 | ato (Abs (a, _, body)) n =
86 "\n*** " ^ indent n ^ "Abs(" ^ a ^ ", _" ^ ato body (n+1)
87 | ato (f $ t) n = (ato f n ^ ato t (n + 1))
89 fun atomw t = writeln ("\n*** -------------" ^ ato t 0 ^ "\n***");
90 fun atomt t = tracing ("\n*** -------------" ^ ato t 0 ^ "\n***");
93 fun term_detail2str t =
94 let fun ato (Const (a, T)) n =
95 "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ T ^ ")"
96 | ato (Free (a, T)) n =
97 "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ T ^ ")"
98 | ato (Var ((a, i), T)) n =
99 "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^
100 string_of_typ T ^ ")"
102 "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
103 | ato (Abs(a, T, body)) n =
104 "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ T ^ ",.."
106 | ato (f $ t) n = ato f n ^ ato t (n + 1)
107 in "\n*** " ^ ato t 0 ^ "\n***" end;
108 fun term_detail2str_thy thy t =
109 let fun ato (Const (a, T)) n =
110 "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ_thy thy T ^ ")"
111 | ato (Free (a, T)) n =
112 "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ_thy thy T ^ ")"
113 | ato (Var ((a, i), T)) n =
114 "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^
115 string_of_typ_thy thy T ^ ")"
117 "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
118 | ato (Abs(a, T, body)) n =
119 "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ_thy thy T ^ ",.."
121 | ato (f $ t) n = ato f n ^ ato t (n + 1)
122 in "\n*** " ^ ato t 0 ^ "\n***" end;
123 fun atomwy t = (writeln o term_detail2str) t;
124 fun atomty t = (tracing o term_detail2str) t;
125 fun atomty_thy thy t = (tracing o (term_detail2str_thy thy)) t;
127 fun term_str thy (Const(s,_)) = s
128 | term_str thy (Free(s,_)) = s
129 | term_str thy (Var((s,i),_)) = s^(string_of_int i)
130 | term_str thy (Bound i) = "B."^(string_of_int i)
131 | term_str thy (Abs(s,_,_)) = s
132 | term_str thy t = error("term_str not for "^term2str t);
134 (*.contains the fst argument the second argument (a leave! of term).*)
135 fun contains_term (Abs(_,_,body)) t = contains_term body t
136 | contains_term (f $ f') t =
137 contains_term f t orelse contains_term f' t
138 | contains_term s t = t = s;
139 (*.contains the term a VAR(("*",_),_) ?.*)
140 fun contains_Var (Abs(_,_,body)) = contains_Var body
141 | contains_Var (f $ f') = contains_Var f orelse contains_Var f'
142 | contains_Var (Var _) = true
143 | contains_Var _ = false;
144 (* contains_Var (str2term "?z = 3") (*true*);
145 contains_Var (str2term "z = 3") (*false*);
148 (*fun int_of_str str =
149 let val ss = Symbol.explode str
150 val str' = case ss of
151 "("::s => drop_last s | _ => ss
152 in case BasisLibrary.Int.fromString (implode str') of
154 | NONE => NONE end;*)
156 let val ss = Symbol.explode str
157 val str' = case ss of
158 "("::s => drop_last s | _ => ss
159 in (SOME (Thy_Output.integer (implode str'))) handle _ => NONE end;
162 val it = SOME 123 : int option
163 > int_of_str "(-123)";
164 val it = SOME 123 : int option
166 val it = NONE : int option
168 val it = SOME ~123 : int option
170 fun int_of_str' str =
171 case int_of_str str of
173 | NONE => raise TERM ("int_of_string: no int-string",[]);
174 val str2int = int_of_str';
176 fun is_numeral str = case int_of_str str of
179 val is_no = is_numeral;
180 fun is_num (Free (s,_)) = if is_numeral s then true else false
183 > is_num ((term_of o the o (parse thy)) "#1");
185 > is_num ((term_of o the o (parse thy)) "#-1");
187 > is_num ((term_of o the o (parse thy)) "a123");
188 val it = false : bool
191 (*fun int_of_Free (Free (intstr, _)) =
192 (case BasisLibrary.Int.fromString intstr of
194 | NONE => error ("int_of_Free ( "^ intstr ^", _)"))
195 | int_of_Free t = error ("int_of_Free ( "^ term2str t ^" )");*)
196 fun int_of_Free (Free (intstr, _)) = (Thy_Output.integer intstr
197 handle _ => error ("int_of_Free ( "^ intstr ^", _)"))
198 | int_of_Free t = error ("int_of_Free ( "^ term2str t ^" )");
202 fun scan vs (Const(s,T)) = vs
203 | scan vs (t as Free(s,T)) = if is_no s then vs else t::vs
204 | scan vs (t as Var((s,i),T)) = t::vs
205 | scan vs (Bound i) = vs
206 | scan vs (Abs(s,T,t)) = scan vs t
207 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
208 in (distinct o (scan [])) t end;
210 fun is_Free (Free _) = true
212 fun is_fun_id (Const _) = true
213 | is_fun_id (Free _) = true
214 | is_fun_id _ = false;
215 fun is_f_x (f $ x) = is_fun_id f andalso is_Free x
217 (* is_f_x (str2term "q_0/2 * L * x") (*false*);
218 is_f_x (str2term "M_b x") (*true*);
222 fun scan vs (Const(s,T)) = vs
223 | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
224 | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
225 | scan vs (Bound i) = vs
226 | scan vs (Abs(s,T,t)) = scan vs t
227 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
228 in (distinct o (scan [])) t end;
232 fun scan vs (Const(s,T)) = if is_no s then vs else s::vs
233 | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
234 | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
235 | scan vs (Bound i) = vs
236 | scan vs (Abs(s,T,t)) = scan (s::vs) t
237 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
238 in (distinct o (scan [])) t end;
240 case Symbol.explode str of
241 "b"::"d"::"v"::_ => true
243 fun is_bdv_ (Free (s,_)) = is_bdv s
246 fun free2str (Free (s,_)) = s
247 | free2str t = error ("free2str not for "^ term2str t);
248 fun free2int (t as Free (s, _)) = ((str2int s)
249 handle _ => error ("free2int: "^term_detail2str t))
250 | free2int t = error ("free2int: "^term_detail2str t);
252 (*compare Logic.unvarify_global, which rejects Free*)
253 fun var2free (t as Const(s,T)) = t
254 | var2free (t as Free(s,T)) = t
255 | var2free (Var((s,i),T)) = Free(s,T)
256 | var2free (t as Bound i) = t
257 | var2free (Abs(s,T,t)) = Abs(s,T,var2free t)
258 | var2free (t1 $ t2) = (var2free t1) $ (var2free t2);
260 (*27.8.01: doesn't find some subterm ???!???*)
261 (*2010 free2var -> Logic.varify, but take care of 'Free ("1",_)'*)
262 fun free2var (t as Const (s, T)) = t
263 | free2var (t as Free (s, T)) = if is_no s then t else Var ((s, 0), T)
264 | free2var (t as Var ((s, i), T)) = t
265 | free2var (t as Bound i) = t
266 | free2var (Abs (s, T, t)) = Abs (s, T, free2var t)
267 | free2var (t1 $ t2) = (free2var t1) $ (free2var t2);
270 fun mk_listT T = Type ("List.list", [T]);
272 Const("List.list.Cons", [T, mk_listT T] ---> mk_listT T);
273 (*28.8.01: TODO: get type from head of list: 1 arg less!!!*)
274 fun list2isalist T [] = Const("List.list.Nil",mk_listT T)
275 | list2isalist T (t::ts) = (list_const T) $ t $ (list2isalist T ts);
277 > val tt = (term_of o the o (parse thy)) "R=(R::real)";
278 > val TT = type_of tt;
279 > val ss = list2isalist TT [tt,tt,tt];
281 val it = "[R = R, R = R, R = R]" : cterm *)
283 fun isapair2pair (Const ("Product_Type.Pair",_) $ a $ b) = (a,b)
285 error ("isapair2pair called with "^term2str t);
287 val listType = Type ("List.list",[Type ("bool",[])]);
288 fun isalist2list ls =
290 fun get es (Const("List.list.Cons",_) $ t $ ls) = get (t::es) ls
291 | get es (Const("List.list.Nil",_)) = es
293 error ("isalist2list applied to NON-list '"^term2str t^"'")
294 in (rev o (get [])) ls end;
296 > val il = str2term "[a=b,c=d,e=f]";
297 > val l = isalist2list il;
298 > (tracing o terms2str) l;
299 ["a = b","c = d","e = f"]
301 > val il = str2term "ss___::bool list";
302 > val l = isalist2list il;
303 [Free ("ss___", "bool List.list")]
306 (*review Isabelle2009/src/HOL/Tools/hologic.ML*)
307 (*val prop = Type ("HOL.Trueprop",[]); ~/Diss.99/Integers-Isa/tools.sml*)
308 val bool = Type ("HOL.bool",[]); (* 2002 Integ.int *)
309 val Trueprop = HOLogic.Trueprop;
310 fun mk_prop t = HOLogic.mk_Trueprop t;
311 val true_as_term = HOLogic.true_const;
312 val false_as_term = HOLogic.false_const;
313 val true_as_cterm = cterm_of (Thy_Info.get_theory "HOL") true_as_term;
314 val false_as_cterm = cterm_of (Thy_Info.get_theory "HOL") false_as_term;
316 infixr 5 -->; (*2002 /Pure/term.ML *)
317 infixr --->; (*2002 /Pure/term.ML *)
318 fun S --> T = Type("fun",[S,T]); (*2002 /Pure/term.ML *)
319 val op ---> = foldr (op -->); (*2002 /Pure/term.ML *)
320 fun list_implies ([], B) = B : term (*2002 /term.ML *)
321 | list_implies (A::AS, B) = Logic.implies $ A $ list_implies(AS,B);
326 fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) = (* = thm.ML *)
327 match_bvs(s, t, if x="" orelse y="" then al
329 | match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al))
330 | match_bvs(_,_,al) = al;
331 fun ren_inst(insts,prop,pat,obj) = (* = thm.ML *)
332 let val ren = match_bvs(pat,obj,[])
333 fun renAbs(Abs(x,T,b)) =
334 Abs(case assoc_string(ren,x) of NONE => x
335 | SOME(y) => y, T, renAbs(b))
336 | renAbs(f$t) = renAbs(f) $ renAbs(t)
338 in subst_vars insts (if null(ren) then prop else renAbs(prop)) end;
345 fun dest_equals' (Const("HOL.eq",_) $ t $ u) = (t,u)(* logic.ML: Const("=="*)
346 | dest_equals' t = raise TERM("dest_equals'", [t]);
347 val lhs_ = (fst o dest_equals');
348 val rhs_ = (snd o dest_equals');
350 fun is_equality (Const("HOL.eq",_) $ t $ u) = true (* logic.ML: Const("=="*)
351 | is_equality _ = false;
352 fun mk_equality (t,u) = (Const("HOL.eq",[type_of t,type_of u]--->bool) $ t $ u);
353 fun is_expliceq (Const("HOL.eq",_) $ (Free _) $ u) = true
354 | is_expliceq _ = false;
355 fun strip_trueprop (Const("HOL.Trueprop",_) $ t) = t
356 | strip_trueprop t = t;
357 (* | strip_trueprop t = raise TERM("strip_trueprop", [t]);
360 (*.(A1==>...An==>B) goes to (A1==>...An==>).*)
361 fun strip_imp_prems' (Const("==>", T) $ A $ t) =
362 let fun coll_prems As (Const("==>", _) $ A $ t) =
363 coll_prems (As $ (Logic.implies $ A)) t
364 | coll_prems As _ = SOME As
365 in coll_prems (Logic.implies $ A) t end
366 | strip_imp_prems' _ = NONE; (* logic.ML: term -> term list*)
368 val thm = real_mult_div_cancel1;
369 val prop = (#prop o rep_thm) thm;
373 *** . Const ( Trueprop)
375 *** . . . Const ( op =)
376 *** . . . . Var ((k, 0), )
377 *** . . . . Const ( 0)
378 *** . Const ( Trueprop)
379 *** . . Const ( op =) *** .............
380 val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
384 *** . Const ( Trueprop)
386 *** . . . Const ( op =)
387 *** . . . . Var ((k, 0), )
388 *** . . . . Const ( 0)
390 val thm = real_le_anti_sym;
391 val prop = (#prop o rep_thm) thm;
395 *** . Const ( Trueprop)
396 *** . . Const ( op <=)
397 *** . . . Var ((z, 0), )
398 *** . . . Var ((w, 0), )
400 *** . . Const ( Trueprop)
401 *** . . . Const ( op <=)
402 *** . . . . Var ((w, 0), )
403 *** . . . . Var ((z, 0), )
404 *** . . Const ( Trueprop)
405 *** . . . Const ( op =)
407 val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
411 *** . Const ( Trueprop)
412 *** . . Const ( op <=)
413 *** . . . Var ((z, 0), )
414 *** . . . Var ((w, 0), )
416 *** . . Const ( Trueprop)
417 *** . . . Const ( op <=)
418 *** . . . . Var ((w, 0), )
419 *** . . . . Var ((z, 0), )
422 (*. (A1==>...An==>) (B) goes to (A1==>...An==>B), where B is lowest branch.*)
423 fun ins_concl (Const("==>", T) $ A $ t) B = Logic.implies $ A $ (ins_concl t B)
424 | ins_concl (Const("==>", T) $ A ) B = Logic.implies $ A $ B
425 | ins_concl t B = raise TERM("ins_concl", [t, B]);
427 val thm = real_le_anti_sym;
428 val prop = (#prop o rep_thm) thm;
429 val concl = Logic.strip_imp_concl prop;
430 val SOME prems = strip_imp_prems' prop;
431 val prop' = ins_concl prems concl;
438 fun vperm (Var _, Var _) = true (*2002 Pure/thm.ML *)
439 | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t)
440 | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2)
441 | vperm (t, u) = (t = u);
443 (*2002 cp from Pure/term.ML --- since 2009 in Pure/old_term.ML*)
444 fun mem_term (_, []) = false
445 | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts);
446 fun subset_term ([], ys) = true
447 | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys);
448 fun eq_set_term (xs, ys) =
449 xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs));
450 (*a total, irreflexive ordering on index names*)
451 fun xless ((a,i), (b,j): indexname) = i<j orelse (i=j andalso a<b);
452 (*a partial ordering (not reflexive) for atomic terms*)
453 fun atless (Const (a,_), Const (b,_)) = a<b
454 | atless (Free (a,_), Free (b,_)) = a<b
455 | atless (Var(v,_), Var(w,_)) = xless(v,w)
456 | atless (Bound i, Bound j) = i<j
458 (*insert atomic term into partially sorted list, suppressing duplicates (?)*)
459 fun insert_aterm (t,us) =
460 let fun inserta [] = [t]
461 | inserta (us as u::us') =
462 if atless(t,u) then t::us
463 else if t=u then us (*duplicate*)
464 else u :: inserta(us')
467 (*Accumulates the Vars in the term, suppressing duplicates*)
468 fun add_term_vars (t, vars: term list) = case t of
469 Var _ => insert_aterm(t,vars)
470 | Abs (_,_,body) => add_term_vars(body,vars)
471 | f$t => add_term_vars (f, add_term_vars(t, vars))
473 fun term_vars t = add_term_vars(t,[]);
476 fun var_perm (t, u) = (*2002 Pure/thm.ML *)
477 vperm (t, u) andalso eq_set_term (term_vars t, term_vars u);
479 (*2002 fun decomp_simp, Pure/thm.ML *)
480 fun perm lhs rhs = var_perm (lhs, rhs) andalso not (lhs aconv rhs)
481 andalso not (is_Var lhs);
485 if n < 0 then "-"^((string_of_int o abs) n)
486 else string_of_int n;
489 val it = "1" : string > str_of_int ~1;
490 val it = "-1" : string
496 if n>0 then b*(power b (n-1))
497 else error ("power "^(str_of_int b)^" "^(str_of_int n));
508 | gcd a b = if a < b then gcd (b mod a) a
509 else gcd (a mod b) b;
510 fun sign n = if n < 0 then ~1
511 else if n = 0 then 0 else 1;
512 fun sign2 n1 n2 = (sign n1) * (sign n2);
515 fun d dvd n = n mod d = 0;
518 let fun pdiv ds d n =
520 else if d dvd n then pdiv (d::ds) d (n div d)
529 fun doubles ds = (* ds is ordered *)
530 let fun dbls ds [] = ds
532 | dbls ds (i::i'::is) = if i=i' then dbls (i::ds) is
533 else dbls ds (i'::is)
536 val it = [] : int list
537 > doubles [2,3,3,5,5,7];
538 val it = [5,3] : int list*)
542 | squfact n = foldl op* (1, (doubles o divisors) n);
553 fun dest_type (Type(T,[])) = T
556 error ("... dest_type: not impl. for this type"));
558 fun term_of_num ntyp n = Free (str_of_int n, ntyp);
560 fun pairT T1 T2 = Type ("*", [T1, T2]);
561 (*> val t = str2term "(1,2)";
562 > type_of t = pairT HOLogic.realT HOLogic.realT;
565 fun PairT T1 T2 = ([T1, T2] ---> Type ("*", [T1, T2]));
566 (*> val t = str2term "(1,2)";
567 > val Const ("Product_Type.Pair",pT) $ _ $ _ = t;
568 > pT = PairT HOLogic.realT HOLogic.realT;
572 Const ("Product_Type.Pair", PairT (type_of t1) (type_of t2)) $ t1 $ t2;
573 (*> val t = str2term "(1,2)";
574 > val (t1, t2) = (str2term "1", str2term "2");
576 val it = true : bool*)
579 fun num_of_term (t as Free (s,_)) =
580 (case int_of_str s of
582 | NONE => error ("num_of_term not for "^ term2str t))
583 | num_of_term t = error ("num_of_term not for "^term2str t);
585 fun mk_factroot op_(*=thy.sqrt*) T fact root =
586 Const ("Groups.times_class.times", [T, T] ---> T) $ (term_of_num T fact) $
587 (Const (op_, T --> T) $ term_of_num T root);
589 val T = (type_of o term_of o the) (parse thy "#12::real");
590 val t = mk_factroot "SqRoot.sqrt" T 2 3;
592 val it = "#2 * sqrt #3 " : cterm
594 fun var_op_num v op_ optype ntyp n =
595 Const (op_, optype) $ v $
596 Free (str_of_int n, ntyp);
598 fun num_op_var v op_ optype ntyp n =
600 Free (str_of_int n, ntyp) $ v;
602 fun num_op_num T1 T2 (op_,Top) n1 n2 =
604 Free (str_of_int n1, T1) $ Free (str_of_int n2, T2);
606 > val t = num_op_num "Int" 3 4;
608 > string_of_cterm ((cterm_of thy) t);
613 fun const_in str (Const _) = false
614 | const_in str (Free (s,_)) = if strip_thy s = str then true else false
615 | const_in str (Bound _) = false
616 | const_in str (Var _) = false
617 | const_in str (Abs (_,_,body)) = const_in str body
618 | const_in str (f$u) = const_in str f orelse const_in str u;
620 > val t = (term_of o the o (parse thy)) "6 + 5 * sqrt 4 + 3";
623 > val t = (term_of o the o (parse thy)) "6 + 5 * 4 + 3";
625 val it = false : bool
628 (*used for calculating built in binary operations in Isabelle2002->Float.ML*)
629 (*fun calc "Groups.plus_class.plus" (n1, n2) = n1+n2
630 | calc "Groups.minus_class.minus" (n1, n2) = n1-n2
631 | calc "Groups.times_class.times" (n1, n2) = n1*n2
632 | calc "Rings.inverse_class.divide"(n1, n2) = n1 div n2
633 | calc "Atools.pow"(n1, n2) = power n1 n2
634 | calc op_ _ = error ("calc: operator = "^op_^" not defined");-----*)
635 fun calc_equ "less" (n1, n2) = n1 < n2
636 | calc_equ "less_eq" (n1, n2) = n1 <= n2
638 error ("calc_equ: operator = "^op_^" not defined");
639 fun sqrt (n:int) = if n < 0 then 0
640 (*FIXME ~~~*) else (trunc o Math.sqrt o Real.fromInt) n;
642 fun mk_thmid thmid op_ n1 n2 =
643 thmid ^ (strip_thy n1) ^ "_" ^ (strip_thy n2);
645 fun dest_binop_typ (Type("fun",[range,Type("fun",[arg2,arg1])])) =
647 | dest_binop_typ _ = error "dest_binop_typ: not binary";
649 > val t = (term_of o the o (parse thy)) "#3^#4";
650 > val hT = type_of (head_of t);
652 val it = ("'a","nat","'a") : typ * typ * typ
656 (** transform binary numeralsstrings **)
657 (*Makarius 100308, hacked by WN*)
658 val numbers_to_string =
661 (case try HOLogic.dest_number t of
663 (*if T = @{typ int} orelse T = @{typ real} then WN*)
664 SOME (Free (signed_string_of_int i, T))
668 fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
669 | to_str (t as (u1 $ u2)) =
672 | NONE => to_str u1 $ to_str u2)
673 | to_str t = perhaps dest_num t;
676 (*.make uminus uniform:
677 Const ("uminus", _) $ Free ("2", "RealDef.real") --> Free ("-2", _)
678 to be used immediately before evaluation of numerals;
679 see Scripts/calculate.sml .*)
680 (*2002 fun(*app_num_tr'2 (Const("0",T)) = Free("0",T)
681 | app_num_tr'2 (Const("1",T)) = Free("1",T)
682 |*)app_num_tr'2 (t as Const("uminus",_) $ Free(s,T)) =
683 (case int_of_str s of SOME i =>
684 if i > 0 then Free("-"^s,T) else Free(s,T)
686 (*| app_num_tr'2 (t as Const(s,T)) = t
687 | app_num_tr'2 (Const("Numeral.number_of",Type ("fun", [_, T])) $ t) =
688 Free(NumeralSyntax.dest_bin_str t, T)
689 | app_num_tr'2 (t as Free(s,T)) = t
690 | app_num_tr'2 (t as Var(n,T)) = t
691 | app_num_tr'2 (t as Bound i) = t
692 *)| app_num_tr'2 (Abs(s,T,body)) = Abs(s,T, app_num_tr'2 body)
693 | app_num_tr'2 (t1 $ t2) = (app_num_tr'2 t1) $ (app_num_tr'2 t2)
694 | app_num_tr'2 t = t;
696 val uminus_to_string =
700 (Const ("Groups.uminus_class.uminus", _) $ Free (s, T)) =>
701 (case int_of_str s of
703 SOME (Free (signed_string_of_int (~1 * i), T))
707 fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
708 | to_str (t as (u1 $ u2)) =
711 | NONE => to_str u1 $ to_str u2)
712 | to_str t = perhaps dest_num t;
716 (*2002 fun num_str thm =
718 val {sign_ref = sign_ref, der = der, maxidx = maxidx,
719 shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} =
721 val prop' = app_num_tr'1 prop;
722 in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end;*)
725 {thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps,
726 hyps = hyps, tpairs = tpairs, prop = prop}) = rep_thm_G thm
727 val prop' = numbers_to_string prop;
728 in assbl_thm deriv thy_ref tags maxidx shyps hyps tpairs prop' end;
730 fun get_thm' xstring = (*?covers 2009 Thm?!, replaces 2002 fun get_thm :
731 val it = fn : theory -> xstring -> Thm.thm*)
733 num_str (ProofContext.get_thm (thy2ctxt' "Isac") xstring));
735 (** get types of Free and Abs for parse' **)
736 (*11.1.00: not used, fix-typed +,*,-,^ instead *)
738 val dummyT = Type ("dummy",[]);
739 val dummyT = TVar (("DUMMY",0),[]);
741 (* assumes only 1 type for numerals
742 and different identifiers for Const, Free and Abs *)
745 fun get ts (Const(s,T)) = (s,T)::ts
746 | get ts (Free(s,T)) = if is_no s
747 then ("#",T)::ts else (s,T)::ts
748 | get ts (Var(n,T)) = ts
749 | get ts (Bound i) = ts
750 | get ts (Abs(s,T,body)) = get ((s,T)::ts) body
751 | get ts (t1 $ t2) = (get ts t1) @ (get ts t2)
752 in distinct (get [] t) end;
754 val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
758 (*11.1.00: not used, fix-typed +,*,-,^ instead *)
759 fun set_types al (Const(s,T)) =
760 (case assoc (al,s) of
761 SOME T' => Const(s,T')
762 | NONE => (warning ("set_types: no type for "^s); Const(s,dummyT)))
763 | set_types al (Free(s,T)) =
765 (case assoc (al,"#") of
766 SOME T' => Free(s,T')
767 | NONE => (warning ("set_types: no type for numerals"); Free(s,T)))
768 else (case assoc (al,s) of
769 SOME T' => Free(s,T')
770 | NONE => (warning ("set_types: no type for "^s); Free(s,T)))
771 | set_types al (Var(n,T)) = Var(n,T)
772 | set_types al (Bound i) = Bound i
773 | set_types al (Abs(s,T,body)) =
774 (case assoc (al,s) of
775 SOME T' => Abs(s,T', set_types al body)
776 | NONE => (warning ("set_types: no type for "^s);
777 Abs(s,T, set_types al body)))
778 | set_types al (t1 $ t2) = (set_types al t1) $ (set_types al t2);
780 val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
781 val al = get_types t;
783 val t = (term_of o the o (parse thy)) "x = #0 + #-1 * #-4";
785 val t' = set_types al t;
788 val it = "x = #0 + #-1 * #-4" : cterm
790 val t = (term_of o the o (parse thy))
791 "#5 * x + x ^^^ #2 = (#2 + x) ^^^ #2";
793 val t' = set_types al t;
796 uncaught exception TYPE (*^^^ is new, NOT in al*)
800 (** from Descript.ML **)
802 (** decompose an isa-list to an ML-list
803 i.e. [] belong to the meta-language, too **)
805 fun is_list ((Const("List.list.Cons",_)) $ _ $ _) = true
807 (* val (SOME ct) = parse thy "lll::real list";
808 > val ty = (#t o rep_cterm) ct;
810 val it = false : bool
811 > val (SOME ct) = parse thy "[lll]";
812 > val ty = (#t o rep_cterm) ct;
814 val it = true : bool *)
818 fun mk_Free (s,T) = Free(s,T);
819 fun mk_free T s = Free(s,T);
821 (*Special case: one argument cp from Isabelle2002/src/Pure/term.ML*)
822 fun subst_bound (arg, t) : term = (*WN100908 neglects 'raise Same.SAME'*)
823 let fun subst (t as Bound i, lev) =
824 if i<lev then t (*var is locally bound*)
825 else if i=lev then incr_boundvars lev arg
826 else Bound(i-1) (*loose: change it*)
827 | subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1))
828 | subst (f$t, lev) = subst(f,lev) $ subst(t,lev)
832 (*instantiate let; necessary for ass_up*)
833 fun inst_abs thy (Const sT) = Const sT (*TODO.WN100907 drop thy*)
834 | inst_abs thy (Free sT) = Free sT
835 | inst_abs thy (Bound n) = Bound n
836 | inst_abs thy (Var iT) = Var iT
837 | inst_abs thy (Const ("HOL.Let",T1) $ e $ (Abs (v, T2, b))) =
838 let val b' = subst_bound (Free (v, T2), b);
839 (*fun variant_abs: term.ML*)
840 in Const ("HOL.Let", T1) $ inst_abs thy e $ (Abs (v, T2, inst_abs thy b')) end
841 | inst_abs thy (t1 $ t2) = inst_abs thy t1 $ inst_abs thy t2
842 | inst_abs thy t = t;
844 "Script Make_fun_by_explicit (f_::real) (v_::real) (eqs_::bool list) = \
845 \ (let h_ = (hd o (filterVar f_)) eqs_; \
846 \ e_1 = hd (dropWhile (ident h_) eqs_); \
847 \ vs_ = dropWhile (ident f_) (Vars h_); \
848 \ v_1 = hd (dropWhile (ident v_) vs_); \
849 \ (s_1::bool list)=(SubProblem(DiffApp_,[univar,equation],[no_met])\
850 \ [BOOL e_1, REAL v_1])\
851 \ in Substitute [(v_1 = (rhs o hd) s_1)] h_)";
852 > val ttt = (term_of o the o (parse thy)) scr;
853 > tracing(term2str ttt);
856 *** Const ( DiffApp.Make'_fun'_by'_explicit)
861 *** . . Const ( Fun.op o)
862 *** . . . Const ( List.hd)
863 *** . . . Const ( DiffApp.filterVar)
864 *** . . . . Free ( f_, )
865 *** . . . Free ( eqs_, )
867 *** . . . Const ( Let)
868 *** . . . . Const ( List.hd)
869 *** . . . . . Const ( List.dropWhile)
870 *** . . . . . . Const ( Atools.ident)
871 *** . . . . . . . Bound 0 <---- Free ( h_, )
872 *** . . . . . . Free ( eqs_, )
873 *** . . . . Abs( e_1,..
874 *** . . . . . Const ( Let)
875 *** . . . . . . Const ( List.dropWhile)
876 *** . . . . . . . Const ( Atools.ident)
877 *** . . . . . . . . Free ( f_, )
878 *** . . . . . . . Const ( Tools.Vars)
879 *** . . . . . . . . Bound 1 <---- Free ( h_, )
880 *** . . . . . . Abs( vs_,..
881 *** . . . . . . . Const ( Let)
882 *** . . . . . . . . Const ( List.hd)
883 *** . . . . . . . . . Const ( List.dropWhile)
884 *** . . . . . . . . . . Const ( Atools.ident)
885 *** . . . . . . . . . . . Free ( v_, )
886 *** . . . . . . . . . . Bound 0 <---- Free ( vs_, )
887 *** . . . . . . . . Abs( v_1,..
888 *** . . . . . . . . . Const ( Let)
889 *** . . . . . . . . . . Const ( Script.SubProblem)
890 *** . . . . . . . . . . . Const ( Pair)
891 *** . . . . . . . . . . . . Free ( DiffApp_, )
892 *** . . . . . . . . . . . . Const ( Pair)
893 *** . . . . . . . . . . . . . Const ( List.list.Cons)
894 *** . . . . . . . . . . . . . . Free ( univar, )
895 *** . . . . . . . . . . . . . . Const ( List.list.Cons)
896 *** . . . . . . . . . . . . . . . Free ( equation, )
897 *** . . . . . . . . . . . . . . . Const ( List.list.Nil)
898 *** . . . . . . . . . . . . . Const ( List.list.Cons)
899 *** . . . . . . . . . . . . . . Free ( no_met, )
900 *** . . . . . . . . . . . . . . Const ( List.list.Nil)
901 *** . . . . . . . . . . . Const ( List.list.Cons)
902 *** . . . . . . . . . . . . Const ( Script.BOOL)
903 *** . . . . . . . . . . . . . Bound 2 <----- Free ( e_1, )
904 *** . . . . . . . . . . . . Const ( List.list.Cons)
905 *** . . . . . . . . . . . . . Const ( Script.real_)
906 *** . . . . . . . . . . . . . . Bound 0 <----- Free ( v_1, )
907 *** . . . . . . . . . . . . . Const ( List.list.Nil)
908 *** . . . . . . . . . . Abs( s_1,..
909 *** . . . . . . . . . . . Const ( Script.Substitute)
910 *** . . . . . . . . . . . . Const ( List.list.Cons)
911 *** . . . . . . . . . . . . . Const ( Pair)
912 *** . . . . . . . . . . . . . . Bound 1 <----- Free ( v_1, )
913 *** . . . . . . . . . . . . . . Const ( Fun.op o)
914 *** . . . . . . . . . . . . . . . Const ( Tools.rhs)
915 *** . . . . . . . . . . . . . . . Const ( List.hd)
916 *** . . . . . . . . . . . . . . . Bound 0 <----- Free ( s_1, )
917 *** . . . . . . . . . . . . . Const ( List.list.Nil)
918 *** . . . . . . . . . . . . Bound 4 <----- Free ( h_, )
920 > val ttt' = inst_abs thy ttt;
921 > tracing(term2str ttt');
922 Script Make_fun_by_explicit f_ v_ eqs_ =
926 *** Const ( DiffApp.Make'_fun'_by'_explicit)
931 *** . . Const ( Fun.op o)
932 *** . . . Const ( List.hd)
933 *** . . . Const ( DiffApp.filterVar)
934 *** . . . . Free ( f_, )
935 *** . . . Free ( eqs_, )
937 *** . . . Const ( Let)
938 *** . . . . Const ( List.hd)
939 *** . . . . . Const ( List.dropWhile)
940 *** . . . . . . Const ( Atools.ident)
941 *** . . . . . . . Free ( h_, ) <---- Bound 0
942 *** . . . . . . Free ( eqs_, )
943 *** . . . . Abs( e_1,..
944 *** . . . . . Const ( Let)
945 *** . . . . . . Const ( List.dropWhile)
946 *** . . . . . . . Const ( Atools.ident)
947 *** . . . . . . . . Free ( f_, )
948 *** . . . . . . . Const ( Tools.Vars)
949 *** . . . . . . . . Free ( h_, ) <---- Bound 1
950 *** . . . . . . Abs( vs_,..
951 *** . . . . . . . Const ( Let)
952 *** . . . . . . . . Const ( List.hd)
953 *** . . . . . . . . . Const ( List.dropWhile)
954 *** . . . . . . . . . . Const ( Atools.ident)
955 *** . . . . . . . . . . . Free ( v_, )
956 *** . . . . . . . . . . Free ( vs_, ) <---- Bound 0
957 *** . . . . . . . . Abs( v_1,..
958 *** . . . . . . . . . Const ( Let)
959 *** . . . . . . . . . . Const ( Script.SubProblem)
960 *** . . . . . . . . . . . Const ( Pair)
961 *** . . . . . . . . . . . . Free ( DiffApp_, )
962 *** . . . . . . . . . . . . Const ( Pair)
963 *** . . . . . . . . . . . . . Const ( List.list.Cons)
964 *** . . . . . . . . . . . . . . Free ( univar, )
965 *** . . . . . . . . . . . . . . Const ( List.list.Cons)
966 *** . . . . . . . . . . . . . . . Free ( equation, )
967 *** . . . . . . . . . . . . . . . Const ( List.list.Nil)
968 *** . . . . . . . . . . . . . Const ( List.list.Cons)
969 *** . . . . . . . . . . . . . . Free ( no_met, )
970 *** . . . . . . . . . . . . . . Const ( List.list.Nil)
971 *** . . . . . . . . . . . Const ( List.list.Cons)
972 *** . . . . . . . . . . . . Const ( Script.BOOL)
973 *** . . . . . . . . . . . . . Free ( e_1, ) <----- Bound 2
974 *** . . . . . . . . . . . . Const ( List.list.Cons)
975 *** . . . . . . . . . . . . . Const ( Script.real_)
976 *** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 0
977 *** . . . . . . . . . . . . . Const ( List.list.Nil)
978 *** . . . . . . . . . . Abs( s_1,..
979 *** . . . . . . . . . . . Const ( Script.Substitute)
980 *** . . . . . . . . . . . . Const ( List.list.Cons)
981 *** . . . . . . . . . . . . . Const ( Pair)
982 *** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 1
983 *** . . . . . . . . . . . . . . Const ( Fun.op o)
984 *** . . . . . . . . . . . . . . . Const ( Tools.rhs)
985 *** . . . . . . . . . . . . . . . Const ( List.hd)
986 *** . . . . . . . . . . . . . . . Free ( s_1, ) <----- Bound 0
987 *** . . . . . . . . . . . . . Const ( List.list.Nil)
988 *** . . . . . . . . . . . . Free ( h_, ) <----- Bound 4
990 Note numbering of de Bruijn indexes !
992 Script Make_fun_by_explicit f_ v_ eqs_ =
993 let h_ = (hd o filterVar f_) eqs_;
994 e_1 = hd (dropWhile (ident h_ BOUND_0) eqs_);
995 vs_ = dropWhile (ident f_) (Vars h_ BOUND_1);
996 v_1 = hd (dropWhile (ident v_) vs_ BOUND_0);
998 SubProblem (DiffApp_, [univar, equation], [no_met])
999 [BOOL e_1 BOUND_2, REAL v_1 BOUND_0]
1000 in Substitute [(v_1 BOUND_1 = (rhs o hd) s_1 BOUND_0)] h_ BOUND_4
1003 (* for parse and parse_patt: fix all types to real *)
1004 fun T_a2real (Type (s, [])) =
1005 if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT
1007 | T_a2real (Type (s, Ts)) = Type (s, map T_a2real Ts)
1008 | T_a2real (TFree (s, srt)) =
1009 if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT
1011 | T_a2real (TVar ((s, i), srt)) =
1012 if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT
1013 else TVar ((s, i), srt)
1014 | T_a2real (TVar (("DUMMY",_), srt)) = HOLogic.realT;
1016 (*FIXME .. fixes the type (+see Typefix.thy*)
1017 fun typ_a2real (Const( s, T)) = (Const( s, T_a2real T))
1018 | typ_a2real (Free( s, T)) = (Free( s, T_a2real T))
1019 | typ_a2real (Var( n, T)) = (Var( n, T_a2real T))
1020 | typ_a2real (Bound i) = (Bound i)
1021 | typ_a2real (Abs(s,T,t)) = Abs(s, T, typ_a2real t)
1022 | typ_a2real (t1 $ t2) = (typ_a2real t1) $ (typ_a2real t2);
1026 fun parseold thy str =
1027 (let val t = ((*typ_a2real o*) numbers_to_string)
1028 (Syntax.read_term_global thy str)
1029 in SOME (cterm_of thy t) end)
1031 (*2002 fun parseN thy str =
1033 val sgn = sign_of thy;
1034 val t = ((*typ_a2real o app_num_tr'1 o*) term_of)
1035 (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
1036 in SOME (cterm_of sgn t) end)
1038 fun parseN thy str =
1039 (let val t = (*(typ_a2real o numbers_to_string)*)
1040 (Syntax.read_term_global thy str)
1041 in SOME (cterm_of thy t) end)
1043 (*2002 fun parse thy str =
1045 val sgn = sign_of thy;
1046 val t = (typ_a2real o app_num_tr'1 o term_of)
1047 (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
1048 in SOME (cterm_of sgn t) end) (*FIXXXXME 10.8.02: return term !!!*)
1050 (*2010 fun parse thy str =
1051 (let val t = (typ_a2real o app_num_tr'1) (Syntax.read_term_global thy str)
1052 in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
1055 (let val t = (typ_a2real o numbers_to_string)
1056 (Syntax.read_term_global thy str)
1057 in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
1060 > val (SOME ct) = parse thy "(-#5)^^^#3";
1061 > atomty (term_of ct);
1063 *** Const ( Nat.op ^, ['a, nat] => 'a)
1064 *** Const ( uminus, 'a => 'a)
1067 > val (SOME ct) = parse thy "R=R";
1068 > atomty (term_of ct);
1070 *** Const ( op =, [real, real] => bool)
1074 THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!!
1076 *** Const ( op =, [RealDef.real, RealDef.real] => bool)
1077 *** Free ( R, RealDef.real)
1078 *** Free ( R, RealDef.real) *)
1080 (*WN110317 parseNEW will replace parse after introduction of ctxt completed*)
1081 fun parseNEW ctxt str = SOME (Syntax.read_term ctxt str |> numbers_to_string)
1084 (* parse term patterns; Var ("v",_), i.e. "?v", are required for instantiation*)
1085 fun parse_patt thy str = (thy, str) |>> thy2ctxt
1086 |-> ProofContext.read_term_pattern
1087 |> numbers_to_string (*TODO drop*)
1088 |> typ_a2real; (*TODO drop*)
1090 (*version for testing local to theories*)
1091 fun str2term_ thy str = (term_of o the o (parse thy)) str;
1093 fun str2term str = (term_of o the o (parse (Thy_Info.get_theory "Isac"))) str;*)
1094 fun str2term str = parse_patt (Thy_Info.get_theory "Isac") str
1095 fun strs2terms ss = map str2term ss;
1096 fun str2termN str = (term_of o the o (parseN (Thy_Info.get_theory "Isac"))) str;
1098 (*+ makes a substitution from the output of Pattern.match +*)
1099 (*fun mk_subs ((id, _):indexname, t:term) = (Free (id,type_of t), t);*)
1100 fun mk_subs (subs: ((string * int) * (Term.typ * Term.term)) list) =
1101 let fun mk_sub ((id, _), (ty, tm)) = (Free (id, ty), tm) in
1102 map mk_sub subs end;
1104 val atomthm = atomt o #prop o rep_thm;
1106 (*.instantiate #prop thm with bound variables (as Free).*)
1107 fun inst_bdv [] t = t : term
1108 | inst_bdv (instl: (term*term) list) t =
1109 let fun subst (v as Var((s,_),T)) =
1110 (case Symbol.explode s of
1112 if_none (assoc(instl,Free(s,T))) (Free(s,T))
1114 | subst (Abs(a,T,body)) = Abs(a, T, subst body)
1115 | subst (f$t') = subst f $ subst t'
1116 | subst t = if_none (assoc(instl,t)) t
1120 (*WN050829 caution: is_atom (str2term"q_0/2 * L * x") = true !!!
1121 use length (vars term) = 1 instead*)
1122 fun is_atom (Const ("Float.Float",_) $ _) = true
1123 | is_atom (Const ("ComplexI.I'_'_",_)) = true
1124 | is_atom (Const ("Groups.times_class.times",_) $ t $ Const ("ComplexI.I'_'_",_)) = is_atom t
1125 | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ Const ("ComplexI.I'_'_",_)) = is_atom t1
1126 | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $
1127 (Const ("Groups.times_class.times",_) $ t2 $ Const ("ComplexI.I'_'_",_))) =
1128 is_atom t1 andalso is_atom t2
1129 | is_atom (Const _) = true
1130 | is_atom (Free _) = true
1131 | is_atom (Var _) = true
1132 | is_atom _ = false;
1133 (* val t = str2term "q_0/2 * L * x";
1137 (*val t = str2term "Float ((1,2),(0,0))";
1139 val it = true : bool
1140 > val t = str2term "Float ((1,2),(0,0)) * I__";
1142 val it = true : bool
1143 > val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * I__";
1145 val it = true : bool
1146 > val t = str2term "1 + 2*I__";
1147 > val Const ("Groups.plus_class.plus",_) $ t1 $ (Const ("Groups.times_class.times",_) $ t2 $ Const ("ComplexI.I'_'_",_)) = t;
1150 (*.adaption from Isabelle/src/Pure/term.ML; reports if ALL Free's
1151 have found a substitution (required for evaluating the preconditions
1152 of _incomplete_ models).*)
1153 fun subst_atomic_all [] t = (false, (*TODO may be 'true' for some terms ?*)
1155 | subst_atomic_all (instl: (term*term) list) t =
1156 let fun subst (Abs(a,T,body)) =
1157 let val (all, body') = subst body
1158 in (all, Abs(a, T, body')) end
1160 let val (all1, f') = subst f
1161 val (all2, tt') = subst tt
1162 in (all1 andalso all2, f' $ tt') end
1163 | subst (t as Free _) =
1164 if is_num t then (true, t) (*numerals cannot be subst*)
1165 else (case assoc(instl,t) of
1166 SOME t' => (true, t')
1167 | NONE => (false, t))
1168 | subst t = (true, if_none (assoc(instl,t)) t)
1171 (*.add two terms with a type given.*)
1173 let val T1 = type_of t1
1175 in if T1 <> T2 then raise TYPE ("mk_add gets ",[T1, T2],[t1,t2])
1176 else (Const ("Groups.plus_class.plus", [T1, T2] ---> T1) $ t1 $ t2)