| author | wenzelm | 
| Thu, 08 Jul 2021 22:21:31 +0200 | |
| changeset 73950 | cc49da3003aa | 
| parent 71262 | a30278c8585f | 
| child 75624 | 22d1c5f2b9f4 | 
| permissions | -rw-r--r-- | 
| 58128 | 1 | (* Title: HOL/BNF_Composition.thy | 
| 48975 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 2 | Author: Dmitriy Traytel, TU Muenchen | 
| 57698 | 3 | Author: Jasmin Blanchette, TU Muenchen | 
| 4 | Copyright 2012, 2013, 2014 | |
| 48975 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 5 | |
| 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 6 | Composition of bounded natural functors. | 
| 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 7 | *) | 
| 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 8 | |
| 60758 | 9 | section \<open>Composition of Bounded Natural Functors\<close> | 
| 48975 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 10 | |
| 58128 | 11 | theory BNF_Composition | 
| 55936 | 12 | imports BNF_Def | 
| 48975 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 13 | begin | 
| 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 14 | |
| 60918 
4ceef1592e8c
new command for lifting BNF structure over typedefs
 traytel parents: 
60758diff
changeset | 15 | lemma ssubst_mem: "\<lbrakk>t = s; s \<in> X\<rbrakk> \<Longrightarrow> t \<in> X" | 
| 
4ceef1592e8c
new command for lifting BNF structure over typedefs
 traytel parents: 
60758diff
changeset | 16 | by simp | 
| 
4ceef1592e8c
new command for lifting BNF structure over typedefs
 traytel parents: 
60758diff
changeset | 17 | |
| 67091 | 18 | lemma empty_natural: "(\<lambda>_. {}) \<circ> f = image g \<circ> (\<lambda>_. {})"
 | 
| 58128 | 19 | by (rule ext) simp | 
| 49312 | 20 | |
| 67091 | 21 | lemma Union_natural: "Union \<circ> image (image f) = image f \<circ> Union" | 
| 58128 | 22 | by (rule ext) (auto simp only: comp_apply) | 
| 49312 | 23 | |
| 67091 | 24 | lemma in_Union_o_assoc: "x \<in> (Union \<circ> gset \<circ> gmap) A \<Longrightarrow> x \<in> (Union \<circ> (gset \<circ> gmap)) A" | 
| 58128 | 25 | by (unfold comp_assoc) | 
| 49312 | 26 | |
| 27 | lemma comp_single_set_bd: | |
| 28 | assumes fbd_Card_order: "Card_order fbd" and | |
| 29 | fset_bd: "\<And>x. |fset x| \<le>o fbd" and | |
| 30 | gset_bd: "\<And>x. |gset x| \<le>o gbd" | |
| 52141 
eff000cab70f
weaker precendence of syntax for big intersection and union on sets
 haftmann parents: 
