117 "fcard :: 'a fset \<Rightarrow> nat" |
117 "fcard :: 'a fset \<Rightarrow> nat" |
118 is |
118 is |
119 "fcard_raw" |
119 "fcard_raw" |
120 |
120 |
121 lemma fcard_raw_0: |
121 lemma fcard_raw_0: |
122 fixes a :: "'a list" |
122 fixes xs :: "'a list" |
123 shows "(fcard_raw a = 0) = (a \<approx> [])" |
123 shows "(fcard_raw xs = 0) = (xs \<approx> [])" |
124 apply (induct a) |
124 by (induct xs) (auto simp add: memb_def) |
125 apply auto |
|
126 apply (drule memb_absorb) |
|
127 apply (auto simp add: nil_not_cons) |
|
128 done |
|
129 |
125 |
130 lemma fcard_raw_gt_0: |
126 lemma fcard_raw_gt_0: |
131 assumes a: "x \<in> set xs" |
127 assumes a: "x \<in> set xs" |
132 shows "0 < fcard_raw xs" |
128 shows "0 < fcard_raw xs" |
133 using a |
129 using a |
134 by (induct xs) (auto simp add: memb_def) |
130 by (induct xs) (auto simp add: memb_def) |
135 |
131 |
136 lemma fcard_raw_not_memb: |
132 lemma fcard_raw_not_memb: |
137 fixes x :: "'a" |
133 fixes x :: "'a" |
138 fixes xs :: "'a list" |
134 fixes xs :: "'a list" |
139 shows "(~(memb x xs)) = (fcard_raw (x # xs) = Suc (fcard_raw xs))" |
135 shows "\<not>(memb x xs) \<longleftrightarrow> (fcard_raw (x # xs) = Suc (fcard_raw xs))" |
140 by auto |
136 by auto |
141 |
137 |
142 lemma fcard_raw_suc: |
138 lemma fcard_raw_suc: |
143 fixes xs :: "'a list" |
139 fixes xs :: "'a list" |
144 fixes n :: "nat" |
140 fixes n :: "nat" |
145 assumes c: "fcard_raw xs = Suc n" |
141 assumes c: "fcard_raw xs = Suc n" |
146 shows "\<exists>a ys. ~(memb a ys) \<and> xs \<approx> (a # ys) \<and> fcard_raw ys = n" |
142 shows "\<exists>x ys. \<not>(memb x ys) \<and> xs \<approx> (x # ys) \<and> fcard_raw ys = n" |
147 unfolding memb_def |
143 unfolding memb_def |
148 using c |
144 using c |
149 proof (induct xs) |
145 proof (induct xs) |
150 case Nil |
146 case Nil |
151 then show ?case by simp |
147 then show ?case by simp |
167 apply (simp add: memb_def) |
163 apply (simp add: memb_def) |
168 done |
164 done |
169 qed |
165 qed |
170 qed |
166 qed |
171 |
167 |
172 lemma singleton_fcard_1: "set a = {b} \<Longrightarrow> fcard_raw a = Suc 0" |
168 lemma singleton_fcard_1: |
173 apply (induct a) |
169 shows "set xs = {x} \<Longrightarrow> fcard_raw xs = Suc 0" |
|
170 apply (induct xs) |
174 apply simp_all |
171 apply simp_all |
175 apply auto |
172 apply auto |
176 apply (subgoal_tac "set a2 = {b}") |
173 apply (subgoal_tac "set xs = {x}") |
177 apply simp |
174 apply simp |
178 apply (simp add: memb_def) |
175 apply (simp add: memb_def) |
179 apply auto |
176 apply auto |
180 apply (subgoal_tac "set a2 = {}") |
177 apply (subgoal_tac "set xs = {}") |
181 apply simp |
178 apply simp |
182 by (metis memb_def subset_empty subset_insert) |
179 by (metis memb_def subset_empty subset_insert) |
183 |
180 |
184 lemma fcard_raw_1: |
181 lemma fcard_raw_1: |
185 fixes a :: "'a list" |
182 fixes a :: "'a list" |
186 shows "(fcard_raw a = 1) = (\<exists>b. a \<approx> [b])" |
183 shows "(fcard_raw xs = 1) = (\<exists>x. xs \<approx> [x])" |
187 apply auto |
184 apply auto |
188 apply (drule fcard_raw_suc) |
185 apply (drule fcard_raw_suc) |
189 apply clarify |
186 apply clarify |
190 apply (simp add: fcard_raw_0) |
187 apply (simp add: fcard_raw_0) |
191 apply (rule_tac x="aa" in exI) |
188 apply (rule_tac x="x" in exI) |
192 apply simp |
189 apply simp |
193 apply (subgoal_tac "set a = {b}") |
190 apply (subgoal_tac "set xs = {x}") |
194 apply (erule singleton_fcard_1) |
191 apply (erule singleton_fcard_1) |
195 apply auto |
192 apply auto |
196 done |
193 done |
197 |
194 |
198 lemma fcard_raw_delete_one: |
195 lemma fcard_raw_delete_one: |
199 "fcard_raw ([x \<leftarrow> xs. x \<noteq> y]) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)" |
196 "fcard_raw ([x \<leftarrow> xs. x \<noteq> y]) = (if memb y xs then fcard_raw xs - 1 else fcard_raw xs)" |
200 by (induct xs) (auto dest: fcard_raw_gt_0 simp add: memb_def) |
197 by (induct xs) (auto dest: fcard_raw_gt_0 simp add: memb_def) |
201 |
198 |
202 lemma fcard_raw_rsp_aux: |
199 lemma fcard_raw_rsp_aux: |
203 assumes a: "a \<approx> b" |
200 assumes a: "xs \<approx> ys" |
204 shows "fcard_raw a = fcard_raw b" |
201 shows "fcard_raw xs = fcard_raw ys" |
205 using a |
202 using a |
206 apply(induct a arbitrary: b) |
203 apply(induct xs arbitrary: ys) |
207 apply(auto simp add: memb_def) |
204 apply(auto simp add: memb_def) |
208 apply(metis) |
205 apply(metis) |
209 apply(drule_tac x="[x \<leftarrow> b. x \<noteq> a1]" in meta_spec) |
206 apply(drule_tac x="[x \<leftarrow> ys. x \<noteq> a]" in meta_spec) |
210 apply(simp add: fcard_raw_delete_one) |
207 apply(simp add: fcard_raw_delete_one) |
211 apply(metis Suc_pred'[OF fcard_raw_gt_0] fcard_raw_delete_one memb_def) |
208 apply(metis Suc_pred'[OF fcard_raw_gt_0] fcard_raw_delete_one memb_def) |
212 done |
209 done |
213 |
210 |
214 lemma fcard_raw_rsp[quot_respect]: |
211 lemma fcard_raw_rsp[quot_respect]: |
245 lemma map_rsp[quot_respect]: |
242 lemma map_rsp[quot_respect]: |
246 shows "(op = ===> op \<approx> ===> op \<approx>) map map" |
243 shows "(op = ===> op \<approx> ===> op \<approx>) map map" |
247 by (auto simp add: map_rsp_aux) |
244 by (auto simp add: map_rsp_aux) |
248 |
245 |
249 lemma cons_left_comm: |
246 lemma cons_left_comm: |
250 "x # y # A \<approx> y # x # A" |
247 "x # y # xs \<approx> y # x # xs" |
251 by (auto simp add: id_simps) |
248 by auto |
252 |
249 |
253 lemma cons_left_idem: |
250 lemma cons_left_idem: |
254 "x # x # A \<approx> x # A" |
251 "x # x # xs \<approx> x # xs" |
255 by (auto simp add: id_simps) |
252 by auto |
256 |
253 |
257 lemma none_mem_nil: |
254 lemma none_mem_nil: |
258 "(\<forall>a. a \<notin> set A) = (A \<approx> [])" |
255 "(\<forall>x. x \<notin> set xs) = (xs \<approx> [])" |
259 by simp |
256 by simp |
260 |
257 |
261 lemma fset_raw_strong_cases: |
258 lemma fset_raw_strong_cases: |
262 "(X = []) \<or> (\<exists>a Y. ((a \<notin> set Y) \<and> (X \<approx> a # Y)))" |
259 "(xs = []) \<or> (\<exists>x ys. ((x \<notin> set ys) \<and> (xs \<approx> x # ys)))" |
263 apply (induct X) |
260 apply (induct xs) |
264 apply (simp) |
261 apply (simp) |
265 apply (rule disjI2) |
262 apply (rule disjI2) |
266 apply (erule disjE) |
263 apply (erule disjE) |
267 apply (rule_tac x="a" in exI) |
264 apply (rule_tac x="a" in exI) |
268 apply (rule_tac x="[]" in exI) |
265 apply (rule_tac x="[]" in exI) |
269 apply (simp) |
266 apply (simp) |
270 apply (erule exE)+ |
267 apply (erule exE)+ |
271 apply (case_tac "a = aa") |
268 apply (case_tac "x = a") |
272 apply (rule_tac x="a" in exI) |
269 apply (rule_tac x="a" in exI) |
273 apply (rule_tac x="Y" in exI) |
270 apply (rule_tac x="ys" in exI) |
274 apply (simp) |
271 apply (simp) |
275 apply (rule_tac x="aa" in exI) |
272 apply (rule_tac x="x" in exI) |
276 apply (rule_tac x="a # Y" in exI) |
273 apply (rule_tac x="a # ys" in exI) |
277 apply (auto) |
274 apply (auto) |
278 done |
275 done |
279 |
276 |
280 fun |
277 fun |
281 delete_raw :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" |
278 delete_raw :: "'a list \<Rightarrow> 'a \<Rightarrow> 'a list" |
282 where |
279 where |
283 "delete_raw [] x = []" |
280 "delete_raw [] x = []" |
284 | "delete_raw (a # A) x = (if (a = x) then delete_raw A x else a # (delete_raw A x))" |
281 | "delete_raw (a # A) x = (if (a = x) then delete_raw A x else a # (delete_raw A x))" |
285 |
282 |
286 lemma memb_delete_raw: |
283 lemma memb_delete_raw: |
287 "memb x (delete_raw A a) = (memb x A \<and> x \<noteq> a)" |
284 "memb x (delete_raw xs y) = (memb x xs \<and> x \<noteq> y)" |
288 by (induct A arbitrary: x a) (auto simp add: memb_def) |
285 by (induct xs arbitrary: x y) (auto simp add: memb_def) |
289 |
286 |
290 lemma [quot_respect]: |
287 lemma [quot_respect]: |
291 "(op \<approx> ===> op = ===> op \<approx>) delete_raw delete_raw" |
288 "(op \<approx> ===> op = ===> op \<approx>) delete_raw delete_raw" |
292 by (simp add: memb_def[symmetric] memb_delete_raw) |
289 by (simp add: memb_def[symmetric] memb_delete_raw) |
293 |
290 |
294 lemma memb_delete_raw_ident: |
291 lemma memb_delete_raw_ident: |
295 "\<not> memb a (delete_raw A a)" |
292 "\<not> memb x (delete_raw xs x)" |
296 by (induct A) (auto simp add: memb_def) |
293 by (induct xs) (auto simp add: memb_def) |
297 |
294 |
298 lemma not_memb_delete_raw_ident: |
295 lemma not_memb_delete_raw_ident: |
299 "\<not> memb b A \<Longrightarrow> delete_raw A b = A" |
296 "\<not> memb x xs \<Longrightarrow> delete_raw xs x = xs" |
300 by (induct A) (auto simp add: memb_def) |
297 by (induct xs) (auto simp add: memb_def) |
301 |
298 |
302 lemma fset_raw_delete_raw_cases: |
299 lemma fset_raw_delete_raw_cases: |
303 "X = [] \<or> (\<exists>a. memb a X \<and> X \<approx> a # delete_raw X a)" |
300 "xs = [] \<or> (\<exists>x. memb x xs \<and> xs \<approx> x # delete_raw xs x)" |
304 by (induct X) (auto simp add: memb_def) |
301 by (induct xs) (auto simp add: memb_def) |
305 |
302 |
306 lemma fdelete_raw_filter: |
303 lemma fdelete_raw_filter: |
307 "delete_raw xs y = [x \<leftarrow> xs. x \<noteq> y]" |
304 "delete_raw xs y = [x \<leftarrow> xs. x \<noteq> y]" |
308 by (induct xs) simp_all |
305 by (induct xs) simp_all |
309 |
306 |
354 apply (rule_tac [!] impI) |
351 apply (rule_tac [!] impI) |
355 apply (rule_tac [!] conjI) |
352 apply (rule_tac [!] conjI) |
356 apply (rule_tac [!] impI) |
353 apply (rule_tac [!] impI) |
357 apply (simp add: in_set_code memb_cons_iff memb_def) |
354 apply (simp add: in_set_code memb_cons_iff memb_def) |
358 apply (metis) |
355 apply (metis) |
359 apply (metis Nitpick.list_size_simp(2) ffold_raw.simps(2) length_Suc_conv memb_absorb memb_cons_iff nil_not_cons(2)) |
356 apply (metis Nitpick.list_size_simp(2) ffold_raw.simps(2) |
|
357 length_Suc_conv memb_absorb memb_cons_iff nil_not_cons(2)) |
360 defer |
358 defer |
361 apply (metis Nitpick.list_size_simp(2) ffold_raw.simps(2) length_Suc_conv memb_absorb memb_cons_iff nil_not_cons(2)) |
359 apply (metis Nitpick.list_size_simp(2) ffold_raw.simps(2) |
|
360 length_Suc_conv memb_absorb memb_cons_iff nil_not_cons(2)) |
362 apply (subgoal_tac "ffold_raw f z b = f a1 (ffold_raw f z (delete_raw b a1))") |
361 apply (subgoal_tac "ffold_raw f z b = f a1 (ffold_raw f z (delete_raw b a1))") |
363 apply (simp only:) |
362 apply (simp only:) |
364 apply (rule_tac f="f a1" in arg_cong) |
363 apply (rule_tac f="f a1" in arg_cong) |
365 apply (subgoal_tac "\<forall>e. memb e a2 = memb e (delete_raw b a1)") |
364 apply (subgoal_tac "\<forall>e. memb e a2 = memb e (delete_raw b a1)") |
366 apply simp |
365 apply simp |