src/HOL/BNF_Def.thy
author blanchet
Wed Feb 12 08:35:57 2014 +0100 (2014-02-12)
changeset 55415 05f5fdb8d093
parent 55414 eab03e9cee8a
child 55642 63beb38e9258
permissions -rw-r--r--
renamed 'nat_{case,rec}' to '{case,rec}_nat'
     1 (*  Title:      HOL/BNF_Def.thy
     2     Author:     Dmitriy Traytel, TU Muenchen
     3     Copyright   2012
     4 
     5 Definition of bounded natural functors.
     6 *)
     7 
     8 header {* Definition of Bounded Natural Functors *}
     9 
    10 theory BNF_Def
    11 imports BNF_Util Fun_Def_Base
    12 keywords
    13   "print_bnfs" :: diag and
    14   "bnf" :: thy_goal
    15 begin
    16 
    17 lemma collect_comp: "collect F o g = collect ((\<lambda>f. f o g) ` F)"
    18   by (rule ext) (auto simp only: comp_apply collect_def)
    19 
    20 definition convol ("<_ , _>") where
    21 "<f , g> \<equiv> %a. (f a, g a)"
    22 
    23 lemma fst_convol:
    24 "fst o <f , g> = f"
    25 apply(rule ext)
    26 unfolding convol_def by simp
    27 
    28 lemma snd_convol:
    29 "snd o <f , g> = g"
    30 apply(rule ext)
    31 unfolding convol_def by simp
    32 
    33 lemma convol_mem_GrpI:
    34 "x \<in> A \<Longrightarrow> <id , g> x \<in> (Collect (split (Grp A g)))"
    35 unfolding convol_def Grp_def by auto
    36 
    37 definition csquare where
    38 "csquare A f1 f2 p1 p2 \<longleftrightarrow> (\<forall> a \<in> A. f1 (p1 a) = f2 (p2 a))"
    39 
    40 lemma eq_alt: "op = = Grp UNIV id"
    41 unfolding Grp_def by auto
    42 
    43 lemma leq_conversepI: "R = op = \<Longrightarrow> R \<le> R^--1"
    44   by auto
    45 
    46 lemma leq_OOI: "R = op = \<Longrightarrow> R \<le> R OO R"
    47   by auto
    48 
    49 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)"
    50   unfolding Grp_def by auto
    51 
    52 lemma Grp_UNIV_id: "f = id \<Longrightarrow> (Grp UNIV f)^--1 OO Grp UNIV f = Grp UNIV f"
    53 unfolding Grp_def by auto
    54 
    55 lemma Grp_UNIV_idI: "x = y \<Longrightarrow> Grp UNIV id x y"
    56 unfolding Grp_def by auto
    57 
    58 lemma Grp_mono: "A \<le> B \<Longrightarrow> Grp A f \<le> Grp B f"
    59 unfolding Grp_def by auto
    60 
    61 lemma GrpI: "\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> Grp A f x y"
    62 unfolding Grp_def by auto
    63 
    64 lemma GrpE: "Grp A f x y \<Longrightarrow> (\<lbrakk>f x = y; x \<in> A\<rbrakk> \<Longrightarrow> R) \<Longrightarrow> R"
    65 unfolding Grp_def by auto
    66 
    67 lemma Collect_split_Grp_eqD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> (f \<circ> fst) z = snd z"
    68 unfolding Grp_def comp_def by auto
    69 
    70 lemma Collect_split_Grp_inD: "z \<in> Collect (split (Grp A f)) \<Longrightarrow> fst z \<in> A"
    71 unfolding Grp_def comp_def by auto
    72 
    73 definition "pick_middlep P Q a c = (SOME b. P a b \<and> Q b c)"
    74 
    75 lemma pick_middlep:
    76 "(P OO Q) a c \<Longrightarrow> P a (pick_middlep P Q a c) \<and> Q (pick_middlep P Q a c) c"
    77 unfolding pick_middlep_def apply(rule someI_ex) by auto
    78 
    79 definition fstOp where "fstOp P Q ac = (fst ac, pick_middlep P Q (fst ac) (snd ac))"
    80 definition sndOp where "sndOp P Q ac = (pick_middlep P Q (fst ac) (snd ac), (snd ac))"
    81 
    82 lemma fstOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> fstOp P Q ac \<in> Collect (split P)"
    83 unfolding fstOp_def mem_Collect_eq
    84 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct1])
    85 
    86 lemma fst_fstOp: "fst bc = (fst \<circ> fstOp P Q) bc"
    87 unfolding comp_def fstOp_def by simp
    88 
    89 lemma snd_sndOp: "snd bc = (snd \<circ> sndOp P Q) bc"
    90 unfolding comp_def sndOp_def by simp
    91 
    92 lemma sndOp_in: "ac \<in> Collect (split (P OO Q)) \<Longrightarrow> sndOp P Q ac \<in> Collect (split Q)"
    93 unfolding sndOp_def mem_Collect_eq
    94 by (subst (asm) surjective_pairing, unfold prod.cases) (erule pick_middlep[THEN conjunct2])
    95 
    96 lemma csquare_fstOp_sndOp:
    97 "csquare (Collect (split (P OO Q))) snd fst (fstOp P Q) (sndOp P Q)"
    98 unfolding csquare_def fstOp_def sndOp_def using pick_middlep by simp
    99 
   100 lemma snd_fst_flip: "snd xy = (fst o (%(x, y). (y, x))) xy"
   101 by (simp split: prod.split)
   102 
   103 lemma fst_snd_flip: "fst xy = (snd o (%(x, y). (y, x))) xy"
   104 by (simp split: prod.split)
   105 
   106 lemma flip_pred: "A \<subseteq> Collect (split (R ^--1)) \<Longrightarrow> (%(x, y). (y, x)) ` A \<subseteq> Collect (split R)"
   107 by auto
   108 
   109 lemma Collect_split_mono: "A \<le> B \<Longrightarrow> Collect (split A) \<subseteq> Collect (split B)"
   110   by auto
   111 
   112 lemma Collect_split_mono_strong: 
   113   "\<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>
   114   A \<subseteq> Collect (split Q)"
   115   by fastforce
   116 
   117 
   118 lemma predicate2_eqD: "A = B \<Longrightarrow> A a b \<longleftrightarrow> B a b"
   119 by metis
   120 
   121 lemma case_sum_o_inj:
   122 "case_sum f g \<circ> Inl = f"
   123 "case_sum f g \<circ> Inr = g"
   124 by auto
   125 
   126 lemma card_order_csum_cone_cexp_def:
   127   "card_order r \<Longrightarrow> ( |A1| +c cone) ^c r = |Func UNIV (Inl ` A1 \<union> {Inr ()})|"
   128   unfolding cexp_def cone_def Field_csum Field_card_of by (auto dest: Field_card_order)
   129 
   130 lemma If_the_inv_into_in_Func:
   131   "\<lbrakk>inj_on g C; C \<subseteq> B \<union> {x}\<rbrakk> \<Longrightarrow>
   132   (\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) \<in> Func UNIV (B \<union> {x})"
   133 unfolding Func_def by (auto dest: the_inv_into_into)
   134 
   135 lemma If_the_inv_into_f_f:
   136   "\<lbrakk>i \<in> C; inj_on g C\<rbrakk> \<Longrightarrow>
   137   ((\<lambda>i. if i \<in> g ` C then the_inv_into C g i else x) o g) i = id i"
   138 unfolding Func_def by (auto elim: the_inv_into_f_f)
   139 
   140 definition vimage2p where
   141   "vimage2p f g R = (\<lambda>x y. R (f x) (g y))"
   142 
   143 lemma vimage2pI: "R (f x) (g y) \<Longrightarrow> vimage2p f g R x y"
   144   unfolding vimage2p_def by -
   145 
   146 lemma fun_rel_iff_leq_vimage2p: "(fun_rel R S) f g = (R \<le> vimage2p f g S)"
   147   unfolding fun_rel_def vimage2p_def by auto
   148 
   149 lemma convol_image_vimage2p: "<f o fst, g o snd> ` Collect (split (vimage2p f g R)) \<subseteq> Collect (split R)"
   150   unfolding vimage2p_def convol_def by auto
   151 
   152 lemma vimage2p_Grp: "vimage2p f g P = Grp UNIV f OO P OO (Grp UNIV g)\<inverse>\<inverse>"
   153   unfolding vimage2p_def Grp_def by auto
   154 
   155 ML_file "Tools/BNF/bnf_def_tactics.ML"
   156 ML_file "Tools/BNF/bnf_def.ML"
   157 
   158 end