| author | haftmann | 
| Thu, 25 Jun 2015 15:01:43 +0200 | |
| changeset 60572 | 718b1ba06429 | 
| parent 59787 | 6e2a20486897 | 
| child 60826 | 695cf1fab6cc | 
| permissions | -rw-r--r-- | 
| 13402 | 1 | (* Title: Pure/Proof/extraction.ML | 
| 2 | Author: Stefan Berghofer, TU Muenchen | |
| 3 | ||
| 4 | Extraction of programs from proofs. | |
| 5 | *) | |
| 6 | ||
| 7 | signature EXTRACTION = | |
| 8 | sig | |
| 16458 | 9 | val set_preprocessor : (theory -> Proofterm.proof -> Proofterm.proof) -> theory -> theory | 
| 13402 | 10 | val add_realizes_eqns_i : ((term * term) list * (term * term)) list -> theory -> theory | 
| 11 | val add_realizes_eqns : string list -> theory -> theory | |
| 12 | val add_typeof_eqns_i : ((term * term) list * (term * term)) list -> theory -> theory | |
| 13 | val add_typeof_eqns : string list -> theory -> theory | |
| 14 | val add_realizers_i : (string * (string list * term * Proofterm.proof)) list | |
| 15 | -> theory -> theory | |
| 16 | val add_realizers : (thm * (string list * string * string)) list | |
| 17 | -> theory -> theory | |
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 18 | val add_expand_thm : bool -> thm -> theory -> theory | 
| 13732 | 19 | val add_types : (xstring * ((term -> term option) list * | 
| 20 | (term -> typ -> term -> typ -> term) option)) list -> theory -> theory | |
| 21 | val extract : (thm * string list) list -> theory -> theory | |
| 13402 | 22 | val nullT : typ | 
| 23 | val nullt : term | |
| 13714 | 24 | val mk_typ : typ -> term | 
| 25 | val etype_of : theory -> string list -> typ list -> term -> typ | |
| 26 | val realizes_of: theory -> string list -> term -> term -> term | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 27 | val abs_corr_shyps: theory -> thm -> string list -> term list -> Proofterm.proof -> Proofterm.proof | 
| 13402 | 28 | end; | 
| 29 | ||
| 30 | structure Extraction : EXTRACTION = | |
| 31 | struct | |
| 32 | ||
| 33 | (**** tools ****) | |
| 34 | ||
| 42407 
5b9dd52f5dca
prefer internal types, via Simple_Syntax.read_typ;
 wenzelm parents: 
42406diff
changeset | 35 | val typ = Simple_Syntax.read_typ; | 
| 
5b9dd52f5dca
prefer internal types, via Simple_Syntax.read_typ;
 wenzelm parents: 
42406diff
changeset | 36 | |
| 
5b9dd52f5dca
prefer internal types, via Simple_Syntax.read_typ;
 wenzelm parents: 
42406diff
changeset | 37 | val add_syntax = | 
| 52788 | 38 | Sign.root_path | 
| 56436 | 39 | #> Sign.add_types_global | 
| 40 |     [(Binding.make ("Type", @{here}), 0, NoSyn),
 | |
| 41 |      (Binding.make ("Null", @{here}), 0, NoSyn)]
 | |
| 56239 | 42 | #> Sign.add_consts | 
| 56436 | 43 |     [(Binding.make ("typeof", @{here}), typ "'b => Type", NoSyn),
 | 
| 44 |      (Binding.make ("Type", @{here}), typ "'a itself => Type", NoSyn),
 | |
| 45 |      (Binding.make ("Null", @{here}), typ "Null", NoSyn),
 | |
| 46 |      (Binding.make ("realizes", @{here}), typ "'a => 'b => 'b", NoSyn)];
 | |
| 13402 | 47 | |
| 48 | val nullT = Type ("Null", []);
 | |
| 49 | val nullt = Const ("Null", nullT);
 | |
| 50 | ||
| 51 | fun mk_typ T = | |
| 19391 | 52 |   Const ("Type", Term.itselfT T --> Type ("Type", [])) $ Logic.mk_type T;
 | 
| 13402 | 53 | |
| 54 | fun typeof_proc defaultS vs (Const ("typeof", _) $ u) =
 | |
| 15531 | 55 | SOME (mk_typ (case strip_comb u of | 
| 13402 | 56 | (Var ((a, i), _), _) => | 
| 20664 | 57 |             if member (op =) vs a then TFree ("'" ^ a ^ ":" ^ string_of_int i, defaultS)
 | 
| 13402 | 58 | else nullT | 
| 59 | | (Free (a, _), _) => | |
| 20664 | 60 |             if member (op =) vs a then TFree ("'" ^ a, defaultS) else nullT
 | 
| 13402 | 61 | | _ => nullT)) | 
| 15531 | 62 | | typeof_proc _ _ _ = NONE; | 
| 13402 | 63 | |
| 49960 | 64 | fun rlz_proc (Const ("realizes", Type (_, [Type ("Null", []), _])) $ _ $ t) = SOME t
 | 
| 13732 | 65 |   | rlz_proc (Const ("realizes", Type (_, [T, _])) $ r $ t) =
 | 
| 66 | (case strip_comb t of | |
| 15531 | 67 | (Var (ixn, U), ts) => SOME (list_comb (Var (ixn, T --> U), r :: ts)) | 
| 68 | | (Free (s, U), ts) => SOME (list_comb (Free (s, T --> U), r :: ts)) | |
| 69 | | _ => NONE) | |
| 70 | | rlz_proc _ = NONE; | |
| 13402 | 71 | |
| 72 | val unpack_ixn = apfst implode o apsnd (fst o read_int o tl) o | |
| 40627 
becf5d5187cc
renamed raw "explode" function to "raw_explode" to emphasize its meaning;
 wenzelm parents: 
40132diff
changeset | 73 | take_prefix (fn s => s <> ":") o raw_explode; | 
| 13402 | 74 | |
| 75 | type rules = | |
| 76 |   {next: int, rs: ((term * term) list * (term * term)) list,
 | |
| 77 | net: (int * ((term * term) list * (term * term))) Net.net}; | |
| 78 | ||
| 79 | val empty_rules : rules = {next = 0, rs = [], net = Net.empty};
 | |
| 80 | ||
| 33337 | 81 | fun add_rule (r as (_, (lhs, _))) ({next, rs, net} : rules) =
 | 
| 16800 | 82 |   {next = next - 1, rs = r :: rs, net = Net.insert_term (K false)
 | 
| 18956 | 83 | (Envir.eta_contract lhs, (next, r)) net}; | 
| 13402 | 84 | |
| 32784 | 85 | fun merge_rules ({next, rs = rs1, net} : rules) ({rs = rs2, ...} : rules) =
 | 
| 33337 | 86 |   fold_rev add_rule (subtract (op =) rs1 rs2) {next = next, rs = rs1, net = net};
 | 
