src/HOL/Library/Quotient_Sum.thy
 author hoelzl Tue Jul 19 14:37:49 2011 +0200 (2011-07-19) changeset 43922 c6f35921056e parent 41372 551eb49a6e91 child 45802 b16f976db515 permissions -rw-r--r--
```     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 lemma sum_rel_unfold:
```
```    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
```
```    24     | _ \<Rightarrow> False)"
```
```    25   by (cases x) (cases y, simp_all)+
```
```    26
```
```    27 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"
```
```    29   by (simp add: sum_rel_unfold split: sum.split)
```
```    30
```
```    31 lemma sum_rel_map2:
```
```    32   "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"
```
```    33   by (simp add: sum_rel_unfold split: sum.split)
```
```    34
```
```    35 lemma sum_map_id [id_simps]:
```
```    36   "sum_map id id = id"
```
```    37   by (simp add: id_def sum_map.identity fun_eq_iff)
```
```    38
```
```    39 lemma sum_rel_eq [id_simps]:
```
```    40   "sum_rel (op =) (op =) = (op =)"
```
```    41   by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
```
```    42
```
```    43 lemma sum_reflp:
```
```    44   "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
```
```    45   by (auto simp add: sum_rel_unfold split: sum.splits intro!: reflpI elim: reflpE)
```
```    46
```
```    47 lemma sum_symp:
```
```    48   "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
```
```    49   by (auto simp add: sum_rel_unfold split: sum.splits intro!: sympI elim: sympE)
```
```    50
```
```    51 lemma sum_transp:
```
```    52   "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
```
```    53   by (auto simp add: sum_rel_unfold split: sum.splits intro!: transpI elim: transpE)
```
```    54
```
```    55 lemma sum_equivp [quot_equiv]:
```
```    56   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
```
```    57   by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
```
```    58
```
```    59 lemma sum_quotient [quot_thm]:
```
```    60   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    61   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    62   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
```
```    63   apply (rule QuotientI)
```
```    64   apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
```
```    65     Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
```
```    66   using Quotient_rel [OF q1] Quotient_rel [OF q2]
```
```    67   apply (simp add: sum_rel_unfold comp_def split: sum.split)
```
```    68   done
```
```    69
```
```    70 lemma sum_Inl_rsp [quot_respect]:
```
```    71   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    72   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    73   shows "(R1 ===> sum_rel R1 R2) Inl Inl"
```
```    74   by auto
```
```    75
```
```    76 lemma sum_Inr_rsp [quot_respect]:
```
```    77   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    78   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    79   shows "(R2 ===> sum_rel R1 R2) Inr Inr"
```
```    80   by auto
```
```    81
```
```    82 lemma sum_Inl_prs [quot_preserve]:
```
```    83   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    84   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    85   shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
```
```    86   apply(simp add: fun_eq_iff)
```
```    87   apply(simp add: Quotient_abs_rep[OF q1])
```
```    88   done
```
```    89
```
```    90 lemma sum_Inr_prs [quot_preserve]:
```
```    91   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    92   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    93   shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
```
```    94   apply(simp add: fun_eq_iff)
```
```    95   apply(simp add: Quotient_abs_rep[OF q2])
```
```    96   done
```
```    97
```
```    98 end
```