src/HOL/Tools/Sledgehammer/sledgehammer_fact.ML
changeset 69597 ff784d5a5bfb
parent 69593 3dda49e08b9d
child 69991 6b097aeb3650
equal deleted inserted replaced
69596:c8a2755bf220 69597:ff784d5a5bfb
    81   | explode_interval max (Facts.From i) = i upto i + max - 1
    81   | explode_interval max (Facts.From i) = i upto i + max - 1
    82   | explode_interval _ (Facts.Single i) = [i]
    82   | explode_interval _ (Facts.Single i) = [i]
    83 
    83 
    84 fun is_rec_eq lhs = Term.exists_subterm (curry (op =) (head_of lhs))
    84 fun is_rec_eq lhs = Term.exists_subterm (curry (op =) (head_of lhs))
    85 
    85 
    86 fun is_rec_def (@{const Trueprop} $ t) = is_rec_def t
    86 fun is_rec_def (\<^const>\<open>Trueprop\<close> $ t) = is_rec_def t
    87   | is_rec_def (@{const Pure.imp} $ _ $ t2) = is_rec_def t2
    87   | is_rec_def (\<^const>\<open>Pure.imp\<close> $ _ $ t2) = is_rec_def t2
    88   | is_rec_def (Const (\<^const_name>\<open>Pure.eq\<close>, _) $ t1 $ t2) = is_rec_eq t1 t2
    88   | is_rec_def (Const (\<^const_name>\<open>Pure.eq\<close>, _) $ t1 $ t2) = is_rec_eq t1 t2
    89   | is_rec_def (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t1 $ t2) = is_rec_eq t1 t2
    89   | is_rec_def (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ t1 $ t2) = is_rec_eq t1 t2
    90   | is_rec_def _ = false
    90   | is_rec_def _ = false
    91 
    91 
    92 fun is_assum assms th = exists (fn ct => Thm.prop_of th aconv Thm.term_of ct) assms
    92 fun is_assum assms th = exists (fn ct => Thm.prop_of th aconv Thm.term_of ct) assms
   252           not (exists_subterm is_interesting_subterm t) then
   252           not (exists_subterm is_interesting_subterm t) then
   253         Boring
   253         Boring
   254       else
   254       else
   255         Interesting
   255         Interesting
   256 
   256 
   257     fun interest_of_prop _ (@{const Trueprop} $ t) = interest_of_bool t
   257     fun interest_of_prop _ (\<^const>\<open>Trueprop\<close> $ t) = interest_of_bool t
   258       | interest_of_prop Ts (@{const Pure.imp} $ t $ u) =
   258       | interest_of_prop Ts (\<^const>\<open>Pure.imp\<close> $ t $ u) =
   259         combine_interests (interest_of_prop Ts t) (interest_of_prop Ts u)
   259         combine_interests (interest_of_prop Ts t) (interest_of_prop Ts u)
   260       | interest_of_prop Ts (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, T, t)) =
   260       | interest_of_prop Ts (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, T, t)) =
   261         if type_has_top_sort T then Deal_Breaker else interest_of_prop (T :: Ts) t
   261         if type_has_top_sort T then Deal_Breaker else interest_of_prop (T :: Ts) t
   262       | interest_of_prop Ts ((t as Const (\<^const_name>\<open>Pure.all\<close>, _)) $ u) =
   262       | interest_of_prop Ts ((t as Const (\<^const_name>\<open>Pure.all\<close>, _)) $ u) =
   263         interest_of_prop Ts (t $ eta_expand Ts u 1)
   263         interest_of_prop Ts (t $ eta_expand Ts u 1)
   334         |> fold (add Intro) intros
   334         |> fold (add Intro) intros
   335         |> fold (add Inductive) spec_intros
   335         |> fold (add Inductive) spec_intros
   336       end
   336       end
   337   end
   337   end
   338 
   338 
   339 fun normalize_eq (@{const Trueprop} $ (t as (t0 as Const (\<^const_name>\<open>HOL.eq\<close>, _)) $ t1 $ t2)) =
   339 fun normalize_eq (\<^const>\<open>Trueprop\<close> $ (t as (t0 as Const (\<^const_name>\<open>HOL.eq\<close>, _)) $ t1 $ t2)) =
   340     if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then t else t0 $ t2 $ t1
   340     if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then t else t0 $ t2 $ t1
   341   | normalize_eq (@{const Trueprop} $ (t as @{const Not}
   341   | normalize_eq (\<^const>\<open>Trueprop\<close> $ (t as \<^const>\<open>Not\<close>
   342       $ ((t0 as Const (\<^const_name>\<open>HOL.eq\<close>, _)) $ t1 $ t2))) =
   342       $ ((t0 as Const (\<^const_name>\<open>HOL.eq\<close>, _)) $ t1 $ t2))) =
   343     if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then t else HOLogic.mk_not (t0 $ t2 $ t1)
   343     if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then t else HOLogic.mk_not (t0 $ t2 $ t1)
   344   | normalize_eq (Const (\<^const_name>\<open>Pure.eq\<close>, Type (_, [T, _])) $ t1 $ t2) =
   344   | normalize_eq (Const (\<^const_name>\<open>Pure.eq\<close>, Type (_, [T, _])) $ t1 $ t2) =
   345     (if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then (t1, t2) else (t2, t1))
   345     (if is_less_equal (Term_Ord.fast_term_ord (t1, t2)) then (t1, t2) else (t2, t1))
   346     |> (fn (t1, t2) => HOLogic.eq_const T $ t1 $ t2)
   346     |> (fn (t1, t2) => HOLogic.eq_const T $ t1 $ t2)
   379   |> sort (int_ord o apply2 fst)
   379   |> sort (int_ord o apply2 fst)
   380   |> map snd
   380   |> map snd
   381 
   381 
   382 fun struct_induct_rule_on th =
   382 fun struct_induct_rule_on th =
   383   (case Logic.strip_horn (Thm.prop_of th) of
   383   (case Logic.strip_horn (Thm.prop_of th) of
   384     (prems, @{const Trueprop} $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) =>
   384     (prems, \<^const>\<open>Trueprop\<close> $ ((p as Var ((p_name, 0), _)) $ (a as Var (_, ind_T)))) =>
   385     if not (is_TVar ind_T) andalso length prems > 1 andalso
   385     if not (is_TVar ind_T) andalso length prems > 1 andalso
   386        exists (exists_subterm (curry (op aconv) p)) prems andalso
   386        exists (exists_subterm (curry (op aconv) p)) prems andalso
   387        not (exists (exists_subterm (curry (op aconv) a)) prems) then
   387        not (exists (exists_subterm (curry (op aconv) a)) prems) then
   388       SOME (p_name, ind_T)
   388       SOME (p_name, ind_T)
   389     else
   389     else