src/HOL/Tools/Sledgehammer/sledgehammer_filter.ML
author blanchet
Thu, 12 May 2011 15:29:19 +0200
changeset 42732 86683865278d
parent 42730 d6db5a815477
child 42735 1d375de437e9
permissions -rw-r--r--
no penality for constants that appear in chained facts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
38988
483879af0643 finished renaming
blanchet
parents: 38986
diff changeset
     1
(*  Title:      HOL/Tools/Sledgehammer/sledgehammer_filter.ML
38027
505657ddb047 standardize "Author" tags
blanchet
parents: 37995
diff changeset
     2
    Author:     Jia Meng, Cambridge University Computer Laboratory and NICTA
36393
be73a2b2443b support readable names even when Isar proof reconstruction is enabled -- useful for debugging
blanchet
parents: 36227
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
39958
88c9aa5666de tuned comments
blanchet
parents: 39946
diff changeset
     4
88c9aa5666de tuned comments
blanchet
parents: 39946
diff changeset
     5
Sledgehammer's relevance filter.
33309
5f67433e6dd8 proper header;
wenzelm
parents: 33306
diff changeset
     6
*)
15452
e2a721567f67 Jia Meng: delta simpsets and clasets
paulson
parents: 15347
diff changeset
     7
38988
483879af0643 finished renaming
blanchet
parents: 38986
diff changeset
     8
signature SLEDGEHAMMER_FILTER =
16802
6eeee59dac4c use Toplevel.print_state_hook instead of adhoc Proof.atp_hook;
wenzelm
parents: 16767
diff changeset
     9
sig
38993
504b9e1efd33 give priority to assumptions in structured proofs
blanchet
parents: 38992
diff changeset
    10
  datatype locality = General | Intro | Elim | Simp | Local | Assum | Chained
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
    11
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    12
  type relevance_fudge =
41159
1e12d6495423 honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents: 41158
diff changeset
    13
    {allow_ext : bool,
41790
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
    14
     local_const_multiplier : real,
41159
1e12d6495423 honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents: 41158
diff changeset
    15
     worse_irrel_freq : real,
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    16
     higher_order_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    17
     abs_rel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    18
     abs_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    19
     skolem_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    20
     theory_const_rel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    21
     theory_const_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    22
     intro_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    23
     elim_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    24
     simp_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    25
     local_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    26
     assum_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    27
     chained_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    28
     max_imperfect : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    29
     max_imperfect_exp : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    30
     threshold_divisor : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    31
     ridiculous_threshold : real}
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    32
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35963
diff changeset
    33
  type relevance_override =
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    34
    {add : (Facts.ref * Attrib.src list) list,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    35
     del : (Facts.ref * Attrib.src list) list,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    36
     only : bool}
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35963
diff changeset
    37
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
    38
  val trace : bool Config.T
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    39
  val new_monomorphizer : bool Config.T
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    40
  val ignore_no_atp : bool Config.T
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    41
  val instantiate_inducts : bool Config.T
42680
b6c27cf04fe9 exploit inferred monotonicity
blanchet
parents: 42671
diff changeset
    42
  val is_locality_global : locality -> bool
40205
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
    43
  val fact_from_ref :
38996
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
    44
    Proof.context -> unit Symtab.table -> thm list
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
    45
    -> Facts.ref * Attrib.src list -> ((string * locality) * thm) list
41767
44b2a0385001 export useful function (needed in a Sledgehammer-related experiment)
blanchet
parents: 41491
diff changeset
    46
  val all_facts :
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
    47
    Proof.context -> 'a Symtab.table -> bool -> thm list -> thm list
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
    48
    -> (((unit -> string) * locality) * (bool * thm)) list
41768
dd2125fb75f9 export more functionality of Sledgehammer to applications (for experiments)
blanchet
parents: 41767
diff changeset
    49
  val const_names_in_fact :
dd2125fb75f9 export more functionality of Sledgehammer to applications (for experiments)
blanchet
parents: 41767
diff changeset
    50
    theory -> (string * typ -> term list -> bool * term list) -> term
dd2125fb75f9 export more functionality of Sledgehammer to applications (for experiments)
blanchet
parents: 41767
diff changeset
    51
    -> string list
37347
635425a442e8 show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents: 37345
diff changeset
    52
  val relevant_facts :
42638
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
    53
    Proof.context -> real * real -> int
41336
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
    54
    -> (string * typ -> term list -> bool * term list) -> relevance_fudge
41066
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
    55
    -> relevance_override -> thm list -> term list -> term
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    56
    -> ((string * locality) * thm) list
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    57
end;
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    58
38988
483879af0643 finished renaming
blanchet
parents: 38986
diff changeset
    59
structure Sledgehammer_Filter : SLEDGEHAMMER_FILTER =
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    60
struct
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
    61
38652
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38644
diff changeset
    62
open Sledgehammer_Util
e063be321438 perform eta-expansion of quantifier bodies in Sledgehammer translation when needed + transform elim rules later;
blanchet
parents: 38644
diff changeset
    63
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
    64
val trace =
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
    65
  Attrib.setup_config_bool @{binding sledgehammer_filter_trace} (K false)
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
    66
fun trace_msg ctxt msg = if Config.get ctxt trace then tracing (msg ()) else ()
35826
1590abc3d42a renamed Sledgehammer structures
blanchet
parents: 35825
diff changeset
    67
41273
35ce17cd7967 made the relevance filter treat unatomizable facts like "atomize_all" properly (these result in problems that get E spinning seemingly forever);
blanchet
parents: 41211
diff changeset
    68
(* experimental features *)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    69
val new_monomorphizer =
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    70
  Attrib.setup_config_bool @{binding sledgehammer_new_monomorphizer} (K false)
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    71
val ignore_no_atp =
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    72
  Attrib.setup_config_bool @{binding sledgehammer_ignore_no_atp} (K false)
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    73
val instantiate_inducts =
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
    74
  Attrib.setup_config_bool @{binding sledgehammer_instantiate_inducts} (K false)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
    75
38993
504b9e1efd33 give priority to assumptions in structured proofs
blanchet
parents: 38992
diff changeset
    76
datatype locality = General | Intro | Elim | Simp | Local | Assum | Chained
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
    77
42449
494e4ac5b0f8 detect some unsound proofs before showing them to the user
blanchet
parents: 42361
diff changeset
    78
(* (quasi-)underapproximation of the truth *)
42680
b6c27cf04fe9 exploit inferred monotonicity
blanchet
parents: 42671
diff changeset
    79
fun is_locality_global Local = false
b6c27cf04fe9 exploit inferred monotonicity
blanchet
parents: 42671
diff changeset
    80
  | is_locality_global Assum = false
b6c27cf04fe9 exploit inferred monotonicity
blanchet
parents: 42671
diff changeset
    81
  | is_locality_global Chained = false
b6c27cf04fe9 exploit inferred monotonicity
blanchet
parents: 42671
diff changeset
    82
  | is_locality_global _ = true
42449
494e4ac5b0f8 detect some unsound proofs before showing them to the user
blanchet
parents: 42361
diff changeset
    83
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    84
type relevance_fudge =
41159
1e12d6495423 honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents: 41158
diff changeset
    85
  {allow_ext : bool,
41790
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
    86
   local_const_multiplier : real,
41159
1e12d6495423 honor "overlord" option for SMT solvers as well and don't pass "ext" to them
blanchet
parents: 41158
diff changeset
    87
   worse_irrel_freq : real,
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    88
   higher_order_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    89
   abs_rel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    90
   abs_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    91
   skolem_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    92
   theory_const_rel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    93
   theory_const_irrel_weight : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    94
   intro_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    95
   elim_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    96
   simp_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    97
   local_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    98
   assum_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
    99
   chained_bonus : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   100
   max_imperfect : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   101
   max_imperfect_exp : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   102
   threshold_divisor : real,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   103
   ridiculous_threshold : real}
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   104
35966
f8c738abaed8 honor the newly introduced Sledgehammer parameters and fixed the parsing;
blanchet
parents: 35963
diff changeset
   105
type relevance_override =
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   106
  {add : (Facts.ref * Attrib.src list) list,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   107
   del : (Facts.ref * Attrib.src list) list,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   108
   only : bool}
21070
0a898140fea2 Added more debugging info
paulson
parents: 20995
diff changeset
   109
37616
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37580
diff changeset
   110
val sledgehammer_prefix = "Sledgehammer" ^ Long_Name.separator
39896
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39718
diff changeset
   111
val abs_name = sledgehammer_prefix ^ "abs"
13b3a2ba9ea7 encode axiom number and cluster number in all zapped quantifiers to help discharging new skolemizer assumptions
blanchet
parents: 39718
diff changeset
   112
