src/HOL/Codatatype/BNF_FP.thy
author blanchet
Mon Sep 17 21:13:30 2012 +0200 (2012-09-17)
changeset 49429 64ac3471005a
parent 49428 93f158d59ead
child 49430 6df729c6a1a6
permissions -rw-r--r--
cleaner way of dealing with the set functions of sums and products
blanchet@49308
     1
(*  Title:      HOL/Codatatype/BNF_FP.thy
blanchet@49308
     2
    Author:     Dmitriy Traytel, TU Muenchen
blanchet@49308
     3
    Author:     Jasmin Blanchette, TU Muenchen
blanchet@49308
     4
    Copyright   2012
blanchet@49308
     5
blanchet@49308
     6
Composition of bounded natural functors.
blanchet@49308
     7
*)
blanchet@49308
     8
blanchet@49308
     9
header {* Composition of Bounded Natural Functors *}
blanchet@49308
    10
blanchet@49308
    11
theory BNF_FP
blanchet@49308
    12
imports BNF_Comp BNF_Wrap
blanchet@49308
    13
keywords
blanchet@49308
    14
  "defaults"
blanchet@49308
    15
begin
blanchet@49308
    16
blanchet@49312
    17
lemma case_unit: "(case u of () => f) = f"
blanchet@49312
    18
by (cases u) (hypsubst, rule unit.cases)
blanchet@49312
    19
blanchet@49335
    20
lemma unit_all_impI: "(P () \<Longrightarrow> Q ()) \<Longrightarrow> \<forall>x. P x \<longrightarrow> Q x"
blanchet@49335
    21
by simp
blanchet@49335
    22
blanchet@49335
    23
lemma prod_all_impI: "(\<And>x y. P (x, y) \<Longrightarrow> Q (x, y)) \<Longrightarrow> \<forall>x. P x \<longrightarrow> Q x"
blanchet@49335
    24
by clarify
blanchet@49335
    25
blanchet@49335
    26
lemma prod_all_impI_step: "(\<And>x. \<forall>y. P (x, y) \<longrightarrow> Q (x, y)) \<Longrightarrow> \<forall>x. P x \<longrightarrow> Q x"
blanchet@49335
    27
by auto
blanchet@49335
    28
blanchet@49368
    29
lemma all_unit_eq: "(\<And>x. PROP P x) \<equiv> PROP P ()"
blanchet@49368
    30
by simp
blanchet@49312
    31
blanchet@49368
    32
lemma all_prod_eq: "(\<And>x. PROP P x) \<equiv> (\<And>a b. PROP P (a, b))"
blanchet@49368
    33
by clarsimp
blanchet@49312
    34
blanchet@49312
    35
lemma rev_bspec: "a \<in> A \<Longrightarrow> \<forall>z \<in> A. P z \<Longrightarrow> P a"
blanchet@49312
    36
by simp
blanchet@49312
    37
blanchet@49312
    38
lemma Un_cong: "\<lbrakk>A = B; C = D\<rbrakk> \<Longrightarrow> A \<union> C = B \<union> D"
blanchet@49312
    39
by simp
blanchet@49312
    40
blanchet@49312
    41
definition convol ("<_ , _>") where
blanchet@49312
    42
"<f , g> \<equiv> %a. (f a, g a)"
blanchet@49312
    43
blanchet@49312
    44
lemma fst_convol:
blanchet@49312
    45
"fst o <f , g> = f"
blanchet@49312
    46
apply(rule ext)
blanchet@49312
    47
unfolding convol_def by simp
blanchet@49312
    48
blanchet@49312
    49
lemma snd_convol:
blanchet@49312
    50
"snd o <f , g> = g"
blanchet@49312
    51
apply(rule ext)
blanchet@49312
    52
unfolding convol_def by simp
blanchet@49312
    53
blanchet@49312
    54
lemma pointfree_idE: "f o g = id \<Longrightarrow> f (g x) = x"
blanchet@49312
    55
unfolding o_def fun_eq_iff by simp
blanchet@49312
    56
blanchet@49312
    57
lemma o_bij:
blanchet@49312
    58
  assumes gf: "g o f = id" and fg: "f o g = id"
blanchet@49312
    59
  shows "bij f"
blanchet@49312
    60
unfolding bij_def inj_on_def surj_def proof safe
blanchet@49312
    61
  fix a1 a2 assume "f a1 = f a2"
