src/HOL/Tools/ATP/reduce_axiomsN.ML
author wenzelm
Mon, 17 Jul 2006 18:42:38 +0200
changeset 20139 804927db5311
parent 20132 de3c295000b2
child 20153 6ff5d35749b0
permissions -rw-r--r--
replaced butlast by Library.split_last;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19208
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
     1
(* Authors: Jia Meng, NICTA and Lawrence C Paulson, Cambridge University Computer Laboratory
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
     2
   ID: $Id$
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
     3
   Filtering strategies *)
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
     4
18791
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
     5
structure ReduceAxiomsN =
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
     6
struct
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
     7
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
     8
val pass_mark = ref 0.6;
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
     9
val convergence = ref 2.4;   (*Higher numbers allow longer inference chains*)
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    10
val follow_defs = ref true;  (*Follow definitions. Makes problems bigger.*)
18791
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
    11
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    12
fun log_weight2 (x:real) = 1.0 + 2.0/Math.ln (x+1.0);
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    13
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    14
(*The default seems best in practice. A constant function of one ignores
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    15
  the constant frequencies.*)
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
    16
val weight_fn = ref log_weight2;
19334
96ca738055a6 Simplified version of Jia's filter. Now all constants are pooled, rather than
paulson
parents: 19321
diff changeset
    17
18791
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
    18
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    19
(*Including equality in this list might be expected to stop rules like subset_antisym from
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    20
  being chosen, but for some reason filtering works better with them listed.*)
19208
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
    21
val standard_consts =
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    22
  ["Trueprop","==>","all","Ex","op &","op |","Not","All","op -->",
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    23
   "op =","==","True","False"];
18791
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
    24
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
    25
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    26
(*** constants with types ***)
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    27
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    28
(*An abstraction of Isabelle types*)
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    29
datatype const_typ =  CTVar | CType of string * const_typ list
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    30
19208
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
    31
fun uni_type (CType(con1,args1)) (CType(con2,args2)) = con1=con2 andalso uni_types args1 args2
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
    32
  | uni_type (CType _) CTVar = true
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    33
  | uni_type CTVar CTVar = true
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    34
  | uni_type CTVar _ = false
19208
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
    35
and uni_types [] [] = true
3e8006cbc925 Tidying and restructuring.
paulson
parents: 19200
diff changeset
    36
  | uni_types (a1::as1) (a2::as2) = uni_type a1 a2 andalso uni_types as1 as2;
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    37
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    38
(*Is there a unifiable constant?*)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    39
fun uni_mem gctab (c,c_typ) =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    40
  case Symtab.lookup gctab c of
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    41
      NONE => false
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    42
    | SOME ctyps_list => exists (uni_types c_typ) ctyps_list;
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    43
  
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    44
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    45
fun const_typ_of (Type (c,typs)) = CType (c, map const_typ_of typs) 
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    46
  | const_typ_of (TFree _) = CTVar
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    47
  | const_typ_of (TVar _) = CTVar
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    48
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    49
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    50
fun const_with_typ thy (c,typ) = 
19212
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
    51
    let val tvars = Sign.const_typargs thy (c,typ)
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    52
    in (c, map const_typ_of tvars) end
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    53
    handle TYPE _ => (c,[]);   (*Variable (locale constant): monomorphic*)   
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    54
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    55
fun add_const_typ_table ((c,ctyps), tab) =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    56
  case Symtab.lookup tab c of
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    57
      NONE => Symtab.update (c, [ctyps]) tab
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    58
    | SOME [] => tab  (*ignore!*)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    59
    | SOME ctyps_list => Symtab.update (c, ctyps ins ctyps_list) tab;
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    60
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
    61
(*Free variables are counted, as well as constants, to handle locales*)
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    62
fun add_term_consts_typs_rm thy (Const(c, typ), tab) =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    63
      add_const_typ_table (const_with_typ thy (c,typ), tab) 
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    64
  | add_term_consts_typs_rm thy (Free(c, typ), tab) =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    65
      add_const_typ_table (const_with_typ thy (c,typ), tab) 
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    66
  | add_term_consts_typs_rm thy (t $ u, tab) =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    67
      add_term_consts_typs_rm thy (t, add_term_consts_typs_rm thy (u, tab))
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    68
  | add_term_consts_typs_rm thy (Abs(_,_,t), tab) = add_term_consts_typs_rm thy (t, tab)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    69
  | add_term_consts_typs_rm thy (_, tab) = tab;
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    70
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    71
(*The empty list here indicates that the constant is being ignored*)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    72
fun add_standard_const (s,tab) = Symtab.update (s,[]) tab;
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    73
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    74
val null_const_tab : const_typ list list Symtab.table = 
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    75
    foldl add_standard_const Symtab.empty standard_consts;
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    76
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
    77
