src/HOL/BNF/BNF_FP_Basic.thy
author traytel
Thu Aug 08 16:38:28 2013 +0200 (2013-08-08)
changeset 52913 2d2d9d1de1a9
parent 52731 dacd47a0633f
child 53105 ec38e9f4352f
permissions -rw-r--r--
theorems relating {c,d}tor_(un)fold/(co)rec and {c,d}tor_map
blanchet@51850
     1
(*  Title:      HOL/BNF/BNF_FP_Basic.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@51740
     6
Basic fixed point operations on bounded natural functors.
blanchet@49308
     7
*)
blanchet@49308
     8
blanchet@51740
     9
header {* Basic Fixed Point Operations on Bounded Natural Functors *}
blanchet@49308
    10
blanchet@51850
    11
theory BNF_FP_Basic
blanchet@51797
    12
imports BNF_Comp BNF_Ctr_Sugar
blanchet@49308
    13
keywords
blanchet@49308
    14
  "defaults"
blanchet@49308
    15
begin
blanchet@49308
    16
blanchet@49590
    17
lemma mp_conj: "(P \<longrightarrow> Q) \<and> R \<Longrightarrow> P \<Longrightarrow> R \<and> Q"
blanchet@49590
    18
by auto
blanchet@49590
    19
blanchet@49591
    20
lemma eq_sym_Unity_conv: "(x = (() = ())) = x"
blanchet@49585
    21
by blast
blanchet@49585
    22
blanchet@49539
    23
lemma unit_case_Unity: "(case u of () => f) = f"
blanchet@49312
    24
by (cases u) (hypsubst, rule unit.cases)
blanchet@49312
    25
blanchet@49539
    26
lemma prod_case_Pair_iden: "(case p of (x, y) \<Rightarrow> (x, y)) = p"
blanchet@49539
    27
by simp
blanchet@49539
    28
blanchet@49335
    29
lemma unit_all_impI: "(P () \<Longrightarrow> Q ()) \<Longrightarrow> \<forall>x. P x \<longrightarrow> Q x"
blanchet@49335
    30
by simp
blanchet@49335
    31
blanchet@49335
    32
lemma prod_all_impI: "(\<And>x y. P (x, y) \<Longrightarrow> Q (x, y)) \<Longrightarrow> \<forall>x. P x \<longrightarrow> Q x"
blanchet@49335
    33
by clarify
blanchet@49335
    34
blanchet@49335
    35
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
    36
by auto
blanchet@49335
    37
blanchet@49683
    38
lemma pointfree_idE: "f \<circ> g = id \<Longrightarrow> f (g x) = x"
blanchet@49312
    39
unfolding o_def fun_eq_iff by simp
blanchet@49312
    40
blanchet@49312
    41
lemma o_bij:
blanchet@49683
    42
  assumes gf: "g \<circ> f = id" and fg: "f \<circ> g = id"
blanchet@49312
    43
  shows "bij f"
blanchet@49312
    44
unfolding bij_def inj_on_def surj_def proof safe
blanchet@49312
    45
  fix a1 a2 assume "f a1 = f a2"
blanchet@49312
    46
  hence "g ( f a1) = g (f a2)" by simp
blanchet@49312
    47
  thus "a1 = a2" using gf unfolding fun_eq_iff by simp
blanchet@49312
    48
next
blanchet@49312
    49
  fix b
blanchet@49312
    50
  have "b = f (g b)"
blanchet@49312
    51
  using fg unfolding fun_eq_iff by simp
blanchet@49312
    52
  thus "EX a. b = f a" by blast
blanchet@49312
    53
qed
blanchet@49312
    54
blanchet@49312
    55
lemma ssubst_mem: "\<lbrakk>t = s; s \<in> X\<rbrakk> \<Longrightarrow> t \<in> X" by simp
blanchet@49312
    56
blanchet@49312
    57
lemma sum_case_step:
blanchet@49683
    58
"sum_case (sum_case f' g') g (Inl p) = sum_case f' g' p"
blanchet@49683
    59
"sum_case f (sum_case f' g') (Inr p) = sum_case f' g' p"
blanchet@49312
    60
by auto
blanchet@49312
    61
blanchet@49312
    62
lemma one_pointE: "\<lbrakk>\<And>x. s = x \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    63
by simp
blanchet@49312
    64
blanchet@49312
    65
lemma obj_one_pointE: "\<forall>x. s = x \<longrightarrow> P \<Longrightarrow> P"
blanchet@49312
    66
by blast
blanchet@49312
    67
blanchet@49312
    68
lemma obj_sumE_f:
blanchet@49312
    69
"\<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"
traytel@52660
    70
by (rule allI) (metis sumE)
blanchet@49312
    71
blanchet@49312
    72
lemma obj_sumE: "\<lbrakk>\<forall>x. s = Inl x \<longrightarrow> P; \<forall>x. s = Inr x \<longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    73
by (cases s) auto
blanchet@49312
    74
blanchet@49312
    75
lemma sum_case_if:
blanchet@49312
    76
"sum_case f g (if p then Inl x else Inr y) = (if p then f x else g y)"
blanchet@49312
    77
by simp
blanchet@49312
    78
blanchet@49428
    79
lemma mem_UN_compreh_eq: "(z : \<Union>{y. \<exists>x\<in>A. y = F x}) = (\<exists>x\<in>A. z : F x)"
blanchet@49428
    80
by blast
blanchet@49428
    81
blanchet@49585
    82
