src/HOL/Library/Quotient_Sum.thy
changeset 47624 16d433895d2e
parent 47455 26315a545e26
child 47634 091bcd569441
equal deleted inserted replaced
47623:01e4fdf9d748 47624:16d433895d2e
     1 (*  Title:      HOL/Library/Quotient_Sum.thy
     1 (*  Title:      HOL/Library/Quotient_Sum.thy
     2     Author:     Cezary Kaliszyk and Christian Urban
     2     Author:     Cezary Kaliszyk, Christian Urban and Brian Huffman
     3 *)
     3 *)
     4 
     4 
     5 header {* Quotient infrastructure for the sum type *}
     5 header {* Quotient infrastructure for the sum type *}
     6 
     6 
     7 theory Quotient_Sum
     7 theory Quotient_Sum
     8 imports Main Quotient_Syntax
     8 imports Main Quotient_Syntax
     9 begin
     9 begin
       
    10 
       
    11 subsection {* Relator for sum type *}
    10 
    12 
    11 fun
    13 fun
    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 :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
    13 where
    15 where
    14   "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
    16   "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
    32 
    34 
    33 lemma sum_map_id [id_simps]:
    35 lemma sum_map_id [id_simps]:
    34   "sum_map id id = id"
    36   "sum_map id id = id"
    35   by (simp add: id_def sum_map.identity fun_eq_iff)
    37   by (simp add: id_def sum_map.identity fun_eq_iff)
    36 
    38 
    37 lemma sum_rel_eq [id_simps]:
    39 lemma sum_rel_eq [id_simps, relator_eq]:
    38   "sum_rel (op =) (op =) = (op =)"
    40   "sum_rel (op =) (op =) = (op =)"
    39   by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
    41   by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
    40 
    42 
       
    43 lemma split_sum_all: "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
       
    44   by (metis sum.exhaust) (* TODO: move to Sum_Type.thy *)
       
    45 
       
    46 lemma split_sum_ex: "(\<exists>x. P x) \<longleftrightarrow> (\<exists>x. P (Inl x)) \<or> (\<exists>x. P (Inr x))"
       
    47   by (metis sum.exhaust) (* TODO: move to Sum_Type.thy *)
       
    48 
    41 lemma sum_reflp:
    49 lemma sum_reflp:
    42   "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
    50   "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)
    51   unfolding reflp_def split_sum_all sum_rel.simps by fast
    44 
    52 
    45 lemma sum_symp:
    53 lemma sum_symp:
    46   "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
    54   "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)
    55   unfolding symp_def split_sum_all sum_rel.simps by fast
    48 
    56 
    49 lemma sum_transp:
    57 lemma sum_transp:
    50   "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
    58   "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)
    59   unfolding transp_def split_sum_all sum_rel.simps by fast
    52 
    60 
    53 lemma sum_equivp [quot_equiv]:
    61 lemma sum_equivp [quot_equiv]:
    54   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
    62   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
    55   by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
    63   by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
    56   
    64 
       
    65 lemma right_total_sum_rel [transfer_rule]:
       
    66   "right_total R1 \<Longrightarrow> right_total R2 \<Longrightarrow> right_total (sum_rel R1 R2)"
       
    67   unfolding right_total_def split_sum_all split_sum_ex by simp
       
    68 
       
    69 lemma right_unique_sum_rel [transfer_rule]:
       
    70   "right_unique R1 \<Longrightarrow> right_unique R2 \<Longrightarrow> right_unique (sum_rel R1 R2)"
       
    71   unfolding right_unique_def split_sum_all by simp
       
    72 
       
    73 lemma bi_total_sum_rel [transfer_rule]:
       
    74   "bi_total R1 \<Longrightarrow> bi_total R2 \<Longrightarrow> bi_total (sum_rel R1 R2)"
       
    75   using assms unfolding bi_total_def split_sum_all split_sum_ex by simp
       
    76 
       
    77 lemma bi_unique_sum_rel [transfer_rule]:
       
    78   "bi_unique R1 \<Longrightarrow> bi_unique R2 \<Longrightarrow> bi_unique (sum_rel R1 R2)"
       
    79   using assms unfolding bi_unique_def split_sum_all by simp
       
    80 
       
    81 subsection {* Correspondence rules for transfer package *}
       
    82 
       
    83 lemma Inl_transfer [transfer_rule]: "(A ===> sum_rel A B) Inl Inl"
       
    84   unfolding fun_rel_def by simp
       
    85 
       
    86 lemma Inr_transfer [transfer_rule]: "(B ===> sum_rel A B) Inr Inr"
       
    87   unfolding fun_rel_def by simp
       
    88 
       
    89 lemma sum_case_transfer [transfer_rule]:
       
    90   "((A ===> C) ===> (B ===> C) ===> sum_rel A B ===> C) sum_case sum_case"
       
    91   unfolding fun_rel_def sum_rel_unfold by (simp split: sum.split)
       
    92 
       
    93 subsection {* Setup for lifting package *}
       
    94 
       
    95 lemma Quotient_sum:
       
    96   assumes "Quotient R1 Abs1 Rep1 T1"
       
    97   assumes "Quotient R2 Abs2 Rep2 T2"
       
    98   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
       
    99     (sum_map Rep1 Rep2) (sum_rel T1 T2)"
       
   100   using assms unfolding Quotient_alt_def
       
   101   by (simp add: split_sum_all)
       
   102 
       
   103 declare [[map sum = (sum_rel, Quotient_sum)]]
       
   104 
       
   105 subsection {* Rules for quotient package *}
       
   106 
    57 lemma sum_quotient [quot_thm]:
   107 lemma sum_quotient [quot_thm]:
    58   assumes q1: "Quotient3 R1 Abs1 Rep1"
   108   assumes q1: "Quotient3 R1 Abs1 Rep1"
    59   assumes q2: "Quotient3 R2 Abs2 Rep2"
   109   assumes q2: "Quotient3 R2 Abs2 Rep2"
    60   shows "Quotient3 (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
   110   shows "Quotient3 (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
    61   apply (rule Quotient3I)
   111   apply (rule Quotient3I)