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