1 (* Title: extends Isabelle/src/Pure/term.ML
2 Author: Walther Neuper 1999
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 print (ato 0 t ^ "\n") end; TODO TUM10*)
38 in tracing (ato 0 t) end;
40 > val T = (type_of o term_of o the o (parse thy)) "a::[real,int] => nat";
43 *** Type (RealDef.real,[])
45 *** Type (IntDef.int,[])
51 (*Prog.Tutorial.p.34, Makarius 1005 does the above like this..*)
53 fun pp_pair (x, y) = Pretty.list "(" ")" [x, y]
54 fun pp_list xs = Pretty.list "[" "]" xs
55 fun pp_str s = Pretty.str s
56 fun pp_qstr s = Pretty.quote (pp_str s)
57 fun pp_int i = pp_str (string_of_int i)
58 fun pp_sort S = pp_list (map pp_qstr S)
59 fun pp_constr a args = Pretty.block [pp_str a, Pretty.brk 1, args]
61 fun raw_pp_typ (TVar ((a, i), S)) =
62 pp_constr "TVar" (pp_pair (pp_pair (pp_qstr a, pp_int i), pp_sort S))
63 | raw_pp_typ (TFree (a, S)) =
64 pp_constr "TFree" (pp_pair (pp_qstr a, pp_sort S))
65 | raw_pp_typ (Type (a, tys)) =
66 pp_constr "Type" (pp_pair (pp_qstr a, pp_list (map raw_pp_typ tys)))
69 PolyML.addPrettyPrinter
70 (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ);
72 PolyML.addPrettyPrinter
73 (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy);
77 let fun ato (Const (a, _)) n =
78 "\n*** " ^ indent n ^ "Const (" ^ a ^ ", _)"
79 | ato (Free (a, _)) n =
80 "\n*** " ^ indent n ^ "Free (" ^ a ^ ", _)"
81 | ato (Var ((a, i), _)) n =
82 "\n*** " ^ indent n ^ "Var (" ^ a ^ ", " ^
83 string_of_int i ^ "), _)"
85 "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
86 | ato (Abs (a, _, body)) n =
87 "\n*** " ^ indent n ^ "Abs(" ^ a ^ ", _" ^ ato body (n+1)
88 | ato (f $ t) n = (ato f n ^ ato t (n + 1))
89 in tracing ("\n*** -------------" ^ ato t 0 ^ "\n***") end;
91 fun term_detail2str t =
92 let fun ato (Const (a, T)) n =
93 "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ T ^ ")"
94 | ato (Free (a, T)) n =
95 "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ T ^ ")"
96 | ato (Var ((a, i), T)) n =
97 "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^
100 "\n*** " ^ indent n ^ "Bound " ^ string_of_int i
101 | ato (Abs(a, T, body)) n =
102 "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ T ^ ",.."
104 | ato (f $ t) n = ato f n ^ ato t (n + 1)
105 in "\n*** " ^ ato t 0 ^ "\n***" end;
106 fun atomty t = (tracing o term_detail2str) t; (*WN100907 broken*)
108 fun term_str thy (Const(s,_)) = s
109 | term_str thy (Free(s,_)) = s
110 | term_str thy (Var((s,i),_)) = s^(string_of_int i)
111 | term_str thy (Bound i) = "B."^(string_of_int i)
112 | term_str thy (Abs(s,_,_)) = s
113 | term_str thy t = raise error("term_str not for "^term2str t);
115 (*.contains the fst argument the second argument (a leave! of term).*)
116 fun contains_term (Abs(_,_,body)) t = contains_term body t
117 | contains_term (f $ f') t =
118 contains_term f t orelse contains_term f' t
119 | contains_term s t = t = s;
120 (*.contains the term a VAR(("*",_),_) ?.*)
121 fun contains_Var (Abs(_,_,body)) = contains_Var body
122 | contains_Var (f $ f') = contains_Var f orelse contains_Var f'
123 | contains_Var (Var _) = true
124 | contains_Var _ = false;
125 (* contains_Var (str2term "?z = 3") (*true*);
126 contains_Var (str2term "z = 3") (*false*);
129 (*fun int_of_str str =
130 let val ss = explode str
131 val str' = case ss of
132 "("::s => drop_last s | _ => ss
133 in case BasisLibrary.Int.fromString (implode str') of
135 | NONE => NONE end;*)
137 let val ss = explode str
138 val str' = case ss of
139 "("::s => drop_last s | _ => ss
140 in (SOME (Thy_Output.integer (implode str'))) handle _ => NONE end;
143 val it = SOME 123 : int option
144 > int_of_str "(-123)";
145 val it = SOME 123 : int option
147 val it = NONE : int option
149 val it = SOME ~123 : int option
151 fun int_of_str' str =
152 case int_of_str str of
154 | NONE => raise TERM ("int_of_string: no int-string",[]);
155 val str2int = int_of_str';
157 fun is_numeral str = case int_of_str str of
160 val is_no = is_numeral;
161 fun is_num (Free (s,_)) = if is_numeral s then true else false
164 > is_num ((term_of o the o (parse thy)) "#1");
166 > is_num ((term_of o the o (parse thy)) "#-1");
168 > is_num ((term_of o the o (parse thy)) "a123");
169 val it = false : bool
172 (*fun int_of_Free (Free (intstr, _)) =
173 (case BasisLibrary.Int.fromString intstr of
175 | NONE => raise error ("int_of_Free ( "^ intstr ^", _)"))
176 | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");*)
177 fun int_of_Free (Free (intstr, _)) = (Thy_Output.integer intstr
178 handle _ => raise error ("int_of_Free ( "^ intstr ^", _)"))
179 | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");
183 fun scan vs (Const(s,T)) = vs
184 | scan vs (t as Free(s,T)) = if is_no s then vs else t::vs
185 | scan vs (t as Var((s,i),T)) = t::vs
186 | scan vs (Bound i) = vs
187 | scan vs (Abs(s,T,t)) = scan vs t
188 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
189 in (distinct o (scan [])) t end;
191 fun is_Free (Free _) = true
193 fun is_fun_id (Const _) = true
194 | is_fun_id (Free _) = true
195 | is_fun_id _ = false;
196 fun is_f_x (f $ x) = is_fun_id f andalso is_Free x
198 (* is_f_x (str2term "q_0/2 * L * x") (*false*);
199 is_f_x (str2term "M_b x") (*true*);
203 fun scan vs (Const(s,T)) = vs
204 | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
205 | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
206 | scan vs (Bound i) = vs
207 | scan vs (Abs(s,T,t)) = scan vs t
208 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
209 in (distinct o (scan [])) t end;
213 fun scan vs (Const(s,T)) = if is_no s then vs else s::vs
214 | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs
215 | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs
216 | scan vs (Bound i) = vs
217 | scan vs (Abs(s,T,t)) = scan (s::vs) t
218 | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2)
219 in (distinct o (scan [])) t end;
222 "b"::"d"::"v"::_ => true
224 fun is_bdv_ (Free (s,_)) = is_bdv s
227 fun free2str (Free (s,_)) = s
228 | free2str t = raise error ("free2str not for "^ term2str t);
229 fun free2int (t as Free (s, _)) = ((str2int s)
230 handle _ => raise error ("free2int: "^term_detail2str t))
231 | free2int t = raise error ("free2int: "^term_detail2str t);
234 fun var2free (t as Const(s,T)) = t
235 | var2free (t as Free(s,T)) = t
236 | var2free (Var((s,i),T)) = Free(s,T)
237 | var2free (t as Bound i) = t
238 | var2free (Abs(s,T,t)) = Abs(s,T,var2free t)
239 | var2free (t1 $ t2) = (var2free t1) $ (var2free t2);
241 (*27.8.01: doesn't find some subterm ???!???*)
242 (*2010 free2var -> Logic.varify, but take care of 'Free ("1",_)'*)
243 fun free2var (t as Const (s, T)) = t
244 | free2var (t as Free (s, T)) = if is_no s then t else Var ((s, 0), T)
245 | free2var (t as Var ((s, i), T)) = t
246 | free2var (t as Bound i) = t
247 | free2var (Abs (s, T, t)) = Abs (s, T, free2var t)
248 | free2var (t1 $ t2) = (free2var t1) $ (free2var t2);
251 fun mk_listT T = Type ("List.list", [T]);
253 Const("List.list.Cons", [T, mk_listT T] ---> mk_listT T);
254 (*28.8.01: TODO: get type from head of list: 1 arg less!!!*)
255 fun list2isalist T [] = Const("List.list.Nil",mk_listT T)
256 | list2isalist T (t::ts) = (list_const T) $ t $ (list2isalist T ts);
258 > val tt = (term_of o the o (parse thy)) "R=(R::real)";
259 > val TT = type_of tt;
260 > val ss = list2isalist TT [tt,tt,tt];
262 val it = "[R = R, R = R, R = R]" : cterm *)
264 fun isapair2pair (Const ("Pair",_) $ a $ b) = (a,b)
266 raise error ("isapair2pair called with "^term2str t);
268 val listType = Type ("List.list",[Type ("bool",[])]);
269 fun isalist2list ls =
271 fun get es (Const("List.list.Cons",_) $ t $ ls) = get (t::es) ls
272 | get es (Const("List.list.Nil",_)) = es
274 raise error ("isalist2list applied to NON-list '"^term2str t^"'")
275 in (rev o (get [])) ls end;
277 > val il = str2term "[a=b,c=d,e=f]";
278 > val l = isalist2list il;
279 > (tracing o terms2str) l;
280 ["a = b","c = d","e = f"]
282 > val il = str2term "ss___::bool list";
283 > val l = isalist2list il;
284 [Free ("ss___", "bool List.list")]
288 (*review Isabelle2009/src/HOL/Tools/hologic.ML*)
289 val prop = Type ("prop",[]); (* ~/Diss.99/Integers-Isa/tools.sml*)
290 val bool = Type ("bool",[]); (* 2002 Integ.int *)
291 val Trueprop = Const("Trueprop",bool-->prop);
292 fun mk_prop t = Trueprop $ t;
293 val true_as_term = Const("True",bool);
294 val false_as_term = Const("False",bool);
295 val true_as_cterm = cterm_of (theory "HOL") true_as_term;
296 val false_as_cterm = cterm_of (theory "HOL") false_as_term;
298 infixr 5 -->; (*2002 /Pure/term.ML *)
299 infixr --->; (*2002 /Pure/term.ML *)
300 fun S --> T = Type("fun",[S,T]); (*2002 /Pure/term.ML *)
301 val op ---> = foldr (op -->); (*2002 /Pure/term.ML *)
302 fun list_implies ([], B) = B : term (*2002 /term.ML *)
303 | list_implies (A::AS, B) = Logic.implies $ A $ list_implies(AS,B);
309 fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) = (* = thm.ML *)
310 match_bvs(s, t, if x="" orelse y="" then al
312 | match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al))
313 | match_bvs(_,_,al) = al;
314 fun ren_inst(insts,prop,pat,obj) = (* = thm.ML *)
315 let val ren = match_bvs(pat,obj,[])
316 fun renAbs(Abs(x,T,b)) =
317 Abs(case assoc_string(ren,x) of NONE => x
318 | SOME(y) => y, T, renAbs(b))
319 | renAbs(f$t) = renAbs(f) $ renAbs(t)
321 in subst_vars insts (if null(ren) then prop else renAbs(prop)) end;
328 fun dest_equals' (Const("op =",_) $ t $ u) = (t,u)(* logic.ML: Const("=="*)
329 | dest_equals' t = raise TERM("dest_equals'", [t]);
330 val lhs_ = (fst o dest_equals');
331 val rhs_ = (snd o dest_equals');
333 fun is_equality (Const("op =",_) $ t $ u) = true (* logic.ML: Const("=="*)
334 | is_equality _ = false;
335 fun mk_equality (t,u) = (Const("op =",[type_of t,type_of u]--->bool) $ t $ u);
336 fun is_expliceq (Const("op =",_) $ (Free _) $ u) = true
337 | is_expliceq _ = false;
338 fun strip_trueprop (Const("Trueprop",_) $ t) = t
339 | strip_trueprop t = t;
340 (* | strip_trueprop t = raise TERM("strip_trueprop", [t]);
343 (*.(A1==>...An==>B) goes to (A1==>...An==>).*)
344 fun strip_imp_prems' (Const("==>", T) $ A $ t) =
345 let fun coll_prems As (Const("==>", _) $ A $ t) =
346 coll_prems (As $ (Logic.implies $ A)) t
347 | coll_prems As _ = SOME As
348 in coll_prems (Logic.implies $ A) t end
349 | strip_imp_prems' _ = NONE; (* logic.ML: term -> term list*)
351 val thm = real_mult_div_cancel1;
352 val prop = (#prop o rep_thm) thm;
356 *** . Const ( Trueprop)
358 *** . . . Const ( op =)
359 *** . . . . Var ((k, 0), )
360 *** . . . . Const ( 0)
361 *** . Const ( Trueprop)
362 *** . . Const ( op =) *** .............
363 val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
367 *** . Const ( Trueprop)
369 *** . . . Const ( op =)
370 *** . . . . Var ((k, 0), )
371 *** . . . . Const ( 0)
373 val thm = real_le_anti_sym;
374 val prop = (#prop o rep_thm) thm;
378 *** . Const ( Trueprop)
379 *** . . Const ( op <=)
380 *** . . . Var ((z, 0), )
381 *** . . . Var ((w, 0), )
383 *** . . Const ( Trueprop)
384 *** . . . Const ( op <=)
385 *** . . . . Var ((w, 0), )
386 *** . . . . Var ((z, 0), )
387 *** . . Const ( Trueprop)
388 *** . . . Const ( op =)
390 val SOME t = strip_imp_prems' ((#prop o rep_thm) thm);
394 *** . Const ( Trueprop)
395 *** . . Const ( op <=)
396 *** . . . Var ((z, 0), )
397 *** . . . Var ((w, 0), )
399 *** . . Const ( Trueprop)
400 *** . . . Const ( op <=)
401 *** . . . . Var ((w, 0), )
402 *** . . . . Var ((z, 0), )
405 (*. (A1==>...An==>) (B) goes to (A1==>...An==>B), where B is lowest branch.*)
406 fun ins_concl (Const("==>", T) $ A $ t) B = Logic.implies $ A $ (ins_concl t B)
407 | ins_concl (Const("==>", T) $ A ) B = Logic.implies $ A $ B
408 | ins_concl t B = raise TERM("ins_concl", [t, B]);
410 val thm = real_le_anti_sym;
411 val prop = (#prop o rep_thm) thm;
412 val concl = Logic.strip_imp_concl prop;
413 val SOME prems = strip_imp_prems' prop;
414 val prop' = ins_concl prems concl;
421 fun vperm (Var _, Var _) = true (*2002 Pure/thm.ML *)
422 | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t)
423 | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2)
424 | vperm (t, u) = (t = u);
426 (*2002 cp from Pure/term.ML --- since 2009 in Pure/old_term.ML*)
427 fun mem_term (_, []) = false
428 | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts);
429 fun subset_term ([], ys) = true
430 | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys);
431 fun eq_set_term (xs, ys) =
432 xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs));
433 (*a total, irreflexive ordering on index names*)
434 fun xless ((a,i), (b,j): indexname) = i<j orelse (i=j andalso a<b);
435 (*a partial ordering (not reflexive) for atomic terms*)
436 fun atless (Const (a,_), Const (b,_)) = a<b
437 | atless (Free (a,_), Free (b,_)) = a<b
438 | atless (Var(v,_), Var(w,_)) = xless(v,w)
439 | atless (Bound i, Bound j) = i<j
441 (*insert atomic term into partially sorted list, suppressing duplicates (?)*)
442 fun insert_aterm (t,us) =
443 let fun inserta [] = [t]
444 | inserta (us as u::us') =
445 if atless(t,u) then t::us
446 else if t=u then us (*duplicate*)
447 else u :: inserta(us')
450 (*Accumulates the Vars in the term, suppressing duplicates*)
451 fun add_term_vars (t, vars: term list) = case t of
452 Var _ => insert_aterm(t,vars)
453 | Abs (_,_,body) => add_term_vars(body,vars)
454 | f$t => add_term_vars (f, add_term_vars(t, vars))
456 fun term_vars t = add_term_vars(t,[]);
459 fun var_perm (t, u) = (*2002 Pure/thm.ML *)
460 vperm (t, u) andalso eq_set_term (term_vars t, term_vars u);
462 (*2002 fun decomp_simp, Pure/thm.ML *)
463 fun perm lhs rhs = var_perm (lhs, rhs) andalso not (lhs aconv rhs)
464 andalso not (is_Var lhs);
468 if n < 0 then "-"^((string_of_int o abs) n)
469 else string_of_int n;
472 val it = "1" : string > str_of_int ~1;
473 val it = "-1" : string
479 if n>0 then b*(power b (n-1))
480 else raise error ("power "^(str_of_int b)^" "^(str_of_int n));
491 | gcd a b = if a < b then gcd (b mod a) a
492 else gcd (a mod b) b;
493 fun sign n = if n < 0 then ~1
494 else if n = 0 then 0 else 1;
495 fun sign2 n1 n2 = (sign n1) * (sign n2);
498 fun d dvd n = n mod d = 0;
501 let fun pdiv ds d n =
503 else if d dvd n then pdiv (d::ds) d (n div d)
512 fun doubles ds = (* ds is ordered *)
513 let fun dbls ds [] = ds
515 | dbls ds (i::i'::is) = if i=i' then dbls (i::ds) is
516 else dbls ds (i'::is)
519 val it = [] : int list
520 > doubles [2,3,3,5,5,7];
521 val it = [5,3] : int list*)
525 | squfact n = foldl op* (1, (doubles o divisors) n);
536 fun dest_type (Type(T,[])) = T
539 raise error ("... dest_type: not impl. for this type"));
541 fun term_of_num ntyp n = Free (str_of_int n, ntyp);
543 fun pairT T1 T2 = Type ("*", [T1, T2]);
544 (*> val t = str2term "(1,2)";
545 > type_of t = pairT HOLogic.realT HOLogic.realT;
548 fun PairT T1 T2 = ([T1, T2] ---> Type ("*", [T1, T2]));
549 (*> val t = str2term "(1,2)";
550 > val Const ("Pair",pT) $ _ $ _ = t;
551 > pT = PairT HOLogic.realT HOLogic.realT;
555 Const ("Pair", PairT (type_of t1) (type_of t2)) $ t1 $ t2;
556 (*> val t = str2term "(1,2)";
557 > val (t1, t2) = (str2term "1", str2term "2");
559 val it = true : bool*)
562 fun num_of_term (t as Free (s,_)) =
563 (case int_of_str s of
565 | NONE => raise error ("num_of_term not for "^ term2str t))
566 | num_of_term t = raise error ("num_of_term not for "^term2str t);
568 fun mk_factroot op_(*=thy.sqrt*) T fact root =
569 Const ("op *", [T, T] ---> T) $ (term_of_num T fact) $
570 (Const (op_, T --> T) $ term_of_num T root);
572 val T = (type_of o term_of o the) (parse thy "#12::real");
573 val t = mk_factroot "SqRoot.sqrt" T 2 3;
575 val it = "#2 * sqrt #3 " : cterm
577 fun var_op_num v op_ optype ntyp n =
578 Const (op_, optype) $ v $
579 Free (str_of_int n, ntyp);
581 fun num_op_var v op_ optype ntyp n =
583 Free (str_of_int n, ntyp) $ v;
585 fun num_op_num T1 T2 (op_,Top) n1 n2 =
587 Free (str_of_int n1, T1) $ Free (str_of_int n2, T2);
589 > val t = num_op_num "Int" 3 4;
591 > string_of_cterm ((cterm_of thy) t);
594 fun const_in str (Const _) = false
595 | const_in str (Free (s,_)) = if strip_thy s = str then true else false
596 | const_in str (Bound _) = false
597 | const_in str (Var _) = false
598 | const_in str (Abs (_,_,body)) = const_in str body
599 | const_in str (f$u) = const_in str f orelse const_in str u;
601 > val t = (term_of o the o (parse thy)) "6 + 5 * sqrt 4 + 3";
604 > val t = (term_of o the o (parse thy)) "6 + 5 * 4 + 3";
606 val it = false : bool
609 (*used for calculating built in binary operations in Isabelle2002->Float.ML*)
610 (*fun calc "Groups.plus_class.plus" (n1, n2) = n1+n2
611 | calc "Groups.minus_class.minus" (n1, n2) = n1-n2
612 | calc "op *" (n1, n2) = n1*n2
613 | calc "Rings.inverse_class.divide"(n1, n2) = n1 div n2
614 | calc "Atools.pow"(n1, n2) = power n1 n2
615 | calc op_ _ = raise error ("calc: operator = "^op_^" not defined");-----*)
616 fun calc_equ "op <" (n1, n2) = n1 < n2
617 | calc_equ "op <=" (n1, n2) = n1 <= n2
619 raise error ("calc_equ: operator = "^op_^" not defined");
620 fun sqrt (n:int) = if n < 0 then 0
621 (*FIXME ~~~*) else (trunc o Math.sqrt o Real.fromInt) n;
623 fun mk_thmid thmid op_ n1 n2 =
624 thmid ^ (strip_thy n1) ^ "_" ^ (strip_thy n2);
626 fun dest_binop_typ (Type("fun",[range,Type("fun",[arg2,arg1])])) =
628 | dest_binop_typ _ = raise error "dest_binop_typ: not binary";
630 > val t = (term_of o the o (parse thy)) "#3^#4";
631 > val hT = type_of (head_of t);
633 val it = ("'a","nat","'a") : typ * typ * typ
637 (** transform binary numeralsstrings **)
638 (*Makarius 100308, hacked by WN*)
639 val numbers_to_string =
642 (case try HOLogic.dest_number t of
644 (*if T = @{typ int} orelse T = @{typ real} then WN*)
645 SOME (Free (signed_string_of_int i, T))
649 fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
650 | to_str (t as (u1 $ u2)) =
653 | NONE => to_str u1 $ to_str u2)
654 | to_str t = perhaps dest_num t;
657 (*.make uminus uniform:
658 Const ("uminus", _) $ Free ("2", "RealDef.real") --> Free ("-2", _)
659 to be used immediately before evaluation of numerals;
660 see Scripts/calculate.sml .*)
661 (*2002 fun(*app_num_tr'2 (Const("0",T)) = Free("0",T)
662 | app_num_tr'2 (Const("1",T)) = Free("1",T)
663 |*)app_num_tr'2 (t as Const("uminus",_) $ Free(s,T)) =
664 (case int_of_str s of SOME i =>
665 if i > 0 then Free("-"^s,T) else Free(s,T)
667 (*| app_num_tr'2 (t as Const(s,T)) = t
668 | app_num_tr'2 (Const("Numeral.number_of",Type ("fun", [_, T])) $ t) =
669 Free(NumeralSyntax.dest_bin_str t, T)
670 | app_num_tr'2 (t as Free(s,T)) = t
671 | app_num_tr'2 (t as Var(n,T)) = t
672 | app_num_tr'2 (t as Bound i) = t
673 *)| app_num_tr'2 (Abs(s,T,body)) = Abs(s,T, app_num_tr'2 body)
674 | app_num_tr'2 (t1 $ t2) = (app_num_tr'2 t1) $ (app_num_tr'2 t2)
675 | app_num_tr'2 t = t;
677 val uminus_to_string =
681 (Const ("Groups.uminus_class.uminus", _) $ Free (s, T)) =>
682 (case int_of_str s of
684 SOME (Free (signed_string_of_int (~1 * i), T))
688 fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b)
689 | to_str (t as (u1 $ u2)) =
692 | NONE => to_str u1 $ to_str u2)
693 | to_str t = perhaps dest_num t;
697 (*2002 fun num_str thm =
699 val {sign_ref = sign_ref, der = der, maxidx = maxidx,
700 shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} =
702 val prop' = app_num_tr'1 prop;
703 in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end;*)
706 {thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps,
707 hyps = hyps, tpairs = tpairs, prop = prop}) = rep_thm_G thm
708 val prop' = numbers_to_string prop;
709 in assbl_thm deriv thy_ref tags maxidx shyps hyps tpairs prop' end;
711 fun get_thm' xstring = (*?covers 2009 Thm?!, replaces 2002 fun get_thm :
712 val it = fn : theory -> xstring -> Thm.thm*)
714 num_str (ProofContext.get_thm (thy2ctxt' "Isac") xstring));
716 (** get types of Free and Abs for parse' **)
717 (*11.1.00: not used, fix-typed +,*,-,^ instead *)
719 val dummyT = Type ("dummy",[]);
720 val dummyT = TVar (("DUMMY",0),[]);
722 (* assumes only 1 type for numerals
723 and different identifiers for Const, Free and Abs *)
726 fun get ts (Const(s,T)) = (s,T)::ts
727 | get ts (Free(s,T)) = if is_no s
728 then ("#",T)::ts else (s,T)::ts
729 | get ts (Var(n,T)) = ts
730 | get ts (Bound i) = ts
731 | get ts (Abs(s,T,body)) = get ((s,T)::ts) body
732 | get ts (t1 $ t2) = (get ts t1) @ (get ts t2)
733 in distinct (get [] t) end;
735 val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
739 (*11.1.00: not used, fix-typed +,*,-,^ instead *)
740 fun set_types al (Const(s,T)) =
741 (case assoc (al,s) of
742 SOME T' => Const(s,T')
743 | NONE => (warning ("set_types: no type for "^s); Const(s,dummyT)))
744 | set_types al (Free(s,T)) =
746 (case assoc (al,"#") of
747 SOME T' => Free(s,T')
748 | NONE => (warning ("set_types: no type for numerals"); Free(s,T)))
749 else (case assoc (al,s) of
750 SOME T' => Free(s,T')
751 | NONE => (warning ("set_types: no type for "^s); Free(s,T)))
752 | set_types al (Var(n,T)) = Var(n,T)
753 | set_types al (Bound i) = Bound i
754 | set_types al (Abs(s,T,body)) =
755 (case assoc (al,s) of
756 SOME T' => Abs(s,T', set_types al body)
757 | NONE => (warning ("set_types: no type for "^s);
758 Abs(s,T, set_types al body)))
759 | set_types al (t1 $ t2) = (set_types al t1) $ (set_types al t2);
761 val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)";
762 val al = get_types t;
764 val t = (term_of o the o (parse thy)) "x = #0 + #-1 * #-4";
766 val t' = set_types al t;
769 val it = "x = #0 + #-1 * #-4" : cterm
771 val t = (term_of o the o (parse thy))
772 "#5 * x + x ^^^ #2 = (#2 + x) ^^^ #2";
774 val t' = set_types al t;
777 uncaught exception TYPE (*^^^ is new, NOT in al*)
781 (** from Descript.ML **)
783 (** decompose an isa-list to an ML-list
784 i.e. [] belong to the meta-language, too **)
786 fun is_list ((Const("List.list.Cons",_)) $ _ $ _) = true
788 (* val (SOME ct) = parse thy "lll::real list";
789 > val ty = (#t o rep_cterm) ct;
791 val it = false : bool
792 > val (SOME ct) = parse thy "[lll]";
793 > val ty = (#t o rep_cterm) ct;
795 val it = true : bool *)
799 fun mk_Free (s,T) = Free(s,T);
800 fun mk_free T s = Free(s,T);
802 (*Special case: one argument cp from Isabelle2002/src/Pure/term.ML*)
803 fun subst_bound (arg, t) : term = (*WN100908 neglects 'raise Same.SAME'*)
804 let fun subst (t as Bound i, lev) =
805 if i<lev then t (*var is locally bound*)
806 else if i=lev then incr_boundvars lev arg
807 else Bound(i-1) (*loose: change it*)
808 | subst (Abs(a,T,body), lev) = Abs(a, T, subst(body,lev+1))
809 | subst (f$t, lev) = subst(f,lev) $ subst(t,lev)
813 (*instantiate let; necessary for ass_up*)
814 fun inst_abs thy (Const sT) = Const sT (*TODO.WN100907 drop thy*)
815 | inst_abs thy (Free sT) = Free sT
816 | inst_abs thy (Bound n) = Bound n
817 | inst_abs thy (Var iT) = Var iT
818 | inst_abs thy (Const ("Let",T1) $ e $ (Abs (v, T2, b))) =
819 let val b' = subst_bound (Free (v, T2), b);
820 (*fun variant_abs: term.ML*)
821 in Const ("Let", T1) $ inst_abs thy e $ (Abs (v, T2, inst_abs thy b')) end
822 | inst_abs thy (t1 $ t2) = inst_abs thy t1 $ inst_abs thy t2
823 | inst_abs thy t = t;
825 "Script Make_fun_by_explicit (f_::real) (v_::real) (eqs_::bool list) = \
826 \ (let h_ = (hd o (filterVar f_)) eqs_; \
827 \ e_1 = hd (dropWhile (ident h_) eqs_); \
828 \ vs_ = dropWhile (ident f_) (Vars h_); \
829 \ v_1 = hd (dropWhile (ident v_) vs_); \
830 \ (s_1::bool list)=(SubProblem(DiffApp_,[univar,equation],[no_met])\
831 \ [BOOL e_1, REAL v_1])\
832 \ in Substitute [(v_1 = (rhs o hd) s_1)] h_)";
833 > val ttt = (term_of o the o (parse thy)) scr;
834 > tracing(term2str ttt);
837 *** Const ( DiffApp.Make'_fun'_by'_explicit)
842 *** . . Const ( Fun.op o)
843 *** . . . Const ( List.hd)
844 *** . . . Const ( DiffApp.filterVar)
845 *** . . . . Free ( f_, )
846 *** . . . Free ( eqs_, )
848 *** . . . Const ( Let)
849 *** . . . . Const ( List.hd)
850 *** . . . . . Const ( List.dropWhile)
851 *** . . . . . . Const ( Atools.ident)
852 *** . . . . . . . Bound 0 <---- Free ( h_, )
853 *** . . . . . . Free ( eqs_, )
854 *** . . . . Abs( e_1,..
855 *** . . . . . Const ( Let)
856 *** . . . . . . Const ( List.dropWhile)
857 *** . . . . . . . Const ( Atools.ident)
858 *** . . . . . . . . Free ( f_, )
859 *** . . . . . . . Const ( Tools.Vars)
860 *** . . . . . . . . Bound 1 <---- Free ( h_, )
861 *** . . . . . . Abs( vs_,..
862 *** . . . . . . . Const ( Let)
863 *** . . . . . . . . Const ( List.hd)
864 *** . . . . . . . . . Const ( List.dropWhile)
865 *** . . . . . . . . . . Const ( Atools.ident)
866 *** . . . . . . . . . . . Free ( v_, )
867 *** . . . . . . . . . . Bound 0 <---- Free ( vs_, )
868 *** . . . . . . . . Abs( v_1,..
869 *** . . . . . . . . . Const ( Let)
870 *** . . . . . . . . . . Const ( Script.SubProblem)
871 *** . . . . . . . . . . . Const ( Pair)
872 *** . . . . . . . . . . . . Free ( DiffApp_, )
873 *** . . . . . . . . . . . . Const ( Pair)
874 *** . . . . . . . . . . . . . Const ( List.list.Cons)
875 *** . . . . . . . . . . . . . . Free ( univar, )
876 *** . . . . . . . . . . . . . . Const ( List.list.Cons)
877 *** . . . . . . . . . . . . . . . Free ( equation, )
878 *** . . . . . . . . . . . . . . . Const ( List.list.Nil)
879 *** . . . . . . . . . . . . . Const ( List.list.Cons)
880 *** . . . . . . . . . . . . . . Free ( no_met, )
881 *** . . . . . . . . . . . . . . Const ( List.list.Nil)
882 *** . . . . . . . . . . . Const ( List.list.Cons)
883 *** . . . . . . . . . . . . Const ( Script.BOOL)
884 *** . . . . . . . . . . . . . Bound 2 <----- Free ( e_1, )
885 *** . . . . . . . . . . . . Const ( List.list.Cons)
886 *** . . . . . . . . . . . . . Const ( Script.real_)
887 *** . . . . . . . . . . . . . . Bound 0 <----- Free ( v_1, )
888 *** . . . . . . . . . . . . . Const ( List.list.Nil)
889 *** . . . . . . . . . . Abs( s_1,..
890 *** . . . . . . . . . . . Const ( Script.Substitute)
891 *** . . . . . . . . . . . . Const ( List.list.Cons)
892 *** . . . . . . . . . . . . . Const ( Pair)
893 *** . . . . . . . . . . . . . . Bound 1 <----- Free ( v_1, )
894 *** . . . . . . . . . . . . . . Const ( Fun.op o)
895 *** . . . . . . . . . . . . . . . Const ( Tools.rhs)
896 *** . . . . . . . . . . . . . . . Const ( List.hd)
897 *** . . . . . . . . . . . . . . . Bound 0 <----- Free ( s_1, )
898 *** . . . . . . . . . . . . . Const ( List.list.Nil)
899 *** . . . . . . . . . . . . Bound 4 <----- Free ( h_, )
901 > val ttt' = inst_abs thy ttt;
902 > tracing(term2str ttt');
903 Script Make_fun_by_explicit f_ v_ eqs_ =
907 *** Const ( DiffApp.Make'_fun'_by'_explicit)
912 *** . . Const ( Fun.op o)
913 *** . . . Const ( List.hd)
914 *** . . . Const ( DiffApp.filterVar)
915 *** . . . . Free ( f_, )
916 *** . . . Free ( eqs_, )
918 *** . . . Const ( Let)
919 *** . . . . Const ( List.hd)
920 *** . . . . . Const ( List.dropWhile)
921 *** . . . . . . Const ( Atools.ident)
922 *** . . . . . . . Free ( h_, ) <---- Bound 0
923 *** . . . . . . Free ( eqs_, )
924 *** . . . . Abs( e_1,..
925 *** . . . . . Const ( Let)
926 *** . . . . . . Const ( List.dropWhile)
927 *** . . . . . . . Const ( Atools.ident)
928 *** . . . . . . . . Free ( f_, )
929 *** . . . . . . . Const ( Tools.Vars)
930 *** . . . . . . . . Free ( h_, ) <---- Bound 1
931 *** . . . . . . Abs( vs_,..
932 *** . . . . . . . Const ( Let)
933 *** . . . . . . . . Const ( List.hd)
934 *** . . . . . . . . . Const ( List.dropWhile)
935 *** . . . . . . . . . . Const ( Atools.ident)
936 *** . . . . . . . . . . . Free ( v_, )
937 *** . . . . . . . . . . Free ( vs_, ) <---- Bound 0
938 *** . . . . . . . . Abs( v_1,..
939 *** . . . . . . . . . Const ( Let)
940 *** . . . . . . . . . . Const ( Script.SubProblem)
941 *** . . . . . . . . . . . Const ( Pair)
942 *** . . . . . . . . . . . . Free ( DiffApp_, )
943 *** . . . . . . . . . . . . Const ( Pair)
944 *** . . . . . . . . . . . . . Const ( List.list.Cons)
945 *** . . . . . . . . . . . . . . Free ( univar, )
946 *** . . . . . . . . . . . . . . Const ( List.list.Cons)
947 *** . . . . . . . . . . . . . . . Free ( equation, )
948 *** . . . . . . . . . . . . . . . Const ( List.list.Nil)
949 *** . . . . . . . . . . . . . Const ( List.list.Cons)
950 *** . . . . . . . . . . . . . . Free ( no_met, )
951 *** . . . . . . . . . . . . . . Const ( List.list.Nil)
952 *** . . . . . . . . . . . Const ( List.list.Cons)
953 *** . . . . . . . . . . . . Const ( Script.BOOL)
954 *** . . . . . . . . . . . . . Free ( e_1, ) <----- Bound 2
955 *** . . . . . . . . . . . . Const ( List.list.Cons)
956 *** . . . . . . . . . . . . . Const ( Script.real_)
957 *** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 0
958 *** . . . . . . . . . . . . . Const ( List.list.Nil)
959 *** . . . . . . . . . . Abs( s_1,..
960 *** . . . . . . . . . . . Const ( Script.Substitute)
961 *** . . . . . . . . . . . . Const ( List.list.Cons)
962 *** . . . . . . . . . . . . . Const ( Pair)
963 *** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 1
964 *** . . . . . . . . . . . . . . Const ( Fun.op o)
965 *** . . . . . . . . . . . . . . . Const ( Tools.rhs)
966 *** . . . . . . . . . . . . . . . Const ( List.hd)
967 *** . . . . . . . . . . . . . . . Free ( s_1, ) <----- Bound 0
968 *** . . . . . . . . . . . . . Const ( List.list.Nil)
969 *** . . . . . . . . . . . . Free ( h_, ) <----- Bound 4
971 Note numbering of de Bruijn indexes !
973 Script Make_fun_by_explicit f_ v_ eqs_ =
974 let h_ = (hd o filterVar f_) eqs_;
975 e_1 = hd (dropWhile (ident h_ BOUND_0) eqs_);
976 vs_ = dropWhile (ident f_) (Vars h_ BOUND_1);
977 v_1 = hd (dropWhile (ident v_) vs_ BOUND_0);
979 SubProblem (DiffApp_, [univar, equation], [no_met])
980 [BOOL e_1 BOUND_2, REAL v_1 BOUND_0]
981 in Substitute [(v_1 BOUND_1 = (rhs o hd) s_1 BOUND_0)] h_ BOUND_4
985 fun T_a2real (Type (s, [])) =
986 if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else Type (s, [])
987 | T_a2real (Type (s, Ts)) = Type (s, map T_a2real Ts)
988 | T_a2real (TFree (s, srt)) =
989 if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else TFree (s, srt)
990 | T_a2real (TVar (("DUMMY",_),srt)) = HOLogic.realT;
992 (*FIXME .. fixes the type (+see Typefix.thy*)
993 fun typ_a2real (Const( s, T)) = (Const( s, T_a2real T))
994 | typ_a2real (Free( s, T)) = (Free( s, T_a2real T))
995 | typ_a2real (Var( n, T)) = (Var( n, T_a2real T))
996 | typ_a2real (Bound i) = (Bound i)
997 | typ_a2real (Abs(s,T,t)) = Abs(s, T, typ_a2real t)
998 | typ_a2real (t1 $ t2) = (typ_a2real t1) $ (typ_a2real t2);
1000 ----------------6.8.02---------------------------------------------------
1002 val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[])));
1006 val t = (app_num_tr' o term_of) t;
1010 val t = typ_a2real t;
1013 *** Const ( 1, real)
1016 val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[])));
1019 *** Const ( Numeral.number_of, bin => 'a)
1020 *** . Const ( Numeral.bin.Bit, [bin, bool] => bin)
1021 *** . . Const ( Numeral.bin.Bit, [bin, bool] => bin)
1022 *** . . . Const ( Numeral.bin.Pls, bin)
1023 *** . . . Const ( True, bool)
1024 *** . . Const ( False, bool)
1025 val t = (app_num_tr' o term_of) t;
1029 val t = typ_a2real t;
1033 ----------------6.8.02---------------------------------------------------
1037 > val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
1038 val t = Free ("R","?DUMMY") : term
1039 > val t' = typ_a2real t;
1040 > (cterm_of thy) t';
1041 val it = "R::RealDef.real" : cterm
1044 > val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
1045 > atomty (typ_a2real t);
1047 *** Const ( op =, [RealDef.real, RealDef.real] => bool)
1048 *** Free ( R, RealDef.real)
1049 *** Free ( R, RealDef.real)
1050 > val t' = typ_a2real t;
1051 > (cterm_of thy) t';
1052 val it = "(R::RealDef.real) = R" : cterm
1054 > val str = "fixed_values [R=R]";
1055 > val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[]))));
1056 > val t' = typ_a2real t;
1057 > (cterm_of thy) t';
1058 val it = "fixed_values [(R::RealDef.real) = R]" : cterm
1061 (*TODO.WN0609: parse should return a term or a string
1062 (or even more comprehensive datastructure for error-messages)
1063 i.e. in wrapping with SOME term or NONE the latter is not sufficient*)
1064 (*2002 fun parseold thy str =
1066 val sgn = sign_of thy;
1067 val t = ((*typ_a2real o*) app_num_tr'1 o term_of)
1068 (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
1069 in SOME (cterm_of sgn t) end)
1074 fun parseold thy str =
1075 (let val t = ((*typ_a2real o*) numbers_to_string)
1076 (Syntax.read_term_global thy str)
1077 in SOME (cterm_of thy t) end)
1079 (*2002 fun parseN thy str =
1081 val sgn = sign_of thy;
1082 val t = ((*typ_a2real o app_num_tr'1 o*) term_of)
1083 (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
1084 in SOME (cterm_of sgn t) end)
1086 fun parseN thy str =
1087 (let val t = (*(typ_a2real o numbers_to_string)*)
1088 (Syntax.read_term_global thy str)
1089 in SOME (cterm_of thy t) end)
1091 (*2002 fun parse thy str =
1093 val sgn = sign_of thy;
1094 val t = (typ_a2real o app_num_tr'1 o term_of)
1095 (read_cterm sgn (str,(TVar(("DUMMY",0),[]))));
1096 in SOME (cterm_of sgn t) end) (*FIXXXXME 10.8.02: return term !!!*)
1098 (*2010 fun parse thy str =
1099 (let val t = (typ_a2real o app_num_tr'1) (Syntax.read_term_global thy str)
1100 in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
1103 (let val t = (typ_a2real o numbers_to_string)
1104 (Syntax.read_term_global thy str)
1105 in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*)
1108 > val (SOME ct) = parse thy "(-#5)^^^#3";
1109 > atomty (term_of ct);
1111 *** Const ( Nat.op ^, ['a, nat] => 'a)
1112 *** Const ( uminus, 'a => 'a)
1115 > val (SOME ct) = parse thy "R=R";
1116 > atomty (term_of ct);
1118 *** Const ( op =, [real, real] => bool)
1122 THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!!
1124 *** Const ( op =, [RealDef.real, RealDef.real] => bool)
1125 *** Free ( R, RealDef.real)
1126 *** Free ( R, RealDef.real) *)
1128 fun parse_patt thy str =
1129 ProofContext.read_term_pattern (thy2ctxt thy) str;
1131 (*version for testing local to theories*)
1132 fun str2term_ thy str = (term_of o the o (parse thy)) str;
1133 fun str2term str = (term_of o the o (parse (theory "Isac"))) str;
1134 fun strs2terms ss = map str2term ss;
1135 fun str2termN str = (term_of o the o (parseN (theory "Isac"))) str;
1137 (*+ makes a substitution from the output of Pattern.match +*)
1138 (*fun mk_subs ((id, _):indexname, t:term) = (Free (id,type_of t), t);*)
1139 fun mk_subs (subs: ((string * int) * (Term.typ * Term.term)) list) =
1140 let fun mk_sub ((id, _), (ty, tm)) = (Free (id, ty), tm) in
1141 map mk_sub subs end;
1143 val atomthm = atomt o #prop o rep_thm;
1145 (*.instantiate #prop thm with bound variables (as Free).*)
1146 fun inst_bdv [] t = t : term
1147 | inst_bdv (instl: (term*term) list) t =
1148 let fun subst (v as Var((s,_),T)) =
1151 if_none (assoc(instl,Free(s,T))) (Free(s,T))
1153 | subst (Abs(a,T,body)) = Abs(a, T, subst body)
1154 | subst (f$t') = subst f $ subst t'
1155 | subst t = if_none (assoc(instl,t)) t
1159 (*WN050829 caution: is_atom (str2term"q_0/2 * L * x") = true !!!
1160 use length (vars term) = 1 instead*)
1161 fun is_atom (Const ("Float.Float",_) $ _) = true
1162 | is_atom (Const ("ComplexI.I'_'_",_)) = true
1163 | is_atom (Const ("op *",_) $ t $ Const ("ComplexI.I'_'_",_)) = is_atom t
1164 | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ Const ("ComplexI.I'_'_",_)) = is_atom t1
1165 | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $
1166 (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_))) =
1167 is_atom t1 andalso is_atom t2
1168 | is_atom (Const _) = true
1169 | is_atom (Free _) = true
1170 | is_atom (Var _) = true
1171 | is_atom _ = false;
1172 (* val t = str2term "q_0/2 * L * x";
1176 (*val t = str2term "Float ((1,2),(0,0))";
1178 val it = true : bool
1179 > val t = str2term "Float ((1,2),(0,0)) * I__";
1181 val it = true : bool
1182 > val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * I__";
1184 val it = true : bool
1185 > val t = str2term "1 + 2*I__";
1186 > val Const ("Groups.plus_class.plus",_) $ t1 $ (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_)) = t;
1189 (*.adaption from Isabelle/src/Pure/term.ML; reports if ALL Free's
1190 have found a substitution (required for evaluating the preconditions
1191 of _incomplete_ models).*)
1192 fun subst_atomic_all [] t = (false, (*TODO may be 'true' for some terms ?*)
1194 | subst_atomic_all (instl: (term*term) list) t =
1195 let fun subst (Abs(a,T,body)) =
1196 let val (all, body') = subst body
1197 in (all, Abs(a, T, body')) end
1199 let val (all1, f') = subst f
1200 val (all2, tt') = subst tt
1201 in (all1 andalso all2, f' $ tt') end
1202 | subst (t as Free _) =
1203 if is_num t then (true, t) (*numerals cannot be subst*)
1204 else (case assoc(instl,t) of
1205 SOME t' => (true, t')
1206 | NONE => (false, t))
1207 | subst t = (true, if_none (assoc(instl,t)) t)
1210 (*.add two terms with a type given.*)
1212 let val T1 = type_of t1
1214 in if T1 <> T2 then raise TYPE ("mk_add gets ",[T1, T2],[t1,t2])
1215 else (Const ("Groups.plus_class.plus", [T1, T2] ---> T1) $ t1 $ t2)