blanchet@49312
    62
  hence "g ( f a1) = g (f a2)" by simp
blanchet@49312
    63
  thus "a1 = a2" using gf unfolding fun_eq_iff by simp
blanchet@49312
    64
next
blanchet@49312
    65
  fix b
blanchet@49312
    66
  have "b = f (g b)"
blanchet@49312
    67
  using fg unfolding fun_eq_iff by simp
blanchet@49312
    68
  thus "EX a. b = f a" by blast
blanchet@49312
    69
qed
blanchet@49312
    70
blanchet@49312
    71
lemma ssubst_mem: "\<lbrakk>t = s; s \<in> X\<rbrakk> \<Longrightarrow> t \<in> X" by simp
blanchet@49312
    72
blanchet@49312
    73
lemma sum_case_step:
blanchet@49312
    74
  "sum_case (sum_case f' g') g (Inl p) = sum_case f' g' p"
blanchet@49312
    75
  "sum_case f (sum_case f' g') (Inr p) = sum_case f' g' p"
blanchet@49312
    76
by auto
blanchet@49312
    77
blanchet@49312
    78
lemma one_pointE: "\<lbrakk>\<And>x. s = x \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    79
by simp
blanchet@49312
    80
blanchet@49312
    81
lemma obj_one_pointE: "\<forall>x. s = x \<longrightarrow> P \<Longrightarrow> P"
blanchet@49312
    82
by blast
blanchet@49312
    83
blanchet@49325
    84
lemma obj_sumE_f':
blanchet@49325
    85
"\<lbrakk>\<forall>x. s = f (Inl x) \<longrightarrow> P; \<forall>x. s = f (Inr x) \<longrightarrow> P\<rbrakk> \<Longrightarrow> s = f x \<longrightarrow> P"
blanchet@49325
    86
by (cases x) blast+
blanchet@49325
    87
blanchet@49312
    88
lemma obj_sumE_f:
blanchet@49312
    89
"\<lbrakk>\<forall>x. s = f (Inl x) \<longrightarrow> P; \<forall>x. s = f (Inr x) \<longrightarrow> P\<rbrakk> \<Longrightarrow> \<forall>x. s = f x \<longrightarrow> P"
blanchet@49325
    90
