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