val skolem_prefix = sledgehammer_prefix ^ "sko"
38992
542474156c66 introduce fudge factors to deal with "theory const"
blanchet
parents: 38988
diff changeset
   113
val theory_const_suffix = Long_Name.separator ^ " 1"
37616
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37580
diff changeset
   114
40227
e31e3f0071d4 support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents: 40205
diff changeset
   115
fun needs_quoting reserved s =
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   116
  Symtab.defined reserved s orelse
42290
b1f544c84040 discontinued special treatment of structure Lexicon;
wenzelm
parents: 41999
diff changeset
   117
  exists (not o Lexicon.is_identifier) (Long_Name.explode s)
40227
e31e3f0071d4 support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents: 40205
diff changeset
   118
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   119
fun make_name reserved multi j name =
40227
e31e3f0071d4 support non-identifier-like fact names in Sledgehammer (e.g., "my lemma") by quoting them
blanchet
parents: 40205
diff changeset
   120
  (name |> needs_quoting reserved name ? quote) ^
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 41336
diff changeset
   121
  (if multi then "(" ^ string_of_int j ^ ")" else "")
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   122
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   123
fun explode_interval _ (Facts.FromTo (i, j)) = i upto j
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   124
  | explode_interval max (Facts.From i) = i upto i + max - 1
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   125
  | explode_interval _ (Facts.Single i) = [i]
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   126
41279
e0400b05a62c escape backticks in altstrings
blanchet
parents: 41273
diff changeset
   127
val backquote =
e0400b05a62c escape backticks in altstrings
blanchet
parents: 41273
diff changeset
   128
  raw_explode #> map (fn "`" => "\\`" | s => s) #> implode #> enclose "`" "`"
40205
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   129
fun fact_from_ref ctxt reserved chained_ths (xthm as (xref, args)) =
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   130
  let
38996
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
   131
    val ths = Attrib.eval_thms ctxt [xthm]
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
   132
    val bracket =
41999
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41989
diff changeset
   133
      map (enclose "[" "]" o Pretty.str_of o Args.pretty_src ctxt) args
3c029ef9e0f2 added "simp:", "intro:", and "elim:" to "try" command
blanchet
parents: 41989
diff changeset
   134
      |> implode
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   135
    fun nth_name j =
38996
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
   136
      case xref of
41279
e0400b05a62c escape backticks in altstrings
blanchet
parents: 41273
diff changeset
   137
        Facts.Fact s => backquote s ^ bracket
38996
6905ba37376c generalize theorem argument parsing syntax
blanchet
parents: 38994
diff changeset
   138
      | Facts.Named (("", _), _) => "[" ^ bracket ^ "]"
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   139
      | Facts.Named ((name, _), NONE) =>
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   140
        make_name reserved (length ths > 1) (j + 1) name ^ bracket
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   141
      | Facts.Named ((name, _), SOME intervals) =>
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   142
        make_name reserved true
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   143
                 (nth (maps (explode_interval (length ths)) intervals) j) name ^
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   144
        bracket
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   145
  in
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   146
    (ths, (0, []))
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   147
    |-> fold (fn th => fn (j, rest) =>
40375
db690d38e4b9 fixed handling of theorem references such as "foo bar" (with quotes), "foo bar(2)", and "foo bar(2)"(2)
blanchet
parents: 40373
diff changeset
   148
                 (j + 1, ((nth_name j,
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   149
                          if member Thm.eq_thm chained_ths th then Chained
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   150
                          else General), th) :: rest))
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   151
    |> snd
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   152
  end
37616
c8d2d84d6011 always perform relevance filtering on original formulas
blanchet
parents: 37580
diff changeset
   153
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   154
(* This is a terrible hack. Free variables are sometimes code as "M__" when they
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   155
   are displayed as "M" and we want to avoid clashes with these. But sometimes
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   156
   it's even worse: "Ma__" encodes "M". So we simply reserve all prefixes of all
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   157
   free variables. In the worse case scenario, where the fact won't be resolved
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   158
   correctly, the user can fix it manually, e.g., by naming the fact in
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   159
   question. Ideally we would need nothing of it, but backticks just don't work
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   160
   with schematic variables. *)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   161
fun all_prefixes_of s =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   162
  map (fn i => String.extract (s, 0, SOME i)) (1 upto size s - 1)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   163
