src/HOL/Sum_Type.thy
changeset 37678 0040bafffdef
parent 37388 793618618f78
child 39198 f967a16dfcdd
equal deleted inserted replaced
37677:c5a8b612e571 37678:0040bafffdef
    15   "Inl_Rep a x y p \<longleftrightarrow> x = a \<and> p"
    15   "Inl_Rep a x y p \<longleftrightarrow> x = a \<and> p"
    16 
    16 
    17 definition Inr_Rep :: "'b \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool \<Rightarrow> bool" where
    17 definition Inr_Rep :: "'b \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool \<Rightarrow> bool" where
    18   "Inr_Rep b x y p \<longleftrightarrow> y = b \<and> \<not> p"
    18   "Inr_Rep b x y p \<longleftrightarrow> y = b \<and> \<not> p"
    19 
    19 
    20 typedef (sum) ('a, 'b) "+" (infixr "+" 10) = "{f. (\<exists>a. f = Inl_Rep (a::'a)) \<or> (\<exists>b. f = Inr_Rep (b::'b))}"
    20 typedef ('a, 'b) sum (infixr "+" 10) = "{f. (\<exists>a. f = Inl_Rep (a::'a)) \<or> (\<exists>b. f = Inr_Rep (b::'b))}"
    21   by auto
    21   by auto
    22 
    22 
    23 lemma Inl_RepI: "Inl_Rep a \<in> sum"
    23 lemma Inl_RepI: "Inl_Rep a \<in> sum"
    24   by (auto simp add: sum_def)
    24   by (auto simp add: sum_def)
    25 
    25 
    81   fix f 
    81   fix f 
    82   assume "s = Abs_sum f" and "f \<in> sum"
    82   assume "s = Abs_sum f" and "f \<in> sum"
    83   with assms show P by (auto simp add: sum_def Inl_def Inr_def)
    83   with assms show P by (auto simp add: sum_def Inl_def Inr_def)
    84 qed
    84 qed
    85 
    85 
    86 rep_datatype (sum) Inl Inr
    86 rep_datatype Inl Inr
    87 proof -
    87 proof -
    88   fix P
    88   fix P
    89   fix s :: "'a + 'b"
    89   fix s :: "'a + 'b"
    90   assume x: "\<And>x\<Colon>'a. P (Inl x)" and y: "\<And>y\<Colon>'b. P (Inr y)"
    90   assume x: "\<And>x\<Colon>'a. P (Inl x)" and y: "\<And>y\<Colon>'b. P (Inr y)"
    91   then show "P s" by (auto intro: sumE [of s])
    91   then show "P s" by (auto intro: sumE [of s])