src/HOL/BNF/BNF_Def.thy
author hoelzl
Tue Nov 05 09:44:57 2013 +0100 (2013-11-05)
changeset 54257 5c7a3b6b05a9
parent 53561 92bcac4f9ac9
child 54421 632be352a5a3
permissions -rw-r--r--
generalize SUP and INF to the syntactic type classes Sup and Inf
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)"
traytel@52749
    18
  by (rule ext) (auto simp only: o_apply collect_def)
traytel@51893
    19
traytel@49495
    20
definition convol ("<_ , _>") where
traytel@49495
    21
"<f , g> \<equiv> %a. (f a, g a)"
traytel@49495
    22
traytel@49495
    23
lemma fst_convol:
traytel@49495
    24
"fst o <f , g> = f"
traytel@49495
    25
apply(rule ext)
traytel@49495
    26
unfolding convol_def by simp
traytel@49495
    27
traytel@49495
    28
lemma snd_convol:
traytel@49495
    29
"snd o <f , g> = g"
traytel@49495
    30
apply(rule ext)
traytel@49495
    31
unfolding convol_def by simp
traytel@49495
    32
traytel@51893
    33
lemma convol_mem_GrpI:
traytel@52986
    34
"x \<in> A \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
traytel@51893
    35
unfolding convol_def Grp_def by auto
traytel@51893
    36
blanchet@49312
    37
definition csquare where
blanchet@49312
    38
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
blanchet@49312
    39
blanchet@49312
    40
(* The pullback of sets *)
blanchet@49312
    41
definition thePull where
blanchet@49312
    42
"thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
blanchet@49312
    43
blanchet@49312
    44
lemma wpull_thePull:
blanchet@49312
    45
"wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
blanchet@49312
    46
unfolding wpull_def thePull_def by auto
blanchet@49312
    47
blanchet@49312
    48
lemma wppull_thePull:
blanchet@49312
    49
assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@49312
    50
shows
blanchet@49312
    51
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
blanchet@49312
    52
   j a' \<in> A \<and>
blanchet@49312
    53
   e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
blanchet@49312
    54
