src/HOL/Library/Quotient_Sum.thy
author haftmann
Thu Nov 18 17:01:16 2010 +0100 (2010-11-18)
changeset 40610 70776ecfe324
parent 40542 9a173a22771c
child 40820 fd9c98ead9a9
permissions -rw-r--r--
mapper for sum type
     1 (*  Title:      HOL/Library/Quotient_Sum.thy
     2     Author:     Cezary Kaliszyk and Christian Urban
     3 *)
     4 
     5 header {* Quotient infrastructure for the sum type *}
     6 
     7 theory Quotient_Sum
     8 imports Main Quotient_Syntax
     9 begin
    10 
    11 fun
    12   sum_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
    13 where
    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"
    18 
    19 declare [[map sum = (sum_map, sum_rel)]]
    20 
    21 
    22 text {* should probably be in @{theory Sum_Type} *}
    23 lemma split_sum_all:
    24   shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
    25   apply(auto)
    26   apply(case_tac x)
    27   apply(simp_all)
    28   done
    29 
    30 lemma sum_equivp[quot_equiv]:
    31   assumes a: "equivp R1"
    32   assumes b: "equivp R2"
    33   shows "equivp (sum_rel R1 R2)"
    34   apply(rule equivpI)
    35   unfolding reflp_def symp_def transp_def
    36   apply(simp_all add: split_sum_all)
    37   apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
    38   apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
    39   apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
    40   done
    41 
    42 lemma sum_quotient[quot_thm]:
    43   assumes q1: "Quotient R1 Abs1 Rep1"
    44   assumes q2: "Quotient R2 Abs2 Rep2"
    45   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
    46   unfolding Quotient_def
    47   apply(simp add: split_sum_all)
    48   apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
    49   apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
    50   using q1 q2
    51   unfolding Quotient_def
    52   apply(blast)+
    53   done
    54 
    55 lemma sum_Inl_rsp[quot_respect]:
    56   assumes q1: "Quotient R1 Abs1 Rep1"
    57   assumes q2: "Quotient R2 Abs2 Rep2"
    58   shows "(R1 ===> sum_rel R1 R2) Inl Inl"
    59   by auto
    60 
    61 lemma sum_Inr_rsp[quot_respect]:
    62   assumes q1: "Quotient R1 Abs1 Rep1"
    63   assumes q2: "Quotient R2 Abs2 Rep2"
    64   shows "(R2 ===> sum_rel R1 R2) Inr Inr"
    65   by auto
    66 
    67 lemma sum_Inl_prs[quot_preserve]:
    68   assumes q1: "Quotient R1 Abs1 Rep1"
    69   assumes q2: "Quotient R2 Abs2 Rep2"
    70   shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
    71   apply(simp add: fun_eq_iff)
    72   apply(simp add: Quotient_abs_rep[OF q1])
    73   done
    74 
    75 lemma sum_Inr_prs[quot_preserve]:
    76   assumes q1: "Quotient R1 Abs1 Rep1"
    77   assumes q2: "Quotient R2 Abs2 Rep2"
    78   shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
    79   apply(simp add: fun_eq_iff)
    80   apply(simp add: Quotient_abs_rep[OF q2])
    81   done
    82 
    83 lemma sum_map_id[id_simps]:
    84   shows "sum_map id id = id"
    85   by (simp add: fun_eq_iff split_sum_all)
    86 
    87 lemma sum_rel_eq[id_simps]:
    88   shows "sum_rel (op =) (op =) = (op =)"
    89   by (simp add: fun_eq_iff split_sum_all)
    90 
    91 end