src/Pure/goal_display.ML
author wenzelm
Sat, 22 Oct 2016 21:10:02 +0200
changeset 64350 3af8566788e7
parent 61268 abe08fb15a12
child 64556 851ae0e7b09c
permissions -rw-r--r--
remote_builds has PAR-SEQ semantics of old isatest-makedist; tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32187
cca43ca13f4f renamed structure Display_Goal to Goal_Display;
wenzelm
parents: 32168
diff changeset
     1
(*  Title:      Pure/goal_display.ML
32089
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
32187
cca43ca13f4f renamed structure Display_Goal to Goal_Display;
wenzelm
parents: 32168
diff changeset
     8
signature GOAL_DISPLAY =
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
     9
sig
39163
4d701c0388c3 more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents: 39134
diff changeset
    10
  val goals_limit_raw: Config.raw
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    11
  val goals_limit: int Config.T
39163
4d701c0388c3 more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents: 39134
diff changeset
    12
  val show_main_goal_raw: Config.raw
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    13
  val show_main_goal: bool Config.T
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    14
  val pretty_goals: Proof.context -> thm -> Pretty.T list
51958
bca32217b304 retain goal display options when printing error messages, to avoid breakdown for huge goals;
wenzelm
parents: 50543
diff changeset
    15
  val pretty_goal: Proof.context -> thm -> Pretty.T
bca32217b304 retain goal display options when printing error messages, to avoid breakdown for huge goals;
wenzelm
parents: 50543
diff changeset
    16
  val string_of_goal: Proof.context -> thm -> string
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    17
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    18
32187
cca43ca13f4f renamed structure Display_Goal to Goal_Display;
wenzelm
parents: 32168
diff changeset
    19
structure Goal_Display: GOAL_DISPLAY =
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    20
struct
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    21
56438
7f6b2634d853 more source positions;
wenzelm
parents: 52284
diff changeset
    22
val goals_limit_raw = Config.declare_option ("goals_limit", @{here});
39163
4d701c0388c3 more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents: 39134
diff changeset
    23
val goals_limit = Config.int goals_limit_raw;
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    24
56438
7f6b2634d853 more source positions;
wenzelm
parents: 52284
diff changeset
    25
val show_main_goal_raw = Config.declare_option ("show_main_goal", @{here});
39163
4d701c0388c3 more explicit indication of Config.raw options, which are only needed for bootstrapping Pure;
wenzelm
parents: 39134
diff changeset
    26
val show_main_goal = Config.bool show_main_goal_raw;
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    27
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    28
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    29
(*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
    30
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    31
local
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    32
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    33
fun ins_entry (x, y) =
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    34
  AList.default (op =) (x, []) #>
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    35
  AList.map_entry (op =) x (insert (op =) y);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    36
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    37
val add_consts = Term.fold_aterms
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    38
  (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
    39
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    40
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    41
val add_vars = Term.fold_aterms
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    42
  (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
    43
    | Var (xi, T) => ins_entry (T, xi)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    44
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    45
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    46
val add_varsT = Term.fold_atyps
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    47
  (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
    48
    | TVar (xi, S) => ins_entry (S, xi)
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    49
    | _ => I);
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    50
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    51
fun sort_idxs vs = map (apsnd (sort (prod_ord string_ord int_ord))) vs;
60924
610794dff23c tuned signature, in accordance to sortBy in Scala;
wenzelm
parents: 56493
diff changeset
    52
fun sort_cnsts cs = map (apsnd (sort_by fst)) cs;
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    53
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    54
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
    55
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
    56
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
    57
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    58
in
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    59
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    60
fun pretty_goals ctxt0 state =
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    61
  let
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    62
    val ctxt = ctxt0
52185
1b481b490454 discontinued obsolete show_all_types;
wenzelm
parents: 52043
diff changeset
    63
      |> Config.put show_types (Config.get ctxt0 show_types orelse Config.get ctxt0 show_sorts)
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    64
      |> Config.put show_sorts false;
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    65
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    66
    val show_sorts0 = Config.get ctxt0 show_sorts;
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    67
    val show_types = Config.get ctxt show_types;
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    68
    val show_consts = Config.get ctxt show_consts
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
    69
    val show_main_goal = Config.get ctxt show_main_goal;
39125
f45d332a90e3 pretty_goals: turned some global references and function arguments into configuration options (goals_limit = 10, goals_total = true, show_main_goal = false) depending on the context;
wenzelm
parents: 39118
diff changeset
    70
    val goals_limit = Config.get ctxt goals_limit;
39115
a00da1674c1c turned show_no_free_types into proper configuration option show_free_types, with flipped polarity;
wenzelm
parents: 39050
diff changeset
    71
32145
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    72
    val prt_sort = Syntax.pretty_sort ctxt;
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    73
    val prt_typ = Syntax.pretty_typ ctxt;
52284
b12f2cef3ee5 Type_Annotation only works *after* uncheck (which usually requires authentic type information);
wenzelm
parents: 52211
diff changeset
    74
    val prt_term =
b12f2cef3ee5 Type_Annotation only works *after* uncheck (which usually requires authentic type information);
wenzelm
parents: 52211
diff changeset
    75
      singleton (Syntax.uncheck_terms ctxt) #>
b12f2cef3ee5 Type_Annotation only works *after* uncheck (which usually requires authentic type information);
wenzelm
parents: 52211
diff changeset
    76
      Type_Annotation.ignore_free_types #>
b12f2cef3ee5 Type_Annotation only works *after* uncheck (which usually requires authentic type information);
wenzelm
parents: 52211
diff changeset
    77
      Syntax.unparse_term ctxt;
32145
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    78
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    79
    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
    80
      [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
    81
        Pretty.brk 1, prtT X];
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    82
32145
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    83
    fun prt_var (x, ~1) = prt_term (Syntax.free x)
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    84
      | prt_var xi = prt_term (Syntax.var xi);
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    85
32145
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    86
    fun prt_varT (x, ~1) = prt_typ (TFree (x, []))
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    87
      | prt_varT xi = prt_typ (TVar (xi, []));
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    88
32145
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    89
    val prt_consts = prt_atoms (prt_term o Const) prt_typ;
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    90
    val prt_vars = prt_atoms prt_var prt_typ;
220c9e439d39 clarified pretty_goals, pretty_thm_aux: plain context;
wenzelm
parents: 32089
diff changeset
    91
    val prt_varsT = prt_atoms prt_varT prt_sort;
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    92
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_list _ _ [] = []
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
    95
      | 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
    96
50537
08ce81aeeacc more subgoal markup information, which is potentially useful to manage proof state output;
wenzelm
parents: 50201
diff changeset
    97
    fun pretty_subgoal s A =
08ce81aeeacc more subgoal markup information, which is potentially useful to manage proof state output;
wenzelm
parents: 50201
diff changeset
    98
      Pretty.markup (Markup.subgoal s) [Pretty.str (" " ^ s ^ ". "), prt_term A];
08ce81aeeacc more subgoal markup information, which is potentially useful to manage proof state output;
wenzelm
parents: 50201
diff changeset
    99
    val pretty_subgoals = map_index (fn (i, A) => pretty_subgoal (string_of_int (i + 1)) A);
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   100
61268
abe08fb15a12 moved remaining display.ML to more_thm.ML;
wenzelm
parents: 61039
diff changeset
   101
    val pretty_ffpairs = pretty_list "flex-flex pairs:" (Thm.pretty_flexpair ctxt);
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   102
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   103
    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
   104
    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
   105
    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
   106
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   107
61039
80f40d89dab6 tuned signature;
wenzelm
parents: 60924
diff changeset
   108
    val prop = Thm.prop_of state;
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   109
    val (As, B) = Logic.strip_horn prop;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   110
    val ngoals = length As;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   111
  in
50543
42bbe637be54 fold main goal;
wenzelm
parents: 50537
diff changeset
   112
    (if show_main_goal then [Pretty.mark Markup.goal (prt_term B)] else []) @
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   113
     (if ngoals = 0 then [Pretty.str "No subgoals!"]
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   114
      else if ngoals > goals_limit then
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   115
        pretty_subgoals (take goals_limit As) @
51959
18d758e38d85 clarified message when subgoals have been stripped -- unconditional;
wenzelm
parents: 51958
diff changeset
   116
        [Pretty.str ("A total of " ^ string_of_int ngoals ^ " subgoals...")]
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   117
      else pretty_subgoals As) @
61039
80f40d89dab6 tuned signature;
wenzelm
parents: 60924
diff changeset
   118
    pretty_ffpairs (Thm.tpairs_of state) @
39134
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   119
    (if show_consts then pretty_consts prop else []) @
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   120
    (if show_types then pretty_vars prop else []) @
917b4b6ba3d2 turned show_sorts/show_types into proper configuration options;
wenzelm
parents: 39125
diff changeset
   121
    (if show_sorts0 then pretty_varsT prop else [])
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   122
  end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   123
51959
18d758e38d85 clarified message when subgoals have been stripped -- unconditional;
wenzelm
parents: 51958
diff changeset
   124
val pretty_goal = Pretty.chunks oo pretty_goals;
51958
bca32217b304 retain goal display options when printing error messages, to avoid breakdown for huge goals;
wenzelm
parents: 50543
diff changeset
   125
val string_of_goal = Pretty.string_of oo pretty_goal;
49847
ed5080c03165 some attempts to unify/simplify pretty_goal;
wenzelm
parents: 45666
diff changeset
   126
32089
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   127
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   128
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   129
end;
568a23753e3a moved pretty_goals etc. to Display_Goal (required by tracing tacticals);
wenzelm
parents:
diff changeset
   130