src/HOL/Codatatype/BNF_Def.thy
author traytel
Fri, 21 Sep 2012 12:27:56 +0200
changeset 50510 675b9df572df
parent 50340 340844cbf7af
child 50524 163914705f8d
permissions -rw-r--r--
rel_Gr does not depend on map_wpull
blanchet@49990
     1
(*  Title:      HOL/Codatatype/BNF_Def.thy
blanchet@49990
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@49990
     3
    Copyright   2012
blanchet@49990
     4
blanchet@49990
     5
Definition of bounded natural functors.
blanchet@49990
     6
*)
blanchet@49990
     7
blanchet@49990
     8
header {* Definition of Bounded Natural Functors *}
blanchet@49990
     9
blanchet@49990
    10
theory BNF_Def
blanchet@50297
    11
imports BNF_Util
blanchet@49990
    12
keywords
blanchet@50301
    13
  "print_bnfs" :: diag and
blanchet@49990
    14
  "bnf_def" :: thy_goal
blanchet@49990
    15
begin
blanchet@49990
    16
blanchet@50327
    17
lemma collect_o: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
blanchet@50327
    18
by (rule ext) (auto simp only: o_apply collect_def)
blanchet@50327
    19
blanchet@50327
    20
lemma converse_mono:
blanchet@50327
    21
"R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
blanchet@50327
    22
unfolding converse_def by auto
blanchet@50327
    23
blanchet@50327
    24
lemma converse_shift:
blanchet@50327
    25
"R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
blanchet@50327
    26
unfolding converse_def by auto
blanchet@50327
    27
traytel@50510
    28
definition convol ("<_ , _>") where
traytel@50510
    29
"<f , g> \<equiv> %a. (f a, g a)"
traytel@50510
    30
traytel@50510
    31
lemma fst_convol:
traytel@50510
    32
"fst o <f , g> = f"
traytel@50510
    33
apply(rule ext)
traytel@50510
    34
unfolding convol_def by simp
traytel@50510
    35
traytel@50510
    36
lemma snd_convol:
traytel@50510
    37
"snd o <f , g> = g"
traytel@50510
    38
apply(rule ext)
traytel@50510
    39
unfolding convol_def by simp
traytel@50510
    40
traytel@50510
    41
lemma convol_memI:
traytel@50510
    42
"\<lbrakk>f x = f' x; g x = g' x; P x\<rbrakk> \<Longrightarrow> <f , g> x \<in> {(f' a, g' a) |a. P a}"
traytel@50510
    43
unfolding convol_def by auto
traytel@50510
    44
blanchet@50327
    45
definition csquare where
blanchet@50327
    46
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
blanchet@50327
    47
blanchet@50327
    48
(* The pullback of sets *)
blanchet@50327
    49
definition thePull where
blanchet@50327
    50
"thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
blanchet@50327
    51
blanchet@50327
    52
lemma wpull_thePull:
blanchet@50327
    53
"wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
blanchet@50327
    54
unfolding wpull_def thePull_def by auto
blanchet@50327
    55
blanchet@50327
    56
lemma wppull_thePull:
blanchet@50327
    57
assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@50327
    58
shows
blanchet@50327
    59
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
blanchet@50327
    60
   j a' \<in> A \<and>
blanchet@50327
    61
   e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
blanchet@50327
    62