fun close_form t =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   164
  (t, [] |> Term.add_free_names t |> maps all_prefixes_of)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   165
  |> fold (fn ((s, i), T) => fn (t', taken) =>
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   166
              let val s' = Name.variant taken s in
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   167
                ((if fastype_of t' = HOLogic.boolT then HOLogic.all_const
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   168
                  else Term.all) T
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   169
                 $ Abs (s', T, abstract_over (Var ((s, i), T), t')),
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   170
                 s' :: taken)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   171
              end)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   172
          (Term.add_vars t [] |> sort_wrt (fst o fst))
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   173
  |> fst
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   174
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   175
fun string_for_term ctxt t =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   176
  Print_Mode.setmp (filter (curry (op =) Symbol.xsymbolsN)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   177
                   (print_mode_value ())) (Syntax.string_of_term ctxt) t
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   178
  |> String.translate (fn c => if Char.isPrint c then str c else "")
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   179
  |> simplify_spaces
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   180
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   181
(** Structural induction rules **)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   182
41200
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   183
fun struct_induct_rule_on th =
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   184
  case Logic.strip_horn (prop_of th) of
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   185
    (prems, @{const Trueprop}
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   186
            $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) =>
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   187
    if not (is_TVar ind_T) andalso length prems > 1 andalso
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   188
       exists (exists_subterm (curry (op aconv) p)) prems andalso
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   189
       not (exists (exists_subterm (curry (op aconv) a)) prems) then
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   190
      SOME (p_name, ind_T)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   191
    else
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   192
      NONE
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   193
  | _ => NONE
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   194
41207
f9c7bdc75dd0 reintroduce the higher penalty for skolems
blanchet
parents: 41205
diff changeset
   195
fun instantiate_induct_rule ctxt concl_prop p_name ((name, loc), (multi, th))
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   196
                            ind_x =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   197
  let
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   198
    fun varify_noninducts (t as Free (s, T)) =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   199
        if (s, T) = ind_x orelse can dest_funT T then t else Var ((s, 0), T)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   200
      | varify_noninducts t = t
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   201
    val p_inst =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   202
      concl_prop |> map_aterms varify_noninducts |> close_form
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   203
                 |> lambda (Free ind_x)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   204
                 |> string_for_term ctxt
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   205
  in
41207
f9c7bdc75dd0 reintroduce the higher penalty for skolems
blanchet
parents: 41205
diff changeset
   206
    ((fn () => name () ^ "[where " ^ p_name ^ " = " ^ quote p_inst ^ "]", loc),
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   207
     (multi, th |> read_instantiate ctxt [((p_name, 0), p_inst)]))
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   208
  end
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   209
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   210
fun type_match thy (T1, T2) =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   211
  (Sign.typ_match thy (T2, T1) Vartab.empty; true)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   212
  handle Type.TYPE_MATCH => false
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   213
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   214
fun instantiate_if_induct_rule ctxt stmt stmt_xs (ax as (_, (_, th))) =
41200
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   215
  case struct_induct_rule_on th of
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   216
    SOME (p_name, ind_T) =>
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   217
    let val thy = Proof_Context.theory_of ctxt in
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   218
      stmt_xs |> filter (fn (_, T) => type_match thy (T, ind_T))
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   219
              |> map_filter (try (instantiate_induct_rule ctxt stmt p_name ax))
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   220
    end
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   221
  | NONE => [ax]
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   222
28477
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents: 28065
diff changeset
   223
(***************************************************************)
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents: 28065
diff changeset
   224
(* Relevance Filtering                                         *)
9339d4dcec8b version of sledgehammer using threads instead of processes, misc cleanup;
wenzelm
parents: 28065
diff changeset
   225
(***************************************************************)
19194
7681c04d8bff Merged res_atp_setup.ML into res_atp.ML.
mengj
parents: 18986
diff changeset
   226
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   227
(*** constants with types ***)
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   228
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   229
fun order_of_type (Type (@{type_name fun}, [T1, @{typ bool}])) =
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   230
    order_of_type T1 (* cheat: pretend sets are first-order *)
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   231
  | order_of_type (Type (@{type_name fun}, [T1, T2])) =
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   232
    Int.max (order_of_type T1 + 1, order_of_type T2)
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   233
  | order_of_type (Type (_, Ts)) = fold (Integer.max o order_of_type) Ts 0
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   234
  | order_of_type _ = 0
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   235
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   236
(* An abstraction of Isabelle types and first-order terms *)
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   237
datatype pattern = PVar | PApp of string * pattern list
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   238
datatype ptype = PType of int * pattern list
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   239
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   240
fun string_for_pattern PVar = "_"
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   241
  | string_for_pattern (PApp (s, ps)) =
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   242
    if null ps then s else s ^ string_for_patterns ps
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   243
and string_for_patterns ps = "(" ^ commas (map string_for_pattern ps) ^ ")"
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   244
fun string_for_ptype (PType (_, ps)) = string_for_patterns ps
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   245
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   246
(*Is the second type an instance of the first one?*)
38824
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   247
fun match_pattern (PVar, _) = true
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   248
  | match_pattern (PApp _, PVar) = false
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   249
  | match_pattern (PApp (s, ps), PApp (t, qs)) =
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   250
    s = t andalso match_patterns (ps, qs)
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   251
and match_patterns (_, []) = true
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   252
  | match_patterns ([], _) = false
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   253
  | match_patterns (p :: ps, q :: qs) =
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   254
    match_pattern (p, q) andalso match_patterns (ps, qs)
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   255
fun match_ptype (PType (_, ps), PType (_, qs)) = match_patterns (ps, qs)
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   256
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   257
(* Is there a unifiable constant? *)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   258
fun pconst_mem f consts (s, ps) =
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   259
  exists (curry (match_ptype o f) ps)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   260
         (map snd (filter (curry (op =) s o fst) consts))
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   261
fun pconst_hyper_mem f const_tab (s, ps) =
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   262
  exists (curry (match_ptype o f) ps) (these (Symtab.lookup const_tab s))
37505
d9af5c01dc4a added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents: 37504
diff changeset
   263
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   264
fun pattern_for_type (Type (s, Ts)) = PApp (s, map pattern_for_type Ts)
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   265
  | pattern_for_type (TFree (s, _)) = PApp (s, [])
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   266
  | pattern_for_type (TVar _) = PVar
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   267
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   268
(* Pairs a constant with the list of its type instantiations. *)
41204
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   269
fun ptype thy const x =
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   270
  (if const then map pattern_for_type (these (try (Sign.const_typargs thy) x))
41204
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   271
   else [])
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   272
fun rich_ptype thy const (s, T) =
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   273
  PType (order_of_type T, ptype thy const (s, T))
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   274
fun rich_pconst thy const (s, T) = (s, rich_ptype thy const (s, T))
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   275
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   276
fun string_for_hyper_pconst (s, ps) =
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   277
  s ^ "{" ^ commas (map string_for_ptype ps) ^ "}"
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   278
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   279
(* Add a pconstant to the table, but a [] entry means a standard
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   280
   connective, which we ignore.*)
41066
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   281
fun add_pconst_to_table also_skolem (s, p) =
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   282
  if (not also_skolem andalso String.isPrefix skolem_prefix s) then I
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   283
  else Symtab.map_default (s, [p]) (insert (op =) p)
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   284
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   285
fun add_pconsts_in_term thy is_built_in_const also_skolems pos =
37505
d9af5c01dc4a added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents: 37504
diff changeset
   286
  let
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   287
    val flip = Option.map not
38587
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   288
    (* We include free variables, as well as constants, to handle locales. For
41205
209546e0af2c comment tuning
blanchet
parents: 41204
diff changeset
   289
       each quantifiers that must necessarily be skolemized by the automatic
209546e0af2c comment tuning
blanchet
parents: 41204
diff changeset
   290
       prover, we introduce a fresh constant to simulate the effect of
209546e0af2c comment tuning
blanchet
parents: 41204
diff changeset
   291
       Skolemization. *)
40373
ff0e17a9d840 pass proper type to SMT_Builtin.is_builtin
blanchet
parents: 40371
diff changeset
   292
    fun do_const const x ts =
41336
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   293
      let val (built_in, ts) = is_built_in_const x ts in
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   294
        (not built_in
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   295
         ? add_pconst_to_table also_skolems (rich_pconst thy const x))
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   296
        #> fold do_term ts
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   297
      end
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   298
    and do_term t =
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   299
      case strip_comb t of
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   300
        (Const x, ts) => do_const true x ts
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   301
      | (Free x, ts) => do_const false x ts
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   302
      | (Abs (_, T, t'), ts) =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   303
        (null ts
41066
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   304
         ? add_pconst_to_table true (abs_name, PType (order_of_type T + 1, [])))
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   305
        #> fold do_term (t' :: ts)
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   306
      | (_, ts) => fold do_term ts
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   307
    fun do_quantifier will_surely_be_skolemized abs_T body_t =
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   308
      do_formula pos body_t
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   309
      #> (if also_skolems andalso will_surely_be_skolemized then
41066
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   310
            add_pconst_to_table true
41207
f9c7bdc75dd0 reintroduce the higher penalty for skolems
blanchet
parents: 41205
diff changeset
   311
                (gensym skolem_prefix, PType (order_of_type abs_T, []))
38587
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   312
          else
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   313
            I)
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   314
    and do_term_or_formula T =
41273
35ce17cd7967 made the relevance filter treat unatomizable facts like "atomize_all" properly (these result in problems that get E spinning seemingly forever);
blanchet
parents: 41211
diff changeset
   315
      if T = HOLogic.boolT then do_formula NONE else do_term
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   316
    and do_formula pos t =
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   317
      case t of
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   318
        Const (@{const_name all}, _) $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   319
        do_quantifier (pos = SOME false) T t'
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   320
      | @{const "==>"} $ t1 $ t2 =>
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   321
        do_formula (flip pos) t1 #> do_formula pos t2
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   322
      | Const (@{const_name "=="}, Type (_, [T, _])) $ t1 $ t2 =>
38587
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   323
        fold (do_term_or_formula T) [t1, t2]
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   324
      | @{const Trueprop} $ t1 => do_formula pos t1
41140
9c68004b8c9d added Sledgehammer support for higher-order propositional reasoning
blanchet
parents: 41138
diff changeset
   325
      | @{const False} => I
9c68004b8c9d added Sledgehammer support for higher-order propositional reasoning
blanchet
parents: 41138
diff changeset
   326
      | @{const True} => I
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   327
      | @{const Not} $ t1 => do_formula (flip pos) t1
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   328
      | Const (@{const_name All}, _) $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   329
        do_quantifier (pos = SOME false) T t'
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   330
      | Const (@{const_name Ex}, _) $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   331
        do_quantifier (pos = SOME true) T t'
38795
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   332
      | @{const HOL.conj} $ t1 $ t2 => fold (do_formula pos) [t1, t2]
848be46708dc formerly unnamed infix conjunction and disjunction now named HOL.conj and HOL.disj
haftmann
parents: 38786
diff changeset
   333
      | @{const HOL.disj} $ t1 $ t2 => fold (do_formula pos) [t1, t2]
38786
e46e7a9cb622 formerly unnamed infix impliciation now named HOL.implies
haftmann
parents: 38752
diff changeset
   334
      | @{const HOL.implies} $ t1 $ t2 =>
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   335
        do_formula (flip pos) t1 #> do_formula pos t2
38864
4abe644fcea5 formerly unnamed infix equality now named HOL.eq
haftmann
parents: 38829
diff changeset
   336
      | Const (@{const_name HOL.eq}, Type (_, [T, _])) $ t1 $ t2 =>
38587
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   337
        fold (do_term_or_formula T) [t1, t2]
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   338
      | Const (@{const_name If}, Type (_, [_, Type (_, [T, _])]))
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   339
        $ t1 $ t2 $ t3 =>
1317657d6aa9 fix the relevance filter so that it ignores If, Ex1, Ball, Bex
blanchet
parents: 38395
diff changeset
   340
        do_formula NONE t1 #> fold (do_term_or_formula T) [t2, t3]
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   341
      | Const (@{const_name Ex1}, _) $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   342
        do_quantifier (is_some pos) T t'
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   343
      | Const (@{const_name Ball}, _) $ t1 $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   344
        do_quantifier (pos = SOME false) T
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   345
                      (HOLogic.mk_imp (incr_boundvars 1 t1 $ Bound 0, t'))
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   346
      | Const (@{const_name Bex}, _) $ t1 $ Abs (_, T, t') =>
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   347
        do_quantifier (pos = SOME true) T
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   348
                      (HOLogic.mk_conj (incr_boundvars 1 t1 $ Bound 0, t'))
37537
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   349
      | (t0 as Const (_, @{typ bool})) $ t1 =>
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   350
        do_term t0 #> do_formula pos t1  (* theory constant *)
8e56d1ccf189 improve the new "natural formula" fact filter
blanchet
parents: 37515
diff changeset
   351
      | _ => do_term t
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   352
  in do_formula pos end
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   353
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   354
(*Inserts a dummy "constant" referring to the theory name, so that relevance
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   355
  takes the given theory into account.*)
41200
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   356
fun theory_constify ({theory_const_rel_weight, theory_const_irrel_weight, ...}
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   357
                     : relevance_fudge) thy_name t =
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   358
  if exists (curry (op <) 0.0) [theory_const_rel_weight,
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   359
                                theory_const_irrel_weight] then
41200
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   360
    Const (thy_name ^ theory_const_suffix, @{typ bool}) $ t
37505
d9af5c01dc4a added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents: 37504
diff changeset
   361
  else
41200
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   362
    t
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   363
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   364
fun theory_const_prop_of fudge th =
6cc9b6fd7f6f add the current theory's constant to the goal to make theorems from the current theory more relevant on the first iteration already
blanchet
parents: 41199
diff changeset
   365
  theory_constify fudge (Context.theory_name (theory_of_thm th)) (prop_of th)
37505
d9af5c01dc4a added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents: 37504
diff changeset
   366
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   367
(**** Constant / Type Frequencies ****)
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   368
38743
69fa75354c58 simplify more code
blanchet
parents: 38742
diff changeset
   369
(* A two-dimensional symbol table counts frequencies of constants. It's keyed
69fa75354c58 simplify more code
blanchet
parents: 38742
diff changeset
   370
   first by constant name and second by its list of type instantiations. For the
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   371
   latter, we need a linear ordering on "pattern list". *)
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   372
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   373
fun pattern_ord p =
38743
69fa75354c58 simplify more code
blanchet
parents: 38742
diff changeset
   374
  case p of
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   375
    (PVar, PVar) => EQUAL
38823
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   376
  | (PVar, PApp _) => LESS
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   377
  | (PApp _, PVar) => GREATER
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   378
  | (PApp q1, PApp q2) =>
828e68441a2f renaming + treat "TFree" better in "pattern_for_type"
blanchet
parents: 38822
diff changeset
   379
    prod_ord fast_string_ord (dict_ord pattern_ord) (q1, q2)
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   380
fun ptype_ord (PType p, PType q) =
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   381
  prod_ord (dict_ord pattern_ord) int_ord (swap p, swap q)
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   382
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   383
structure PType_Tab = Table(type key = ptype val ord = ptype_ord)
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   384
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   385
fun count_fact_consts thy fudge =
37503
c2dfa26b9da6 cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents: 37502
diff changeset
   386
  let
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   387
    fun do_const const (s, T) ts =
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   388
      (* Two-dimensional table update. Constant maps to types maps to count. *)
41204
bd57cf5944cb get rid of experimental feature of term patterns in relevance filter -- doesn't work well unless we take into consideration the equality theory entailed by the relevant facts
blanchet
parents: 41202
diff changeset
   389
      PType_Tab.map_default (rich_ptype thy const (s, T), 0) (Integer.add 1)
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   390
      |> Symtab.map_default (s, PType_Tab.empty)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   391
      #> fold do_term ts
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   392
    and do_term t =
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   393
      case strip_comb t of
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   394
        (Const x, ts) => do_const true x ts
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   395
      | (Free x, ts) => do_const false x ts
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   396
      | (Abs (_, _, t'), ts) => fold do_term (t' :: ts)
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   397
      | (_, ts) => fold do_term ts
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   398
  in do_term o theory_const_prop_of fudge o snd end
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   399
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   400
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   401
(**** Actual Filtering Code ****)
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   402
39367
blanchet
parents: 39366
diff changeset
   403
fun pow_int _ 0 = 1.0
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   404
  | pow_int x 1 = x
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   405
  | pow_int x n = if n > 0 then x * pow_int x (n - 1) else pow_int x (n + 1) / x
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   406
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   407
(*The frequency of a constant is the sum of those of all instances of its type.*)
38824
f74513bbe627 cosmetics
blanchet
parents: 38823
diff changeset
   408
fun pconst_freq match const_tab (c, ps) =
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   409
  PType_Tab.fold (fn (qs, m) => match (ps, qs) ? Integer.add m)
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   410
                 (the (Symtab.lookup const_tab c)) 0
38686
45eeee8d6b12 modified relevance filter
blanchet
parents: 38684
diff changeset
   411
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   412
38085
cc44e887246c avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents: 38027
diff changeset
   413
(* A surprising number of theorems contain only a few significant constants.
cc44e887246c avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents: 38027
diff changeset
   414
   These include all induction rules, and other general theorems. *)
37503
c2dfa26b9da6 cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents: 37502
diff changeset
   415
c2dfa26b9da6 cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents: 37502
diff changeset
   416
(* "log" seems best in practice. A constant function of one ignores the constant
38938
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   417
   frequencies. Rare constants give more points if they are relevant than less
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   418
   rare ones. *)
39367
blanchet
parents: 39366
diff changeset
   419
fun rel_weight_for _ freq = 1.0 + 2.0 / Math.ln (Real.fromInt freq + 1.0)
38938
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   420
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   421
(* Irrelevant constants are treated differently. We associate lower penalties to
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   422
   very rare constants and very common ones -- the former because they can't
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   423
   lead to the inclusion of too many new facts, and the latter because they are
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   424
   so common as to be of little interest. *)
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   425
fun irrel_weight_for ({worse_irrel_freq, higher_order_irrel_weight, ...}
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   426
                      : relevance_fudge) order freq =
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   427
  let val (k, x) = worse_irrel_freq |> `Real.ceil in
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   428
    (if freq < k then Math.ln (Real.fromInt (freq + 1)) / Math.ln x
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   429
     else rel_weight_for order freq / rel_weight_for order k)
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   430
    * pow_int higher_order_irrel_weight (order - 1)
38938
2b93dbc07778 improve weighting of irrelevant constants, based on Mirabelle experiments
blanchet
parents: 38937
diff changeset
   431
  end
37503
c2dfa26b9da6 cosmetics + prevent consideration of inlined Skolem terms in relevance filter
blanchet
parents: 37502
diff changeset
   432
41790
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   433
fun multiplier_for_const_name local_const_multiplier s =
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   434
  if String.isSubstring "." s then 1.0 else local_const_multiplier
38821
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   435
41790
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   436
(* Computes a constant's weight, as determined by its frequency. *)
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   437
fun generic_pconst_weight local_const_multiplier abs_weight skolem_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   438
                          theory_const_weight weight_for f const_tab
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   439
                          (c as (s, PType (m, _))) =
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   440
  if s = abs_name then
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   441
    abs_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   442
  else if String.isPrefix skolem_prefix s then
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   443
    skolem_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   444
  else if String.isSuffix theory_const_suffix s then
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   445
    theory_const_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   446
  else
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   447
    multiplier_for_const_name local_const_multiplier s
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   448
    * weight_for m (pconst_freq (match_ptype o f) const_tab c)
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   449
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   450
fun rel_pconst_weight ({local_const_multiplier, abs_rel_weight,
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   451
                        theory_const_rel_weight, ...} : relevance_fudge)
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   452
                      const_tab =
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   453
  generic_pconst_weight local_const_multiplier abs_rel_weight 0.0
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   454
                        theory_const_rel_weight rel_weight_for I const_tab
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   455
fun irrel_pconst_weight (fudge as {local_const_multiplier, abs_irrel_weight,
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   456
                                   skolem_irrel_weight,
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   457
                                   theory_const_irrel_weight, ...}) const_tab =
41790
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   458
  generic_pconst_weight local_const_multiplier abs_irrel_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   459
                        skolem_irrel_weight theory_const_irrel_weight
56dcd46ddf7a give more weight to Frees than to Consts in relevance filter
blanchet
parents: 41768
diff changeset
   460
                        (irrel_weight_for fudge) swap const_tab
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   461
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   462
fun locality_bonus (_ : relevance_fudge) General = 0.0
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   463
  | locality_bonus {intro_bonus, ...} Intro = intro_bonus
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   464
  | locality_bonus {elim_bonus, ...} Elim = elim_bonus
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   465
  | locality_bonus {simp_bonus, ...} Simp = simp_bonus
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   466
  | locality_bonus {local_bonus, ...} Local = local_bonus
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   467
  | locality_bonus {assum_bonus, ...} Assum = assum_bonus
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   468
  | locality_bonus {chained_bonus, ...} Chained = chained_bonus
38751
01c4d14b2a61 add a bonus for chained facts, since they are likely to be relevant;
blanchet
parents: 38749
diff changeset
   469
40418
8b73059e97a1 better detection of completely irrelevant facts
blanchet
parents: 40408
diff changeset
   470
fun is_odd_const_name s =
8b73059e97a1 better detection of completely irrelevant facts
blanchet
parents: 40408
diff changeset
   471
  s = abs_name orelse String.isPrefix skolem_prefix s orelse
8b73059e97a1 better detection of completely irrelevant facts
blanchet
parents: 40408
diff changeset
   472
  String.isSuffix theory_const_suffix s
8b73059e97a1 better detection of completely irrelevant facts
blanchet
parents: 40408
diff changeset
   473
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   474
fun fact_weight fudge loc const_tab relevant_consts chained_consts fact_consts =
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   475
  case fact_consts |> List.partition (pconst_hyper_mem I relevant_consts)
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   476
                   ||> filter_out (pconst_hyper_mem swap relevant_consts) of
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   477
    ([], _) => 0.0
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   478
  | (rel, irrel) =>
40418
8b73059e97a1 better detection of completely irrelevant facts
blanchet
parents: 40408
diff changeset
   479
    if forall (forall (is_odd_const_name o fst)) [rel, irrel] then
40371
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   480
      0.0
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   481
    else
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   482
      let
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   483
        val irrel =
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   484
          irrel |> filter_out (pconst_mem swap rel orf
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   485
                               pconst_hyper_mem I chained_consts)
40371
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   486
        val rel_weight =
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   487
          0.0 |> fold (curry (op +) o rel_pconst_weight fudge const_tab) rel
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   488
        val irrel_weight =
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   489
          ~ (locality_bonus fudge loc)
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   490
          |> fold (curry (op +) o irrel_pconst_weight fudge const_tab) irrel
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   491
        val res = rel_weight / (rel_weight + irrel_weight)
8fe3c26c49af ignore facts with only theory constants in them
blanchet
parents: 40369
diff changeset
   492
      in if Real.isFinite res then res else 0.0 end
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   493
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   494
fun pconsts_in_fact thy is_built_in_const t =
38825
4ec3cbd95f25 rename and simplify
blanchet
parents: 38824
diff changeset
   495
  Symtab.fold (fn (s, pss) => fold (cons o pair s) pss)
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   496
              (Symtab.empty |> add_pconsts_in_term thy is_built_in_const true
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   497
                                                   (SOME true) t) []
42729
e011f632227c tune whitespace
blanchet
parents: 42728
diff changeset
   498
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   499
fun pair_consts_fact thy is_built_in_const fudge fact =
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   500
  case fact |> snd |> theory_const_prop_of fudge
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   501
            |> pconsts_in_fact thy is_built_in_const of
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   502
    [] => NONE
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   503
  | consts => SOME ((fact, consts), NONE)
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   504
41768
dd2125fb75f9 export more functionality of Sledgehammer to applications (for experiments)
blanchet
parents: 41767
diff changeset
   505
val const_names_in_fact = map fst ooo pconsts_in_fact
dd2125fb75f9 export more functionality of Sledgehammer to applications (for experiments)
blanchet
parents: 41767
diff changeset
   506
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   507
type annotated_thm =
38939
f0aa0c49fdbf add a penalty for being higher-order
blanchet
parents: 38938
diff changeset
   508
  (((unit -> string) * locality) * thm) * (string * ptype) list
37505
d9af5c01dc4a added code to optionally perform fact filtering on the original (non-CNF) formulas
blanchet
parents: 37504
diff changeset
   509
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   510
fun take_most_relevant ctxt max_relevant remaining_max
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   511
        ({max_imperfect, max_imperfect_exp, ...} : relevance_fudge)
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   512
        (candidates : (annotated_thm * real) list) =
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   513
  let
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   514
    val max_imperfect =
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   515
      Real.ceil (Math.pow (max_imperfect,
38904
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   516
                    Math.pow (Real.fromInt remaining_max
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   517
                              / Real.fromInt max_relevant, max_imperfect_exp)))
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   518
    val (perfect, imperfect) =
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   519
      candidates |> sort (Real.compare o swap o pairself snd)
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   520
                 |> take_prefix (fn (_, w) => w > 0.99999)
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   521
    val ((accepts, more_rejects), rejects) =
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   522
      chop max_imperfect imperfect |>> append perfect |>> chop remaining_max
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   523
  in
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   524
    trace_msg ctxt (fn () =>
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 41336
diff changeset
   525
        "Actually passed (" ^ string_of_int (length accepts) ^ " of " ^
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 41336
diff changeset
   526
        string_of_int (length candidates) ^ "): " ^
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   527
        (accepts |> map (fn ((((name, _), _), _), weight) =>
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   528
                            name () ^ " [" ^ Real.toString weight ^ "]")
38745
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   529
                 |> commas));
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   530
    (accepts, more_rejects @ rejects)
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   531
  end
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   532
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   533
fun if_empty_replace_with_locality thy is_built_in_const facts loc tab =
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   534
  if Symtab.is_empty tab then
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   535
    Symtab.empty
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   536
    |> fold (add_pconsts_in_term thy is_built_in_const false (SOME false))
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   537
            (map_filter (fn ((_, loc'), th) =>
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   538
                            if loc' = loc then SOME (prop_of th) else NONE)
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   539
                        facts)
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   540
  else
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   541
    tab
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   542
42702
blanchet
parents: 42680
diff changeset
   543
fun consider_arities is_built_in_const th =
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   544
  let
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   545
    fun aux _ _ NONE = NONE
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   546
      | aux t args (SOME tab) =
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   547
        case t of
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   548
          t1 $ t2 => SOME tab |> aux t1 (t2 :: args) |> aux t2 []
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   549
        | Const (x as (s, _)) =>
41336
0ea5b9c7d233 proper handling of the arguments of SMT builtins -- for numerals, ignore the arguments (Pls, Bit0, Bit1, ..), for functions, consider them;
blanchet
parents: 41279
diff changeset
   550
          (if is_built_in_const x args |> fst then
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   551
             SOME tab
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   552
           else case Symtab.lookup tab s of
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   553
             NONE => SOME (Symtab.update (s, length args) tab)
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   554
           | SOME n => if n = length args then SOME tab else NONE)
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   555
        | _ => SOME tab
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   556
  in aux (prop_of th) [] end
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   557
42702
blanchet
parents: 42680
diff changeset
   558
(* FIXME: This is currently only useful for polymorphic type systems. *)
blanchet
parents: 42680
diff changeset
   559
fun could_benefit_from_ext is_built_in_const facts =
blanchet
parents: 42680
diff changeset
   560
  fold (consider_arities is_built_in_const o snd) facts (SOME Symtab.empty)
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   561
  |> is_none
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   562
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   563
fun relevance_filter ctxt threshold0 decay max_relevant is_built_in_const
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   564
        (fudge as {threshold_divisor, ridiculous_threshold, ...})
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   565
        ({add, del, ...} : relevance_override) facts chained_ts hyp_ts concl_t =
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   566
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   567
    val thy = Proof_Context.theory_of ctxt
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   568
    val const_tab = fold (count_fact_consts thy fudge) facts Symtab.empty
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   569
    val add_pconsts = add_pconsts_in_term thy is_built_in_const false o SOME
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   570
    val chained_const_tab = Symtab.empty |> fold (add_pconsts true) chained_ts
38819
71c9f61516cd if the goal contains no constants or frees, fall back on chained facts, then on local facts, etc., instead of generating a trivial ATP problem
blanchet
parents: 38818
diff changeset
   571
    val goal_const_tab =
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   572
      Symtab.empty |> fold (add_pconsts true) hyp_ts
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   573
                   |> add_pconsts false concl_t
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   574
      |> (fn tab => if Symtab.is_empty tab then chained_const_tab else tab)
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   575
      |> fold (if_empty_replace_with_locality thy is_built_in_const facts)
38993
504b9e1efd33 give priority to assumptions in structured proofs
blanchet
parents: 38992
diff changeset
   576
              [Chained, Assum, Local]
39012
96d97d1c676f cosmetics
blanchet
parents: 38997
diff changeset
   577
    val add_ths = Attrib.eval_thms ctxt add
96d97d1c676f cosmetics
blanchet
parents: 38997
diff changeset
   578
    val del_ths = Attrib.eval_thms ctxt del
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   579
    val facts = facts |> filter_out (member Thm.eq_thm del_ths o snd)
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   580
    fun iter j remaining_max threshold rel_const_tab hopeless hopeful =
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   581
      let
40191
257d2e06bfb8 put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents: 40071
diff changeset
   582
        fun relevant [] _ [] =
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   583
            (* Nothing has been added this iteration. *)
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   584
            if j = 0 andalso threshold >= ridiculous_threshold then
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   585
              (* First iteration? Try again. *)
40070
bdb890782d4a replaced references with proper record that's threaded through
blanchet
parents: 39958
diff changeset
   586
              iter 0 max_relevant (threshold / threshold_divisor) rel_const_tab
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   587
                   hopeless hopeful
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   588
            else
40191
257d2e06bfb8 put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents: 40071
diff changeset
   589
              []
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   590
          | relevant candidates rejects [] =
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   591
            let
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   592
              val (accepts, more_rejects) =
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   593
                take_most_relevant ctxt max_relevant remaining_max fudge
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   594
                                   candidates
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   595
              val rel_const_tab' =
38745
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   596
                rel_const_tab
41066
3890ef4e02f9 pass constant arguments to the built-in check function, cf. d2b1fc1b8e19
blanchet
parents: 40418
diff changeset
   597
                |> fold (add_pconst_to_table false) (maps (snd o fst) accepts)
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   598
              fun is_dirty (c, _) =
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   599
                Symtab.lookup rel_const_tab' c <> Symtab.lookup rel_const_tab c
38745
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   600
              val (hopeful_rejects, hopeless_rejects) =
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   601
                 (rejects @ hopeless, ([], []))
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   602
                 |-> fold (fn (ax as (_, consts), old_weight) =>
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   603
                              if exists is_dirty consts then
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   604
                                apfst (cons (ax, NONE))
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   605
                              else
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   606
                                apsnd (cons (ax, old_weight)))
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   607
                 |>> append (more_rejects
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   608
                             |> map (fn (ax as (_, consts), old_weight) =>
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   609
                                        (ax, if exists is_dirty consts then NONE
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   610
                                             else SOME old_weight)))
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   611
              val threshold =
38822
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   612
                1.0 - (1.0 - threshold)
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   613
                      * Math.pow (decay, Real.fromInt (length accepts))
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   614
              val remaining_max = remaining_max - length accepts
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   615
            in
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   616
              trace_msg ctxt (fn () => "New or updated constants: " ^
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   617
                  commas (rel_const_tab' |> Symtab.dest
38822
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   618
                          |> subtract (op =) (rel_const_tab |> Symtab.dest)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   619
                          |> map string_for_hyper_pconst));
38745
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   620
              map (fst o fst) accepts @
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   621
              (if remaining_max = 0 then
40191
257d2e06bfb8 put theorems added using "add:" at the beginning of the list returned by the relevance filter, so that they don't get truncated away
blanchet
parents: 40071
diff changeset
   622
                 []
38745
ad577fd62ee4 reorganize options regarding to the relevance threshold and decay
blanchet
parents: 38744
diff changeset
   623
               else
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   624
                 iter (j + 1) remaining_max threshold rel_const_tab'
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   625
                      hopeless_rejects hopeful_rejects)
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   626
            end
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   627
          | relevant candidates rejects
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   628
                     (((ax as (((_, loc), _), fact_consts)), cached_weight)
38747
b264ae66cede fiddle with relevance filter
blanchet
parents: 38745
diff changeset
   629
                      :: hopeful) =
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   630
            let
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   631
              val weight =
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   632
                case cached_weight of
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   633
                  SOME w => w
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   634
                | NONE => fact_weight fudge loc const_tab rel_const_tab
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   635
                                      chained_const_tab fact_consts
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   636
            in
38741
7635bf8918a1 get rid of "defs_relevant" feature;
blanchet
parents: 38739
diff changeset
   637
              if weight >= threshold then
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   638
                relevant ((ax, weight) :: candidates) rejects hopeful
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   639
              else
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   640
                relevant candidates ((ax, weight) :: rejects) hopeful
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   641
            end
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   642
        in
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   643
          trace_msg ctxt (fn () =>
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   644
              "ITERATION " ^ string_of_int j ^ ": current threshold: " ^
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   645
              Real.toString threshold ^ ", constants: " ^
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   646
              commas (rel_const_tab |> Symtab.dest
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   647
                      |> filter (curry (op <>) [] o snd)
38827
cf01645cbbce extended relevance filter with first-order term matching
blanchet
parents: 38825
diff changeset
   648
                      |> map string_for_hyper_pconst));
38889
d0e3f68dde63 fiddle with the relevance filter
blanchet
parents: 38829
diff changeset
   649
          relevant [] [] hopeful
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   650
        end
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   651
    fun add_facts ths accepts =
41167
b05014180288 move facts supplied with "add:" to the front, so that they get a better weight (SMT)
blanchet
parents: 41159
diff changeset
   652
      (facts |> filter (member Thm.eq_thm ths o snd)) @
b05014180288 move facts supplied with "add:" to the front, so that they get a better weight (SMT)
blanchet
parents: 41159
diff changeset
   653
      (accepts |> filter_out (member Thm.eq_thm ths o snd))
40408
0d0acdf068b8 always honor the max relevant constraint
blanchet
parents: 40375
diff changeset
   654
      |> take max_relevant
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   655
  in
40369
53dca3bd4250 use the SMT integration's official list of built-ins
blanchet
parents: 40251
diff changeset
   656
    facts |> map_filter (pair_consts_fact thy is_built_in_const fudge)
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   657
          |> iter 0 max_relevant threshold0 goal_const_tab []
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   658
          |> not (null add_ths) ? add_facts add_ths
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   659
          |> (fn accepts =>
42702
blanchet
parents: 42680
diff changeset
   660
                 accepts |> could_benefit_from_ext is_built_in_const accepts
41158
8c9c31a757f5 make Sledgehammer's relevance filter include the "ext" rule when appropriate
blanchet
parents: 41140
diff changeset
   661
                            ? add_facts @{thms ext})
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   662
          |> tap (fn accepts => trace_msg ctxt (fn () =>
41491
a2ad5b824051 eliminated Int.toString;
wenzelm
parents: 41336
diff changeset
   663
                      "Total relevant: " ^ string_of_int (length accepts)))
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   664
  end
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   665
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   666
24287
c857dac06da6 combining the relevance filter with res_atp
paulson
parents: 24286
diff changeset
   667
(***************************************************************)
19768
9afd9b9c47d0 ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents: 19746
diff changeset
   668
(* Retrieving and filtering lemmas                             *)
9afd9b9c47d0 ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents: 19746
diff changeset
   669
(***************************************************************)
9afd9b9c47d0 ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents: 19746
diff changeset
   670
33022
c95102496490 Removal of the unused atpset concept, the atp attribute and some related code.
paulson
parents: 32994
diff changeset
   671
(*** retrieve lemmas and filter them ***)
19768
9afd9b9c47d0 ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents: 19746
diff changeset
   672
20757
fe84fe0dfd30 Definitions produced by packages are now blacklisted.
paulson
parents: 20661
diff changeset
   673
(*Reject theorems with names like "List.filter.filter_list_def" or
21690
552d20ff9a95 Removal of theorem tagging, which the ATP linkup no longer requires.
paulson
parents: 21588
diff changeset
   674
  "Accessible_Part.acc.defs", as these are definitions arising from packages.*)
20757
fe84fe0dfd30 Definitions produced by packages are now blacklisted.
paulson
parents: 20661
diff changeset
   675
fun is_package_def a =
40205
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   676
  let val names = Long_Name.explode a in
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   677
    (length names > 2 andalso not (hd names = "local") andalso
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   678
     String.isSuffix "_def" a) orelse String.isSuffix "_defs" a
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   679
  end
20757
fe84fe0dfd30 Definitions produced by packages are now blacklisted.
paulson
parents: 20661
diff changeset
   680
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   681
fun mk_fact_table g f xs =
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   682
  fold (Termtab.update o `(g o prop_of o f)) xs Termtab.empty
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   683
fun uniquify xs = Termtab.fold (cons o snd) (mk_fact_table I snd xs) []
19768
9afd9b9c47d0 ATP/res_clasimpset.ML has been merged into res_atp.ML.
mengj
parents: 19746
diff changeset
   684
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   685
(* FIXME: put other record thms here, or declare as "no_atp" *)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   686
fun multi_base_blacklist ctxt =
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   687
  ["defs", "select_defs", "update_defs", "split", "splits", "split_asm",
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   688
   "cases", "ext_cases", "eq.simps", "eq.refl", "nchotomy", "case_cong",
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   689
   "weak_case_cong"]
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   690
  |> not (Config.get ctxt instantiate_inducts) ? append ["induct", "inducts"]
38682
3a203da3f89b weed out junk in relevance filter
blanchet
parents: 38681
diff changeset
   691
  |> map (prefix ".")
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   692
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   693
val max_lambda_nesting = 3
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   694
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   695
fun term_has_too_many_lambdas max (t1 $ t2) =
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   696
    exists (term_has_too_many_lambdas max) [t1, t2]
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   697
  | term_has_too_many_lambdas max (Abs (_, _, t)) =
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   698
    max = 0 orelse term_has_too_many_lambdas (max - 1) t
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   699
  | term_has_too_many_lambdas _ _ = false
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   700
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   701
(* Don't count nested lambdas at the level of formulas, since they are
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   702
   quantifiers. *)
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   703
fun formula_has_too_many_lambdas Ts (Abs (_, T, t)) =
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   704
    formula_has_too_many_lambdas (T :: Ts) t
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   705
  | formula_has_too_many_lambdas Ts t =
41273
35ce17cd7967 made the relevance filter treat unatomizable facts like "atomize_all" properly (these result in problems that get E spinning seemingly forever);
blanchet
parents: 41211
diff changeset
   706
    if member (op =) [HOLogic.boolT, propT] (fastype_of1 (Ts, t)) then
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   707
      exists (formula_has_too_many_lambdas Ts) (#2 (strip_comb t))
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   708
    else
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   709
      term_has_too_many_lambdas max_lambda_nesting t
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   710
38692
89d3550d8e16 cosmetics
blanchet
parents: 38689
diff changeset
   711
(* The max apply depth of any "metis" call in "Metis_Examples" (on 2007-10-31)
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   712
   was 11. *)
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   713
val max_apply_depth = 15
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   714
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   715
fun apply_depth (f $ t) = Int.max (apply_depth f, apply_depth t + 1)
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   716
  | apply_depth (Abs (_, _, t)) = apply_depth t
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   717
  | apply_depth _ = 0
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   718
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   719
fun is_formula_too_complex t =
38085
cc44e887246c avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents: 38027
diff changeset
   720
  apply_depth t > max_apply_depth orelse formula_has_too_many_lambdas [] t
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   721
39946
78faa9b31202 move Metis into Plain
blanchet
parents: 39896
diff changeset
   722
(* FIXME: Extend to "Meson" and "Metis" *)
37543
2e733b0a963c a76ace919f1c wasn't quite right; second try
blanchet
parents: 37538
diff changeset
   723
val exists_sledgehammer_const =
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   724
  exists_Const (fn (s, _) => String.isPrefix sledgehammer_prefix s)
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   725
38904
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   726
(* FIXME: make more reliable *)
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   727
val exists_low_level_class_const =
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   728
  exists_Const (fn (s, _) =>
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   729
     String.isSubstring (Long_Name.separator ^ "class" ^ Long_Name.separator) s)
5e760c0f81a6 rule out low-level class facts
blanchet
parents: 38901
diff changeset
   730
38821
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   731
fun is_metastrange_theorem th =
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   732
  case head_of (concl_of th) of
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   733
      Const (a, _) => (a <> @{const_name Trueprop} andalso
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   734
                       a <> @{const_name "=="})
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   735
    | _ => false
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   736
38821
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   737
fun is_that_fact th =
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   738
  String.isSuffix (Long_Name.separator ^ Obtain.thatN) (Thm.get_name_hint th)
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   739
  andalso exists_subterm (fn Free (s, _) => s = Name.skolem Auto_Bind.thesisN
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   740
                           | _ => false) (prop_of th)
d0275b6c4e9d avoid needless "that" fact
blanchet
parents: 38820
diff changeset
   741
37626
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   742
val type_has_top_sort =
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   743
  exists_subtype (fn TFree (_, []) => true | TVar (_, []) => true | _ => false)
1146291fe718 move blacklisting completely out of the clausifier;
blanchet
parents: 37616
diff changeset
   744
38085
cc44e887246c avoid "clause" and "cnf" terminology where it no longer makes sense
blanchet
parents: 38027
diff changeset
   745
(**** Predicates to detect unwanted facts (prolific or likely to cause
37347
635425a442e8 show more respect for user-specified facts, even if they could lead to unsound proofs + don't throw away "unsound" theorems in "full_type" mode, since they are then sound
blanchet
parents: 37345
diff changeset
   746
      unsoundness) ****)
21470
7c1b59ddcd56 Consolidation of code to "blacklist" unhelpful theorems, including record
paulson
parents: 21431
diff changeset
   747
42638
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   748
fun is_theorem_bad_for_atps thm =
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   749
  let val t = prop_of thm in
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   750
    is_formula_too_complex t orelse exists_type type_has_top_sort t orelse
42638
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   751
    exists_sledgehammer_const t orelse exists_low_level_class_const t orelse
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   752
    is_metastrange_theorem thm orelse is_that_fact thm
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   753
  end
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   754
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   755
fun meta_equify (@{const Trueprop}
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   756
                 $ (Const (@{const_name HOL.eq}, Type (_, [T, _])) $ t1 $ t2)) =
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   757
    Const (@{const_name "=="}, T --> T --> @{typ prop}) $ t1 $ t2
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   758
  | meta_equify t = t
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   759
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   760
val normalize_simp_prop =
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   761
  meta_equify
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   762
  #> map_aterms (fn Var ((s, _), T) => Var ((s, 0), T) | t => t)
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   763
  #> map_types (map_type_tvar (fn ((s, _), S) => TVar ((s, 0), S)))
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   764
38937
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   765
fun clasimpset_rules_of ctxt =
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   766
  let
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   767
    val {safeIs, safeEs, hazIs, hazEs, ...} = ctxt |> claset_of |> rep_cs
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   768
    val intros = safeIs @ hazIs
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   769
    val elims = map Classical.classical_rule (safeEs @ hazEs)
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   770
    val simps = ctxt |> simpset_of |> dest_ss |> #simps
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   771
  in
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   772
    (mk_fact_table I I intros,
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   773
     mk_fact_table I I elims,
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   774
     mk_fact_table normalize_simp_prop snd simps)
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   775
  end
38937
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   776
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   777
fun all_facts ctxt reserved really_all add_ths chained_ths =
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   778
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   779
    val thy = Proof_Context.theory_of ctxt
39557
fe5722fce758 renamed structure PureThy to Pure_Thy and moved most content to Global_Theory, to emphasize that this is global-only;
wenzelm
parents: 39367
diff changeset
   780
    val global_facts = Global_Theory.facts_of thy
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   781
    val local_facts = Proof_Context.facts_of ctxt
38644
25bbbaf7ce65 don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents: 38629
diff changeset
   782
    val named_locals = local_facts |> Facts.dest_static []
38993
504b9e1efd33 give priority to assumptions in structured proofs
blanchet
parents: 38992
diff changeset
   783
    val assms = Assumption.all_assms_of ctxt
504b9e1efd33 give priority to assumptions in structured proofs
blanchet
parents: 38992
diff changeset
   784
    fun is_assum th = exists (fn ct => prop_of th aconv term_of ct) assms
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   785
    val is_chained = member Thm.eq_thm chained_ths
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   786
    val (intros, elims, simps) = clasimpset_rules_of ctxt
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   787
    fun locality_of_theorem global th =
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   788
      if is_chained th then
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   789
        Chained
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   790
      else if global then
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   791
        let val t = prop_of th in
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   792
          if Termtab.defined intros t then Intro
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   793
          else if Termtab.defined elims t then Elim
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   794
          else if Termtab.defined simps (normalize_simp_prop t) then Simp
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   795
          else General
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   796
        end
38937
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   797
      else
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   798
        if is_assum th then Assum else Local
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38699
diff changeset
   799
    fun is_good_unnamed_local th =
38820
d0f98bd81a85 add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents: 38819
diff changeset
   800
      not (Thm.has_name_hint th) andalso
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38699
diff changeset
   801
      forall (fn (_, ths) => not (member Thm.eq_thm ths th)) named_locals
38644
25bbbaf7ce65 don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents: 38629
diff changeset
   802
    val unnamed_locals =
38820
d0f98bd81a85 add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents: 38819
diff changeset
   803
      union Thm.eq_thm (Facts.props local_facts) chained_ths
d0f98bd81a85 add nameless chained facts to the pool of things known to Sledgehammer
blanchet
parents: 38819
diff changeset
   804
      |> filter is_good_unnamed_local |> map (pair "" o single)
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   805
    val full_space =
38738
0ce517c1970f make sure that "undo_ascii_of" is the inverse of "ascii_of", also for non-printable characters -- and avoid those in ``-style facts
blanchet
parents: 38699
diff changeset
   806
      Name_Space.merge (Facts.space_of global_facts, Facts.space_of local_facts)
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   807
    fun add_facts global foldx facts =
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   808
      foldx (fn (name0, ths) =>
41989
c1d560db15ec add option to relevance filter's "all_facts" function to really get all facts (needed for some experiments)
blanchet
parents: 41790
diff changeset
   809
        if not really_all andalso name0 <> "" andalso
39012
96d97d1c676f cosmetics
blanchet
parents: 38997
diff changeset
   810
           forall (not o member Thm.eq_thm add_ths) ths andalso
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   811
           (Facts.is_concealed facts name0 orelse
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   812
            (not (Config.get ctxt ignore_no_atp) andalso
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   813
             is_package_def name0) orelse
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   814
            exists (fn s => String.isSuffix s name0)
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   815
                   (multi_base_blacklist ctxt) orelse
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   816
            String.isSuffix "_def_raw" (* FIXME: crude hack *) name0) then
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   817
          I
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   818
        else
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   819
          let
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   820
            val multi = length ths > 1
41279
e0400b05a62c escape backticks in altstrings
blanchet
parents: 41273
diff changeset
   821
            val backquote_thm =
e0400b05a62c escape backticks in altstrings
blanchet
parents: 41273
diff changeset
   822
              backquote o string_for_term ctxt o close_form o prop_of
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   823
            fun check_thms a =
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   824
              case try (Proof_Context.get_thms ctxt) a of
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   825
                NONE => false
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   826
              | SOME ths' => Thm.eq_thms (ths, ths')
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   827
          in
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   828
            pair 1
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   829
            #> fold (fn th => fn (j, rest) =>
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   830
                        (j + 1,
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   831
                         if is_theorem_bad_for_atps th andalso
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   832
                            not (member Thm.eq_thm add_ths th) then
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   833
                           rest
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   834
                         else
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   835
                           (((fn () =>
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   836
                                 if name0 = "" then
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   837
                                   th |> backquote_thm
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   838
                                 else
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   839
                                   [Facts.extern ctxt facts name0,
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   840
                                    Name_Space.extern ctxt full_space name0,
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   841
                                    name0]
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   842
                                   |> find_first check_thms
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   843
                                   |> (fn SOME name =>
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   844
                                          make_name reserved multi j name
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   845
                                        | NONE => "")),
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   846
                              locality_of_theorem global th),
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   847
                              (multi, th)) :: rest)) ths
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   848
            #> snd
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   849
          end)
38644
25bbbaf7ce65 don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents: 38629
diff changeset
   850
  in
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   851
    [] |> add_facts false fold local_facts (unnamed_locals @ named_locals)
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   852
       |> add_facts true Facts.fold_static global_facts global_facts
38644
25bbbaf7ce65 don't penalize abstractions in relevance filter + support nameless `foo`-style facts
blanchet
parents: 38629
diff changeset
   853
  end
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   854
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   855
(* The single-name theorems go after the multiple-name ones, so that single
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   856
   names are preferred when both are available. *)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   857
fun rearrange_facts ctxt only =
38744
2b6333f78a9e make relevance filter work in term of a "max_relevant" option + use Vampire SOS;
blanchet
parents: 38743
diff changeset
   858
  List.partition (fst o snd) #> op @ #> map (apsnd snd)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   859
  #> (not (Config.get ctxt ignore_no_atp) andalso not only)
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   860
     ? filter_out (No_ATPs.member ctxt o snd)
38627
760a2d5cc671 make sure minimizer facts go through "transform_elim_theorems"
blanchet
parents: 38617
diff changeset
   861
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   862
fun external_frees t =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   863
  [] |> Term.add_frees t |> filter_out (can Name.dest_internal o fst)
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   864
42638
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   865
fun relevant_facts ctxt (threshold0, threshold1) max_relevant is_built_in_const
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   866
                   fudge (override as {add, only, ...}) chained_ths hyp_ts
a7a30721767a have each ATP filter out dangerous facts for themselves, based on their type system
blanchet
parents: 42589
diff changeset
   867
                   concl_t =
37538
97ab019d5ac8 make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents: 37537
diff changeset
   868
  let
42361
23f352990944 modernized structure Proof_Context;
wenzelm
parents: 42358
diff changeset
   869
    val thy = Proof_Context.theory_of ctxt
38822
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   870
    val decay = Math.pow ((1.0 - threshold1) / (1.0 - threshold0),
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   871
                          1.0 / Real.fromInt (max_relevant + 1))
39012
96d97d1c676f cosmetics
blanchet
parents: 38997
diff changeset
   872
    val add_ths = Attrib.eval_thms ctxt add
38696
4c6b65d6a135 quote facts whose names collide with a keyword or command name (cf. "subclass" in "Jinja/J/TypeSafe.thy")
blanchet
parents: 38692
diff changeset
   873
    val reserved = reserved_isar_keyword_table ()
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   874
    val ind_stmt =
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   875
      Logic.list_implies (hyp_ts |> filter_out (null o external_frees), concl_t)
41211
1e2e16bc0077 no need to do a super-duper atomization if Metis fails afterwards anyway
blanchet
parents: 41207
diff changeset
   876
      |> Object_Logic.atomize_term thy
41199
4698d12dd860 instantiate induction rules automatically
blanchet
parents: 41167
diff changeset
   877
    val ind_stmt_xs = external_frees ind_stmt
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   878
    val facts =
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   879
      (if only then
38752
6628adcae4a7 consider "locality" when assigning weights to facts
blanchet
parents: 38751
diff changeset
   880
         maps (map (fn ((name, loc), th) => ((K name, loc), (true, th)))
40205
277508b07418 if "debug" is on, print list of relevant facts (poweruser request);
blanchet
parents: 40204
diff changeset
   881
               o fact_from_ref ctxt reserved chained_ths) add
38699
27378b4a776b compute names lazily;
blanchet
parents: 38698
diff changeset
   882
       else
42641
2cd4e6463842 recognize simplification rules even if they look a bit different from the theorems in the theories (meta equality, variable numbers)
blanchet
parents: 42638
diff changeset
   883
         all_facts ctxt reserved false add_ths chained_ths)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   884
      |> Config.get ctxt instantiate_inducts
41273
35ce17cd7967 made the relevance filter treat unatomizable facts like "atomize_all" properly (these result in problems that get E spinning seemingly forever);
blanchet
parents: 41211
diff changeset
   885
         ? maps (instantiate_if_induct_rule ctxt ind_stmt ind_stmt_xs)
42728
44cd74a419ce added configuration options for experimental features
blanchet
parents: 42702
diff changeset
   886
      |> rearrange_facts ctxt only
38937
1b1a2f5ccd7d take into consideration whether a fact is an "intro"/"elim"/"simp" rule as an additional factor influencing the relevance filter
blanchet
parents: 38907
diff changeset
   887
      |> uniquify
37538
97ab019d5ac8 make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents: 37537
diff changeset
   888
  in
42646
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   889
    trace_msg ctxt (fn () => "Considering " ^ string_of_int (length facts) ^
4781fcd53572 replaced some Unsynchronized.refs with Config.Ts
blanchet
parents: 42641
diff changeset
   890
                             " facts");
39366
f58fbb959826 handle relevance filter corner cases more gracefully;
blanchet
parents: 39265
diff changeset
   891
    (if only orelse threshold1 < 0.0 then
40204
da97d75e20e6 standardize on "fact" terminology (vs. "axiom" or "theorem") in Sledgehammer -- but keep "Axiom" in the lower-level "ATP_Problem" module
blanchet
parents: 40191
diff changeset
   892
       facts
39366
f58fbb959826 handle relevance filter corner cases more gracefully;
blanchet
parents: 39265
diff changeset
   893
     else if threshold0 > 1.0 orelse threshold0 > threshold1 orelse
f58fbb959826 handle relevance filter corner cases more gracefully;
blanchet
parents: 39265
diff changeset
   894
             max_relevant = 0 then
38739
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   895
       []
8b8ed80b5699 renamed "relevance_convergence" to "relevance_decay"
blanchet
parents: 38738
diff changeset
   896
     else
42732
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   897
       relevance_filter ctxt threshold0 decay max_relevant is_built_in_const
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   898
           fudge override facts (chained_ths |> map prop_of) hyp_ts
86683865278d no penality for constants that appear in chained facts
blanchet
parents: 42730
diff changeset
   899
           (concl_t |> theory_constify fudge (Context.theory_name thy)))
38822
aa0101e618e2 fix threshold computation + remove "op =" from relevant constants
blanchet
parents: 38821
diff changeset
   900
    |> map (apfst (apfst (fn f => f ())))
37538
97ab019d5ac8 make sure that theorems passed using "add:" to Sledgehammer are not eliminated on heuristic grounds
blanchet
parents: 37537
diff changeset
   901
  end
30536
07b4f050e4df split relevance-filter and writing of problem-files;
immler@in.tum.de
parents: 30364
diff changeset
   902
15347
14585bc8fa09 resolution package tools by Jia Meng
paulson
parents:
diff changeset
   903
end;