equal
deleted
inserted
replaced
5 *) |
5 *) |
6 |
6 |
7 section \<open>Type of finite sets defined as a subtype of sets\<close> |
7 section \<open>Type of finite sets defined as a subtype of sets\<close> |
8 |
8 |
9 theory FSet |
9 theory FSet |
10 imports Main |
10 imports Main Countable |
11 begin |
11 begin |
12 |
12 |
13 subsection \<open>Definition of the type\<close> |
13 subsection \<open>Definition of the type\<close> |
14 |
14 |
15 typedef 'a fset = "{A :: 'a set. finite A}" morphisms fset Abs_fset |
15 typedef 'a fset = "{A :: 'a set. finite A}" morphisms fset Abs_fset |
1113 qed |
1113 qed |
1114 qed |
1114 qed |
1115 qed |
1115 qed |
1116 |
1116 |
1117 |
1117 |
|
1118 subsubsection \<open>Countability\<close> |
|
1119 |
|
1120 lemma exists_fset_of_list: "\<exists>xs. fset_of_list xs = S" |
|
1121 including fset.lifting |
|
1122 by transfer (rule finite_list) |
|
1123 |
|
1124 lemma fset_of_list_surj[simp, intro]: "surj fset_of_list" |
|
1125 proof - |
|
1126 have "x \<in> range fset_of_list" for x :: "'a fset" |
|
1127 unfolding image_iff |
|
1128 using exists_fset_of_list by fastforce |
|
1129 thus ?thesis by auto |
|
1130 qed |
|
1131 |
|
1132 instance fset :: (countable) countable |
|
1133 proof |
|
1134 obtain to_nat :: "'a list \<Rightarrow> nat" where "inj to_nat" |
|
1135 by (metis ex_inj) |
|
1136 moreover have "inj (inv fset_of_list)" |
|
1137 using fset_of_list_surj by (rule surj_imp_inj_inv) |
|
1138 ultimately have "inj (to_nat \<circ> inv fset_of_list)" |
|
1139 by (rule inj_comp) |
|
1140 thus "\<exists>to_nat::'a fset \<Rightarrow> nat. inj to_nat" |
|
1141 by auto |
|
1142 qed |
|
1143 |
|
1144 |
1118 subsection \<open>Quickcheck setup\<close> |
1145 subsection \<open>Quickcheck setup\<close> |
1119 |
1146 |
1120 text \<open>Setup adapted from sets.\<close> |
1147 text \<open>Setup adapted from sets.\<close> |
1121 |
1148 |
1122 notation Quickcheck_Exhaustive.orelse (infixr "orelse" 55) |
1149 notation Quickcheck_Exhaustive.orelse (infixr "orelse" 55) |