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