author | nipkow |
Sun, 23 Sep 2018 15:42:19 +0200 | |
changeset 69038 | 2ce9bc515a64 |
parent 67613 | ce654b0e6d69 |
child 69605 | a96320074298 |
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:
60758
diff
changeset
|
13 |
keywords |
4ceef1592e8c
new command for lifting BNF structure over typedefs
traytel
parents:
60758
diff
changeset
|
14 |
"copy_bnf" :: thy_decl and |
4ceef1592e8c
new command for lifting BNF structure over typedefs
traytel
parents:
60758
diff
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:
60758
diff
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:
60758
diff
changeset
|
19 |
by simp |
4ceef1592e8c
new command for lifting BNF structure over typedefs
traytel
parents:
60758
diff
changeset
|
20 |
|
67091 | 21 |
lemma empty_natural: "(\<lambda>_. {}) \<circ> f = image g \<circ> (\<lambda>_. {})" |
58128 | 22 |
by (rule ext) simp |
49312 | 23 |
|
67091 | 24 |
lemma Union_natural: "Union \<circ> image (image f) = image f \<circ> Union" |
58128 | 25 |
by (rule ext) (auto simp only: comp_apply) |
49312 | 26 |
|
67091 | 27 |
lemma in_Union_o_assoc: "x \<in> (Union \<circ> gset \<circ> gmap) A \<Longrightarrow> x \<in> (Union \<circ> (gset \<circ> 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:
51893
diff
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:
55930
diff
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:
55930
diff
changeset
|
57 |
|
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
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:
55930
diff
changeset
|
62 |
|
52141
eff000cab70f
weaker precendence of syntax for big intersection and union on sets
haftmann
parents:
51893
diff
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:
51893
diff
changeset
|
66 |
lemma Union_image_empty: "A \<union> \<Union>(f ` {}) = A" |
58128 | 67 |
by simp |
49312 | 68 |
|
67091 | 69 |
lemma image_o_collect: "collect ((\<lambda>f. image g \<circ> f) ` F) = image g \<circ> 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:
51893
diff
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:
51893
diff
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 |
|
62324 | 81 |
lemma Collect_inj: "Collect P = Collect Q \<Longrightarrow> P = Q" |
82 |
by blast |
|
83 |
||
67613 | 84 |
lemma Grp_fst_snd: "(Grp (Collect (case_prod R)) fst)\<inverse>\<inverse> OO Grp (Collect (case_prod R)) snd = R" |
58128 | 85 |
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:
49512
diff
changeset
|
86 |
|
67613 | 87 |
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 | 88 |
by (rule arg_cong) |
51893
596baae88a88
got rid of the set based relator---use (binary) predicate based relator instead
traytel
parents:
49512
diff
changeset
|
89 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
90 |
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:
55705
diff
changeset
|
91 |
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:
55705
diff
changeset
|
92 |
unfolding vimage2p_def by auto |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
93 |
|
67091 | 94 |
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:
55705
diff
changeset
|
95 |
by auto |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
96 |
|
67091 | 97 |
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:
55705
diff
changeset
|
98 |
by auto |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
99 |
|
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
100 |
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:
55705
diff
changeset
|
101 |
by simp |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
102 |
|
67091 | 103 |
lemma Ball_comp_iff: "(\<lambda>x. Ball (A x) f) \<circ> g = (\<lambda>x. Ball ((A \<circ> g) x) f)" |
62324 | 104 |
unfolding o_def by auto |
105 |
||
67091 | 106 |
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 | 107 |
unfolding o_def by auto |
108 |
||
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
109 |
context |
58128 | 110 |
fixes Rep Abs |
111 |
assumes type_copy: "type_definition Rep Abs UNIV" |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
112 |
begin |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
113 |
|
67091 | 114 |
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:
55705
diff
changeset
|
115 |
using type_definition.Rep_inverse[OF type_copy] by auto |
55811 | 116 |
|
67091 | 117 |
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:
55705
diff
changeset
|
118 |
using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto |
55811 | 119 |
|
67091 | 120 |
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:
55705
diff
changeset
|
121 |
using type_definition.Abs_inverse[OF type_copy UNIV_I] by (auto simp: o_def fun_eq_iff) |
55811 | 122 |
|
67091 | 123 |
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:
55705
diff
changeset
|
124 |
using type_definition.Abs_inverse[OF type_copy UNIV_I] by auto |
55811 | 125 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
126 |
lemma type_copy_vimage2p_Grp_Rep: "vimage2p f Rep (Grp (Collect P) h) = |
67091 | 127 |
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:
55705
diff
changeset
|
128 |
unfolding vimage2p_def Grp_def fun_eq_iff |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
129 |
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:
55705
diff
changeset
|
130 |
type_definition.Rep_inverse[OF type_copy] dest: sym) |
55811 | 131 |
|
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
132 |
lemma type_copy_vimage2p_Grp_Abs: |
67091 | 133 |
"\<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:
55705
diff
changeset
|
134 |
unfolding vimage2p_def Grp_def fun_eq_iff |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
135 |
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:
55705
diff
changeset
|
136 |
type_definition.Rep_inverse[OF type_copy] dest: sym) |
55811 | 137 |
|
138 |
lemma type_copy_ex_RepI: "(\<exists>b. F b) = (\<exists>b. F (Rep b))" |
|
139 |
proof safe |
|
140 |
fix b assume "F b" |
|
141 |
show "\<exists>b'. F (Rep b')" |
|
142 |
proof (rule exI) |
|
60758 | 143 |
from \<open>F b\<close> show "F (Rep (Abs b))" using type_definition.Abs_inverse[OF type_copy] by auto |
55811 | 144 |
qed |
145 |
qed blast |
|
146 |
||
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
147 |
lemma vimage2p_relcompp_converse: |
67613 | 148 |
"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:
55705
diff
changeset
|
149 |
unfolding vimage2p_def relcompp.simps conversep.simps fun_eq_iff image_def |
55811 | 150 |
by (auto simp: type_copy_ex_RepI) |
55803
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
151 |
|
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
152 |
end |
74d3fe9031d8
joint work with blanchet: intermediate typedef for the input to fp-operations
traytel
parents:
55705
diff
changeset
|
153 |
|
55935
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
154 |
bnf DEADID: 'a |
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
155 |
map: "id :: 'a \<Rightarrow> 'a" |
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
156 |
bd: natLeq |
67399 | 157 |
rel: "(=) :: 'a \<Rightarrow> 'a \<Rightarrow> bool" |
62324 | 158 |
by (auto simp add: natLeq_card_order natLeq_cinfinite) |
55935
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
159 |
|
58353 | 160 |
definition id_bnf :: "'a \<Rightarrow> 'a" where |
161 |
"id_bnf \<equiv> (\<lambda>x. x)" |
|
55935
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
162 |
|
58181 | 163 |
lemma id_bnf_apply: "id_bnf x = x" |
164 |
unfolding id_bnf_def by simp |
|
56016
8875cdcfc85b
unfold intermediate definitions after sealing the bnf
traytel
parents:
55936
diff
changeset
|
165 |
|
55935
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
166 |
bnf ID: 'a |
58181 | 167 |
map: "id_bnf :: ('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b" |
55935
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
168 |
sets: "\<lambda>x. {x}" |
8f20d09d294e
move special BNFs used for composition only to BNF_Comp;
traytel
parents:
55930
diff
changeset
|
169 |
bd: natLeq |
58181 | 170 |
rel: "id_bnf :: ('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool" |
62324 | 171 |
pred: "id_bnf :: ('a \<Rightarrow> bool) \<Rightarrow> 'a \<Rightarrow> bool" |
58181 | 172 |
unfolding id_bnf_def |
58128 | 173 |
apply (auto simp: Grp_def fun_eq_iff relcompp.simps natLeq_card_order natLeq_cinfinite) |
174 |
apply (rule ordLess_imp_ordLeq[OF finite_ordLess_infinite[OF _ natLeq_Well_order]]) |
|
175 |
apply (auto simp add: Field_card_of Field_natLeq card_of_well_order_on)[3] |
|
176 |
done |
|
55854
ee270328a781
make 'typedef' optional, depending on size of original type
blanchet
parents:
55851
diff
changeset
|
177 |
|
58181 | 178 |
lemma type_definition_id_bnf_UNIV: "type_definition id_bnf id_bnf UNIV" |
179 |
unfolding id_bnf_def by unfold_locales auto |
|
55854
ee270328a781
make 'typedef' optional, depending on size of original type
blanchet
parents:
55851
diff
changeset
|
180 |
|
55062 | 181 |
ML_file "Tools/BNF/bnf_comp_tactics.ML" |
182 |
ML_file "Tools/BNF/bnf_comp.ML" |
|
60918
4ceef1592e8c
new command for lifting BNF structure over typedefs
traytel
parents:
60758
diff
changeset
|
183 |
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:
49308
diff
changeset
|
184 |
|
58282 | 185 |
hide_fact |
186 |
DEADID.inj_map DEADID.inj_map_strong DEADID.map_comp DEADID.map_cong DEADID.map_cong0 |
|
187 |
DEADID.map_cong_simp DEADID.map_id DEADID.map_id0 DEADID.map_ident DEADID.map_transfer |
|
188 |
DEADID.rel_Grp DEADID.rel_compp DEADID.rel_compp_Grp DEADID.rel_conversep DEADID.rel_eq |
|
189 |
DEADID.rel_flip DEADID.rel_map DEADID.rel_mono DEADID.rel_transfer |
|
190 |
ID.inj_map ID.inj_map_strong ID.map_comp ID.map_cong ID.map_cong0 ID.map_cong_simp ID.map_id |
|
191 |
ID.map_id0 ID.map_ident ID.map_transfer ID.rel_Grp ID.rel_compp ID.rel_compp_Grp ID.rel_conversep |
|
192 |
ID.rel_eq ID.rel_flip ID.rel_map ID.rel_mono ID.rel_transfer ID.set_map ID.set_transfer |
|
193 |
||
48975
7f79f94a432c
added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff
changeset
|
194 |
end |