author traytel
Tue May 07 14:22:54 2013 +0200 (2013-05-07)
changeset 51893 596baae88a88
parent 51836 4d6dcd51dd52
child 51909 eb3169abcbd5
permissions -rw-r--r--
got rid of the set based relator---use (binary) predicate based relator instead
     1 (*  Title:      HOL/BNF/BNF_Def.thy
     2     Author:     Dmitriy Traytel, TU Muenchen
     3     Copyright   2012
     5 Definition of bounded natural functors.
     6 *)
     8 header {* Definition of Bounded Natural Functors *}
    10 theory BNF_Def
    11 imports BNF_Util
    12 keywords
    13   "print_bnfs" :: diag and
    14   "bnf" :: thy_goal
    15 begin
    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)
    20 lemma converse_mono:
    21 "R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
    22 unfolding converse_def by auto
    24 lemma conversep_mono:
    25 "R1 ^--1 \<le> R2 ^--1 \<longleftrightarrow> R1 \<le> R2"
    26 unfolding conversep.simps by auto
    28 lemma converse_shift:
    29 "R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
    30 unfolding converse_def by auto
    32 lemma conversep_shift:
    33 "R1 \<le> R2 ^--1 \<Longrightarrow> R1 ^--1 \<le> R2"
    34 unfolding conversep.simps by auto
    36 definition convol ("<_ , _>") where
    37 "<f , g> \<equiv> %a. (f a, g a)"
    39 lemma fst_convol:
    40 "fst o <f , g> = f"
    41 apply(rule ext)
    42 unfolding convol_def by simp
    44 lemma snd_convol:
    45 "snd o <f , g> = g"
    46 apply(rule ext)
    47 unfolding convol_def by simp
    49 lemma convol_memI:
    50 "\<lbrakk>f x = f' x; g x = g' x; P x\<rbrakk> \<Longrightarrow> <f , g> x \<in> {(f' a, g' a) |a. P a}"
    51 unfolding convol_def by auto
    53 lemma convol_mem_GrpI:
    54 "\<lbrakk>g x = g' x; x \<in> A\<rbrakk> \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
    55 unfolding convol_def Grp_def by auto
    57 definition csquare where
    58 "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
    60 (* The pullback of sets *)
    61 definition thePull where
    62 "thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
    64 lemma wpull_thePull:
    65 "wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
    66 unfolding wpull_def thePull_def by auto
    68 lemma wppull_thePull:
    69 assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
    70 shows
    71 "\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
    72    j a' \<in> A \<and>
    73    e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
    74 (is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
    75 proof(rule bchoice[of ?A' ?phi], default)
    76   fix a' assume a': "a' \<in> ?A'"
    77   hence "fst a' \<in> B1" unfolding thePull_def by auto
    78   moreover
    79   from a' have "snd a' \<in> B2" unfolding thePull_def by auto
    80   moreover have "f1 (fst a') = f2 (snd a')"
    81   using a' unfolding csquare_def thePull_def by auto
    82   ultimately show "\<exists> ja'. ?phi a' ja'"
    83   using assms unfolding wppull_def by blast
    84 qed
    86 lemma wpull_wppull:
    87 assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
    88 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')"
    89 shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
    90 unfolding wppull_def proof safe
    91   fix b1 b2
    92   assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
    93   then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
    94   using wp unfolding wpull_def by blast
    95   show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
    96   apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
    97 qed
    99 lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
   100    wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
   101 by (erule wpull_wppull) auto
   103 lemma Id_alt: "Id = Gr UNIV id"
   104 unfolding Gr_def by auto
   106 lemma eq_alt: "op = = Grp UNIV id"
   107 unfolding Grp_def by auto
   109 lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
   110   by auto
   112 lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
   113   by auto
   115 lemma Gr_UNIV_id: "f = id \<Longrightarrow> (Gr UNIV f)^-1 O Gr UNIV f = Gr UNIV f"
   116 unfolding Gr_def by auto
   118 lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
   119 unfolding Grp_def by auto
   121 lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
   122 unfolding Grp_def by auto
   124 lemma Gr_mono: "A \<subseteq> B \<Longrightarrow> Gr A f \<subseteq> Gr B f"
   125 unfolding Gr_def by auto
   127 lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
   128 unfolding Grp_def by auto
   130 lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
   131 unfolding Grp_def by auto
   133 lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
   134 unfolding Grp_def by auto
   136 lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
   137 unfolding Grp_def o_def by auto
   139 lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
   140 unfolding Grp_def o_def by auto
   142 lemma wpull_Gr:
   143 "wpull (Gr A f) A (f ` A) f id fst snd"
   144 unfolding wpull_def Gr_def by auto
   146 lemma wpull_Grp:
   147 "wpull (Collect (split (Grp A f))) A (f ` A) f id fst snd"
   148 unfolding wpull_def Grp_def by auto
   150 definition "pick_middle P Q a c = (SOME b. (a,b) \<in> P \<and> (b,c) \<in> Q)"
   152 definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
   154 lemma pick_middle:
   155 "(a,c) \<in> P O Q \<Longrightarrow> (a, pick_middle P Q a c) \<in> P \<and> (pick_middle P Q a c, c) \<in> Q"
   156 unfolding pick_middle_def apply(rule someI_ex) by auto
   158 lemma pick_middlep:
   159 "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
   160 unfolding pick_middlep_def apply(rule someI_ex) by auto
   162 definition fstO where "fstO P Q ac = (fst ac, pick_middle P Q (fst ac) (snd ac))"
   163 definition sndO where "sndO P Q ac = (pick_middle P Q (fst ac) (snd ac), snd ac)"
   165 definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
   166 definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
   168 lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
   169 unfolding fstO_def by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct1])
   171 lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
   172 unfolding fstOp_def mem_Collect_eq
   173 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
   175 lemma fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
   176 unfolding comp_def fstO_def by simp
   178 lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
   179 unfolding comp_def fstOp_def by simp
   181 lemma snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
   182 unfolding comp_def sndO_def by simp
   184 lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
   185 unfolding comp_def sndOp_def by simp
   187 lemma sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
   188 unfolding sndO_def
   189 by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct2])
   191 lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
   192 unfolding sndOp_def mem_Collect_eq
   193 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
   195 lemma csquare_fstO_sndO:
   196 "csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
   197 unfolding csquare_def fstO_def sndO_def using pick_middle by simp
   199 lemma csquare_fstOp_sndOp:
   200 "csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
   201 unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
   203 lemma wppull_fstO_sndO:
   204 shows "wppull (P O Q) P Q snd fst fst snd (fstO P Q) (sndO P Q)"
   205 using pick_middle unfolding wppull_def fstO_def sndO_def relcomp_def by auto
   207 lemma wppull_fstOp_sndOp:
   208 shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q)) snd fst fst snd (fstOp P Q) (sndOp P Q)"
   209 using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
   211 lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
   212 by (simp split: prod.split)
   214 lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
   215 by (simp split: prod.split)
   217 lemma flip_rel: "A \<subseteq> (R ^-1) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> R"
   218 by auto
   220 lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
   221 by auto
   223 lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
   224 unfolding o_def fun_eq_iff by simp
   226 lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
   227   by auto
   229 lemma predicate2_cong: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
   230 by metis
   232 lemma fun_cong_pair: "f = g \<Longrightarrow> f {(a, b). R a b} = g {(a, b). R a b}"
   233 by (rule fun_cong)
   235 lemma flip_as_converse: "{(a, b). R b a} = converse {(a, b). R a b}"
   236 unfolding converse_def mem_Collect_eq prod.cases
   237 apply (rule arg_cong[of _ _ "\<lambda>x. Collect (prod_case x)"])
   238 apply (rule ext)+
   239 apply (unfold conversep_iff)
   240 by (rule refl)
   242 ML_file "Tools/bnf_def_tactics.ML"
   243 ML_file "Tools/bnf_def.ML"
   246 end