src/HOL/Codatatype/BNF_Def.thy
author traytel
Fri, 21 Sep 2012 12:27:56 +0200
changeset 49495 675b9df572df
parent 49325 340844cbf7af
child 49509 163914705f8d
permissions -rw-r--r--
rel_Gr does not depend on map_wpull
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
49495
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    28
definition convol ("<_ , _>") where
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    29
"<f , g> \<equiv> %a. (f a, g a)"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    30
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    31
lemma fst_convol:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    32
"fst o <f , g> = f"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    33
apply(rule ext)
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    34
unfolding convol_def by simp
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    35
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    36
lemma snd_convol:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    37
"snd o <f , g> = g"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    38
apply(rule ext)
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    39
unfolding convol_def by simp
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    40
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    41
lemma convol_memI:
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    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}"
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    43
unfolding convol_def by auto
675b9df572df rel_Gr does not depend on map_wpull
traytel
parents: 49325
diff changeset
    44
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    45
definition csquare where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    46
"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
    47
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    48
(* The pullback of sets *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    49
definition thePull where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    50
"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
    51
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    52
lemma wpull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    53
"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
    54
unfolding wpull_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    55
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    56
lemma wppull_thePull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    57
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
    58
shows
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    59
"\<exists> j. \<forall> a' \<in> thePull B1 B2 f1 f2.
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    60
   j a' \<in> A \<and>
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    61
   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
    62
(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
    63
proof(rule bchoice[of ?A' ?phi], default)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    64
  fix a' assume a': "a' \<in> ?A'"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    65
  hence "fst a' \<in> B1" unfolding thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    66
  moreover
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    67
  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
    68
  moreover have "f1 (fst a') = f2 (snd a')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    69
  using a' unfolding csquare_def thePull_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    70
  ultimately show "\<exists> ja'. ?phi a' ja'"
49325
blanchet
parents: 49312
diff changeset
    71
  using assms unfolding wppull_def by blast
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    72
qed
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 wpull_wppull:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    75
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
    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')"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    77
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
    78
unfolding wppull_def proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    79
  fix b1 b2
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    80
  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
    81
  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
    82
  using wp unfolding wpull_def by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    83
  show "\<exists>a\<in>A. e1 (p1 a) = e1 b1 \<and> e2 (p2 a) = e2 b2"
49325
blanchet
parents: 49312
diff changeset
    84
  apply (rule bexI[of _ "j a'"]) unfolding b1 b2 using a' 1 by auto
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    85
qed
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
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
    88
   wppull UNIV UNIV UNIV f1 f2 e1 e2 p1 p2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    89
by (erule wpull_wppull) auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    90
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    91
lemma Id_alt: "Id = Gr UNIV id"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    92
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    93
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    94
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
    95
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    96
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    97
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
    98
unfolding Gr_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    99
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   100
lemma wpull_Gr:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   101
"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
   102
unfolding wpull_def Gr_def by auto
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
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
   105
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   106
lemma pick_middle:
49325
blanchet
parents: 49312
diff changeset
   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"
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   108
unfolding pick_middle_def apply(rule someI_ex)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   109
using assms unfolding relcomp_def by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   110
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   111
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
   112
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
   113
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   114
lemma fstO_in: "ac \<in> P O Q \<Longrightarrow> fstO P Q ac \<in> P"
49325
blanchet
parents: 49312
diff changeset
   115
unfolding fstO_def
blanchet
parents: 49312
diff changeset
   116
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct1])
49312
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 fst_fstO: "fst bc = (fst \<circ> fstO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   119
unfolding comp_def fstO_def by simp
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 snd_sndO: "snd bc = (snd \<circ> sndO P Q) bc"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   122
unfolding comp_def sndO_def by simp
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 sndO_in: "ac \<in> P O Q \<Longrightarrow> sndO P Q ac \<in> Q"
49325
blanchet
parents: 49312
diff changeset
   125
unfolding sndO_def
blanchet
parents: 49312
diff changeset
   126
by (subst (asm) surjective_pairing) (rule pick_middle[THEN conjunct2])
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   127
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   128
lemma csquare_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   129
"csquare (P O Q) snd fst (fstO P Q) (sndO P Q)"
49325
blanchet
parents: 49312
diff changeset
   130
unfolding csquare_def fstO_def sndO_def using pick_middle by simp
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   131
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   132
lemma wppull_fstO_sndO:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   133
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
   134
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
   135
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   136
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
   137
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   138
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   139
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
   140
by (simp split: prod.split)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   141
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   142
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
   143
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   144
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   145
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
   146
unfolding o_def fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   147
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49286
diff changeset
   148
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
   149
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
   150
48975
7f79f94a432c added new (co)datatype package + theories of ordinals and cardinals (with Dmitriy and Andrei)
blanchet
parents:
diff changeset
   151
end