src/HOL/BNF_Def.thy
author wenzelm
Thu, 24 Jul 2014 11:54:15 +0200
changeset 58983 dc59f147b27d
parent 58740 882091eb1e9a
child 59180 85ec71012df8
permissions -rw-r--r--
more robust notation BNF_Def.convol, which is private to main HOL, but may cause syntax ambiguities nonetheless (e.g. List.thy);
blanchet@56401
     1
(*  Title:      HOL/BNF_Def.thy
blanchet@49990
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@58740
     3
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@49990
     4
    Copyright   2012
blanchet@49990
     5
blanchet@49990
     6
Definition of bounded natural functors.
blanchet@49990
     7
*)
blanchet@49990
     8
blanchet@49990
     9
header {* Definition of Bounded Natural Functors *}
blanchet@49990
    10
blanchet@49990
    11
theory BNF_Def
blanchet@58740
    12
imports BNF_Cardinal_Arithmetic Fun_Def_Base
blanchet@49990
    13
keywords
blanchet@50301
    14
  "print_bnfs" :: diag and
blanchet@52973
    15
  "bnf" :: thy_goal
blanchet@49990
    16
begin
blanchet@49990
    17
blanchet@58740
    18
definition
blanchet@58740
    19
  rel_fun :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool"
blanchet@58740
    20
where
blanchet@58740
    21
  "rel_fun A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))"
blanchet@58740
    22
blanchet@58740
    23
lemma rel_funI [intro]:
blanchet@58740
    24
  assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)"
blanchet@58740
    25
  shows "rel_fun A B f g"
blanchet@58740
    26
  using assms by (simp add: rel_fun_def)
blanchet@58740
    27
blanchet@58740
    28
lemma rel_funD:
blanchet@58740
    29
  assumes "rel_fun A B f g" and "A x y"
blanchet@58740
    30
  shows "B (f x) (g y)"
blanchet@58740
    31
  using assms by (simp add: rel_fun_def)
blanchet@58740
    32
blanchet@58740
    33
definition collect where
blanchet@58740
    34
"collect F x = (\<Union>f \<in> F. f x)"
blanchet@58740
    35
blanchet@58740
    36
lemma fstI: "x = (y, z) \<Longrightarrow> fst x = y"
blanchet@58740
    37
by simp
blanchet@58740
    38
blanchet@58740
    39
lemma sndI: "x = (y, z) \<Longrightarrow> snd x = z"
blanchet@58740
    40
by simp
blanchet@58740
    41
blanchet@58740
    42
lemma bijI': "\<lbrakk>\<And>x y. (f x = f y) = (x = y); \<And>y. \<exists>x. y = f x\<rbrakk> \<Longrightarrow> bij f"
blanchet@58740
    43
unfolding bij_def inj_on_def by auto blast
blanchet@58740
    44
blanchet@58740
    45
(* Operator: *)
blanchet@58740
    46
definition "Gr A f = {(a, f a) | a. a \<in> A}"
blanchet@58740
    47
blanchet@58740
    48
definition "Grp A f = (\<lambda>a b. b = f a \<and> a \<in> A)"
blanchet@58740
    49
blanchet@58740
    50
definition vimage2p where
blanchet@58740
    51
  "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
blanchet@58740
    52
blanchet@57977
    53
lemma collect_comp: "collect F \<circ> g = collect ((\<lambda>f. f \<circ> g) ` F)"
blanchet@56408
    54
  by (rule ext) (auto simp only: comp_apply collect_def)
traytel@53030
    55
wenzelm@58983
    56
definition convol ("\<langle>(_,/ _)\<rangle>") where
wenzelm@58983
    57
"\<langle>f, g\<rangle> \<equiv> \<lambda>a. (f a, g a)"
traytel@50510
    58
traytel@50510
    59
lemma fst_convol:
wenzelm@58983
    60
"fst \<circ> \<langle>f, g\<rangle> = f"
traytel@50510
    61
apply(rule ext)
traytel@50510
    62
unfolding convol_def by simp
traytel@50510
    63
traytel@50510
    64
lemma snd_convol:
wenzelm@58983
    65
"snd \<circ> \<langle>f, g\<rangle> = g"
traytel@50510
    66
apply(rule ext)
traytel@50510
    67
unfolding convol_def by simp
traytel@50510
    68
traytel@53030
    69
lemma convol_mem_GrpI:
wenzelm@58983
    70
"x \<in> A \<Longrightarrow> \<langle>id, g\<rangle> x \<in> (Collect (split (Grp A g)))"
traytel@53030
    71
unfolding convol_def Grp_def by auto
traytel@53030
    72
blanchet@50327
    73
definition csquare where
blanchet@50327
    74
"csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
blanchet@50327
    75
traytel@53030
    76
lemma eq_alt: "op = = Grp UNIV id"
traytel@53030
    77
unfolding Grp_def by auto
traytel@53030
    78
traytel@53030
    79
lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
traytel@53030
    80
  by auto
traytel@53030
    81
traytel@56183
    82
lemma leq_OOI: "R = op = \<Longrightarrow> R \<le> R OO R"
traytel@53030
    83
  by auto
traytel@53030
    84
traytel@54698
    85
lemma OO_Grp_alt: "(Grp A f)^--1 OO Grp A g = (\<lambda>x y. \<exists>z. z \<in> A \<and> f z = x \<and> g z = y)"
traytel@54698
    86
  unfolding Grp_def by auto
traytel@54698
    87
traytel@53030
    88
lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
traytel@53030
    89
unfolding Grp_def by auto
traytel@53030
    90
traytel@53030
    91
lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
traytel@53030
    92
unfolding Grp_def by auto
traytel@53030
    93
traytel@53030
    94
lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
traytel@53030
    95
unfolding Grp_def by auto
traytel@53030
    96
traytel@53030
    97
lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
traytel@53030
    98
unfolding Grp_def by auto
traytel@53030
    99
traytel@53030
   100
lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
traytel@53030
   101
unfolding Grp_def by auto
traytel@53030
   102
traytel@53030
   103
lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
blanchet@56408
   104
unfolding Grp_def comp_def by auto
traytel@53030
   105
traytel@53030
   106
lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
blanchet@56408
   107
unfolding Grp_def comp_def by auto
traytel@53030
   108
traytel@53030
   109
definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
traytel@53030
   110
traytel@53030
   111
lemma pick_middlep:
traytel@53030
   112
"(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
traytel@53030
   113
unfolding pick_middlep_def apply(rule someI_ex) by auto
blanchet@50327
   114
traytel@53030
   115
definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
traytel@53030
   116
definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
traytel@53030
   117
traytel@53030
   118
lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
traytel@53030
   119
unfolding fstOp_def mem_Collect_eq
blanchet@56984
   120
by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct1])
blanchet@50327
   121
traytel@53030
   122
lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
traytel@53030
   123
unfolding comp_def fstOp_def by simp
traytel@53030
   124
traytel@53030
   125
lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
traytel@53030
   126
unfolding comp_def sndOp_def by simp
traytel@53030
   127
traytel@53030
   128
lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
traytel@53030
   129
unfolding sndOp_def mem_Collect_eq
blanchet@56984
   130
by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct2])
traytel@53030
   131
traytel@53030
   132
lemma csquare_fstOp_sndOp:
traytel@53030
   133
"csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
traytel@53030
   134
unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
traytel@53030
   135
blanchet@57977
   136
lemma snd_fst_flip: "snd xy = (fst \<circ> (%(x, y). (y, x))) xy"
blanchet@50327
   137
by (simp split: prod.split)
blanchet@50327
   138
blanchet@57977
   139
lemma fst_snd_flip: "fst xy = (snd \<circ> (%(x, y). (y, x))) xy"
blanchet@50327
   140
by (simp split: prod.split)
blanchet@50327
   141
traytel@53030
   142
lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
traytel@53030
   143
by auto
traytel@53030
   144
traytel@53030
   145
lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
traytel@53030
   146
  by auto
traytel@53030
   147
traytel@53053
   148
lemma Collect_split_mono_strong: 
traytel@56505
   149
  "\<lbrakk>X = fst ` A; Y = snd ` A; \<forall>a\<in>X. \<forall>b \<in> Y. P a b \<longrightarrow> Q a b; A \<subseteq> Collect (split P)\<rbrakk> \<Longrightarrow>
traytel@53053
   150
  A \<subseteq> Collect (split Q)"
traytel@53053
   151
  by fastforce
traytel@53053
   152
traytel@56505
   153
traytel@53054
   154
lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
traytel@57153
   155
by simp
blanchet@50552
   156
blanchet@56756
   157
lemma case_sum_o_inj:
blanchet@56756
   158
"case_sum f g \<circ> Inl = f"
blanchet@56756
   159
"case_sum f g \<circ> Inr = g"
traytel@53772
   160
by auto
traytel@53772
   161
traytel@53772
   162
lemma card_order_csum_cone_cexp_def:
traytel@53772
   163
  "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
traytel@53772
   164
  unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
traytel@53772
   165
traytel@53772
   166
lemma If_the_inv_into_in_Func:
traytel@53772
   167
  "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
traytel@53772
   168
  (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
traytel@53772
   169
unfolding Func_def by (auto dest: the_inv_into_into)
traytel@53772
   170
traytel@53772
   171
lemma If_the_inv_into_f_f:
traytel@53772
   172
  "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow>
blanchet@57977
   173
  ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<circ> g) i = id i"
traytel@53772
   174
unfolding Func_def by (auto elim: the_inv_into_f_f)
traytel@53772
   175
blanchet@57977
   176
lemma the_inv_f_o_f_id: "inj f \<Longrightarrow> (the_inv f \<circ> f) z = id z"
blanchet@57977
   177
  by (simp add: the_inv_f_f)
blanchet@57977
   178
traytel@53868
   179
lemma vimage2pI: "R (f x) (g y) \<Longrightarrow> vimage2p f g R x y"
traytel@53868
   180
  unfolding vimage2p_def by -
traytel@53856
   181
blanchet@57287
   182
lemma rel_fun_iff_leq_vimage2p: "(rel_fun R S) f g = (R \<le> vimage2p f g S)"
blanchet@57287
   183
  unfolding rel_fun_def vimage2p_def by auto
traytel@53856
   184
wenzelm@58983
   185
lemma convol_image_vimage2p: "\<langle>f \<circ> fst, g \<circ> snd\<rangle> ` Collect (split (vimage2p f g R)) \<subseteq> Collect (split R)"
traytel@53868
   186
  unfolding vimage2p_def convol_def by auto
traytel@53856
   187
traytel@56303
   188
lemma vimage2p_Grp: "vimage2p f g P = Grp UNIV f OO P OO (Grp UNIV g)\<inverse>\<inverse>"
traytel@56303
   189
  unfolding vimage2p_def Grp_def by auto
traytel@56303
   190
blanchet@58740
   191
ML_file "Tools/BNF/bnf_util.ML"
blanchet@58740
   192
ML_file "Tools/BNF/bnf_tactics.ML"
blanchet@56404
   193
ML_file "Tools/BNF/bnf_def_tactics.ML"
blanchet@56404
   194
ML_file "Tools/BNF/bnf_def.ML"
blanchet@50324
   195
blanchet@49990
   196
end