src/Pure/goals.ML
author lcp
Tue Jul 25 17:03:16 1995 +0200 (1995-07-25 ago)
changeset 1194 563ecd14c1d8
parent 922 196ca0973a6d
child 1219 b1a04399f530
permissions -rw-r--r--
Added weak_eq_thm and forall_intr_vars (thanks to Mark Staples)
wenzelm@39
     1
(*  Title: 	Pure/goals.ML
clasohm@0
     2
    ID:         $Id$
clasohm@0
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
clasohm@0
     4
    Copyright   1993  University of Cambridge
clasohm@0
     5
clasohm@0
     6
Goal stack package.  The goal stack initially holds a dummy proof, and can
clasohm@0
     7
never become empty.  Each goal stack consists of a list of levels.  The
clasohm@0
     8
undo list is a list of goal stacks.  Finally, there may be a stack of
clasohm@0
     9
pending proofs.
clasohm@0
    10
*)
clasohm@0
    11
clasohm@0
    12
clasohm@0
    13
signature GOALS =
clasohm@0
    14
  sig
clasohm@0
    15
  structure Tactical: TACTICAL
clasohm@0
    16
  local open Tactical Tactical.Thm in
clasohm@0
    17
  type proof
lcp@577
    18
  val ba		: int -> unit
lcp@577
    19
  val back		: unit -> unit
lcp@577
    20
  val bd		: thm -> int -> unit
lcp@577
    21
  val bds		: thm list -> int -> unit
lcp@577
    22
  val be		: thm -> int -> unit
lcp@577
    23
  val bes		: thm list -> int -> unit
lcp@577
    24
  val br		: thm -> int -> unit
lcp@577
    25
  val brs		: thm list -> int -> unit
lcp@577
    26
  val bw		: thm -> unit
lcp@577
    27
  val bws		: thm list -> unit
lcp@577
    28
  val by		: tactic -> unit
lcp@577
    29
  val byev		: tactic list -> unit
lcp@577
    30
  val chop		: unit -> unit
lcp@577
    31
  val choplev		: int -> unit
lcp@577
    32
  val fa		: unit -> unit
lcp@577
    33
  val fd		: thm -> unit
lcp@577
    34
  val fds		: thm list -> unit
lcp@577
    35
  val fe		: thm -> unit
lcp@577
    36
  val fes		: thm list -> unit
lcp@577
    37
  val filter_goal	: (term*term->bool) -> thm list -> int -> thm list
lcp@577
    38
  val fr		: thm -> unit
lcp@577
    39
  val frs		: thm list -> unit
lcp@577
    40
  val getgoal		: int -> term
lcp@577
    41
  val gethyps		: int -> thm list
lcp@577
    42
  val goal		: theory -> string -> thm list
lcp@577
    43
  val goalw		: theory -> thm list -> string -> thm list
lcp@577
    44
  val goalw_cterm	: thm list -> cterm -> thm list
lcp@577
    45
  val pop_proof		: unit -> thm list
lcp@577
    46
  val pr		: unit -> unit
lcp@577
    47
  val premises		: unit -> thm list
lcp@577
    48
  val prin		: term -> unit
lcp@577
    49
  val printyp		: typ -> unit
lcp@577
    50
  val pprint_term	: term -> pprint_args -> unit
lcp@577
    51
  val pprint_typ	: typ -> pprint_args -> unit
lcp@577
    52
  val print_exn		: exn -> 'a
lcp@577
    53
  val print_sign_exn	: Sign.sg -> exn -> 'a
lcp@577
    54
  val prlev		: int -> unit
lcp@577
    55
  val proof_timing	: bool ref
lcp@577
    56
  val prove_goal	: theory -> string -> (thm list -> tactic list) -> thm
lcp@577
    57
  val prove_goalw      : theory->thm list->string->(thm list->tactic list)->thm
lcp@577
    58
  val prove_goalw_cterm	: thm list->cterm->(thm list->tactic list)->thm
lcp@577
    59
  val push_proof	: unit -> unit
lcp@577
    60
  val read		: string -> term
lcp@577
    61
  val ren		: string -> int -> unit
