src/Pure/Isar/method.ML
changeset 8195 af2575a5c5ae
parent 8167 7574835ed01e
child 8205 9f0ff98f37f6
equal deleted inserted replaced
8194:0c5d9d23b715 8195:af2575a5c5ae
    39   val multi_resolves: thm list -> thm list -> thm Seq.seq
    39   val multi_resolves: thm list -> thm list -> thm Seq.seq
    40   val rule_tac: thm list -> thm list -> int -> tactic
    40   val rule_tac: thm list -> thm list -> int -> tactic
    41   val erule_tac: thm list -> thm list -> int -> tactic
    41   val erule_tac: thm list -> thm list -> int -> tactic
    42   val rule: thm list -> Proof.method
    42   val rule: thm list -> Proof.method
    43   val erule: thm list -> Proof.method
    43   val erule: thm list -> Proof.method
       
    44   val this: Proof.method
    44   val assumption: Proof.context -> Proof.method
    45   val assumption: Proof.context -> Proof.method
    45   exception METHOD_FAIL of (string * Position.T) * exn
    46   exception METHOD_FAIL of (string * Position.T) * exn
    46   val help_methods: theory option -> unit
    47   val help_methods: theory option -> unit
    47   val method: theory -> Args.src -> Proof.context -> Proof.method
    48   val method: theory -> Args.src -> Proof.context -> Proof.method
    48   val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
    49   val add_methods: (bstring * (Args.src -> Proof.context -> Proof.method) * string) list
   279 val some_erule = gen_rule' erule_tac;
   280 val some_erule = gen_rule' erule_tac;
   280 
   281 
   281 end;
   282 end;
   282 
   283 
   283 
   284 
   284 (* assumption / finish *)
   285 (* this *)
       
   286 
       
   287 val this = METHOD (EVERY o map (FINDGOAL o Tactic.rtac));
       
   288 
       
   289 
       
   290 (* assumption *)
   285 
   291 
   286 fun assm_tac ctxt =
   292 fun assm_tac ctxt =
   287   assume_tac APPEND' resolve_tac (filter Thm.no_prems (ProofContext.prems_of ctxt));
   293   assume_tac APPEND' resolve_tac (filter Thm.no_prems (ProofContext.prems_of ctxt));
   288 
   294 
   289 fun assumption_tac ctxt [] = assm_tac ctxt
   295 fun assumption_tac ctxt [] = assm_tac ctxt
   290   | assumption_tac _ [fact] = resolve_tac [fact]
   296   | assumption_tac _ [fact] = resolve_tac [fact]
   291   | assumption_tac _ _ = K no_tac;
   297   | assumption_tac _ _ = K no_tac;
   292 
   298 
   293 fun assumption ctxt = METHOD (FINDGOAL o assumption_tac ctxt);
   299 fun assumption ctxt = METHOD (FINDGOAL o assumption_tac ctxt);
   294 fun finish ctxt = METHOD (K (FILTER Thm.no_prems (ALLGOALS (assm_tac ctxt) THEN flexflex_tac)));
       
   295 
   300 
   296 
   301 
   297 
   302 
   298 (** methods theory data **)
   303 (** methods theory data **)
   299 
   304 
   456 
   461 
   457 
   462 
   458 (* structured proof steps *)
   463 (* structured proof steps *)
   459 
   464 
   460 val default_text = Source (Args.src (("default", []), Position.none));
   465 val default_text = Source (Args.src (("default", []), Position.none));
       
   466 val this_text = Basic (K this);
       
   467 
       
   468 fun finish ctxt = METHOD (K (FILTER Thm.no_prems (ALLGOALS (assm_tac ctxt) THEN flexflex_tac)));
   461 
   469 
   462 fun finish_text None = Basic finish
   470 fun finish_text None = Basic finish
   463   | finish_text (Some txt) = Then [txt, Basic finish];
   471   | finish_text (Some txt) = Then [txt, Basic finish];
   464 
   472 
   465 fun proof opt_text state =
   473 fun proof opt_text state =
   468   |> refine (if_none opt_text default_text)
   476   |> refine (if_none opt_text default_text)
   469   |> Seq.map Proof.enter_forward;
   477   |> Seq.map Proof.enter_forward;
   470 
   478 
   471 fun local_qed opt_text = Proof.local_qed (refine (finish_text opt_text));
   479 fun local_qed opt_text = Proof.local_qed (refine (finish_text opt_text));
   472 fun local_terminal_proof (text, opt_text) pr = Seq.THEN (proof (Some text), local_qed opt_text pr);
   480 fun local_terminal_proof (text, opt_text) pr = Seq.THEN (proof (Some text), local_qed opt_text pr);
   473 val local_immediate_proof = local_terminal_proof (Basic assumption, None);
   481 val local_immediate_proof = local_terminal_proof (this_text, None);
   474 val local_default_proof = local_terminal_proof (default_text, None);
   482 val local_default_proof = local_terminal_proof (default_text, None);
   475 
   483 
   476 
   484 
   477 fun global_qeds opt_text = Proof.global_qed (refine (finish_text opt_text));
   485 fun global_qeds opt_text = Proof.global_qed (refine (finish_text opt_text));
   478 
   486 
   488   |> Proof.check_result "Terminal proof method failed" state
   496   |> Proof.check_result "Terminal proof method failed" state
   489   |> (Seq.flat o Seq.map (global_qeds opt_text))
   497   |> (Seq.flat o Seq.map (global_qeds opt_text))
   490   |> Proof.check_result "Failed to finish proof (after successful terminal method)" state
   498   |> Proof.check_result "Failed to finish proof (after successful terminal method)" state
   491   |> Seq.hd;
   499   |> Seq.hd;
   492 
   500 
   493 val global_immediate_proof = global_terminal_proof (Basic assumption, None);
   501 val global_immediate_proof = global_terminal_proof (this_text, None);
   494 val global_default_proof = global_terminal_proof (default_text, None);
   502 val global_default_proof = global_terminal_proof (default_text, None);
   495 
   503 
   496 
   504 
   497 
   505 
   498 (** theory setup **)
   506 (** theory setup **)
   507   ("unfold", thms_args unfold, "unfold definitions"),
   515   ("unfold", thms_args unfold, "unfold definitions"),
   508   ("fold", thms_args fold, "fold definitions"),
   516   ("fold", thms_args fold, "fold definitions"),
   509   ("default", thms_ctxt_args some_rule, "apply some rule"),
   517   ("default", thms_ctxt_args some_rule, "apply some rule"),
   510   ("rule", thms_ctxt_args some_rule, "apply some rule"),
   518   ("rule", thms_ctxt_args some_rule, "apply some rule"),
   511   ("erule", thms_ctxt_args some_erule, "apply some erule (improper!)"),
   519   ("erule", thms_ctxt_args some_erule, "apply some erule (improper!)"),
       
   520   ("this", no_args this, "apply current facts as rules"),
   512   ("assumption", ctxt_args assumption, "proof by assumption, preferring facts")];
   521   ("assumption", ctxt_args assumption, "proof by assumption, preferring facts")];
   513 
   522 
   514 
   523 
   515 (* setup *)
   524 (* setup *)
   516 
   525