src/Pure/Isar/proof_context.ML
changeset 11816 545aab7410ac
parent 11793 5f0ab6f5c280
child 11915 df030220a2a8
equal deleted inserted replaced
11815:ef7619398680 11816:545aab7410ac
    40   val declare_terms: term list -> context -> context
    40   val declare_terms: term list -> context -> context
    41   val warn_extra_tfrees: context -> context -> context
    41   val warn_extra_tfrees: context -> context -> context
    42   val generalizeT: context -> context -> typ -> typ
    42   val generalizeT: context -> context -> typ -> typ
    43   val generalize: context -> context -> term -> term
    43   val generalize: context -> context -> term -> term
    44   val find_free: term -> string -> term option
    44   val find_free: term -> string -> term option
    45   val export_wrt: bool -> context -> context option -> (thm -> thm Seq.seq) * (int -> tactic) list
    45   val export_wrt: bool -> context -> context option -> thm -> thm Seq.seq
    46   val drop_schematic: indexname * term option -> indexname * term option
    46   val drop_schematic: indexname * term option -> indexname * term option
    47   val add_binds: (indexname * string option) list -> context -> context
    47   val add_binds: (indexname * string option) list -> context -> context
    48   val add_binds_i: (indexname * term option) list -> context -> context
    48   val add_binds_i: (indexname * term option) list -> context -> context
    49   val auto_bind_goal: term -> context -> context
    49   val auto_bind_goal: term -> context -> context
    50   val auto_bind_facts: string -> term list -> context -> context
    50   val auto_bind_facts: string -> term list -> context -> context
   118 struct
   118 struct
   119 
   119 
   120 
   120 
   121 (** datatype context **)
   121 (** datatype context **)
   122 
   122 
   123 type exporter =
   123 type exporter = bool -> cterm list -> thm -> thm Seq.seq;
   124   (cterm list -> thm -> thm Seq.seq) * (bool -> int -> (int -> tactic) list);
       
   125 
   124 
   126 datatype context =
   125 datatype context =
   127   Context of
   126   Context of
   128    {thy: theory,                                                        (*current theory*)
   127    {thy: theory,                                                        (*current theory*)
   129     data: Object.T Symtab.table,                                        (*user data*)
   128     data: Object.T Symtab.table,                                        (*user data*)
   576 fun get_free x (None, t as Free (y, _)) = if x = y then Some t else None
   575 fun get_free x (None, t as Free (y, _)) = if x = y then Some t else None
   577   | get_free _ (opt, _) = opt;
   576   | get_free _ (opt, _) = opt;
   578 
   577 
   579 fun find_free t x = foldl_aterms (get_free x) (None, t);
   578 fun find_free t x = foldl_aterms (get_free x) (None, t);
   580 
   579 
   581 
       
   582 local
       
   583 
       
   584 fun export tfrees fixes goal_asms thm =
       
   585   thm
       
   586   |> Tactic.norm_hhf
       
   587   |> Seq.EVERY (rev (map op |> goal_asms))
       
   588   |> Seq.map (fn rule =>
       
   589     let
       
   590       val {sign, prop, maxidx, ...} = Thm.rep_thm rule;
       
   591       val frees = map (Thm.cterm_of sign) (mapfilter (find_free prop) fixes);
       
   592     in
       
   593       rule
       
   594       |> Drule.forall_intr_list frees
       
   595       |> Tactic.norm_hhf
       
   596       |> Drule.tvars_intr_list tfrees
       
   597     end);
       
   598 
       
   599 fun diff_context inner None = (gen_tfrees inner None, fixed_names inner, assumptions inner)
   580 fun diff_context inner None = (gen_tfrees inner None, fixed_names inner, assumptions inner)
   600   | diff_context inner (Some outer) =
   581   | diff_context inner (Some outer) =
   601       (gen_tfrees inner (Some outer),
   582       (gen_tfrees inner (Some outer),
   602         fixed_names inner \\ fixed_names outer,
   583         fixed_names inner \\ fixed_names outer,
   603         Library.drop (length (assumptions outer), assumptions inner));
   584         Library.drop (length (assumptions outer), assumptions inner));
   604 
   585 
   605 in
       
   606 
       
   607 fun export_wrt is_goal inner opt_outer =
   586 fun export_wrt is_goal inner opt_outer =
   608   let
   587   let
   609     val (tfrees, fixes, asms) = diff_context inner opt_outer;
   588     val (tfrees, fixes, asms) = diff_context inner opt_outer;
   610     val goal_asms = map (fn (cprops, (exp, _)) => (map Drule.mk_cgoal cprops, exp)) asms;
   589     val exp_asms = map (fn (cprops, exp) => exp is_goal cprops) asms;
   611     val tacs = flat (map (fn (cprops, (_, f)) => f is_goal (length cprops)) asms);
   590   in fn thm =>
   612   in (export tfrees fixes goal_asms, tacs) end;
   591     thm
   613 
   592     |> Tactic.norm_hhf
   614 end;
   593     |> Seq.EVERY (rev exp_asms)
       
   594     |> Seq.map (fn rule =>
       
   595       let
       
   596         val {sign, prop, ...} = Thm.rep_thm rule;
       
   597         val frees = map (Thm.cterm_of sign) (mapfilter (find_free prop) fixes);
       
   598       in
       
   599         rule
       
   600         |> Drule.forall_intr_list frees
       
   601         |> Tactic.norm_hhf
       
   602         |> Drule.tvars_intr_list tfrees
       
   603       end)
       
   604   end;
   615 
   605 
   616 
   606 
   617 
   607 
   618 (** bindings **)
   608 (** bindings **)
   619 
   609 
   847 local
   837 local
   848 
   838 
   849 fun add_assm (ctxt, ((name, attrs), props)) =
   839 fun add_assm (ctxt, ((name, attrs), props)) =
   850   let
   840   let
   851     val cprops = map (Thm.cterm_of (sign_of ctxt)) props;
   841     val cprops = map (Thm.cterm_of (sign_of ctxt)) props;
   852     val asms = map (Tactic.norm_hhf o Drule.assume_goal) cprops;
   842     val asms = map (Tactic.norm_hhf o Thm.assume) cprops;
   853 
   843 
   854     val ths = map (fn th => ([th], [])) asms;
   844     val ths = map (fn th => ([th], [])) asms;
   855     val (ctxt', [(_, thms)]) =
   845     val (ctxt', [(_, thms)]) =
   856       ctxt
   846       ctxt
   857       |> auto_bind_facts name props
   847       |> auto_bind_facts name props