src/HOL/Tools/Old_Datatype/old_datatype.ML
changeset 60752 b48830b670a1
parent 60328 9c94e6a30d29
child 60774 6c28d8ed2488
equal deleted inserted replaced
60751:83f04804696c 60752:b48830b670a1
   186       |> Sign.parent_path
   186       |> Sign.parent_path
   187       |> fold_map
   187       |> fold_map
   188         (fn (((name, mx), tvs), c) =>
   188         (fn (((name, mx), tvs), c) =>
   189           Typedef.add_typedef_global false (name, tvs, mx)
   189           Typedef.add_typedef_global false (name, tvs, mx)
   190             (Collect $ Const (c, UnivT')) NONE
   190             (Collect $ Const (c, UnivT')) NONE
   191             (fn ctxt => rtac exI 1 THEN rtac CollectI 1 THEN
   191             (fn ctxt =>
       
   192               resolve_tac ctxt [exI] 1 THEN
       
   193               resolve_tac ctxt [CollectI] 1 THEN
   192               QUIET_BREADTH_FIRST (has_fewer_prems 1)
   194               QUIET_BREADTH_FIRST (has_fewer_prems 1)
   193               (resolve_tac ctxt rep_intrs 1)))
   195               (resolve_tac ctxt rep_intrs 1)))
   194         (types_syntax ~~ tyvars ~~ take (length newTs) rep_set_names)
   196         (types_syntax ~~ tyvars ~~ take (length newTs) rep_set_names)
   195       ||> Sign.add_path big_name;
   197       ||> Sign.add_path big_name;
   196 
   198 
   353         (* prove characteristic equations *)
   355         (* prove characteristic equations *)
   354 
   356 
   355         val rewrites = def_thms @ map mk_meta_eq rec_rewrites;
   357         val rewrites = def_thms @ map mk_meta_eq rec_rewrites;
   356         val char_thms' =
   358         val char_thms' =
   357           map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn
   359           map (fn eqn => Goal.prove_sorry_global thy' [] [] eqn
   358             (fn {context = ctxt, ...} => EVERY [rewrite_goals_tac ctxt rewrites, rtac refl 1])) eqns;
   360             (fn {context = ctxt, ...} =>
       
   361               EVERY [rewrite_goals_tac ctxt rewrites, resolve_tac ctxt [refl] 1])) eqns;
   359 
   362 
   360       in (thy', char_thms' @ char_thms) end;
   363       in (thy', char_thms' @ char_thms) end;
   361 
   364 
   362     val (thy5, iso_char_thms) =
   365     val (thy5, iso_char_thms) =
   363       fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []);
   366       fold_rev make_iso_defs (tl descr) (Sign.add_path big_name thy4, []);
   380               (Logic.mk_implies
   383               (Logic.mk_implies
   381                 (HOLogic.mk_Trueprop (HOLogic.list_all
   384                 (HOLogic.mk_Trueprop (HOLogic.list_all
   382                    (map (pair "x") Ts, S $ Old_Datatype_Aux.app_bnds f i)),
   385                    (map (pair "x") Ts, S $ Old_Datatype_Aux.app_bnds f i)),
   383                  HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts
   386                  HOLogic.mk_Trueprop (HOLogic.mk_eq (fold_rev (Term.abs o pair "x") Ts
   384                    (r $ (a $ Old_Datatype_Aux.app_bnds f i)), f))))
   387                    (r $ (a $ Old_Datatype_Aux.app_bnds f i)), f))))
   385               (fn {context = ctxt, ...} => EVERY [REPEAT_DETERM_N i (rtac @{thm ext} 1),
   388               (fn {context = ctxt, ...} =>
   386                  REPEAT (etac allE 1), rtac thm 1, assume_tac ctxt 1])
   389                 EVERY [REPEAT_DETERM_N i (resolve_tac ctxt @{thms ext} 1),
       
   390                  REPEAT (eresolve_tac ctxt [allE] 1),
       
   391                  resolve_tac ctxt [thm] 1,
       
   392                  assume_tac ctxt 1])
   387           end
   393           end
   388       in map (fn r => r RS subst) (thm :: map mk_thm arities) end;
   394       in map (fn r => r RS subst) (thm :: map mk_thm arities) end;
   389 
   395 
   390     (* prove  inj Rep_dt_i  and  Rep_dt_i x : rep_set_dt_i *)
   396     (* prove  inj Rep_dt_i  and  Rep_dt_i x : rep_set_dt_i *)
   391 
   397 
   419             (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl1))
   425             (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj ind_concl1))
   420             (fn {context = ctxt, ...} => EVERY
   426             (fn {context = ctxt, ...} => EVERY
   421               [(Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   427               [(Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   422                   Object_Logic.atomize_prems_tac ctxt) 1,
   428                   Object_Logic.atomize_prems_tac ctxt) 1,
   423                REPEAT (EVERY
   429                REPEAT (EVERY
   424                  [rtac allI 1, rtac impI 1,
   430                  [resolve_tac ctxt [allI] 1, resolve_tac ctxt [impI] 1,
   425                   Old_Datatype_Aux.exh_tac ctxt (exh_thm_of dt_info) 1,
   431                   Old_Datatype_Aux.exh_tac ctxt (exh_thm_of dt_info) 1,
   426                   REPEAT (EVERY
   432                   REPEAT (EVERY
   427                     [hyp_subst_tac ctxt 1,
   433                     [hyp_subst_tac ctxt 1,
   428                      rewrite_goals_tac ctxt rewrites,
   434                      rewrite_goals_tac ctxt rewrites,
   429                      REPEAT (dresolve_tac ctxt [In0_inject, In1_inject] 1),
   435                      REPEAT (dresolve_tac ctxt [In0_inject, In1_inject] 1),
   430                      (eresolve_tac ctxt [In0_not_In1 RS notE, In1_not_In0 RS notE] 1)
   436                      (eresolve_tac ctxt [In0_not_In1 RS notE, In1_not_In0 RS notE] 1)
   431                      ORELSE (EVERY
   437                      ORELSE (EVERY
   432                        [REPEAT (eresolve_tac ctxt (Scons_inject ::
   438                        [REPEAT (eresolve_tac ctxt (Scons_inject ::
   433                           map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1),
   439                           map make_elim [Leaf_inject, Inl_inject, Inr_inject]) 1),
   434                         REPEAT (cong_tac ctxt 1), rtac refl 1,
   440                         REPEAT (cong_tac ctxt 1), resolve_tac ctxt [refl] 1,
   435                         REPEAT (assume_tac ctxt 1 ORELSE (EVERY
   441                         REPEAT (assume_tac ctxt 1 ORELSE (EVERY
   436                           [REPEAT (rtac @{thm ext} 1),
   442                           [REPEAT (resolve_tac ctxt @{thms ext} 1),
   437                            REPEAT (eresolve_tac ctxt (mp :: allE ::
   443                            REPEAT (eresolve_tac ctxt (mp :: allE ::
   438                              map make_elim (Suml_inject :: Sumr_inject ::
   444                              map make_elim (Suml_inject :: Sumr_inject ::
   439                                Lim_inject :: inj_thms') @ fun_congs) 1),
   445                                Lim_inject :: inj_thms') @ fun_congs) 1),
   440                            assume_tac ctxt 1]))])])])]);
   446                            assume_tac ctxt 1]))])])])]);
   441 
   447 
   448               EVERY [
   454               EVERY [
   449                 (Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   455                 (Old_Datatype_Aux.ind_tac ctxt induct [] THEN_ALL_NEW
   450                   Object_Logic.atomize_prems_tac ctxt) 1,
   456                   Object_Logic.atomize_prems_tac ctxt) 1,
   451                 rewrite_goals_tac ctxt rewrites,
   457                 rewrite_goals_tac ctxt rewrites,
   452                 REPEAT ((resolve_tac ctxt rep_intrs THEN_ALL_NEW
   458                 REPEAT ((resolve_tac ctxt rep_intrs THEN_ALL_NEW
   453                   ((REPEAT o etac allE) THEN' ares_tac elem_thms)) 1)]);
   459                   ((REPEAT o eresolve_tac ctxt [allE]) THEN' ares_tac elem_thms)) 1)]);
   454 
   460 
   455       in (inj_thms'' @ inj_thms, elem_thms @ Old_Datatype_Aux.split_conj_thm elem_thm) end;
   461       in (inj_thms'' @ inj_thms, elem_thms @ Old_Datatype_Aux.split_conj_thm elem_thm) end;
   456 
   462 
   457     val (iso_inj_thms_unfolded, iso_elem_thms) =
   463     val (iso_inj_thms_unfolded, iso_elem_thms) =
   458       fold_rev prove_iso_thms (tl descr) ([], map #3 newT_iso_axms);
   464       fold_rev prove_iso_thms (tl descr) ([], map #3 newT_iso_axms);
   483       else
   489       else
   484         drop (length newTs) (Old_Datatype_Aux.split_conj_thm
   490         drop (length newTs) (Old_Datatype_Aux.split_conj_thm
   485           (Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY
   491           (Goal.prove_sorry_global thy5 [] [] iso_t (fn {context = ctxt, ...} => EVERY
   486              [(Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   492              [(Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   487                  Object_Logic.atomize_prems_tac ctxt) 1,
   493                  Object_Logic.atomize_prems_tac ctxt) 1,
   488               REPEAT (rtac TrueI 1),
   494               REPEAT (resolve_tac ctxt [TrueI] 1),
   489               rewrite_goals_tac ctxt (mk_meta_eq @{thm choice_eq} ::
   495               rewrite_goals_tac ctxt (mk_meta_eq @{thm choice_eq} ::
   490                 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs),
   496                 Thm.symmetric (mk_meta_eq @{thm fun_eq_iff}) :: range_eqs),
   491               rewrite_goals_tac ctxt (map Thm.symmetric range_eqs),
   497               rewrite_goals_tac ctxt (map Thm.symmetric range_eqs),
   492               REPEAT (EVERY
   498               REPEAT (EVERY
   493                 [REPEAT (eresolve_tac ctxt ([rangeE, @{thm ex1_implies_ex} RS exE] @
   499                 [REPEAT (eresolve_tac ctxt ([rangeE, @{thm ex1_implies_ex} RS exE] @
   494                    maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1),
   500                    maps (mk_funs_inv thy5 o #1) newT_iso_axms) 1),
   495                  TRY (hyp_subst_tac ctxt 1),
   501                  TRY (hyp_subst_tac ctxt 1),
   496                  rtac (sym RS range_eqI) 1,
   502                  resolve_tac ctxt [sym RS range_eqI] 1,
   497                  resolve_tac ctxt iso_char_thms 1])])));
   503                  resolve_tac ctxt iso_char_thms 1])])));
   498 
   504 
   499     val Abs_inverse_thms' =
   505     val Abs_inverse_thms' =
   500       map #1 newT_iso_axms @
   506       map #1 newT_iso_axms @
   501       map2 (fn r_inj => fn r => @{thm f_the_inv_into_f} OF [r_inj, r RS mp])
   507       map2 (fn r_inj => fn r => @{thm f_the_inv_into_f} OF [r_inj, r RS mp])
   516       in
   522       in
   517         Goal.prove_sorry_global thy5 [] [] eqn
   523         Goal.prove_sorry_global thy5 [] [] eqn
   518         (fn {context = ctxt, ...} => EVERY
   524         (fn {context = ctxt, ...} => EVERY
   519           [resolve_tac ctxt inj_thms 1,
   525           [resolve_tac ctxt inj_thms 1,
   520            rewrite_goals_tac ctxt rewrites,
   526            rewrite_goals_tac ctxt rewrites,
   521            rtac refl 3,
   527            resolve_tac ctxt [refl] 3,
   522            resolve_tac ctxt rep_intrs 2,
   528            resolve_tac ctxt rep_intrs 2,
   523            REPEAT (resolve_tac ctxt iso_elem_thms 1)])
   529            REPEAT (resolve_tac ctxt iso_elem_thms 1)])
   524       end;
   530       end;
   525 
   531 
   526     (*--------------------------------------------------------------*)
   532     (*--------------------------------------------------------------*)
   558               [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject,
   564               [In0_inject, In1_inject, Leaf_inject, Inl_inject, Inr_inject,
   559                Lim_inject, Suml_inject, Sumr_inject])
   565                Lim_inject, Suml_inject, Sumr_inject])
   560       in
   566       in
   561         Goal.prove_sorry_global thy5 [] [] t
   567         Goal.prove_sorry_global thy5 [] [] t
   562           (fn {context = ctxt, ...} => EVERY
   568           (fn {context = ctxt, ...} => EVERY
   563             [rtac iffI 1,
   569             [resolve_tac ctxt [iffI] 1,
   564              REPEAT (etac conjE 2), hyp_subst_tac ctxt 2, rtac refl 2,
   570              REPEAT (eresolve_tac ctxt [conjE] 2), hyp_subst_tac ctxt 2,
   565              dresolve_tac ctxt rep_congs 1, dtac @{thm box_equals} 1,
   571              resolve_tac ctxt [refl] 2,
       
   572              dresolve_tac ctxt rep_congs 1,
       
   573              dresolve_tac ctxt @{thms box_equals} 1,
   566              REPEAT (resolve_tac ctxt rep_thms 1),
   574              REPEAT (resolve_tac ctxt rep_thms 1),
   567              REPEAT (eresolve_tac ctxt inj_thms 1),
   575              REPEAT (eresolve_tac ctxt inj_thms 1),
   568              REPEAT (ares_tac [conjI] 1 ORELSE (EVERY [REPEAT (rtac @{thm ext} 1),
   576              REPEAT (ares_tac [conjI] 1 ORELSE (EVERY [REPEAT (resolve_tac ctxt @{thms ext} 1),
   569                REPEAT (eresolve_tac ctxt (make_elim fun_cong :: inj_thms) 1),
   577                REPEAT (eresolve_tac ctxt (make_elim fun_cong :: inj_thms) 1),
   570                assume_tac ctxt 1]))])
   578                assume_tac ctxt 1]))])
   571       end;
   579       end;
   572 
   580 
   573     val constr_inject =
   581     val constr_inject =
   616         (Logic.mk_implies
   624         (Logic.mk_implies
   617           (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_prems),
   625           (HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_prems),
   618            HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_concls)))
   626            HOLogic.mk_Trueprop (Old_Datatype_Aux.mk_conj indrule_lemma_concls)))
   619         (fn {context = ctxt, ...} =>
   627         (fn {context = ctxt, ...} =>
   620           EVERY
   628           EVERY
   621            [REPEAT (etac conjE 1),
   629            [REPEAT (eresolve_tac ctxt [conjE] 1),
   622             REPEAT (EVERY
   630             REPEAT (EVERY
   623               [TRY (rtac conjI 1), resolve_tac ctxt Rep_inverse_thms 1,
   631               [TRY (resolve_tac ctxt [conjI] 1), resolve_tac ctxt Rep_inverse_thms 1,
   624                etac mp 1, resolve_tac ctxt iso_elem_thms 1])]);
   632                eresolve_tac ctxt [mp] 1, resolve_tac ctxt iso_elem_thms 1])]);
   625 
   633 
   626     val Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (Thm.concl_of indrule_lemma)));
   634     val Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (Thm.concl_of indrule_lemma)));
   627     val frees =
   635     val frees =
   628       if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))]
   636       if length Ps = 1 then [Free ("P", snd (dest_Var (hd Ps)))]
   629       else map (Free o apfst fst o dest_Var) Ps;
   637       else map (Free o apfst fst o dest_Var) Ps;
   635       Goal.prove_sorry_global thy6 []
   643       Goal.prove_sorry_global thy6 []
   636       (Logic.strip_imp_prems dt_induct_prop)
   644       (Logic.strip_imp_prems dt_induct_prop)
   637       (Logic.strip_imp_concl dt_induct_prop)
   645       (Logic.strip_imp_concl dt_induct_prop)
   638       (fn {context = ctxt, prems, ...} =>
   646       (fn {context = ctxt, prems, ...} =>
   639         EVERY
   647         EVERY
   640           [rtac indrule_lemma' 1,
   648           [resolve_tac ctxt [indrule_lemma'] 1,
   641            (Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   649            (Old_Datatype_Aux.ind_tac ctxt rep_induct [] THEN_ALL_NEW
   642               Object_Logic.atomize_prems_tac ctxt) 1,
   650               Object_Logic.atomize_prems_tac ctxt) 1,
   643            EVERY (map (fn (prem, r) => (EVERY
   651            EVERY (map (fn (prem, r) => (EVERY
   644              [REPEAT (eresolve_tac ctxt Abs_inverse_thms 1),
   652              [REPEAT (eresolve_tac ctxt Abs_inverse_thms 1),
   645               simp_tac (put_simpset HOL_basic_ss ctxt
   653               simp_tac (put_simpset HOL_basic_ss ctxt
   646                 addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1,
   654                 addsimps (Thm.symmetric r :: Rep_inverse_thms')) 1,
   647               DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE etac allE 1)]))
   655               DEPTH_SOLVE_1 (ares_tac [prem] 1 ORELSE eresolve_tac ctxt [allE] 1)]))
   648                   (prems ~~ (constr_defs @ map mk_meta_eq iso_char_thms)))]);
   656                   (prems ~~ (constr_defs @ map mk_meta_eq iso_char_thms)))]);
   649 
   657 
   650     val ([(_, [dt_induct'])], thy7) =
   658     val ([(_, [dt_induct'])], thy7) =
   651       thy6
   659       thy6
   652       |> Global_Theory.note_thmss ""
   660       |> Global_Theory.note_thmss ""