(is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
blanchet@50327
    63
proof(rule bchoice[of ?A' ?phi], default)
blanchet@50327
    64
  fix a' assume a': "a' \<in> ?A'"
blanchet@50327
    65
  hence "fst a' \<in> B1" unfolding thePull_def by auto
blanchet@50327
    66
  moreover
blanchet@50327
    67
  from a' have "snd a' \<in> B2" unfolding thePull_def by auto
blanchet@50327
    68
  moreover have "f1 (fst a') = f2 (snd a')"
blanchet@50327
    69
  using a' unfolding csquare_def thePull_def by auto
blanchet@50327
    70
  ultimately show "\<exists> ja'. ?phi a' ja'"
blanchet@50340
    71
  using assms unfolding wppull_def by blast
blanchet@50327
    72
qed
blanchet@50327
    73
blanchet@50327
    74
lemma wpull_wppull:
blanchet@50327
    75
assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
blanchet@50327
    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')"
blanchet@50327
    77
shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@50327
    78
unfolding wppull_def proof safe
blanchet@50327
    79
  fix b1 b2
blanchet@50327
    80
  assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
blanchet@50327
    81
  then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
blanchet@50327
    82
  using wp unfolding wpull_def by blast
blanchet@50327
    83
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
blanchet@50340
    84
  apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
blanchet@50327
    85
qed
blanchet@50327
    86
blanchet@50327
    87
lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
blanchet@50327
    88
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
blanchet@50327
    89
by (erule wpull_wppull) auto
blanchet@50327
    90
blanchet@50327
    91
lemma Id_alt: "Id = Gr UNIV id"
blanchet@50327
    92
unfolding Gr_def by auto
blanchet@50327
    93
blanchet@50327
    94
lemma Gr_UNIV_id: "f = id \<Longrightarrow> (Gr UNIV f)^-1 O Gr UNIV f = Gr UNIV f"
blanchet@50327
    95
unfolding Gr_def by auto
blanchet@50327
    96
blanchet@50327
    97
lemma Gr_mono: "A \<subseteq> B \<Longrightarrow> Gr A f \<subseteq> Gr B f"
blanchet@50327
    98
unfolding Gr_def by auto
blanchet@50327
    99
blanchet@50327
   100
lemma wpull_Gr:
blanchet@50327
   101
"wpull (Gr A f) A (f ` A) f id fst snd"
blanchet@50327
   102
unfolding wpull_def Gr_def by auto
blanchet@50327
   103
blanchet@50327
   104
definition "pick_middle P Q a c = (SOME b. (a,b) \<in> P \<and> (b,c) \<in> Q)"
blanchet@50327
   105
blanchet@50327
   106
lemma pick_middle:
blanchet@50340
   107
"(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"
blanchet@50327
   108
unfolding pick_middle_def apply(rule someI_ex)
blanchet@50327
   109
using assms unfolding relcomp_def by auto
blanchet@50327
   110
blanchet@50327
   111
definition fstO where "fstO P Q ac = (fst ac, pick_middle P Q (fst ac) (snd ac))"
blanchet@50327
   112
definition sndO where "sndO P Q ac = (pick_middle P Q (fst ac) (snd ac), snd ac)"
blanchet@50327
   113
blanchet@50327
   114
lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
blanchet@50340
   115
unfolding fstO_def
blanchet@50340
   116
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct1])
blanchet@50327
   117
blanchet@50327
   118
lemma fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
blanchet@50327
   119
unfolding comp_def fstO_def by simp
blanchet@50327
   120
blanchet@50327
   121
lemma snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
blanchet@50327
   122
unfolding comp_def sndO_def by simp
blanchet@50327
   123
blanchet@50327
   124
lemma sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
blanchet@50340
   125
unfolding sndO_def
blanchet@50340
   126
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct2])
blanchet@50327
   127
blanchet@50327
   128
lemma csquare_fstO_sndO:
blanchet@50327
   129
"csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
blanchet@50340
   130
unfolding csquare_def fstO_def sndO_def using pick_middle by simp
blanchet@50327
   131
blanchet@50327
   132
lemma wppull_fstO_sndO:
blanchet@50327
   133
shows "wppull (P O Q) P Q snd fst fst snd (fstO P Q) (sndO P Q)"
blanchet@50327
   134
using pick_middle unfolding wppull_def fstO_def sndO_def relcomp_def by auto
blanchet@50327
   135
blanchet@50327
   136
lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
blanchet@50327
   137
by (simp split: prod.split)
blanchet@50327
   138
blanchet@50327
   139
lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
blanchet@50327
   140
by (simp split: prod.split)
blanchet@50327
   141
blanchet@50327
   142
lemma flip_rel: "A \<subseteq> (R ^-1) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> R"
blanchet@50327
   143
by auto
blanchet@50327
   144
blanchet@50327
   145
lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
blanchet@50327
   146
unfolding o_def fun_eq_iff by simp
blanchet@50327
   147
blanchet@50324
   148
ML_file "Tools/bnf_def_tactics.ML"
blanchet@50324
   149
ML_file"Tools/bnf_def.ML"
blanchet@50324
   150
blanchet@49990
   151
end