src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
changeset 54076 5337fd7d53c9
parent 54040 04715fecbda6
child 54077 af65902b6e30
     1.1 --- a/src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML	Mon Oct 07 23:44:53 2013 +0200
     1.2 +++ b/src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML	Tue Oct 08 14:41:25 2013 +0200
     1.3 @@ -126,23 +126,28 @@
     1.4    in fst (norm t (([], 0), ([], 0))) end
     1.5  
     1.6  fun status_of_thm css name th =
     1.7 -  let val t = normalize_vars (prop_of th) in
     1.8 +  let val t = prop_of th in
     1.9      (* FIXME: use structured name *)
    1.10      if String.isSubstring ".induct" name andalso may_be_induction t then
    1.11        Induction
    1.12 -    else case Termtab.lookup css t of
    1.13 -      SOME status => status
    1.14 -    | NONE =>
    1.15 -      let val concl = Logic.strip_imp_concl t in
    1.16 -        case try (HOLogic.dest_eq o HOLogic.dest_Trueprop) concl of
    1.17 -          SOME lrhss =>
    1.18 -          let
    1.19 -            val prems = Logic.strip_imp_prems t
    1.20 -            val t' = Logic.list_implies (prems, Logic.mk_equals lrhss)
    1.21 -          in
    1.22 -            Termtab.lookup css t' |> the_default General
    1.23 +    else if Termtab.is_empty css then
    1.24 +      General
    1.25 +    else
    1.26 +      let val t = normalize_vars t in
    1.27 +        case Termtab.lookup css t of
    1.28 +          SOME status => status
    1.29 +        | NONE =>
    1.30 +          let val concl = Logic.strip_imp_concl t in
    1.31 +            case try (HOLogic.dest_eq o HOLogic.dest_Trueprop) concl of
    1.32 +              SOME lrhss =>
    1.33 +              let
    1.34 +                val prems = Logic.strip_imp_prems t
    1.35 +                val t' = Logic.list_implies (prems, Logic.mk_equals lrhss)
    1.36 +              in
    1.37 +                Termtab.lookup css t' |> the_default General
    1.38 +              end
    1.39 +            | NONE => General
    1.40            end
    1.41 -        | NONE => General
    1.42        end
    1.43    end
    1.44  
    1.45 @@ -346,8 +351,6 @@
    1.46      else HOLogic.mk_Trueprop (HOLogic.mk_not (t0 $ t2 $ t1))
    1.47    | normalize_eq t = t
    1.48  
    1.49 -val normalize_eq_vars = normalize_eq #> normalize_vars
    1.50 -
    1.51  fun if_thm_before th th' =
    1.52    if Theory.subthy (pairself Thm.theory_of_thm (th, th')) then th else th'
    1.53  
    1.54 @@ -362,7 +365,7 @@
    1.55  fun build_name_tables name_of facts =
    1.56    let
    1.57      fun cons_thm (_, th) =
    1.58 -      Termtab.cons_list (normalize_eq_vars (prop_of th), th)
    1.59 +      Termtab.cons_list (normalize_vars (normalize_eq (prop_of th)), th)
    1.60      fun add_plain canon alias =
    1.61        Symtab.update (Thm.get_name_hint alias,
    1.62                       name_of (if_thm_before canon alias))
    1.63 @@ -374,17 +377,18 @@
    1.64      val inclass_name_tab = Symtab.fold add_inclass plain_name_tab Symtab.empty
    1.65    in (plain_name_tab, inclass_name_tab) end
    1.66  
    1.67 -fun keyed_distinct key_of xs =
    1.68 -  let val tab = fold (Termtab.default o `key_of) xs Termtab.empty in
    1.69 -    Termtab.fold (cons o snd) tab []
    1.70 -  end
    1.71 +fun keyed_distinct key1_of key2_of ths =
    1.72 +  fold (fn fact as (_, th) =>
    1.73 +      Net.insert_term_safe (op aconv o pairself (key2_of o key1_of o prop_of o snd)) (key1_of (prop_of th), fact))
    1.74 +    ths Net.empty
    1.75 +  |> Net.entries
    1.76  
    1.77 -fun hashed_keyed_distinct hash_of key_of xs =
    1.78 +fun hashed_keyed_distinct hash_of key1_of key2_of facts =
    1.79    let
    1.80 -    val ys = map (`hash_of) xs
    1.81 +    val ys = map (`(hash_of o prop_of o snd)) facts
    1.82      val sorted_ys = sort (int_ord o pairself fst) ys
    1.83      val grouped_ys = AList.coalesce (op =) sorted_ys
    1.84 -  in maps (keyed_distinct key_of o snd) grouped_ys end
    1.85 +  in maps (keyed_distinct key1_of key2_of o snd) grouped_ys end
    1.86  
    1.87  fun struct_induct_rule_on th =
    1.88    case Logic.strip_horn (prop_of th) of
    1.89 @@ -540,10 +544,8 @@
    1.90         else
    1.91           let val (add, del) = pairself (Attrib.eval_thms ctxt) (add, del) in
    1.92             all_facts ctxt false ho_atp reserved add chained css
    1.93 -           |> filter_out
    1.94 -                  ((member Thm.eq_thm_prop del orf No_ATPs.member ctxt) o snd)
    1.95 -           |> hashed_keyed_distinct (size_of_term o prop_of o snd)
    1.96 -                  (normalize_eq_vars o prop_of o snd)
    1.97 +           |> filter_out ((member Thm.eq_thm_prop del orf No_ATPs.member ctxt) o snd)
    1.98 +           |> hashed_keyed_distinct size_of_term normalize_eq normalize_vars
    1.99           end)
   1.100        |> maybe_instantiate_inducts ctxt hyp_ts concl_t
   1.101      end