src/HOL/BNF/BNF_Def.thy
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
blanchet@49509
     1
(*  Title:      HOL/BNF/BNF_Def.thy
blanchet@48975
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@48975
     3
    Copyright   2012
blanchet@48975
     4
blanchet@48975
     5
Definition of bounded natural functors.
blanchet@48975
     6
*)
blanchet@48975
     7
blanchet@48975
     8
header {* Definition of Bounded Natural Functors *}
blanchet@48975
     9
blanchet@48975
    10
theory BNF_Def
blanchet@49282
    11
imports BNF_Util
blanchet@48975
    12
keywords
blanchet@49286
    13
  "print_bnfs" :: diag and
blanchet@51836
    14
  "bnf" :: thy_goal
blanchet@48975
    15
begin
blanchet@48975
    16
blanchet@49312
    17
lemma collect_o: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
blanchet@49312
    18
by (rule ext) (auto simp only: o_apply collect_def)
blanchet@49312
    19
blanchet@49312
    20
lemma converse_mono:
blanchet@49312
    21
"R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
blanchet@49312
    22
unfolding converse_def by auto
blanchet@49312
    23
traytel@51893
    24
lemma conversep_mono:
traytel@51893
    25
"R1 ^--1 \<le> R2 ^--1 \<longleftrightarrow> R1 \<le> R2"
traytel@51893
    26
unfolding conversep.simps by auto
traytel@51893
    27
blanchet@49312
    28
lemma converse_shift:
blanchet@49312
    29
"R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
blanchet@49312
    30
unfolding converse_def by auto
blanchet@49312
    31
traytel@51893
    32
lemma conversep_shift:
traytel@51893
    33
"R1 \<le> R2 ^--1 \<Longrightarrow> R1 ^--1 \<le> R2"
traytel@51893
    34
unfolding conversep.simps by auto
traytel@51893
    35
traytel@49495
    36
definition convol ("<_ , _>") where
traytel@49495
    37
"<f , g> \<equiv> %a. (f a, g a)"
traytel@49495
    38
traytel@49495
    39
lemma fst_convol:
traytel@49495
    40
"fst o <f , g> = f"
traytel@49495
    41
apply(rule ext)
traytel@49495
    42
unfolding convol_def by simp
traytel@49495
    43
traytel@49495
    44
lemma snd_convol:
traytel@49495
    45
"snd o <f , g> = g"
traytel@49495
    46
apply(rule ext)
traytel@49495
    47
unfolding convol_def by simp
traytel@49495
    48
traytel@49495
    49
lemma convol_memI:
traytel@49495
    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}"
traytel@49495
    51
unfolding convol_def by auto
traytel@49495
    52
traytel@51893
    53
lemma convol_mem_GrpI:
traytel@51893
    54
"\<lbrakk>g x = g' x; x \<in> A\<rbrakk> \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
traytel@51893
    55
unfolding convol_def Grp_def by auto
traytel@51893
    56
blanchet@49312
    57
definition csquare where
blanchet@49312
    58
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
blanchet@49312
    59
blanchet@49312
    60
(* The pullback of sets *)
blanchet@49312
    61
definition thePull where
blanchet@49312
    62
"thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
blanchet@49312
    63
blanchet@49312
    64
lemma wpull_thePull:
blanchet@49312
    65
"wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
blanchet@49312
    66
unfolding wpull_def thePull_def by auto
blanchet@49312
    67
blanchet@49312
    68
lemma wppull_thePull:
blanchet@49312
    69
assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@49312
    70
shows
blanchet@49312
    71
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
blanchet@49312
    72
   j a' \<in> A \<and>
blanchet@49312
    73
   e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
blanchet@49312
    74
