src/HOL/Library/Quotient_Sum.thy
changeset 51956 a4d81cdebf8b
parent 51377 7da251a6c16e
child 51994 82cc2aeb7d13
equal deleted inserted replaced
51955:04d9381bebff 51956:a4d81cdebf8b
    21 lemma sum_rel_unfold:
    21 lemma sum_rel_unfold:
    22   "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
    22   "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
    23     | (Inr x, Inr y) \<Rightarrow> R2 x y
    23     | (Inr x, Inr y) \<Rightarrow> R2 x y
    24     | _ \<Rightarrow> False)"
    24     | _ \<Rightarrow> False)"
    25   by (cases x) (cases y, simp_all)+
    25   by (cases x) (cases y, simp_all)+
       
    26 
       
    27 fun sum_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> bool"
       
    28 where
       
    29   "sum_pred P1 P2 (Inl a) = P1 a"
       
    30 | "sum_pred P1 P2 (Inr a) = P2 a"
       
    31 
       
    32 lemma sum_pred_unfold:
       
    33   "sum_pred P1 P2 x = (case x of Inl x \<Rightarrow> P1 x
       
    34     | Inr x \<Rightarrow> P2 x)"
       
    35 by (cases x) simp_all
    26 
    36 
    27 lemma sum_rel_map1:
    37 lemma sum_rel_map1:
    28   "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"
    38   "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"
    29   by (simp add: sum_rel_unfold split: sum.split)
    39   by (simp add: sum_rel_unfold split: sum.split)
    30 
    40 
    53 using assms by (auto simp: sum_rel_unfold split: sum.splits)
    63 using assms by (auto simp: sum_rel_unfold split: sum.splits)
    54 
    64 
    55 lemma sum_rel_OO[relator_distr]:
    65 lemma sum_rel_OO[relator_distr]:
    56   "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
    66   "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
    57 by (rule ext)+ (auto simp add: sum_rel_unfold OO_def split_sum_ex split: sum.split)
    67 by (rule ext)+ (auto simp add: sum_rel_unfold OO_def split_sum_ex split: sum.split)
       
    68 
       
    69 lemma Domainp_sum[relator_domain]:
       
    70   assumes "Domainp R1 = P1"
       
    71   assumes "Domainp R2 = P2"
       
    72   shows "Domainp (sum_rel R1 R2) = (sum_pred P1 P2)"
       
    73 using assms
       
    74 by (auto simp add: Domainp_iff split_sum_ex sum_pred_unfold iff: fun_eq_iff split: sum.split)
    58 
    75 
    59 lemma sum_reflp[reflexivity_rule]:
    76 lemma sum_reflp[reflexivity_rule]:
    60   "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
    77   "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
    61   unfolding reflp_def split_sum_all sum_rel.simps by fast
    78   unfolding reflp_def split_sum_all sum_rel.simps by fast
    62 
    79 
   114   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
   131   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
   115     (sum_map Rep1 Rep2) (sum_rel T1 T2)"
   132     (sum_map Rep1 Rep2) (sum_rel T1 T2)"
   116   using assms unfolding Quotient_alt_def
   133   using assms unfolding Quotient_alt_def
   117   by (simp add: split_sum_all)
   134   by (simp add: split_sum_all)
   118 
   135 
   119 fun sum_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> bool"
       
   120 where
       
   121   "sum_pred R1 R2 (Inl a) = R1 a"
       
   122 | "sum_pred R1 R2 (Inr a) = R2 a"
       
   123 
       
   124 lemma sum_invariant_commute [invariant_commute]: 
   136 lemma sum_invariant_commute [invariant_commute]: 
   125   "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
   137   "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
   126   apply (simp add: fun_eq_iff Lifting.invariant_def)
   138   by (auto simp add: fun_eq_iff Lifting.invariant_def sum_rel_unfold sum_pred_unfold split: sum.split)
   127   apply (intro allI) 
       
   128   apply (case_tac x rule: sum.exhaust)
       
   129   apply (case_tac xa rule: sum.exhaust)
       
   130   apply auto[2]
       
   131   apply (case_tac xa rule: sum.exhaust)
       
   132   apply auto
       
   133 done
       
   134 
   139 
   135 subsection {* Rules for quotient package *}
   140 subsection {* Rules for quotient package *}
   136 
   141 
   137 lemma sum_quotient [quot_thm]:
   142 lemma sum_quotient [quot_thm]:
   138   assumes q1: "Quotient3 R1 Abs1 Rep1"
   143   assumes q1: "Quotient3 R1 Abs1 Rep1"