src/HOL/Codatatype/BNF_FP.thy
author blanchet
Wed Sep 12 17:26:05 2012 +0200 (2012-09-12)
changeset 49335 096967bf3940
parent 49325 340844cbf7af
child 49368 df359ce891ac
permissions -rw-r--r--
added sumEN_tupled_balanced
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@49312
    29
lemma all_unit_eq: "(\<And>x. PROP P x) \<equiv> PROP P ()" by simp
blanchet@49312
    30
blanchet@49312
    31
lemma all_prod_eq: "(\<And>x. PROP P x) \<equiv> (\<And>a b. PROP P (a, b))" by clarsimp
blanchet@49312
    32
blanchet@49312
    33
(* FIXME: needed? *)
blanchet@49312
    34
lemma False_imp_eq: "(False \<Longrightarrow> P) \<equiv> Trueprop True"
blanchet@49312
    35
by presburger
blanchet@49312
    36
blanchet@49312
    37
(* FIXME: needed? *)
blanchet@49312
    38
lemma all_point_1: "(\<And>z. z = b \<Longrightarrow> phi z) \<equiv> Trueprop (phi b)"
blanchet@49312
    39
by presburger
blanchet@49312
    40
blanchet@49312
    41
lemma rev_bspec: "a \<in> A \<Longrightarrow> \<forall>z \<in> A. P z \<Longrightarrow> P a"
blanchet@49312
    42
by simp
blanchet@49312
    43
blanchet@49312
    44
lemma Un_cong: "\<lbrakk>A = B; C = D\<rbrakk> \<Longrightarrow> A \<union> C = B \<union> D"
blanchet@49312
    45
by simp
blanchet@49312
    46
blanchet@49312
    47
definition convol ("<_ , _>") where
blanchet@49312
    48
"<f , g> \<equiv> %a. (f a, g a)"
blanchet@49312
    49
blanchet@49312
    50
lemma fst_convol:
blanchet@49312
    51
"fst o <f , g> = f"
blanchet@49312
    52
apply(rule ext)
blanchet@49312
    53
unfolding convol_def by simp
blanchet@49312
    54
blanchet@49312
    55
lemma snd_convol:
blanchet@49312
    56
"snd o <f , g> = g"
blanchet@49312
    57
apply(rule ext)
blanchet@49312
    58
unfolding convol_def by simp
blanchet@49312
    59
blanchet@49312
    60
lemma pointfree_idE: "f o g = id \<Longrightarrow> f (g x) = x"
blanchet@49312
    61
unfolding o_def fun_eq_iff by simp
blanchet@49312
    62
blanchet@49312
    63
lemma o_bij:
blanchet@49312
    64
  assumes gf: "g o f = id" and fg: "f o g = id"
blanchet@49312
    65
  shows "bij f"
blanchet@49312
    66
unfolding bij_def inj_on_def surj_def proof safe
blanchet@49312
    67
  fix a1 a2 assume "f a1 = f a2"
blanchet@49312
    68
  hence "g ( f a1) = g (f a2)" by simp
blanchet@49312
    69
  thus "a1 = a2" using gf unfolding fun_eq_iff by simp
blanchet@49312
    70
next
blanchet@49312
    71
  fix b
blanchet@49312
    72
  have "b = f (g b)"
blanchet@49312
    73
  using fg unfolding fun_eq_iff by simp
blanchet@49312
    74
  thus "EX a. b = f a" by blast
blanchet@49312
    75
qed
blanchet@49312
    76
blanchet@49312
    77
lemma ssubst_mem: "\<lbrakk>t = s; s \<in> X\<rbrakk> \<Longrightarrow> t \<in> X" by simp
blanchet@49312
    78
blanchet@49312
    79
lemma sum_case_step:
blanchet@49312
    80
  "sum_case (sum_case f' g') g (Inl p) = sum_case f' g' p"
blanchet@49312
    81
  "sum_case f (sum_case f' g') (Inr p) = sum_case f' g' p"
blanchet@49312
    82
by auto
blanchet@49312
    83
blanchet@49312
    84
lemma one_pointE: "\<lbrakk>\<And>x. s = x \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    85
by simp
blanchet@49312
    86
blanchet@49312
    87
lemma obj_one_pointE: "\<forall>x. s = x \<longrightarrow> P \<Longrightarrow> P"
blanchet@49312
    88
by blast
blanchet@49312
    89
blanchet@49325
    90
lemma obj_sumE_f':
blanchet@49325
    91
"\<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
    92
by (cases x) blast+
blanchet@49325
    93
blanchet@49312
    94
lemma obj_sumE_f:
blanchet@49312
    95
"\<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
    96
by (rule allI) (rule obj_sumE_f')
blanchet@49312
    97
blanchet@49312
    98
lemma obj_sumE: "\<lbrakk>\<forall>x. s = Inl x \<longrightarrow> P; \<forall>x. s = Inr x \<longrightarrow> P\<rbrakk> \<Longrightarrow> P"
blanchet@49312
    99
by (cases s) auto
blanchet@49312
   100
blanchet@49325
   101
lemma obj_sum_step':
blanchet@49325
   102
"\<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
   103
by (cases x) blast+
blanchet@49325
   104
blanchet@49312
   105
lemma obj_sum_step:
blanchet@49325
   106
"\<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
   107
by (rule allI) (rule obj_sum_step')
blanchet@49312
   108
blanchet@49312
   109
lemma sum_case_if:
blanchet@49312
   110
"sum_case f g (if p then Inl x else Inr y) = (if p then f x else g y)"
blanchet@49312
   111
by simp
blanchet@49312
   112
blanchet@49309
   113
ML_file "Tools/bnf_fp_util.ML"
blanchet@49309
   114
ML_file "Tools/bnf_fp_sugar_tactics.ML"
blanchet@49309
   115
ML_file "Tools/bnf_fp_sugar.ML"
blanchet@49309
   116
blanchet@49308
   117
end