lcp@577
    62
  val restore_proof	: proof -> thm list
lcp@577
    63
  val result		: unit -> thm  
lcp@577
    64
  val rotate_proof	: unit -> thm list
lcp@577
    65
  val uresult		: unit -> thm  
lcp@577
    66
  val save_proof	: unit -> proof
lcp@577
    67
  val topthm		: unit -> thm
lcp@577
    68
  val undo		: unit -> unit
clasohm@0
    69
  end
clasohm@0
    70
  end;
clasohm@0
    71
clasohm@0
    72
functor GoalsFun (structure Logic: LOGIC and Drule: DRULE and Tactic: TACTIC
clasohm@0
    73
                        and Pattern:PATTERN
clasohm@0
    74
	  sharing type Pattern.type_sig = Drule.Thm.Sign.Type.type_sig
clasohm@0
    75
              and Drule.Thm = Tactic.Tactical.Thm) : GOALS =
clasohm@0
    76
struct
clasohm@0
    77
structure Tactical = Tactic.Tactical
clasohm@0
    78
local open Tactic Tactic.Tactical Tactic.Tactical.Thm Drule
clasohm@0
    79
in
clasohm@0
    80
clasohm@0
    81
(*Each level of goal stack includes a proof state and alternative states,
clasohm@0
    82
  the output of the tactic applied to the preceeding level.  *)
clasohm@0
    83
type gstack = (thm * thm Sequence.seq) list;
clasohm@0
    84
clasohm@0
    85
datatype proof = Proof of gstack list * thm list * (bool*thm->thm);
clasohm@0
    86
clasohm@0
    87
(*** References ***)
clasohm@0
    88
clasohm@0
    89
(*Should process time be printed after proof steps?*)
clasohm@0
    90
val proof_timing = ref false;
clasohm@0
    91
clasohm@0
    92
(*Current assumption list -- set by "goal".*)
clasohm@0
    93
val curr_prems = ref([] : thm list);
clasohm@0
    94
clasohm@0
    95
(*Return assumption list -- useful if you didn't save "goal"'s result. *)
clasohm@0
    96
fun premises() = !curr_prems;
clasohm@0
    97
clasohm@0
    98
(*Current result maker -- set by "goal", used by "result".  *)
clasohm@0
    99
val curr_mkresult = 
clasohm@0
   100
    ref((fn _=> error"No goal has been supplied in subgoal module") 
clasohm@0
   101
       : bool*thm->thm);
clasohm@0
   102
clasohm@922
   103
val dummy = trivial(read_cterm Sign.proto_pure 
clasohm@0
   104
    ("PROP No_goal_has_been_supplied",propT));
clasohm@0
   105
clasohm@0
   106
(*List of previous goal stacks, for the undo operation.  Set by setstate. 
clasohm@0
   107
  A list of lists!*)
clasohm@0
   108
val undo_list = ref([[(dummy, Sequence.null)]] : gstack list);
clasohm@0
   109
clasohm@0
   110
(* Stack of proof attempts *)
clasohm@0
   111
val proofstack = ref([]: proof list);
clasohm@0
   112
clasohm@0
   113
clasohm@0
   114
(*** Setting up goal-directed proof ***)
clasohm@0
   115
clasohm@0
   116