| 13402 | 87 | |
| 16458 | 88 | fun condrew thy rules procs = | 
| 13402 | 89 | let | 
| 90 | fun rew tm = | |
| 17203 | 91 | Pattern.rewrite_term thy [] (condrew' :: procs) tm | 
| 15399 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 92 | and condrew' tm = | 
| 13402 | 93 | let | 
| 32738 | 94 | val cache = Unsynchronized.ref ([] : (term * term) list); | 
| 17232 | 95 | fun lookup f x = (case AList.lookup (op =) (!cache) x of | 
| 15531 | 96 | NONE => | 
| 15399 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 97 | let val y = f x | 
| 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 98 | in (cache := (x, y) :: !cache; y) end | 
| 15531 | 99 | | SOME y => y); | 
| 15399 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 100 | in | 
| 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 101 | get_first (fn (_, (prems, (tm1, tm2))) => | 
| 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 102 | let | 
| 19466 | 103 | fun ren t = the_default t (Term.rename_abs tm1 tm t); | 
| 59787 | 104 | val inc = Logic.incr_indexes ([], [], maxidx_of_term tm + 1); | 
| 18184 | 105 | val env as (Tenv, tenv) = Pattern.match thy (inc tm1, tm) (Vartab.empty, Vartab.empty); | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58950diff
changeset | 106 | val prems' = map (apply2 (Envir.subst_term env o inc o ren)) prems; | 
| 15399 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 107 | val env' = Envir.Envir | 
| 32032 | 108 |             {maxidx = fold (fn (t, u) => Term.maxidx_term t #> Term.maxidx_term u) prems' ~1,
 | 
| 109 | tenv = tenv, tyenv = Tenv}; | |
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58950diff
changeset | 110 | val env'' = fold (Pattern.unify (Context.Theory thy) o apply2 (lookup rew)) prems' env'; | 
| 15531 | 111 | in SOME (Envir.norm_term env'' (inc (ren tm2))) | 
| 112 | end handle Pattern.MATCH => NONE | Pattern.Unif => NONE) | |
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58950diff
changeset | 113 | (sort (int_ord o apply2 fst) | 
| 18956 | 114 | (Net.match_term rules (Envir.eta_contract tm))) | 
| 15399 
683d83051d6a
Added term cache to function condrew in order to speed up rewriting.
 berghofe parents: 
14981diff
changeset | 115 | end; | 
| 13402 | 116 | |
| 117 | in rew end; | |
| 118 | ||
| 37310 | 119 | val chtype = Proofterm.change_type o SOME; | 
| 13402 | 120 | |
| 30364 
577edc39b501
moved basic algebra of long names from structure NameSpace to Long_Name;
 wenzelm parents: 
30344diff
changeset | 121 | fun extr_name s vs = Long_Name.append "extr" (space_implode "_" (s :: vs)); | 
| 16195 | 122 | fun corr_name s vs = extr_name s vs ^ "_correctness"; | 
| 13402 | 123 | |
| 58843 | 124 | fun msg d s = writeln (Pretty.spaces d ^ s); | 
| 13402 | 125 | |
| 28812 
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
 berghofe parents: 
28805diff
changeset | 126 | fun vars_of t = map Var (rev (Term.add_vars t [])); | 
| 
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
 berghofe parents: 
28805diff
changeset | 127 | fun frees_of t = map Free (rev (Term.add_frees t [])); | 
| 
413695e07bd4
Frees in PThms are now quantified in the order of their appearance in the
 berghofe parents: 
28805diff
changeset | 128 | fun vfs_of t = vars_of t @ frees_of t; | 
| 13402 | 129 | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 130 | val mkabs = fold_rev (fn v => fn t => Abs ("x", fastype_of v, abstract_over (v, t)));
 | 
| 13402 | 131 | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 132 | val mkabsp = fold_rev (fn t => fn prf => AbsP ("H", SOME t, prf));
 | 
| 13402 | 133 | |
| 13732 | 134 | fun strip_abs 0 t = t | 
| 135 | | strip_abs n (Abs (_, _, t)) = strip_abs (n-1) t | |
| 136 | | strip_abs _ _ = error "strip_abs: not an abstraction"; | |
| 137 | ||
| 37310 | 138 | val prf_subst_TVars = Proofterm.map_proof_types o typ_subst_TVars; | 
| 13402 | 139 | |
| 40844 | 140 | fun relevant_vars types prop = | 
| 141 | List.foldr | |
| 142 | (fn (Var ((a, _), T), vs) => | |
| 143 | (case body_type T of | |
| 144 | Type (s, _) => if member (op =) types s then a :: vs else vs | |
| 145 | | _ => vs) | |
| 146 | | (_, vs) => vs) [] (vars_of prop); | |
| 13402 | 147 | |
| 13732 | 148 | fun tname_of (Type (s, _)) = s | 
| 149 | | tname_of _ = ""; | |
| 150 | ||
| 151 | fun get_var_type t = | |
| 152 | let | |
| 16865 | 153 | val vs = Term.add_vars t []; | 
| 154 | val fs = Term.add_frees t []; | |
| 42406 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 155 | in | 
| 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 156 | fn Var (ixn, _) => | 
| 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 157 | (case AList.lookup (op =) vs ixn of | 
| 15531 | 158 | NONE => error "get_var_type: no such variable in term" | 
| 159 | | SOME T => Var (ixn, T)) | |
| 42406 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 160 | | Free (s, _) => | 
| 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 161 | (case AList.lookup (op =) fs s of | 
| 15531 | 162 | NONE => error "get_var_type: no such variable in term" | 
| 163 | | SOME T => Free (s, T)) | |
| 13732 | 164 | | _ => error "get_var_type: not a variable" | 
| 165 | end; | |
| 166 | ||
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 167 | fun read_term thy T s = | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 168 | let | 
| 42360 | 169 | val ctxt = Proof_Context.init_global thy | 
| 42406 
05f2468d6b36
eliminated obsolete Proof_Syntax.strip_sorts_consttypes;
 wenzelm parents: 
42375diff
changeset | 170 | |> Config.put Type_Infer_Context.const_sorts false | 
| 42360 | 171 | |> Proof_Context.set_defsort []; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 172 | val parse = if T = propT then Syntax.parse_prop else Syntax.parse_term; | 
| 39288 | 173 | in parse ctxt s |> Type.constraint T |> Syntax.check_term ctxt end; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 174 | |
| 13402 | 175 | |
| 176 | (**** theory data ****) | |
| 177 | ||
| 22846 | 178 | (* theory data *) | 
| 13402 | 179 | |
| 33522 | 180 | structure ExtractionData = Theory_Data | 
| 22846 | 181 | ( | 
| 13402 | 182 | type T = | 
| 183 |     {realizes_eqns : rules,
 | |
| 184 | typeof_eqns : rules, | |
| 13732 | 185 | types : (string * ((term -> term option) list * | 
| 186 | (term -> typ -> term -> typ -> term) option)) list, | |
| 13402 | 187 | realizers : (string list * (term * proof)) list Symtab.table, | 
| 188 | defs : thm list, | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 189 | expand : string list, | 
| 16458 | 190 | prep : (theory -> proof -> proof) option} | 
| 13402 | 191 | |
| 192 | val empty = | |
| 193 |     {realizes_eqns = empty_rules,
 | |
| 194 | typeof_eqns = empty_rules, | |
| 195 | types = [], | |
| 196 | realizers = Symtab.empty, | |
| 197 | defs = [], | |
| 198 | expand = [], | |
| 15531 | 199 | prep = NONE}; | 
| 16458 | 200 | val extend = I; | 
| 13402 | 201 | |
| 33522 | 202 | fun merge | 
| 203 |     ({realizes_eqns = realizes_eqns1, typeof_eqns = typeof_eqns1, types = types1,
 | |
| 13402 | 204 | realizers = realizers1, defs = defs1, expand = expand1, prep = prep1}, | 
| 205 |       {realizes_eqns = realizes_eqns2, typeof_eqns = typeof_eqns2, types = types2,
 | |
| 33522 | 206 | realizers = realizers2, defs = defs2, expand = expand2, prep = prep2}) : T = | 
| 13402 | 207 |     {realizes_eqns = merge_rules realizes_eqns1 realizes_eqns2,
 | 
| 208 | typeof_eqns = merge_rules typeof_eqns1 typeof_eqns2, | |
| 22717 | 209 | types = AList.merge (op =) (K true) (types1, types2), | 
| 59058 
a78612c67ec0
renamed "pairself" to "apply2", in accordance to @{apply 2};
 wenzelm parents: 
58950diff
changeset | 210 | realizers = Symtab.merge_list (eq_set (op =) o apply2 #1) (realizers1, realizers2), | 
| 22662 | 211 | defs = Library.merge Thm.eq_thm (defs1, defs2), | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 212 | expand = Library.merge (op =) (expand1, expand2), | 
| 38761 | 213 | prep = if is_some prep1 then prep1 else prep2}; | 
| 22846 | 214 | ); | 
| 13402 | 215 | |
| 216 | fun read_condeq thy = | |
| 16458 | 217 | let val thy' = add_syntax thy | 
| 13402 | 218 | in fn s => | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 219 | let val t = Logic.varify_global (read_term thy' propT s) | 
| 35424 | 220 | in | 
| 221 | (map Logic.dest_equals (Logic.strip_imp_prems t), | |
| 222 | Logic.dest_equals (Logic.strip_imp_concl t)) | |
| 223 |       handle TERM _ => error ("Not a (conditional) meta equality:\n" ^ s)
 | |
| 224 | end | |
| 13402 | 225 | end; | 
| 226 | ||
| 227 | (** preprocessor **) | |
| 228 | ||
| 229 | fun set_preprocessor prep thy = | |
| 230 |   let val {realizes_eqns, typeof_eqns, types, realizers,
 | |
| 231 | defs, expand, ...} = ExtractionData.get thy | |
| 232 | in | |
| 233 | ExtractionData.put | |
| 234 |       {realizes_eqns = realizes_eqns, typeof_eqns = typeof_eqns, types = types,
 | |
| 15531 | 235 | realizers = realizers, defs = defs, expand = expand, prep = SOME prep} thy | 
| 13402 | 236 | end; | 
| 237 | ||
| 238 | (** equations characterizing realizability **) | |
| 239 | ||
| 240 | fun gen_add_realizes_eqns prep_eq eqns thy = | |
| 241 |   let val {realizes_eqns, typeof_eqns, types, realizers,
 | |
| 242 | defs, expand, prep} = ExtractionData.get thy; | |
| 243 | in | |
| 244 | ExtractionData.put | |
| 33337 | 245 |       {realizes_eqns = fold_rev add_rule (map (prep_eq thy) eqns) realizes_eqns,
 | 
| 13402 | 246 | typeof_eqns = typeof_eqns, types = types, realizers = realizers, | 
| 247 | defs = defs, expand = expand, prep = prep} thy | |
| 248 | end | |
| 249 | ||
| 250 | val add_realizes_eqns_i = gen_add_realizes_eqns (K I); | |
| 251 | val add_realizes_eqns = gen_add_realizes_eqns read_condeq; | |
| 252 | ||
| 253 | (** equations characterizing type of extracted program **) | |
| 254 | ||
| 255 | fun gen_add_typeof_eqns prep_eq eqns thy = | |
| 256 | let | |
| 257 |     val {realizes_eqns, typeof_eqns, types, realizers,
 | |
| 258 | defs, expand, prep} = ExtractionData.get thy; | |
| 13732 | 259 | val eqns' = map (prep_eq thy) eqns | 
| 13402 | 260 | in | 
| 261 | ExtractionData.put | |
| 262 |       {realizes_eqns = realizes_eqns, realizers = realizers,
 | |
| 33337 | 263 | typeof_eqns = fold_rev add_rule eqns' typeof_eqns, | 
| 13732 | 264 | types = types, defs = defs, expand = expand, prep = prep} thy | 
| 13402 | 265 | end | 
| 266 | ||
| 267 | val add_typeof_eqns_i = gen_add_typeof_eqns (K I); | |
| 268 | val add_typeof_eqns = gen_add_typeof_eqns read_condeq; | |
| 269 | ||
| 270 | fun thaw (T as TFree (a, S)) = | |
| 28375 | 271 | if exists_string (fn s => s = ":") a then TVar (unpack_ixn a, S) else T | 
| 13402 | 272 | | thaw (Type (a, Ts)) = Type (a, map thaw Ts) | 
| 273 | | thaw T = T; | |
| 274 | ||
| 275 | fun freeze (TVar ((a, i), S)) = TFree (a ^ ":" ^ string_of_int i, S) | |
| 276 | | freeze (Type (a, Ts)) = Type (a, map freeze Ts) | |
| 277 | | freeze T = T; | |
| 278 | ||
| 279 | fun freeze_thaw f x = | |
| 20548 
8ef25fe585a8
renamed Term.map_term_types to Term.map_types (cf. Term.fold_types);
 wenzelm parents: 
19482diff
changeset | 280 | map_types thaw (f (map_types freeze x)); | 
| 13402 | 281 | |
| 16458 | 282 | fun etype_of thy vs Ts t = | 
| 13402 | 283 | let | 
| 16458 | 284 |     val {typeof_eqns, ...} = ExtractionData.get thy;
 | 
| 13402 | 285 |     fun err () = error ("Unable to determine type of extracted program for\n" ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26653diff
changeset | 286 | Syntax.string_of_term_global thy t) | 
| 46219 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 287 | in | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 288 | (case | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 289 | strip_abs_body | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 290 | (freeze_thaw (condrew thy (#net typeof_eqns) [typeof_proc [] vs]) | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 291 | (fold (Term.abs o pair "x") Ts | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 292 |             (Const ("typeof", fastype_of1 (Ts, t) --> Type ("Type", [])) $ t))) of
 | 
| 13402 | 293 |       Const ("Type", _) $ u => (Logic.dest_type u handle TERM _ => err ())
 | 
| 46219 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 294 | | _ => err ()) | 
| 13402 | 295 | end; | 
| 296 | ||
| 297 | (** realizers for axioms / theorems, together with correctness proofs **) | |
| 298 | ||
| 299 | fun gen_add_realizers prep_rlz rs thy = | |
| 300 |   let val {realizes_eqns, typeof_eqns, types, realizers,
 | |
| 301 | defs, expand, prep} = ExtractionData.get thy | |
| 302 | in | |
| 303 | ExtractionData.put | |
| 304 |       {realizes_eqns = realizes_eqns, typeof_eqns = typeof_eqns, types = types,
 | |
| 25389 | 305 | realizers = fold (Symtab.cons_list o prep_rlz thy) rs realizers, | 
| 13402 | 306 | defs = defs, expand = expand, prep = prep} thy | 
| 307 | end | |
| 308 | ||
| 309 | fun prep_realizer thy = | |
| 310 | let | |
| 13732 | 311 |     val {realizes_eqns, typeof_eqns, defs, types, ...} =
 | 
| 13402 | 312 | ExtractionData.get thy; | 
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19466diff
changeset | 313 | val procs = maps (fst o snd) types; | 
| 13732 | 314 | val rtypes = map fst types; | 
| 16800 | 315 | val eqns = Net.merge (K false) (#net realizes_eqns, #net typeof_eqns); | 
| 13402 | 316 | val thy' = add_syntax thy; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 317 | val rd = Proof_Syntax.read_proof thy' true false; | 
| 13402 | 318 | in fn (thm, (vs, s1, s2)) => | 
| 319 | let | |
| 36744 
6e1f3d609a68
renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
 wenzelm parents: 
36620diff
changeset | 320 | val name = Thm.derivation_name thm; | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21646diff
changeset | 321 | val _ = name <> "" orelse error "add_realizers: unnamed theorem"; | 
| 59582 | 322 | val prop = Thm.unconstrainT thm |> Thm.prop_of |> | 
| 323 | Pattern.rewrite_term thy' (map (Logic.dest_equals o Thm.prop_of) defs) []; | |
| 13402 | 324 | val vars = vars_of prop; | 
| 13732 | 325 | val vars' = filter_out (fn v => | 
| 20664 | 326 | member (op =) rtypes (tname_of (body_type (fastype_of v)))) vars; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 327 | val shyps = maps (fn Var ((x, i), _) => | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 328 | if member (op =) vs x then Logic.mk_of_sort | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 329 |           (TVar (("'" ^ x, i), []), Sign.defaultS thy')
 | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 330 | else []) vars; | 
| 16458 | 331 | val T = etype_of thy' vs [] prop; | 
| 33832 | 332 | val (T', thw) = Type.legacy_freeze_thaw_type | 
| 13732 | 333 | (if T = nullT then nullT else map fastype_of vars' ---> T); | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 334 | val t = map_types thw (read_term thy' T' s1); | 
| 16458 | 335 | val r' = freeze_thaw (condrew thy' eqns | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 336 | (procs @ [typeof_proc [] vs, rlz_proc])) | 
| 13402 | 337 |           (Const ("realizes", T --> propT --> propT) $
 | 
| 13732 | 338 | (if T = nullT then t else list_comb (t, vars')) $ prop); | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 339 | val r = Logic.list_implies (shyps, | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 340 | fold_rev Logic.all (map (get_var_type r') vars) r'); | 
| 16458 | 341 | val prf = Reconstruct.reconstruct_proof thy' r (rd s2); | 
| 13402 | 342 | in (name, (vs, (t, prf))) end | 
| 343 | end; | |
| 344 | ||
| 345 | val add_realizers_i = gen_add_realizers | |
| 346 | (fn _ => fn (name, (vs, t, prf)) => (name, (vs, (t, prf)))); | |
| 347 | val add_realizers = gen_add_realizers prep_realizer; | |
| 348 | ||
| 13714 | 349 | fun realizes_of thy vs t prop = | 
| 350 | let | |
| 351 | val thy' = add_syntax thy; | |
| 13732 | 352 |     val {realizes_eqns, typeof_eqns, defs, types, ...} =
 | 
| 13714 | 353 | ExtractionData.get thy'; | 
| 22717 | 354 | val procs = maps (rev o fst o snd) types; | 
| 16800 | 355 | val eqns = Net.merge (K false) (#net realizes_eqns, #net typeof_eqns); | 
| 17203 | 356 | val prop' = Pattern.rewrite_term thy' | 
| 59582 | 357 | (map (Logic.dest_equals o Thm.prop_of) defs) [] prop; | 
| 16458 | 358 | in freeze_thaw (condrew thy' eqns | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 359 | (procs @ [typeof_proc [] vs, rlz_proc])) | 
| 13714 | 360 |       (Const ("realizes", fastype_of t --> propT --> propT) $ t $ prop')
 | 
| 361 | end; | |
| 362 | ||
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 363 | fun abs_corr_shyps thy thm vs xs prf = | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 364 | let | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 365 | val S = Sign.defaultS thy; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 366 | val ((atyp_map, constraints, _), prop') = | 
| 59582 | 367 | Logic.unconstrainT (#shyps (Thm.rep_thm thm)) (Thm.prop_of thm); | 
| 368 | val atyps = fold_types (fold_atyps (insert (op =))) (Thm.prop_of thm) []; | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 369 | val Ts = map_filter (fn ((v, i), _) => if member (op =) vs v then | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 370 |         SOME (TVar (("'" ^ v, i), [])) else NONE)
 | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 371 | (rev (Term.add_vars prop' [])); | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 372 | val cs = maps (fn T => map (pair T) S) Ts; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 373 | val constraints' = map Logic.mk_of_class cs; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 374 | fun typ_map T = Type.strip_sorts | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 375 | (map_atyps (fn U => if member (op =) atyps U then atyp_map U else U) T); | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 376 | fun mk_hyp (T, c) = Hyp (Logic.mk_of_class (typ_map T, c)); | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 377 | val xs' = map (map_types typ_map) xs | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 378 | in | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 379 | prf |> | 
| 37310 | 380 | Same.commit (Proofterm.map_proof_same (map_types typ_map) typ_map mk_hyp) |> | 
| 381 | fold_rev Proofterm.implies_intr_proof' (map snd constraints) |> | |
| 382 | fold_rev Proofterm.forall_intr_proof' xs' |> | |
| 383 | fold_rev Proofterm.implies_intr_proof' constraints' | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 384 | end; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 385 | |
| 13402 | 386 | (** expanding theorems / definitions **) | 
| 387 | ||
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 388 | fun add_expand_thm is_def thm thy = | 
| 13402 | 389 | let | 
| 390 |     val {realizes_eqns, typeof_eqns, types, realizers,
 | |
| 391 | defs, expand, prep} = ExtractionData.get thy; | |
| 392 | ||
| 36744 
6e1f3d609a68
renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
 wenzelm parents: 
36620diff
changeset | 393 | val name = Thm.derivation_name thm; | 
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 394 | val _ = name <> "" orelse error "add_expand_thm: unnamed theorem"; | 
| 13402 | 395 | in | 
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 396 | thy |> ExtractionData.put | 
| 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 397 | (if is_def then | 
| 13402 | 398 |         {realizes_eqns = realizes_eqns,
 | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 399 | typeof_eqns = add_rule ([], Logic.dest_equals (map_types | 
| 59582 | 400 | Type.strip_sorts (Thm.prop_of (Drule.abs_def thm)))) typeof_eqns, | 
| 13402 | 401 | types = types, | 
| 22360 
26ead7ed4f4b
moved eq_thm etc. to structure Thm in Pure/more_thm.ML;
 wenzelm parents: 
21858diff
changeset | 402 | realizers = realizers, defs = insert Thm.eq_thm thm defs, | 
| 13402 | 403 | expand = expand, prep = prep} | 
| 404 | else | |
| 405 |         {realizes_eqns = realizes_eqns, typeof_eqns = typeof_eqns, types = types,
 | |
| 406 | realizers = realizers, defs = defs, | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 407 | expand = insert (op =) name expand, prep = prep}) | 
| 13402 | 408 | end; | 
| 409 | ||
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 410 | fun extraction_expand is_def = | 
| 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 411 | Thm.declaration_attribute (fn th => Context.mapping (add_expand_thm is_def th) I); | 
| 13402 | 412 | |
| 15801 | 413 | |
| 13732 | 414 | (** types with computational content **) | 
| 415 | ||
| 416 | fun add_types tys thy = | |
| 22717 | 417 | ExtractionData.map | 
| 418 |     (fn {realizes_eqns, typeof_eqns, types, realizers, defs, expand, prep} =>
 | |
| 13732 | 419 |       {realizes_eqns = realizes_eqns, typeof_eqns = typeof_eqns,
 | 
| 22717 | 420 | types = fold (AList.update (op =) o apfst (Sign.intern_type thy)) tys types, | 
| 421 | realizers = realizers, defs = defs, expand = expand, prep = prep}) | |
| 422 | thy; | |
| 13732 | 423 | |
| 13402 | 424 | |
| 15801 | 425 | (** Pure setup **) | 
| 426 | ||
| 53171 | 427 | val _ = Theory.setup | 
| 18708 | 428 |   (add_types [("prop", ([], NONE))] #>
 | 
| 15801 | 429 | |
| 430 | add_typeof_eqns | |
| 431 | ["(typeof (PROP P)) == (Type (TYPE(Null))) ==> \ | |
| 432 |     \  (typeof (PROP Q)) == (Type (TYPE('Q))) ==>  \
 | |
| 433 |     \    (typeof (PROP P ==> PROP Q)) == (Type (TYPE('Q)))",
 | |
| 434 | ||
| 435 | "(typeof (PROP Q)) == (Type (TYPE(Null))) ==> \ | |
| 436 | \ (typeof (PROP P ==> PROP Q)) == (Type (TYPE(Null)))", | |
| 437 | ||
| 438 |       "(typeof (PROP P)) == (Type (TYPE('P))) ==>  \
 | |
| 439 |     \  (typeof (PROP Q)) == (Type (TYPE('Q))) ==>  \
 | |
| 440 |     \    (typeof (PROP P ==> PROP Q)) == (Type (TYPE('P => 'Q)))",
 | |
| 441 | ||
| 442 | "(%x. typeof (PROP P (x))) == (%x. Type (TYPE(Null))) ==> \ | |
| 443 | \ (typeof (!!x. PROP P (x))) == (Type (TYPE(Null)))", | |
| 444 | ||
| 445 |       "(%x. typeof (PROP P (x))) == (%x. Type (TYPE('P))) ==>  \
 | |
| 446 |     \    (typeof (!!x::'a. PROP P (x))) == (Type (TYPE('a => 'P)))",
 | |
| 447 | ||
| 448 |       "(%x. typeof (f (x))) == (%x. Type (TYPE('f))) ==>  \
 | |
| 18708 | 449 |     \    (typeof (f)) == (Type (TYPE('f)))"] #>
 | 
| 15801 | 450 | |
| 451 | add_realizes_eqns | |
| 452 | ["(typeof (PROP P)) == (Type (TYPE(Null))) ==> \ | |
| 453 | \ (realizes (r) (PROP P ==> PROP Q)) == \ | |
| 454 | \ (PROP realizes (Null) (PROP P) ==> PROP realizes (r) (PROP Q))", | |
| 455 | ||
| 456 |       "(typeof (PROP P)) == (Type (TYPE('P))) ==>  \
 | |
| 457 | \ (typeof (PROP Q)) == (Type (TYPE(Null))) ==> \ | |
| 458 | \ (realizes (r) (PROP P ==> PROP Q)) == \ | |
| 459 | \ (!!x::'P. PROP realizes (x) (PROP P) ==> PROP realizes (Null) (PROP Q))", | |
| 460 | ||
| 461 | "(realizes (r) (PROP P ==> PROP Q)) == \ | |
| 462 | \ (!!x. PROP realizes (x) (PROP P) ==> PROP realizes (r (x)) (PROP Q))", | |
| 463 | ||
| 464 | "(%x. typeof (PROP P (x))) == (%x. Type (TYPE(Null))) ==> \ | |
| 465 | \ (realizes (r) (!!x. PROP P (x))) == \ | |
| 466 | \ (!!x. PROP realizes (Null) (PROP P (x)))", | |
| 467 | ||
| 468 | "(realizes (r) (!!x. PROP P (x))) == \ | |
| 18708 | 469 | \ (!!x. PROP realizes (r (x)) (PROP P (x)))"] #> | 
| 15801 | 470 | |
| 56206 | 471 |    Attrib.setup @{binding extraction_expand} (Scan.succeed (extraction_expand false))
 | 
| 33704 
6aeb8454efc1
add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
 wenzelm parents: 
33522diff
changeset | 472 | "specify theorems to be expanded during extraction" #> | 
| 56206 | 473 |    Attrib.setup @{binding extraction_expand_def} (Scan.succeed (extraction_expand true))
 | 
| 53171 | 474 | "specify definitions to be expanded during extraction"); | 
| 15801 | 475 | |
| 476 | ||
| 13402 | 477 | (**** extract program ****) | 
| 478 | ||
| 479 | val dummyt = Const ("dummy", dummyT);
 | |
| 480 | ||
| 58436 | 481 | fun extract thm_vss thy = | 
| 13402 | 482 | let | 
| 16458 | 483 | val thy' = add_syntax thy; | 
| 13402 | 484 |     val {realizes_eqns, typeof_eqns, types, realizers, defs, expand, prep} =
 | 
| 485 | ExtractionData.get thy; | |
| 22717 | 486 | val procs = maps (rev o fst o snd) types; | 
| 13732 | 487 | val rtypes = map fst types; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 488 | val typroc = typeof_proc []; | 
| 19466 | 489 | val prep = the_default (K I) prep thy' o ProofRewriteRules.elim_defs thy' false defs o | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 490 |       Reconstruct.expand_proof thy' (map (rpair NONE) ("" :: expand));
 | 
| 16800 | 491 | val rrews = Net.merge (K false) (#net realizes_eqns, #net typeof_eqns); | 
| 13402 | 492 | |
| 493 | fun find_inst prop Ts ts vs = | |
| 494 | let | |
| 13732 | 495 | val rvs = relevant_vars rtypes prop; | 
| 13402 | 496 | val vars = vars_of prop; | 
| 497 | val n = Int.min (length vars, length ts); | |
| 498 | ||
| 33337 | 499 | fun add_args (Var ((a, i), _), t) (vs', tye) = | 
| 20664 | 500 | if member (op =) rvs a then | 
| 16458 | 501 | let val T = etype_of thy' vs Ts t | 
| 13402 | 502 | in if T = nullT then (vs', tye) | 
| 503 |                else (a :: vs', (("'" ^ a, i), T) :: tye)
 | |
| 504 | end | |
| 505 | else (vs', tye) | |
| 506 | ||
| 33957 | 507 | in fold_rev add_args (take n vars ~~ take n ts) ([], []) end; | 
| 13402 | 508 | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 509 | fun mk_shyps tye = maps (fn (ixn, _) => | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 510 | Logic.mk_of_sort (TVar (ixn, []), Sign.defaultS thy)) tye; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 511 | |
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 512 | fun mk_sprfs cs tye = maps (fn (_, T) => | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 513 | ProofRewriteRules.mk_of_sort_proof thy (map SOME cs) | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 514 | (T, Sign.defaultS thy)) tye; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 515 | |
| 33038 | 516 | fun find (vs: string list) = Option.map snd o find_first (curry (eq_set (op =)) vs o fst); | 
| 28375 | 517 | fun find' (s: string) = map_filter (fn (s', x) => if s = s' then SOME x else NONE); | 
| 13402 | 518 | |
| 46219 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 519 | fun app_rlz_rews Ts vs t = | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 520 | strip_abs (length Ts) | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 521 | (freeze_thaw (condrew thy' rrews (procs @ [typroc vs, rlz_proc])) | 
| 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 522 | (fold (Term.abs o pair "x") Ts t)); | 
| 13732 | 523 | |
| 524 | fun realizes_null vs prop = app_rlz_rews [] vs | |
| 525 |       (Const ("realizes", nullT --> propT --> propT) $ nullt $ prop);
 | |
| 13402 | 526 | |
| 49960 | 527 | fun corr d vs ts Ts hs cs _ (PBound i) _ defs = (PBound i, defs) | 
| 13402 | 528 | |
| 49960 | 529 | | corr d vs ts Ts hs cs t (Abst (s, SOME T, prf)) (Abst (_, _, prf')) defs = | 
| 530 | let val (corr_prf, defs') = corr d vs [] (T :: Ts) | |
| 531 | (dummyt :: hs) cs (case t of SOME (Abs (_, _, u)) => SOME u | _ => NONE) | |
| 532 | prf (Proofterm.incr_pboundvars 1 0 prf') defs | |
| 533 | in (Abst (s, SOME T, corr_prf), defs') end | |
| 13402 | 534 | |
| 49960 | 535 | | corr d vs ts Ts hs cs t (AbsP (s, SOME prop, prf)) (AbsP (_, _, prf')) defs = | 
| 13402 | 536 | let | 
| 16458 | 537 | val T = etype_of thy' vs Ts prop; | 
| 42407 
5b9dd52f5dca
prefer internal types, via Simple_Syntax.read_typ;
 wenzelm parents: 
42406diff
changeset | 538 | val u = if T = nullT then | 
| 15531 | 539 | (case t of SOME u => SOME (incr_boundvars 1 u) | NONE => NONE) | 
| 540 | else (case t of SOME (Abs (_, _, u)) => SOME u | _ => NONE); | |
| 49960 | 541 | val (corr_prf, defs') = | 
| 542 | corr d vs [] (T :: Ts) (prop :: hs) | |
| 543 | (prop :: cs) u (Proofterm.incr_pboundvars 0 1 prf) | |
| 544 | (Proofterm.incr_pboundvars 0 1 prf') defs; | |
| 13402 | 545 |             val rlz = Const ("realizes", T --> propT --> propT)
 | 
| 49960 | 546 | in ( | 
| 13732 | 547 |             if T = nullT then AbsP ("R",
 | 
| 15531 | 548 | SOME (app_rlz_rews Ts vs (rlz $ nullt $ prop)), | 
| 37310 | 549 | Proofterm.prf_subst_bounds [nullt] corr_prf) | 
| 15531 | 550 |             else Abst (s, SOME T, AbsP ("R",
 | 
| 551 | SOME (app_rlz_rews (T :: Ts) vs | |
| 49960 | 552 | (rlz $ Bound 0 $ incr_boundvars 1 prop)), corr_prf)), defs') | 
| 13402 | 553 | end | 
| 554 | ||
| 49960 | 555 | | corr d vs ts Ts hs cs t' (prf % SOME t) (prf' % _) defs = | 
| 13732 | 556 | let | 
| 557 | val (Us, T) = strip_type (fastype_of1 (Ts, t)); | |
| 49960 | 558 | val (corr_prf, defs') = corr d vs (t :: ts) Ts hs cs | 
| 20664 | 559 | (if member (op =) rtypes (tname_of T) then t' | 
| 49960 | 560 | else (case t' of SOME (u $ _) => SOME u | _ => NONE)) | 
| 561 | prf prf' defs; | |
| 20664 | 562 | val u = if not (member (op =) rtypes (tname_of T)) then t else | 
| 13732 | 563 | let | 
| 16458 | 564 | val eT = etype_of thy' vs Ts t; | 
| 13732 | 565 | val (r, Us') = if eT = nullT then (nullt, Us) else | 
| 566 | (Bound (length Us), eT :: Us); | |
| 567 | val u = list_comb (incr_boundvars (length Us') t, | |
| 568 | map Bound (length Us - 1 downto 0)); | |
| 17271 | 569 | val u' = (case AList.lookup (op =) types (tname_of T) of | 
| 15531 | 570 | SOME ((_, SOME f)) => f r eT u T | 
| 13732 | 571 |                   | _ => Const ("realizes", eT --> T --> T) $ r $ u)
 | 
| 46219 
426ed18eba43
discontinued old-style Term.list_abs in favour of plain Term.abs;
 wenzelm parents: 
44057diff
changeset | 572 | in app_rlz_rews Ts vs (fold_rev (Term.abs o pair "x") Us' u') end | 
| 49960 | 573 | in (corr_prf % SOME u, defs') end | 
| 13402 | 574 | |
| 49960 | 575 | | corr d vs ts Ts hs cs t (prf1 %% prf2) (prf1' %% prf2') defs = | 
| 13402 | 576 | let | 
| 577 | val prop = Reconstruct.prop_of' hs prf2'; | |
| 16458 | 578 | val T = etype_of thy' vs Ts prop; | 
| 49960 | 579 | val (f, u, defs1) = if T = nullT then (t, NONE, defs) else | 
| 13402 | 580 | (case t of | 
| 49960 | 581 | SOME (f $ u) => (SOME f, SOME u, defs) | 
| 13402 | 582 | | _ => | 
| 49960 | 583 | let val (u, defs1) = extr d vs [] Ts hs prf2' defs | 
| 584 | in (NONE, SOME u, defs1) end) | |
| 585 | val ((corr_prf1, corr_prf2), defs2) = | |
| 586 | defs1 | |
| 587 | |> corr d vs [] Ts hs cs f prf1 prf1' | |
| 588 | ||>> corr d vs [] Ts hs cs u prf2 prf2'; | |
| 13402 | 589 | in | 
| 49960 | 590 | if T = nullT then (corr_prf1 %% corr_prf2, defs2) else | 
| 591 | (corr_prf1 % u %% corr_prf2, defs2) | |
| 13402 | 592 | end | 
| 593 | ||
| 49960 | 594 | | corr d vs ts Ts hs cs _ (prf0 as PThm (_, ((name, prop, SOME Ts'), body))) _ defs = | 
| 13402 | 595 | let | 
| 37310 | 596 | val prf = Proofterm.join_proof body; | 
| 13402 | 597 | val (vs', tye) = find_inst prop Ts ts vs; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 598 | val shyps = mk_shyps tye; | 
| 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 599 | val sprfs = mk_sprfs cs tye; | 
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 600 | val tye' = (map fst (Term.add_tvars prop [] |> rev) ~~ Ts') @ tye; | 
| 16458 | 601 | val T = etype_of thy' vs' [] prop; | 
| 13402 | 602 | val defs' = if T = nullT then defs | 
| 49960 | 603 | else snd (extr d vs ts Ts hs prf0 defs) | 
| 13402 | 604 | in | 
| 49960 | 605 | if T = nullT andalso realizes_null vs' prop aconv prop then (prf0, defs) | 
| 606 | else (case Symtab.lookup realizers name of | |
| 15531 | 607 | NONE => (case find vs' (find' name defs') of | 
| 608 | NONE => | |
| 13402 | 609 | let | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21646diff
changeset | 610 | val _ = T = nullT orelse error "corr: internal error"; | 
| 13402 | 611 |                     val _ = msg d ("Building correctness proof for " ^ quote name ^
 | 
| 612 | (if null vs' then "" | |
| 613 | else " (relevant variables: " ^ commas_quote vs' ^ ")")); | |
| 16458 | 614 | val prf' = prep (Reconstruct.reconstruct_proof thy' prop prf); | 
| 49960 | 615 | val (corr_prf0, defs'') = corr (d + 1) vs' [] [] [] | 
| 616 | (rev shyps) NONE prf' prf' defs'; | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 617 | val corr_prf = mkabsp shyps corr_prf0; | 
| 13732 | 618 | val corr_prop = Reconstruct.prop_of corr_prf; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 619 | val corr_prf' = | 
| 37310 | 620 | Proofterm.proof_combP (Proofterm.proof_combt | 
| 28805 | 621 | (PThm (serial (), | 
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 622 | ((corr_name name vs', corr_prop, SOME (map TVar (Term.add_tvars corr_prop [] |> rev))), | 
| 37310 | 623 | Future.value (Proofterm.approximate_proof_body corr_prf))), | 
| 624 | vfs_of corr_prop), | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 625 | map PBound (length shyps - 1 downto 0)) |> | 
| 37310 | 626 | fold_rev Proofterm.forall_intr_proof' | 
| 627 | (map (get_var_type corr_prop) (vfs_of prop)) |> | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 628 | mkabsp shyps | 
| 13402 | 629 | in | 
| 49960 | 630 | (Proofterm.proof_combP (prf_subst_TVars tye' corr_prf', sprfs), | 
| 631 | (name, (vs', ((nullt, nullt), (corr_prf, corr_prf')))) :: defs'') | |
| 13402 | 632 | end | 
| 37310 | 633 | | SOME (_, (_, prf')) => | 
| 49960 | 634 | (Proofterm.proof_combP (prf_subst_TVars tye' prf', sprfs), defs')) | 
| 15531 | 635 | | SOME rs => (case find vs' rs of | 
| 49960 | 636 | SOME (_, prf') => (Proofterm.proof_combP (prf_subst_TVars tye' prf', sprfs), defs') | 
| 15531 | 637 |               | NONE => error ("corr: no realizer for instance of theorem " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26653diff
changeset | 638 | quote name ^ ":\n" ^ Syntax.string_of_term_global thy' (Envir.beta_norm | 
| 49960 | 639 | (Reconstruct.prop_of (Proofterm.proof_combt (prf0, ts))))))) | 
| 13402 | 640 | end | 
| 641 | ||
| 49960 | 642 | | corr d vs ts Ts hs cs _ (prf0 as PAxm (s, prop, SOME Ts')) _ defs = | 
| 13402 | 643 | let | 
| 644 | val (vs', tye) = find_inst prop Ts ts vs; | |
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 645 | val tye' = (map fst (Term.add_tvars prop [] |> rev) ~~ Ts') @ tye | 
| 13402 | 646 | in | 
| 16458 | 647 | if etype_of thy' vs' [] prop = nullT andalso | 
| 49960 | 648 | realizes_null vs' prop aconv prop then (prf0, defs) | 
| 18956 | 649 | else case find vs' (Symtab.lookup_list realizers s) of | 
| 49960 | 650 | SOME (_, prf) => (Proofterm.proof_combP (prf_subst_TVars tye' prf, mk_sprfs cs tye), | 
| 651 | defs) | |
| 15531 | 652 |             | NONE => error ("corr: no realizer for instance of axiom " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26653diff
changeset | 653 | quote s ^ ":\n" ^ Syntax.string_of_term_global thy' (Envir.beta_norm | 
| 37310 | 654 | (Reconstruct.prop_of (Proofterm.proof_combt (prf0, ts))))) | 
| 13402 | 655 | end | 
| 656 | ||
| 49960 | 657 | | corr d vs ts Ts hs _ _ _ _ defs = error "corr: bad proof" | 
| 13402 | 658 | |
| 49960 | 659 | and extr d vs ts Ts hs (PBound i) defs = (Bound i, defs) | 
| 13402 | 660 | |
| 49960 | 661 | | extr d vs ts Ts hs (Abst (s, SOME T, prf)) defs = | 
| 662 | let val (t, defs') = extr d vs [] | |
| 663 | (T :: Ts) (dummyt :: hs) (Proofterm.incr_pboundvars 1 0 prf) defs | |
| 664 | in (Abs (s, T, t), defs') end | |
| 13402 | 665 | |
| 49960 | 666 | | extr d vs ts Ts hs (AbsP (s, SOME t, prf)) defs = | 
| 13402 | 667 | let | 
| 16458 | 668 | val T = etype_of thy' vs Ts t; | 
| 49960 | 669 | val (t, defs') = | 
| 670 | extr d vs [] (T :: Ts) (t :: hs) (Proofterm.incr_pboundvars 0 1 prf) defs | |
| 671 | in | |
| 672 | (if T = nullT then subst_bound (nullt, t) else Abs (s, T, t), defs') | |
| 13402 | 673 | end | 
| 674 | ||
| 49960 | 675 | | extr d vs ts Ts hs (prf % SOME t) defs = | 
| 676 | let val (u, defs') = extr d vs (t :: ts) Ts hs prf defs | |
| 677 | in (if member (op =) rtypes (tname_of (body_type (fastype_of1 (Ts, t)))) then u | |
| 678 | else u $ t, defs') | |
| 13732 | 679 | end | 
| 13402 | 680 | |
| 49960 | 681 | | extr d vs ts Ts hs (prf1 %% prf2) defs = | 
| 13402 | 682 | let | 
| 49960 | 683 | val (f, defs') = extr d vs [] Ts hs prf1 defs; | 
| 13402 | 684 | val prop = Reconstruct.prop_of' hs prf2; | 
| 16458 | 685 | val T = etype_of thy' vs Ts prop | 
| 13402 | 686 | in | 
| 49960 | 687 | if T = nullT then (f, defs') else | 
| 688 | let val (t, defs'') = extr d vs [] Ts hs prf2 defs' | |
| 689 | in (f $ t, defs'') end | |
| 13402 | 690 | end | 
| 691 | ||
| 49960 | 692 | | extr d vs ts Ts hs (prf0 as PThm (_, ((s, prop, SOME Ts'), body))) defs = | 
| 13402 | 693 | let | 
| 37310 | 694 | val prf = Proofterm.join_proof body; | 
| 13402 | 695 | val (vs', tye) = find_inst prop Ts ts vs; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 696 | val shyps = mk_shyps tye; | 
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 697 | val tye' = (map fst (Term.add_tvars prop [] |> rev) ~~ Ts') @ tye | 
| 13402 | 698 | in | 
| 17412 | 699 | case Symtab.lookup realizers s of | 
| 15531 | 700 | NONE => (case find vs' (find' s defs) of | 
| 701 | NONE => | |
| 13402 | 702 | let | 
| 703 |                     val _ = msg d ("Extracting " ^ quote s ^
 | |
| 704 | (if null vs' then "" | |
| 705 | else " (relevant variables: " ^ commas_quote vs' ^ ")")); | |
| 16458 | 706 | val prf' = prep (Reconstruct.reconstruct_proof thy' prop prf); | 
| 49960 | 707 | val (t, defs') = extr (d + 1) vs' [] [] [] prf' defs; | 
| 708 | val (corr_prf, defs'') = corr (d + 1) vs' [] [] [] | |
| 709 | (rev shyps) (SOME t) prf' prf' defs'; | |
| 13402 | 710 | |
| 711 | val nt = Envir.beta_norm t; | |
| 20664 | 712 | val args = filter_out (fn v => member (op =) rtypes | 
| 713 | (tname_of (body_type (fastype_of v)))) (vfs_of prop); | |
| 33317 | 714 | val args' = filter (fn v => Logic.occs (v, nt)) args; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 715 | val t' = mkabs args' nt; | 
| 13402 | 716 | val T = fastype_of t'; | 
| 13732 | 717 | val cname = extr_name s vs'; | 
| 13402 | 718 | val c = Const (cname, T); | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 719 | val u = mkabs args (list_comb (c, args')); | 
| 13402 | 720 | val eqn = Logic.mk_equals (c, t'); | 
| 721 | val rlz = | |
| 722 |                       Const ("realizes", fastype_of nt --> propT --> propT);
 | |
| 13732 | 723 | val lhs = app_rlz_rews [] vs' (rlz $ nt $ prop); | 
| 724 | val rhs = app_rlz_rews [] vs' (rlz $ list_comb (c, args') $ prop); | |
| 725 | val f = app_rlz_rews [] vs' | |
| 726 |                       (Abs ("x", T, rlz $ list_comb (Bound 0, args') $ prop));
 | |
| 13402 | 727 | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 728 | val corr_prf' = mkabsp shyps | 
| 37310 | 729 | (chtype [] Proofterm.equal_elim_axm %> lhs %> rhs %% | 
| 730 | (chtype [propT] Proofterm.symmetric_axm %> rhs %> lhs %% | |
| 731 | (chtype [T, propT] Proofterm.combination_axm %> f %> f %> c %> t' %% | |
| 732 | (chtype [T --> propT] Proofterm.reflexive_axm %> f) %% | |
| 46909 | 733 | PAxm (Thm.def_name cname, eqn, | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 734 | SOME (map TVar (Term.add_tvars eqn [] |> rev))))) %% corr_prf); | 
| 13732 | 735 | val corr_prop = Reconstruct.prop_of corr_prf'; | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 736 | val corr_prf'' = | 
| 37310 | 737 | Proofterm.proof_combP (Proofterm.proof_combt | 
| 28805 | 738 | (PThm (serial (), | 
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 739 | ((corr_name s vs', corr_prop, SOME (map TVar (Term.add_tvars corr_prop [] |> rev))), | 
| 37310 | 740 | Future.value (Proofterm.approximate_proof_body corr_prf'))), | 
| 741 | vfs_of corr_prop), | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 742 | map PBound (length shyps - 1 downto 0)) |> | 
| 37310 | 743 | fold_rev Proofterm.forall_intr_proof' | 
| 744 | (map (get_var_type corr_prop) (vfs_of prop)) |> | |
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 745 | mkabsp shyps | 
| 13402 | 746 | in | 
| 49960 | 747 | (subst_TVars tye' u, | 
| 748 | (s, (vs', ((t', u), (corr_prf', corr_prf'')))) :: defs'') | |
| 13402 | 749 | end | 
| 49960 | 750 | | SOME ((_, u), _) => (subst_TVars tye' u, defs)) | 
| 15531 | 751 | | SOME rs => (case find vs' rs of | 
| 49960 | 752 | SOME (t, _) => (subst_TVars tye' t, defs) | 
| 15531 | 753 |               | NONE => error ("extr: no realizer for instance of theorem " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26653diff
changeset | 754 | quote s ^ ":\n" ^ Syntax.string_of_term_global thy' (Envir.beta_norm | 
| 37310 | 755 | (Reconstruct.prop_of (Proofterm.proof_combt (prf0, ts)))))) | 
| 13402 | 756 | end | 
| 757 | ||
| 49960 | 758 | | extr d vs ts Ts hs (prf0 as PAxm (s, prop, SOME Ts')) defs = | 
| 13402 | 759 | let | 
| 760 | val (vs', tye) = find_inst prop Ts ts vs; | |
| 36042 
85efdadee8ae
switched PThm/PAxm etc. to use canonical order of type variables (term variables unchanged)
 krauss parents: 
35985diff
changeset | 761 | val tye' = (map fst (Term.add_tvars prop [] |> rev) ~~ Ts') @ tye | 
| 13402 | 762 | in | 
| 18956 | 763 | case find vs' (Symtab.lookup_list realizers s) of | 
| 49960 | 764 | SOME (t, _) => (subst_TVars tye' t, defs) | 
| 15531 | 765 |             | NONE => error ("extr: no realizer for instance of axiom " ^
 | 
| 26939 
1035c89b4c02
moved global pretty/string_of functions from Sign to Syntax;
 wenzelm parents: 
26653diff
changeset | 766 | quote s ^ ":\n" ^ Syntax.string_of_term_global thy' (Envir.beta_norm | 
| 37310 | 767 | (Reconstruct.prop_of (Proofterm.proof_combt (prf0, ts))))) | 
| 13402 | 768 | end | 
| 769 | ||
| 49960 | 770 | | extr d vs ts Ts hs _ defs = error "extr: bad proof"; | 
| 13402 | 771 | |
| 58436 | 772 | fun prep_thm vs thm = | 
| 13402 | 773 | let | 
| 26626 
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
 wenzelm parents: 
26481diff
changeset | 774 | val thy = Thm.theory_of_thm thm; | 
| 
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
 wenzelm parents: 
26481diff
changeset | 775 | val prop = Thm.prop_of thm; | 
| 28814 | 776 | val prf = Thm.proof_of thm; | 
| 36744 
6e1f3d609a68
renamed Thm.get_name -> Thm.derivation_name and Thm.put_name -> Thm.name_derivation, to emphasize the true nature of these operations;
 wenzelm parents: 
36620diff
changeset | 777 | val name = Thm.derivation_name thm; | 
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21646diff
changeset | 778 | val _ = name <> "" orelse error "extraction: unnamed theorem"; | 
| 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21646diff
changeset | 779 |         val _ = etype_of thy' vs [] prop <> nullT orelse error ("theorem " ^
 | 
| 13402 | 780 | quote name ^ " has no computational content") | 
| 58436 | 781 | in Reconstruct.reconstruct_proof thy prop prf end; | 
| 13402 | 782 | |
| 33245 | 783 | val defs = | 
| 58436 | 784 | fold (fn (thm, vs) => snd o (extr 0 vs [] [] [] o prep_thm vs) thm) | 
| 785 | thm_vss []; | |
| 13402 | 786 | |
| 16149 | 787 | fun add_def (s, (vs, ((t, u), (prf, _)))) thy = | 
| 16458 | 788 | (case Sign.const_type thy (extr_name s vs) of | 
| 15531 | 789 | NONE => | 
| 13732 | 790 | let | 
| 791 | val corr_prop = Reconstruct.prop_of prf; | |
| 33832 | 792 | val ft = Type.legacy_freeze t; | 
| 793 | val fu = Type.legacy_freeze u; | |
| 22750 | 794 | val (def_thms, thy') = if t = nullt then ([], thy) else | 
| 795 | thy | |
| 56239 | 796 | |> Sign.add_consts [(Binding.qualified_name (extr_name s vs), fastype_of ft, NoSyn)] | 
| 46909 | 797 | |> Global_Theory.add_defs false | 
| 798 | [((Binding.qualified_name (Thm.def_name (extr_name s vs)), | |
| 22750 | 799 | Logic.mk_equals (head_of (strip_abs_body fu), ft)), [])] | 
| 13732 | 800 | in | 
| 22750 | 801 | thy' | 
| 39557 
fe5722fce758
renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
 wenzelm parents: 
39288diff
changeset | 802 | |> Global_Theory.store_thm (Binding.qualified_name (corr_name s vs), | 
| 37233 
b78f31ca4675
Adapted to new format of proof terms containing explicit proofs of class membership.
 berghofe parents: 
36953diff
changeset | 803 | Thm.varifyT_global (funpow (length (vars_of corr_prop)) | 
| 35985 
0bbf0d2348f9
moved Drule.forall_intr_frees to Thm.forall_intr_frees (in more_thm.ML, which is loaded before pure_thy.ML);
 wenzelm parents: 
35845diff
changeset | 804 | (Thm.forall_elim_var 0) (Thm.forall_intr_frees | 
| 44057 | 805 | (Proof_Checker.thm_of_proof thy' | 
| 26481 | 806 | (fst (Proofterm.freeze_thaw_prf prf)))))) | 
| 22750 | 807 | |> snd | 
| 28370 | 808 | |> fold Code.add_default_eqn def_thms | 
| 13732 | 809 | end | 
| 15531 | 810 | | SOME _ => thy); | 
| 13402 | 811 | |
| 16149 | 812 | in | 
| 813 | thy | |
| 30435 
e62d6ecab6ad
explicit Binding.qualified_name -- prevents implicitly qualified bstring;
 wenzelm parents: 
30364diff
changeset | 814 | |> Sign.root_path | 
| 16149 | 815 | |> fold_rev add_def defs | 
| 22796 | 816 | |> Sign.restore_naming thy | 
| 13402 | 817 | end; | 
| 818 | ||
| 16458 | 819 | val etype_of = etype_of o add_syntax; | 
| 13714 | 820 | |
| 13402 | 821 | end; |