|
1 (* Title: HOL/BNF/Examples/HFset.thy |
|
2 Author: Andrei Popescu, TU Muenchen |
|
3 Copyright 2012 |
|
4 |
|
5 Hereditary sets. |
|
6 *) |
|
7 |
|
8 header {* Hereditary Sets *} |
|
9 |
|
10 theory HFset |
|
11 imports "../BNF" |
|
12 begin |
|
13 |
|
14 |
|
15 section {* Datatype definition *} |
|
16 |
|
17 data_raw hfset: 'hfset = "'hfset fset" |
|
18 |
|
19 |
|
20 section {* Customization of terms *} |
|
21 |
|
22 subsection{* Constructors *} |
|
23 |
|
24 definition "Fold hs \<equiv> hfset_ctor hs" |
|
25 |
|
26 lemma hfset_simps[simp]: |
|
27 "\<And>hs1 hs2. Fold hs1 = Fold hs2 \<longrightarrow> hs1 = hs2" |
|
28 unfolding Fold_def hfset.ctor_inject by auto |
|
29 |
|
30 theorem hfset_cases[elim, case_names Fold]: |
|
31 assumes Fold: "\<And> hs. h = Fold hs \<Longrightarrow> phi" |
|
32 shows phi |
|
33 using Fold unfolding Fold_def |
|
34 by (cases rule: hfset.ctor_exhaust[of h]) simp |
|
35 |
|
36 lemma hfset_induct[case_names Fold, induct type: hfset]: |
|
37 assumes Fold: "\<And> hs. (\<And> h. h |\<in>| hs \<Longrightarrow> phi h) \<Longrightarrow> phi (Fold hs)" |
|
38 shows "phi t" |
|
39 apply (induct rule: hfset.ctor_induct) |
|
40 using Fold unfolding Fold_def fset_fset_member mem_Collect_eq .. |
|
41 |
|
42 (* alternative induction principle, using fset: *) |
|
43 lemma hfset_induct_fset[case_names Fold, induct type: hfset]: |
|
44 assumes Fold: "\<And> hs. (\<And> h. h \<in> fset hs \<Longrightarrow> phi h) \<Longrightarrow> phi (Fold hs)" |
|
45 shows "phi t" |
|
46 apply (induct rule: hfset_induct) |
|
47 using Fold by (metis notin_fset) |
|
48 |
|
49 subsection{* Recursion and iteration (fold) *} |
|
50 |
|
51 lemma hfset_ctor_rec: |
|
52 "hfset_ctor_rec R (Fold hs) = R (map_fset <id, hfset_ctor_rec R> hs)" |
|
53 using hfset.ctor_recs unfolding Fold_def . |
|
54 |
|
55 (* The iterator has a simpler form: *) |
|
56 lemma hfset_ctor_fold: |
|
57 "hfset_ctor_fold R (Fold hs) = R (map_fset (hfset_ctor_fold R) hs)" |
|
58 using hfset.ctor_folds unfolding Fold_def . |
|
59 |
|
60 end |