src/Pure/Isar/isar_thy.ML
changeset 7012 ae9dac5af9d1
parent 7002 01a4e15ee253
child 7103 1c44df10a7bc
equal deleted inserted replaced
7011:7e8e9a26ba2c 7012:ae9dac5af9d1
   121   val terminal_proof: ((Method.text * Comment.interest) * (Method.text * Comment.interest) option)
   121   val terminal_proof: ((Method.text * Comment.interest) * (Method.text * Comment.interest) option)
   122     * Comment.text -> Toplevel.transition -> Toplevel.transition
   122     * Comment.text -> Toplevel.transition -> Toplevel.transition
   123   val immediate_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
   123   val immediate_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
   124   val default_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
   124   val default_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
   125   val skip_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
   125   val skip_proof: Comment.text -> Toplevel.transition -> Toplevel.transition
       
   126   val get_thmss: (string * Args.src list) list -> Proof.state -> thm list
   126   val also: ((string * Args.src list) list * Comment.interest) option * Comment.text
   127   val also: ((string * Args.src list) list * Comment.interest) option * Comment.text
   127     -> Toplevel.transition -> Toplevel.transition
   128     -> Toplevel.transition -> Toplevel.transition
   128   val also_i: (thm list * Comment.interest) option * Comment.text
   129   val also_i: (thm list * Comment.interest) option * Comment.text
   129     -> Toplevel.transition -> Toplevel.transition
   130     -> Toplevel.transition -> Toplevel.transition
   130   val finally: ((string * Args.src list) list * Comment.interest) option * Comment.text
   131   val finally: ((string * Args.src list) list * Comment.interest) option * Comment.text
   222 
   223 
   223 fun local_have_thmss x =
   224 fun local_have_thmss x =
   224   gen_have_thmss (ProofContext.get_thms o Proof.context_of)
   225   gen_have_thmss (ProofContext.get_thms o Proof.context_of)
   225     (Attrib.local_attribute o Proof.theory_of) x;
   226     (Attrib.local_attribute o Proof.theory_of) x;
   226 
   227 
   227 fun have_thmss_i f ((name, more_atts), th_atts) =
   228 fun gen_have_thmss_i f ((name, more_atts), th_atts) =
   228   f name more_atts (map (apfst single) th_atts);
   229   f name more_atts (map (apfst single) th_atts);
   229 
   230 
   230 fun have_lemss name atts = PureThy.have_thmss name (atts @ [Drule.tag_lemma]);
   231 fun have_lemss name atts = PureThy.have_thmss name (atts @ [Drule.tag_lemma]);
   231 
   232 
   232 
   233 
   233 fun apply_theorems th_srcs = global_have_thmss PureThy.have_thmss ((None, []), th_srcs);
   234 fun apply_theorems th_srcs = global_have_thmss PureThy.have_thmss ((None, []), th_srcs);
   234 fun apply_theorems_i th_srcs = have_thmss_i PureThy.have_thmss ((None, []), th_srcs);
   235 fun apply_theorems_i th_srcs = gen_have_thmss_i PureThy.have_thmss ((None, []), th_srcs);
   235 val have_theorems = #1 oo (global_have_thmss (PureThy.have_thmss o Some) o Comment.ignore);
   236 val have_theorems = #1 oo (global_have_thmss (PureThy.have_thmss o Some) o Comment.ignore);
   236 val have_theorems_i = #1 oo (have_thmss_i (PureThy.have_thmss o Some) o Comment.ignore);
   237 val have_theorems_i = #1 oo (gen_have_thmss_i (PureThy.have_thmss o Some) o Comment.ignore);
   237 val have_lemmas = #1 oo (global_have_thmss (have_lemss o Some) o Comment.ignore);
   238 val have_lemmas = #1 oo (global_have_thmss (have_lemss o Some) o Comment.ignore);
   238 val have_lemmas_i = #1 oo (have_thmss_i (have_lemss o Some) o Comment.ignore);
   239 val have_lemmas_i = #1 oo (gen_have_thmss_i (have_lemss o Some) o Comment.ignore);
   239 val have_facts = ProofHistory.apply o local_have_thmss (Proof.have_thmss []) o Comment.ignore;
   240 val have_facts = ProofHistory.apply o local_have_thmss (Proof.have_thmss []) o Comment.ignore;
   240 val have_facts_i = ProofHistory.apply o have_thmss_i (Proof.have_thmss []) o Comment.ignore;
   241 val have_facts_i = ProofHistory.apply o gen_have_thmss_i (Proof.have_thmss []) o Comment.ignore;
   241 
   242 
   242 
   243 
   243 (* forward chaining *)
   244 (* forward chaining *)
   244 
   245 
   245 fun gen_from_facts f = ProofHistory.apply o (Proof.chain oo curry f ("", []));
   246 fun gen_from_facts f = ProofHistory.apply o (Proof.chain oo curry f ("", []));
   246 
   247 
   247 fun add_thmss name atts ths_atts state =
   248 fun add_thmss name atts ths_atts state =
   248   Proof.have_thmss (Proof.the_facts state) name atts ths_atts state;
   249   Proof.have_thmss (Proof.the_facts state) name atts ths_atts state;
   249 
   250 
   250 val from_facts = gen_from_facts (local_have_thmss (Proof.have_thmss [])) o Comment.ignore;
   251 val from_facts = gen_from_facts (local_have_thmss (Proof.have_thmss [])) o Comment.ignore;
   251 val from_facts_i = gen_from_facts (have_thmss_i (Proof.have_thmss [])) o Comment.ignore;
   252 val from_facts_i = gen_from_facts (gen_have_thmss_i (Proof.have_thmss [])) o Comment.ignore;
   252 val with_facts = gen_from_facts (local_have_thmss add_thmss) o Comment.ignore;
   253 val with_facts = gen_from_facts (local_have_thmss add_thmss) o Comment.ignore;
   253 val with_facts_i = gen_from_facts (have_thmss_i add_thmss) o Comment.ignore;
   254 val with_facts_i = gen_from_facts (gen_have_thmss_i add_thmss) o Comment.ignore;
   254 
   255 
   255 fun chain comment_ignore = ProofHistory.apply Proof.chain;
   256 fun chain comment_ignore = ProofHistory.apply Proof.chain;
   256 fun export_chain comment_ignore = ProofHistory.applys Proof.export_chain;
   257 fun export_chain comment_ignore = ProofHistory.applys Proof.export_chain;
   257 
   258 
   258 
   259 
   381   if int then Pretty.writeln (Pretty.big_list "calculation:" [Proof.pretty_thm thm])
   382   if int then Pretty.writeln (Pretty.big_list "calculation:" [Proof.pretty_thm thm])
   382   else ();
   383   else ();
   383 
   384 
   384 fun proof''' f = Toplevel.proof' (f o cond_print_calc);
   385 fun proof''' f = Toplevel.proof' (f o cond_print_calc);
   385 
   386 
       
   387 fun gen_calc get f (args, _) prt state =
       
   388   f (apsome (fn (srcs, _) => get srcs state) args) prt state;
       
   389 
       
   390 in
       
   391 
   386 fun get_thmss srcs = Proof.the_facts o local_have_thmss (Proof.have_thmss []) (("", []), srcs); 
   392 fun get_thmss srcs = Proof.the_facts o local_have_thmss (Proof.have_thmss []) (("", []), srcs); 
   387 fun get_thmss_i thms _ = thms;
   393 fun get_thmss_i thms _ = thms;
   388 
       
   389 fun gen_calc get f (args, _) prt state =
       
   390   f (apsome (fn (srcs, _) => get srcs state) args) prt state;
       
   391 
       
   392 in
       
   393 
   394 
   394 fun also x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.also x);
   395 fun also x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.also x);
   395 fun also_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.also x);
   396 fun also_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.also x);
   396 fun finally x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.finally x);
   397 fun finally x = proof''' (ProofHistory.applys o gen_calc get_thmss Calculation.finally x);
   397 fun finally_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.finally x);
   398 fun finally_i x = proof''' (ProofHistory.applys o gen_calc get_thmss_i Calculation.finally x);