src/HOL/BNF_Def.thy
author haftmann
Tue Oct 13 09:21:15 2015 +0200 (2015-10-13)
changeset 61424 c3658c18b7bc
parent 61423 9b6a0fb85fa3
child 61681 ca53150406c9
permissions -rw-r--r--
prod_case as canonical name for product type eliminator
blanchet@55059
     1
(*  Title:      HOL/BNF_Def.thy
blanchet@48975
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@57398
     3
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@57698
     4
    Copyright   2012, 2013, 2014
blanchet@48975
     5
blanchet@48975
     6
Definition of bounded natural functors.
blanchet@48975
     7
*)
blanchet@48975
     8
wenzelm@60758
     9
section \<open>Definition of Bounded Natural Functors\<close>
blanchet@48975
    10
blanchet@48975
    11
theory BNF_Def
blanchet@57398
    12
imports BNF_Cardinal_Arithmetic Fun_Def_Base
blanchet@48975
    13
keywords
blanchet@49286
    14
  "print_bnfs" :: diag and
blanchet@51836
    15
  "bnf" :: thy_goal
blanchet@48975
    16
begin
blanchet@48975
    17
haftmann@61424
    18
lemma Collect_case_prodD: "x \<in> Collect (case_prod A) \<Longrightarrow> A (fst x) (snd x)"
desharna@58104
    19
  by auto
desharna@58104
    20
traytel@58916
    21
inductive
traytel@58916
    22
   rel_sum :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool" for R1 R2
desharna@58446
    23
where
traytel@58916
    24
  "R1 a c \<Longrightarrow> rel_sum R1 R2 (Inl a) (Inl c)"
traytel@58916
    25
| "R2 b d \<Longrightarrow> rel_sum R1 R2 (Inr b) (Inr d)"
traytel@58916
    26
traytel@58916
    27
hide_fact rel_sum_def
desharna@58446
    28
desharna@58446
    29
definition
blanchet@57398
    30
  rel_fun :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> ('a \<Rightarrow> 'b) \<Rightarrow> ('c \<Rightarrow> 'd) \<Rightarrow> bool"
blanchet@57398
    31
where
blanchet@57398
    32
  "rel_fun A B = (\<lambda>f g. \<forall>x y. A x y \<longrightarrow> B (f x) (g y))"
blanchet@57398
    33
blanchet@57398
    34
lemma rel_funI [intro]:
blanchet@57398
    35
  assumes "\<And>x y. A x y \<Longrightarrow> B (f x) (g y)"
blanchet@57398
    36
  shows "rel_fun A B f g"
blanchet@57398
    37
  using assms by (simp add: rel_fun_def)
blanchet@57398
    38
blanchet@57398
    39
lemma rel_funD:
blanchet@57398
    40
  assumes "rel_fun A B f g" and "A x y"
blanchet@57398
    41
  shows "B (f x) (g y)"
blanchet@57398
    42
  using assms by (simp add: rel_fun_def)
blanchet@57398
    43
Andreas@59513
    44
lemma rel_fun_mono:
Andreas@59513
    45
  "\<lbrakk> rel_fun X A f g; \<And>x y. Y x y \<longrightarrow> X x y; \<And>x y. A x y \<Longrightarrow> B x y \<rbrakk> \<Longrightarrow> rel_fun Y B f g"
Andreas@59513
    46
by(simp add: rel_fun_def)
Andreas@59513
    47
Andreas@59513
    48
lemma rel_fun_mono' [mono]:
Andreas@59513
    49
  "\<lbrakk> \<And>x y. Y x y \<longrightarrow> X x y; \<And>x y. A x y \<longrightarrow> B x y \<rbrakk> \<Longrightarrow> rel_fun X A f g \<longrightarrow> rel_fun Y B f g"
Andreas@59513
    50
by(simp add: rel_fun_def)
Andreas@59513
    51
desharna@58104
    52
definition rel_set :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a set \<Rightarrow> 'b set \<Rightarrow> bool"
desharna@58104
    53
  where "rel_set R = (\<lambda>A B. (\<forall>x\<in>A. \<exists>y\<in>B. R x y) \<and> (\<forall>y\<in>B. \<exists>x\<in>A. R x y))"
