# HG changeset patch # User Walther Neuper # Date 1285651690 -7200 # Node ID 67a110289e4e7829b9e19a2236625d5be3bfb093 # Parent 20231cdf39e77aeea4906f5ae8a01b8ae925adb3 repaired fun uminus_to_string, fun rewrite_terms_ rewrite now adjusts to 2 changes from 2002 to 2009-2 (1) Pattern.match requires _Trueprop $_ pat (2) rewrite returns assumptions without _Trueprop $_ asm diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/Build_Isac.thy --- a/src/Tools/isac/Build_Isac.thy Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/Build_Isac.thy Tue Sep 28 07:28:10 2010 +0200 @@ -24,7 +24,7 @@ use "calcelems.sml" ML {* check_guhs_unique := true *} -use "ProgLang/term.sml" +use "ProgLang/termC.sml" use "ProgLang/calculate.sml" use "ProgLang/rewrite.sml" use_thy"ProgLang/Script" (*ListC, Tools, Script*) diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/Build_Test_Isac.thy --- a/src/Tools/isac/Build_Test_Isac.thy Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/Build_Test_Isac.thy Tue Sep 28 07:28:10 2010 +0200 @@ -24,7 +24,7 @@ use "calcelems.sml" ML {* check_guhs_unique := true *} -use "ProgLang/term.sml" +use "ProgLang/termC.sml" use "ProgLang/calculate.sml" use "ProgLang/rewrite.sml" use_thy"ProgLang/Script" (*ListC, Tools, Script*) diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/Knowledge/Rational-WN.sml --- a/src/Tools/isac/Knowledge/Rational-WN.sml Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/Knowledge/Rational-WN.sml Tue Sep 28 07:28:10 2010 +0200 @@ -20,7 +20,7 @@ ---------------------------------------------------------------------*) -(*diese vvv funktionen kommen nach src/Isa99/term.sml -------------*) +(*diese vvv funktionen kommen nach src/Isa99/termC.sml -------------*) fun term2str t = let fun ato (Const(a,T)) n = "\n"^indent n^"Const ( "^a^")" @@ -37,7 +37,7 @@ fun free2int (t as Free (s, _)) = (((the o int_of_str) s) handle _ => raise error ("free2int: "^term2str t)) | free2int t = raise error ("free2int: "^term2str t); -(*diese ^^^ funktionen kommen nach src/Isa99/term.sml -------------*) +(*diese ^^^ funktionen kommen nach src/Isa99/termC.sml -------------*) (* remark on exceptions: 'error' is implemented by Isabelle diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/ProgLang/ListC.thy --- a/src/Tools/isac/ProgLang/ListC.thy Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/ProgLang/ListC.thy Tue Sep 28 07:28:10 2010 +0200 @@ -5,12 +5,12 @@ theory ListC imports Complex_Main uses ("library.sml")("calcelems.sml") -("ProgLang/term.sml")("ProgLang/calculate.sml") +("ProgLang/termC.sml")("ProgLang/calculate.sml") ("ProgLang/rewrite.sml") begin use "library.sml" (*indent,...*) use "calcelems.sml" (*str_of_type, Thm,...*) -use "ProgLang/term.sml" (*num_str,...*) +use "ProgLang/termC.sml" (*num_str,...*) use "ProgLang/calculate.sml" (*???*) use "ProgLang/rewrite.sml" (*?*** At command "end" (line 205../ListC.thy*) diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/ProgLang/rewrite.sml --- a/src/Tools/isac/ProgLang/rewrite.sml Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/ProgLang/rewrite.sml Tue Sep 28 07:28:10 2010 +0200 @@ -272,30 +272,30 @@ in*) rewrite__set_ thy 1 put_asm subst (*sub*)rls ct (*end*); -(* val (thy, ord, erls, subte, t) = (thy, dummy_ord, Erls, subte, t); - *) -(*.rewrite using a list of terms.*) -fun rewrite_terms_ thy ord erls subte t = - let (*val _=tracing("### rewrite_terms_ subte= '"^terms2str subte^"' ..."^ - term_detail2str (hd subte)^ +(* given a list of equalities (lhs = rhs) and a term, + replace all occurrences of lhs in the term with rhs; + thus the order or equalities matters: put variables in lhs first. *) +fun rewrite_terms_ thy ord erls equs t = + let (*val _=tracing("### rewrite_terms_ equs= '"^terms2str equs^"' ..."^ + term_detail2str (hd equs)^ "### rewrite_terms_ t= '"^term2str t^"' ..."^ term_detail2str t);*) fun rew_ (t', asm') [] _ = (t', asm') - (* 1st val (t', asm', rules as r::rs, t) = (e_term, [], subte, t); + (* 1st val (t', asm', rules as r::rs, t) = (e_term, [], equs, t); 2nd val (t', asm', rules as r::rs, t) = (t'', [], rules, t''); rew_ (t', asm') (r::rs) t; *) | rew_ (t', asm') (rules as r::rs) t = let val _ = tracing("rew_ "^term2str t); val (t'', asm'', lrd, rew) = - rew_sub thy 1 [] ord erls false [] r t + rew_sub thy 1 [] ord erls false [] (Trueprop $ r) t in if rew - then (tracing("true rew_ "^term2str t''); + then (tracing ("true rew_ " ^ term2str t''); rew_ (t'', asm' @ asm'') rules t'') - else (tracing("false rew_ "^term2str t''); + else (tracing ("false rew_ " ^ term2str t''); rew_ (t', asm') rs t') end - val (t'', asm'') = rew_ (e_term, []) subte t + val (t'', asm'') = rew_ (e_term, []) equs t in if t'' = e_term then NONE else SOME (t'', asm'') end; diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/ProgLang/scrtools.sml --- a/src/Tools/isac/ProgLang/scrtools.sml Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/ProgLang/scrtools.sml Tue Sep 28 07:28:10 2010 +0200 @@ -1,4 +1,4 @@ -(* tools which depend on Script.thy and thus are not in term.sml +(* tools which depend on Script.thy and thus are not in termC.sml (c) Walther Neuper 2000 use"ProgLang/scrtools.sml"; diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/ProgLang/term.sml --- a/src/Tools/isac/ProgLang/term.sml Mon Sep 27 13:35:06 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1219 +0,0 @@ -(* extends Isabelle/src/Pure/term.ML - (c) Walther Neuper 1999 - -use"ProgLang/term.sml"; -use"term.sml"; -*) - -(* -> (cterm_of thy) a_term; -val it = "empty" : cterm *) - -(*2003 fun match thy t pat = - (snd (Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t))) - handle _ => []; -fn : theory -> - Term.term -> Term.term -> (Term.indexname * Term.term) list*) -(*see src/Tools/eqsubst.ML fun clean_match*) -(*2003 fun matches thy tm pa = if match thy tm pa = [] then false else true;*) -fun matches thy tm pa = - (Pattern.match thy (pa, tm) (Vartab.empty, Vartab.empty); true) - handle _ => false - -fun atomtyp t = (*WN10 see raw_pp_typ*) - let - fun ato n (Type (s,[])) = - ("\n*** "^indent n^"Type ("^s^",[])") - | ato n (Type (s,Ts)) = - ("\n*** "^indent n^"Type ("^s^",["^ atol (n+1) Ts) - - | ato n (TFree (s,sort)) = - ("\n*** "^indent n^"TFree ("^s^",["^ strs2str' sort) - - | ato n (TVar ((s,i),sort)) = - ("\n*** "^indent n^"TVar (("^s^","^ - string_of_int i ^ strs2str' sort) - and atol n [] = - ("\n*** "^indent n^"]") - | atol n (T::Ts) = (ato n T ^ atol n Ts) -(*in print (ato 0 t ^ "\n") end; TODO TUM10*) -in tracing (ato 0 t) end; -(* -> val T = (type_of o term_of o the o (parse thy)) "a::[real,int] => nat"; -> atomtyp T; -*** Type (fun,[ -*** Type (RealDef.real,[]) -*** Type (fun,[ -*** Type (IntDef.int,[]) -*** Type (nat,[]) -*** ] -*** ] -*) - -(*Prog.Tutorial.p.34, Makarius 1005 does the above like this..*) -local - fun pp_pair (x, y) = Pretty.list "(" ")" [x, y] - fun pp_list xs = Pretty.list "[" "]" xs - fun pp_str s = Pretty.str s - fun pp_qstr s = Pretty.quote (pp_str s) - fun pp_int i = pp_str (string_of_int i) - fun pp_sort S = pp_list (map pp_qstr S) - fun pp_constr a args = Pretty.block [pp_str a, Pretty.brk 1, args] -in -fun raw_pp_typ (TVar ((a, i), S)) = - pp_constr "TVar" (pp_pair (pp_pair (pp_qstr a, pp_int i), pp_sort S)) - | raw_pp_typ (TFree (a, S)) = - pp_constr "TFree" (pp_pair (pp_qstr a, pp_sort S)) - | raw_pp_typ (Type (a, tys)) = - pp_constr "Type" (pp_pair (pp_qstr a, pp_list (map raw_pp_typ tys))) -end -(* install -PolyML.addPrettyPrinter - (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ); -de-install -PolyML.addPrettyPrinter - (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy); -*) - -fun atomt t = - let fun ato (Const (a, _)) n = - "\n*** " ^ indent n ^ "Const (" ^ a ^ ", _)" - | ato (Free (a, _)) n = - "\n*** " ^ indent n ^ "Free (" ^ a ^ ", _)" - | ato (Var ((a, i), _)) n = - "\n*** " ^ indent n ^ "Var (" ^ a ^ ", " ^ - string_of_int i ^ "), _)" - | ato (Bound i) n = - "\n*** " ^ indent n ^ "Bound " ^ string_of_int i - | ato (Abs (a, _, body)) n = - "\n*** " ^ indent n ^ "Abs(" ^ a ^ ", _" ^ ato body (n+1) - | ato (f $ t) n = (ato f n ^ ato t (n + 1)) - in tracing ("\n*** -------------" ^ ato t 0 ^ "\n***") end; - -fun term_detail2str t = - let fun ato (Const (a, T)) n = - "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ T ^ ")" - | ato (Free (a, T)) n = - "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ T ^ ")" - | ato (Var ((a, i), T)) n = - "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^ - string_of_typ T ^ ")" - | ato (Bound i) n = - "\n*** " ^ indent n ^ "Bound " ^ string_of_int i - | ato (Abs(a, T, body)) n = - "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ T ^ ",.." - ^ ato body (n + 1) - | ato (f $ t) n = ato f n ^ ato t (n + 1) - in "\n*** " ^ ato t 0 ^ "\n***" end; -fun atomty t = (tracing o term_detail2str) t; (*WN100907 broken*) - -fun term_str thy (Const(s,_)) = s - | term_str thy (Free(s,_)) = s - | term_str thy (Var((s,i),_)) = s^(string_of_int i) - | term_str thy (Bound i) = "B."^(string_of_int i) - | term_str thy (Abs(s,_,_)) = s - | term_str thy t = raise error("term_str not for "^term2str t); - -(*.contains the fst argument the second argument (a leave! of term).*) -fun contains_term (Abs(_,_,body)) t = contains_term body t - | contains_term (f $ f') t = - contains_term f t orelse contains_term f' t - | contains_term s t = t = s; -(*.contains the term a VAR(("*",_),_) ?.*) -fun contains_Var (Abs(_,_,body)) = contains_Var body - | contains_Var (f $ f') = contains_Var f orelse contains_Var f' - | contains_Var (Var _) = true - | contains_Var _ = false; -(* contains_Var (str2term "?z = 3") (*true*); - contains_Var (str2term "z = 3") (*false*); - *) - -(*fun int_of_str str = - let val ss = explode str - val str' = case ss of - "("::s => drop_last s | _ => ss - in case BasisLibrary.Int.fromString (implode str') of - SOME i => SOME i - | NONE => NONE end;*) -fun int_of_str str = - let val ss = explode str - val str' = case ss of - "("::s => drop_last s | _ => ss - in (SOME (Thy_Output.integer (implode str'))) handle _ => NONE end; -(* -> int_of_str "123"; -val it = SOME 123 : int option -> int_of_str "(-123)"; -val it = SOME 123 : int option -> int_of_str "#123"; -val it = NONE : int option -> int_of_str "-123"; -val it = SOME ~123 : int option -*) -fun int_of_str' str = - case int_of_str str of - SOME i => i - | NONE => raise TERM ("int_of_string: no int-string",[]); -val str2int = int_of_str'; - -fun is_numeral str = case int_of_str str of - SOME _ => true - | NONE => false; -val is_no = is_numeral; -fun is_num (Free (s,_)) = if is_numeral s then true else false - | is_num _ = false; -(*> -> is_num ((term_of o the o (parse thy)) "#1"); -val it = true : bool -> is_num ((term_of o the o (parse thy)) "#-1"); -val it = true : bool -> is_num ((term_of o the o (parse thy)) "a123"); -val it = false : bool -*) - -(*fun int_of_Free (Free (intstr, _)) = - (case BasisLibrary.Int.fromString intstr of - SOME i => i - | NONE => raise error ("int_of_Free ( "^ intstr ^", _)")) - | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");*) -fun int_of_Free (Free (intstr, _)) = (Thy_Output.integer intstr - handle _ => raise error ("int_of_Free ( "^ intstr ^", _)")) - | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )"); - -fun vars t = - let - fun scan vs (Const(s,T)) = vs - | scan vs (t as Free(s,T)) = if is_no s then vs else t::vs - | scan vs (t as Var((s,i),T)) = t::vs - | scan vs (Bound i) = vs - | scan vs (Abs(s,T,t)) = scan vs t - | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) - in (distinct o (scan [])) t end; - -fun is_Free (Free _) = true - | is_Free _ = false; -fun is_fun_id (Const _) = true - | is_fun_id (Free _) = true - | is_fun_id _ = false; -fun is_f_x (f $ x) = is_fun_id f andalso is_Free x - | is_f_x _ = false; -(* is_f_x (str2term "q_0/2 * L * x") (*false*); - is_f_x (str2term "M_b x") (*true*); - *) -fun vars_str t = - let - fun scan vs (Const(s,T)) = vs - | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs - | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs - | scan vs (Bound i) = vs - | scan vs (Abs(s,T,t)) = scan vs t - | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) - in (distinct o (scan [])) t end; - -fun ids2str t = - let - fun scan vs (Const(s,T)) = if is_no s then vs else s::vs - | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs - | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs - | scan vs (Bound i) = vs - | scan vs (Abs(s,T,t)) = scan (s::vs) t - | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) - in (distinct o (scan [])) t end; -fun is_bdv str = - case explode str of - "b"::"d"::"v"::_ => true - | _ => false; -fun is_bdv_ (Free (s,_)) = is_bdv s - | is_bdv_ _ = false; - -fun free2str (Free (s,_)) = s - | free2str t = raise error ("free2str not for "^ term2str t); -fun free2int (t as Free (s, _)) = ((str2int s) - handle _ => raise error ("free2int: "^term_detail2str t)) - | free2int t = raise error ("free2int: "^term_detail2str t); - -(*27.8.01: unused*) -fun var2free (t as Const(s,T)) = t - | var2free (t as Free(s,T)) = t - | var2free (Var((s,i),T)) = Free(s,T) - | var2free (t as Bound i) = t - | var2free (Abs(s,T,t)) = Abs(s,T,var2free t) - | var2free (t1 $ t2) = (var2free t1) $ (var2free t2); - -(*27.8.01: doesn't find some subterm ???!???*) -(*2010 Logic.varify !!!*) -fun free2var (t as Const(s,T)) = t - | free2var (t as Free(s,T)) = if is_no s then t else Var((s,0),T) - | free2var (t as Var((s,i),T)) = t - | free2var (t as Bound i) = t - | free2var (Abs(s,T,t)) = Abs(s,T,free2var t) - | free2var (t1 $ t2) = (free2var t1) $ (free2var t2); - - -fun mk_listT T = Type ("List.list", [T]); -fun list_const T = - Const("List.list.Cons", [T, mk_listT T] ---> mk_listT T); -(*28.8.01: TODO: get type from head of list: 1 arg less!!!*) -fun list2isalist T [] = Const("List.list.Nil",mk_listT T) - | list2isalist T (t::ts) = (list_const T) $ t $ (list2isalist T ts); -(* -> val tt = (term_of o the o (parse thy)) "R=(R::real)"; -> val TT = type_of tt; -> val ss = list2isalist TT [tt,tt,tt]; -> (cterm_of thy) ss; -val it = "[R = R, R = R, R = R]" : cterm *) - -fun isapair2pair (Const ("Pair",_) $ a $ b) = (a,b) - | isapair2pair t = - raise error ("isapair2pair called with "^term2str t); - -val listType = Type ("List.list",[Type ("bool",[])]); -fun isalist2list ls = - let - fun get es (Const("List.list.Cons",_) $ t $ ls) = get (t::es) ls - | get es (Const("List.list.Nil",_)) = es - | get _ t = - raise error ("isalist2list applied to NON-list '"^term2str t^"'") - in (rev o (get [])) ls end; -(* -> val il = str2term "[a=b,c=d,e=f]"; -> val l = isalist2list il; -> (tracing o terms2str) l; -["a = b","c = d","e = f"] - -> val il = str2term "ss___::bool list"; -> val l = isalist2list il; -[Free ("ss___", "bool List.list")] -*) - - -(*review Isabelle2009/src/HOL/Tools/hologic.ML*) -val prop = Type ("prop",[]); (* ~/Diss.99/Integers-Isa/tools.sml*) -val bool = Type ("bool",[]); (* 2002 Integ.int *) -val Trueprop = Const("Trueprop",bool-->prop); -fun mk_prop t = Trueprop $ t; -val true_as_term = Const("True",bool); -val false_as_term = Const("False",bool); -val true_as_cterm = cterm_of (theory "HOL") true_as_term; -val false_as_cterm = cterm_of (theory "HOL") false_as_term; - -infixr 5 -->; (*2002 /Pure/term.ML *) -infixr --->; (*2002 /Pure/term.ML *) -fun S --> T = Type("fun",[S,T]); (*2002 /Pure/term.ML *) -val op ---> = foldr (op -->); (*2002 /Pure/term.ML *) -fun list_implies ([], B) = B : term (*2002 /term.ML *) - | list_implies (A::AS, B) = Logic.implies $ A $ list_implies(AS,B); - - - -(** substitution **) - -fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) = (* = thm.ML *) - match_bvs(s, t, if x="" orelse y="" then al - else (x,y)::al) - | match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al)) - | match_bvs(_,_,al) = al; -fun ren_inst(insts,prop,pat,obj) = (* = thm.ML *) - let val ren = match_bvs(pat,obj,[]) - fun renAbs(Abs(x,T,b)) = - Abs(case assoc_string(ren,x) of NONE => x - | SOME(y) => y, T, renAbs(b)) - | renAbs(f$t) = renAbs(f) $ renAbs(t) - | renAbs(t) = t - in subst_vars insts (if null(ren) then prop else renAbs(prop)) end; - - - - - - -fun dest_equals' (Const("op =",_) $ t $ u) = (t,u)(* logic.ML: Const("=="*) - | dest_equals' t = raise TERM("dest_equals'", [t]); -val lhs_ = (fst o dest_equals'); -val rhs_ = (snd o dest_equals'); - -fun is_equality (Const("op =",_) $ t $ u) = true (* logic.ML: Const("=="*) - | is_equality _ = false; -fun mk_equality (t,u) = (Const("op =",[type_of t,type_of u]--->bool) $ t $ u); -fun is_expliceq (Const("op =",_) $ (Free _) $ u) = true - | is_expliceq _ = false; -fun strip_trueprop (Const("Trueprop",_) $ t) = t - | strip_trueprop t = t; -(* | strip_trueprop t = raise TERM("strip_trueprop", [t]); -*) - -(*.(A1==>...An==>B) goes to (A1==>...An==>).*) -fun strip_imp_prems' (Const("==>", T) $ A $ t) = - let fun coll_prems As (Const("==>", _) $ A $ t) = - coll_prems (As $ (Logic.implies $ A)) t - | coll_prems As _ = SOME As - in coll_prems (Logic.implies $ A) t end - | strip_imp_prems' _ = NONE; (* logic.ML: term -> term list*) -(* - val thm = real_mult_div_cancel1; - val prop = (#prop o rep_thm) thm; - atomt prop; -*** ------------- -*** Const ( ==>) -*** . Const ( Trueprop) -*** . . Const ( Not) -*** . . . Const ( op =) -*** . . . . Var ((k, 0), ) -*** . . . . Const ( 0) -*** . Const ( Trueprop) -*** . . Const ( op =) *** ............. - val SOME t = strip_imp_prems' ((#prop o rep_thm) thm); - atomt t; -*** ------------- -*** Const ( ==>) -*** . Const ( Trueprop) -*** . . Const ( Not) -*** . . . Const ( op =) -*** . . . . Var ((k, 0), ) -*** . . . . Const ( 0) - - val thm = real_le_anti_sym; - val prop = (#prop o rep_thm) thm; - atomt prop; -*** ------------- -*** Const ( ==>) -*** . Const ( Trueprop) -*** . . Const ( op <=) -*** . . . Var ((z, 0), ) -*** . . . Var ((w, 0), ) -*** . Const ( ==>) -*** . . Const ( Trueprop) -*** . . . Const ( op <=) -*** . . . . Var ((w, 0), ) -*** . . . . Var ((z, 0), ) -*** . . Const ( Trueprop) -*** . . . Const ( op =) -*** ............. - val SOME t = strip_imp_prems' ((#prop o rep_thm) thm); - atomt t; -*** ------------- -*** Const ( ==>) -*** . Const ( Trueprop) -*** . . Const ( op <=) -*** . . . Var ((z, 0), ) -*** . . . Var ((w, 0), ) -*** . Const ( ==>) -*** . . Const ( Trueprop) -*** . . . Const ( op <=) -*** . . . . Var ((w, 0), ) -*** . . . . Var ((z, 0), ) -*) - -(*. (A1==>...An==>) (B) goes to (A1==>...An==>B), where B is lowest branch.*) -fun ins_concl (Const("==>", T) $ A $ t) B = Logic.implies $ A $ (ins_concl t B) - | ins_concl (Const("==>", T) $ A ) B = Logic.implies $ A $ B - | ins_concl t B = raise TERM("ins_concl", [t, B]); -(* - val thm = real_le_anti_sym; - val prop = (#prop o rep_thm) thm; - val concl = Logic.strip_imp_concl prop; - val SOME prems = strip_imp_prems' prop; - val prop' = ins_concl prems concl; - prop = prop'; - atomt prop; - atomt prop'; -*) - - -fun vperm (Var _, Var _) = true (*2002 Pure/thm.ML *) - | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t) - | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2) - | vperm (t, u) = (t = u); - -(*2002 cp from Pure/term.ML --- since 2009 in Pure/old_term.ML*) -fun mem_term (_, []) = false - | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts); -fun subset_term ([], ys) = true - | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys); -fun eq_set_term (xs, ys) = - xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs)); -(*a total, irreflexive ordering on index names*) -fun xless ((a,i), (b,j): indexname) = i insert_aterm(t,vars) - | Abs (_,_,body) => add_term_vars(body,vars) - | f$t => add_term_vars (f, add_term_vars(t, vars)) - | _ => vars; -fun term_vars t = add_term_vars(t,[]); - - -fun var_perm (t, u) = (*2002 Pure/thm.ML *) - vperm (t, u) andalso eq_set_term (term_vars t, term_vars u); - -(*2002 fun decomp_simp, Pure/thm.ML *) -fun perm lhs rhs = var_perm (lhs, rhs) andalso not (lhs aconv rhs) - andalso not (is_Var lhs); - - -fun str_of_int n = - if n < 0 then "-"^((string_of_int o abs) n) - else string_of_int n; -(* -> str_of_int 1; -val it = "1" : string > str_of_int ~1; -val it = "-1" : string -*) - - -fun power b 0 = 1 - | power b n = - if n>0 then b*(power b (n-1)) - else raise error ("power "^(str_of_int b)^" "^(str_of_int n)); -(* -> power 2 3; -val it = 8 : int -> power ~2 3; -val it = ~8 : int -> power ~3 2; -val it = 9 : int -> power 3 ~2; -*) -fun gcd 0 b = b - | gcd a b = if a < b then gcd (b mod a) a - else gcd (a mod b) b; -fun sign n = if n < 0 then ~1 - else if n = 0 then 0 else 1; -fun sign2 n1 n2 = (sign n1) * (sign n2); - -infix dvd; -fun d dvd n = n mod d = 0; - -fun divisors n = - let fun pdiv ds d n = - if d=n then d::ds - else if d dvd n then pdiv (d::ds) d (n div d) - else pdiv ds (d+1) n - in pdiv [] 2 n end; - -divisors 30; -divisors 32; -divisors 60; -divisors 11; - -fun doubles ds = (* ds is ordered *) - let fun dbls ds [] = ds - | dbls ds [i] = ds - | dbls ds (i::i'::is) = if i=i' then dbls (i::ds) is - else dbls ds (i'::is) - in dbls [] ds end; -(*> doubles [2,3,4]; -val it = [] : int list -> doubles [2,3,3,5,5,7]; -val it = [5,3] : int list*) - -fun squfact 0 = 0 - | squfact 1 = 1 - | squfact n = foldl op* (1, (doubles o divisors) n); -(*> squfact 30; -val it = 1 : int -> squfact 32; -val it = 4 : int -> squfact 60; -val it = 2 : int -> squfact 11; -val it = 1 : int*) - - -fun dest_type (Type(T,[])) = T - | dest_type T = - (atomtyp T; - raise error ("... dest_type: not impl. for this type")); - -fun term_of_num ntyp n = Free (str_of_int n, ntyp); - -fun pairT T1 T2 = Type ("*", [T1, T2]); -(*> val t = str2term "(1,2)"; -> type_of t = pairT HOLogic.realT HOLogic.realT; -val it = true : bool -*) -fun PairT T1 T2 = ([T1, T2] ---> Type ("*", [T1, T2])); -(*> val t = str2term "(1,2)"; -> val Const ("Pair",pT) $ _ $ _ = t; -> pT = PairT HOLogic.realT HOLogic.realT; -val it = true : bool -*) -fun pairt t1 t2 = - Const ("Pair", PairT (type_of t1) (type_of t2)) $ t1 $ t2; -(*> val t = str2term "(1,2)"; -> val (t1, t2) = (str2term "1", str2term "2"); -> t = pairt t1 t2; -val it = true : bool*) - - -fun num_of_term (t as Free (s,_)) = - (case int_of_str s of - SOME s' => s' - | NONE => raise error ("num_of_term not for "^ term2str t)) - | num_of_term t = raise error ("num_of_term not for "^term2str t); - -fun mk_factroot op_(*=thy.sqrt*) T fact root = - Const ("op *", [T, T] ---> T) $ (term_of_num T fact) $ - (Const (op_, T --> T) $ term_of_num T root); -(* -val T = (type_of o term_of o the) (parse thy "#12::real"); -val t = mk_factroot "SqRoot.sqrt" T 2 3; -(cterm_of thy) t; -val it = "#2 * sqrt #3 " : cterm -*) -fun var_op_num v op_ optype ntyp n = - Const (op_, optype) $ v $ - Free (str_of_int n, ntyp); - -fun num_op_var v op_ optype ntyp n = - Const (op_,optype) $ - Free (str_of_int n, ntyp) $ v; - -fun num_op_num T1 T2 (op_,Top) n1 n2 = - Const (op_,Top) $ - Free (str_of_int n1, T1) $ Free (str_of_int n2, T2); -(* -> val t = num_op_num "Int" 3 4; -> atomty t; -> string_of_cterm ((cterm_of thy) t); -*) - -fun const_in str (Const _) = false - | const_in str (Free (s,_)) = if strip_thy s = str then true else false - | const_in str (Bound _) = false - | const_in str (Var _) = false - | const_in str (Abs (_,_,body)) = const_in str body - | const_in str (f$u) = const_in str f orelse const_in str u; -(* -> val t = (term_of o the o (parse thy)) "6 + 5 * sqrt 4 + 3"; -> const_in "sqrt" t; -val it = true : bool -> val t = (term_of o the o (parse thy)) "6 + 5 * 4 + 3"; -> const_in "sqrt" t; -val it = false : bool -*) - -(*used for calculating built in binary operations in Isabelle2002->Float.ML*) -(*fun calc "Groups.plus_class.plus" (n1, n2) = n1+n2 - | calc "Groups.minus_class.minus" (n1, n2) = n1-n2 - | calc "op *" (n1, n2) = n1*n2 - | calc "Rings.inverse_class.divide"(n1, n2) = n1 div n2 - | calc "Atools.pow"(n1, n2) = power n1 n2 - | calc op_ _ = raise error ("calc: operator = "^op_^" not defined");-----*) -fun calc_equ "op <" (n1, n2) = n1 < n2 - | calc_equ "op <=" (n1, n2) = n1 <= n2 - | calc_equ op_ _ = - raise error ("calc_equ: operator = "^op_^" not defined"); -fun sqrt (n:int) = if n < 0 then 0 - (*FIXME ~~~*) else (trunc o Math.sqrt o Real.fromInt) n; - -fun mk_thmid thmid op_ n1 n2 = - thmid ^ (strip_thy n1) ^ "_" ^ (strip_thy n2); - -fun dest_binop_typ (Type("fun",[range,Type("fun",[arg2,arg1])])) = - (arg1,arg2,range) - | dest_binop_typ _ = raise error "dest_binop_typ: not binary"; -(* ----- -> val t = (term_of o the o (parse thy)) "#3^#4"; -> val hT = type_of (head_of t); -> dest_binop_typ hT; -val it = ("'a","nat","'a") : typ * typ * typ - ----- *) - - -(** transform binary numeralsstrings **) -(*Makarius 100308, hacked by WN*) -val numbers_to_string = - let - fun dest_num t = - (case try HOLogic.dest_number t of - SOME (T, i) => - (*if T = @{typ int} orelse T = @{typ real} then WN*) - SOME (Free (signed_string_of_int i, T)) - (*else NONE WN*) - | NONE => NONE); - - fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b) - | to_str (t as (u1 $ u2)) = - (case dest_num t of - SOME t' => t' - | NONE => to_str u1 $ to_str u2) - | to_str t = perhaps dest_num t; - in to_str end - -(*.make uminus uniform: - Const ("uminus", _) $ Free ("2", "RealDef.real") --> Free ("-2", _) -to be used immediately before evaluation of numerals; -see Scripts/calculate.sml .*) -(*2002 fun(*app_num_tr'2 (Const("0",T)) = Free("0",T) - | app_num_tr'2 (Const("1",T)) = Free("1",T) - |*)app_num_tr'2 (t as Const("uminus",_) $ Free(s,T)) = - (case int_of_str s of SOME i => - if i > 0 then Free("-"^s,T) else Free(s,T) - | NONE => t) -(*| app_num_tr'2 (t as Const(s,T)) = t - | app_num_tr'2 (Const("Numeral.number_of",Type ("fun", [_, T])) $ t) = - Free(NumeralSyntax.dest_bin_str t, T) - | app_num_tr'2 (t as Free(s,T)) = t - | app_num_tr'2 (t as Var(n,T)) = t - | app_num_tr'2 (t as Bound i) = t -*)| app_num_tr'2 (Abs(s,T,body)) = Abs(s,T, app_num_tr'2 body) - | app_num_tr'2 (t1 $ t2) = (app_num_tr'2 t1) $ (app_num_tr'2 t2) - | app_num_tr'2 t = t; -*) -val uminus_to_string = - let - fun dest_num t = - (case t of - (Const ("HOL.uminus_class.uminus", _) $ Free (s, T)) => - (case int_of_str s of - SOME i => - SOME (Free (signed_string_of_int (~1 * i), T)) - | NONE => NONE) - | _ => NONE); - - fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b) - | to_str (t as (u1 $ u2)) = - (case dest_num t of - SOME t' => t' - | NONE => to_str u1 $ to_str u2) - | to_str t = perhaps dest_num t; - in to_str end; - - -(*2002 fun num_str thm = - let - val {sign_ref = sign_ref, der = der, maxidx = maxidx, - shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} = - rep_thm_G thm; - val prop' = app_num_tr'1 prop; - in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end;*) -fun num_str thm = - let val (deriv, - {thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps, - hyps = hyps, tpairs = tpairs, prop = prop}) = rep_thm_G thm - val prop' = numbers_to_string prop; - in assbl_thm deriv thy_ref tags maxidx shyps hyps tpairs prop' end; - -fun get_thm' xstring = (*?covers 2009 Thm?!, replaces 2002 fun get_thm : -val it = fn : theory -> xstring -> Thm.thm*) - Thm (xstring, - num_str (ProofContext.get_thm (thy2ctxt' "Isac") xstring)); - -(** get types of Free and Abs for parse' **) -(*11.1.00: not used, fix-typed +,*,-,^ instead *) - -val dummyT = Type ("dummy",[]); -val dummyT = TVar (("DUMMY",0),[]); - -(* assumes only 1 type for numerals - and different identifiers for Const, Free and Abs *) -fun get_types t = - let - fun get ts (Const(s,T)) = (s,T)::ts - | get ts (Free(s,T)) = if is_no s - then ("#",T)::ts else (s,T)::ts - | get ts (Var(n,T)) = ts - | get ts (Bound i) = ts - | get ts (Abs(s,T,body)) = get ((s,T)::ts) body - | get ts (t1 $ t2) = (get ts t1) @ (get ts t2) - in distinct (get [] t) end; -(* -val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)"; -get_types t; -*) - -(*11.1.00: not used, fix-typed +,*,-,^ instead *) -fun set_types al (Const(s,T)) = - (case assoc (al,s) of - SOME T' => Const(s,T') - | NONE => (warning ("set_types: no type for "^s); Const(s,dummyT))) - | set_types al (Free(s,T)) = - if is_no s then - (case assoc (al,"#") of - SOME T' => Free(s,T') - | NONE => (warning ("set_types: no type for numerals"); Free(s,T))) - else (case assoc (al,s) of - SOME T' => Free(s,T') - | NONE => (warning ("set_types: no type for "^s); Free(s,T))) - | set_types al (Var(n,T)) = Var(n,T) - | set_types al (Bound i) = Bound i - | set_types al (Abs(s,T,body)) = - (case assoc (al,s) of - SOME T' => Abs(s,T', set_types al body) - | NONE => (warning ("set_types: no type for "^s); - Abs(s,T, set_types al body))) - | set_types al (t1 $ t2) = (set_types al t1) $ (set_types al t2); -(* -val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)"; -val al = get_types t; - -val t = (term_of o the o (parse thy)) "x = #0 + #-1 * #-4"; -atomty t; (* 'a *) -val t' = set_types al t; -atomty t'; (*real*) -(cterm_of thy) t'; -val it = "x = #0 + #-1 * #-4" : cterm - -val t = (term_of o the o (parse thy)) - "#5 * x + x ^^^ #2 = (#2 + x) ^^^ #2"; -atomty t; -val t' = set_types al t; -atomty t'; -(cterm_of thy) t'; -uncaught exception TYPE (*^^^ is new, NOT in al*) -*) - - -(** from Descript.ML **) - -(** decompose an isa-list to an ML-list - i.e. [] belong to the meta-language, too **) - -fun is_list ((Const("List.list.Cons",_)) $ _ $ _) = true - | is_list _ = false; -(* val (SOME ct) = parse thy "lll::real list"; -> val ty = (#t o rep_cterm) ct; -> is_list ty; -val it = false : bool -> val (SOME ct) = parse thy "[lll]"; -> val ty = (#t o rep_cterm) ct; -> is_list ty; -val it = true : bool *) - - - -fun mk_Free (s,T) = Free(s,T); -fun mk_free T s = Free(s,T); - -(*Special case: one argument cp from Isabelle2002/src/Pure/term.ML*) -fun subst_bound (arg, t) : term = (*WN100908 neglects 'raise Same.SAME'*) - let fun subst (t as Bound i, lev) = - if i val ttt = (term_of o the o (parse thy)) scr; -> tracing(term2str ttt); -> atomt ttt; -*** ------------- -*** Const ( DiffApp.Make'_fun'_by'_explicit) -*** . Free ( f_, ) -*** . Free ( v_, ) -*** . Free ( eqs_, ) -*** . Const ( Let) -*** . . Const ( Fun.op o) -*** . . . Const ( List.hd) -*** . . . Const ( DiffApp.filterVar) -*** . . . . Free ( f_, ) -*** . . . Free ( eqs_, ) -*** . . Abs( h_,.. -*** . . . Const ( Let) -*** . . . . Const ( List.hd) -*** . . . . . Const ( List.dropWhile) -*** . . . . . . Const ( Atools.ident) -*** . . . . . . . Bound 0 <---- Free ( h_, ) -*** . . . . . . Free ( eqs_, ) -*** . . . . Abs( e_1,.. -*** . . . . . Const ( Let) -*** . . . . . . Const ( List.dropWhile) -*** . . . . . . . Const ( Atools.ident) -*** . . . . . . . . Free ( f_, ) -*** . . . . . . . Const ( Tools.Vars) -*** . . . . . . . . Bound 1 <---- Free ( h_, ) -*** . . . . . . Abs( vs_,.. -*** . . . . . . . Const ( Let) -*** . . . . . . . . Const ( List.hd) -*** . . . . . . . . . Const ( List.dropWhile) -*** . . . . . . . . . . Const ( Atools.ident) -*** . . . . . . . . . . . Free ( v_, ) -*** . . . . . . . . . . Bound 0 <---- Free ( vs_, ) -*** . . . . . . . . Abs( v_1,.. -*** . . . . . . . . . Const ( Let) -*** . . . . . . . . . . Const ( Script.SubProblem) -*** . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . Free ( DiffApp_, ) -*** . . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . Free ( univar, ) -*** . . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . . Free ( equation, ) -*** . . . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . Free ( no_met, ) -*** . . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . Const ( Script.BOOL) -*** . . . . . . . . . . . . . Bound 2 <----- Free ( e_1, ) -*** . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . Const ( Script.real_) -*** . . . . . . . . . . . . . . Bound 0 <----- Free ( v_1, ) -*** . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . Abs( s_1,.. -*** . . . . . . . . . . . Const ( Script.Substitute) -*** . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . . . Bound 1 <----- Free ( v_1, ) -*** . . . . . . . . . . . . . . Const ( Fun.op o) -*** . . . . . . . . . . . . . . . Const ( Tools.rhs) -*** . . . . . . . . . . . . . . . Const ( List.hd) -*** . . . . . . . . . . . . . . . Bound 0 <----- Free ( s_1, ) -*** . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . . Bound 4 <----- Free ( h_, ) - -> val ttt' = inst_abs thy ttt; -> tracing(term2str ttt'); -Script Make_fun_by_explicit f_ v_ eqs_ = - ... as above ... -> atomt ttt'; -*** ------------- -*** Const ( DiffApp.Make'_fun'_by'_explicit) -*** . Free ( f_, ) -*** . Free ( v_, ) -*** . Free ( eqs_, ) -*** . Const ( Let) -*** . . Const ( Fun.op o) -*** . . . Const ( List.hd) -*** . . . Const ( DiffApp.filterVar) -*** . . . . Free ( f_, ) -*** . . . Free ( eqs_, ) -*** . . Abs( h_,.. -*** . . . Const ( Let) -*** . . . . Const ( List.hd) -*** . . . . . Const ( List.dropWhile) -*** . . . . . . Const ( Atools.ident) -*** . . . . . . . Free ( h_, ) <---- Bound 0 -*** . . . . . . Free ( eqs_, ) -*** . . . . Abs( e_1,.. -*** . . . . . Const ( Let) -*** . . . . . . Const ( List.dropWhile) -*** . . . . . . . Const ( Atools.ident) -*** . . . . . . . . Free ( f_, ) -*** . . . . . . . Const ( Tools.Vars) -*** . . . . . . . . Free ( h_, ) <---- Bound 1 -*** . . . . . . Abs( vs_,.. -*** . . . . . . . Const ( Let) -*** . . . . . . . . Const ( List.hd) -*** . . . . . . . . . Const ( List.dropWhile) -*** . . . . . . . . . . Const ( Atools.ident) -*** . . . . . . . . . . . Free ( v_, ) -*** . . . . . . . . . . Free ( vs_, ) <---- Bound 0 -*** . . . . . . . . Abs( v_1,.. -*** . . . . . . . . . Const ( Let) -*** . . . . . . . . . . Const ( Script.SubProblem) -*** . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . Free ( DiffApp_, ) -*** . . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . Free ( univar, ) -*** . . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . . Free ( equation, ) -*** . . . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . . Free ( no_met, ) -*** . . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . Const ( Script.BOOL) -*** . . . . . . . . . . . . . Free ( e_1, ) <----- Bound 2 -*** . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . Const ( Script.real_) -*** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 0 -*** . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . Abs( s_1,.. -*** . . . . . . . . . . . Const ( Script.Substitute) -*** . . . . . . . . . . . . Const ( List.list.Cons) -*** . . . . . . . . . . . . . Const ( Pair) -*** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 1 -*** . . . . . . . . . . . . . . Const ( Fun.op o) -*** . . . . . . . . . . . . . . . Const ( Tools.rhs) -*** . . . . . . . . . . . . . . . Const ( List.hd) -*** . . . . . . . . . . . . . . . Free ( s_1, ) <----- Bound 0 -*** . . . . . . . . . . . . . Const ( List.list.Nil) -*** . . . . . . . . . . . . Free ( h_, ) <----- Bound 4 - -Note numbering of de Bruijn indexes ! - -Script Make_fun_by_explicit f_ v_ eqs_ = - let h_ = (hd o filterVar f_) eqs_; - e_1 = hd (dropWhile (ident h_ BOUND_0) eqs_); - vs_ = dropWhile (ident f_) (Vars h_ BOUND_1); - v_1 = hd (dropWhile (ident v_) vs_ BOUND_0); - s_1 = - SubProblem (DiffApp_, [univar, equation], [no_met]) - [BOOL e_1 BOUND_2, REAL v_1 BOUND_0] - in Substitute [(v_1 BOUND_1 = (rhs o hd) s_1 BOUND_0)] h_ BOUND_4 -*) - - -fun T_a2real (Type (s, [])) = - if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else Type (s, []) - | T_a2real (Type (s, Ts)) = Type (s, map T_a2real Ts) - | T_a2real (TFree (s, srt)) = - if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else TFree (s, srt) - | T_a2real (TVar (("DUMMY",_),srt)) = HOLogic.realT; - -(*FIXME .. fixes the type (+see Typefix.thy*) -fun typ_a2real (Const( s, T)) = (Const( s, T_a2real T)) - | typ_a2real (Free( s, T)) = (Free( s, T_a2real T)) - | typ_a2real (Var( n, T)) = (Var( n, T_a2real T)) - | typ_a2real (Bound i) = (Bound i) - | typ_a2real (Abs(s,T,t)) = Abs(s, T, typ_a2real t) - | typ_a2real (t1 $ t2) = (typ_a2real t1) $ (typ_a2real t2); -(* -----------------6.8.02--------------------------------------------------- - val str = "1"; - val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[]))); - atomty (term_of t); -*** ------------- -*** Const ( 1, 'a) - val t = (app_num_tr' o term_of) t; - atomty t; -*** ------------- -*** Const ( 1, 'a) - val t = typ_a2real t; - atomty t; -*** ------------- -*** Const ( 1, real) - - val str = "2"; - val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[]))); - atomty (term_of t); -*** ------------- -*** Const ( Numeral.number_of, bin => 'a) -*** . Const ( Numeral.bin.Bit, [bin, bool] => bin) -*** . . Const ( Numeral.bin.Bit, [bin, bool] => bin) -*** . . . Const ( Numeral.bin.Pls, bin) -*** . . . Const ( True, bool) -*** . . Const ( False, bool) - val t = (app_num_tr' o term_of) t; - atomty t; -*** ------------- -*** Free ( 2, 'a) - val t = typ_a2real t; - atomty t; -*** ------------- -*** Free ( 2, real) -----------------6.8.02--------------------------------------------------- - - -> val str = "R"; -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); -val t = Free ("R","?DUMMY") : term -> val t' = typ_a2real t; -> (cterm_of thy) t'; -val it = "R::RealDef.real" : cterm - -> val str = "R=R"; -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); -> atomty (typ_a2real t); -*** ------------- -*** Const ( op =, [RealDef.real, RealDef.real] => bool) -*** Free ( R, RealDef.real) -*** Free ( R, RealDef.real) -> val t' = typ_a2real t; -> (cterm_of thy) t'; -val it = "(R::RealDef.real) = R" : cterm - -> val str = "fixed_values [R=R]"; -> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); -> val t' = typ_a2real t; -> (cterm_of thy) t'; -val it = "fixed_values [(R::RealDef.real) = R]" : cterm -*) - -(*TODO.WN0609: parse should return a term or a string - (or even more comprehensive datastructure for error-messages) - i.e. in wrapping with SOME term or NONE the latter is not sufficient*) -(*2002 fun parseold thy str = - (let - val sgn = sign_of thy; - val t = ((*typ_a2real o*) app_num_tr'1 o term_of) - (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); - in SOME (cterm_of sgn t) end) - handle _ => NONE;*) - - - -fun parseold thy str = - (let val t = ((*typ_a2real o*) numbers_to_string) - (Syntax.read_term_global thy str) - in SOME (cterm_of thy t) end) - handle _ => NONE; -(*2002 fun parseN thy str = - (let - val sgn = sign_of thy; - val t = ((*typ_a2real o app_num_tr'1 o*) term_of) - (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); - in SOME (cterm_of sgn t) end) - handle _ => NONE;*) -fun parseN thy str = - (let val t = (*(typ_a2real o numbers_to_string)*) - (Syntax.read_term_global thy str) - in SOME (cterm_of thy t) end) - handle _ => NONE; -(*2002 fun parse thy str = - (let - val sgn = sign_of thy; - val t = (typ_a2real o app_num_tr'1 o term_of) - (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); - in SOME (cterm_of sgn t) end) (*FIXXXXME 10.8.02: return term !!!*) - handle _ => NONE;*) -(*2010 fun parse thy str = - (let val t = (typ_a2real o app_num_tr'1) (Syntax.read_term_global thy str) - in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*) - handle _ => NONE;*) -fun parse thy str = - (let val t = (typ_a2real o numbers_to_string) - (Syntax.read_term_global thy str) - in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*) - handle _ => NONE; -(* -> val (SOME ct) = parse thy "(-#5)^^^#3"; -> atomty (term_of ct); -*** ------------- -*** Const ( Nat.op ^, ['a, nat] => 'a) -*** Const ( uminus, 'a => 'a) -*** Free ( #5, 'a) -*** Free ( #3, nat) -> val (SOME ct) = parse thy "R=R"; -> atomty (term_of ct); -*** ------------- -*** Const ( op =, [real, real] => bool) -*** Free ( R, real) -*** Free ( R, real) - -THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!! -*** ------------- -*** Const ( op =, [RealDef.real, RealDef.real] => bool) -*** Free ( R, RealDef.real) -*** Free ( R, RealDef.real) *) - -fun parse_patt thy str = - ProofContext.read_term_pattern (thy2ctxt thy) str; - -(*version for testing local to theories*) -fun str2term_ thy str = (term_of o the o (parse thy)) str; -fun str2term str = (term_of o the o (parse (theory "Isac"))) str; -fun strs2terms ss = map str2term ss; -fun str2termN str = (term_of o the o (parseN (theory "Isac"))) str; - -(*+ makes a substitution from the output of Pattern.match +*) -(*fun mk_subs ((id, _):indexname, t:term) = (Free (id,type_of t), t);*) -fun mk_subs (subs: ((string * int) * (Term.typ * Term.term)) list) = -let fun mk_sub ((id, _), (ty, tm)) = (Free (id, ty), tm) in -map mk_sub subs end; - -val atomthm = atomt o #prop o rep_thm; - -(*.instantiate #prop thm with bound variables (as Free).*) -fun inst_bdv [] t = t : term - | inst_bdv (instl: (term*term) list) t = - let fun subst (v as Var((s,_),T)) = - (case explode s of - "b"::"d"::"v"::_ => - if_none (assoc(instl,Free(s,T))) (Free(s,T)) - | _ => v) - | subst (Abs(a,T,body)) = Abs(a, T, subst body) - | subst (f$t') = subst f $ subst t' - | subst t = if_none (assoc(instl,t)) t - in subst t end; - - -(*WN050829 caution: is_atom (str2term"q_0/2 * L * x") = true !!! - use length (vars term) = 1 instead*) -fun is_atom (Const ("Float.Float",_) $ _) = true - | is_atom (Const ("ComplexI.I'_'_",_)) = true - | is_atom (Const ("op *",_) $ t $ Const ("ComplexI.I'_'_",_)) = is_atom t - | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ Const ("ComplexI.I'_'_",_)) = is_atom t1 - | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ - (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_))) = - is_atom t1 andalso is_atom t2 - | is_atom (Const _) = true - | is_atom (Free _) = true - | is_atom (Var _) = true - | is_atom _ = false; -(* val t = str2term "q_0/2 * L * x"; - - -*) -(*val t = str2term "Float ((1,2),(0,0))"; -> is_atom t; -val it = true : bool -> val t = str2term "Float ((1,2),(0,0)) * I__"; -> is_atom t; -val it = true : bool -> val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * I__"; -> is_atom t; -val it = true : bool -> val t = str2term "1 + 2*I__"; -> val Const ("Groups.plus_class.plus",_) $ t1 $ (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_)) = t; -*) - -(*.adaption from Isabelle/src/Pure/term.ML; reports if ALL Free's - have found a substitution (required for evaluating the preconditions - of _incomplete_ models).*) -fun subst_atomic_all [] t = (false, (*TODO may be 'true' for some terms ?*) - t : term) - | subst_atomic_all (instl: (term*term) list) t = - let fun subst (Abs(a,T,body)) = - let val (all, body') = subst body - in (all, Abs(a, T, body')) end - | subst (f$tt) = - let val (all1, f') = subst f - val (all2, tt') = subst tt - in (all1 andalso all2, f' $ tt') end - | subst (t as Free _) = - if is_num t then (true, t) (*numerals cannot be subst*) - else (case assoc(instl,t) of - SOME t' => (true, t') - | NONE => (false, t)) - | subst t = (true, if_none (assoc(instl,t)) t) - in subst t end; - -(*.add two terms with a type given.*) -fun mk_add t1 t2 = - let val T1 = type_of t1 - val T2 = type_of t2 - in if T1 <> T2 then raise TYPE ("mk_add gets ",[T1, T2],[t1,t2]) - else (Const ("Groups.plus_class.plus", [T1, T2] ---> T1) $ t1 $ t2) - end; - diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/ProgLang/termC.sml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Tools/isac/ProgLang/termC.sml Tue Sep 28 07:28:10 2010 +0200 @@ -0,0 +1,1217 @@ +(* Title: extends Isabelle/src/Pure/term.ML + Author: Walther Neuper 1999 + (c) due to copyright terms +*) + +(* +> (cterm_of thy) a_term; +val it = "empty" : cterm *) + +(*2003 fun match thy t pat = + (snd (Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t))) + handle _ => []; +fn : theory -> + Term.term -> Term.term -> (Term.indexname * Term.term) list*) +(*see src/Tools/eqsubst.ML fun clean_match*) +(*2003 fun matches thy tm pa = if match thy tm pa = [] then false else true;*) +fun matches thy tm pa = + (Pattern.match thy (pa, tm) (Vartab.empty, Vartab.empty); true) + handle _ => false + +fun atomtyp t = (*WN10 see raw_pp_typ*) + let + fun ato n (Type (s,[])) = + ("\n*** "^indent n^"Type ("^s^",[])") + | ato n (Type (s,Ts)) = + ("\n*** "^indent n^"Type ("^s^",["^ atol (n+1) Ts) + + | ato n (TFree (s,sort)) = + ("\n*** "^indent n^"TFree ("^s^",["^ strs2str' sort) + + | ato n (TVar ((s,i),sort)) = + ("\n*** "^indent n^"TVar (("^s^","^ + string_of_int i ^ strs2str' sort) + and atol n [] = + ("\n*** "^indent n^"]") + | atol n (T::Ts) = (ato n T ^ atol n Ts) +(*in print (ato 0 t ^ "\n") end; TODO TUM10*) +in tracing (ato 0 t) end; +(* +> val T = (type_of o term_of o the o (parse thy)) "a::[real,int] => nat"; +> atomtyp T; +*** Type (fun,[ +*** Type (RealDef.real,[]) +*** Type (fun,[ +*** Type (IntDef.int,[]) +*** Type (nat,[]) +*** ] +*** ] +*) + +(*Prog.Tutorial.p.34, Makarius 1005 does the above like this..*) +local + fun pp_pair (x, y) = Pretty.list "(" ")" [x, y] + fun pp_list xs = Pretty.list "[" "]" xs + fun pp_str s = Pretty.str s + fun pp_qstr s = Pretty.quote (pp_str s) + fun pp_int i = pp_str (string_of_int i) + fun pp_sort S = pp_list (map pp_qstr S) + fun pp_constr a args = Pretty.block [pp_str a, Pretty.brk 1, args] +in +fun raw_pp_typ (TVar ((a, i), S)) = + pp_constr "TVar" (pp_pair (pp_pair (pp_qstr a, pp_int i), pp_sort S)) + | raw_pp_typ (TFree (a, S)) = + pp_constr "TFree" (pp_pair (pp_qstr a, pp_sort S)) + | raw_pp_typ (Type (a, tys)) = + pp_constr "Type" (pp_pair (pp_qstr a, pp_list (map raw_pp_typ tys))) +end +(* install +PolyML.addPrettyPrinter + (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ); +de-install +PolyML.addPrettyPrinter + (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy); +*) + +fun atomt t = + let fun ato (Const (a, _)) n = + "\n*** " ^ indent n ^ "Const (" ^ a ^ ", _)" + | ato (Free (a, _)) n = + "\n*** " ^ indent n ^ "Free (" ^ a ^ ", _)" + | ato (Var ((a, i), _)) n = + "\n*** " ^ indent n ^ "Var (" ^ a ^ ", " ^ + string_of_int i ^ "), _)" + | ato (Bound i) n = + "\n*** " ^ indent n ^ "Bound " ^ string_of_int i + | ato (Abs (a, _, body)) n = + "\n*** " ^ indent n ^ "Abs(" ^ a ^ ", _" ^ ato body (n+1) + | ato (f $ t) n = (ato f n ^ ato t (n + 1)) + in tracing ("\n*** -------------" ^ ato t 0 ^ "\n***") end; + +fun term_detail2str t = + let fun ato (Const (a, T)) n = + "\n*** " ^ indent n ^ "Const (" ^ a ^ ", " ^ string_of_typ T ^ ")" + | ato (Free (a, T)) n = + "\n*** " ^ indent n ^ "Free (" ^ a ^ ", " ^ string_of_typ T ^ ")" + | ato (Var ((a, i), T)) n = + "\n*** " ^ indent n ^ "Var ((" ^ a ^ ", " ^ string_of_int i ^ "), "^ + string_of_typ T ^ ")" + | ato (Bound i) n = + "\n*** " ^ indent n ^ "Bound " ^ string_of_int i + | ato (Abs(a, T, body)) n = + "\n*** " ^ indent n ^ "Abs (" ^ a ^ ", " ^ string_of_typ T ^ ",.." + ^ ato body (n + 1) + | ato (f $ t) n = ato f n ^ ato t (n + 1) + in "\n*** " ^ ato t 0 ^ "\n***" end; +fun atomty t = (tracing o term_detail2str) t; (*WN100907 broken*) + +fun term_str thy (Const(s,_)) = s + | term_str thy (Free(s,_)) = s + | term_str thy (Var((s,i),_)) = s^(string_of_int i) + | term_str thy (Bound i) = "B."^(string_of_int i) + | term_str thy (Abs(s,_,_)) = s + | term_str thy t = raise error("term_str not for "^term2str t); + +(*.contains the fst argument the second argument (a leave! of term).*) +fun contains_term (Abs(_,_,body)) t = contains_term body t + | contains_term (f $ f') t = + contains_term f t orelse contains_term f' t + | contains_term s t = t = s; +(*.contains the term a VAR(("*",_),_) ?.*) +fun contains_Var (Abs(_,_,body)) = contains_Var body + | contains_Var (f $ f') = contains_Var f orelse contains_Var f' + | contains_Var (Var _) = true + | contains_Var _ = false; +(* contains_Var (str2term "?z = 3") (*true*); + contains_Var (str2term "z = 3") (*false*); + *) + +(*fun int_of_str str = + let val ss = explode str + val str' = case ss of + "("::s => drop_last s | _ => ss + in case BasisLibrary.Int.fromString (implode str') of + SOME i => SOME i + | NONE => NONE end;*) +fun int_of_str str = + let val ss = explode str + val str' = case ss of + "("::s => drop_last s | _ => ss + in (SOME (Thy_Output.integer (implode str'))) handle _ => NONE end; +(* +> int_of_str "123"; +val it = SOME 123 : int option +> int_of_str "(-123)"; +val it = SOME 123 : int option +> int_of_str "#123"; +val it = NONE : int option +> int_of_str "-123"; +val it = SOME ~123 : int option +*) +fun int_of_str' str = + case int_of_str str of + SOME i => i + | NONE => raise TERM ("int_of_string: no int-string",[]); +val str2int = int_of_str'; + +fun is_numeral str = case int_of_str str of + SOME _ => true + | NONE => false; +val is_no = is_numeral; +fun is_num (Free (s,_)) = if is_numeral s then true else false + | is_num _ = false; +(*> +> is_num ((term_of o the o (parse thy)) "#1"); +val it = true : bool +> is_num ((term_of o the o (parse thy)) "#-1"); +val it = true : bool +> is_num ((term_of o the o (parse thy)) "a123"); +val it = false : bool +*) + +(*fun int_of_Free (Free (intstr, _)) = + (case BasisLibrary.Int.fromString intstr of + SOME i => i + | NONE => raise error ("int_of_Free ( "^ intstr ^", _)")) + | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )");*) +fun int_of_Free (Free (intstr, _)) = (Thy_Output.integer intstr + handle _ => raise error ("int_of_Free ( "^ intstr ^", _)")) + | int_of_Free t = raise error ("int_of_Free ( "^ term2str t ^" )"); + +fun vars t = + let + fun scan vs (Const(s,T)) = vs + | scan vs (t as Free(s,T)) = if is_no s then vs else t::vs + | scan vs (t as Var((s,i),T)) = t::vs + | scan vs (Bound i) = vs + | scan vs (Abs(s,T,t)) = scan vs t + | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) + in (distinct o (scan [])) t end; + +fun is_Free (Free _) = true + | is_Free _ = false; +fun is_fun_id (Const _) = true + | is_fun_id (Free _) = true + | is_fun_id _ = false; +fun is_f_x (f $ x) = is_fun_id f andalso is_Free x + | is_f_x _ = false; +(* is_f_x (str2term "q_0/2 * L * x") (*false*); + is_f_x (str2term "M_b x") (*true*); + *) +fun vars_str t = + let + fun scan vs (Const(s,T)) = vs + | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs + | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs + | scan vs (Bound i) = vs + | scan vs (Abs(s,T,t)) = scan vs t + | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) + in (distinct o (scan [])) t end; + +fun ids2str t = + let + fun scan vs (Const(s,T)) = if is_no s then vs else s::vs + | scan vs (t as Free(s,T)) = if is_no s then vs else s::vs + | scan vs (t as Var((s,i),T)) = (s^"_"^(string_of_int i))::vs + | scan vs (Bound i) = vs + | scan vs (Abs(s,T,t)) = scan (s::vs) t + | scan vs (t1 $ t2) = (scan vs t1) @ (scan vs t2) + in (distinct o (scan [])) t end; +fun is_bdv str = + case explode str of + "b"::"d"::"v"::_ => true + | _ => false; +fun is_bdv_ (Free (s,_)) = is_bdv s + | is_bdv_ _ = false; + +fun free2str (Free (s,_)) = s + | free2str t = raise error ("free2str not for "^ term2str t); +fun free2int (t as Free (s, _)) = ((str2int s) + handle _ => raise error ("free2int: "^term_detail2str t)) + | free2int t = raise error ("free2int: "^term_detail2str t); + +(*27.8.01: unused*) +fun var2free (t as Const(s,T)) = t + | var2free (t as Free(s,T)) = t + | var2free (Var((s,i),T)) = Free(s,T) + | var2free (t as Bound i) = t + | var2free (Abs(s,T,t)) = Abs(s,T,var2free t) + | var2free (t1 $ t2) = (var2free t1) $ (var2free t2); + +(*27.8.01: doesn't find some subterm ???!???*) +(*2010 free2var -> Logic.varify, but take care of 'Free ("1",_)'*) +fun free2var (t as Const (s, T)) = t + | free2var (t as Free (s, T)) = if is_no s then t else Var ((s, 0), T) + | free2var (t as Var ((s, i), T)) = t + | free2var (t as Bound i) = t + | free2var (Abs (s, T, t)) = Abs (s, T, free2var t) + | free2var (t1 $ t2) = (free2var t1) $ (free2var t2); + + +fun mk_listT T = Type ("List.list", [T]); +fun list_const T = + Const("List.list.Cons", [T, mk_listT T] ---> mk_listT T); +(*28.8.01: TODO: get type from head of list: 1 arg less!!!*) +fun list2isalist T [] = Const("List.list.Nil",mk_listT T) + | list2isalist T (t::ts) = (list_const T) $ t $ (list2isalist T ts); +(* +> val tt = (term_of o the o (parse thy)) "R=(R::real)"; +> val TT = type_of tt; +> val ss = list2isalist TT [tt,tt,tt]; +> (cterm_of thy) ss; +val it = "[R = R, R = R, R = R]" : cterm *) + +fun isapair2pair (Const ("Pair",_) $ a $ b) = (a,b) + | isapair2pair t = + raise error ("isapair2pair called with "^term2str t); + +val listType = Type ("List.list",[Type ("bool",[])]); +fun isalist2list ls = + let + fun get es (Const("List.list.Cons",_) $ t $ ls) = get (t::es) ls + | get es (Const("List.list.Nil",_)) = es + | get _ t = + raise error ("isalist2list applied to NON-list '"^term2str t^"'") + in (rev o (get [])) ls end; +(* +> val il = str2term "[a=b,c=d,e=f]"; +> val l = isalist2list il; +> (tracing o terms2str) l; +["a = b","c = d","e = f"] + +> val il = str2term "ss___::bool list"; +> val l = isalist2list il; +[Free ("ss___", "bool List.list")] +*) + + +(*review Isabelle2009/src/HOL/Tools/hologic.ML*) +val prop = Type ("prop",[]); (* ~/Diss.99/Integers-Isa/tools.sml*) +val bool = Type ("bool",[]); (* 2002 Integ.int *) +val Trueprop = Const("Trueprop",bool-->prop); +fun mk_prop t = Trueprop $ t; +val true_as_term = Const("True",bool); +val false_as_term = Const("False",bool); +val true_as_cterm = cterm_of (theory "HOL") true_as_term; +val false_as_cterm = cterm_of (theory "HOL") false_as_term; + +infixr 5 -->; (*2002 /Pure/term.ML *) +infixr --->; (*2002 /Pure/term.ML *) +fun S --> T = Type("fun",[S,T]); (*2002 /Pure/term.ML *) +val op ---> = foldr (op -->); (*2002 /Pure/term.ML *) +fun list_implies ([], B) = B : term (*2002 /term.ML *) + | list_implies (A::AS, B) = Logic.implies $ A $ list_implies(AS,B); + + + +(** substitution **) + +fun match_bvs(Abs(x,_,s),Abs(y,_,t), al) = (* = thm.ML *) + match_bvs(s, t, if x="" orelse y="" then al + else (x,y)::al) + | match_bvs(f$s, g$t, al) = match_bvs(f,g,match_bvs(s,t,al)) + | match_bvs(_,_,al) = al; +fun ren_inst(insts,prop,pat,obj) = (* = thm.ML *) + let val ren = match_bvs(pat,obj,[]) + fun renAbs(Abs(x,T,b)) = + Abs(case assoc_string(ren,x) of NONE => x + | SOME(y) => y, T, renAbs(b)) + | renAbs(f$t) = renAbs(f) $ renAbs(t) + | renAbs(t) = t + in subst_vars insts (if null(ren) then prop else renAbs(prop)) end; + + + + + + +fun dest_equals' (Const("op =",_) $ t $ u) = (t,u)(* logic.ML: Const("=="*) + | dest_equals' t = raise TERM("dest_equals'", [t]); +val lhs_ = (fst o dest_equals'); +val rhs_ = (snd o dest_equals'); + +fun is_equality (Const("op =",_) $ t $ u) = true (* logic.ML: Const("=="*) + | is_equality _ = false; +fun mk_equality (t,u) = (Const("op =",[type_of t,type_of u]--->bool) $ t $ u); +fun is_expliceq (Const("op =",_) $ (Free _) $ u) = true + | is_expliceq _ = false; +fun strip_trueprop (Const("Trueprop",_) $ t) = t + | strip_trueprop t = t; +(* | strip_trueprop t = raise TERM("strip_trueprop", [t]); +*) + +(*.(A1==>...An==>B) goes to (A1==>...An==>).*) +fun strip_imp_prems' (Const("==>", T) $ A $ t) = + let fun coll_prems As (Const("==>", _) $ A $ t) = + coll_prems (As $ (Logic.implies $ A)) t + | coll_prems As _ = SOME As + in coll_prems (Logic.implies $ A) t end + | strip_imp_prems' _ = NONE; (* logic.ML: term -> term list*) +(* + val thm = real_mult_div_cancel1; + val prop = (#prop o rep_thm) thm; + atomt prop; +*** ------------- +*** Const ( ==>) +*** . Const ( Trueprop) +*** . . Const ( Not) +*** . . . Const ( op =) +*** . . . . Var ((k, 0), ) +*** . . . . Const ( 0) +*** . Const ( Trueprop) +*** . . Const ( op =) *** ............. + val SOME t = strip_imp_prems' ((#prop o rep_thm) thm); + atomt t; +*** ------------- +*** Const ( ==>) +*** . Const ( Trueprop) +*** . . Const ( Not) +*** . . . Const ( op =) +*** . . . . Var ((k, 0), ) +*** . . . . Const ( 0) + + val thm = real_le_anti_sym; + val prop = (#prop o rep_thm) thm; + atomt prop; +*** ------------- +*** Const ( ==>) +*** . Const ( Trueprop) +*** . . Const ( op <=) +*** . . . Var ((z, 0), ) +*** . . . Var ((w, 0), ) +*** . Const ( ==>) +*** . . Const ( Trueprop) +*** . . . Const ( op <=) +*** . . . . Var ((w, 0), ) +*** . . . . Var ((z, 0), ) +*** . . Const ( Trueprop) +*** . . . Const ( op =) +*** ............. + val SOME t = strip_imp_prems' ((#prop o rep_thm) thm); + atomt t; +*** ------------- +*** Const ( ==>) +*** . Const ( Trueprop) +*** . . Const ( op <=) +*** . . . Var ((z, 0), ) +*** . . . Var ((w, 0), ) +*** . Const ( ==>) +*** . . Const ( Trueprop) +*** . . . Const ( op <=) +*** . . . . Var ((w, 0), ) +*** . . . . Var ((z, 0), ) +*) + +(*. (A1==>...An==>) (B) goes to (A1==>...An==>B), where B is lowest branch.*) +fun ins_concl (Const("==>", T) $ A $ t) B = Logic.implies $ A $ (ins_concl t B) + | ins_concl (Const("==>", T) $ A ) B = Logic.implies $ A $ B + | ins_concl t B = raise TERM("ins_concl", [t, B]); +(* + val thm = real_le_anti_sym; + val prop = (#prop o rep_thm) thm; + val concl = Logic.strip_imp_concl prop; + val SOME prems = strip_imp_prems' prop; + val prop' = ins_concl prems concl; + prop = prop'; + atomt prop; + atomt prop'; +*) + + +fun vperm (Var _, Var _) = true (*2002 Pure/thm.ML *) + | vperm (Abs (_, _, s), Abs (_, _, t)) = vperm (s, t) + | vperm (t1 $ t2, u1 $ u2) = vperm (t1, u1) andalso vperm (t2, u2) + | vperm (t, u) = (t = u); + +(*2002 cp from Pure/term.ML --- since 2009 in Pure/old_term.ML*) +fun mem_term (_, []) = false + | mem_term (t, t'::ts) = t aconv t' orelse mem_term(t,ts); +fun subset_term ([], ys) = true + | subset_term (x :: xs, ys) = mem_term (x, ys) andalso subset_term(xs, ys); +fun eq_set_term (xs, ys) = + xs = ys orelse (subset_term (xs, ys) andalso subset_term (ys, xs)); +(*a total, irreflexive ordering on index names*) +fun xless ((a,i), (b,j): indexname) = i insert_aterm(t,vars) + | Abs (_,_,body) => add_term_vars(body,vars) + | f$t => add_term_vars (f, add_term_vars(t, vars)) + | _ => vars; +fun term_vars t = add_term_vars(t,[]); + + +fun var_perm (t, u) = (*2002 Pure/thm.ML *) + vperm (t, u) andalso eq_set_term (term_vars t, term_vars u); + +(*2002 fun decomp_simp, Pure/thm.ML *) +fun perm lhs rhs = var_perm (lhs, rhs) andalso not (lhs aconv rhs) + andalso not (is_Var lhs); + + +fun str_of_int n = + if n < 0 then "-"^((string_of_int o abs) n) + else string_of_int n; +(* +> str_of_int 1; +val it = "1" : string > str_of_int ~1; +val it = "-1" : string +*) + + +fun power b 0 = 1 + | power b n = + if n>0 then b*(power b (n-1)) + else raise error ("power "^(str_of_int b)^" "^(str_of_int n)); +(* +> power 2 3; +val it = 8 : int +> power ~2 3; +val it = ~8 : int +> power ~3 2; +val it = 9 : int +> power 3 ~2; +*) +fun gcd 0 b = b + | gcd a b = if a < b then gcd (b mod a) a + else gcd (a mod b) b; +fun sign n = if n < 0 then ~1 + else if n = 0 then 0 else 1; +fun sign2 n1 n2 = (sign n1) * (sign n2); + +infix dvd; +fun d dvd n = n mod d = 0; + +fun divisors n = + let fun pdiv ds d n = + if d=n then d::ds + else if d dvd n then pdiv (d::ds) d (n div d) + else pdiv ds (d+1) n + in pdiv [] 2 n end; + +divisors 30; +divisors 32; +divisors 60; +divisors 11; + +fun doubles ds = (* ds is ordered *) + let fun dbls ds [] = ds + | dbls ds [i] = ds + | dbls ds (i::i'::is) = if i=i' then dbls (i::ds) is + else dbls ds (i'::is) + in dbls [] ds end; +(*> doubles [2,3,4]; +val it = [] : int list +> doubles [2,3,3,5,5,7]; +val it = [5,3] : int list*) + +fun squfact 0 = 0 + | squfact 1 = 1 + | squfact n = foldl op* (1, (doubles o divisors) n); +(*> squfact 30; +val it = 1 : int +> squfact 32; +val it = 4 : int +> squfact 60; +val it = 2 : int +> squfact 11; +val it = 1 : int*) + + +fun dest_type (Type(T,[])) = T + | dest_type T = + (atomtyp T; + raise error ("... dest_type: not impl. for this type")); + +fun term_of_num ntyp n = Free (str_of_int n, ntyp); + +fun pairT T1 T2 = Type ("*", [T1, T2]); +(*> val t = str2term "(1,2)"; +> type_of t = pairT HOLogic.realT HOLogic.realT; +val it = true : bool +*) +fun PairT T1 T2 = ([T1, T2] ---> Type ("*", [T1, T2])); +(*> val t = str2term "(1,2)"; +> val Const ("Pair",pT) $ _ $ _ = t; +> pT = PairT HOLogic.realT HOLogic.realT; +val it = true : bool +*) +fun pairt t1 t2 = + Const ("Pair", PairT (type_of t1) (type_of t2)) $ t1 $ t2; +(*> val t = str2term "(1,2)"; +> val (t1, t2) = (str2term "1", str2term "2"); +> t = pairt t1 t2; +val it = true : bool*) + + +fun num_of_term (t as Free (s,_)) = + (case int_of_str s of + SOME s' => s' + | NONE => raise error ("num_of_term not for "^ term2str t)) + | num_of_term t = raise error ("num_of_term not for "^term2str t); + +fun mk_factroot op_(*=thy.sqrt*) T fact root = + Const ("op *", [T, T] ---> T) $ (term_of_num T fact) $ + (Const (op_, T --> T) $ term_of_num T root); +(* +val T = (type_of o term_of o the) (parse thy "#12::real"); +val t = mk_factroot "SqRoot.sqrt" T 2 3; +(cterm_of thy) t; +val it = "#2 * sqrt #3 " : cterm +*) +fun var_op_num v op_ optype ntyp n = + Const (op_, optype) $ v $ + Free (str_of_int n, ntyp); + +fun num_op_var v op_ optype ntyp n = + Const (op_,optype) $ + Free (str_of_int n, ntyp) $ v; + +fun num_op_num T1 T2 (op_,Top) n1 n2 = + Const (op_,Top) $ + Free (str_of_int n1, T1) $ Free (str_of_int n2, T2); +(* +> val t = num_op_num "Int" 3 4; +> atomty t; +> string_of_cterm ((cterm_of thy) t); +*) + +fun const_in str (Const _) = false + | const_in str (Free (s,_)) = if strip_thy s = str then true else false + | const_in str (Bound _) = false + | const_in str (Var _) = false + | const_in str (Abs (_,_,body)) = const_in str body + | const_in str (f$u) = const_in str f orelse const_in str u; +(* +> val t = (term_of o the o (parse thy)) "6 + 5 * sqrt 4 + 3"; +> const_in "sqrt" t; +val it = true : bool +> val t = (term_of o the o (parse thy)) "6 + 5 * 4 + 3"; +> const_in "sqrt" t; +val it = false : bool +*) + +(*used for calculating built in binary operations in Isabelle2002->Float.ML*) +(*fun calc "Groups.plus_class.plus" (n1, n2) = n1+n2 + | calc "Groups.minus_class.minus" (n1, n2) = n1-n2 + | calc "op *" (n1, n2) = n1*n2 + | calc "Rings.inverse_class.divide"(n1, n2) = n1 div n2 + | calc "Atools.pow"(n1, n2) = power n1 n2 + | calc op_ _ = raise error ("calc: operator = "^op_^" not defined");-----*) +fun calc_equ "op <" (n1, n2) = n1 < n2 + | calc_equ "op <=" (n1, n2) = n1 <= n2 + | calc_equ op_ _ = + raise error ("calc_equ: operator = "^op_^" not defined"); +fun sqrt (n:int) = if n < 0 then 0 + (*FIXME ~~~*) else (trunc o Math.sqrt o Real.fromInt) n; + +fun mk_thmid thmid op_ n1 n2 = + thmid ^ (strip_thy n1) ^ "_" ^ (strip_thy n2); + +fun dest_binop_typ (Type("fun",[range,Type("fun",[arg2,arg1])])) = + (arg1,arg2,range) + | dest_binop_typ _ = raise error "dest_binop_typ: not binary"; +(* ----- +> val t = (term_of o the o (parse thy)) "#3^#4"; +> val hT = type_of (head_of t); +> dest_binop_typ hT; +val it = ("'a","nat","'a") : typ * typ * typ + ----- *) + + +(** transform binary numeralsstrings **) +(*Makarius 100308, hacked by WN*) +val numbers_to_string = + let + fun dest_num t = + (case try HOLogic.dest_number t of + SOME (T, i) => + (*if T = @{typ int} orelse T = @{typ real} then WN*) + SOME (Free (signed_string_of_int i, T)) + (*else NONE WN*) + | NONE => NONE); + + fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b) + | to_str (t as (u1 $ u2)) = + (case dest_num t of + SOME t' => t' + | NONE => to_str u1 $ to_str u2) + | to_str t = perhaps dest_num t; + in to_str end + +(*.make uminus uniform: + Const ("uminus", _) $ Free ("2", "RealDef.real") --> Free ("-2", _) +to be used immediately before evaluation of numerals; +see Scripts/calculate.sml .*) +(*2002 fun(*app_num_tr'2 (Const("0",T)) = Free("0",T) + | app_num_tr'2 (Const("1",T)) = Free("1",T) + |*)app_num_tr'2 (t as Const("uminus",_) $ Free(s,T)) = + (case int_of_str s of SOME i => + if i > 0 then Free("-"^s,T) else Free(s,T) + | NONE => t) +(*| app_num_tr'2 (t as Const(s,T)) = t + | app_num_tr'2 (Const("Numeral.number_of",Type ("fun", [_, T])) $ t) = + Free(NumeralSyntax.dest_bin_str t, T) + | app_num_tr'2 (t as Free(s,T)) = t + | app_num_tr'2 (t as Var(n,T)) = t + | app_num_tr'2 (t as Bound i) = t +*)| app_num_tr'2 (Abs(s,T,body)) = Abs(s,T, app_num_tr'2 body) + | app_num_tr'2 (t1 $ t2) = (app_num_tr'2 t1) $ (app_num_tr'2 t2) + | app_num_tr'2 t = t; +*) +val uminus_to_string = + let + fun dest_num t = + (case t of + (Const ("Groups.uminus_class.uminus", _) $ Free (s, T)) => + (case int_of_str s of + SOME i => + SOME (Free (signed_string_of_int (~1 * i), T)) + | NONE => NONE) + | _ => NONE); + + fun to_str (Abs (x, T, b)) = Abs (x, T, to_str b) + | to_str (t as (u1 $ u2)) = + (case dest_num t of + SOME t' => t' + | NONE => to_str u1 $ to_str u2) + | to_str t = perhaps dest_num t; + in to_str end; + + +(*2002 fun num_str thm = + let + val {sign_ref = sign_ref, der = der, maxidx = maxidx, + shyps = shyps, hyps = hyps, (*tpairs = tpairs,*) prop = prop} = + rep_thm_G thm; + val prop' = app_num_tr'1 prop; + in assbl_thm sign_ref der maxidx shyps hyps (*tpairs*) prop' end;*) +fun num_str thm = + let val (deriv, + {thy_ref = thy_ref, tags = tags, maxidx = maxidx, shyps = shyps, + hyps = hyps, tpairs = tpairs, prop = prop}) = rep_thm_G thm + val prop' = numbers_to_string prop; + in assbl_thm deriv thy_ref tags maxidx shyps hyps tpairs prop' end; + +fun get_thm' xstring = (*?covers 2009 Thm?!, replaces 2002 fun get_thm : +val it = fn : theory -> xstring -> Thm.thm*) + Thm (xstring, + num_str (ProofContext.get_thm (thy2ctxt' "Isac") xstring)); + +(** get types of Free and Abs for parse' **) +(*11.1.00: not used, fix-typed +,*,-,^ instead *) + +val dummyT = Type ("dummy",[]); +val dummyT = TVar (("DUMMY",0),[]); + +(* assumes only 1 type for numerals + and different identifiers for Const, Free and Abs *) +fun get_types t = + let + fun get ts (Const(s,T)) = (s,T)::ts + | get ts (Free(s,T)) = if is_no s + then ("#",T)::ts else (s,T)::ts + | get ts (Var(n,T)) = ts + | get ts (Bound i) = ts + | get ts (Abs(s,T,body)) = get ((s,T)::ts) body + | get ts (t1 $ t2) = (get ts t1) @ (get ts t2) + in distinct (get [] t) end; +(* +val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)"; +get_types t; +*) + +(*11.1.00: not used, fix-typed +,*,-,^ instead *) +fun set_types al (Const(s,T)) = + (case assoc (al,s) of + SOME T' => Const(s,T') + | NONE => (warning ("set_types: no type for "^s); Const(s,dummyT))) + | set_types al (Free(s,T)) = + if is_no s then + (case assoc (al,"#") of + SOME T' => Free(s,T') + | NONE => (warning ("set_types: no type for numerals"); Free(s,T))) + else (case assoc (al,s) of + SOME T' => Free(s,T') + | NONE => (warning ("set_types: no type for "^s); Free(s,T))) + | set_types al (Var(n,T)) = Var(n,T) + | set_types al (Bound i) = Bound i + | set_types al (Abs(s,T,body)) = + (case assoc (al,s) of + SOME T' => Abs(s,T', set_types al body) + | NONE => (warning ("set_types: no type for "^s); + Abs(s,T, set_types al body))) + | set_types al (t1 $ t2) = (set_types al t1) $ (set_types al t2); +(* +val t = (term_of o the o (parse thy)) "sqrt(#9+#4*x)=sqrt x + sqrt(#-3+x)"; +val al = get_types t; + +val t = (term_of o the o (parse thy)) "x = #0 + #-1 * #-4"; +atomty t; (* 'a *) +val t' = set_types al t; +atomty t'; (*real*) +(cterm_of thy) t'; +val it = "x = #0 + #-1 * #-4" : cterm + +val t = (term_of o the o (parse thy)) + "#5 * x + x ^^^ #2 = (#2 + x) ^^^ #2"; +atomty t; +val t' = set_types al t; +atomty t'; +(cterm_of thy) t'; +uncaught exception TYPE (*^^^ is new, NOT in al*) +*) + + +(** from Descript.ML **) + +(** decompose an isa-list to an ML-list + i.e. [] belong to the meta-language, too **) + +fun is_list ((Const("List.list.Cons",_)) $ _ $ _) = true + | is_list _ = false; +(* val (SOME ct) = parse thy "lll::real list"; +> val ty = (#t o rep_cterm) ct; +> is_list ty; +val it = false : bool +> val (SOME ct) = parse thy "[lll]"; +> val ty = (#t o rep_cterm) ct; +> is_list ty; +val it = true : bool *) + + + +fun mk_Free (s,T) = Free(s,T); +fun mk_free T s = Free(s,T); + +(*Special case: one argument cp from Isabelle2002/src/Pure/term.ML*) +fun subst_bound (arg, t) : term = (*WN100908 neglects 'raise Same.SAME'*) + let fun subst (t as Bound i, lev) = + if i val ttt = (term_of o the o (parse thy)) scr; +> tracing(term2str ttt); +> atomt ttt; +*** ------------- +*** Const ( DiffApp.Make'_fun'_by'_explicit) +*** . Free ( f_, ) +*** . Free ( v_, ) +*** . Free ( eqs_, ) +*** . Const ( Let) +*** . . Const ( Fun.op o) +*** . . . Const ( List.hd) +*** . . . Const ( DiffApp.filterVar) +*** . . . . Free ( f_, ) +*** . . . Free ( eqs_, ) +*** . . Abs( h_,.. +*** . . . Const ( Let) +*** . . . . Const ( List.hd) +*** . . . . . Const ( List.dropWhile) +*** . . . . . . Const ( Atools.ident) +*** . . . . . . . Bound 0 <---- Free ( h_, ) +*** . . . . . . Free ( eqs_, ) +*** . . . . Abs( e_1,.. +*** . . . . . Const ( Let) +*** . . . . . . Const ( List.dropWhile) +*** . . . . . . . Const ( Atools.ident) +*** . . . . . . . . Free ( f_, ) +*** . . . . . . . Const ( Tools.Vars) +*** . . . . . . . . Bound 1 <---- Free ( h_, ) +*** . . . . . . Abs( vs_,.. +*** . . . . . . . Const ( Let) +*** . . . . . . . . Const ( List.hd) +*** . . . . . . . . . Const ( List.dropWhile) +*** . . . . . . . . . . Const ( Atools.ident) +*** . . . . . . . . . . . Free ( v_, ) +*** . . . . . . . . . . Bound 0 <---- Free ( vs_, ) +*** . . . . . . . . Abs( v_1,.. +*** . . . . . . . . . Const ( Let) +*** . . . . . . . . . . Const ( Script.SubProblem) +*** . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . Free ( DiffApp_, ) +*** . . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . Free ( univar, ) +*** . . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . . Free ( equation, ) +*** . . . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . Free ( no_met, ) +*** . . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . Const ( Script.BOOL) +*** . . . . . . . . . . . . . Bound 2 <----- Free ( e_1, ) +*** . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . Const ( Script.real_) +*** . . . . . . . . . . . . . . Bound 0 <----- Free ( v_1, ) +*** . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . Abs( s_1,.. +*** . . . . . . . . . . . Const ( Script.Substitute) +*** . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . . . Bound 1 <----- Free ( v_1, ) +*** . . . . . . . . . . . . . . Const ( Fun.op o) +*** . . . . . . . . . . . . . . . Const ( Tools.rhs) +*** . . . . . . . . . . . . . . . Const ( List.hd) +*** . . . . . . . . . . . . . . . Bound 0 <----- Free ( s_1, ) +*** . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . . Bound 4 <----- Free ( h_, ) + +> val ttt' = inst_abs thy ttt; +> tracing(term2str ttt'); +Script Make_fun_by_explicit f_ v_ eqs_ = + ... as above ... +> atomt ttt'; +*** ------------- +*** Const ( DiffApp.Make'_fun'_by'_explicit) +*** . Free ( f_, ) +*** . Free ( v_, ) +*** . Free ( eqs_, ) +*** . Const ( Let) +*** . . Const ( Fun.op o) +*** . . . Const ( List.hd) +*** . . . Const ( DiffApp.filterVar) +*** . . . . Free ( f_, ) +*** . . . Free ( eqs_, ) +*** . . Abs( h_,.. +*** . . . Const ( Let) +*** . . . . Const ( List.hd) +*** . . . . . Const ( List.dropWhile) +*** . . . . . . Const ( Atools.ident) +*** . . . . . . . Free ( h_, ) <---- Bound 0 +*** . . . . . . Free ( eqs_, ) +*** . . . . Abs( e_1,.. +*** . . . . . Const ( Let) +*** . . . . . . Const ( List.dropWhile) +*** . . . . . . . Const ( Atools.ident) +*** . . . . . . . . Free ( f_, ) +*** . . . . . . . Const ( Tools.Vars) +*** . . . . . . . . Free ( h_, ) <---- Bound 1 +*** . . . . . . Abs( vs_,.. +*** . . . . . . . Const ( Let) +*** . . . . . . . . Const ( List.hd) +*** . . . . . . . . . Const ( List.dropWhile) +*** . . . . . . . . . . Const ( Atools.ident) +*** . . . . . . . . . . . Free ( v_, ) +*** . . . . . . . . . . Free ( vs_, ) <---- Bound 0 +*** . . . . . . . . Abs( v_1,.. +*** . . . . . . . . . Const ( Let) +*** . . . . . . . . . . Const ( Script.SubProblem) +*** . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . Free ( DiffApp_, ) +*** . . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . Free ( univar, ) +*** . . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . . Free ( equation, ) +*** . . . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . . Free ( no_met, ) +*** . . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . Const ( Script.BOOL) +*** . . . . . . . . . . . . . Free ( e_1, ) <----- Bound 2 +*** . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . Const ( Script.real_) +*** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 0 +*** . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . Abs( s_1,.. +*** . . . . . . . . . . . Const ( Script.Substitute) +*** . . . . . . . . . . . . Const ( List.list.Cons) +*** . . . . . . . . . . . . . Const ( Pair) +*** . . . . . . . . . . . . . . Free ( v_1, ) <----- Bound 1 +*** . . . . . . . . . . . . . . Const ( Fun.op o) +*** . . . . . . . . . . . . . . . Const ( Tools.rhs) +*** . . . . . . . . . . . . . . . Const ( List.hd) +*** . . . . . . . . . . . . . . . Free ( s_1, ) <----- Bound 0 +*** . . . . . . . . . . . . . Const ( List.list.Nil) +*** . . . . . . . . . . . . Free ( h_, ) <----- Bound 4 + +Note numbering of de Bruijn indexes ! + +Script Make_fun_by_explicit f_ v_ eqs_ = + let h_ = (hd o filterVar f_) eqs_; + e_1 = hd (dropWhile (ident h_ BOUND_0) eqs_); + vs_ = dropWhile (ident f_) (Vars h_ BOUND_1); + v_1 = hd (dropWhile (ident v_) vs_ BOUND_0); + s_1 = + SubProblem (DiffApp_, [univar, equation], [no_met]) + [BOOL e_1 BOUND_2, REAL v_1 BOUND_0] + in Substitute [(v_1 BOUND_1 = (rhs o hd) s_1 BOUND_0)] h_ BOUND_4 +*) + + +fun T_a2real (Type (s, [])) = + if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else Type (s, []) + | T_a2real (Type (s, Ts)) = Type (s, map T_a2real Ts) + | T_a2real (TFree (s, srt)) = + if s = "'a" orelse s = "'b" orelse s = "'c" then HOLogic.realT else TFree (s, srt) + | T_a2real (TVar (("DUMMY",_),srt)) = HOLogic.realT; + +(*FIXME .. fixes the type (+see Typefix.thy*) +fun typ_a2real (Const( s, T)) = (Const( s, T_a2real T)) + | typ_a2real (Free( s, T)) = (Free( s, T_a2real T)) + | typ_a2real (Var( n, T)) = (Var( n, T_a2real T)) + | typ_a2real (Bound i) = (Bound i) + | typ_a2real (Abs(s,T,t)) = Abs(s, T, typ_a2real t) + | typ_a2real (t1 $ t2) = (typ_a2real t1) $ (typ_a2real t2); +(* +----------------6.8.02--------------------------------------------------- + val str = "1"; + val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[]))); + atomty (term_of t); +*** ------------- +*** Const ( 1, 'a) + val t = (app_num_tr' o term_of) t; + atomty t; +*** ------------- +*** Const ( 1, 'a) + val t = typ_a2real t; + atomty t; +*** ------------- +*** Const ( 1, real) + + val str = "2"; + val t = read_cterm (sign_of thy) (str,(TVar(("DUMMY",0),[]))); + atomty (term_of t); +*** ------------- +*** Const ( Numeral.number_of, bin => 'a) +*** . Const ( Numeral.bin.Bit, [bin, bool] => bin) +*** . . Const ( Numeral.bin.Bit, [bin, bool] => bin) +*** . . . Const ( Numeral.bin.Pls, bin) +*** . . . Const ( True, bool) +*** . . Const ( False, bool) + val t = (app_num_tr' o term_of) t; + atomty t; +*** ------------- +*** Free ( 2, 'a) + val t = typ_a2real t; + atomty t; +*** ------------- +*** Free ( 2, real) +----------------6.8.02--------------------------------------------------- + + +> val str = "R"; +> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); +val t = Free ("R","?DUMMY") : term +> val t' = typ_a2real t; +> (cterm_of thy) t'; +val it = "R::RealDef.real" : cterm + +> val str = "R=R"; +> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); +> atomty (typ_a2real t); +*** ------------- +*** Const ( op =, [RealDef.real, RealDef.real] => bool) +*** Free ( R, RealDef.real) +*** Free ( R, RealDef.real) +> val t' = typ_a2real t; +> (cterm_of thy) t'; +val it = "(R::RealDef.real) = R" : cterm + +> val str = "fixed_values [R=R]"; +> val t = term_of (read_cterm(sign_of thy)(str,(TVar(("DUMMY",0),[])))); +> val t' = typ_a2real t; +> (cterm_of thy) t'; +val it = "fixed_values [(R::RealDef.real) = R]" : cterm +*) + +(*TODO.WN0609: parse should return a term or a string + (or even more comprehensive datastructure for error-messages) + i.e. in wrapping with SOME term or NONE the latter is not sufficient*) +(*2002 fun parseold thy str = + (let + val sgn = sign_of thy; + val t = ((*typ_a2real o*) app_num_tr'1 o term_of) + (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); + in SOME (cterm_of sgn t) end) + handle _ => NONE;*) + + + +fun parseold thy str = + (let val t = ((*typ_a2real o*) numbers_to_string) + (Syntax.read_term_global thy str) + in SOME (cterm_of thy t) end) + handle _ => NONE; +(*2002 fun parseN thy str = + (let + val sgn = sign_of thy; + val t = ((*typ_a2real o app_num_tr'1 o*) term_of) + (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); + in SOME (cterm_of sgn t) end) + handle _ => NONE;*) +fun parseN thy str = + (let val t = (*(typ_a2real o numbers_to_string)*) + (Syntax.read_term_global thy str) + in SOME (cterm_of thy t) end) + handle _ => NONE; +(*2002 fun parse thy str = + (let + val sgn = sign_of thy; + val t = (typ_a2real o app_num_tr'1 o term_of) + (read_cterm sgn (str,(TVar(("DUMMY",0),[])))); + in SOME (cterm_of sgn t) end) (*FIXXXXME 10.8.02: return term !!!*) + handle _ => NONE;*) +(*2010 fun parse thy str = + (let val t = (typ_a2real o app_num_tr'1) (Syntax.read_term_global thy str) + in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*) + handle _ => NONE;*) +fun parse thy str = + (let val t = (typ_a2real o numbers_to_string) + (Syntax.read_term_global thy str) + in SOME (cterm_of thy t) end) (*FIXXXXME 10.8.02: return term !!!*) + handle _ => NONE; +(* +> val (SOME ct) = parse thy "(-#5)^^^#3"; +> atomty (term_of ct); +*** ------------- +*** Const ( Nat.op ^, ['a, nat] => 'a) +*** Const ( uminus, 'a => 'a) +*** Free ( #5, 'a) +*** Free ( #3, nat) +> val (SOME ct) = parse thy "R=R"; +> atomty (term_of ct); +*** ------------- +*** Const ( op =, [real, real] => bool) +*** Free ( R, real) +*** Free ( R, real) + +THIS IS THE OUTPUT FOR VERSION (3) above at typ_a2real !!!!! +*** ------------- +*** Const ( op =, [RealDef.real, RealDef.real] => bool) +*** Free ( R, RealDef.real) +*** Free ( R, RealDef.real) *) + +fun parse_patt thy str = + ProofContext.read_term_pattern (thy2ctxt thy) str; + +(*version for testing local to theories*) +fun str2term_ thy str = (term_of o the o (parse thy)) str; +fun str2term str = (term_of o the o (parse (theory "Isac"))) str; +fun strs2terms ss = map str2term ss; +fun str2termN str = (term_of o the o (parseN (theory "Isac"))) str; + +(*+ makes a substitution from the output of Pattern.match +*) +(*fun mk_subs ((id, _):indexname, t:term) = (Free (id,type_of t), t);*) +fun mk_subs (subs: ((string * int) * (Term.typ * Term.term)) list) = +let fun mk_sub ((id, _), (ty, tm)) = (Free (id, ty), tm) in +map mk_sub subs end; + +val atomthm = atomt o #prop o rep_thm; + +(*.instantiate #prop thm with bound variables (as Free).*) +fun inst_bdv [] t = t : term + | inst_bdv (instl: (term*term) list) t = + let fun subst (v as Var((s,_),T)) = + (case explode s of + "b"::"d"::"v"::_ => + if_none (assoc(instl,Free(s,T))) (Free(s,T)) + | _ => v) + | subst (Abs(a,T,body)) = Abs(a, T, subst body) + | subst (f$t') = subst f $ subst t' + | subst t = if_none (assoc(instl,t)) t + in subst t end; + + +(*WN050829 caution: is_atom (str2term"q_0/2 * L * x") = true !!! + use length (vars term) = 1 instead*) +fun is_atom (Const ("Float.Float",_) $ _) = true + | is_atom (Const ("ComplexI.I'_'_",_)) = true + | is_atom (Const ("op *",_) $ t $ Const ("ComplexI.I'_'_",_)) = is_atom t + | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ Const ("ComplexI.I'_'_",_)) = is_atom t1 + | is_atom (Const ("Groups.plus_class.plus",_) $ t1 $ + (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_))) = + is_atom t1 andalso is_atom t2 + | is_atom (Const _) = true + | is_atom (Free _) = true + | is_atom (Var _) = true + | is_atom _ = false; +(* val t = str2term "q_0/2 * L * x"; + + +*) +(*val t = str2term "Float ((1,2),(0,0))"; +> is_atom t; +val it = true : bool +> val t = str2term "Float ((1,2),(0,0)) * I__"; +> is_atom t; +val it = true : bool +> val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * I__"; +> is_atom t; +val it = true : bool +> val t = str2term "1 + 2*I__"; +> val Const ("Groups.plus_class.plus",_) $ t1 $ (Const ("op *",_) $ t2 $ Const ("ComplexI.I'_'_",_)) = t; +*) + +(*.adaption from Isabelle/src/Pure/term.ML; reports if ALL Free's + have found a substitution (required for evaluating the preconditions + of _incomplete_ models).*) +fun subst_atomic_all [] t = (false, (*TODO may be 'true' for some terms ?*) + t : term) + | subst_atomic_all (instl: (term*term) list) t = + let fun subst (Abs(a,T,body)) = + let val (all, body') = subst body + in (all, Abs(a, T, body')) end + | subst (f$tt) = + let val (all1, f') = subst f + val (all2, tt') = subst tt + in (all1 andalso all2, f' $ tt') end + | subst (t as Free _) = + if is_num t then (true, t) (*numerals cannot be subst*) + else (case assoc(instl,t) of + SOME t' => (true, t') + | NONE => (false, t)) + | subst t = (true, if_none (assoc(instl,t)) t) + in subst t end; + +(*.add two terms with a type given.*) +fun mk_add t1 t2 = + let val T1 = type_of t1 + val T2 = type_of t2 + in if T1 <> T2 then raise TYPE ("mk_add gets ",[T1, T2],[t1,t2]) + else (Const ("Groups.plus_class.plus", [T1, T2] ---> T1) $ t1 $ t2) + end; + diff -r 20231cdf39e7 -r 67a110289e4e src/Tools/isac/Test_Isac.thy --- a/src/Tools/isac/Test_Isac.thy Mon Sep 27 13:35:06 2010 +0200 +++ b/src/Tools/isac/Test_Isac.thy Tue Sep 28 07:28:10 2010 +0200 @@ -27,37 +27,21 @@ cd "../.."; *) ML{* writeln "**** run systests complete ******************************" *}; - -ML {* -val t1 = @{term "1+2::real"}; -val t2 = @{term "abc"}; -term2str t2 = "abc"; -fun terms2str ts = (strs2str o (map term2str )) ts; -terms2str [t1,t2] = "[\"1 + 2\",\"abc\"]"; -fun terms2str' ts = (strs2str' o (map term2str )) ts; -terms2str' [t1,t2] = "[1 + 2,abc]"; -fun terms2strs ts = (map term2str) ts; -terms2strs [t1,t2] = ["1 + 2", "abc"]; -*} - (* cd"smltest/Scripts"; - use"calculate-float.sml"; *) -use"ProgLang/calculate.sml"; (*part.*) +use"../../../test/Tools/isac/ProgLang/termC.sml"; (*part.*) +use"../../../test/Tools/isac/ProgLang/calculate.sml"; (*part.*) +use"../../../test/Tools/isac/ProgLang/rewrite.sml"; (*part.*) (* use"listg.sml"; -*) -use"ProgLang/rewrite.sml"; (*part.*) -(* use"scrtools.sml"; - use"term.sml"; use"tools.sml"; cd "../.."; cd"smltest/ME"; use"ctree.sml"; *) -use "Interpret/calchead.sml" (*part.*) +use "../../../test/Tools/isac/Interpret/calchead.sml" (*part.*) (* use"calchead.sml"; use"rewtools.sml"; @@ -89,7 +73,7 @@ (*use"inssort.sml"; problems with recdef in Isabelle2002*) use"logexp.sml"; *) -use"Knowledge/poly.sml"; (*part.*) +use"../../../test/Tools/isac/Knowledge/poly.sml"; (*part.*) (* use"polyminus.sml"; use"polyeq.sml"; (*TODO 31.b, n1., 44.a, 1.a~, 1.b (all'expanded')WN @@ -119,12 +103,12 @@ use_thy "../../Tools/isac/ADDTESTS/trace-rewrite/Build_Test" *) -use_thy "../../Pure/Isar/Test_Parse_Term" -use_thy "../../Pure/Isar/Test_Parsers" +use_thy "../../../test/Pure/Isar/Test_Parse_Term" +use_thy "../../../test/Pure/Isar/Test_Parsers" ML{* writeln "**** run tests on IsacKnowledge complete ****************" *}; (* -val path = "/home/neuper/proto2/testsml2xml/"; +val path = "/home/neuper/proto3/testsml2xml/"; pbl_hierarchy2file (path ^ "pbl/"); pbls2file (path ^ "pbl/"); met_hierarchy2file (path ^ "met/"); diff -r 20231cdf39e7 -r 67a110289e4e test/Tools/isac/ProgLang/calculate-float.sml --- a/test/Tools/isac/ProgLang/calculate-float.sml Mon Sep 27 13:35:06 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -(* (c) Stefan Rath 2005 - tests for sml/Scripts/calculate.sml - - use"~/proto2/isac/src/smltest/Scripts/calculate-float.sml"; - use"calculate-float.sml"; - *) - - -(*WN.28.3.03 fuer Matthias*) -(*Floatingpointnumbers, direkte Darstellung der abstrakten Syntax:*) - val thy = Float.thy; - val t = str2term "Float ((1,2),(0,0))"; - atomt t; - val t = (term_of o the o (parse thy)) - "Float ((1,2),(0,0)) + Float ((3,4),(0,0)) * \ - \Float ((5,6),(0,0)) / Float ((7,8),(0,0))"; - atomt t; -(*die konkrete Syntax wird noch verschoenert*) - - val thy = "Test.thy"; - val op_ = "divide_"; - val ct = "-6 / 3"; - val SOME (ct,_) = calculate thy (the (assoc (calclist, op_))) ct; - -(*-----WN050315------------------------------------------------------*) -(*..*) -val t = str2term "Float ((1,2),(0,0))"; -atomty t; -val Const ("Float.Float",_) $ - (Const ("Pair",_) $ - (Const ("Pair",_) $ Free (i1,_) $ Free (i2,_)) $ _) = t; - -val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0))"; -atomty t; -(*-----WN050315------------------------------------------------------*) - - -val thy = Float.thy; - -(*.calculate the value of a pair of floats.*) -val ((a,b),(c,d)) = calc "Groups.plus_class.plus" ((~1,0),(0,0)) ((2,0),(0,0)); - - -(*.build the term.*) -term_of_float HOLogic.realT ((~1,0),(0,0)); -term_of_float HOLogic.realT ((~1,11),(0,0)); - -(*--18.3.05-------------------------*) -val t = Free ("sdfsdfsdf", HOLogic.realT); -val t = Free ("-123,456", HOLogic.realT); -val t = Free ("0,123456", HOLogic.realT); -term2str t; -(*----(1)------------------------------*) -val t = str2term "IFloat (1, 2, 3)"; -val t = str2term "CFloat (1, 2)"; -atomt t; -atomty t; -val SOME ct = parse Float.thy "IFloat (1, 2, 3)"; -val SOME ct = parse Float.thy "CFloat (1, 2)"; -atomt (term_of ct); -atomty (term_of ct); -(*----(2)------------------------------*) -val SOME ct = parse Float.thy "IFloat (-1, 2, 3)"; -val t = (term_of ct); -atomty t; -(*#######################################################################3 -val Const - ("Float.IFloat", _) $ - (Const - ("Pair", _) $ - Free (no, _) $ - (Const - ("Pair", _) $ - Free (commas, _) $ Free (exp, _))) = t; - -fun IFloat2CFloat - (Const - ("Float.IFloat", _) $ - (Const - ("Pair", _) $ - Free (no, _) $ - (Const - ("Pair", _) $ - Free (commas, _) $ Free (exp, _)))) = - Const ("Float.CFloat", HOLogic.realT(*wrong type*)) $ - (Const - ("Pair", HOLogic.realT(*wrong type*)) $ - Free (no^"."^commas, HOLogic.realT) - $ Free ("accuracy", HOLogic.realT)) - - | IFloat2CFloat t = - raise error ("IFloat2CFloat: invalid argument "^term2str t); - -val cf = IFloat2CFloat t; -term2str cf; - -(*in IsacKnowledge/Float.ML: fun pairt -> Pair-term*) - -fun CFloat2Free (Const ("Float.CFloat", _) $ - (Const ("Pair", _) $ Free (no_commas, _) $ _)) = - Free (no_commas, HOLogic.realT); - -val t' = CFloat2Free cf; -term2str t'; - -fun CFloat2sml (Const ("Float.CFloat", _) $ - (Const ("Pair", _) $ Free (float, _) $ _(**))) = - float; -CFloat2sml cf; - -(*--18.3.05-------------------------*) - - -(*.the function evaluating a binary operator.*) -val t = str2term "Float ((1,2),(0,0)) + Float ((3,4),(0,0))"; -val SOME (thmid, t) = eval_binop "#add_" "Groups.plus_class.plus" t thy; -term2str t; - - -(*.scan a term for a pair of floats.*) - val SOME (thmid,t') = get_pair thy op_ eval_fn t; - - -(*.use 'calculate' explicitly.*) - val thy = Test.thy; - val op_ = "divide_"; - val t = str2term "sqrt (x ^^^ 2 + -3 * x) =\ - \Float ((5,6),(0,0)) / Float ((7,8),(0,0))"; - val SOME (t',_) = calculate_ thy (the (assoc (calclist, op_))) t; - term2str t'; - - -(*.rewrite with ruleset TEST...simplify (calling calculate internally.*) -val t = str2term "a + Float ((1,2),(0,0)) + a + Float ((3,4),(0,0)) * \ - \Float ((5,6),(0,0)) / Float ((7,8),(0,0))"; -val SOME (t',_) = rewrite_set_ thy false norm_Rational(*///*) t; term2str t'; -(*Float ((...,...) + 2*a*) - - -(*. parse a float as seen by the user .*) -val SOME t = parse Float.thy "123.456"; -val SOME t = parse Float.thy "-123.456"; -val SOME t = parse Float.thy "123.456 E6789"; -val SOME t = parse Float.thy "123.456 E-6789"; -val SOME t = parse Float.thy "-123.456 E-6789"; - -################################################################*) diff -r 20231cdf39e7 -r 67a110289e4e test/Tools/isac/ProgLang/rewrite.sml --- a/test/Tools/isac/ProgLang/rewrite.sml Mon Sep 27 13:35:06 2010 +0200 +++ b/test/Tools/isac/ProgLang/rewrite.sml Tue Sep 28 07:28:10 2010 +0200 @@ -14,7 +14,7 @@ "----------- test rewriting without Isac's thys ---------"; "----------- conditional rewriting without Isac's thys --"; "----------- step through 'and rew_sub': ----------------"; -"----------- rewrite_terms_ ----------------------------"; +"----------- step through 'fun rewrite_terms_' ---------"; "----------- rewrite_inst_ bdvs -------------------------"; "----------- check diff 2002--2009-3 --------------------"; "--------------------------------------------------------"; @@ -155,6 +155,7 @@ "----------- step through 'and rew_sub': ----------------"; "----------- step through 'and rew_sub': ----------------"; (*and make asms without Trueprop, beginning with the result:*) +val tm = @{term "x*y / y::real"}; val (t', asm, _, _) = rew_sub thy 0 [] dummy_ord e_rls true [] (prop_of thm) tm; show_types := false; "----- evaluate arguments"; @@ -163,11 +164,11 @@ "----- step 1: lhs, rhs of rule"; val (lhs, rhs) = (HOLogic.dest_eq o HOLogic.dest_Trueprop o Logic.strip_imp_concl) r; -term2str r = "?b ~= (0::?'a) ==> ?a * ?b / ?b = ?a"; +term2str r = "?b ~= (0::?'a) ==> ?a * ?b / ?b = ?a"; term2str lhs = "?a * ?b / ?b"; term2str rhs = "?a"; "----- step 2: the rule instantiated"; - val r' = Envir.subst_term (Pattern.match thy (lhs, t) - (Vartab.empty, Vartab.empty)) r; + val r' = Envir.subst_term + (Pattern.match thy (lhs, t) (Vartab.empty, Vartab.empty)) r; term2str r' = "y ~= 0 ==> x * y / y = x"; "----- step 3: get the (instantiated) assumption(s)"; val p' = (fst o Logic.strip_prems) (Logic.count_prems r', [], r'); @@ -185,28 +186,38 @@ o Logic.strip_imp_concl) r'; term2str t' = "x"; -(*===== inhibit exn ============================================================ -"----------- rewrite_terms_ ----------------------------"; -"----------- rewrite_terms_ ----------------------------"; -"----------- rewrite_terms_ ----------------------------"; -val subte = [str2term "x = 0"]; -val t = str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2"; -val SOME (t',_) = rewrite_terms_ thy dummy_ord Erls subte t; (*NONE..TODO*) +"----------- step through 'fun rewrite_terms_' ---------"; +"----------- step through 'fun rewrite_terms_' ---------"; +"----------- step through 'fun rewrite_terms_' ---------"; +"----- step 0: args for rewrite_terms_, local fun"; +val (thy, ord, erls, equs, t) = + (theory "Biegelinie", dummy_ord, Erls, [str2term "x = 0"], + str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2"); +"----- step 1: args for rew_"; +val ((t', asm'), (rules as r::rs), t) = ((e_term, []), equs, t); +"----- step 2: rew_sub"; +rew_sub thy 1 [] ord erls false [] (Trueprop $ r) t; +"----- step 3: step through rew_sub -- inefficient: goes into subterms"; + + +val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t; +writeln "----------- rewrite_terms_ 1---------------------------"; if term2str t' = "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then () else raise error "rewrite.sml rewrite_terms_ [x = 0]"; -val subte = [str2term "M_b 0 = 0"]; -val t = str2term"M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2"; -val SOME (t',_) = rewrite_terms_ thy dummy_ord Erls subte t; +val equs = [str2term "M_b 0 = 0"]; +val t = str2term "M_b 0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2"; +val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t; +writeln "----------- rewrite_terms_ 2---------------------------"; if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then () else raise error "rewrite.sml rewrite_terms_ [M_b 0 = 0]"; -val subte = [str2term"x = 0", str2term"M_b 0 = 0"]; -val t = str2term"M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2"; -val SOME (t',_) = rewrite_terms_ thy dummy_ord Erls subte t; +val equs = [str2term "x = 0", str2term"M_b 0 = 0"]; +val t = str2term "M_b x = -1 * q_0 * x ^^^ 2 / 2 + x * c + c_2"; +val SOME (t', _) = rewrite_terms_ thy dummy_ord Erls equs t; +writeln "----------- rewrite_terms_ 3---------------------------"; if term2str t' = "0 = -1 * q_0 * 0 ^^^ 2 / 2 + 0 * c + c_2" then () else raise error "rewrite.sml rewrite_terms_ [x = 0, M_b 0 = 0]"; -===== inhibit exn ============================================================*) "----------- rewrite_inst_ bdvs -------------------------"; @@ -233,6 +244,7 @@ trace_rewrite:=true; trace_rewrite:=false;--------------------------------------------*) + "----------- check diff 2002--2009-3 --------------------"; "----------- check diff 2002--2009-3 --------------------"; "----------- check diff 2002--2009-3 --------------------"; @@ -323,3 +335,10 @@ (* ^^^^^ goes with '====== calc. to: False' above from beginning*) trace_rewrite := false; (*<<<<<<<<<<<<<<<<<<<<<###############################*) "--------------------------------------------------------"; + + +(*===== inhibit exn ============================================================ +===== inhibit exn ============================================================*) + +(*-.-.-.-.-.-isolate response.-.-.-.-.-.-. +-.-.-.-.-.-.-isolate response.-.-.-.-.-.*) diff -r 20231cdf39e7 -r 67a110289e4e test/Tools/isac/ProgLang/term.sml --- a/test/Tools/isac/ProgLang/term.sml Mon Sep 27 13:35:06 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,168 +0,0 @@ -(* tests on Scripts/term_G.sml - author: Walther Neuper - 051006, - (c) due to copyright terms - -use"../smltest/Scripts/term_G.sml"; -use"term_G.sml"; -*) - -"-----------------------------------------------------------------"; -"table of contents -----------------------------------------------"; -"-----------------------------------------------------------------"; -"----------- inst_bdv --------------------------------------------"; -"----------- subst_atomic_all ------------------------------------"; -"----------- Pattern.match ---------------------------------------"; -"----------- fun matches -----------------------------------------"; -"------------parse------------------------------------------------"; -"----------- uminus_to_string ------------------------------------"; -"-----------------------------------------------------------------"; -"-----------------------------------------------------------------"; - - -"----------- inst_bdv --------------------------------------------"; -"----------- inst_bdv --------------------------------------------"; -"----------- inst_bdv --------------------------------------------"; -if string_of_thm (num_str @{thm d1_isolate_add2}) = - "\"~ ?bdv occurs_in ?a ==> (?a + ?bdv = 0) = (?bdv = -1 * ?a)\"" then () -else raise error "term_G.sml d1_isolate_add2"; -val subst = [(str2term "bdv", str2term "x")]; -val t = (norm o #prop o rep_thm) (num_str @{thm d1_isolate_add2}); -val t' = inst_bdv subst t; -if term2str t' = "~ x occurs_in ?a ==> (?a + x = 0) = (x = -1 * ?a)" then () -else raise error "term_G.sml inst_bdv 1"; - -if string_of_thm (num_str @{thm separate_bdvs_add}) = - "\"[] from_ [?bdv_1.0, ?bdv_2.0, ?bdv_3.0, ?bdv_4.0] occur_exactly_in ?a\n\ - \ ==> (?a + ?b = ?c) = (?b = ?c + -1 * ?a)\"" then () -else raise error "term_G.sml separate_bdvs_add"; -val subst = [(str2term"bdv_1",str2term"c"), - (str2term"bdv_2",str2term"c_2"), - (str2term"bdv_3",str2term"c_3"), - (str2term"bdv_4",str2term"c_4")]; -val t = (norm o #prop o rep_thm) (num_str @{thm separate_bdvs_add}); -val t' = inst_bdv subst t; -if term2str t' = "[] from_ [c, c_2, c_3, c_4] occur_exactly_in ?a\n\ - \==> (?a + ?b = ?c) = (?b = ?c + -1 * ?a)" then () -else raise error "term_G.sml inst_bdv 2"; - - -"----------- subst_atomic_all ------------------------------------"; -"----------- subst_atomic_all ------------------------------------"; -"----------- subst_atomic_all ------------------------------------"; -val t = str2term"(tl vs_) from_ vs_ occur_exactly_in (nth_ 1(es_::bool list))"; -val env = [(str2term"vs_::real list",str2term"[c, c_2]"), - (str2term"es_::bool list",str2term"[c_2=0, c+c_2=1]")]; -val (all_Free_subst, t') = subst_atomic_all env t; -if all_Free_subst andalso - term2str t' = "tl [c, c_2] from_ [c, c_2] occur_exactly_in nth_ 1 [c_2 = 0, c + c_2 = 1]" then () -else raise error "term_G.sml subst_atomic_all should be 'true'"; - - -val (all_Free_subst, t') = subst_atomic_all (tl env) t; -if not all_Free_subst andalso - term2str t' = "tl vs_ from_ vs_ occur_exactly_in nth_ 1 [c_2 = 0, c + c_2 = 1]" then () -else raise error "term_G.sml subst_atomic_all should be 'false'"; - - -"----------- Pattern.match ---------------------------------------"; -"----------- Pattern.match ---------------------------------------"; -"----------- Pattern.match ---------------------------------------"; -val t = (term_of o the o (parse thy)) "3 * x^^^2 = 1"; -val pat = (free2var o term_of o the o (parse thy)) "a * b^^^2 = c"; -(* !^^^^^^^^!... necessary for Pattern.match*) -val insts = Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t); -(*val insts = - ([], - [(("c",0),Free ("1","RealDef.real")),(("b",0),Free ("x","RealDef.real")), - (("a",0),Free ("3","RealDef.real"))]) - : (indexname * typ) list * (indexname * term) list*) - -"----- throws exn MATCH..."; -val t = str2term "x"; -(Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t)) -handle MATCH => ([(* (Term.indexname * Term.typ) *)], - [(* (Term.indexname * Term.term) *)]); -Pattern.MATCH; - -(*ML {**) -val thy = @{theory "Complex_Main"}; -val PARSE = Syntax.read_term_global thy; -val (pa, tm) = (PARSE "a + b::real", PARSE "x + 2*z::real"); -"-------"; -val (tye, tme) = - (Vartab.empty : Type.tyenv, Vartab.empty : Envir.tenv); -"-------"; -val (tye, tme) = Pattern.match thy (Logic.varify pa, tm) (Vartab.empty, - Vartab.empty); -"-------"; -val (tyenv, tenv) = Pattern.match thy (Logic.varify pa, tm) - (Vartab.empty, Vartab.empty); -Vartab.dest tenv; -match thy tm (Logic.varify pa); - -(**}*) - -"----------- fun matches -----------------------------------------"; -"----------- fun matches -----------------------------------------"; -"----------- fun matches -----------------------------------------"; -(*smltest/IsacKnowledge/polyeq.sml: - Where=[Correct "matches (?a = 0) (-8 - 2 * x + x ^^^ 2 = 0)"*) -(*smltest/ME/ptyps.sml: - |\nmatches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],*) -(*ML {**) -val thy = @{theory "Complex_Main"}; -"----- test 1"; -val pa = Logic.varify @{term "a = (0::real)"}; -"----- test 1 true"; -val tm = @{term "-8 - 2 * x + x ^ 2 = (0::real)"}; -if matches thy tm pa then () - else error "term_G.sml diff.behav. in matches true"; -"----- test 2 false"; -val tm = @{term "-8 - 2 * x + x ^ 2 = (3::real)"}; -if matches thy tm pa then error "term_G.sml diff.behav. in matches false" - else (); -(**}*) - -"------------parse------------------------------------------------"; -"------------parse------------------------------------------------"; -"------------parse------------------------------------------------"; -(*ML {**) -Toplevel.debug := true; -(* literal types: -PolyML.addPrettyPrinter - (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ); -*)(* pretty types: -PolyML.addPrettyPrinter - (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy); -print_depth 99; -*) -val thy = @{theory "Complex_Main"}; -val str = "x + z"; -parse thy str; -"---------------"; -val str = "x + 2*z"; -val t = (Syntax.read_term_global thy str); -val t = numbers_to_string (Syntax.read_term_global thy str); -val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str); -cterm_of thy t; -val t = (the (parse thy str)) handle _ => error "term_G.sml parsing 'x + 2*z' failed"; -(**}*) -(*Makarius.1003 -ML {* @{term "2::int"} *} - -term "(1.24444) :: real" - -ML {* numbers_to_string @{term "%x. (-9993::int) + x + 1"} *} -*) - - -"----------- uminus_to_string ------------------------------------"; -"----------- uminus_to_string ------------------------------------"; -"----------- uminus_to_string ------------------------------------"; -(*ML {*) -val t1 = numbers_to_string @{term "-2::real"}; -val t2 = numbers_to_string @{term "- 2::real"}; -if uminus_to_string t2 = t1 then () -else error "term_G.sml diff.behav. in uminus_to_string"; -(*}*) diff -r 20231cdf39e7 -r 67a110289e4e test/Tools/isac/ProgLang/termC.sml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/Tools/isac/ProgLang/termC.sml Tue Sep 28 07:28:10 2010 +0200 @@ -0,0 +1,219 @@ +(* Title: tests on ProgLang/termC.sml + Author: Walther Neuper 051006, + (c) due to copyright terms +*) +"--------------------------------------------------------"; +"table of contents --------------------------------------"; +"--------------------------------------------------------"; +"----------- inst_bdv -----------------------------------"; +"----------- subst_atomic_all ---------------------------"; +"----------- Pattern.match ------------------------------"; +"----------- fun matches --------------------------------"; +"------------parse---------------------------------------"; +"----------- uminus_to_string ---------------------------"; +"--------------------------------------------------------"; +"--------------------------------------------------------"; + + +(*===== inhibit exn ============================================================ +"----------- inst_bdv -----------------------------------"; +"----------- inst_bdv -----------------------------------"; +"----------- inst_bdv -----------------------------------"; +if (term2str o prop_of o num_str) @{thm d1_isolate_add2} = + "~ ?bdv occurs_in ?a ==> (?a + ?bdv = 0) = (?bdv = -1 * ?a)" then () +else raise error "termC.sml d1_isolate_add2"; +val subst = [(str2term "bdv", str2term "x")]; +val t = (norm o #prop o rep_thm) (num_str @{thm d1_isolate_add2}); +val t' = inst_bdv subst t; +if term2str t' = "~ x occurs_in ?a ==> (?a + x = 0) = (x = -1 * ?a)" then () +else raise error "termC.sml inst_bdv 1"; + +if string_of_thm (num_str @{thm separate_bdvs_add}) = + "\"[] from_ [?bdv_1.0, ?bdv_2.0, ?bdv_3.0, ?bdv_4.0] occur_exactly_in ?a\n\ + \ ==> (?a + ?b = ?c) = (?b = ?c + -1 * ?a)\"" then () +else raise error "termC.sml separate_bdvs_add"; +val subst = [(str2term"bdv_1",str2term"c"), + (str2term"bdv_2",str2term"c_2"), + (str2term"bdv_3",str2term"c_3"), + (str2term"bdv_4",str2term"c_4")]; +val t = (norm o #prop o rep_thm) (num_str @{thm separate_bdvs_add}); +val t' = inst_bdv subst t; +if term2str t' = "[] from_ [c, c_2, c_3, c_4] occur_exactly_in ?a\n\ + \==> (?a + ?b = ?c) = (?b = ?c + -1 * ?a)" then () +else raise error "termC.sml inst_bdv 2"; + + +"----------- subst_atomic_all ---------------------------"; +"----------- subst_atomic_all ---------------------------"; +"----------- subst_atomic_all ---------------------------"; +val t = str2term "(tl vs_) from_ vs_ occur_exactly_in (nth_ 1(es_::bool list))"; +val env = [(str2term"vs_::real list",str2term"[c, c_2]"), + (str2term"es_::bool list",str2term"[c_2=0, c+c_2=1]")]; +val (all_Free_subst, t') = subst_atomic_all env t; +if all_Free_subst andalso + term2str t' = "tl [c, c_2] from_ [c, c_2] occur_exactly_in nth_ 1 [c_2 = 0, c + c_2 = 1]" then () +else raise error "termC.sml subst_atomic_all should be 'true'"; + + +val (all_Free_subst, t') = subst_atomic_all (tl env) t; +if not all_Free_subst andalso + term2str t' = "tl vs_ from_ vs_ occur_exactly_in nth_ 1 [c_2 = 0, c + c_2 = 1]" then () +else raise error "termC.sml subst_atomic_all should be 'false'"; +===== inhibit exn ============================================================*) + + +"----------- Pattern.match ------------------------------"; +"----------- Pattern.match ------------------------------"; +"----------- Pattern.match ------------------------------"; +(*===== inhibit exn ============================================================ +val t = (term_of o the o (parse thy)) "3 * x^^^2 = 1"; +val pat = (free2var o term_of o the o (parse thy)) "a * b^^^2 = c"; +(* !^^^^^^^^!... necessary for Pattern.match*) +val insts = Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t); +(*val insts = + ([], + [(("c",0),Free ("1","RealDef.real")),(("b",0),Free ("x","RealDef.real")), + (("a",0),Free ("3","RealDef.real"))]) + : (indexname * typ) list * (indexname * term) list*) + +"----- throws exn MATCH..."; +val t = str2term "x"; +(Pattern.match (Sign.tsig_of (sign_of thy)) (pat, t)) +handle MATCH => ([(* (Term.indexname * Term.typ) *)], + [(* (Term.indexname * Term.term) *)]); +Pattern.MATCH; + +val thy = @{theory "Complex_Main"}; +val PARSE = Syntax.read_term_global thy; +val (pa, tm) = (PARSE "a + b::real", PARSE "x + 2*z::real"); +"-------"; +val (tye, tme) = + (Vartab.empty : Type.tyenv, Vartab.empty : Envir.tenv); +"-------"; +val (tye, tme) = Pattern.match thy (Logic.varify_global pa, tm) (Vartab.empty, + Vartab.empty); +"-------"; +val (tyenv, tenv) = Pattern.match thy (Logic.varify_global pa, tm) + (Vartab.empty, Vartab.empty); +Vartab.dest tenv; +match thy tm (Logic.varify pa); +===== inhibit exn ============================================================*) + +"----------- fun matches --------------------------------"; +"----------- fun matches --------------------------------"; +"----------- fun matches --------------------------------"; +(*test/../Knowledge/polyeq.sml: + Where=[Correct "matches (?a = 0) (-8 - 2 * x + x ^^^ 2 = 0)"*) +(*test/../Interpret/ptyps.sml: + |\nmatches (?a + ?b * x = #0) ((x + #1) * (x + #2) = x ^^^ #2 + #8)"],*) +val thy = @{theory "Complex_Main"}; + +"----- test 1: OK"; +val pa = Logic.varify_global @{term "a = (0::real)"}; (*<<<<<<<---------------*) +tracing "paIsa=..."; atomty pa; tracing "...=paIsa"; +(*** +*** Const (op =, real => real => bool) +*** . Var ((a, 0), real) +*** . Const (Groups.zero_class.zero, real) +***) +"----- test 1a true"; +val tm = @{term "-8 - 2 * x + x ^ 2 = (0::real)"}; (*<<<<<<<---------------*) +if matches thy tm pa then () + else error "termC.sml diff.behav. in matches true 1"; +"----- test 1b false"; +val tm = @{term "-8 - 2 * x + x ^ 2 = (3::real)"}; (*<<<<<<<---------------*) +if matches thy tm pa then error "termC.sml diff.behav. in matches false 1" + else (); + +"----- test 2: Nok"; +val pa = Logic.varify_global (str2term "a = (0::real)");(*<<<<<<<-------------*) +tracing "paLo2=..."; atomty pa; tracing "...=paLo2"; +(*** +*** Const (op =, real => real => bool) +*** . Var ((a, 0), real) +*** . Var ((0, 0), real) +***) +"----- test 2a true"; +val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)"; (*<<<<<<<-------------*) +if matches thy tm pa then () + else error "termC.sml diff.behav. in matches true 2"; +"----- test 2b false"; +val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)"; (*<<<<<<<-------------*) +if matches thy tm pa then () + else error "termC.sml diff.behav. in matches false 2"; +(* i.e. !!!!!!!!!!!!!!!!! THIS KIND OF PATTERN IS NOT RELIABLE !!!!!!!!!!!!!!!!! +if matches thy tm pa then error "termC.sml diff.behav. in matches false 2" + else ();*) + +"----- test 3: OK"; +val pa = free2var (str2term "a = (0::real)");(*<<<<<<<-------------*) +tracing "paF2=..."; atomty pa; tracing "...=paF2"; +(*** +*** Const (op =, real => real => bool) +*** . Var ((a, 0), real) +*** . Free (0, real) +***) +"----- test 3a true"; +val tm = str2term "-8 - 2 * x + x ^ 2 = (0::real)"; (*<<<<<<<-------------*) +if matches thy tm pa then () + else error "termC.sml diff.behav. in matches true 3"; +"----- test 3b false"; +val tm = str2term "-8 - 2 * x + x ^ 2 = (3::real)"; (*<<<<<<<-------------*) +if matches thy tm pa then error "termC.sml diff.behav. in matches false 3" + else (); + +"----- test 4=3 with specific data"; +val pa = free2var (str2term "M_b 0"); +"----- test 4a true"; +val tm = str2term "M_b 0"; +if matches thy tm pa then () + else error "termC.sml diff.behav. in matches true 4"; +"----- test 4b false"; +val tm = str2term "M_b x"; +if matches thy tm pa then error "termC.sml diff.behav. in matches false 4" + else (); + + +"------------parse---------------------------------------"; +"------------parse---------------------------------------"; +"------------parse---------------------------------------"; +Toplevel.debug := true; +(* literal types: +PolyML.addPrettyPrinter + (fn _ => fn _ => ml_pretty o Pretty.to_ML o raw_pp_typ); +*)(* pretty types: +PolyML.addPrettyPrinter + (fn _ => fn _ => ml_pretty o Pretty.to_ML o Proof_Display.pp_typ Pure.thy); +print_depth 99; +*) +val thy = @{theory "Complex_Main"}; +val str = "x + z"; +parse thy str; +"---------------"; +val str = "x + 2*z"; +val t = (Syntax.read_term_global thy str); +val t = numbers_to_string (Syntax.read_term_global thy str); +val t = (typ_a2real o numbers_to_string) (Syntax.read_term_global thy str); +cterm_of thy t; +val t = (the (parse thy str)) handle _ => error "termC.sml parsing 'x + 2*z' failed"; + +(*Makarius.1003 +ML {* @{term "2::int"} *} + +term "(1.24444) :: real" + +ML {* numbers_to_string @{term "%x. (-9993::int) + x + 1"} *} +*) + + +"----------- uminus_to_string ---------------------------"; +"----------- uminus_to_string ---------------------------"; +"----------- uminus_to_string ---------------------------"; +val t1 = numbers_to_string @{term "-2::real"}; +val t2 = numbers_to_string @{term "- 2::real"}; +if uminus_to_string t2 = t1 then () +else error "termC.sml diff.behav. in uminus_to_string"; + + +(*-.-.-.-.-.-isolate response.-.-.-.-.-.-. +-.-.-.-.-.-.-isolate response.-.-.-.-.-.*) diff -r 20231cdf39e7 -r 67a110289e4e test/Tools/isac/Test_Isac.thy --- a/test/Tools/isac/Test_Isac.thy Mon Sep 27 13:35:06 2010 +0200 +++ b/test/Tools/isac/Test_Isac.thy Tue Sep 28 07:28:10 2010 +0200 @@ -55,7 +55,7 @@ use"ProgLang/rewrite.sml"; (*part.*) (* use"scrtools.sml"; - use"term.sml"; + use"termC.sml"; use"tools.sml"; cd "../.."; cd"smltest/ME";