src/HOL/Library/Quotient_Sum.thy
 author haftmann Tue Nov 09 14:02:13 2010 +0100 (2010-11-09) changeset 40465 2989f9f3aa10 parent 39302 d7728f65b353 child 40542 9a173a22771c permissions -rw-r--r--
more appropriate specification packages; fun_rel_def is no simp rule by default
```     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> 'a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'a + 'b \<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 primrec
```
```    20   sum_map :: "('a \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd"
```
```    21 where
```
```    22   "sum_map f1 f2 (Inl a) = Inl (f1 a)"
```
```    23 | "sum_map f1 f2 (Inr a) = Inr (f2 a)"
```
```    24
```
```    25 declare [[map sum = (sum_map, sum_rel)]]
```
```    26
```
```    27
```
```    28 text {* should probably be in @{theory Sum_Type} *}
```
```    29 lemma split_sum_all:
```
```    30   shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
```
```    31   apply(auto)
```
```    32   apply(case_tac x)
```
```    33   apply(simp_all)
```
```    34   done
```
```    35
```
```    36 lemma sum_equivp[quot_equiv]:
```
```    37   assumes a: "equivp R1"
```
```    38   assumes b: "equivp R2"
```
```    39   shows "equivp (sum_rel R1 R2)"
```
```    40   apply(rule equivpI)
```
```    41   unfolding reflp_def symp_def transp_def
```
```    42   apply(simp_all add: split_sum_all)
```
```    43   apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
```
```    44   apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
```
```    45   apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
```
```    46   done
```
```    47
```
```    48 lemma sum_quotient[quot_thm]:
```
```    49   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    50   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    51   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
```
```    52   unfolding Quotient_def
```
```    53   apply(simp add: split_sum_all)
```
```    54   apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
```
```    55   apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
```
```    56   using q1 q2
```
```    57   unfolding Quotient_def
```
```    58   apply(blast)+
```
```    59   done
```
```    60
```
```    61 lemma sum_Inl_rsp[quot_respect]:
```
```    62   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    63   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    64   shows "(R1 ===> sum_rel R1 R2) Inl Inl"
```
```    65   by auto
```
```    66
```
```    67 lemma sum_Inr_rsp[quot_respect]:
```
```    68   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    69   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    70   shows "(R2 ===> sum_rel R1 R2) Inr Inr"
```
```    71   by auto
```
```    72
```
```    73 lemma sum_Inl_prs[quot_preserve]:
```
```    74   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    75   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    76   shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
```
```    77   apply(simp add: fun_eq_iff)
```
```    78   apply(simp add: Quotient_abs_rep[OF q1])
```
```    79   done
```
```    80
```
```    81 lemma sum_Inr_prs[quot_preserve]:
```
```    82   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    83   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    84   shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
```
```    85   apply(simp add: fun_eq_iff)
```
```    86   apply(simp add: Quotient_abs_rep[OF q2])
```
```    87   done
```
```    88
```
```    89 lemma sum_map_id[id_simps]:
```
```    90   shows "sum_map id id = id"
```
```    91   by (simp add: fun_eq_iff split_sum_all)
```
```    92
```
```    93 lemma sum_rel_eq[id_simps]:
```
```    94   shows "sum_rel (op =) (op =) = (op =)"
```
```    95   by (simp add: fun_eq_iff split_sum_all)
```
```    96
```
```    97 end
```