src/Pure/display_goal.ML
author wenzelm
Mon, 20 Jul 2009 21:20:09 +0200
changeset 32089 568a23753e3a
child 32145 220c9e439d39
permissions -rw-r--r--
moved pretty_goals etc. to Display_Goal (required by tracing tacticals); load display.ML after assumption.ML, to accomodate proper contextual theorem display;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/display_goal.ML
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     3
    Author:     Makarius
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     4
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     5
Display tactical goal state.
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     6
*)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     7
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     8
signature DISPLAY_GOAL =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     9
sig
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    10
  val goals_limit: int ref
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    11
  val show_consts: bool ref
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    12
  val pretty_flexpair: Pretty.pp -> term * term -> Pretty.T
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    13
  val pretty_goals_aux: Pretty.pp -> Markup.T -> bool * bool -> int -> thm -> Pretty.T list
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    14
  val pretty_goals: int -> thm -> Pretty.T list
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    15
  val print_goals: int -> thm -> unit
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    16
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    17
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    18
structure Display_Goal: DISPLAY_GOAL =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    19
struct
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    20
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    21
val goals_limit = ref 10;      (*max number of goals to print*)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    22
val show_consts = ref false;   (*true: show consts with types in proof state output*)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    23
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    24
fun pretty_flexpair pp (t, u) = Pretty.block
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    25
  [Pretty.term pp t, Pretty.str " =?=", Pretty.brk 1, Pretty.term pp u];
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    26
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    27
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    28
(*print thm A1,...,An/B in "goal style" -- premises as numbered subgoals*)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    29
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    30
local
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    31
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    32
fun ins_entry (x, y) =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    33
  AList.default (op =) (x, []) #>
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    34
  AList.map_entry (op =) x (insert (op =) y);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    35
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    36
val add_consts = Term.fold_aterms
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    37
  (fn Const (c, T) => ins_entry (T, (c, T))
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    38
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    39
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    40
val add_vars = Term.fold_aterms
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    41
  (fn Free (x, T) => ins_entry (T, (x, ~1))
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    42
    | Var (xi, T) => ins_entry (T, xi)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    43
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    44
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    45
val add_varsT = Term.fold_atyps
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    46
  (fn TFree (x, S) => ins_entry (S, (x, ~1))
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    47
    | TVar (xi, S) => ins_entry (S, xi)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    48
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    49
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    50
fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    51
fun sort_cnsts cs = map (apsnd (sort_wrt fst)) cs;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    52
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    53
fun consts_of t = sort_cnsts (add_consts t []);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    54
fun vars_of t = sort_idxs (add_vars t []);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    55
fun varsT_of t = rev (sort_idxs (Term.fold_types add_varsT t []));
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    56
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    57
in
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    58
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    59
fun pretty_goals_aux pp markup (msg, main) maxgoals state =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    60
  let
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    61
    fun prt_atoms prt prtT (X, xs) = Pretty.block
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    62
      [Pretty.block (Pretty.commas (map prt xs)), Pretty.str " ::",
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    63
        Pretty.brk 1, prtT X];
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    64
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    65
    fun prt_var (x, ~1) = Pretty.term pp (Syntax.free x)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    66
      | prt_var xi = Pretty.term pp (Syntax.var xi);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    67
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    68
    fun prt_varT (x, ~1) = Pretty.typ pp (TFree (x, []))
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    69
      | prt_varT xi = Pretty.typ pp (TVar (xi, []));
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    70
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    71
    val prt_consts = prt_atoms (Pretty.term pp o Const) (Pretty.typ pp);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    72
    val prt_vars = prt_atoms prt_var (Pretty.typ pp);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    73
    val prt_varsT = prt_atoms prt_varT (Pretty.sort pp);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    74
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    75
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    76
    fun pretty_list _ _ [] = []
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    77
      | pretty_list name prt lst = [Pretty.big_list name (map prt lst)];
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    78
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    79
    fun pretty_subgoal (n, A) = Pretty.markup markup
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    80
      [Pretty.str (" " ^ string_of_int n ^ ". "), Pretty.term pp A];
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    81
    fun pretty_subgoals As = map pretty_subgoal (1 upto length As ~~ As);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    82
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    83
    val pretty_ffpairs = pretty_list "flex-flex pairs:" (pretty_flexpair pp);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    84
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    85
    val pretty_consts = pretty_list "constants:" prt_consts o consts_of;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    86
    val pretty_vars = pretty_list "variables:" prt_vars o vars_of;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    87
    val pretty_varsT = pretty_list "type variables:" prt_varsT o varsT_of;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    88
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    89
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    90
    val {prop, tpairs, ...} = Thm.rep_thm state;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    91
    val (As, B) = Logic.strip_horn prop;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    92
    val ngoals = length As;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    93
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    94
    fun pretty_gs (types, sorts) =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    95
      (if main then [Pretty.term pp B] else []) @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    96
       (if ngoals = 0 then [Pretty.str "No subgoals!"]
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    97
        else if ngoals > maxgoals then
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    98
          pretty_subgoals (Library.take (maxgoals, As)) @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    99
          (if msg then [Pretty.str ("A total of " ^ string_of_int ngoals ^ " subgoals...")]
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   100
           else [])
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   101
        else pretty_subgoals As) @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   102
      pretty_ffpairs tpairs @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   103
      (if ! show_consts then pretty_consts prop else []) @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   104
      (if types then pretty_vars prop else []) @
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   105
      (if sorts then pretty_varsT prop else []);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   106
  in
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   107
    setmp show_no_free_types true
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   108
      (setmp show_types (! show_types orelse ! show_sorts orelse ! show_all_types)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   109
        (setmp show_sorts false pretty_gs))
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   110
   (! show_types orelse ! show_sorts orelse ! show_all_types, ! show_sorts)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   111
  end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   112
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   113
fun pretty_goals n th =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   114
  pretty_goals_aux (Syntax.pp_global (Thm.theory_of_thm th)) Markup.none (true, true) n th;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   115
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   116
val print_goals = (Pretty.writeln o Pretty.chunks) oo pretty_goals;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   117
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   118
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   119
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   120
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   121