desharna@58104
    54
desharna@58104
    55
lemma rel_setI:
desharna@58104
    56
  assumes "\<And>x. x \<in> A \<Longrightarrow> \<exists>y\<in>B. R x y"
desharna@58104
    57
  assumes "\<And>y. y \<in> B \<Longrightarrow> \<exists>x\<in>A. R x y"
desharna@58104
    58
  shows "rel_set R A B"
desharna@58104
    59
  using assms unfolding rel_set_def by simp
desharna@58104
    60
desharna@58104
    61
lemma predicate2_transferD:
desharna@58104
    62
   "\<lbrakk>rel_fun R1 (rel_fun R2 (op =)) P Q; a \<in> A; b \<in> B; A \<subseteq> {(x, y). R1 x y}; B \<subseteq> {(x, y). R2 x y}\<rbrakk> \<Longrightarrow>
desharna@58104
    63
   P (fst a) (fst b) \<longleftrightarrow> Q (snd a) (snd b)"
haftmann@61424
    64
  unfolding rel_fun_def by (blast dest!: Collect_case_prodD)
desharna@58104
    65
blanchet@57398
    66
definition collect where
blanchet@58352
    67
  "collect F x = (\<Union>f \<in> F. f x)"
blanchet@57398
    68
blanchet@57398
    69
lemma fstI: "x = (y, z) \<Longrightarrow> fst x = y"
blanchet@58352
    70
  by simp
blanchet@57398
    71
blanchet@57398
    72
lemma sndI: "x = (y, z) \<Longrightarrow> snd x = z"
blanchet@58352
    73
  by simp
blanchet@57398
    74
blanchet@57398
    75
lemma bijI': "\<lbrakk>\<And>x y. (f x = f y) = (x = y); \<And>y. \<exists>x. y = f x\<rbrakk> \<Longrightarrow> bij f"
blanchet@58352
    76
  unfolding bij_def inj_on_def by auto blast
blanchet@57398
    77
blanchet@57398
    78
(* Operator: *)
blanchet@57398
    79
definition "Gr A f = {(a, f a) | a. a \<in> A}"
blanchet@57398
    80
blanchet@57398
    81
definition "Grp A f = (\<lambda>a b. b = f a \<and> a \<in> A)"
blanchet@57398
    82
blanchet@57398
    83
definition vimage2p where
blanchet@57398
    84
  "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
blanchet@57398
    85
blanchet@56635
    86
lemma collect_comp: "collect F \<circ> g = collect ((\<lambda>f. f \<circ> g) ` F)"
blanchet@55066
    87
  by (rule ext) (auto simp only: comp_apply collect_def)
traytel@51893
    88
wenzelm@57641
    89
definition convol ("\<langle>(_,/ _)\<rangle>") where
blanchet@58352
    90
  "\<langle>f, g\<rangle> \<equiv> \<lambda>a. (f a, g a)"
traytel@49495
    91
blanchet@58352
    92
lemma fst_convol: "fst \<circ> \<langle>f, g\<rangle> = f"
blanchet@58352
    93
  apply(rule ext)
blanchet@58352
    94
  unfolding convol_def by simp
traytel@49495
    95
blanchet@58352
    96
lemma snd_convol: "snd \<circ> \<langle>f, g\<rangle> = g"
blanchet@58352
    97
  apply(rule ext)
blanchet@58352
    98
  unfolding convol_def by simp
traytel@49495
    99
traytel@51893
   100
lemma convol_mem_GrpI:
haftmann@61032
   101
  "x \<in> A \<Longrightarrow> \<langle>id, g\<rangle> x \<in> (Collect (case_prod (Grp A g)))"
blanchet@58352
   102
  unfolding convol_def Grp_def by auto
traytel@51893
   103
blanchet@49312
   104
definition csquare where
blanchet@58352
   105
  "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
blanchet@49312
   106
traytel@51893
   107
lemma eq_alt: "op = = Grp UNIV id"
blanchet@58352
   108
  unfolding Grp_def by auto
traytel@51893
   109
traytel@51893
   110
lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
traytel@51893
   111
  by auto
traytel@51893
   112
traytel@54841
   113
