src/HOL/Codatatype/BNF_FP.thy
author blanchet
Wed, 12 Sep 2012 10:35:56 +0200
changeset 49325 340844cbf7af
parent 49312 c874ff5658dc
child 49335 096967bf3940
permissions -rw-r--r--
tuning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
49308
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     1
(*  Title:      HOL/Codatatype/BNF_FP.thy
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     2
    Author:     Dmitriy Traytel, TU Muenchen
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     3
    Author:     Jasmin Blanchette, TU Muenchen
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     4
    Copyright   2012
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     5
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     6
Composition of bounded natural functors.
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     7
*)
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     8
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
     9
header {* Composition of Bounded Natural Functors *}
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    10
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    11
theory BNF_FP
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    12
imports BNF_Comp BNF_Wrap
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    13
keywords
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    14
  "defaults"
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    15
begin
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
    16
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    17
lemma case_unit: "(case u of () => f) = f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    18
by (cases u) (hypsubst, rule unit.cases)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    19
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    20
(* FIXME: needed? *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    21
lemma all_unit_eq: "(\<And>x. PROP P x) \<equiv> PROP P ()" by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    22
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    23
(* FIXME: needed? *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    24
lemma all_prod_eq: "(\<And>x. PROP P x) \<equiv> (\<And>a b. PROP P (a, b))" by clarsimp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    25
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    26
(* FIXME: needed? *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    27
lemma False_imp_eq: "(False \<Longrightarrow> P) \<equiv> Trueprop True"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    28
by presburger
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    29
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    30
(* FIXME: needed? *)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    31
lemma all_point_1: "(\<And>z. z = b \<Longrightarrow> phi z) \<equiv> Trueprop (phi b)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    32
by presburger
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    33
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    34
lemma rev_bspec: "a \<in> A \<Longrightarrow> \<forall>z \<in> A. P z \<Longrightarrow> P a"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    35
by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    36
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    37
lemma Un_cong: "\<lbrakk>A = B; C = D\<rbrakk> \<Longrightarrow> A \<union> C = B \<union> D"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    38
by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    39
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    40
definition convol ("<_ , _>") where
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    41
"<f , g> \<equiv> %a. (f a, g a)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    42
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    43
lemma fst_convol:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    44
"fst o <f , g> = f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    45
apply(rule ext)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    46
unfolding convol_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    47
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    48
lemma snd_convol:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    49
"snd o <f , g> = g"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    50
apply(rule ext)
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    51
unfolding convol_def by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    52
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    53
lemma pointfree_idE: "f o g = id \<Longrightarrow> f (g x) = x"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    54
unfolding o_def fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    55
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    56
lemma o_bij:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    57
  assumes gf: "g o f = id" and fg: "f o g = id"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    58
  shows "bij f"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    59
unfolding bij_def inj_on_def surj_def proof safe
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    60
  fix a1 a2 assume "f a1 = f a2"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    61
  hence "g ( f a1) = g (f a2)" by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    62
  thus "a1 = a2" using gf unfolding fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    63
next
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    64
  fix b
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    65
  have "b = f (g b)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    66
  using fg unfolding fun_eq_iff by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    67
  thus "EX a. b = f a" by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    68
qed
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    69
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    70
lemma ssubst_mem: "\<lbrakk>t = s; s \<in> X\<rbrakk> \<Longrightarrow> t \<in> X" by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    71
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    72
lemma sum_case_step:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    73
  "sum_case (sum_case f' g') g (Inl p) = sum_case f' g' p"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    74
  "sum_case f (sum_case f' g') (Inr p) = sum_case f' g' p"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    75
by auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    76
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    77
lemma one_pointE: "\<lbrakk>\<And>x. s = x \<Longrightarrow> P\<rbrakk> \<Longrightarrow> P"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    78
by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    79
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    80
lemma obj_one_pointE: "\<forall>x. s = x \<longrightarrow> P \<Longrightarrow> P"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    81
by blast
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    82
49325
blanchet
parents: 49312
diff changeset
    83
lemma obj_sumE_f':
blanchet
parents: 49312
diff changeset
    84
"\<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
parents: 49312
diff changeset
    85
by (cases x) blast+
blanchet
parents: 49312
diff changeset
    86
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    87
lemma obj_sumE_f:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    88
"\<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"
49325
blanchet
parents: 49312
diff changeset
    89
by (rule allI) (rule obj_sumE_f')
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    90
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    91
lemma obj_sumE: "\<lbrakk>\<forall>x. s = Inl x \<longrightarrow> P; \<forall>x. s = Inr x \<longrightarrow> P\<rbrakk> \<Longrightarrow> P"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    92
by (cases s) auto
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    93
49325
blanchet
parents: 49312
diff changeset
    94
lemma obj_sum_step':
blanchet
parents: 49312
diff changeset
    95
"\<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
parents: 49312
diff changeset
    96
by (cases x) blast+
blanchet
parents: 49312
diff changeset
    97
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
    98
lemma obj_sum_step:
49325
blanchet
parents: 49312
diff changeset
    99
"\<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
parents: 49312
diff changeset
   100
by (rule allI) (rule obj_sum_step')
49312
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   101
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   102
lemma sum_case_if:
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   103
"sum_case f g (if p then Inl x else Inr y) = (if p then f x else g y)"
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   104
by simp
c874ff5658dc moved theorems closer to where they are used
blanchet
parents: 49309
diff changeset
   105
49309
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49308
diff changeset
   106
ML_file "Tools/bnf_fp_util.ML"
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49308
diff changeset
   107
ML_file "Tools/bnf_fp_sugar_tactics.ML"
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49308
diff changeset
   108
ML_file "Tools/bnf_fp_sugar.ML"
f20b24214ac2 split basic BNFs into really basic ones and others, and added Andreas Lochbihler's "option" BNF
blanchet
parents: 49308
diff changeset
   109
49308
6190b701e4f4 reorganized dependencies so that the sugar does not depend on GFP -- this will be essential for bootstrapping
blanchet
parents:
diff changeset
   110
end