src/HOL/BNF/BNF_Def.thy
 author traytel Tue May 07 18:40:23 2013 +0200 (2013-05-07) changeset 51909 eb3169abcbd5 parent 51893 596baae88a88 child 51916 eac9e9a45bf5 permissions -rw-r--r--
```     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_mono:
```
```    21 "R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
```
```    22 unfolding converse_def by auto
```
```    23
```
```    24 lemma conversep_mono:
```
```    25 "R1 ^--1 \<le> R2 ^--1 \<longleftrightarrow> R1 \<le> R2"
```
```    26 unfolding conversep.simps by auto
```
```    27
```
```    28 lemma converse_shift:
```
```    29 "R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
```
```    30 unfolding converse_def by auto
```
```    31
```
```    32 lemma conversep_shift:
```
```    33 "R1 \<le> R2 ^--1 \<Longrightarrow> R1 ^--1 \<le> R2"
```
```    34 unfolding conversep.simps by auto
```
```    35
```
```    36 definition convol ("<_ , _>") where
```
```    37 "<f , g> \<equiv> %a. (f a, g a)"
```
```    38
```
```    39 lemma fst_convol:
```
```    40 "fst o <f , g> = f"
```
```    41 apply(rule ext)
```
```    42 unfolding convol_def by simp
```
```    43
```
```    44 lemma snd_convol:
```
```    45 "snd o <f , g> = g"
```
```    46 apply(rule ext)
```
```    47 unfolding convol_def by simp
```
```    48
```
```    49 lemma convol_mem_GrpI:
```
```    50 "\<lbrakk>g x = g' x; x \<in> A\<rbrakk> \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
```
```    51 unfolding convol_def Grp_def by auto
```
```    52
```
```    53 definition csquare where
```
```    54 "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
```
```    55
```
```    56 (* The pullback of sets *)
```
```    57 definition thePull where
```
```    58 "thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
```
```    59
```
```    60 lemma wpull_thePull:
```
```    61 "wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
```
```    62 unfolding wpull_def thePull_def by auto
```
```    63
```
```    64 lemma wppull_thePull:
```
```    65 assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
```
```    66 shows
```
```    67 "\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
```
```    68    j a' \<in> A \<and>
```
```    69    e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
```
```    70 (is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
```
```    71 proof(rule bchoice[of ?A' ?phi], default)
```
```    72   fix a' assume a': "a' \<in> ?A'"
```
```    73   hence "fst a' \<in> B1" unfolding thePull_def by auto
```
```    74   moreover
```
```    75   from a' have "snd a' \<in> B2" unfolding thePull_def by auto
```
```    76   moreover have "f1 (fst a') = f2 (snd a')"
```
```    77   using a' unfolding csquare_def thePull_def by auto
```
```    78   ultimately show "\<exists> ja'. ?phi a' ja'"
```
```    79   using assms unfolding wppull_def by blast
```
```    80 qed
```
```    81
```
```    82 lemma wpull_wppull:
```
```    83 assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
```
```    84 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')"
```
```    85 shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
```
```    86 unfolding wppull_def proof safe
```
```    87   fix b1 b2
```
```    88   assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
```
```    89   then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
```
```    90   using wp unfolding wpull_def by blast
```
```    91   show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
```
```    92   apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
```
```    93 qed
```
```    94
```
```    95 lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
```
```    96    wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
```
```    97 by (erule wpull_wppull) auto
```
```    98
```
```    99 lemma eq_alt: "op = = Grp UNIV id"
```
```   100 unfolding Grp_def by auto
```
```   101
```
```   102 lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
```
```   103   by auto
```
```   104
```
```   105 lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
```
```   106   by auto
```
```   107
```
```   108 lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
```
```   109 unfolding Grp_def by auto
```
```   110
```
```   111 lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
```
```   112 unfolding Grp_def by auto
```
```   113
```
```   114 lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
```
```   115 unfolding Grp_def by auto
```
```   116
```
```   117 lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
```
```   118 unfolding Grp_def by auto
```
```   119
```
```   120 lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
```
```   121 unfolding Grp_def by auto
```
```   122
```
```   123 lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
```
```   124 unfolding Grp_def o_def by auto
```
```   125
```
```   126 lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
```
```   127 unfolding Grp_def o_def by auto
```
```   128
```
```   129 lemma wpull_Grp:
```
```   130 "wpull (Collect (split (Grp A f))) A (f ` A) f id fst snd"
```
```   131 unfolding wpull_def Grp_def by auto
```
```   132
```
```   133 definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
```
```   134
```
```   135 lemma pick_middlep:
```
```   136 "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
```
```   137 unfolding pick_middlep_def apply(rule someI_ex) by auto
```
```   138
```
```   139 definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
```
```   140 definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
```
```   141
```
```   142 lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
```
```   143 unfolding fstOp_def mem_Collect_eq
```
```   144 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
```
```   145
```
```   146 lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
```
```   147 unfolding comp_def fstOp_def by simp
```
```   148
```
```   149 lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
```
```   150 unfolding comp_def sndOp_def by simp
```
```   151
```
```   152 lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
```
```   153 unfolding sndOp_def mem_Collect_eq
```
```   154 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
```
```   155
```
```   156 lemma csquare_fstOp_sndOp:
```
```   157 "csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
```
```   158 unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
```
```   159
```
```   160 lemma wppull_fstOp_sndOp:
```
```   161 shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q))
```
```   162   snd fst fst snd (fstOp P Q) (sndOp P Q)"
```
```   163 using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
```
```   164
```
```   165 lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
```
```   166 by (simp split: prod.split)
```
```   167
```
```   168 lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
```
```   169 by (simp split: prod.split)
```
```   170
```
```   171 lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
```
```   172 by auto
```
```   173
```
```   174 lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
```
```   175 unfolding o_def fun_eq_iff by simp
```
```   176
```
```   177 lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
```
```   178   by auto
```
```   179
```
```   180 lemma predicate2_cong: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
```
```   181 by metis
```
```   182
```
```   183 lemma fun_cong_pair: "f = g \<Longrightarrow> f {(a, b). R a b} = g {(a, b). R a b}"
```
```   184 by (rule fun_cong)
```
```   185
```
```   186 lemma flip_as_converse: "{(a, b). R b a} = converse {(a, b). R a b}"
```
```   187 unfolding converse_def mem_Collect_eq prod.cases
```
```   188 apply (rule arg_cong[of _ _ "\<lambda>x. Collect (prod_case x)"])
```
```   189 apply (rule ext)+
```
```   190 apply (unfold conversep_iff)
```
```   191 by (rule refl)
```
```   192
```
```   193 ML_file "Tools/bnf_def_tactics.ML"
```
```   194 ML_file "Tools/bnf_def.ML"
```
```   195
```
```   196
```
```   197 end
```