src/HOL/BNF_Def.thy
 author blanchet Tue Jul 29 23:39:35 2014 +0200 (2014-07-29) changeset 57698 afef6616cbae parent 57641 dc59f147b27d child 57802 9c065009cd8a permissions -rw-r--r--
1 (*  Title:      HOL/BNF_Def.thy
2     Author:     Dmitriy Traytel, TU Muenchen
3     Author:     Jasmin Blanchette, TU Muenchen
6 Definition of bounded natural functors.
7 *)
9 header {* Definition of Bounded Natural Functors *}
11 theory BNF_Def
12 imports BNF_Cardinal_Arithmetic Fun_Def_Base
13 keywords
14   "print_bnfs" :: diag and
15   "bnf" :: thy_goal
16 begin
18 definition
19   rel_fun :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool"
20 where
21   "rel_fun A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))"
23 lemma rel_funI [intro]:
24   assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)"
25   shows "rel_fun A B f g"
26   using assms by (simp add: rel_fun_def)
28 lemma rel_funD:
29   assumes "rel_fun A B f g" and "A x y"
30   shows "B (f x) (g y)"
31   using assms by (simp add: rel_fun_def)
33 definition collect where
34 "collect F x = (\<Union>f \<in> F. f x)"
36 lemma fstI: "x = (y, z) \<Longrightarrow> fst x = y"
37 by simp
39 lemma sndI: "x = (y, z) \<Longrightarrow> snd x = z"
40 by simp
42 lemma bijI': "\<lbrakk>\<And>x y. (f x = f y) = (x = y); \<And>y. \<exists>x. y = f x\<rbrakk> \<Longrightarrow> bij f"
43 unfolding bij_def inj_on_def by auto blast
45 (* Operator: *)
46 definition "Gr A f = {(a, f a) | a. a \<in> A}"
48 definition "Grp A f = (\<lambda>a b. b = f a \<and> a \<in> A)"
50 definition vimage2p where
51   "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
53 lemma collect_comp: "collect F \<circ> g = collect ((\<lambda>f. f \<circ> g) ` F)"
54   by (rule ext) (auto simp only: comp_apply collect_def)
56 definition convol ("\<langle>(_,/ _)\<rangle>") where
57 "\<langle>f, g\<rangle> \<equiv> \<lambda>a. (f a, g a)"
59 lemma fst_convol:
60 "fst \<circ> \<langle>f, g\<rangle> = f"
61 apply(rule ext)
62 unfolding convol_def by simp
64 lemma snd_convol:
65 "snd \<circ> \<langle>f, g\<rangle> = g"
66 apply(rule ext)
67 unfolding convol_def by simp
69 lemma convol_mem_GrpI:
70 "x \<in> A \<Longrightarrow> \<langle>id, g\<rangle> x \<in> (Collect (split (Grp A g)))"
71 unfolding convol_def Grp_def by auto
73 definition csquare where
74 "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
76 lemma eq_alt: "op = = Grp UNIV id"
77 unfolding Grp_def by auto
79 lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
80   by auto
82 lemma leq_OOI: "R = op = \<Longrightarrow> R \<le> R OO R"
83   by auto
85 lemma OO_Grp_alt: "(Grp A f)^--1 OO Grp A g = (\<lambda>x y. \<exists>z. z \<in> A \<and> f z = x \<and> g z = y)"
86   unfolding Grp_def by auto
88 lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
89 unfolding Grp_def by auto
91 lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
92 unfolding Grp_def by auto
94 lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
95 unfolding Grp_def by auto
97 lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
98 unfolding Grp_def by auto
100 lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
101 unfolding Grp_def by auto
103 lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
104 unfolding Grp_def comp_def by auto
106 lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
107 unfolding Grp_def comp_def by auto
109 definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
111 lemma pick_middlep:
112 "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
113 unfolding pick_middlep_def apply(rule someI_ex) by auto
115 definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
116 definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
118 lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
119 unfolding fstOp_def mem_Collect_eq
120 by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct1])
122 lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
123 unfolding comp_def fstOp_def by simp
125 lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
126 unfolding comp_def sndOp_def by simp
128 lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
129 unfolding sndOp_def mem_Collect_eq
130 by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct2])
132 lemma csquare_fstOp_sndOp:
133 "csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
134 unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
136 lemma snd_fst_flip: "snd xy = (fst \<circ> (%(x, y). (y, x))) xy"
137 by (simp split: prod.split)
139 lemma fst_snd_flip: "fst xy = (snd \<circ> (%(x, y). (y, x))) xy"
140 by (simp split: prod.split)
142 lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
143 by auto
145 lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
146   by auto
148 lemma Collect_split_mono_strong:
149   "\<lbrakk>X = fst ` A; Y = snd ` A; \<forall>a\<in>X. \<forall>b \<in> Y. P a b \<longrightarrow> Q a b; A \<subseteq> Collect (split P)\<rbrakk> \<Longrightarrow>
150   A \<subseteq> Collect (split Q)"
151   by fastforce
154 lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
155 by simp
157 lemma case_sum_o_inj:
158 "case_sum f g \<circ> Inl = f"
159 "case_sum f g \<circ> Inr = g"
160 by auto
162 lemma card_order_csum_cone_cexp_def:
163   "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
164   unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
166 lemma If_the_inv_into_in_Func:
167   "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
168   (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
169 unfolding Func_def by (auto dest: the_inv_into_into)
171 lemma If_the_inv_into_f_f:
172   "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow>
173   ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<circ> g) i = id i"
174 unfolding Func_def by (auto elim: the_inv_into_f_f)
176 lemma the_inv_f_o_f_id: "inj f \<Longrightarrow> (the_inv f \<circ> f) z = id z"