lemma leq_OOI: "R = op = \<Longrightarrow> R \<le> R OO R"
traytel@51893
   114
  by auto
traytel@51893
   115
traytel@53561
   116
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@53561
   117
  unfolding Grp_def by auto
traytel@53561
   118
traytel@51893
   119
lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
blanchet@58352
   120
  unfolding Grp_def by auto
traytel@51893
   121
traytel@51893
   122
lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
blanchet@58352
   123
  unfolding Grp_def by auto
traytel@51893
   124
traytel@51893
   125
lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
blanchet@58352
   126
  unfolding Grp_def by auto
traytel@51893
   127
traytel@51893
   128
lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
blanchet@58352
   129
  unfolding Grp_def by auto
traytel@51893
   130
traytel@51893
   131
lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
blanchet@58352
   132
  unfolding Grp_def by auto
traytel@51893
   133
haftmann@61424
   134
lemma Collect_case_prod_Grp_eqD: "z \<in> Collect (case_prod (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
blanchet@58352
   135
  unfolding Grp_def comp_def by auto
traytel@51893
   136
haftmann@61424
   137
lemma Collect_case_prod_Grp_in: "z \<in> Collect (case_prod (Grp A f)) \<Longrightarrow> fst z \<in> A"
blanchet@58352
   138
  unfolding Grp_def comp_def by auto
traytel@51893
   139
traytel@51893
   140
definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
traytel@51893
   141
traytel@51893
   142
lemma pick_middlep:
blanchet@58352
   143
  "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
blanchet@58352
   144
  unfolding pick_middlep_def apply(rule someI_ex) by auto
blanchet@49312
   145
blanchet@58352
   146
definition fstOp where
blanchet@58352
   147
  "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
blanchet@58352
   148
blanchet@58352
   149
definition sndOp where
blanchet@58352
   150
  "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
traytel@51893
   151
haftmann@61032
   152
lemma fstOp_in: "ac \<in> Collect (case_prod (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (case_prod P)"
blanchet@58352
   153
  unfolding fstOp_def mem_Collect_eq
blanchet@58352
   154
  by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct1])
blanchet@49312
   155
traytel@51893
   156
lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
blanchet@58352
   157
  unfolding comp_def fstOp_def by simp
traytel@51893
   158
traytel@51893
   159
lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
blanchet@58352
   160
  unfolding comp_def sndOp_def by simp
traytel@51893
   161
haftmann@61032
   162
lemma sndOp_in: "ac \<in> Collect (case_prod (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (case_prod Q)"
blanchet@58352
   163
  unfolding sndOp_def mem_Collect_eq
blanchet@58352
   164
  by (subst (asm) surjective_pairing, unfold prod.case) (erule pick_middlep[THEN conjunct2])
traytel@51893
   165
traytel@51893
   166
lemma csquare_fstOp_sndOp:
haftmann@61423
   167
  "csquare (Collect (f (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
blanchet@58352
   168
  unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
traytel@51893
   169
blanchet@56635
   170
lemma snd_fst_flip: "snd xy = (fst \<circ> (%(x, y). (y, x))) xy"
blanchet@58352
   171
  by (simp split: prod.split)
blanchet@49312
   172
blanchet@56635
   173
lemma fst_snd_flip: "fst xy = (snd \<circ> (%(x, y). (y, x))) xy"
blanchet@58352
   174
  by (simp split: prod.split)
blanchet@49312
   175
haftmann@61032
   176
lemma flip_pred: "A \<subseteq> Collect (case_prod (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (case_prod R)"
blanchet@58352
   177
  by auto
traytel@51893
   178
traytel@51917
   179
lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
blanchet@58352
   180
  by simp
blanchet@49537
   181
blanchet@58352
   182
lemma case_sum_o_inj: "case_sum f g \<circ> Inl = f" "case_sum f g \<circ> Inr = g"
blanchet@58352
   183
  by auto
traytel@52635
   184
blanchet@58352
   185
lemma map_sum_o_inj: "map_sum f g o Inl = Inl o f" "map_sum f g o Inr = Inr o g"
blanchet@58352
   186
  by auto
traytel@57802
   187
traytel@52635
   188
lemma card_order_csum_cone_cexp_def:
traytel@52635
   189
  "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
