src/Pure/context_tactic.ML
author wenzelm
Tue, 13 Aug 2019 10:27:21 +0200
changeset 70520 11d8517d9384
child 70521 9ddd66d53130
permissions -rw-r--r--
clarified modules;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
70520
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/context_tactic.ML
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     3
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     4
Tactics with proof context / cases -- as basis for Isar proof methods.
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     5
*)
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     6
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     7
infix 1 CONTEXT_THEN_ALL_NEW;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     8
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
     9
signature BASIC_CONTEXT_TACTIC =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    10
sig
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    11
  type context_state = Proof.context * thm
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    12
  type context_tactic = context_state -> context_state Seq.result Seq.seq
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    13
  val TACTIC_CONTEXT: Proof.context -> thm Seq.seq -> context_state Seq.result Seq.seq
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    14
  val CONTEXT_TACTIC: tactic -> context_tactic
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    15
  val NO_CONTEXT_TACTIC: Proof.context -> context_tactic -> tactic
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    16
  val CONTEXT_CASES: Rule_Cases.cases -> tactic -> context_tactic
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    17
  val CONTEXT_SUBGOAL: (term * int -> context_tactic) -> int -> context_tactic
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    18
  val CONTEXT_THEN_ALL_NEW: (int -> context_tactic) * (int -> tactic) -> int -> context_tactic
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    19
end;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    20
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    21
signature CONTEXT_TACTIC =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    22
sig
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    23
  include BASIC_CONTEXT_TACTIC
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    24
end;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    25
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    26
structure Context_Tactic: CONTEXT_TACTIC =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    27
struct
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    28
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    29
type context_state = Proof.context * thm;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    30
type context_tactic = context_state -> context_state Seq.result Seq.seq;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    31
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    32
fun TACTIC_CONTEXT ctxt : thm Seq.seq -> context_state Seq.result Seq.seq =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    33
  Seq.map (Seq.Result o pair ctxt);
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    34
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    35
fun CONTEXT_TACTIC tac : context_tactic =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    36
  fn (ctxt, st) => TACTIC_CONTEXT ctxt (tac st);
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    37
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    38
fun NO_CONTEXT_TACTIC ctxt (tac: context_tactic) st =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    39
  tac (ctxt, st) |> Seq.filter_results |> Seq.map snd;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    40
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    41
fun CONTEXT_CASES cases tac : context_tactic =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    42
  fn (ctxt, st) => TACTIC_CONTEXT (Proof_Context.update_cases cases ctxt) (tac st);
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    43
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    44
fun CONTEXT_SUBGOAL tac i : context_tactic =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    45
  fn (ctxt, st) =>
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    46
    (case try Logic.nth_prem (i, Thm.prop_of st) of
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    47
      SOME goal => tac (goal, i) (ctxt, st)
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    48
    | NONE => Seq.empty);
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    49
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    50
fun (tac1 CONTEXT_THEN_ALL_NEW tac2) i : context_tactic =
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    51
  fn (ctxt, st) =>
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    52
    (ctxt, st) |> tac1 i |> Seq.maps_results (fn (ctxt', st') =>
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    53
      TACTIC_CONTEXT ctxt' ((Seq.INTERVAL tac2 i (i + Thm.nprems_of st' - Thm.nprems_of st)) st'));
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    54
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    55
end;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    56
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    57
structure Basic_Context_Tactic: BASIC_CONTEXT_TACTIC = Context_Tactic;
11d8517d9384 clarified modules;
wenzelm
parents:
diff changeset
    58
open Basic_Context_Tactic;