src/HOL/Codatatype/BNF_Def.thy
author blanchet
Wed, 12 Sep 2012 06:27:48 +0200
changeset 49312 c874ff5658dc
parent 49309 f20b24214ac2
child 49325 340844cbf7af
permissions -rw-r--r--
moved theorems closer to where they are used
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/Codatatype/BNF_Def.thy
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     3
    Copyright   2012
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     4
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     5
Definition of bounded natural functors.
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     6
*)
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     7
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     8
header {* Definition of Bounded Natural Functors *}
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
     9
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    10
theory BNF_Def
49282
c057e1b39f16 renamed "BNF_Library" to "BNF_Util"
blanchet
parents: 48975
diff changeset
    11
imports BNF_Util
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    12
keywords
49286
dde4967c9233 added "defaults" option
blanchet
parents: 49284
diff changeset
    13
  "print_bnfs" :: diag and
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    14
  "bnf_def" :: thy_goal
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    15
begin
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
    16
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    17
lemma collect_o: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    18
by (rule ext) (auto simp only: o_apply collect_def)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    19
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    20
lemma converse_mono:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    21
"R1 ^-1 \<subseteq> R2 ^-1 \<longleftrightarrow> R1 \<subseteq> R2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    22
unfolding converse_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    23
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    24
lemma converse_shift:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    25
"R1 \<subseteq> R2 ^-1 \<Longrightarrow> R1 ^-1 \<subseteq> R2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    26
unfolding converse_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    27
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    28
definition csquare where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    29
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    30
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    31
(* The pullback of sets *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    32
definition thePull where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    33
"thePull B1 B2 f1 f2 = {(b1,b2). b1 \<in> B1 \<and> b2 \<in> B2 \<and> f1 b1 = f2 b2}"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    34
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    35
lemma wpull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    36
"wpull (thePull B1 B2 f1 f2) B1 B2 f1 f2 fst snd"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    37
unfolding wpull_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    38
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    39
lemma wppull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    40
assumes "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    41
shows
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    42
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    43
   j a' \<in> A \<and>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    44
   e1 (p1 (j a')) = e1 (fst a') \<and> e2 (p2 (j a')) = e2 (snd a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    45
(is "\<exists> j. \<forall> a' \<in> ?A'. ?phi a' (j a')")
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    46
proof(rule bchoice[of ?A' ?phi], default)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    47
  fix a' assume a': "a' \<in> ?A'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    48
  hence "fst a' \<in> B1" unfolding thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    49
  moreover
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    50
  from a' have "snd a' \<in> B2" unfolding thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    51
  moreover have "f1 (fst a') = f2 (snd a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    52
  using a' unfolding csquare_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    53
  ultimately show "\<exists> ja'. ?phi a' ja'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    54
  using assms unfolding wppull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    55
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    56
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    57
lemma wpull_wppull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    58
assumes wp: "wpull A' B1 B2 f1 f2 p1' p2'" and
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    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')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    60
shows "wppull A B1 B2 f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    61
unfolding wppull_def proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    62
  fix b1 b2
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    63
  assume b1: "b1 \<in> B1" and b2: "b2 \<in> B2" and f: "f1 b1 = f2 b2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    64
  then obtain a' where a': "a' \<in> A'" and b1: "b1 = p1' a'" and b2: "b2 = p2' a'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    65
  using wp unfolding wpull_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    66
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    67
  apply(rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    68
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    69
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    70
lemma wppull_id: "\<lbrakk>wpull UNIV UNIV UNIV f1 f2 p1 p2; e1 = id; e2 = id\<rbrakk> \<Longrightarrow>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    71
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    72
by (erule wpull_wppull) auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    73
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    74
lemma Id_alt: "Id = Gr UNIV id"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    75
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    76
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    77
lemma Gr_UNIV_id: "f = id \<Longrightarrow> (Gr UNIV f)^-1 O Gr UNIV f = Gr UNIV f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    78
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    79
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    80
lemma Gr_mono: "A \<subseteq> B \<Longrightarrow> Gr A f \<subseteq> Gr B f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    81
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    82
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    83
lemma wpull_Gr:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    84
"wpull (Gr A f) A (f ` A) f id fst snd"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    85
unfolding wpull_def Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    86
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    87
definition "pick_middle P Q a c = (SOME b. (a,b) \<in> P \<and> (b,c) \<in> Q)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    88
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    89
lemma pick_middle:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    90
assumes "(a,c) \<in> P O Q"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    91
shows "(a, pick_middle P Q a c) \<in> P \<and> (pick_middle P Q a c, c) \<in> Q"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    92
unfolding pick_middle_def apply(rule someI_ex)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    93
using assms unfolding relcomp_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    94
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    95
definition fstO where "fstO P Q ac = (fst ac, pick_middle P Q (fst ac) (snd ac))"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    96
definition sndO where "sndO P Q ac = (pick_middle P Q (fst ac) (snd ac), snd ac)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    97
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    98
lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    99
by (metis assms fstO_def pick_middle surjective_pairing)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   100
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   101
lemma fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   102
unfolding comp_def fstO_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   103
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   104
lemma snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   105
unfolding comp_def sndO_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   106
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   107
lemma sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   108
by (metis assms sndO_def pick_middle surjective_pairing)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   109
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   110
lemma csquare_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   111
"csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   112
unfolding csquare_def fstO_def sndO_def using pick_middle by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   113
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   114
lemma wppull_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   115
shows "wppull (P O Q) P Q snd fst fst snd (fstO P Q) (sndO P Q)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   116
using pick_middle unfolding wppull_def fstO_def sndO_def relcomp_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   117
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   118
lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   119
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   120
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   121
lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   122
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   123
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   124
lemma flip_rel: "A \<subseteq> (R ^-1) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> R"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   125
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   126
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   127
lemma pointfreeE: "f o g = f' o g' \<Longrightarrow> f (g x) = f' (g' x)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   128
unfolding o_def fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   129
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   130
ML_file "Tools/bnf_def_tactics.ML"
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   131
ML_file"Tools/bnf_def.ML"
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   132
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   133
end