(is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
blanchet@49312
    75
proof(rule bchoice[of ?A' ?phi], default)
blanchet@49312
    76
  fix a' assume a': "a' \<in> ?A'"
blanchet@49312
    77
  hence "fst a' \<in> B1" unfolding thePull_def by auto
blanchet@49312
    78
  moreover
blanchet@49312
    79
  from a' have "snd a' \<in> B2" unfolding thePull_def by auto
blanchet@49312
    80
  moreover have "f1 (fst a') = f2 (snd a')"
blanchet@49312
    81
  using a' unfolding csquare_def thePull_def by auto
blanchet@49312
    82
  ultimately show "\<exists> ja'. ?phi a' ja'"
blanchet@49325
    83
  using assms unfolding wppull_def by blast
blanchet@49312
    84
qed
blanchet@49312
    85
blanchet@49312
    86
lemma wpull_wppull:
blanchet@49312
    87
assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
blanchet@49312
    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')"
blanchet@49312
    89
shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@49312
    90
unfolding wppull_def proof safe
blanchet@49312
    91
  fix b1 b2
blanchet@49312
    92
  assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
blanchet@49312
    93
  then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
blanchet@49312
    94
  using wp unfolding wpull_def by blast
blanchet@49312
    95
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
blanchet@49325
    96
  apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
blanchet@49312
    97
qed
blanchet@49312
    98
blanchet@49312
    99
lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
blanchet@49312
   100
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
blanchet@49312
   101
by (erule wpull_wppull) auto
blanchet@49312
   102
blanchet@49312
   103
lemma Id_alt: "Id = Gr UNIV id"
blanchet@49312
   104
unfolding Gr_def by auto
blanchet@49312
   105
traytel@51893
   106
lemma eq_alt: "op = = Grp UNIV id"
traytel@51893
   107
unfolding Grp_def by auto
traytel@51893
   108
traytel@51893
   109
lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
traytel@51893
   110
  by auto
traytel@51893
   111
traytel@51893
   112
lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
traytel@51893
   113
  by auto
traytel@51893
   114
blanchet@49312
   115
lemma Gr_UNIV_id: "f = id \<Longrightarrow> (Gr UNIV f)^-1 O Gr UNIV f = Gr UNIV f"
blanchet@49312
   116
unfolding Gr_def by auto
blanchet@49312
   117
traytel@51893
   118
lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
traytel@51893
   119
unfolding Grp_def by auto
traytel@51893
   120
traytel@51893
   121
lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
traytel@51893
   122
unfolding Grp_def by auto
traytel@51893
   123
blanchet@49312
   124
lemma Gr_mono: "A \<subseteq> B \<Longrightarrow> Gr A f \<subseteq> Gr B f"
blanchet@49312
   125
unfolding Gr_def by auto
blanchet@49312
   126
traytel@51893
   127
lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
traytel@51893
   128
unfolding Grp_def by auto
traytel@51893
   129
traytel@51893
   130
lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
traytel@51893
   131
unfolding Grp_def by auto
traytel@51893
   132
traytel@51893
   133
lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
traytel@51893
   134
unfolding Grp_def by auto
traytel@51893
   135
traytel@51893
   136
lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
traytel@51893
   137
unfolding Grp_def o_def by auto
traytel@51893
   138
traytel@51893
   139
lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
traytel@51893
   140
unfolding Grp_def o_def by auto
traytel@51893
   141
blanchet@49312
   142
lemma wpull_Gr:
blanchet@49312
   143
"wpull (Gr A f) A (f ` A) f id fst snd"
blanchet@49312
   144
unfolding wpull_def Gr_def by auto
blanchet@49312
   145
traytel@51893
   146
lemma wpull_Grp:
traytel@51893
   147
"wpull (Collect (split (Grp A f))) A (f ` A) f id fst snd"
traytel@51893
   148
unfolding wpull_def Grp_def by auto
traytel@51893
   149
blanchet@49312
   150
definition "pick_middle P Q a c = (SOME b. (a,b) \<in> P \<and> (b,c) \<in> Q)"
blanchet@49312
   151
traytel@51893
   152
definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
traytel@51893
   153
blanchet@49312
   154
lemma pick_middle:
blanchet@49325
   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"
traytel@51893
   156
unfolding pick_middle_def apply(rule someI_ex) by auto
traytel@51893
   157
traytel@51893
   158
lemma pick_middlep:
traytel@51893
   159
"(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
traytel@51893
   160
unfolding pick_middlep_def apply(rule someI_ex) by auto
blanchet@49312
   161
blanchet@49312
   162
definition fstO where "fstO P Q ac = (fst ac, pick_middle P Q (fst ac) (snd ac))"
blanchet@49312
   163
definition sndO where "sndO P Q ac = (pick_middle P Q (fst ac) (snd ac), snd ac)"
blanchet@49312
   164
traytel@51893
   165
definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
traytel@51893
   166
definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
traytel@51893
   167
blanchet@49312
   168
lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
traytel@51893
   169
unfolding fstO_def by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct1])
traytel@51893
   170
traytel@51893
   171
lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
traytel@51893
   172
unfolding fstOp_def mem_Collect_eq
traytel@51893
   173
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
blanchet@49312
   174
blanchet@49312
   175
lemma fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
blanchet@49312
   176
unfolding comp_def fstO_def by simp
blanchet@49312
   177
traytel@51893
   178
lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
traytel@51893
   179
unfolding comp_def fstOp_def by simp
traytel@51893
   180
blanchet@49312
   181
lemma snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
blanchet@49312
   182
unfolding comp_def sndO_def by simp
blanchet@49312
   183
traytel@51893
   184
lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
traytel@51893
   185
unfolding comp_def sndOp_def by simp
traytel@51893
   186
blanchet@49312
   187
lemma sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
blanchet@49325
   188
unfolding sndO_def
blanchet@49325
   189
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct2])
blanchet@49312
   190
