src/HOL/Tools/Nitpick/nitpick_util.ML
author wenzelm
Wed, 04 Mar 2015 19:53:18 +0100
changeset 59582 0fbed69ff081
parent 59433 9da5b2c61049
child 61770 a20048c78891
permissions -rw-r--r--
tuned signature -- prefer qualified names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33982
1ae222745c4a fixed paths in Nitpick's ML file headers
blanchet
parents: 33705
diff changeset
     1
(*  Title:      HOL/Tools/Nitpick/nitpick_util.ML
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     2
    Author:     Jasmin Blanchette, TU Muenchen
34982
7b8c366e34a2 added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
blanchet
parents: 34936
diff changeset
     3
    Copyright   2008, 2009, 2010
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     4
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     5
General-purpose functions used by the Nitpick modules.
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     6
*)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     7
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33232
diff changeset
     8
signature NITPICK_UTIL =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
     9
sig
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    10
  datatype polarity = Pos | Neg | Neut
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    11
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    12
  exception ARG of string * string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    13
  exception BAD of string * string
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
    14
  exception TOO_SMALL of string * string
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
    15
  exception TOO_LARGE of string * string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    16
  exception NOT_SUPPORTED of string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    17
  exception SAME of unit
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    18
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    19
  val nitpick_prefix : string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    20
  val curry3 : ('a * 'b * 'c -> 'd) -> 'a -> 'b -> 'c -> 'd
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33232
diff changeset
    21
  val pairf : ('a -> 'b) -> ('a -> 'c) -> 'a -> 'b * 'c
