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