by (rule allI) (rule obj_sumE_f')
blanchet@49312
    91
blanchet@49312
    92
lemma obj_sumE: "\<lbrakk>\<forall>x. s = Inl x \<longrightarrow> P; \<forall>x. s = Inr x \<longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    93
by (cases s) auto
blanchet@49312
    94
blanchet@49325
    95
lemma obj_sum_step':
blanchet@49325
    96
"\<lbrakk>\<forall>x. s = f (Inr (Inl x)) \<longrightarrow> P; \<forall>x. s = f (Inr (Inr x)) \<longrightarrow> P\<rbrakk> \<Longrightarrow> s = f (Inr x) \<longrightarrow> P"
blanchet@49325
    97
by (cases x) blast+
blanchet@49325
    98
blanchet@49312
    99
lemma obj_sum_step:
blanchet@49325
   100
"\<lbrakk>\<forall>x. s = f (Inr (Inl x)) \<longrightarrow> P; \<forall>x. s = f (Inr (Inr x)) \<longrightarrow> P\<rbrakk> \<Longrightarrow> \<forall>x. s = f (Inr x) \<longrightarrow> P"
blanchet@49325
   101
by (rule allI) (rule obj_sum_step')
blanchet@49312
   102
blanchet@49312
   103
lemma sum_case_if:
blanchet@49312
   104
"sum_case f g (if p then Inl x else Inr y) = (if p then f x else g y)"
blanchet@49312
   105
by simp
blanchet@49312
   106
blanchet@49426
   107
lemma UN_compreh_bex_eq_empty:
blanchet@49426
   108
"\<Union>{y. \<exists>x\<in>A. y = {}} = {}"
blanchet@49426
   109
by blast
blanchet@49426
   110
blanchet@49426
   111
lemma UN_compreh_bex_eq_singleton:
blanchet@49426
   112
"\<Union>{y. \<exists>x\<in>A. y = {f x}} = {y. \<exists>x\<in>A. y = f x}"
blanchet@49426
   113
by blast
blanchet@49426
   114
blanchet@49426
   115
lemma mem_UN_comprehI:
blanchet@49426
   116
"z \<in> {y. \<exists>x\<in>A. y = f x} \<Longrightarrow> z \<in> \<Union>{y. \<exists>x\<in>A. y = {f x}}"
blanchet@49426
   117
"z \<in> {y. \<exists>x\<in>A. y = f x} \<union> B \<Longrightarrow> z \<in> \<Union>{y. \<exists>x\<in>A. y = {f x}} \<union> B"
blanchet@49426
   118
"z \<in> \<Union>{y. \<exists>x\<in>A. y = F x} \<union> \<Union>{y. \<exists>x\<in>A. y = G x} \<Longrightarrow> z \<in> \<Union>{y. \<exists>x\<in>A. y = F x \<union> G x}"
blanchet@49426
   119
"z \<in> \<Union>{y. \<exists>x\<in>A. y = F x} \<union> (\<Union>{y. \<exists>x\<in>A. y = G x} \<union> B) \<Longrightarrow> z \<in> \<Union>{y. \<exists>x\<in>A. y = F x \<union> G x} \<union> B"
blanchet@49368
   120
by blast+
blanchet@49368
   121
blanchet@49426
   122
lemma mem_UN_comprehI':
blanchet@49426
   123
"\<exists>y. (\<exists>x\<in>A. y = F x) \<and> z \<in> y \<Longrightarrow> z \<in> \<Union>{y. \<exists>x\<in>A. y = {y. \<exists>y'\<in>F x. y = y'}}"
blanchet@49426
   124
by blast
blanchet@49426
   125
blanchet@49428
   126
lemma mem_UN_compreh_eq: "(z : \<Union>{y. \<exists>x\<in>A. y = F x}) = (\<exists>x\<in>A. z : F x)"
blanchet@49428
   127
by blast
blanchet@49428
   128
blanchet@49428
   129
lemma eq_UN_compreh_Un: "(xa = \<Union>{y. \<exists>x\<in>A. y = c_set1 x \<union> c_set2 x}) =
blanchet@49428
   130
  (xa = (\<Union>{y. \<exists>x\<in>A. y = c_set1 x} \<union> \<Union>{y. \<exists>x\<in>A. y = c_set2 x}))"
blanchet@49428
   131
by blast
blanchet@49428
   132
blanchet@49427
   133
lemma mem_compreh_eq_iff:
blanchet@49428
   134
"z \<in> {y. \<exists>x\<in>A. y = f x} = (\<exists> x. x \<in> A & z \<in> {f x})"
blanchet@49427
   135
by blast
blanchet@49427
   136
blanchet@49427
   137
lemma ex_mem_singleton: "(\<exists>y. y \<in> A \<and> y \<in> {x}) = (x \<in> A)"
blanchet@49427
   138
by simp
blanchet@49427
   139
blanchet@49429
   140
lemma prod_set_simps:
blanchet@49429
   141
"fsts (x, y) = {x}"
blanchet@49429
   142
"snds (x, y) = {y}"
blanchet@49429
   143
unfolding fsts_def snds_def by simp+
blanchet@49429
   144
blanchet@49429
   145
lemma sum_set_simps:
blanchet@49429
   146
"sum_setl (Inl x) = {x}"
blanchet@49429
   147
"sum_setl (Inr x) = {}"
blanchet@49429
   148
"sum_setr (Inl x) = {}"
blanchet@49429
   149
"sum_setr (Inr x) = {x}"
blanchet@49429
   150
unfolding sum_setl_def sum_setr_def by simp+
blanchet@49429
   151
blanchet@49427
   152
lemma induct_set_step:
blanchet@49427
   153
"\<lbrakk>b \<in> A; c \<in> F b\<rbrakk> \<Longrightarrow> \<exists>x. x \<in> A \<and> c \<in> F x"
blanchet@49427
   154
"\<lbrakk>B \<in> A; c \<in> f B\<rbrakk> \<Longrightarrow> \<exists>C. (\<exists>a \<in> A. C = f a) \<and>c \<in> C"
blanchet@49427
   155
by blast+
blanchet@49368
   156
blanchet@49309
   157
ML_file "Tools/bnf_fp_util.ML"
blanchet@49309
   158
ML_file "Tools/bnf_fp_sugar_tactics.ML"
blanchet@49309
   159
ML_file "Tools/bnf_fp_sugar.ML"
blanchet@49309
   160
blanchet@49308
   161
end