fun get_goal_consts_typs thy cs = foldl (add_term_consts_typs_rm thy) null_const_tab cs;
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
    78
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    79
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    80
(**** Constant / Type Frequencies ****)
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    81
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    82
local
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    83
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    84
fun cons_nr CTVar = 0
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    85
  | cons_nr (CType _) = 1;
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    86
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    87
in
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    88
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    89
fun const_typ_ord TU =
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    90
  case TU of
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    91
    (CType (a, Ts), CType (b, Us)) =>
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    92
      (case fast_string_ord(a,b) of EQUAL => dict_ord const_typ_ord (Ts,Us) | ord => ord)
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    93
  | (T, U) => int_ord (cons_nr T, cons_nr U);
19212
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
    94
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    95
end;
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    96
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
    97
structure CTtab = TableFun(type key = const_typ list val ord = dict_ord const_typ_ord);
19212
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
    98
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
    99
fun count_axiom_consts thy ((thm,_), tab) = 
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   100
  let fun count_const (a, T, tab) =
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   101
	let val (c, cts) = const_with_typ thy (a,T)
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   102
	    val cttab = Option.getOpt (Symtab.lookup tab c, CTtab.empty)
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   103
	    val n = Option.getOpt (CTtab.lookup cttab cts, 0)
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   104
	in 
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   105
	    Symtab.update (c, CTtab.update (cts, n+1) cttab) tab
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   106
	end
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   107
      fun count_term_consts (Const(a,T), tab) = count_const(a,T,tab)
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   108
	| count_term_consts (Free(a,T), tab) = count_const(a,T,tab)
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   109
	| count_term_consts (t $ u, tab) =
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   110
	    count_term_consts (t, count_term_consts (u, tab))
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   111
	| count_term_consts (Abs(_,_,t), tab) = count_term_consts (t, tab)
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   112
	| count_term_consts (_, tab) = tab
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   113
  in  count_term_consts (prop_of thm, tab)  end;
