src/HOL/Library/Quotient_Sum.thy
changeset 35222 4f1fba00f66d
child 35243 024fef37a65d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Quotient_Sum.thy	Fri Feb 19 13:54:19 2010 +0100
     1.3 @@ -0,0 +1,96 @@
     1.4 +(*  Title:      Quotient_Sum.thy
     1.5 +    Author:     Cezary Kaliszyk and Christian Urban
     1.6 +*)
     1.7 +theory Quotient_Sum
     1.8 +imports Main Quotient_Syntax
     1.9 +begin
    1.10 +
    1.11 +section {* Quotient infrastructure for the sum type. *}
    1.12 +
    1.13 +fun
    1.14 +  sum_rel
    1.15 +where
    1.16 +  "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
    1.17 +| "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
    1.18 +| "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
    1.19 +| "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
    1.20 +
    1.21 +fun
    1.22 +  sum_map
    1.23 +where
    1.24 +  "sum_map f1 f2 (Inl a) = Inl (f1 a)"
    1.25 +| "sum_map f1 f2 (Inr a) = Inr (f2 a)"
    1.26 +
    1.27 +declare [[map "+" = (sum_map, sum_rel)]]
    1.28 +
    1.29 +
    1.30 +text {* should probably be in Sum_Type.thy *}
    1.31 +lemma split_sum_all:
    1.32 +  shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
    1.33 +  apply(auto)
    1.34 +  apply(case_tac x)
    1.35 +  apply(simp_all)
    1.36 +  done
    1.37 +
    1.38 +lemma sum_equivp[quot_equiv]:
    1.39 +  assumes a: "equivp R1"
    1.40 +  assumes b: "equivp R2"
    1.41 +  shows "equivp (sum_rel R1 R2)"
    1.42 +  apply(rule equivpI)
    1.43 +  unfolding reflp_def symp_def transp_def
    1.44 +  apply(simp_all add: split_sum_all)
    1.45 +  apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
    1.46 +  apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
    1.47 +  apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
    1.48 +  done
    1.49 +
    1.50 +lemma sum_quotient[quot_thm]:
    1.51 +  assumes q1: "Quotient R1 Abs1 Rep1"
    1.52 +  assumes q2: "Quotient R2 Abs2 Rep2"
    1.53 +  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
    1.54 +  unfolding Quotient_def
    1.55 +  apply(simp add: split_sum_all)
    1.56 +  apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
    1.57 +  apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
    1.58 +  using q1 q2
    1.59 +  unfolding Quotient_def
    1.60 +  apply(blast)+
    1.61 +  done
    1.62 +
    1.63 +lemma sum_Inl_rsp[quot_respect]:
    1.64 +  assumes q1: "Quotient R1 Abs1 Rep1"
    1.65 +  assumes q2: "Quotient R2 Abs2 Rep2"
    1.66 +  shows "(R1 ===> sum_rel R1 R2) Inl Inl"
    1.67 +  by simp
    1.68 +
    1.69 +lemma sum_Inr_rsp[quot_respect]:
    1.70 +  assumes q1: "Quotient R1 Abs1 Rep1"
    1.71 +  assumes q2: "Quotient R2 Abs2 Rep2"
    1.72 +  shows "(R2 ===> sum_rel R1 R2) Inr Inr"
    1.73 +  by simp
    1.74 +
    1.75 +lemma sum_Inl_prs[quot_preserve]:
    1.76 +  assumes q1: "Quotient R1 Abs1 Rep1"
    1.77 +  assumes q2: "Quotient R2 Abs2 Rep2"
    1.78 +  shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
    1.79 +  apply(simp add: expand_fun_eq)
    1.80 +  apply(simp add: Quotient_abs_rep[OF q1])
    1.81 +  done
    1.82 +
    1.83 +lemma sum_Inr_prs[quot_preserve]:
    1.84 +  assumes q1: "Quotient R1 Abs1 Rep1"
    1.85 +  assumes q2: "Quotient R2 Abs2 Rep2"
    1.86 +  shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
    1.87 +  apply(simp add: expand_fun_eq)
    1.88 +  apply(simp add: Quotient_abs_rep[OF q2])
    1.89 +  done
    1.90 +
    1.91 +lemma sum_map_id[id_simps]:
    1.92 +  shows "sum_map id id = id"
    1.93 +  by (simp add: expand_fun_eq split_sum_all)
    1.94 +
    1.95 +lemma sum_rel_eq[id_simps]:
    1.96 +  shows "sum_rel (op =) (op =) = (op =)"
    1.97 +  by (simp add: expand_fun_eq split_sum_all)
    1.98 +
    1.99 +end