src/HOL/Library/Quotient_Sum.thy
 author Andreas Lochbihler Fri Sep 20 10:09:16 2013 +0200 (2013-09-20) changeset 53745 788730ab7da4 parent 53026 e1a548c11845 child 55564 e81ee43ab290 permissions -rw-r--r--
prefer Code.abort over code_abort
```     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 subsection {* Rules for the Quotient package *}
```
```    12
```
```    13 lemma sum_rel_map1:
```
```    14   "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"
```
```    15   by (simp add: sum_rel_def split: sum.split)
```
```    16
```
```    17 lemma sum_rel_map2:
```
```    18   "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"
```
```    19   by (simp add: sum_rel_def split: sum.split)
```
```    20
```
```    21 lemma sum_map_id [id_simps]:
```
```    22   "sum_map id id = id"
```
```    23   by (simp add: id_def sum_map.identity fun_eq_iff)
```
```    24
```
```    25 lemma sum_rel_eq [id_simps]:
```
```    26   "sum_rel (op =) (op =) = (op =)"
```
```    27   by (simp add: sum_rel_def fun_eq_iff split: sum.split)
```
```    28
```
```    29 lemma sum_symp:
```
```    30   "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
```
```    31   unfolding symp_def split_sum_all sum_rel_simps by fast
```
```    32
```
```    33 lemma sum_transp:
```
```    34   "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
```
```    35   unfolding transp_def split_sum_all sum_rel_simps by fast
```
```    36
```
```    37 lemma sum_equivp [quot_equiv]:
```
```    38   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
```
```    39   by (blast intro: equivpI reflp_sum_rel sum_symp sum_transp elim: equivpE)
```
```    40
```
```    41 lemma sum_quotient [quot_thm]:
```
```    42   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```    43   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```    44   shows "Quotient3 (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
```
```    45   apply (rule Quotient3I)
```
```    46   apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
```
```    47     Quotient3_abs_rep [OF q1] Quotient3_rel_rep [OF q1] Quotient3_abs_rep [OF q2] Quotient3_rel_rep [OF q2])
```
```    48   using Quotient3_rel [OF q1] Quotient3_rel [OF q2]
```
```    49   apply (simp add: sum_rel_def comp_def split: sum.split)
```
```    50   done
```
```    51
```
```    52 declare [[mapQ3 sum = (sum_rel, sum_quotient)]]
```
```    53
```
```    54 lemma sum_Inl_rsp [quot_respect]:
```
```    55   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```    56   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```    57   shows "(R1 ===> sum_rel R1 R2) Inl Inl"
```
```    58   by auto
```
```    59
```
```    60 lemma sum_Inr_rsp [quot_respect]:
```
```    61   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```    62   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```    63   shows "(R2 ===> sum_rel R1 R2) Inr Inr"
```
```    64   by auto
```
```    65
```
```    66 lemma sum_Inl_prs [quot_preserve]:
```
```    67   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```    68   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```    69   shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
```
```    70   apply(simp add: fun_eq_iff)
```
```    71   apply(simp add: Quotient3_abs_rep[OF q1])
```
```    72   done
```
```    73
```
```    74 lemma sum_Inr_prs [quot_preserve]:
```
```    75   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```    76   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```    77   shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
```
```    78   apply(simp add: fun_eq_iff)
```
```    79   apply(simp add: Quotient3_abs_rep[OF q2])
```
```    80   done
```
```    81
```
```    82 end
```