lemma UN_compreh_eq_eq:
blanchet@49585
    83
"\<Union>{y. \<exists>x\<in>A. y = {}} = {}"
blanchet@49585
    84
"\<Union>{y. \<exists>x\<in>A. y = {x}} = A"
blanchet@49585
    85
by blast+
blanchet@49585
    86
blanchet@51745
    87
lemma Inl_Inr_False: "(Inl x = Inr y) = False"
blanchet@51745
    88
by simp
blanchet@51745
    89
blanchet@49429
    90
lemma prod_set_simps:
blanchet@49429
    91
"fsts (x, y) = {x}"
blanchet@49429
    92
"snds (x, y) = {y}"
blanchet@49429
    93
unfolding fsts_def snds_def by simp+
blanchet@49429
    94
blanchet@49429
    95
lemma sum_set_simps:
blanchet@49451
    96
"setl (Inl x) = {x}"
blanchet@49451
    97
"setl (Inr x) = {}"
blanchet@49451
    98
"setr (Inl x) = {}"
blanchet@49451
    99
"setr (Inr x) = {x}"
blanchet@49451
   100
unfolding sum_set_defs by simp+
blanchet@49429
   101
blanchet@49642
   102
lemma prod_rel_simp:
blanchet@49642
   103
"prod_rel P Q (x, y) (x', y') \<longleftrightarrow> P x x' \<and> Q y y'"
blanchet@49642
   104
unfolding prod_rel_def by simp
blanchet@49642
   105
blanchet@49642
   106
lemma sum_rel_simps:
blanchet@49642
   107
"sum_rel P Q (Inl x) (Inl x') \<longleftrightarrow> P x x'"
blanchet@49642
   108
"sum_rel P Q (Inr y) (Inr y') \<longleftrightarrow> Q y y'"
blanchet@49642
   109
"sum_rel P Q (Inl x) (Inr y') \<longleftrightarrow> False"
blanchet@49642
   110
"sum_rel P Q (Inr y) (Inl x') \<longleftrightarrow> False"
blanchet@49642
   111
unfolding sum_rel_def by simp+
blanchet@49642
   112
traytel@52505
   113
lemma spec2: "\<forall>x y. P x y \<Longrightarrow> P x y"
traytel@52505
   114
by blast
traytel@52505
   115
traytel@52913
   116
lemma rewriteR_comp_comp: "\<lbrakk>g o h = r\<rbrakk> \<Longrightarrow> f o g o h = f o r"
traytel@52913
   117
  unfolding o_def fun_eq_iff by auto
traytel@52913
   118
traytel@52913
   119
lemma rewriteR_comp_comp2: "\<lbrakk>g o h = r1 o r2; f o r1 = l\<rbrakk> \<Longrightarrow> f o g o h = l o r2"
traytel@52913
   120
  unfolding o_def fun_eq_iff by auto
traytel@52913
   121
traytel@52913
   122
lemma rewriteL_comp_comp: "\<lbrakk>f o g = l\<rbrakk> \<Longrightarrow> f o (g o h) = l o h"
traytel@52913
   123
  unfolding o_def fun_eq_iff by auto
traytel@52913
   124
traytel@52913
   125
lemma rewriteL_comp_comp2: "\<lbrakk>f o g = l1 o l2; l2 o h = r\<rbrakk> \<Longrightarrow> f o (g o h) = l1 o r"
traytel@52913
   126
  unfolding o_def fun_eq_iff by auto
traytel@52913
   127
traytel@52913
   128
lemma convol_o: "<f, g> o h = <f o h, g o h>"
traytel@52913
   129
  unfolding convol_def by auto
traytel@52913
   130
traytel@52913
   131
lemma map_pair_o_convol: "map_pair h1 h2 o <f, g> = <h1 o f, h2 o g>"
traytel@52913
   132
  unfolding convol_def by auto
traytel@52913
   133
traytel@52913
   134
lemma map_pair_o_convol_id: "(map_pair f id \<circ> <id , g>) x = <id \<circ> f , g> x"
traytel@52913
   135
  unfolding map_pair_o_convol id_o o_id ..
traytel@52913
   136
traytel@52913
   137
lemma o_sum_case: "h o sum_case f g = sum_case (h o f) (h o g)"
traytel@52913
   138
  unfolding o_def by (auto split: sum.splits)
traytel@52913
   139
traytel@52913
   140
lemma sum_case_o_sum_map: "sum_case f g o sum_map h1 h2 = sum_case (f o h1) (g o h2)"
traytel@52913
   141
  unfolding o_def by (auto split: sum.splits)
traytel@52913
   142
traytel@52913
   143
lemma sum_case_o_sum_map_id: "(sum_case id g o sum_map f id) x = sum_case (f o id) g x"
traytel@52913
   144
  unfolding sum_case_o_sum_map id_o o_id ..
traytel@52913
   145
traytel@52731
   146
lemma fun_rel_def_butlast:
traytel@52731
   147
  "(fun_rel R (fun_rel S T)) f g = (\<forall>x y. R x y \<longrightarrow> (fun_rel S T) (f x) (g y))"
traytel@52731
   148
  unfolding fun_rel_def ..
traytel@52731
   149
blanchet@51850
   150
ML_file "Tools/bnf_fp_util.ML"
blanchet@49636
   151
ML_file "Tools/bnf_fp_def_sugar_tactics.ML"
blanchet@49636
   152
ML_file "Tools/bnf_fp_def_sugar.ML"
blanchet@49309
   153
blanchet@49308
   154
end