35385
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
    22
  val pair_from_fun : (bool -> 'a) -> 'a * 'a
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
    23
  val fun_from_pair : 'a * 'a -> bool -> 'a
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
    24
  val int_from_bool : bool -> int
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33232
diff changeset
    25
  val nat_minus : int -> int -> int
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    26
  val reasonable_power : int -> int -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    27
  val exact_log : int -> int -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    28
  val exact_root : int -> int -> int
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    29
  val offset_list : int list -> int list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    30
  val index_seq : int -> int -> int list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    31
  val filter_indices : int list -> 'a list -> 'a list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    32
  val filter_out_indices : int list -> 'a list -> 'a list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    33
  val fold1 : ('a -> 'a -> 'a) -> 'a list -> 'a
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    34
  val replicate_list : int -> 'a list -> 'a list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    35
  val n_fold_cartesian_product : 'a list list -> 'a list list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    36
  val all_distinct_unordered_pairs_of : ''a list -> (''a * ''a) list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    37
  val nth_combination : (int * int) list -> int -> int list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    38
  val all_combinations : (int * int) list -> int list list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    39
  val all_permutations : 'a list -> 'a list list
48323
7b5f7ca25d17 optimized MaSh output by chunking it
blanchet
parents: 47667
diff changeset
    40
  val chunk_list : int -> 'a list -> 'a list list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    41
  val chunk_list_unevenly : int list -> 'a list -> 'a list list
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    42
  val double_lookup :
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    43
    ('a * 'a -> bool) -> ('a option * 'b) list -> 'a -> 'b option
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    44
  val triple_lookup :
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    45
    (''a * ''a -> bool) -> (''a option * 'b) list -> ''a -> 'b option
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    46
  val is_substring_of : string -> string -> bool
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    47
  val plural_s : int -> string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    48
  val plural_s_for_list : 'a list -> string
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
    49
  val serial_commas : string -> string list -> string list
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
    50
  val pretty_serial_commas : string -> Pretty.T list -> Pretty.T list
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
    51
  val parse_bool_option : bool -> string -> string -> bool option
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54696
diff changeset
    52
  val parse_time : string -> string -> Time.time
52031
9a9238342963 tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents: 50557
diff changeset
    53
  val string_of_time : Time.time -> string
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38240
diff changeset
    54
  val nat_subscript : int -> string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    55
  val flip_polarity : polarity -> polarity
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    56
  val prop_T : typ
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    57
  val bool_T : typ
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    58
  val nat_T : typ
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    59
  val int_T : typ
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 36555
diff changeset
    60
  val simple_string_of_typ : typ -> string
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 54816
diff changeset
    61
  val num_binder_types : typ -> int
42697
9bc5dc48f1a5 query typedefs as well for monotonicity
blanchet
parents: 42680
diff changeset
    62
  val varify_type : Proof.context -> typ -> typ
9bc5dc48f1a5 query typedefs as well for monotonicity
blanchet
parents: 42680
diff changeset
    63
  val instantiate_type : theory -> typ -> typ -> typ -> typ
9bc5dc48f1a5 query typedefs as well for monotonicity
blanchet
parents: 42680
diff changeset
    64
  val varify_and_instantiate_type : Proof.context -> typ -> typ -> typ -> typ
53806
de4653037e0d don't generalize w.r.t. wrong context -- better overgeneralize (since the instantiation phase will compensate for it)
blanchet
parents: 53802
diff changeset
    65
  val varify_and_instantiate_type_global : theory -> typ -> typ -> typ -> typ
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 36555
diff changeset
    66
  val is_of_class_const : theory -> string * typ -> bool
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 36555
diff changeset
    67
  val get_class_def : theory -> string -> (string * term) option
36555
8ff45c2076da expand combinators in Isar proofs constructed by Sledgehammer;
blanchet
parents: 36483
diff changeset
    68
  val monomorphic_term : Type.tyenv -> term -> term
37260
dde817e6dfb1 added "atoms" option to Nitpick (request from Karlsruhe) + wrap Refute. functions to "nitpick_util.ML"
blanchet
parents: 36555
diff changeset
    69
  val specialize_type : theory -> string * typ -> term -> term
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38240
diff changeset
    70
  val eta_expand : typ list -> term -> int -> term
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54696
diff changeset
    71
  val DETERM_TIMEOUT : Time.time -> tactic -> tactic
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    72
  val indent_size : int
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58634
diff changeset
    73
  val pretty_maybe_quote : Keyword.keywords -> Pretty.T -> Pretty.T
43827
62d64709af3b added option to control which lambda translation to use (for experiments)
blanchet
parents: 43085
diff changeset
    74
  val hash_term : term -> int
53815
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
    75
  val spying : bool -> (unit -> Proof.state * int * string) -> unit
35866
513074557e06 move the Sledgehammer Isar commands together into one file;
blanchet
parents: 35807
diff changeset
    76
end;
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    77
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33192
diff changeset
    78
structure Nitpick_Util : NITPICK_UTIL =
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    79
struct
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    80
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    81
datatype polarity = Pos | Neg | Neut
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    82
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    83
exception ARG of string * string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    84
exception BAD of string * string
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
    85
exception TOO_SMALL of string * string
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
    86
exception TOO_LARGE of string * string
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    87
exception NOT_SUPPORTED of string
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    88
exception SAME of unit
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    89
46711
f745bcc4a1e5 more explicit Long_Name operations (NB: analyzing qualifiers is inherently fragile);
wenzelm
parents: 45896
diff changeset
    90
val nitpick_prefix = "Nitpick" ^ Long_Name.separator
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    91
53802
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
    92
val timestamp = ATP_Util.timestamp
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
    93
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    94
fun curry3 f = fn x => fn y => fn z => f (x, y, z)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    95
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33232
diff changeset
    96
fun pairf f g x = (f x, g x)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
    97
35385
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
    98
fun pair_from_fun f = (f false, f true)
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
    99
fun fun_from_pair (f, t) b = if b then t else f
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
   100
29f81babefd7 improved precision of infinite "shallow" datatypes in Nitpick;
blanchet
parents: 35280
diff changeset
   101
fun int_from_bool b = if b then 1 else 0
33705
947184dc75c9 removed a few global names in Nitpick (styp, nat_less, pairf)
blanchet
parents: 33232
diff changeset
   102
fun nat_minus i j = if i > j then i - j else 0
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   103
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   104
val max_exponent = 16384
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   105
35280
54ab4921f826 fixed a few bugs in Nitpick and removed unreferenced variables
blanchet
parents: 35220
diff changeset
   106
fun reasonable_power _ 0 = 1
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   107
  | reasonable_power a 1 = a
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   108
  | reasonable_power 0 _ = 0
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   109
  | reasonable_power 1 _ = 1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   110
  | reasonable_power a b =
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   111
    if b < 0 then
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   112
      raise ARG ("Nitpick_Util.reasonable_power",
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   113
                 "negative exponent (" ^ signed_string_of_int b ^ ")")
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   114
    else if b > max_exponent then
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   115
      raise TOO_LARGE ("Nitpick_Util.reasonable_power",
47667
b4f71d8aecd6 handle exception (needed to solve TPTP problem SEU880^5)
blanchet
parents: 46711
diff changeset
   116
                       "too large exponent (" ^ signed_string_of_int a ^ " ^ " ^
b4f71d8aecd6 handle exception (needed to solve TPTP problem SEU880^5)
blanchet
parents: 46711
diff changeset
   117
                       signed_string_of_int b ^ ")")
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   118
    else
34124
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   119
      let val c = reasonable_power a (b div 2) in
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   120
        c * c * reasonable_power a (b mod 2)
c4628a1dcf75 added support for binary nat/int representation to Nitpick
blanchet
parents: 34039
diff changeset
   121
      end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   122
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   123
fun exact_log m n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   124
  let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   125
    val r = Math.ln (Real.fromInt n) / Math.ln (Real.fromInt m) |> Real.round
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   126
  in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   127
    if reasonable_power m r = n then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   128
      r
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   129
    else
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33192
diff changeset
   130
      raise ARG ("Nitpick_Util.exact_log",
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   131
                 commas (map signed_string_of_int [m, n]))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   132
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   133
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   134
fun exact_root m n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   135
  let val r = Math.pow (Real.fromInt n, 1.0 / (Real.fromInt m)) |> Real.round in
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   136
    if reasonable_power r m = n then
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   137
      r
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   138
    else
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33192
diff changeset
   139
      raise ARG ("Nitpick_Util.exact_root",
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   140
                 commas (map signed_string_of_int [m, n]))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   141
  end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   142
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   143
fun fold1 f = foldl1 (uncurry f)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   144
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   145
fun replicate_list 0 _ = []
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   146
  | replicate_list n xs = xs @ replicate_list (n - 1) xs
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   147
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   148
fun offset_list ns = rev (tl (fold (fn x => fn xs => (x + hd xs) :: xs) ns [0]))
55889
6bfbec3dff62 tuned code
blanchet
parents: 55080
diff changeset
   149
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   150
fun index_seq j0 n = if j0 < 0 then j0 downto j0 - n + 1 else j0 upto j0 + n - 1
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   151
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   152
fun filter_indices js xs =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   153
  let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   154
    fun aux _ [] _ = []
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   155
      | aux i (j :: js) (x :: xs) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   156
        if i = j then x :: aux (i + 1) js xs else aux (i + 1) (j :: js) xs
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33192
diff changeset
   157
      | aux _ _ _ = raise ARG ("Nitpick_Util.filter_indices",
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   158
                               "indices unordered or out of range")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   159
  in aux 0 js xs end
55889
6bfbec3dff62 tuned code
blanchet
parents: 55080
diff changeset
   160
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   161
fun filter_out_indices js xs =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   162
  let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   163
    fun aux _ [] xs = xs
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   164
      | aux i (j :: js) (x :: xs) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   165
        if i = j then aux (i + 1) js xs else x :: aux (i + 1) (j :: js) xs
33232
f93390060bbe internal renaming in Nitpick and fixed Kodkodi invokation on Linux;
blanchet
parents: 33192
diff changeset
   166
      | aux _ _ _ = raise ARG ("Nitpick_Util.filter_out_indices",
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   167
                               "indices unordered or out of range")
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   168
  in aux 0 js xs end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   169
57055
df3a26987a8d reverted '|' features in MaSh -- these sounded like a good idea but never really worked
blanchet
parents: 55891
diff changeset
   170
fun cartesian_product [] _ = []
df3a26987a8d reverted '|' features in MaSh -- these sounded like a good idea but never really worked
blanchet
parents: 55891
diff changeset
   171
  | cartesian_product (x :: xs) yss = map (cons x) yss @ cartesian_product xs yss
df3a26987a8d reverted '|' features in MaSh -- these sounded like a good idea but never really worked
blanchet
parents: 55891
diff changeset
   172
df3a26987a8d reverted '|' features in MaSh -- these sounded like a good idea but never really worked
blanchet
parents: 55891
diff changeset
   173
fun n_fold_cartesian_product xss = fold_rev cartesian_product xss [[]]
54695
a9efdf970720 generate problems with type classes
blanchet
parents: 54554
diff changeset
   174
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   175
fun all_distinct_unordered_pairs_of [] = []
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   176
  | all_distinct_unordered_pairs_of (x :: xs) =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   177
    map (pair x) xs @ all_distinct_unordered_pairs_of xs
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   178
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   179
val nth_combination =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   180
  let
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   181
    fun aux [] n = ([], n)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   182
      | aux ((k, j0) :: xs) n =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   183
        let val (js, n) = aux xs n in ((n mod k) + j0 :: js, n div k) end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   184
  in fst oo aux end
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   185
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   186
val all_combinations = n_fold_cartesian_product o map (uncurry index_seq o swap)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   187
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   188
fun all_permutations [] = [[]]
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   189
  | all_permutations xs =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   190
    maps (fn j => map (cons (nth xs j)) (all_permutations (nth_drop j xs)))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   191
         (index_seq 0 (length xs))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   192
49206
blanchet
parents: 48555
diff changeset
   193
(* FIXME: use "Library.chop_groups" *)
48323
7b5f7ca25d17 optimized MaSh output by chunking it
blanchet
parents: 47667
diff changeset
   194
val chunk_list = ATP_Util.chunk_list
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   195
49206
blanchet
parents: 48555
diff changeset
   196
(* FIXME: use "Library.unflat" *)
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   197
fun chunk_list_unevenly _ [] = []
48323
7b5f7ca25d17 optimized MaSh output by chunking it
blanchet
parents: 47667
diff changeset
   198
  | chunk_list_unevenly [] xs = map single xs
7b5f7ca25d17 optimized MaSh output by chunking it
blanchet
parents: 47667
diff changeset
   199
  | chunk_list_unevenly (k :: ks) xs =
7b5f7ca25d17 optimized MaSh output by chunking it
blanchet
parents: 47667
diff changeset
   200
    let val (xs1, xs2) = chop k xs in xs1 :: chunk_list_unevenly ks xs2 end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   201
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   202
fun double_lookup eq ps key =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   203
  case AList.lookup (fn (SOME x, SOME y) => eq (x, y) | _ => false) ps
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   204
                    (SOME key) of
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   205
    SOME z => SOME z
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   206
  | NONE => ps |> find_first (is_none o fst) |> Option.map snd
55889
6bfbec3dff62 tuned code
blanchet
parents: 55080
diff changeset
   207
35220
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 34982
diff changeset
   208
fun triple_lookup _ [(NONE, z)] _ = SOME z
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 34982
diff changeset
   209
  | triple_lookup eq ps key =
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 34982
diff changeset
   210
    case AList.lookup (op =) ps (SOME key) of
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 34982
diff changeset
   211
      SOME z => SOME z
2bcdae5f4fdb added support for nonstandard "nat"s to Nitpick and fixed bugs in binary "nat"s and "int"s
blanchet
parents: 34982
diff changeset
   212
    | NONE => double_lookup eq ps key
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   213
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   214
fun is_substring_of needle stack =
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   215
  not (Substring.isEmpty (snd (Substring.position needle
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   216
                                                  (Substring.full stack))))
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   217
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
   218
val plural_s = Sledgehammer_Util.plural_s
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   219
fun plural_s_for_list xs = plural_s (length xs)
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   220
43029
3e060b1c844b use helpers and tweak Quickcheck's priority to it comes second (to give Solve Direct slightly more time before another prover runs)
blanchet
parents: 42697
diff changeset
   221
val serial_commas = Try.serial_commas
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
   222
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   223
fun pretty_serial_commas _ [] = []
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   224
  | pretty_serial_commas _ [p] = [p]
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   225
  | pretty_serial_commas conj [p1, p2] =
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   226
    [p1, Pretty.brk 1, Pretty.str conj, Pretty.brk 1, p2]
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   227
  | pretty_serial_commas conj [p1, p2, p3] =
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   228
    [p1, Pretty.str ",", Pretty.brk 1, p2, Pretty.str ",", Pretty.brk 1,
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   229
     Pretty.str conj, Pretty.brk 1, p3]
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   230
  | pretty_serial_commas conj (p :: ps) =
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   231
    p :: Pretty.str "," :: Pretty.brk 1 :: pretty_serial_commas conj ps
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   232
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
   233
val parse_bool_option = Sledgehammer_Util.parse_bool_option
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54696
diff changeset
   234
val parse_time = Sledgehammer_Util.parse_time
52031
9a9238342963 tuning -- renamed '_from_' to '_of_' in Sledgehammer
blanchet
parents: 50557
diff changeset
   235
val string_of_time = ATP_Util.string_of_time
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
   236
53021
d0fa3f446b9d discontinued special treatment of \<^isub> and \<^isup> in rendering or editor front-end;
wenzelm
parents: 53015
diff changeset
   237
val subscript = implode o map (prefix "\<^sub>") o Symbol.explode
55889
6bfbec3dff62 tuned code
blanchet
parents: 55080
diff changeset
   238
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38240
diff changeset
   239
fun nat_subscript n =
53021
d0fa3f446b9d discontinued special treatment of \<^isub> and \<^isup> in rendering or editor front-end;
wenzelm
parents: 53015
diff changeset
   240
  n |> signed_string_of_int |> print_mode_active Symbol.xsymbolsN ? subscript
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38240
diff changeset
   241
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   242
fun flip_polarity Pos = Neg
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   243
  | flip_polarity Neg = Pos
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   244
  | flip_polarity Neut = Neut
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   245
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   246
val prop_T = @{typ prop}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   247
val bool_T = @{typ bool}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   248
val nat_T = @{typ nat}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   249
val int_T = @{typ int}
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   250
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 54816
diff changeset
   251
fun simple_string_of_typ (Type (s, _)) = s
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 54816
diff changeset
   252
  | simple_string_of_typ (TFree (s, _)) = s
49985
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   253
  | simple_string_of_typ (TVar ((s, _), _)) = s
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   254
55080
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 54816
diff changeset
   255
val num_binder_types = BNF_Util.num_binder_types
b7c41accbff2 have Nitpick lookup codatatypes
blanchet
parents: 54816
diff changeset
   256
43085
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   257
val varify_type = ATP_Util.varify_type
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   258
val instantiate_type = ATP_Util.instantiate_type
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   259
val varify_and_instantiate_type = ATP_Util.varify_and_instantiate_type
49985
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   260
53806
de4653037e0d don't generalize w.r.t. wrong context -- better overgeneralize (since the instantiation phase will compensate for it)
blanchet
parents: 53802
diff changeset
   261
fun varify_and_instantiate_type_global thy T1 T1' T2 =
de4653037e0d don't generalize w.r.t. wrong context -- better overgeneralize (since the instantiation phase will compensate for it)
blanchet
parents: 53802
diff changeset
   262
  instantiate_type thy (Logic.varifyT_global T1) T1' (Logic.varifyT_global T2)
de4653037e0d don't generalize w.r.t. wrong context -- better overgeneralize (since the instantiation phase will compensate for it)
blanchet
parents: 53802
diff changeset
   263
49985
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   264
fun is_of_class_const thy (s, _) =
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   265
  member (op =) (map Logic.const_of_class (Sign.all_classes thy)) s
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   266
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   267
fun get_class_def thy class =
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   268
  let val axname = class ^ "_class_def" in
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   269
    Option.map (pair axname)
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   270
      (AList.lookup (op =) (Theory.all_axioms_of thy) axname)
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   271
  end;
5b4b0e4e5205 moved Refute to "HOL/Library" to speed up building "Main" even more
blanchet
parents: 49206
diff changeset
   272
43085
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   273
val monomorphic_term = ATP_Util.monomorphic_term
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   274
val specialize_type = ATP_Util.specialize_type
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   275
val eta_expand = ATP_Util.eta_expand
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   276
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   277
fun DETERM_TIMEOUT delay tac st =
54816
10d48c2a3e32 made timeouts in Sledgehammer not be 'option's -- simplified lots of code
blanchet
parents: 54696
diff changeset
   278
  Seq.of_list (the_list (TimeLimit.timeLimit delay (fn () => SINGLE tac st) ()))
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   279
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   280
val indent_size = 2
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   281
43085
0a2f5b86bdd7 first step in sharing more code between ATP and Metis translation
blanchet
parents: 43029
diff changeset
   282
val maybe_quote = ATP_Util.maybe_quote
55889
6bfbec3dff62 tuned code
blanchet
parents: 55080
diff changeset
   283
58928
23d0ffd48006 plain value Keywords.keywords, which might be used outside theory for bootstrap purposes;
wenzelm
parents: 58634
diff changeset
   284
fun pretty_maybe_quote keywords pretty =
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   285
  let val s = Pretty.str_of pretty in
58929
wenzelm
parents: 58928
diff changeset
   286
    if maybe_quote keywords s = s then pretty else Pretty.quote pretty
38188
7f12a03c513c better "Pretty" handling
blanchet
parents: 38026
diff changeset
   287
  end
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   288
53802
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   289
val hashw = ATP_Util.hashw
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   290
val hashw_string = ATP_Util.hashw_string
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   291
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   292
fun hashw_term (t1 $ t2) = hashw (hashw_term t1, hashw_term t2)
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   293
  | hashw_term (Const (s, _)) = hashw_string (s, 0w0)
44bc6ff8f350 added "spy" option to Nitpick
blanchet
parents: 53514
diff changeset
   294
  | hashw_term (Free (s, _)) = hashw_string (s, 0w0)
53505
412f8c590c6c moved ML function closer to its remaining use
blanchet
parents: 53021
diff changeset
   295
  | hashw_term _ = 0w0
412f8c590c6c moved ML function closer to its remaining use
blanchet
parents: 53021
diff changeset
   296
412f8c590c6c moved ML function closer to its remaining use
blanchet
parents: 53021
diff changeset
   297
val hash_term = Word.toInt o hashw_term
36380
1e8fcaccb3e8 stop referring to Sledgehammer_Util stuff all over Nitpick code; instead, redeclare any needed function in Nitpick_Util as synonym for the Sledgehammer_Util function of the same name
blanchet
parents: 35964
diff changeset
   298
53815
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   299
val hackish_string_of_term = Sledgehammer_Util.hackish_string_of_term
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   300
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   301
val spying_version = "b"
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   302
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   303
fun spying false _ = ()
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   304
  | spying true f =
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   305
    let
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   306
      val (state, i, message) = f ()
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   307
      val ctxt = Proof.context_of state
59582
0fbed69ff081 tuned signature -- prefer qualified names;
wenzelm
parents: 59433
diff changeset
   308
      val goal = Logic.get_goal (Thm.prop_of (#goal (Proof.goal state))) i
53815
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   309
      val hash = String.substring (SHA1.rep (SHA1.digest (hackish_string_of_term ctxt goal)), 0, 12)
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   310
    in
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   311
      File.append (Path.explode "$ISABELLE_HOME_USER/spy_nitpick")
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   312
        (spying_version ^ " " ^ timestamp () ^ ": " ^ hash ^ ": " ^ message ^ "\n")
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   313
    end
e8aa538e959e encode goal digest in spying log (to detect duplicates)
blanchet
parents: 53806
diff changeset
   314
33192
08a39a957ed7 added Nitpick's theory and ML files to Isabelle/HOL;
blanchet
parents:
diff changeset
   315
end;