(is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
blanchet@49312
    55
proof(rule bchoice[of ?A' ?phi], default)
blanchet@49312
    56
  fix a' assume a': "a' \<in> ?A'"
blanchet@49312
    57
  hence "fst a' \<in> B1" unfolding thePull_def by auto
blanchet@49312
    58
  moreover
blanchet@49312
    59
  from a' have "snd a' \<in> B2" unfolding thePull_def by auto
blanchet@49312
    60
  moreover have "f1 (fst a') = f2 (snd a')"
blanchet@49312
    61
  using a' unfolding csquare_def thePull_def by auto
blanchet@49312
    62
  ultimately show "\<exists> ja'. ?phi a' ja'"
blanchet@49325
    63
  using assms unfolding wppull_def by blast
blanchet@49312
    64
qed
blanchet@49312
    65
blanchet@49312
    66
lemma wpull_wppull:
blanchet@49312
    67
assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
blanchet@49312
    68
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
    69
shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
blanchet@49312
    70
unfolding wppull_def proof safe
blanchet@49312
    71
  fix b1 b2
blanchet@49312
    72
  assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
blanchet@49312
    73
  then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
blanchet@49312
    74
  using wp unfolding wpull_def by blast
blanchet@49312
    75
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
blanchet@49325
    76
  apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
blanchet@49312
    77
qed
blanchet@49312
    78
blanchet@49312
    79
lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
blanchet@49312
    80
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
blanchet@49312
    81
by (erule wpull_wppull) auto
blanchet@49312
    82
traytel@51893
    83
lemma eq_alt: "op = = Grp UNIV id"
traytel@51893
    84
unfolding Grp_def by auto
traytel@51893
    85
traytel@51893
    86
lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
traytel@51893
    87
  by auto
traytel@51893
    88
traytel@51893
    89
lemma eq_OOI: "R = op = \<Longrightarrow> R = R OO R"
traytel@51893
    90
  by auto
traytel@51893
    91
traytel@53561
    92
lemma OO_Grp_alt: "(Grp A f)^--1 OO Grp A g = (\<lambda>x y. \<exists>z. z \<in> A \<and> f z = x \<and> g z = y)"
traytel@53561
    93
  unfolding Grp_def by auto
traytel@53561
    94
traytel@51893
    95
lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
traytel@51893
    96
unfolding Grp_def by auto
traytel@51893
    97
traytel@51893
    98
lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
traytel@51893
    99
unfolding Grp_def by auto
traytel@51893
   100
traytel@51893
   101
lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
traytel@51893
   102
unfolding Grp_def by auto
traytel@51893
   103
traytel@51893
   104
lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
traytel@51893
   105
unfolding Grp_def by auto
traytel@51893
   106
traytel@51893
   107
lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
traytel@51893
   108
unfolding Grp_def by auto
traytel@51893
   109
traytel@51893
   110
lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
traytel@51893
   111
unfolding Grp_def o_def by auto
traytel@51893
   112
traytel@51893
   113
lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
traytel@51893
   114
unfolding Grp_def o_def by auto
traytel@51893
   115
traytel@51893
   116
definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
traytel@51893
   117
traytel@51893
   118
lemma pick_middlep:
traytel@51893
   119
"(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
   120
unfolding pick_middlep_def apply(rule someI_ex) by auto
blanchet@49312
   121
traytel@51893
   122
definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
traytel@51893
   123
definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
traytel@51893
   124
traytel@51893
   125
lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
traytel@51893
   126
unfolding fstOp_def mem_Collect_eq
traytel@51893
   127
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
blanchet@49312
   128
traytel@51893
   129
lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
traytel@51893
   130
unfolding comp_def fstOp_def by simp
traytel@51893
   131
traytel@51893
   132
lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
traytel@51893
   133
unfolding comp_def sndOp_def by simp
traytel@51893
   134
traytel@51893
   135
lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
traytel@51893
   136
unfolding sndOp_def mem_Collect_eq
traytel@51893
   137
by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
traytel@51893
   138
traytel@51893
   139
lemma csquare_fstOp_sndOp:
traytel@51893
   140
"csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
traytel@51893
   141
unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
traytel@51893
   142
traytel@51893
   143
lemma wppull_fstOp_sndOp:
traytel@51909
   144
shows "wppull (Collect (split (P OO Q))) (Collect (split P)) (Collect (split Q))
traytel@51909
   145
  snd fst fst snd (fstOp P Q) (sndOp P Q)"
traytel@51893
   146
using pick_middlep unfolding wppull_def fstOp_def sndOp_def relcompp.simps by auto
traytel@51893
   147
blanchet@49312
   148
lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
blanchet@49312
   149
by (simp split: prod.split)
blanchet@49312
   150
blanchet@49312
   151
lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
blanchet@49312
   152
by (simp split: prod.split)
blanchet@49312
   153
traytel@51893
   154
lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
traytel@51893
   155
by auto
traytel@51893
   156
traytel@51893
   157
lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
traytel@51893
   158
  by auto
traytel@51893
   159
traytel@51916
   160
lemma Collect_split_mono_strong: 
traytel@51916
   161
  "\<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>
traytel@51916
   162
  A \<subseteq> Collect (split Q)"
traytel@51916
   163
  by fastforce
traytel@51916
   164
traytel@51917
   165
lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
traytel@51893
   166
by metis
blanchet@49537
   167
traytel@52635
   168
lemma sum_case_o_inj:
traytel@52635
   169
"sum_case f g \<circ> Inl = f"
traytel@52635
   170
"sum_case f g \<circ> Inr = g"
traytel@52635
   171
by auto
traytel@52635
   172
traytel@52635
   173
lemma card_order_csum_cone_cexp_def:
traytel@52635
   174
  "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
traytel@52635
   175
  unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
traytel@52635
   176
traytel@52635
   177
lemma If_the_inv_into_in_Func:
traytel@52635
   178
  "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
traytel@52635
   179
  (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
traytel@52635
   180
unfolding Func_def by (auto dest: the_inv_into_into)
traytel@52635
   181
traytel@52635
   182
lemma If_the_inv_into_f_f:
traytel@52635
   183
  "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow>
traytel@52635
   184
  ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) o g) i = id i"
traytel@52635
   185
unfolding Func_def by (auto elim: the_inv_into_f_f)
traytel@52635
   186
traytel@52731
   187
definition vimage2p where
traytel@52731
   188
  "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
traytel@52719
   189
traytel@52731
   190
lemma vimage2pI: "R (f x) (g y) \<Longrightarrow> vimage2p f g R x y"
traytel@52731
   191
  unfolding vimage2p_def by -
traytel@52719
   192
traytel@52731
   193
lemma vimage2pD: "vimage2p f g R x y \<Longrightarrow> R (f x) (g y)"
traytel@52731
   194
  unfolding vimage2p_def by -
traytel@52719
   195
traytel@52731
   196
lemma fun_rel_iff_leq_vimage2p: "(fun_rel R S) f g = (R \<le> vimage2p f g S)"
traytel@52731
   197
  unfolding fun_rel_def vimage2p_def by auto
traytel@52719
   198
traytel@52731
   199
lemma convol_image_vimage2p: "<f o fst, g o snd> ` Collect (split (vimage2p f g R)) \<subseteq> Collect (split R)"
traytel@52731
   200
  unfolding vimage2p_def convol_def by auto
traytel@52719
   201
blanchet@49309
   202
ML_file "Tools/bnf_def_tactics.ML"
blanchet@49537
   203
ML_file "Tools/bnf_def.ML"
blanchet@49309
   204
traytel@51893
   205
blanchet@48975
   206
end