src/HOL/BNF/BNF_Def.thy
 author traytel Thu Jul 25 16:46:53 2013 +0200 (2013-07-25) changeset 52731 dacd47a0633f parent 52730 6bf02eb4ddf7 child 52749 ed416f4ac34e permissions -rw-r--r--
transfer rule for {c,d}tor_{,un}fold
```     1 (*  Title:      HOL/BNF/BNF_Def.thy
```
```     2     Author:     Dmitriy Traytel, TU Muenchen
```
```     3     Copyright   2012
```
```     4
```
```     5 Definition of bounded natural functors.
```
```     6 *)
```
```     7
```
```     8 header {* Definition of Bounded Natural Functors *}
```
```     9
```
```    10 theory BNF_Def
```
```    11 imports BNF_Util
```
```    12 keywords
```
```    13   "print_bnfs" :: diag and
```
```    14   "bnf" :: thy_goal
```
```    15 begin
```
```    16
```
```    17 lemma collect_o: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
```
```    18 by (rule ext) (auto simp only: o_apply collect_def)
```
```    19
```
```    20 lemma converse_shift:
```
```    21 "R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
```
```    22 unfolding converse_def by auto
```
```    23
```
```    24 lemma conversep_shift:
```
```    25 "R1 \<le> R2 ^--1 \<Longrightarrow> R1 ^--1 \<le> R2"
```
```    26 unfolding conversep.simps by auto
```
```    27
```
```    28 definition convol ("<_ , _>") where
```
```    29 "<f , g> \<equiv> %a. (f a, g a)"
```
```    30
```
```    31 lemma fst_convol:
```
```    32 "fst o <f , g> = f"
```
```    33 apply(rule ext)
```
```    34 unfolding convol_def by simp
```
```    35
```
```    36 lemma snd_convol:
```
```    37 "snd o <f , g> = g"
```
```    38 apply(rule ext)
```
```    39 unfolding convol_def by simp
```
```    40
```
```    41 lemma convol_mem_GrpI:
```
```    42 "\<lbrakk>g x = g' x; x \<in> A\<rbrakk> \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
```
```    43 unfolding convol_def Grp_def by auto
```
```    44
```
```    45 definition csquare where
```
```    46 "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
```
```    47
```
```    48 (* The pullback of sets *)
```
```    49 definition thePull where
```
```    50 "thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
```
```    51
```
```    52 lemma wpull_thePull:
```
```    53 "wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
```
```    54 unfolding wpull_def thePull_def by auto
```
```    55
```
```    56 lemma wppull_thePull:
```
```    57 assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
```
```    58 shows
```
```    59 "\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
```
```    60    j a' \<in> A \<and>
```
```    61    e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
```
```    62 (is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
```
```    63 proof(rule bchoice[of ?A' ?phi], default)
```
```    64   fix a' assume a': "a' \<in> ?A'"
```
```    65   hence "fst a' \<in> B1" unfolding thePull_def by auto
```
```    66   moreover
```
```    67   from a' have "snd a' \<in> B2" unfolding thePull_def by auto
```
```    68   moreover have "f1 (fst a') = f2 (snd a')"
```
```    69   using a' unfolding csquare_def thePull_def by auto
```
```    70   ultimately show "\<exists> ja'. ?phi a' ja'"
```
```    71   using assms unfolding wppull_def by blast
```
```    72 qed
```
```    73
```
```    74 lemma wpull_wppull:
```
```    75 assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
```
```    76 1: "\<forall> a' \<in> A'. j a' \<in> A \<and> e1 (p1 (j a')) = e1 (p1' a') \<and> e2 (p2 (j a')) = e2 (p2' a')"
```
```    77 shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
```
```    78 unfolding wppull_def proof safe
```
```    79   fix b1 b2
```
```    80   assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
```
```    81   then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
```
```    82   using wp unfolding wpull_def by blast
```
```    83   show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
```
```    84   apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
```
```    85 qed
```
```    86
```
```    87 lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
```
```    88    wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
```
```    89 by (erule wpull_wppull) auto
```
```    90
```
```    91 lemma eq_alt: "op = = Grp UNIV id"
```
```    92 unfolding Grp_def by auto
```
```    93
```
```    94 lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
```
```    95   by auto
```
```    96
```
```    97 lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
```
```    98   by auto
```
```    99
```
```   100 lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
```
```   101 unfolding Grp_def by auto
```
```   102
```
```   103 lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
```
```   104 unfolding Grp_def by auto
```
```   105
```
```   106 lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
```
```   107 unfolding Grp_def by auto
```
```   108
```
```   109 lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
```
```   110 unfolding Grp_def by auto
```
```   111
```
```   112 lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
```
```   113 unfolding Grp_def by auto
```
```   114
```
```   115 lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
```
```   116 unfolding Grp_def o_def by auto
```
```   117
```
```   118 lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
```
```   119 unfolding Grp_def o_def by auto
```
```   120
```
```   121 lemma wpull_Grp:
```
```   122 "wpull (Collect (split (Grp A f))) A (f ` A) f id fst snd"
```
```   123 unfolding wpull_def Grp_def by auto
```
```   124
```
```   125 definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
```
```   126
```
```   127 lemma pick_middlep:
```
```   128 "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
```
```   129 unfolding pick_middlep_def apply(rule someI_ex) by auto
```
```   130
```
```   131 definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
```
```   132 definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
```
```   133
```
```   134 lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
```
```   135 unfolding fstOp_def mem_Collect_eq
```
```   136 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
```
```   137
```
```   138 lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
```
```   139 unfolding comp_def fstOp_def by simp
```
```   140
```
```   141 lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
```
```   142 unfolding comp_def sndOp_def by simp
```
```   143
```
```   144 lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
```
```   145 unfolding sndOp_def mem_Collect_eq
```
```   146 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
```
```   147
```
```   148 lemma csquare_fstOp_sndOp:
```
```   149 "csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
```
```   150 unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
```
```   151
```
```   152 lemma wppull_fstOp_sndOp:
```
```   153 shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q))
```
```   154   snd fst fst snd (fstOp P Q) (sndOp P Q)"
```
```   155 using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
```
```   156
```
```   157 lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
```
```   158 by (simp split: prod.split)
```
```   159
```
```   160 lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
```
```   161 by (simp split: prod.split)
```
```   162
```
```   163 lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
```
```   164 by auto
```
```   165
```
```   166 lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
```
```   167   by auto
```
```   168
```
```   169 lemma Collect_split_mono_strong:
```
```   170   "\<lbrakk>\<forall>a\<in>fst ` A. \<forall>b \<in> snd ` A. P a b \<longrightarrow> Q a b; A \<subseteq> Collect (split P)\<rbrakk> \<Longrightarrow>
```
```   171   A \<subseteq> Collect (split Q)"
```
```   172   by fastforce
```
```   173
```
```   174 lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
```
```   175 by metis
```
```   176
```
```   177 lemma sum_case_o_inj:
```
```   178 "sum_case f g \<circ> Inl = f"
```
```   179 "sum_case f g \<circ> Inr = g"
```
```   180 by auto
```
```   181
```
```   182 lemma card_order_csum_cone_cexp_def:
```
```   183   "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
```
```   184   unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
```
```   185
```
```   186 lemma If_the_inv_into_in_Func:
```
```   187   "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
```
```   188   (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
```
```   189 unfolding Func_def by (auto dest: the_inv_into_into)
```
```   190
```
```   191 lemma If_the_inv_into_f_f:
```
```   192   "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow>
```
```   193   ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) o g) i = id i"
```
```   194 unfolding Func_def by (auto elim: the_inv_into_f_f)
```
```   195
```
```   196 definition vimage2p where
```
```   197   "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
```
```   198
```
```   199 lemma vimage2pI: "R (f x) (g y) \<Longrightarrow> vimage2p f g R x y"
```
```   200   unfolding vimage2p_def by -
```
```   201
```
```   202 lemma vimage2pD: "vimage2p f g R x y \<Longrightarrow> R (f x) (g y)"
```
```   203   unfolding vimage2p_def by -
```
```   204
```
```   205 lemma fun_rel_iff_leq_vimage2p: "(fun_rel R S) f g = (R \<le> vimage2p f g S)"
```
```   206   unfolding fun_rel_def vimage2p_def by auto
```
```   207
```
```   208 lemma convol_image_vimage2p: "<f o fst, g o snd> ` Collect (split (vimage2p f g R)) \<subseteq> Collect (split R)"
```
```   209   unfolding vimage2p_def convol_def by auto
```
```   210
```
```   211 ML_file "Tools/bnf_def_tactics.ML"
```
```   212 ML_file "Tools/bnf_def.ML"
```
```   213
```
```   214
```
```   215 end
```