traytel@52635
   190
  unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
traytel@52635
   191
traytel@52635
   192
lemma If_the_inv_into_in_Func:
traytel@52635
   193
  "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
blanchet@58352
   194
   (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
blanchet@58352
   195
  unfolding Func_def by (auto dest: the_inv_into_into)
traytel@52635
   196
traytel@52635
   197
lemma If_the_inv_into_f_f:
blanchet@58352
   198
  "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow> ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<circ> g) i = id i"
blanchet@58352
   199
  unfolding Func_def by (auto elim: the_inv_into_f_f)
traytel@52635
   200
blanchet@56635
   201
lemma the_inv_f_o_f_id: "inj f \<Longrightarrow> (the_inv f \<circ> f) z = id z"
blanchet@56635
   202
  by (simp add: the_inv_f_f)
blanchet@56635
   203
traytel@52731
   204
lemma vimage2pI: "R (f x) (g y) \<Longrightarrow> vimage2p f g R x y"
traytel@52731
   205
  unfolding vimage2p_def by -
traytel@52719
   206
blanchet@55945
   207
lemma rel_fun_iff_leq_vimage2p: "(rel_fun R S) f g = (R \<le> vimage2p f g S)"
blanchet@55945
   208
  unfolding rel_fun_def vimage2p_def by auto
traytel@52719
   209
haftmann@61032
   210
lemma convol_image_vimage2p: "\<langle>f \<circ> fst, g \<circ> snd\<rangle> ` Collect (case_prod (vimage2p f g R)) \<subseteq> Collect (case_prod R)"
traytel@52731
   211
  unfolding vimage2p_def convol_def by auto
traytel@52719
   212
traytel@54961
   213
lemma vimage2p_Grp: "vimage2p f g P = Grp UNIV f OO P OO (Grp UNIV g)\<inverse>\<inverse>"
traytel@54961
   214
  unfolding vimage2p_def Grp_def by auto
traytel@54961
   215
desharna@58106
   216
lemma subst_Pair: "P x y \<Longrightarrow> a = (x, y) \<Longrightarrow> P (fst a) (snd a)"
desharna@58106
   217
  by simp
desharna@58106
   218
blanchet@58352
   219
lemma comp_apply_eq: "f (g x) = h (k x) \<Longrightarrow> (f \<circ> g) x = (h \<circ> k) x"
blanchet@58352
   220
  unfolding comp_apply by assumption
blanchet@58352
   221
traytel@59726
   222
lemma refl_ge_eq: "(\<And>x. R x x) \<Longrightarrow> op = \<le> R"
traytel@59726
   223
  by auto
traytel@59726
   224
traytel@59726
   225
lemma ge_eq_refl: "op = \<le> R \<Longrightarrow> R x x"
traytel@59726
   226
  by auto
traytel@59726
   227
traytel@61240
   228
lemma reflp_eq: "reflp R = (op = \<le> R)"
traytel@61240
   229
  by (auto simp: reflp_def fun_eq_iff)
traytel@61240
   230
traytel@61240
   231
lemma transp_relcompp: "transp r \<longleftrightarrow> r OO r \<le> r"
traytel@61240
   232
  by (auto simp: transp_def)
traytel@61240
   233
traytel@61240
   234
lemma symp_conversep: "symp R = (R\<inverse>\<inverse> \<le> R)"
traytel@61240
   235
  by (auto simp: symp_def fun_eq_iff)
traytel@61240
   236
traytel@61240
   237
lemma diag_imp_eq_le: "(\<And>x. x \<in> A \<Longrightarrow> R x x) \<Longrightarrow> \<forall>x y. x \<in> A \<longrightarrow> y \<in> A \<longrightarrow> x = y \<longrightarrow> R x y"
traytel@61240
   238
  by blast
traytel@61240
   239
blanchet@57398
   240
ML_file "Tools/BNF/bnf_util.ML"
blanchet@57398
   241
ML_file "Tools/BNF/bnf_tactics.ML"
blanchet@55062
   242
ML_file "Tools/BNF/bnf_def_tactics.ML"
blanchet@55062
   243
ML_file "Tools/BNF/bnf_def.ML"
blanchet@49309
   244
blanchet@48975
   245
end