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