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