61 (* kinds; the user specifies a list of atom-kind names *) |
61 (* kinds; the user specifies a list of atom-kind names *) |
62 (* atom_decl <ak1> ... <akn> *) |
62 (* atom_decl <ak1> ... <akn> *) |
63 fun create_nom_typedecls ak_names thy = |
63 fun create_nom_typedecls ak_names thy = |
64 let |
64 let |
65 |
65 |
66 (* declares a type-decl for every atom-kind: *) |
66 val (_,thy1) = |
67 (* that is typedecl <ak> *) |
67 fold_map (fn ak => fn thy => |
68 val thy1 = TypedefPackage.add_typedecls (map (fn x => (x,[],NoSyn)) ak_names) thy; |
68 let val dt = ([],ak,NoSyn,[(ak,[@{typ nat}],NoSyn)]) |
69 |
69 val ({inject,case_thms,...},thy1) = DatatypePackage.add_datatype_i true false [ak] [dt] thy |
|
70 val inject_flat = Library.flat inject |
|
71 val ak_type = Type (Sign.intern_type thy1 ak,[]) |
|
72 val ak_sign = Sign.intern_const thy1 ak |
|
73 |
|
74 val inj_type = @{typ nat}-->ak_type |
|
75 val inj_on_type = inj_type-->(@{typ "nat set"})-->@{typ bool} |
|
76 |
|
77 (* first statement *) |
|
78 val stmnt1 = HOLogic.mk_Trueprop |
|
79 (Const (@{const_name "inj_on"},inj_on_type) $ |
|
80 Const (ak_sign,inj_type) $ HOLogic.mk_UNIV @{typ nat}) |
|
81 |
|
82 val simp1 = @{thm inj_on_def}::inject_flat |
|
83 |
|
84 val proof1 = fn _ => EVERY [simp_tac (HOL_basic_ss addsimps simp1) 1, |
|
85 rtac @{thm ballI} 1, |
|
86 rtac @{thm ballI} 1, |
|
87 rtac @{thm impI} 1, |
|
88 atac 1] |
|
89 |
|
90 val (inj_thm,thy2) = |
|
91 PureThy.add_thms [((ak^"_inj",Goal.prove_global thy1 [] [] stmnt1 proof1), [])] thy1 |
|
92 |
|
93 (* second statement *) |
|
94 val y = Free ("y",ak_type) |
|
95 val stmnt2 = HOLogic.mk_Trueprop |
|
96 (HOLogic.mk_exists ("x",@{typ nat},HOLogic.mk_eq (y,Const (ak_sign,inj_type) $ Bound 0))) |
|
97 |
|
98 val proof2 = fn _ => EVERY [case_tac "y" 1, |
|
99 asm_simp_tac (HOL_basic_ss addsimps simp1) 1, |
|
100 rtac @{thm exI} 1, |
|
101 rtac @{thm refl} 1] |
|
102 |
|
103 (* third statement *) |
|
104 val (inject_thm,thy3) = |
|
105 PureThy.add_thms [((ak^"_injection",Goal.prove_global thy2 [] [] stmnt2 proof2), [])] thy2 |
|
106 |
|
107 val stmnt3 = HOLogic.mk_Trueprop |
|
108 (HOLogic.mk_not |
|
109 (Const ("Finite_Set.finite", HOLogic.mk_setT ak_type --> HOLogic.boolT) $ |
|
110 HOLogic.mk_UNIV ak_type)) |
|
111 |
|
112 val simp2 = [@{thm image_def},@{thm bex_UNIV}]@inject_thm |
|
113 val simp3 = [@{thm UNIV_def}] |
|
114 |
|
115 val proof3 = fn _ => EVERY [cut_facts_tac inj_thm 1, |
|
116 dtac @{thm range_inj_infinite} 1, |
|
117 asm_full_simp_tac (HOL_basic_ss addsimps simp2) 1, |
|
118 simp_tac (HOL_basic_ss addsimps simp3) 1] |
|
119 |
|
120 val (inf_thm,thy4) = |
|
121 PureThy.add_thms [((ak^"_infinite",Goal.prove_global thy1 [] [] stmnt3 proof3), [])] thy3 |
|
122 in |
|
123 ((inj_thm,inject_thm,inf_thm),thy4) |
|
124 end) ak_names thy |
|
125 |
70 (* produces a list consisting of pairs: *) |
126 (* produces a list consisting of pairs: *) |
71 (* fst component is the atom-kind name *) |
127 (* fst component is the atom-kind name *) |
72 (* snd component is its type *) |
128 (* snd component is its type *) |
73 val full_ak_names = map (Sign.intern_type thy1) ak_names; |
129 val full_ak_names = map (Sign.intern_type thy1) ak_names; |
74 val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names; |
130 val ak_names_types = ak_names ~~ map (Type o rpair []) full_ak_names; |