(*Generates the list of new theories when the proof state's signature changes*)
clasohm@0
   117
fun sign_error (sign,sign') =
clasohm@0
   118
  let val stamps = #stamps(Sign.rep_sg sign') \\ 
clasohm@0
   119
                   #stamps(Sign.rep_sg sign)
clasohm@0
   120
  in  case stamps of
clasohm@0
   121
        [stamp] => "\nNew theory: " ^ !stamp
clasohm@0
   122
      | _       => "\nNew theories: " ^ space_implode ", " (map ! stamps)
clasohm@0
   123
  end;
clasohm@0
   124
clasohm@0
   125
(*Common treatment of "goal" and "prove_goal":
clasohm@0
   126
  Return assumptions, initial proof state, and function to make result. *)
clasohm@0
   127
fun prepare_proof rths chorn =
lcp@230
   128
  let val {sign, t=horn,...} = rep_cterm chorn;
clasohm@0
   129
      val (_,As,B) = Logic.strip_horn(horn);
lcp@230
   130
      val cAs = map (cterm_of sign) As;
clasohm@0
   131
      val p_rew = if null rths then I else rewrite_rule rths;
clasohm@0
   132
      val c_rew = if null rths then I else rewrite_goals_rule rths;
clasohm@0
   133
      val prems = map (p_rew o forall_elim_vars(0) o assume) cAs
lcp@230
   134
      and st0 = c_rew (trivial (cterm_of sign B))
clasohm@0
   135
      fun result_error state msg = 
clasohm@0
   136
        (writeln ("Bad final proof state:");
lcp@68
   137
 	 !print_goals_ref (!goals_limit) state;
clasohm@0
   138
	 error msg)
clasohm@0
   139
      (*discharges assumptions from state in the order they appear in goal;
clasohm@0
   140
	checks (if requested) that resulting theorem is equivalent to goal. *)
clasohm@0
   141
      fun mkresult (check,state) =
lcp@696
   142
        let val state = Sequence.hd (flexflex_rule state)
lcp@696
   143
	    		handle _ => state   (*smash flexflex pairs*)
lcp@696
   144
	    val ngoals = nprems_of state
clasohm@0
   145
            val th = implies_intr_list cAs state
clasohm@0
   146
            val {hyps,prop,sign=sign',...} = rep_thm th
clasohm@0
   147
        in  if not check then standard th
wenzelm@253
   148
	    else if not (Sign.eq_sg(sign,sign')) then result_error state
clasohm@0
   149
		("Signature of proof state has changed!" ^
clasohm@0
   150
		 sign_error (sign,sign'))
clasohm@0
   151
            else if ngoals>0 then result_error state
clasohm@0
   152
		(string_of_int ngoals ^ " unsolved goals!")
clasohm@0
   153
            else if not (null hyps) then result_error state
clasohm@0
   154
                ("Additional hypotheses:\n" ^ 
clasohm@0
   155
                 cat_lines (map (Sign.string_of_term sign) hyps))
nipkow@678
   156
	    else if Pattern.matches (#tsig(Sign.rep_sg sign)) 
nipkow@678
   157
			            (term_of chorn, prop)
clasohm@0
   158
		 then  standard th 
clasohm@0
   159
	    else  result_error state "proved a different theorem"
clasohm@0
   160
        end
nipkow@678
   161
  in
nipkow@678
   162
     if Sign.eq_sg(sign, #sign(rep_thm st0))
clasohm@0
   163
     then (prems, st0, mkresult)
clasohm@0
   164
     else error ("Definitions would change the proof state's signature" ^
clasohm@0
   165
		 sign_error (sign, #sign(rep_thm st0)))
clasohm@0
   166
  end
clasohm@0
   167
  handle THM(s,_,_) => error("prepare_proof: exception THM was raised!\n" ^ s);
clasohm@0
   168
clasohm@0
   169
(*Prints exceptions readably to users*)
lcp@577
   170
fun print_sign_exn_unit sign e = 
clasohm@0
   171
  case e of
clasohm@0
   172
     THM (msg,i,thms) =>
clasohm@0
   173
	 (writeln ("Exception THM " ^ string_of_int i ^ " raised:\n" ^ msg);
clasohm@0
   174
	  seq print_thm thms)
clasohm@0
   175
   | THEORY (msg,thys) =>
clasohm@0
   176
	 (writeln ("Exception THEORY raised:\n" ^ msg);
clasohm@0
   177
	  seq print_theory thys)
clasohm@0
   178
   | TERM (msg,ts) =>
clasohm@0
   179
	 (writeln ("Exception TERM raised:\n" ^ msg);
clasohm@0
   180
	  seq (writeln o Sign.string_of_term sign) ts)
clasohm@0
   181
   | TYPE (msg,Ts,ts) =>
clasohm@0
   182
	 (writeln ("Exception TYPE raised:\n" ^ msg);
clasohm@0
   183
	  seq (writeln o Sign.string_of_typ sign) Ts;
clasohm@0
   184
	  seq (writeln o Sign.string_of_term sign) ts)
clasohm@0
   185
   | e => raise e;
clasohm@0
   186
lcp@577
   187
(*Prints an exception, then fails*)
lcp@577
   188
fun print_sign_exn sign e = (print_sign_exn_unit sign e; raise ERROR);
lcp@577
   189
clasohm@0
   190
(** the prove_goal.... commands
clasohm@0
   191
    Prove theorem using the listed tactics; check it has the specified form.
clasohm@0
   192
    Augment signature with all type assignments of goal.
clasohm@0
   193
    Syntax is similar to "goal" command for easy keyboard use. **)
clasohm@0
   194
clasohm@0
   195
(*Version taking the goal as a cterm*)
clasohm@0
   196
fun prove_goalw_cterm rths chorn tacsf =
clasohm@0
   197
  let val (prems, st0, mkresult) = prepare_proof rths chorn
clasohm@0
   198
      val tac = EVERY (tacsf prems)
clasohm@0
   199
      fun statef() = 
clasohm@0
   200
	  (case Sequence.pull (tapply(tac,st0)) of 
clasohm@0
   201
	       Some(st,_) => st
clasohm@0
   202
	     | _ => error ("prove_goal: tactic failed"))
lcp@545
   203
  in  mkresult (true, cond_timeit (!proof_timing) statef)  end
lcp@914
   204
  handle e => (print_sign_exn_unit (#sign (rep_cterm chorn)) e;
lcp@545
   205
	       error ("The exception above was raised for\n" ^ 
lcp@545
   206
		      string_of_cterm chorn));
lcp@545
   207
clasohm@0
   208
clasohm@0
   209
(*Version taking the goal as a string*)
clasohm@0
   210
fun prove_goalw thy rths agoal tacsf =
clasohm@0
   211
  let val sign = sign_of thy
lcp@230
   212
      val chorn = read_cterm sign (agoal,propT)
lcp@545
   213
  in  prove_goalw_cterm rths chorn tacsf end
lcp@545
   214
  handle ERROR => error (*from read_cterm?*)
lcp@545
   215
		("The error above occurred for " ^ quote agoal);
clasohm@0
   216
clasohm@0
   217
(*String version with no meta-rewrite-rules*)
clasohm@0
   218
fun prove_goal thy = prove_goalw thy [];
clasohm@0
   219
clasohm@0
   220
clasohm@0
   221
(*** Commands etc ***)
clasohm@0
   222
clasohm@0
   223
(*Return the current goal stack, if any, from undo_list*)
clasohm@0
   224
fun getstate() : gstack = case !undo_list of 
clasohm@0
   225
      []   => error"No current state in subgoal module"
clasohm@0
   226
    | x::_ => x;
clasohm@0
   227
clasohm@0
   228
(*Pops the given goal stack*)
clasohm@0
   229
fun pop [] = error"Cannot go back past the beginning of the proof!"
clasohm@0
   230
  | pop (pair::pairs) = (pair,pairs);
clasohm@0
   231
clasohm@0
   232
clasohm@0
   233
(*Print a level of the goal stack.*)
clasohm@0
   234
fun print_top ((th,_), pairs) = 
clasohm@0
   235
   (prs("Level " ^ string_of_int(length pairs) ^ "\n"); 
lcp@68
   236
    !print_goals_ref (!goals_limit) th);
clasohm@0
   237
clasohm@0
   238
(*Printing can raise exceptions, so the assignment occurs last.
clasohm@0
   239
  Can do   setstate[(st,Sequence.null)]  to set st as the state.  *)
clasohm@0
   240
fun setstate newgoals = 
clasohm@0
   241
  (print_top (pop newgoals);  undo_list := newgoals :: !undo_list);
clasohm@0
   242
clasohm@0
   243
(*Given a proof state transformation, return a command that updates
clasohm@0
   244
    the goal stack*)
clasohm@0
   245
fun make_command com = setstate (com (pop (getstate())));
clasohm@0
   246
clasohm@0
   247
(*Apply a function on proof states to the current goal stack*)
clasohm@0
   248
fun apply_fun f = f (pop(getstate()));
clasohm@0
   249
clasohm@0
   250
(*Return the top theorem, representing the proof state*)
clasohm@0
   251
fun topthm () = apply_fun  (fn ((th,_), _) => th);
clasohm@0
   252
clasohm@0
   253
(*Return the final result.  *)
clasohm@0
   254
fun result () = !curr_mkresult (true, topthm());
clasohm@0
   255
clasohm@0
   256
(*Return the result UNCHECKED that it equals the goal -- for synthesis,
clasohm@0
   257
  answer extraction, or other instantiation of Vars *)
clasohm@0
   258
fun uresult () = !curr_mkresult (false, topthm());
clasohm@0
   259
clasohm@0
   260
(*Get subgoal i from goal stack*)
clasohm@0
   261
fun getgoal i = 
clasohm@0
   262
      (case  drop (i-1, prems_of (topthm()))  of
clasohm@0
   263
	    [] => error"getgoal: Goal number out of range"
clasohm@0
   264
	  | Q::_ => Q);
clasohm@0
   265
clasohm@0
   266
(*Return subgoal i's hypotheses as meta-level assumptions.
clasohm@0
   267
  For debugging uses of METAHYPS*)
clasohm@0
   268
local exception GETHYPS of thm list
clasohm@0
   269
in
clasohm@0
   270
fun gethyps i = 
clasohm@0
   271
    (tapply(METAHYPS (fn hyps => raise (GETHYPS hyps)) i, topthm());  [])
clasohm@0
   272
    handle GETHYPS hyps => hyps
clasohm@0
   273
end;
clasohm@0
   274
clasohm@0
   275
(*Which thms could apply to goal i? (debugs tactics involving filter_thms) *)
clasohm@0
   276
fun filter_goal could ths i = filter_thms could (999, getgoal i, ths);
clasohm@0
   277
clasohm@0
   278
(*For inspecting earlier levels of the backward proof*)
clasohm@0
   279
fun chop_level n (pair,pairs) = 
clasohm@0
   280
  let val level = length pairs
clasohm@0
   281
  in  if 0<=n andalso n<= level
clasohm@0
   282
      then  drop (level - n, pair::pairs) 
clasohm@0
   283
      else  error ("Level number must lie between 0 and " ^ 
clasohm@0
   284
		   string_of_int level)
clasohm@0
   285
  end;
clasohm@0
   286
clasohm@0
   287
(*Print the given level of the proof*)
clasohm@0
   288
fun prlev n = apply_fun (print_top o pop o (chop_level n));
clasohm@0
   289
fun pr () = apply_fun print_top;
clasohm@0
   290
clasohm@0
   291
(** the goal.... commands
clasohm@0
   292
    Read main goal.  Set global variables curr_prems, curr_mkresult. 
clasohm@0
   293
    Initial subgoal and premises are rewritten using rths. **)
clasohm@0
   294
clasohm@0
   295
(*Version taking the goal as a cterm; if you have a term t and theory thy, use
lcp@230
   296
    goalw_cterm rths (cterm_of (sign_of thy) t);      *)
clasohm@0
   297
fun goalw_cterm rths chorn = 
clasohm@0
   298
  let val (prems, st0, mkresult) = prepare_proof rths chorn
clasohm@0
   299
  in  undo_list := [];
clasohm@0
   300
      setstate [ (st0, Sequence.null) ];  
clasohm@0
   301
      curr_prems := prems;
clasohm@0
   302
      curr_mkresult := mkresult;
clasohm@0
   303
      prems
clasohm@0
   304
  end;
clasohm@0
   305
clasohm@0
   306
(*Version taking the goal as a string*)
clasohm@0
   307
fun goalw thy rths agoal = 
lcp@230
   308
  goalw_cterm rths (read_cterm(sign_of thy)(agoal,propT))
clasohm@0
   309
  handle ERROR => error (*from type_assign, etc via prepare_proof*)
wenzelm@39
   310
	    ("The error above occurred for " ^ quote agoal);
clasohm@0
   311
clasohm@0
   312
(*String version with no meta-rewrite-rules*)
clasohm@0
   313
fun goal thy = goalw thy [];
clasohm@0
   314
clasohm@0
   315
(*Proof step "by" the given tactic -- apply tactic to the proof state*)
clasohm@0
   316
fun by_com tac ((th,ths), pairs) : gstack =
clasohm@0
   317
  (case  Sequence.pull(tapply(tac, th))  of
clasohm@0
   318
     None      => error"by: tactic failed"
clasohm@0
   319
   | Some(th2,ths2) => 
clasohm@0
   320
       (if eq_thm(th,th2) 
clasohm@0
   321
	  then writeln"Warning: same as previous level"
clasohm@0
   322
	  else if eq_thm_sg(th,th2) then ()
clasohm@0
   323
	  else writeln("Warning: signature of proof state has changed" ^
clasohm@0
   324
		       sign_error (#sign(rep_thm th), #sign(rep_thm th2)));
clasohm@0
   325
       ((th2,ths2)::(th,ths)::pairs)));
clasohm@0
   326
clasohm@0
   327
fun by tac = cond_timeit (!proof_timing) 
clasohm@0
   328
    (fn() => make_command (by_com tac));
clasohm@0
   329
clasohm@0
   330
(* byev[tac1,...,tacn] applies tac1 THEN ... THEN tacn.
clasohm@0
   331
   Good for debugging proofs involving prove_goal.*)
clasohm@0
   332
val byev = by o EVERY;
clasohm@0
   333
clasohm@0
   334
clasohm@0
   335
(*Backtracking means find an alternative result from a tactic.
clasohm@0
   336
  If none at this level, try earlier levels*)
clasohm@0
   337
fun backtrack [] = error"back: no alternatives"
clasohm@0
   338
  | backtrack ((th,thstr) :: pairs) =
clasohm@0
   339
     (case Sequence.pull thstr of
clasohm@0
   340
	  None      => (writeln"Going back a level..."; backtrack pairs)
clasohm@0
   341
	| Some(th2,thstr2) =>  
clasohm@0
   342
	   (if eq_thm(th,th2) 
clasohm@0
   343
	      then writeln"Warning: same as previous choice at this level"
clasohm@0
   344
	      else if eq_thm_sg(th,th2) then ()
clasohm@0
   345
	      else writeln"Warning: signature of proof state has changed";
clasohm@0
   346
	    (th2,thstr2)::pairs));
clasohm@0
   347
clasohm@0
   348
fun back() = setstate (backtrack (getstate()));
clasohm@0
   349
clasohm@0
   350
(*Chop back to previous level of the proof*)
clasohm@0
   351
fun choplev n = make_command (chop_level n);
clasohm@0
   352
clasohm@0
   353
(*Chopping back the goal stack*)
clasohm@0
   354
fun chop () = make_command (fn (_,pairs) => pairs);
clasohm@0
   355
clasohm@0
   356
(*Restore the previous proof state;  discard current state. *)
clasohm@0
   357
fun undo() = case !undo_list of
clasohm@0
   358
      [] => error"No proof state"
clasohm@0
   359
    | [_] => error"Already at initial state"
clasohm@0
   360
    | _::newundo =>  (undo_list := newundo;  pr()) ;
clasohm@0
   361
clasohm@0
   362
clasohm@0
   363
(*** Managing the proof stack ***)
clasohm@0
   364
clasohm@0
   365
fun save_proof() = Proof(!undo_list, !curr_prems, !curr_mkresult);
clasohm@0
   366
clasohm@0
   367
fun restore_proof(Proof(ul,prems,mk)) =
clasohm@0
   368
 (undo_list:= ul;  curr_prems:= prems;  curr_mkresult := mk;  prems);
clasohm@0
   369
clasohm@0
   370
clasohm@0
   371
fun top_proof() = case !proofstack of
clasohm@0
   372
	[] => error("Stack of proof attempts is empty!")
clasohm@0
   373
    | p::ps => (p,ps);
clasohm@0
   374
clasohm@0
   375
(*  push a copy of the current proof state on to the stack *)
clasohm@0
   376
fun push_proof() = (proofstack := (save_proof() :: !proofstack));
clasohm@0
   377
clasohm@0
   378
(* discard the top proof state of the stack *)
clasohm@0
   379
fun pop_proof() = 
clasohm@0
   380
  let val (p,ps) = top_proof()
clasohm@0
   381
      val prems = restore_proof p
clasohm@0
   382
  in proofstack := ps;  pr();  prems end;
clasohm@0
   383
clasohm@0
   384
(* rotate the stack so that the top element goes to the bottom *)
clasohm@0
   385
fun rotate_proof() = let val (p,ps) = top_proof()
clasohm@0
   386
		    in proofstack := ps@[save_proof()];
clasohm@0
   387
		       restore_proof p;
clasohm@0
   388
		       pr();
clasohm@0
   389
		       !curr_prems
clasohm@0
   390
		    end;
clasohm@0
   391
clasohm@0
   392
clasohm@0
   393
(** Shortcuts for commonly-used tactics **)
clasohm@0
   394
clasohm@0
   395
fun bws rls = by (rewrite_goals_tac rls);
clasohm@0
   396
fun bw rl = bws [rl];
clasohm@0
   397
clasohm@0
   398
fun brs rls i = by (resolve_tac rls i);
clasohm@0
   399
fun br rl = brs [rl];
clasohm@0
   400
clasohm@0
   401
fun bes rls i = by (eresolve_tac rls i);
clasohm@0
   402
fun be rl = bes [rl];
clasohm@0
   403
clasohm@0
   404
fun bds rls i = by (dresolve_tac rls i);
clasohm@0
   405
fun bd rl = bds [rl];
clasohm@0
   406
clasohm@0
   407
fun ba i = by (assume_tac i);
clasohm@0
   408
clasohm@0
   409
fun ren str i = by (rename_tac str i);
clasohm@0
   410
clasohm@0
   411
(** Shortcuts to work on the first applicable subgoal **)
clasohm@0
   412
clasohm@0
   413
fun frs rls = by (FIRSTGOAL (trace_goalno_tac (resolve_tac rls)));
clasohm@0
   414
fun fr rl = frs [rl];
clasohm@0
   415
clasohm@0
   416
fun fes rls = by (FIRSTGOAL (trace_goalno_tac (eresolve_tac rls)));
clasohm@0
   417
fun fe rl = fes [rl];
clasohm@0
   418
clasohm@0
   419
fun fds rls = by (FIRSTGOAL (trace_goalno_tac (dresolve_tac rls)));
clasohm@0
   420
fun fd rl = fds [rl];
clasohm@0
   421
clasohm@0
   422
fun fa() = by (FIRSTGOAL (trace_goalno_tac assume_tac));
clasohm@0
   423
clasohm@0
   424
(** Reading and printing terms wrt the current theory **)
clasohm@0
   425
clasohm@0
   426
fun top_sg() = #sign(rep_thm(topthm()));
clasohm@0
   427
lcp@230
   428
fun read s = term_of (read_cterm (top_sg())
clasohm@0
   429
			                   (s, (TVar(("DUMMY",0),[]))));
clasohm@0
   430
clasohm@0
   431
(*Print a term under the current signature of the proof state*)
clasohm@0
   432
fun prin t = writeln (Sign.string_of_term (top_sg()) t);
clasohm@0
   433
clasohm@0
   434
fun printyp T = writeln (Sign.string_of_typ (top_sg()) T);
clasohm@0
   435
clasohm@0
   436
fun pprint_term t = Sign.pprint_term (top_sg()) t;
clasohm@0
   437
clasohm@0
   438
fun pprint_typ T = Sign.pprint_typ (top_sg()) T;
clasohm@0
   439
clasohm@0
   440
(*Prints exceptions nicely at top level; 
clasohm@0
   441
  raises the exception in order to have a polymorphic type!*)
lcp@914
   442
fun print_exn e = (print_sign_exn_unit (top_sg()) e;  raise e);
clasohm@0
   443
clasohm@0
   444
end;
clasohm@0
   445
end;