src/Pure/old_goals.ML
author wenzelm
Sat, 21 Jan 2006 23:02:14 +0100
changeset 18728 6790126ab5f6
parent 18678 dd0c569fa43d
child 19053 358c0eb6d785
permissions -rw-r--r--
simplified type attribute;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
18120
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/old_goals.ML
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     5
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     6
Old-style goal stack package.  The goal stack initially holds a dummy
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     7
proof, and can never become empty.  Each goal stack consists of a list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     8
of levels.  The undo list is a list of goal stacks.  Finally, there
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
     9
may be a stack of pending proofs.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    10
*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    11
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    12
signature GOALS =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    13
sig
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    14
  val premises: unit -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    15
  val prove_goal: theory -> string -> (thm list -> tactic list) -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    16
  val prove_goalw: theory -> thm list -> string -> (thm list -> tactic list) -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    17
  val disable_pr: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    18
  val enable_pr: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    19
  val topthm: unit -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    20
  val result: unit -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    21
  val uresult: unit -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    22
  val getgoal: int -> term
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    23
  val gethyps: int -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    24
  val prlev: int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    25
  val pr: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    26
  val prlim: int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    27
  val goal: theory -> string -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    28
  val goalw: theory -> thm list -> string -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    29
  val Goal: string -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    30
  val Goalw: thm list -> string -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    31
  val by: tactic -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    32
  val back: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    33
  val choplev: int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    34
  val chop: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    35
  val undo: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    36
  val bind_thm: string * thm -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    37
  val bind_thms: string * thm list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    38
  val qed: string -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    39
  val qed_goal: string -> theory -> string -> (thm list -> tactic list) -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    40
  val qed_goalw: string -> theory -> thm list -> string
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    41
    -> (thm list -> tactic list) -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    42
  val qed_spec_mp: string -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    43
  val qed_goal_spec_mp: string -> theory -> string -> (thm list -> tactic list) -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    44
  val qed_goalw_spec_mp: string -> theory -> thm list -> string
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    45
    -> (thm list -> tactic list) -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    46
  val no_qed: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    47
  val thms_containing: xstring list -> (string * thm) list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    48
