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