51893diff
changeset | 31 | shows "|\<Union>(fset ` gset x)| \<le>o gbd *c fbd" | 
| 58128 | 32 | apply simp | 
| 33 | apply (rule ordLeq_transitive) | |
| 34 | apply (rule card_of_UNION_Sigma) | |
| 35 | apply (subst SIGMA_CSUM) | |
| 36 | apply (rule ordLeq_transitive) | |
| 37 | apply (rule card_of_Csum_Times') | |
| 38 | apply (rule fbd_Card_order) | |
| 39 | apply (rule ballI) | |
| 40 | apply (rule fset_bd) | |
| 41 | apply (rule ordLeq_transitive) | |
| 42 | apply (rule cprod_mono1) | |
| 43 | apply (rule gset_bd) | |
| 44 | apply (rule ordIso_imp_ordLeq) | |
| 45 | apply (rule ordIso_refl) | |
| 46 | apply (rule Card_order_cprod) | |
| 47 | done | |
| 49312 | 48 | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 49 | lemma csum_dup: "cinfinite r \<Longrightarrow> Card_order r \<Longrightarrow> p +c p' =o r +c r \<Longrightarrow> p +c p' =o r" | 
| 58128 | 50 | apply (erule ordIso_transitive) | 
| 51 | apply (frule csum_absorb2') | |
| 52 | apply (erule ordLeq_refl) | |
| 53 | by simp | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 54 | |
| 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 55 | lemma cprod_dup: "cinfinite r \<Longrightarrow> Card_order r \<Longrightarrow> p *c p' =o r *c r \<Longrightarrow> p *c p' =o r" | 
| 58128 | 56 | apply (erule ordIso_transitive) | 
| 57 | apply (rule cprod_infinite) | |
| 58 | by simp | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 59 | |
| 52141 
eff000cab70f
weaker precendence of syntax for big intersection and union on sets
 haftmann parents: 
51893diff
changeset | 60 | lemma Union_image_insert: "\<Union>(f ` insert a B) = f a \<union> \<Union>(f ` B)" | 
| 58128 | 61 | by simp | 
| 49312 | 62 | |
| 52141 
eff000cab70f
weaker precendence of syntax for big intersection and union on sets
 haftmann parents: 
51893diff
changeset | 63 | lemma Union_image_empty: "A \<union> \<Union>(f ` {}) = A"
 | 
| 58128 | 64 | by simp | 
| 49312 | 65 | |
| 67091 | 66 | lemma image_o_collect: "collect ((\<lambda>f. image g \<circ> f) ` F) = image g \<circ> collect F" | 
| 58128 | 67 | by (rule ext) (auto simp add: collect_def) | 
| 49312 | 68 | |
| 69 | lemma conj_subset_def: "A \<subseteq> {x. P x \<and> Q x} = (A \<subseteq> {x. P x} \<and> A \<subseteq> {x. Q x})"
 | |
| 58128 | 70 | by blast | 
| 49312 | 71 | |
| 52141 
eff000cab70f
weaker precendence of syntax for big intersection and union on sets
 haftmann parents: 
51893diff
changeset | 72 | lemma UN_image_subset: "\<Union>(f ` g x) \<subseteq> X = (g x \<subseteq> {x. f x \<subseteq> X})"
 | 
| 58128 | 73 | by blast | 
| 49312 | 74 | |
| 69745 | 75 | lemma comp_set_bd_Union_o_collect: "|\<Union>(\<Union>((\<lambda>f. f x) ` X))| \<le>o hbd \<Longrightarrow> |(Union \<circ> collect X) x| \<le>o hbd" | 
| 58128 | 76 | by (unfold comp_apply collect_def) simp | 
| 49312 | 77 | |
| 62324 | 78 | lemma Collect_inj: "Collect P = Collect Q \<Longrightarrow> P = Q" | 
| 79 | by blast | |
| 80 | ||
| 67613 | 81 | lemma Grp_fst_snd: "(Grp (Collect (case_prod R)) fst)\<inverse>\<inverse> OO Grp (Collect (case_prod R)) snd = R" | 
| 58128 | 82 | unfolding Grp_def fun_eq_iff relcompp.simps by auto | 
| 51893 
596baae88a88
got rid of the set based relator---use (binary) predicate based relator instead
 traytel parents: 
49512diff
changeset | 83 | |
| 67613 | 84 | lemma OO_Grp_cong: "A = B \<Longrightarrow> (Grp A f)\<inverse>\<inverse> OO Grp A g = (Grp B f)\<inverse>\<inverse> OO Grp B g" | 
| 58128 | 85 | by (rule arg_cong) | 
| 51893 
596baae88a88
got rid of the set based relator---use (binary) predicate based relator instead
 traytel parents: 
49512diff
changeset | 86 | |
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 87 | lemma vimage2p_relcompp_mono: "R OO S \<le> T \<Longrightarrow> | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 88 | vimage2p f g R OO vimage2p g h S \<le> vimage2p f h T" | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 89 | unfolding vimage2p_def by auto | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 90 | |
| 67091 | 91 | lemma type_copy_map_cong0: "M (g x) = N (h x) \<Longrightarrow> (f \<circ> M \<circ> g) x = (f \<circ> N \<circ> h) x" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 92 | by auto | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 93 | |
| 67091 | 94 | lemma type_copy_set_bd: "(\<And>y. |S y| \<le>o bd) \<Longrightarrow> |(S \<circ> Rep) x| \<le>o bd" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 95 | by auto | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 96 | |
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 97 | lemma vimage2p_cong: "R = S \<Longrightarrow> vimage2p f g R = vimage2p f g S" | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 98 | by simp | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 99 | |
| 67091 | 100 | lemma Ball_comp_iff: "(\<lambda>x. Ball (A x) f) \<circ> g = (\<lambda>x. Ball ((A \<circ> g) x) f)" | 
| 62324 | 101 | unfolding o_def by auto | 
| 102 | ||
| 67091 | 103 | lemma conj_comp_iff: "(\<lambda>x. P x \<and> Q x) \<circ> g = (\<lambda>x. (P \<circ> g) x \<and> (Q \<circ> g) x)" | 
| 62324 | 104 | unfolding o_def by auto | 
| 105 | ||
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 106 | context | 
| 58128 | 107 | fixes Rep Abs | 
| 108 | assumes type_copy: "type_definition Rep Abs UNIV" | |
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 109 | begin | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 110 | |
| 67091 | 111 | lemma type_copy_map_id0: "M = id \<Longrightarrow> Abs \<circ> M \<circ> Rep = id" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 112 | using type_definition.Rep_inverse[OF type_copy] by auto | 
| 55811 | 113 | |
| 67091 | 114 | lemma type_copy_map_comp0: "M = M1 \<circ> M2 \<Longrightarrow> f \<circ> M \<circ> g = (f \<circ> M1 \<circ> Rep) \<circ> (Abs \<circ> M2 \<circ> g)" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 115 | using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto | 
| 55811 | 116 | |
| 67091 | 117 | lemma type_copy_set_map0: "S \<circ> M = image f \<circ> S' \<Longrightarrow> (S \<circ> Rep) \<circ> (Abs \<circ> M \<circ> g) = image f \<circ> (S' \<circ> g)" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 118 | using type_definition.Abs_inverse[OF type_copy UNIV_I] by (auto simp: o_def fun_eq_iff) | 
| 55811 | 119 | |
| 67091 | 120 | lemma type_copy_wit: "x \<in> (S \<circ> Rep) (Abs y) \<Longrightarrow> x \<in> S y" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 121 | using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto | 
| 55811 | 122 | |
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 123 | lemma type_copy_vimage2p_Grp_Rep: "vimage2p f Rep (Grp (Collect P) h) = | 
| 67091 | 124 | Grp (Collect (\<lambda>x. P (f x))) (Abs \<circ> h \<circ> f)" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 125 | unfolding vimage2p_def Grp_def fun_eq_iff | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 126 | by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 127 | type_definition.Rep_inverse[OF type_copy] dest: sym) | 
| 55811 | 128 | |
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 129 | lemma type_copy_vimage2p_Grp_Abs: | 
| 67091 | 130 | "\<And>h. vimage2p g Abs (Grp (Collect P) h) = Grp (Collect (\<lambda>x. P (g x))) (Rep \<circ> h \<circ> g)" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 131 | unfolding vimage2p_def Grp_def fun_eq_iff | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 132 | by (auto simp: type_definition.Abs_inverse[OF type_copy UNIV_I] | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 133 | type_definition.Rep_inverse[OF type_copy] dest: sym) | 
| 55811 | 134 | |
| 135 | lemma type_copy_ex_RepI: "(\<exists>b. F b) = (\<exists>b. F (Rep b))" | |
| 136 | proof safe | |
| 137 | fix b assume "F b" | |
| 138 | show "\<exists>b'. F (Rep b')" | |
| 139 | proof (rule exI) | |
| 60758 | 140 | from \<open>F b\<close> show "F (Rep (Abs b))" using type_definition.Abs_inverse[OF type_copy] by auto | 
| 55811 | 141 | qed | 
| 142 | qed blast | |
| 143 | ||
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 144 | lemma vimage2p_relcompp_converse: | 
| 67613 | 145 | "vimage2p f g (R\<inverse>\<inverse> OO S) = (vimage2p Rep f R)\<inverse>\<inverse> OO vimage2p Rep g S" | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 146 | unfolding vimage2p_def relcompp.simps conversep.simps fun_eq_iff image_def | 
| 55811 | 147 | by (auto simp: type_copy_ex_RepI) | 
| 55803 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 148 | |
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 149 | end | 
| 
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
 traytel parents: 
55705diff
changeset | 150 | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 151 | bnf DEADID: 'a | 
| 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 152 | map: "id :: 'a \<Rightarrow> 'a" | 
| 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 153 | bd: natLeq | 
| 67399 | 154 | rel: "(=) :: 'a \<Rightarrow> 'a \<Rightarrow> bool" | 
| 62324 | 155 | by (auto simp add: natLeq_card_order natLeq_cinfinite) | 
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 156 | |
| 58353 | 157 | definition id_bnf :: "'a \<Rightarrow> 'a" where | 
| 158 | "id_bnf \<equiv> (\<lambda>x. x)" | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 159 | |
| 58181 | 160 | lemma id_bnf_apply: "id_bnf x = x" | 
| 161 | unfolding id_bnf_def by simp | |
| 56016 
8875cdcfc85b
unfold intermediate definitions after sealing the bnf
 traytel parents: 
55936diff
changeset | 162 | |
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 163 | bnf ID: 'a | 
| 58181 | 164 |   map: "id_bnf :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b"
 | 
| 55935 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 165 |   sets: "\<lambda>x. {x}"
 | 
| 
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
 traytel parents: 
55930diff
changeset | 166 | bd: natLeq | 
| 58181 | 167 |   rel: "id_bnf :: ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
 | 
| 62324 | 168 |   pred: "id_bnf :: ('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool"
 | 
| 58181 | 169 | unfolding id_bnf_def | 
| 58128 | 170 | apply (auto simp: Grp_def fun_eq_iff relcompp.simps natLeq_card_order natLeq_cinfinite) | 
| 171 | apply (rule ordLess_imp_ordLeq[OF finite_ordLess_infinite[OF _ natLeq_Well_order]]) | |
| 172 | apply (auto simp add: Field_card_of Field_natLeq card_of_well_order_on)[3] | |
| 173 | done | |
| 55854 
ee270328a781
make 'typedef' optional, depending on size of original type
 blanchet parents: 
55851diff
changeset | 174 | |
| 58181 | 175 | lemma type_definition_id_bnf_UNIV: "type_definition id_bnf id_bnf UNIV" | 
| 176 | unfolding id_bnf_def by unfold_locales auto | |
| 55854 
ee270328a781
make 'typedef' optional, depending on size of original type
 blanchet parents: 
55851diff
changeset | 177 | |
| 69605 | 178 | ML_file \<open>Tools/BNF/bnf_comp_tactics.ML\<close> | 
| 179 | ML_file \<open>Tools/BNF/bnf_comp.ML\<close> | |
| 49309 
f20b24214ac2
split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
 blanchet parents: 
49308diff
changeset | 180 | |
| 58282 | 181 | hide_fact | 
| 182 | DEADID.inj_map DEADID.inj_map_strong DEADID.map_comp DEADID.map_cong DEADID.map_cong0 | |
| 183 | DEADID.map_cong_simp DEADID.map_id DEADID.map_id0 DEADID.map_ident DEADID.map_transfer | |
| 184 | DEADID.rel_Grp DEADID.rel_compp DEADID.rel_compp_Grp DEADID.rel_conversep DEADID.rel_eq | |
| 185 | DEADID.rel_flip DEADID.rel_map DEADID.rel_mono DEADID.rel_transfer | |
| 186 | ID.inj_map ID.inj_map_strong ID.map_comp ID.map_cong ID.map_cong0 ID.map_cong_simp ID.map_id | |
| 187 | ID.map_id0 ID.map_ident ID.map_transfer ID.rel_Grp ID.rel_compp ID.rel_compp_Grp ID.rel_conversep | |
| 188 | ID.rel_eq ID.rel_flip ID.rel_map ID.rel_mono ID.rel_transfer ID.set_map ID.set_transfer | |
| 189 | ||
| 48975 
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
 blanchet parents: diff
changeset | 190 | end |