end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    49
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    50
signature OLD_GOALS =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    51
sig
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    52
  include GOALS
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    53
  val legacy: bool ref
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    54
  type proof
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    55
  val reset_goals: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    56
  val result_error_fn: (thm -> string -> thm) ref
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    57
  val print_sign_exn: theory -> exn -> 'a
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    58
  val prove_goalw_cterm: thm list->cterm->(thm list->tactic list)->thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    59
  val prove_goalw_cterm_nocheck: thm list->cterm->(thm list->tactic list)->thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    60
  val quick_and_dirty_prove_goalw_cterm: theory -> thm list -> cterm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    61
    -> (thm list -> tactic list) -> thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    62
  val print_exn: exn -> 'a
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    63
  val filter_goal: (term*term->bool) -> thm list -> int -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    64
  val goalw_cterm: thm list -> cterm -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    65
  val simple_prove_goal_cterm: cterm->(thm list->tactic list)->thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    66
  val byev: tactic list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    67
  val save_proof: unit -> proof
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    68
  val restore_proof: proof -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    69
  val push_proof: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    70
  val pop_proof: unit -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    71
  val rotate_proof: unit -> thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    72
  val bws: thm list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    73
  val bw: thm -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    74
  val brs: thm list -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    75
  val br: thm -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    76
  val bes: thm list -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    77
  val be: thm -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    78
  val bds: thm list -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    79
  val bd: thm -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    80
  val ba: int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    81
  val ren: string -> int -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    82
  val frs: thm list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    83
  val fr: thm -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    84
  val fes: thm list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    85
  val fe: thm -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    86
  val fds: thm list -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    87
  val fd: thm -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    88
  val fa: unit -> unit
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    89
end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    90
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    91
structure OldGoals: OLD_GOALS =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    92
struct
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    93
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    94
val legacy = ref false;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    95
fun warn_obsolete () = if ! legacy then () else warning "Obsolete goal command encountered";
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    96
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    97
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    98
(*** Goal package ***)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
    99
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   100
(*Each level of goal stack includes a proof state and alternative states,
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   101
  the output of the tactic applied to the preceeding level.  *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   102
type gstack = (thm * thm Seq.seq) list;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   103
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   104
datatype proof = Proof of gstack list * thm list * (bool*thm->thm);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   105
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   106
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   107
(*** References ***)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   108
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   109
(*Current assumption list -- set by "goal".*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   110
val curr_prems = ref([] : thm list);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   111
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   112
(*Return assumption list -- useful if you didn't save "goal"'s result. *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   113
fun premises() = !curr_prems;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   114
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   115
(*Current result maker -- set by "goal", used by "result".  *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   116
fun init_mkresult _ = error "No goal has been supplied in subgoal module";
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   117
val curr_mkresult = ref (init_mkresult: bool*thm->thm);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   118
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   119
val dummy = Thm.trivial (read_cterm ProtoPure.thy ("PROP No_goal_has_been_supplied", propT));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   120
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   121
(*List of previous goal stacks, for the undo operation.  Set by setstate.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   122
  A list of lists!*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   123
val undo_list = ref([[(dummy, Seq.empty)]] : gstack list);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   124
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   125
(* Stack of proof attempts *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   126
val proofstack = ref([]: proof list);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   127
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   128
(*reset all refs*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   129
fun reset_goals () =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   130
  (curr_prems := []; curr_mkresult := init_mkresult;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   131
    undo_list := [[(dummy, Seq.empty)]]);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   132
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   133
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   134
(*** Setting up goal-directed proof ***)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   135
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   136
(*Generates the list of new theories when the proof state's theory changes*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   137
fun thy_error (thy,thy') =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   138
  let val names = Context.names_of thy' \\ Context.names_of thy
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   139
  in  case names of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   140
        [name] => "\nNew theory: " ^ name
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   141
      | _       => "\nNew theories: " ^ space_implode ", " names
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   142
  end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   143
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   144
(*Default action is to print an error message; could be suppressed for
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   145
  special applications.*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   146
fun result_error_default state msg : thm =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   147
  Pretty.str "Bad final proof state:" :: Display.pretty_goals (!goals_limit) state @
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   148
    [Pretty.str msg, Pretty.str "Proof failed!"] |> Pretty.chunks |> Pretty.string_of |> error;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   149
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   150
val result_error_fn = ref result_error_default;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   151
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   152
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   153
(*Common treatment of "goal" and "prove_goal":
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   154
  Return assumptions, initial proof state, and function to make result.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   155
  "atomic" indicates if the goal should be wrapped up in the function
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   156
  "Goal::prop=>prop" to avoid assumptions being returned separately.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   157
*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   158
fun prepare_proof atomic rths chorn =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   159
  let
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   160
      val _ = warn_obsolete ();
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   161
      val {thy, t=horn,...} = rep_cterm chorn;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   162
      val _ = Term.no_dummy_patterns horn handle TERM (msg, _) => error msg;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   163
      val (As, B) = Logic.strip_horn horn;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   164
      val atoms = atomic andalso
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   165
            forall (fn t => not(Logic.is_implies t orelse Logic.is_all t)) As;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   166
      val (As,B) = if atoms then ([],horn) else (As,B);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   167
      val cAs = map (cterm_of thy) As;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   168
      val prems = map (rewrite_rule rths o forall_elim_vars 0 o Thm.assume) cAs;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   169
      val cB = cterm_of thy B;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   170
      val st0 = let val st = Goal.init cB |> fold Thm.weaken cAs
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   171
                in  rewrite_goals_rule rths st end
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   172
      (*discharges assumptions from state in the order they appear in goal;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   173
        checks (if requested) that resulting theorem is equivalent to goal. *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   174
      fun mkresult (check,state) =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   175
        let val state = Seq.hd (flexflex_rule state)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   176
                        handle THM _ => state   (*smash flexflex pairs*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   177
            val ngoals = nprems_of state
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   178
            val ath = implies_intr_list cAs state
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   179
            val th = Goal.conclude ath
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   180
            val {hyps,prop,thy=thy',...} = rep_thm th
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   181
            val final_th = standard th
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   182
        in  if not check then final_th
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   183
            else if not (eq_thy(thy,thy')) then !result_error_fn state
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   184
                ("Theory of proof state has changed!" ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   185
                 thy_error (thy,thy'))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   186
            else if ngoals>0 then !result_error_fn state
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   187
                (string_of_int ngoals ^ " unsolved goals!")
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   188
            else if not (null hyps) then !result_error_fn state
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   189
                ("Additional hypotheses:\n" ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   190
                 cat_lines (map (Sign.string_of_term thy) hyps))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   191
            else if Pattern.matches thy
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   192
                                    (Envir.beta_norm (term_of chorn), Envir.beta_norm prop)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   193
                 then final_th
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   194
            else  !result_error_fn state "proved a different theorem"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   195
        end
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   196
  in
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   197
     if eq_thy(thy, Thm.theory_of_thm st0)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   198
     then (prems, st0, mkresult)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   199
     else error ("Definitions would change the proof state's theory" ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   200
                 thy_error (thy, Thm.theory_of_thm st0))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   201
  end
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   202
  handle THM(s,_,_) => error("prepare_proof: exception THM was raised!\n" ^ s);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   203
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   204
(*Prints exceptions readably to users*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   205
fun print_sign_exn_unit thy e =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   206
  case e of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   207
     THM (msg,i,thms) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   208
         (writeln ("Exception THM " ^ string_of_int i ^ " raised:\n" ^ msg);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   209
          List.app print_thm thms)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   210
   | THEORY (msg,thys) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   211
         (writeln ("Exception THEORY raised:\n" ^ msg);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   212
          List.app (writeln o Context.str_of_thy) thys)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   213
   | TERM (msg,ts) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   214
         (writeln ("Exception TERM raised:\n" ^ msg);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   215
          List.app (writeln o Sign.string_of_term thy) ts)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   216
   | TYPE (msg,Ts,ts) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   217
         (writeln ("Exception TYPE raised:\n" ^ msg);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   218
          List.app (writeln o Sign.string_of_typ thy) Ts;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   219
          List.app (writeln o Sign.string_of_term thy) ts)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   220
   | e => raise e;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   221
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   222
(*Prints an exception, then fails*)
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18120
diff changeset
   223
fun print_sign_exn thy e = (print_sign_exn_unit thy e; raise ERROR "");
18120
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   224
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   225
(** the prove_goal.... commands
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   226
    Prove theorem using the listed tactics; check it has the specified form.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   227
    Augment theory with all type assignments of goal.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   228
    Syntax is similar to "goal" command for easy keyboard use. **)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   229
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   230
(*Version taking the goal as a cterm*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   231
fun prove_goalw_cterm_general check rths chorn tacsf =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   232
  let val (prems, st0, mkresult) = prepare_proof false rths chorn
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   233
      val tac = EVERY (tacsf prems)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   234
      fun statef() =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   235
          (case Seq.pull (tac st0) of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   236
               SOME(st,_) => st
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   237
             | _ => error ("prove_goal: tactic failed"))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   238
  in  mkresult (check, cond_timeit (!Output.timing) statef)  end
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   239
  handle e => (print_sign_exn_unit (#thy (rep_cterm chorn)) e;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   240
               writeln ("The exception above was raised for\n" ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   241
                      Display.string_of_cterm chorn); raise e);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   242
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   243
(*Two variants: one checking the result, one not.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   244
  Neither prints runtime messages: they are for internal packages.*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   245
fun prove_goalw_cterm rths chorn =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   246
        setmp Output.timing false (prove_goalw_cterm_general true rths chorn)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   247
and prove_goalw_cterm_nocheck rths chorn =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   248
        setmp Output.timing false (prove_goalw_cterm_general false rths chorn);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   249
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   250
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   251
(*Version taking the goal as a string*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   252
fun prove_goalw thy rths agoal tacsf =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   253
  let val chorn = read_cterm thy (agoal, propT)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   254
  in prove_goalw_cterm_general true rths chorn tacsf end
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18120
diff changeset
   255
  handle ERROR msg => cat_error msg (*from read_cterm?*)
18120
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   256
                ("The error(s) above occurred for " ^ quote agoal);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   257
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   258
(*String version with no meta-rewrite-rules*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   259
fun prove_goal thy = prove_goalw thy [];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   260
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   261
(*quick and dirty version (conditional)*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   262
fun quick_and_dirty_prove_goalw_cterm thy rews ct tacs =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   263
  prove_goalw_cterm rews ct
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   264
    (if ! quick_and_dirty then (K [SkipProof.cheat_tac thy]) else tacs);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   265
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   266
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   267
(*** Commands etc ***)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   268
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   269
(*Return the current goal stack, if any, from undo_list*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   270
fun getstate() : gstack = case !undo_list of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   271
      []   => error"No current state in subgoal module"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   272
    | x::_ => x;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   273
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   274
(*Pops the given goal stack*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   275
fun pop [] = error"Cannot go back past the beginning of the proof!"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   276
  | pop (pair::pairs) = (pair,pairs);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   277
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   278
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   279
(* Print a level of the goal stack -- subject to quiet mode *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   280
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   281
val quiet = ref false;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   282
fun disable_pr () = quiet := true;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   283
fun enable_pr () = quiet := false;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   284
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   285
fun print_top ((th, _), pairs) =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   286
  if ! quiet then ()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   287
  else ! Display.print_current_goals_fn (length pairs) (! goals_limit) th;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   288
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   289
(*Printing can raise exceptions, so the assignment occurs last.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   290
  Can do   setstate[(st,Seq.empty)]  to set st as the state.  *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   291
fun setstate newgoals =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   292
  (print_top (pop newgoals);  undo_list := newgoals :: !undo_list);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   293
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   294
(*Given a proof state transformation, return a command that updates
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   295
    the goal stack*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   296
fun make_command com = setstate (com (pop (getstate())));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   297
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   298
(*Apply a function on proof states to the current goal stack*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   299
fun apply_fun f = f (pop(getstate()));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   300
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   301
(*Return the top theorem, representing the proof state*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   302
fun topthm () = apply_fun  (fn ((th,_), _) => th);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   303
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   304
(*Return the final result.  *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   305
fun result () = !curr_mkresult (true, topthm());
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   306
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   307
(*Return the result UNCHECKED that it equals the goal -- for synthesis,
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   308
  answer extraction, or other instantiation of Vars *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   309
fun uresult () = !curr_mkresult (false, topthm());
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   310
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   311
(*Get subgoal i from goal stack*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   312
fun getgoal i = Logic.get_goal (prop_of (topthm())) i;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   313
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   314
(*Return subgoal i's hypotheses as meta-level assumptions.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   315
  For debugging uses of METAHYPS*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   316
local exception GETHYPS of thm list
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   317
in
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   318
fun gethyps i =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   319
    (METAHYPS (fn hyps => raise (GETHYPS hyps)) i (topthm());  [])
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   320
    handle GETHYPS hyps => hyps
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   321
end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   322
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   323
(*Prints exceptions nicely at top level;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   324
  raises the exception in order to have a polymorphic type!*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   325
fun print_exn e = (print_sign_exn_unit (Thm.theory_of_thm (topthm())) e;  raise e);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   326
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   327
(*Which thms could apply to goal i? (debugs tactics involving filter_thms) *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   328
fun filter_goal could ths i = filter_thms could (999, getgoal i, ths);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   329
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   330
(*For inspecting earlier levels of the backward proof*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   331
fun chop_level n (pair,pairs) =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   332
  let val level = length pairs
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   333
  in  if n<0 andalso ~n <= level
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   334
      then  List.drop (pair::pairs, ~n)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   335
      else if 0<=n andalso n<= level
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   336
      then  List.drop (pair::pairs, level - n)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   337
      else  error ("Level number must lie between 0 and " ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   338
                   string_of_int level)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   339
  end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   340
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   341
(*Print the given level of the proof; prlev ~1 prints previous level*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   342
fun prlev n = (enable_pr (); apply_fun (print_top o pop o (chop_level n)));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   343
fun pr () = (enable_pr (); apply_fun print_top);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   344
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   345
(*Set goals_limit and print again*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   346
fun prlim n = (goals_limit:=n; pr());
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   347
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   348
(** the goal.... commands
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   349
    Read main goal.  Set global variables curr_prems, curr_mkresult.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   350
    Initial subgoal and premises are rewritten using rths. **)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   351
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   352
(*Version taking the goal as a cterm; if you have a term t and theory thy, use
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   353
    goalw_cterm rths (cterm_of thy t);      *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   354
fun agoalw_cterm atomic rths chorn =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   355
  let val (prems, st0, mkresult) = prepare_proof atomic rths chorn
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   356
  in  undo_list := [];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   357
      setstate [ (st0, Seq.empty) ];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   358
      curr_prems := prems;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   359
      curr_mkresult := mkresult;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   360
      prems
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   361
  end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   362
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   363
val goalw_cterm = agoalw_cterm false;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   364
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   365
(*Version taking the goal as a string*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   366
fun agoalw atomic thy rths agoal =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   367
    agoalw_cterm atomic rths (read_cterm thy (agoal, propT))
18678
dd0c569fa43d sane ERROR handling;
wenzelm
parents: 18120
diff changeset
   368
    handle ERROR msg => cat_error msg (*from type_assign, etc via prepare_proof*)
18120
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   369
        ("The error(s) above occurred for " ^ quote agoal);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   370
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   371
val goalw = agoalw false;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   372
fun goal thy = goalw thy [];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   373
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   374
(*now the versions that wrap the goal up in `Goal' to make it atomic*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   375
fun Goalw thms s = agoalw true (Context.the_context ()) thms s;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   376
val Goal = Goalw [];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   377
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   378
(*simple version with minimal amount of checking and postprocessing*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   379
fun simple_prove_goal_cterm G f =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   380
  let
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   381
    val _ = warn_obsolete ();
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   382
    val As = Drule.strip_imp_prems G;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   383
    val B = Drule.strip_imp_concl G;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   384
    val asms = map (Goal.norm_hhf o Thm.assume) As;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   385
    fun check NONE = error "prove_goal: tactic failed"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   386
      | check (SOME (thm, _)) = (case nprems_of thm of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   387
            0 => thm
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   388
          | i => !result_error_fn thm (string_of_int i ^ " unsolved goals!"))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   389
  in
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   390
    standard (implies_intr_list As
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   391
      (check (Seq.pull (EVERY (f asms) (trivial B)))))
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   392
  end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   393
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   394
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   395
(*Proof step "by" the given tactic -- apply tactic to the proof state*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   396
fun by_com tac ((th,ths), pairs) : gstack =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   397
  (case  Seq.pull(tac th)  of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   398
     NONE      => error"by: tactic failed"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   399
   | SOME(th2,ths2) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   400
       (if eq_thm(th,th2)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   401
          then warning "Warning: same as previous level"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   402
          else if eq_thm_thy(th,th2) then ()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   403
          else warning ("Warning: theory of proof state has changed" ^
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   404
                       thy_error (Thm.theory_of_thm th, Thm.theory_of_thm th2));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   405
       ((th2,ths2)::(th,ths)::pairs)));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   406
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   407
fun by tac = cond_timeit (!Output.timing)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   408
    (fn() => make_command (by_com tac));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   409
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   410
(* byev[tac1,...,tacn] applies tac1 THEN ... THEN tacn.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   411
   Good for debugging proofs involving prove_goal.*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   412
val byev = by o EVERY;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   413
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   414
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   415
(*Backtracking means find an alternative result from a tactic.
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   416
  If none at this level, try earlier levels*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   417
fun backtrack [] = error"back: no alternatives"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   418
  | backtrack ((th,thstr) :: pairs) =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   419
     (case Seq.pull thstr of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   420
          NONE      => (writeln"Going back a level..."; backtrack pairs)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   421
        | SOME(th2,thstr2) =>
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   422
           (if eq_thm(th,th2)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   423
              then warning "Warning: same as previous choice at this level"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   424
              else if eq_thm_thy(th,th2) then ()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   425
              else warning "Warning: theory of proof state has changed";
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   426
            (th2,thstr2)::pairs));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   427
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   428
fun back() = setstate (backtrack (getstate()));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   429
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   430
(*Chop back to previous level of the proof*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   431
fun choplev n = make_command (chop_level n);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   432
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   433
(*Chopping back the goal stack*)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   434
fun chop () = make_command (fn (_,pairs) => pairs);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   435
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   436
(*Restore the previous proof state;  discard current state. *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   437
fun undo() = case !undo_list of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   438
      [] => error"No proof state"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   439
    | [_] => error"Already at initial state"
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   440
    | _::newundo =>  (undo_list := newundo;  pr()) ;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   441
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   442
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   443
(*** Managing the proof stack ***)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   444
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   445
fun save_proof() = Proof(!undo_list, !curr_prems, !curr_mkresult);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   446
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   447
fun restore_proof(Proof(ul,prems,mk)) =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   448
 (undo_list:= ul;  curr_prems:= prems;  curr_mkresult := mk;  prems);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   449
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   450
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   451
fun top_proof() = case !proofstack of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   452
        [] => error("Stack of proof attempts is empty!")
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   453
    | p::ps => (p,ps);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   454
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   455
(*  push a copy of the current proof state on to the stack *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   456
fun push_proof() = (proofstack := (save_proof() :: !proofstack));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   457
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   458
(* discard the top proof state of the stack *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   459
fun pop_proof() =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   460
  let val (p,ps) = top_proof()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   461
      val prems = restore_proof p
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   462
  in proofstack := ps;  pr();  prems end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   463
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   464
(* rotate the stack so that the top element goes to the bottom *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   465
fun rotate_proof() = let val (p,ps) = top_proof()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   466
                    in proofstack := ps@[save_proof()];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   467
                       restore_proof p;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   468
                       pr();
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   469
                       !curr_prems
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   470
                    end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   471
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   472
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   473
(** Shortcuts for commonly-used tactics **)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   474
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   475
fun bws rls = by (rewrite_goals_tac rls);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   476
fun bw rl = bws [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   477
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   478
fun brs rls i = by (resolve_tac rls i);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   479
fun br rl = brs [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   480
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   481
fun bes rls i = by (eresolve_tac rls i);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   482
fun be rl = bes [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   483
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   484
fun bds rls i = by (dresolve_tac rls i);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   485
fun bd rl = bds [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   486
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   487
fun ba i = by (assume_tac i);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   488
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   489
fun ren str i = by (rename_tac str i);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   490
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   491
(** Shortcuts to work on the first applicable subgoal **)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   492
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   493
fun frs rls = by (FIRSTGOAL (trace_goalno_tac (resolve_tac rls)));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   494
fun fr rl = frs [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   495
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   496
fun fes rls = by (FIRSTGOAL (trace_goalno_tac (eresolve_tac rls)));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   497
fun fe rl = fes [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   498
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   499
fun fds rls = by (FIRSTGOAL (trace_goalno_tac (dresolve_tac rls)));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   500
fun fd rl = fds [rl];
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   501
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   502
fun fa() = by (FIRSTGOAL (trace_goalno_tac assume_tac));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   503
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   504
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   505
(** theorem database operations **)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   506
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   507
(* store *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   508
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   509
fun bind_thm (name, thm) = ThmDatabase.ml_store_thm (name, standard thm);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   510
fun bind_thms (name, thms) = ThmDatabase.ml_store_thms (name, map standard thms);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   511
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   512
fun qed name = ThmDatabase.ml_store_thm (name, result ());
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   513
fun qed_goal name thy goal tacsf = ThmDatabase.ml_store_thm (name, prove_goal thy goal tacsf);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   514
fun qed_goalw name thy rews goal tacsf =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   515
  ThmDatabase.ml_store_thm (name, prove_goalw thy rews goal tacsf);
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   516
fun qed_spec_mp name =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   517
  ThmDatabase.ml_store_thm (name, ObjectLogic.rulify_no_asm (result ()));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   518
fun qed_goal_spec_mp name thy s p =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   519
  bind_thm (name, ObjectLogic.rulify_no_asm (prove_goal thy s p));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   520
fun qed_goalw_spec_mp name thy defs s p =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   521
  bind_thm (name, ObjectLogic.rulify_no_asm (prove_goalw thy defs s p));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   522
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   523
fun no_qed () = ();
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   524
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   525
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   526
(* retrieve *)
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   527
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   528
fun thms_containing raw_consts =
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   529
  let
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   530
    val thy = Thm.theory_of_thm (topthm ());
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   531
    val consts = map (Sign.intern_const thy) raw_consts;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   532
  in
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   533
    (case List.filter (is_none o Sign.const_type thy) consts of
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   534
      [] => ()
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   535
    | cs => error ("thms_containing: undeclared consts " ^ commas_quote cs));
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   536
    PureThy.thms_containing_consts thy consts
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   537
  end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   538
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   539
end;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   540
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   541
structure Goals: GOALS = OldGoals;
41328805d4db renamed goals.ML to old_goals.ML;
wenzelm
parents:
diff changeset
   542
open Goals;