src/Pure/subgoal.ML
author wenzelm
Wed Jul 26 19:37:42 2006 +0200 (2006-07-26)
changeset 20219 3bff4719f3d6
parent 20210 8fe4ae4360eb
child 20231 dcdd565a7fbe
permissions -rw-r--r--
focus: result record includes (fixed) schematic variables;
SUBGOAL: disallow pending subgoals, more robust re-composition;
wenzelm@20210
     1
(*  Title:      Pure/subgoal.ML
wenzelm@20210
     2
    ID:         $Id$
wenzelm@20210
     3
    Author:     Makarius
wenzelm@20210
     4
wenzelm@20210
     5
Tactical operations depending on local subgoal structure.
wenzelm@20210
     6
*)
wenzelm@20210
     7
wenzelm@20210
     8
signature BASIC_SUBGOAL =
wenzelm@20210
     9
sig
wenzelm@20210
    10
  val SUBPROOF: Proof.context ->
wenzelm@20219
    11
    ({context: Proof.context, schematics: ctyp list * cterm list,
wenzelm@20219
    12
      params: cterm list, asms: cterm list, concl: cterm,
wenzelm@20219
    13
      prems: thm list} -> tactic) -> int -> tactic
wenzelm@20210
    14
end
wenzelm@20210
    15
wenzelm@20210
    16
signature SUBGOAL =
wenzelm@20210
    17
sig
wenzelm@20210
    18
  include BASIC_SUBGOAL
wenzelm@20210
    19
  val focus: Proof.context -> int -> thm ->
wenzelm@20219
    20
   {context: Proof.context, schematics: ctyp list * cterm list,
wenzelm@20219
    21
    params: cterm list, asms: cterm list, concl: cterm, prems: thm list} * thm
wenzelm@20210
    22
wenzelm@20210
    23
end;
wenzelm@20210
    24
wenzelm@20210
    25
structure Subgoal: SUBGOAL =
wenzelm@20210
    26
struct
wenzelm@20210
    27
wenzelm@20210
    28
(* canonical proof decomposition -- similar to fix/assume/show *)
wenzelm@20210
    29
wenzelm@20210
    30
fun focus ctxt i st =
wenzelm@20210
    31
  let
wenzelm@20219
    32
    val ((schematics, [st']), ctxt') = Variable.import true [Goal.norm_hhf st] ctxt;
wenzelm@20210
    33
    val ((params, goal), ctxt'') = Variable.focus (Thm.cprem_of st' i) ctxt';
wenzelm@20210
    34
    val asms = Drule.strip_imp_prems goal;
wenzelm@20210
    35
    val concl = Drule.strip_imp_concl goal;
wenzelm@20210
    36
    val (prems, context) = ProofContext.add_assumes asms ctxt'';
wenzelm@20210
    37
  in
wenzelm@20219
    38
    ({context = context, schematics = schematics, params = params,
wenzelm@20219
    39
      asms = asms, concl = concl, prems = prems}, Goal.init concl)
wenzelm@20210
    40
  end;
wenzelm@20210
    41
wenzelm@20210
    42
fun SUBPROOF ctxt tac i st =
wenzelm@20210
    43
  if Thm.nprems_of st < i then Seq.empty
wenzelm@20210
    44
  else
wenzelm@20210
    45
    let
wenzelm@20219
    46
      val (args as {context, params, ...}, st') = focus ctxt i st;
wenzelm@20219
    47
      fun export_closed th =
wenzelm@20219
    48
        let
wenzelm@20219
    49
          val (th' :: params') = ProofContext.export context ctxt (th :: map Drule.mk_term params);
wenzelm@20219
    50
          val vs = map (#2 o Thm.dest_comb o Drule.strip_imp_concl o Thm.cprop_of) params';
wenzelm@20219
    51
        in Drule.forall_intr_list vs th' end;
wenzelm@20219
    52
      fun retrofit th = Thm.compose_no_flatten false (th, 0) i;
wenzelm@20219
    53
    in Seq.lifts retrofit (Seq.map (Goal.finish #> export_closed) (tac args st')) st end
wenzelm@20210
    54
wenzelm@20210
    55
end;
wenzelm@20210
    56
wenzelm@20210
    57
structure BasicSubgoal: BASIC_SUBGOAL = Subgoal;
wenzelm@20210
    58
open BasicSubgoal;