src/Pure/Isar/proof.ML
changeset 14564 3667b4616e9a
parent 14554 b9cd48af3512
child 14876 477c414000f8
equal deleted inserted replaced
14563:4bf2d10461f3 14564:3667b4616e9a
    51   val refine_end: (context -> method) -> state -> state Seq.seq
    51   val refine_end: (context -> method) -> state -> state Seq.seq
    52   val match_bind: (string list * string) list -> state -> state
    52   val match_bind: (string list * string) list -> state -> state
    53   val match_bind_i: (term list * term) list -> state -> state
    53   val match_bind_i: (term list * term) list -> state -> state
    54   val let_bind: (string list * string) list -> state -> state
    54   val let_bind: (string list * string) list -> state -> state
    55   val let_bind_i: (term list * term) list -> state -> state
    55   val let_bind_i: (term list * term) list -> state -> state
    56   val simple_have_thms: string -> thm list -> state -> state
    56   val simple_note_thms: string -> thm list -> state -> state
    57   val have_thmss: ((bstring * context attribute list) *
    57   val note_thmss: ((bstring * context attribute list) *
    58     (xstring * context attribute list) list) list -> state -> state
    58     (xstring * context attribute list) list) list -> state -> state
    59   val have_thmss_i: ((bstring * context attribute list) *
    59   val note_thmss_i: ((bstring * context attribute list) *
    60     (thm list * context attribute list) list) list -> state -> state
    60     (thm list * context attribute list) list) list -> state -> state
    61   val with_thmss: ((bstring * context attribute list) *
    61   val with_thmss: ((bstring * context attribute list) *
    62     (xstring * context attribute list) list) list -> state -> state
    62     (xstring * context attribute list) list) list -> state -> state
    63   val with_thmss_i: ((bstring * context attribute list) *
    63   val with_thmss_i: ((bstring * context attribute list) *
    64     (thm list * context attribute list) list) list -> state -> state
    64     (thm list * context attribute list) list) list -> state -> state
   509 val match_bind_i = gen_bind (ProofContext.match_bind_i false);
   509 val match_bind_i = gen_bind (ProofContext.match_bind_i false);
   510 val let_bind = gen_bind (ProofContext.match_bind true);
   510 val let_bind = gen_bind (ProofContext.match_bind true);
   511 val let_bind_i = gen_bind (ProofContext.match_bind_i true);
   511 val let_bind_i = gen_bind (ProofContext.match_bind_i true);
   512 
   512 
   513 
   513 
   514 (* have_thmss *)
   514 (* note_thmss *)
   515 (* CB: this implements "note" of the Isar/VM *)
       
   516 
   515 
   517 local
   516 local
   518 
   517 
   519 fun gen_have_thmss f args state =
   518 fun gen_note_thmss f args state =
   520   state
   519   state
   521   |> assert_forward
   520   |> assert_forward
   522   |> map_context_result (f args)
   521   |> map_context_result (f args)
   523   |> these_factss;
   522   |> these_factss;
   524 
   523 
   525 in
   524 in
   526 
   525 
   527 val have_thmss = gen_have_thmss ProofContext.have_thmss;
   526 val note_thmss = gen_note_thmss ProofContext.note_thmss;
   528 val have_thmss_i = gen_have_thmss ProofContext.have_thmss_i;
   527 val note_thmss_i = gen_note_thmss ProofContext.note_thmss_i;
   529 
   528 
   530 fun simple_have_thms name thms = have_thmss_i [((name, []), [(thms, [])])];
   529 fun simple_note_thms name thms = note_thmss_i [((name, []), [(thms, [])])];
   531 
   530 
   532 end;
   531 end;
   533 
   532 
   534 
   533 
   535 (* with_thmss *)
   534 (* with_thmss *)
   536 
   535 
   537 local
   536 local
   538 
   537 
   539 fun gen_with_thmss f args state =
   538 fun gen_with_thmss f args state =
   540   let val state' = state |> f args
   539   let val state' = state |> f args
   541   in state' |> simple_have_thms "" (the_facts state' @ the_facts state) end;
   540   in state' |> simple_note_thms "" (the_facts state' @ the_facts state) end;
   542 
   541 
   543 in
   542 in
   544 
   543 
   545 val with_thmss = gen_with_thmss have_thmss;
   544 val with_thmss = gen_with_thmss note_thmss;
   546 val with_thmss_i = gen_with_thmss have_thmss_i;
   545 val with_thmss_i = gen_with_thmss note_thmss_i;
   547 
   546 
   548 end;
   547 end;
   549 
   548 
   550 
   549 
   551 (* using_thmss *)
   550 (* using_thmss *)
   560     let val (_, (_, ((result, (facts, thm)), x))) = find_goal st;
   559     let val (_, (_, ((result, (facts, thm)), x))) = find_goal st;
   561     in st |> map_goal I (K ((result, (facts @ flat (map snd named_facts), thm)), x)) end);
   560     in st |> map_goal I (K ((result, (facts @ flat (map snd named_facts), thm)), x)) end);
   562 
   561 
   563 in
   562 in
   564 
   563 
   565 val using_thmss = gen_using_thmss ProofContext.have_thmss;
   564 val using_thmss = gen_using_thmss ProofContext.note_thmss;
   566 val using_thmss_i = gen_using_thmss ProofContext.have_thmss_i;
   565 val using_thmss_i = gen_using_thmss ProofContext.note_thmss_i;
   567 
   566 
   568 end;
   567 end;
   569 
   568 
   570 
   569 
   571 (* locale instantiation *)
   570 (* locale instantiation *)
   648     state'
   647     state'
   649     |> add_binds_i lets
   648     |> add_binds_i lets
   650     |> map_context (ProofContext.qualified true)
   649     |> map_context (ProofContext.qualified true)
   651     |> assume_i assumptions
   650     |> assume_i assumptions
   652     |> map_context (ProofContext.hide_thms false qnames)
   651     |> map_context (ProofContext.hide_thms false qnames)
   653     |> (fn st => simple_have_thms name (the_facts st) st)
   652     |> (fn st => simple_note_thms name (the_facts st) st)
   654     |> map_context (ProofContext.restore_qualified (context_of state))
   653     |> map_context (ProofContext.restore_qualified (context_of state))
   655   end;
   654   end;
   656 
   655 
   657 
   656 
   658 
   657 
   809     conditional pr (fn () => print_result goal_ctxt
   808     conditional pr (fn () => print_result goal_ctxt
   810       (kind_name (sign_of state) kind, names ~~ Library.unflat tss results));
   809       (kind_name (sign_of state) kind, names ~~ Library.unflat tss results));
   811     outer_state
   810     outer_state
   812     |> auto_bind_facts (ProofContext.generalize goal_ctxt outer_ctxt ts)
   811     |> auto_bind_facts (ProofContext.generalize goal_ctxt outer_ctxt ts)
   813     |> (fn st => Seq.map (fn res =>
   812     |> (fn st => Seq.map (fn res =>
   814       have_thmss_i ((names ~~ attss) ~~ map (single o Thm.no_attributes) res) st) resultq)
   813       note_thmss_i ((names ~~ attss) ~~ map (single o Thm.no_attributes) res) st) resultq)
   815     |> (Seq.flat o Seq.map opt_solve)
   814     |> (Seq.flat o Seq.map opt_solve)
   816     |> (Seq.flat o Seq.map after_qed)
   815     |> (Seq.flat o Seq.map after_qed)
   817   end;
   816   end;
   818 
   817 
   819 fun local_qed finalize print state =
   818 fun local_qed finalize print state =
   853           |> Locale.add_thmss loc ((names ~~ Library.unflat tss locale_results') ~~ loc_attss)
   852           |> Locale.add_thmss loc ((names ~~ Library.unflat tss locale_results') ~~ loc_attss)
   854           |> (fn ((thy', ctxt'), res) =>
   853           |> (fn ((thy', ctxt'), res) =>
   855             if name = "" andalso null loc_atts then thy'
   854             if name = "" andalso null loc_atts then thy'
   856             else (thy', ctxt')
   855             else (thy', ctxt')
   857               |> (#1 o #1 o Locale.add_thmss loc [((name, flat (map #2 res)), loc_atts)])))
   856               |> (#1 o #1 o Locale.add_thmss loc [((name, flat (map #2 res)), loc_atts)])))
   858       |> Locale.smart_have_thmss k locale_spec
   857       |> Locale.smart_note_thmss k locale_spec
   859         ((names ~~ attss) ~~ map (single o Thm.no_attributes) (Library.unflat tss results))
   858         ((names ~~ attss) ~~ map (single o Thm.no_attributes) (Library.unflat tss results))
   860       |> (fn (thy, res) => (thy, res)
   859       |> (fn (thy, res) => (thy, res)
   861           |>> (#1 o Locale.smart_have_thmss k locale_spec
   860           |>> (#1 o Locale.smart_note_thmss k locale_spec
   862             [((name, atts), [(flat (map #2 res), [])])]));
   861             [((name, atts), [(flat (map #2 res), [])])]));
   863   in (theory', ((k, name), results')) end;
   862   in (theory', ((k, name), results')) end;
   864 
   863 
   865 
   864 
   866 (*note: clients should inspect first result only, as backtracking may destroy theory*)
   865 (*note: clients should inspect first result only, as backtracking may destroy theory*)