src/HOL/Tools/Nunchaku/nunchaku_collect.ML
changeset 71179 592e2afdd50c
parent 69992 bd3c10813cc4
child 71207 8af82f3e03c9
equal deleted inserted replaced
71178:c7d4f2ab40b9 71179:592e2afdd50c
   477 
   477 
   478     fun subst_of t0 =
   478     fun subst_of t0 =
   479       try (Sign.typ_match thy (fastype_of t0, T)) Vartab.empty;
   479       try (Sign.typ_match thy (fastype_of t0, T)) Vartab.empty;
   480 
   480 
   481     fun process_spec _ (res as SOME _) = res
   481     fun process_spec _ (res as SOME _) = res
   482       | process_spec (classif, (ts0, ths as _ :: _)) NONE =
   482       | process_spec {rough_classification = classif, terms = ts0, rules = ths as _ :: _, ...} NONE =
   483         (case get_first subst_of ts0 of
   483         (case get_first subst_of ts0 of
   484           SOME subst =>
   484           SOME subst =>
   485           (let
   485           (let
   486              val ts = map (Envir.subst_term_types subst) ts0;
   486              val ts = map (Envir.subst_term_types subst) ts0;
   487              val poly_props = map Thm.prop_of ths;
   487              val poly_props = map Thm.prop_of ths;
   494         | NONE => NONE)
   494         | NONE => NONE)
   495       | process_spec _ NONE = NONE;
   495       | process_spec _ NONE = NONE;
   496 
   496 
   497     fun spec_rules () =
   497     fun spec_rules () =
   498       Spec_Rules.retrieve ctxt (Const x)
   498       Spec_Rules.retrieve ctxt (Const x)
   499       |> sort (Spec_Rules.rough_classification_ord o apply2 fst);
   499       |> sort (Spec_Rules.rough_classification_ord o apply2 #rough_classification);
   500 
   500 
   501     val specs =
   501     val specs =
   502       if s = \<^const_name>\<open>The\<close> then
   502       if s = \<^const_name>\<open>The\<close> then
   503         [(Spec_Rules.Unknown, ([Logic.varify_global \<^term>\<open>The\<close>], [@{thm theI_unique}]))]
   503         [{name = "", rough_classification = Spec_Rules.Unknown,
       
   504           terms = [Logic.varify_global \<^term>\<open>The\<close>],
       
   505           rules = [@{thm theI_unique}]}]
   504       else if s = \<^const_name>\<open>finite\<close> then
   506       else if s = \<^const_name>\<open>finite\<close> then
   505         let val card = card_of_type ctxt T in
   507         let val card = card_of_type ctxt T in
   506           if card = Inf orelse card = Fin_or_Inf then
   508           if card = Inf orelse card = Fin_or_Inf then
   507             spec_rules ()
   509             spec_rules ()
   508           else
   510           else
   509             [(Spec_Rules.equational, ([Logic.varify_global \<^term>\<open>finite\<close>],
   511             [{name = "", rough_classification = Spec_Rules.equational,
   510                [Skip_Proof.make_thm thy (Logic.varify_global \<^prop>\<open>finite A = True\<close>)]))]
   512               terms = [Logic.varify_global \<^term>\<open>finite\<close>],
       
   513               rules = [Skip_Proof.make_thm thy (Logic.varify_global \<^prop>\<open>finite A = True\<close>)]}]
   511         end
   514         end
   512       else
   515       else
   513         spec_rules ();
   516         spec_rules ();
   514   in
   517   in
   515     fold process_spec specs NONE
   518     fold process_spec specs NONE
   535 fun is_builtin_theory thy_id =
   538 fun is_builtin_theory thy_id =
   536   Context.subthy_id (thy_id, Context.theory_id \<^theory>\<open>Hilbert_Choice\<close>);
   539   Context.subthy_id (thy_id, Context.theory_id \<^theory>\<open>Hilbert_Choice\<close>);
   537 
   540 
   538 val orphan_axioms_of =
   541 val orphan_axioms_of =
   539   Spec_Rules.get
   542   Spec_Rules.get
   540   #> filter (Spec_Rules.is_unknown o fst)
   543   #> filter (Spec_Rules.is_unknown o #rough_classification)
   541   #> map snd
   544   #> filter (null o #terms)
   542   #> filter (null o fst)
   545   #> maps #rules
   543   #> maps snd
       
   544   #> filter_out (is_builtin_theory o Thm.theory_id)
   546   #> filter_out (is_builtin_theory o Thm.theory_id)
   545   #> map Thm.prop_of;
   547   #> map Thm.prop_of;
   546 
   548 
   547 fun keys_of _ (ITVal (T, _)) = [key_of_typ T]
   549 fun keys_of _ (ITVal (T, _)) = [key_of_typ T]
   548   | keys_of _ (ITypedef {abs_typ, ...}) = [key_of_typ abs_typ]
   550   | keys_of _ (ITypedef {abs_typ, ...}) = [key_of_typ abs_typ]
   959                               [IRec (map2 (fn const => fn props =>
   961                               [IRec (map2 (fn const => fn props =>
   960                                    {const = const, props = props,
   962                                    {const = const, props = props,
   961                                     pat_complete = is_apparently_pat_complete ctxt props})
   963                                     pat_complete = is_apparently_pat_complete ctxt props})
   962                                  consts propss)])
   964                                  consts propss)])
   963                            | NONE => def_or_spec ())
   965                            | NONE => def_or_spec ())
   964                          else if (Spec_Rules.is_inductive orf Spec_Rules.is_co_inductive) classif
   966                          else if Spec_Rules.is_relational classif
   965                          then
   967                          then
   966                            if is_inductive_set_intro (hd props) then
   968                            if is_inductive_set_intro (hd props) then
   967                              def_or_spec ()
   969                              def_or_spec ()
   968                            else
   970                            else
   969                              (case partition_props consts props of
   971                              (case partition_props consts props of