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