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