19212
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
   114
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   115
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   116
(******** filter clauses ********)
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   117
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   118
fun const_weight ctab (c, cts) =
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   119
  let val pairs = CTtab.dest (Option.valOf (Symtab.lookup ctab c))
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   120
      fun add ((cts',m), n) = if uni_types cts cts' then m+n else n
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   121
  in  List.foldl add 0 pairs  end;
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   122
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   123
fun add_ct_weight ctab ((c,T), w) =
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   124
  w + !weight_fn (real (const_weight ctab (c,T)));
19212
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
   125
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
   126
fun consts_typs_weight ctab =
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
   127
    List.foldl (add_ct_weight ctab) 0.0;
ec53c138277a Frequency strategy. Revised indentation, etc.
paulson
parents: 19208
diff changeset
   128
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   129
(*Relevant constants are weighted according to frequency, 
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   130
  but irrelevant constants are simply counted. Otherwise, Skolem functions,
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   131
  which are rare, would harm a clause's chances of being picked.*)
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   132
fun clause_weight ctab gctyps consts_typs =
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   133
    let val rel = filter (uni_mem gctyps) consts_typs
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   134
        val rel_weight = consts_typs_weight ctab rel
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   135
    in
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   136
	rel_weight / (rel_weight + real (length consts_typs - length rel))
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   137
    end;
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   138
    
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   139
fun add_consts_with_typs (c,[]) cpairs = cpairs
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   140
  | add_consts_with_typs (c, ctyps_list) cpairs =
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   141
      foldl (fn (ctyps,cpairs) => (c,ctyps)::cpairs) cpairs ctyps_list;
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   142
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   143
fun consts_typs_of_term thy t = 
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   144
  let val tab = add_term_consts_typs_rm thy (t, null_const_tab)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   145
  in  Symtab.fold add_consts_with_typs tab []  end;
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   146
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   147
fun pair_consts_typs_axiom thy (thm,name) =
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   148
    ((thm,name), (consts_typs_of_term thy (prop_of thm)));
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   149
19321
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   150
exception ConstFree;
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   151
fun dest_ConstFree (Const aT) = aT
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   152
  | dest_ConstFree (Free aT) = aT
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   153
  | dest_ConstFree _ = raise ConstFree;
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   154
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   155
(*Look for definitions of the form f ?x1 ... ?xn = t, but not reversed.*)
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   156
fun defines thy (thm,(name,n)) gctypes =
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   157
    let val tm = prop_of thm
19448
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   158
	fun defs lhs rhs =
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   159
            let val (rator,args) = strip_comb lhs
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   160
		val ct = const_with_typ thy (dest_ConstFree rator)
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   161
            in  forall is_Var args andalso 
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   162
                term_varnames rhs subset term_varnames lhs andalso
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   163
                uni_mem gctypes ct 
19448
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   164
            end
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   165
	    handle ConstFree => false
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   166
    in    
19448
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   167
	case tm of Const ("Trueprop",_) $ (Const("op =",_) $ lhs $ rhs) => 
72dab71cb11e definition expansion checks for excess variables
paulson
parents: 19355
diff changeset
   168
		   defs lhs rhs andalso
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   169
		   (Output.debug ("Definition found: " ^ name ^ "_" ^ Int.toString n); true)
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   170
		 | _ => false
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   171
    end;
19321
30b5bb35dd33 detection of definitions of relevant constants
paulson
parents: 19315
diff changeset
   172
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   173
fun relevant_clauses thy ctab p rel_consts =
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   174
  let fun relevant (newrels,rejects) []  =
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   175
	    if null newrels then [] 
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   176
	    else 
20132
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   177
	      let val new_consts = List.concat (map #2 newrels)
de3c295000b2 Replaced a-lists by tables to improve efficiency
paulson
parents: 19448
diff changeset
   178
	          val rel_consts' = foldl add_const_typ_table rel_consts new_consts
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   179
                  val newp = p + (1.0-p) / !convergence
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   180
	      in Output.debug ("found relevant: " ^ Int.toString (length newrels));
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   181
                 newrels @ relevant_clauses thy ctab newp rel_consts' rejects
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   182
	      end
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   183
	| relevant (newrels,rejects) ((ax as (clsthm,consts_typs)) :: axs) =
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   184
	    let val weight = clause_weight ctab rel_consts consts_typs
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   185
	    in
19355
3140daf6863d filter now accepts axioms as thm, instead of term.
mengj
parents: 19337
diff changeset
   186
	      if p <= weight orelse (!follow_defs andalso defines thy clsthm rel_consts)
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   187
	      then relevant (ax::newrels, rejects) axs
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   188
	      else relevant (newrels, ax::rejects) axs
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   189
	    end
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   190
    in  Output.debug ("relevant_clauses: " ^ Real.toString p);
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   191
        relevant ([],[]) end;
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   192
	
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   193
     
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   194
fun relevance_filter_aux thy axioms goals = 
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   195
  let val const_tab = List.foldl (count_axiom_consts thy) Symtab.empty axioms
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   196
      val goals_consts_typs = get_goal_consts_typs thy goals
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   197
      val rels = relevant_clauses thy const_tab (!pass_mark) goals_consts_typs 
19334
96ca738055a6 Simplified version of Jia's filter. Now all constants are pooled, rather than
paulson
parents: 19321
diff changeset
   198
                   (map (pair_consts_typs_axiom thy) axioms)
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   199
  in
19334
96ca738055a6 Simplified version of Jia's filter. Now all constants are pooled, rather than
paulson
parents: 19321
diff changeset
   200
      Output.debug ("Total relevant: " ^ Int.toString (length rels));
96ca738055a6 Simplified version of Jia's filter. Now all constants are pooled, rather than
paulson
parents: 19321
diff changeset
   201
      rels
19231
c8879dd3a953 Frequency analysis of constants (with types).
paulson
parents: 19212
diff changeset
   202
  end;
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   203
19315
b218cc3d1bb4 Removal of obsolete strategies. Initial support for locales: Frees and Consts
paulson
parents: 19231
diff changeset
   204
fun relevance_filter thy axioms goals =
19337
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   205
  if !pass_mark < 0.1 then axioms
146b25b893bb pool of constants; definition expansion; current best settings
paulson
parents: 19335
diff changeset
   206
  else map #1 (relevance_filter_aux thy axioms goals);
19009
bb29bf9d3a72 Added another filter strategy.
mengj
parents: 18791
diff changeset
   207
    
18791
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
   208
9b4ae9fa67a4 Relevance filtering. Has replaced the previous version.
mengj
parents:
diff changeset
   209
end;