src/Pure/Isar/proof.ML
changeset 12065 5f7f44d5e3dd
parent 12055 a9c44895cc8c
child 12085 235576bea937
equal deleted inserted replaced
12064:34c270893ecb 12065:5f7f44d5e3dd
    74   val presume_i: ((string * context attribute list) * (term * (term list * term list)) list) list
    74   val presume_i: ((string * context attribute list) * (term * (term list * term list)) list) list
    75     -> state -> state
    75     -> state -> state
    76   val def: string -> context attribute list -> string *  (string * string list) -> state -> state
    76   val def: string -> context attribute list -> string *  (string * string list) -> state -> state
    77   val def_i: string -> context attribute list -> string * (term * term list) -> state -> state
    77   val def_i: string -> context attribute list -> string * (term * term list) -> state -> state
    78   val invoke_case: string * string option list * context attribute list -> state -> state
    78   val invoke_case: string * string option list * context attribute list -> state -> state
    79   val theorem: string -> xstring option -> context attribute Locale.element list -> bstring
    79   val theorem: string
    80     -> theory attribute list -> string * (string list * string list) -> theory -> state
    80     -> (xstring * context attribute list) option -> context attribute Locale.element list
    81   val theorem_i: string -> string option -> context attribute Locale.element_i list -> bstring
    81     -> bstring -> theory attribute list -> string * (string list * string list) -> theory -> state
    82     -> theory attribute list -> term * (term list * term list) -> theory -> state
    82   val theorem_i: string
       
    83     -> (string * context attribute list) option -> context attribute Locale.element_i list
       
    84     -> bstring -> theory attribute list -> term * (term list * term list) -> theory -> state
    83   val chain: state -> state
    85   val chain: state -> state
    84   val from_facts: thm list -> state -> state
    86   val from_facts: thm list -> state -> state
    85   val show: (bool -> state -> state) -> (state -> state Seq.seq) -> string
    87   val show: (bool -> state -> state) -> (state -> state Seq.seq) -> string
    86     -> context attribute list -> string * (string list * string list) -> bool -> state -> state
    88     -> context attribute list -> string * (string list * string list) -> bool -> state -> state
    87   val show_i: (bool -> state -> state) -> (state -> state Seq.seq) -> string
    89   val show_i: (bool -> state -> state) -> (state -> state Seq.seq) -> string
   117 
   119 
   118 
   120 
   119 (* type goal *)
   121 (* type goal *)
   120 
   122 
   121 datatype kind =
   123 datatype kind =
   122   Theorem of string * string option * theory attribute list |    (*theorem with kind and locale*)
   124   Theorem of string * (string * context attribute list) option * theory attribute list |
   123   Show of context attribute list |               (*intermediate result, solving subgoal*)
   125     (*theorem with kind, locale target, attributes*)
   124   Have of context attribute list;                (*intermediate result*)
   126   Show of context attribute list |  (*intermediate result, solving subgoal*)
       
   127   Have of context attribute list;   (*intermediate result*)
   125 
   128 
   126 fun kind_name _ (Theorem (s, None, _)) = s
   129 fun kind_name _ (Theorem (s, None, _)) = s
   127   | kind_name sg (Theorem (s, Some loc, _)) = s ^ " (in " ^ Locale.cond_extern sg loc ^ ")"
   130   | kind_name sg (Theorem (s, Some (name, _), _)) = s ^ " (in " ^ Locale.cond_extern sg name ^ ")"
   128   | kind_name _ (Show _) = "show"
   131   | kind_name _ (Show _) = "show"
   129   | kind_name _ (Have _) = "have";
   132   | kind_name _ (Have _) = "have";
   130 
   133 
   131 type goal =
   134 type goal =
   132  (kind *        (*result kind*)
   135  (kind *        (*result kind*)
   608     |> new_block
   611     |> new_block
   609     |> enter_backward
   612     |> enter_backward
   610   end;
   613   end;
   611 
   614 
   612 (*global goals*)
   615 (*global goals*)
   613 fun global_goal prepp act_locale act_elems kind locale elems name atts x thy =
   616 fun global_goal prepp prep_locale activate kind raw_locale elems name atts x thy =
   614   thy |> init_state
   617   let val locale = apsome (apfst (prep_locale (Theory.sign_of thy))) raw_locale in
   615   |> open_block |> (case locale of Some loc => map_context (act_locale loc) | None => I)
   618     thy
   616   |> open_block |> map_context (act_elems elems)
   619     |> init_state
   617   |> setup_goal I prepp (ProofContext.fix_frees o single) (Theorem (kind, locale, atts))
   620     |> open_block
   618     Seq.single name x;
   621     |> (case locale of Some (name, _) => map_context (Locale.activate_locale_i name) | None => I)
   619 
   622     |> open_block
   620 val theorem = global_goal ProofContext.bind_propp_schematic
   623     |> map_context (activate elems)
   621   Locale.activate_locale Locale.activate_elements;
   624     |> setup_goal I prepp (ProofContext.fix_frees o single) (Theorem (kind, locale, atts))
   622 
   625       Seq.single name x
   623 val theorem_i = global_goal ProofContext.bind_propp_schematic_i
   626   end;
   624   Locale.activate_locale_i Locale.activate_elements_i;
   627 
       
   628 val theorem = global_goal ProofContext.bind_propp_schematic Locale.intern Locale.activate_elements;
       
   629 val theorem_i = global_goal ProofContext.bind_propp_schematic_i (K I) Locale.activate_elements_i;
   625 
   630 
   626 
   631 
   627 (*local goals*)
   632 (*local goals*)
   628 fun local_goal' prepp kind (check: bool -> state -> state)
   633 fun local_goal' prepp kind (check: bool -> state -> state)
   629     f name atts args int state =
   634     f name atts args int state =
   706   |> (Seq.flat o Seq.map (finish_local print));
   711   |> (Seq.flat o Seq.map (finish_local print));
   707 
   712 
   708 
   713 
   709 (* global_qed *)
   714 (* global_qed *)
   710 
   715 
       
   716 fun locale_store_thm _ None _ = I
       
   717   | locale_store_thm name (Some (loc, atts)) th = Locale.store_thm loc ((name, th), atts);
       
   718 
   711 fun finish_global state =
   719 fun finish_global state =
   712   let
   720   let
       
   721     fun export inner outer th =
       
   722       (case Seq.pull (ProofContext.export false inner outer th) of
       
   723         Some (th', _) => th' |> Drule.local_standard
       
   724       | None => raise STATE ("Internal failure of theorem export", state));
       
   725 
   713     val (goal_ctxt, (((kind, name, t), (_, raw_thm)), _)) = current_goal state;
   726     val (goal_ctxt, (((kind, name, t), (_, raw_thm)), _)) = current_goal state;
   714     val full_name = if name = "" then "" else Sign.full_name (sign_of state) name;
   727     val locale_ctxt = context_of (state |> close_block);
   715     val locale_context = context_of (state |> close_block);  (* FIXME unused *)
   728     val theory_ctxt = context_of (state |> close_block |> close_block);
   716     val theory_context = context_of (state |> close_block |> close_block);
   729 
   717 
   730     val locale_result = prep_result state t raw_thm |> export goal_ctxt locale_ctxt;
   718     val result = prep_result state t raw_thm;
   731     val result = locale_result |> export locale_ctxt theory_ctxt;
   719     val resultq =
   732 
   720       ProofContext.export false goal_ctxt theory_context result
   733     val (kname, atts, locale) =
   721       |> Seq.map Drule.local_standard;
   734       (case kind of Theorem (s, locale, atts) => (s, atts @ [Drule.kind s], locale)
   722 
       
   723     val (atts, opt_locale) =
       
   724       (case kind of Theorem (s, loc, atts) => (atts @ [Drule.kind s], loc)
       
   725       | _ => err_malformed "finish_global" state);
   735       | _ => err_malformed "finish_global" state);
   726     val thy = theory_of state;
   736     val (thy', result') =
   727   in
   737       theory_of state
   728     resultq |> Seq.map (fn res =>
   738       |> PureThy.store_thm ((name, result), atts)
   729       let val (thy', res') = PureThy.store_thm ((name, res), atts) thy
   739       |>> locale_store_thm name locale locale_result;
   730       in (thy', {kind = kind_name (sign_of state) kind, name = name, thm = res'}) end)
   740   in (thy', {kind = kname, name = name, thm = result'}) end;
   731   end;
       
   732 
   741 
   733 (*note: clients should inspect first result only, as backtracking may destroy theory*)
   742 (*note: clients should inspect first result only, as backtracking may destroy theory*)
   734 fun global_qed finalize state =
   743 fun global_qed finalize state =
   735   state
   744   state
   736   |> end_proof true
   745   |> end_proof true
   737   |> finalize
   746   |> finalize
   738   |> Seq.map finish_global
   747   |> Seq.map finish_global;
   739   |> Seq.flat;
       
   740 
   748 
   741 
   749 
   742 
   750 
   743 (** blocks **)
   751 (** blocks **)
   744 
   752