traytel@51893
   191
lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
traytel@51893
   192
unfolding sndOp_def mem_Collect_eq
traytel@51893
   193
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
traytel@51893
   194
blanchet@49312
   195
lemma csquare_fstO_sndO:
blanchet@49312
   196
"csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
blanchet@49325
   197
unfolding csquare_def fstO_def sndO_def using pick_middle by simp
blanchet@49312
   198
traytel@51893
   199
lemma csquare_fstOp_sndOp:
traytel@51893
   200
"csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
traytel@51893
   201
unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
traytel@51893
   202
blanchet@49312
   203
lemma wppull_fstO_sndO:
blanchet@49312
   204
shows "wppull (P O Q) P Q snd fst fst snd (fstO P Q) (sndO P Q)"
blanchet@49312
   205
using pick_middle unfolding wppull_def fstO_def sndO_def relcomp_def by auto
blanchet@49312
   206
traytel@51893
   207
lemma wppull_fstOp_sndOp:
traytel@51893
   208
shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q)) snd fst fst snd (fstOp P Q) (sndOp P Q)"
traytel@51893
   209
using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
traytel@51893
   210
blanchet@49312
   211
lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
blanchet@49312
   212
by (simp split: prod.split)
blanchet@49312
   213
blanchet@49312
   214
lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
blanchet@49312
   215
by (simp split: prod.split)
blanchet@49312
   216
blanchet@49312
   217
lemma flip_rel: "A \<subseteq> (R ^-1) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> R"
blanchet@49312
   218
by auto
blanchet@49312
   219
traytel@51893
   220
lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
traytel@51893
   221
by auto
traytel@51893
   222
blanchet@49312
   223
lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
blanchet@49312
   224
unfolding o_def fun_eq_iff by simp
blanchet@49312
   225
traytel@51893
   226
lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
traytel@51893
   227
  by auto
traytel@51893
   228
traytel@51893
   229
lemma predicate2_cong: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
traytel@51893
   230
by metis
blanchet@49537
   231
blanchet@49537
   232
lemma fun_cong_pair: "f = g \<Longrightarrow> f {(a, b). R a b} = g {(a, b). R a b}"
blanchet@49537
   233
by (rule fun_cong)
blanchet@49537
   234
blanchet@49537
   235
lemma flip_as_converse: "{(a, b). R b a} = converse {(a, b). R a b}"
blanchet@49537
   236
unfolding converse_def mem_Collect_eq prod.cases
blanchet@49537
   237
apply (rule arg_cong[of _ _ "\<lambda>x. Collect (prod_case x)"])
blanchet@49537
   238
apply (rule ext)+
blanchet@49537
   239
apply (unfold conversep_iff)
blanchet@49537
   240
by (rule refl)
blanchet@49537
   241
blanchet@49309
   242
ML_file "Tools/bnf_def_tactics.ML"
blanchet@49537
   243
ML_file "Tools/bnf_def.ML"
blanchet@49309
   244
traytel@51893
   245
blanchet@48975
   246
end