src/HOL/Library/Quotient_Sum.thy
 author nipkow Mon, 13 Sep 2010 11:13:15 +0200 changeset 39302 d7728f65b353 parent 39198 f967a16dfcdd child 40465 2989f9f3aa10 permissions -rw-r--r--
renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
```
(*  Title:      HOL/Library/Quotient_Sum.thy
Author:     Cezary Kaliszyk and Christian Urban
*)

header {* Quotient infrastructure for the sum type *}

theory Quotient_Sum
imports Main Quotient_Syntax
begin

fun
sum_rel
where
"sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
| "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
| "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
| "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"

fun
sum_map
where
"sum_map f1 f2 (Inl a) = Inl (f1 a)"
| "sum_map f1 f2 (Inr a) = Inr (f2 a)"

declare [[map sum = (sum_map, sum_rel)]]

text {* should probably be in @{theory Sum_Type} *}
lemma split_sum_all:
shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
apply(auto)
apply(case_tac x)
apply(simp_all)
done

lemma sum_equivp[quot_equiv]:
assumes a: "equivp R1"
assumes b: "equivp R2"
shows "equivp (sum_rel R1 R2)"
apply(rule equivpI)
unfolding reflp_def symp_def transp_def
apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
done

lemma sum_quotient[quot_thm]:
assumes q1: "Quotient R1 Abs1 Rep1"
assumes q2: "Quotient R2 Abs2 Rep2"
shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
unfolding Quotient_def
apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
using q1 q2
unfolding Quotient_def
apply(blast)+
done

lemma sum_Inl_rsp[quot_respect]:
assumes q1: "Quotient R1 Abs1 Rep1"
assumes q2: "Quotient R2 Abs2 Rep2"
shows "(R1 ===> sum_rel R1 R2) Inl Inl"
by simp

lemma sum_Inr_rsp[quot_respect]:
assumes q1: "Quotient R1 Abs1 Rep1"
assumes q2: "Quotient R2 Abs2 Rep2"
shows "(R2 ===> sum_rel R1 R2) Inr Inr"
by simp

lemma sum_Inl_prs[quot_preserve]:
assumes q1: "Quotient R1 Abs1 Rep1"
assumes q2: "Quotient R2 Abs2 Rep2"
shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
done

lemma sum_Inr_prs[quot_preserve]:
assumes q1: "Quotient R1 Abs1 Rep1"
assumes q2: "Quotient R2 Abs2 Rep2"
shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"