1 (* Title: HOL/Library/Quotient_Sum.thy
2 Author: Cezary Kaliszyk and Christian Urban
5 header {* Quotient infrastructure for the sum type *}
8 imports Main Quotient_Syntax
12 sum_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
14 "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
15 | "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
16 | "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
17 | "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
20 "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
21 | (Inr x, Inr y) \<Rightarrow> R2 x y
22 | _ \<Rightarrow> False)"
23 by (cases x) (cases y, simp_all)+
26 "sum_rel R1 R2 (sum_map f1 f2 x) y \<longleftrightarrow> sum_rel (\<lambda>x. R1 (f1 x)) (\<lambda>x. R2 (f2 x)) x y"
27 by (simp add: sum_rel_unfold split: sum.split)
30 "sum_rel R1 R2 x (sum_map f1 f2 y) \<longleftrightarrow> sum_rel (\<lambda>x y. R1 x (f1 y)) (\<lambda>x y. R2 x (f2 y)) x y"
31 by (simp add: sum_rel_unfold split: sum.split)
33 lemma sum_map_id [id_simps]:
35 by (simp add: id_def sum_map.identity fun_eq_iff)
37 lemma sum_rel_eq [id_simps]:
38 "sum_rel (op =) (op =) = (op =)"
39 by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
42 "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
43 by (auto simp add: sum_rel_unfold split: sum.splits intro!: reflpI elim: reflpE)
46 "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
47 by (auto simp add: sum_rel_unfold split: sum.splits intro!: sympI elim: sympE)
50 "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
51 by (auto simp add: sum_rel_unfold split: sum.splits intro!: transpI elim: transpE)
53 lemma sum_equivp [quot_equiv]:
54 "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
55 by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
57 lemma sum_quotient [quot_thm]:
58 assumes q1: "Quotient R1 Abs1 Rep1"
59 assumes q2: "Quotient R2 Abs2 Rep2"
60 shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
61 apply (rule QuotientI)
62 apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
63 Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
64 using Quotient_rel [OF q1] Quotient_rel [OF q2]
65 apply (simp add: sum_rel_unfold comp_def split: sum.split)
68 declare [[map sum = (sum_rel, sum_quotient)]]
70 lemma sum_Inl_rsp [quot_respect]:
71 assumes q1: "Quotient R1 Abs1 Rep1"
72 assumes q2: "Quotient R2 Abs2 Rep2"
73 shows "(R1 ===> sum_rel R1 R2) Inl Inl"
76 lemma sum_Inr_rsp [quot_respect]:
77 assumes q1: "Quotient R1 Abs1 Rep1"
78 assumes q2: "Quotient R2 Abs2 Rep2"
79 shows "(R2 ===> sum_rel R1 R2) Inr Inr"
82 lemma sum_Inl_prs [quot_preserve]:
83 assumes q1: "Quotient R1 Abs1 Rep1"
84 assumes q2: "Quotient R2 Abs2 Rep2"
85 shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
86 apply(simp add: fun_eq_iff)
87 apply(simp add: Quotient_abs_rep[OF q1])
90 lemma sum_Inr_prs [quot_preserve]:
91 assumes q1: "Quotient R1 Abs1 Rep1"
92 assumes q2: "Quotient R2 Abs2 Rep2"
93 shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
94 apply(simp add: fun_eq_iff)
95 apply(simp add: Quotient_abs_rep[OF q2])