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