src/Pure/Isar/proof.ML
changeset 5918 4cbd726577f7
parent 5875 6aae55ae3473
child 5936 406eb27fe53c
equal deleted inserted replaced
5917:dcb669fda86b 5918:4cbd726577f7
     4 
     4 
     5 Proof states and methods.
     5 Proof states and methods.
     6 
     6 
     7 TODO:
     7 TODO:
     8   - assume: improve schematic Vars handling (!?);
     8   - assume: improve schematic Vars handling (!?);
       
     9   - warn_vars;
     9   - bind: check rhs (extra (T)Vars etc.) (How to handle these anyway?);
    10   - bind: check rhs (extra (T)Vars etc.) (How to handle these anyway?);
    10   - prep_result: avoid duplicate asms;
    11   - prep_result: avoid duplicate asms;
    11   - goal: need asms field? (may take from goal context!?);
       
    12   - finish: filter results (!??) (no?);
       
    13   - finish_tac: make a parameter (method) (!!?);
       
    14   - prep_result error: use error channel (!);
    12   - prep_result error: use error channel (!);
       
    13   - check_finished: trace results (!?);
    15   - next_block: fetch_facts (!?);
    14   - next_block: fetch_facts (!?);
    16   - warn_vars;
       
    17   - string constants in one place (e.g. "it", "thesis") (??!);
       
    18   - check_finished: trace results (!?);
       
    19 *)
    15 *)
    20 
    16 
    21 signature PROOF =
    17 signature PROOF =
    22 sig
    18 sig
    23   type context
    19   type context
    39   val refine: (context -> method) -> state -> state Seq.seq
    35   val refine: (context -> method) -> state -> state Seq.seq
    40   val bind: (indexname * string) list -> state -> state
    36   val bind: (indexname * string) list -> state -> state
    41   val bind_i: (indexname * term) list -> state -> state
    37   val bind_i: (indexname * term) list -> state -> state
    42   val match_bind: (string * string) list -> state -> state
    38   val match_bind: (string * string) list -> state -> state
    43   val match_bind_i: (term * term) list -> state -> state
    39   val match_bind_i: (term * term) list -> state -> state
    44   val have_tthms: string -> context attribute list ->
    40   val have_tthmss: string -> context attribute list ->
    45     (tthm * context attribute list) list -> state -> state
    41     (tthm list * context attribute list) list -> state -> state
    46   val assume: string -> context attribute list -> string list -> state -> state
    42   val assume: string -> context attribute list -> string list -> state -> state
    47   val assume_i: string -> context attribute list -> term list -> state -> state
    43   val assume_i: string -> context attribute list -> term list -> state -> state
    48   val fix: (string * string option) list -> state -> state
    44   val fix: (string * string option) list -> state -> state
    49   val fix_i: (string * typ) list -> state -> state
    45   val fix_i: (string * typ) list -> state -> state
    50   val theorem: bstring -> theory attribute list -> string -> theory -> state
    46   val theorem: bstring -> theory attribute list -> string -> theory -> state
    68 sig
    64 sig
    69   include PROOF
    65   include PROOF
    70   val put_data: Object.kind -> ('a -> Object.T) -> 'a -> state -> state
    66   val put_data: Object.kind -> ('a -> Object.T) -> 'a -> state -> state
    71 end;
    67 end;
    72 
    68 
    73 
       
    74 structure Proof: PROOF_PRIVATE =
    69 structure Proof: PROOF_PRIVATE =
    75 struct
    70 struct
    76 
    71 
    77 
    72 
    78 (** proof state **)
    73 (** proof state **)
   431 
   426 
   432 val match_bind = gen_bind ProofContext.match_binds;
   427 val match_bind = gen_bind ProofContext.match_binds;
   433 val match_bind_i = gen_bind ProofContext.match_binds_i;
   428 val match_bind_i = gen_bind ProofContext.match_binds_i;
   434 
   429 
   435 
   430 
   436 (* have_tthms *)
   431 (* have_tthmss *)
   437 
   432 
   438 val def_name = fn "" => "it" | name => name;
   433 fun have_tthmss name atts ths_atts state =
   439 
   434   state
   440 fun have_tthms name atts ths_atts state =
   435   |> assert_forward
   441   state
   436   |> map_context_result (ProofContext.have_tthmss (PureThy.default_name name) atts ths_atts)
   442   |> assert_forward
       
   443   |> map_context_result (ProofContext.have_tthms (def_name name) atts ths_atts)
       
   444   |> these_facts;
   437   |> these_facts;
   445 
   438 
   446 
   439 
   447 (* fix *)
   440 (* fix *)
   448 
   441 
   459 (* assume *)
   452 (* assume *)
   460 
   453 
   461 fun gen_assume f name atts props state =
   454 fun gen_assume f name atts props state =
   462   state
   455   state
   463   |> assert_forward
   456   |> assert_forward
   464   |> map_context_result (f (def_name name) atts props)
   457   |> map_context_result (f (PureThy.default_name name) atts props)
   465   |> these_facts
   458   |> these_facts
   466   |> (fn st => let_tthms ("prems", ProofContext.assumptions (context_of st)) st);
   459   |> (fn st => let_tthms ("prems", ProofContext.assumptions (context_of st)) st);
   467 
   460 
   468 val assume = gen_assume ProofContext.assume;
   461 val assume = gen_assume ProofContext.assume;
   469 val assume_i = gen_assume ProofContext.assume_i;
   462 val assume_i = gen_assume ProofContext.assume_i;
   506     |> assert_forward_or_chain
   499     |> assert_forward_or_chain
   507     |> enter_forward
   500     |> enter_forward
   508     |> opt_block
   501     |> opt_block
   509 
   502 
   510     |> declare_term prop
   503     |> declare_term prop
   511     |> put_goal (Some ((kind atts, (def_name name), casms, prop), ([], thm)))
   504     |> put_goal (Some ((kind atts, (PureThy.default_name name), casms, prop), ([], thm)))
   512     |> bind_props [("thesis", prop)]
   505     |> bind_props [("thesis", prop)]
   513     |> (if is_chain state then use_facts else reset_facts)
   506     |> (if is_chain state then use_facts else reset_facts)
   514 
   507 
   515     |> new_block
   508     |> new_block
   516     |> enter_backward
   509     |> enter_backward
   605       | Aux atts => (atts, Seq.single)
   598       | Aux atts => (atts, Seq.single)
   606       | _ => raise STATE ("No local goal!", state));
   599       | _ => raise STATE ("No local goal!", state));
   607   in
   600   in
   608     state
   601     state
   609     |> close_block
   602     |> close_block
   610     |> have_tthms name atts [((result, []), [])]
   603     |> have_tthmss name atts [([(result, [])], [])]
   611     |> opt_solve
   604     |> opt_solve
   612   end;
   605   end;
   613 
   606 
   614 fun end_block meth_fun state =
   607 fun end_block meth_fun state =
   615   if can assert_current_goal (close_block state) then
   608   if can assert_current_goal (close_block state) then
   634 
   627 
   635     val name = if_none alt_name def_name;
   628     val name = if_none alt_name def_name;
   636     val atts =
   629     val atts =
   637       (case kind of
   630       (case kind of
   638         Theorem atts => if_none alt_atts atts
   631         Theorem atts => if_none alt_atts atts
   639       | Lemma atts => Attribute.tag_lemma :: if_none alt_atts atts
   632       | Lemma atts => (if_none alt_atts atts) @ [Attribute.tag_lemma]
   640       | _ => raise STATE ("No global goal!", state));
   633       | _ => raise STATE ("No global goal!", state));
   641 
   634 
   642     val (thy', result') = PureThy.store_tthm ((name, (result, [])), atts) (theory_of state);
   635     val (thy', result') = PureThy.store_tthm ((name, (result, [])), atts) (theory_of state);
   643   in (thy', (kind_name kind, name, result')) end;
   636   in (thy', (kind_name kind, name, result')) end;
   644 
   637