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