src/HOL/Eisbach/eisbach_rule_insts.ML
changeset 60909 3db3f4154e18
parent 60791 e3f2262786ea
child 61852 d273c24b5776
equal deleted inserted replaced
60908:d32915a03c63 60909:3db3f4154e18
    12 structure Eisbach_Rule_Insts: sig end =
    12 structure Eisbach_Rule_Insts: sig end =
    13 struct
    13 struct
    14 
    14 
    15 fun restore_tags thm = Thm.map_tags (K (Thm.get_tags thm));
    15 fun restore_tags thm = Thm.map_tags (K (Thm.get_tags thm));
    16 
    16 
       
    17 val mk_term_type_internal = Logic.protect o Logic.mk_term o Logic.mk_type;
       
    18 
       
    19 fun term_type_cases f g t = 
       
    20   (case (try (Logic.dest_type o Logic.dest_term o Logic.unprotect) t) of
       
    21     SOME T => f T
       
    22   | NONE => 
       
    23     (case (try Logic.dest_term t) of
       
    24       SOME t => g t
       
    25     | NONE => raise Fail "Lost encoded instantiation"))
       
    26 
    17 fun add_thm_insts ctxt thm =
    27 fun add_thm_insts ctxt thm =
    18   let
    28   let
    19     val tyvars = Thm.fold_terms Term.add_tvars thm [];
    29     val tyvars = Thm.fold_terms Term.add_tvars thm [];
    20     val tyvars' = tyvars |> map (Logic.mk_term o Logic.mk_type o TVar);
    30     val tyvars' = tyvars |> map (mk_term_type_internal o TVar);
    21 
    31 
    22     val tvars = Thm.fold_terms Term.add_vars thm [];
    32     val tvars = Thm.fold_terms Term.add_vars thm [];
    23     val tvars' = tvars  |> map (Logic.mk_term o Var);
    33     val tvars' = tvars  |> map (Logic.mk_term o Var);
    24 
    34 
    25     val conj =
    35     val conj =
    34 
    44 
    35     val insts' = insts
    45     val insts' = insts
    36       |> Drule.dest_term
    46       |> Drule.dest_term
    37       |> Thm.term_of
    47       |> Thm.term_of
    38       |> Logic.dest_conjunction_list
    48       |> Logic.dest_conjunction_list
    39       |> map Logic.dest_term
       
    40       |> (fn f => fold (fn t => fn (tys, ts) =>
    49       |> (fn f => fold (fn t => fn (tys, ts) =>
    41           (case try Logic.dest_type t of
    50           term_type_cases (fn T => (T :: tys, ts)) (fn t => (tys, t :: ts)) t) f ([], []))
    42             SOME T => (T :: tys, ts)
       
    43           | NONE => (tys, t :: ts))) f ([], []))
       
    44       ||> rev
    51       ||> rev
    45       |>> rev;
    52       |>> rev;
    46   in
    53   in
    47     (thm', insts')
    54     (thm', insts')
    48   end;
    55   end;