src/HOL/Library/Quotient_Sum.thy
 author huffman Fri Mar 30 12:32:35 2012 +0200 (2012-03-30) changeset 47220 52426c62b5d0 parent 47094 1a7ad2601cb5 child 47308 9caab698dbe4 permissions -rw-r--r--
replace lemmas eval_nat_numeral with a simpler reformulation
```     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 lemma sum_rel_unfold:
```
```    20   "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
```
```    21     | (Inr x, Inr y) \<Rightarrow> R2 x y
```
```    22     | _ \<Rightarrow> False)"
```
```    23   by (cases x) (cases y, simp_all)+
```
```    24
```
```    25 lemma sum_rel_map1:
```
```    26   "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"
```
```    27   by (simp add: sum_rel_unfold split: sum.split)
```
```    28
```
```    29 lemma sum_rel_map2:
```
```    30   "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"
```
```    31   by (simp add: sum_rel_unfold split: sum.split)
```
```    32
```
```    33 lemma sum_map_id [id_simps]:
```
```    34   "sum_map id id = id"
```
```    35   by (simp add: id_def sum_map.identity fun_eq_iff)
```
```    36
```
```    37 lemma sum_rel_eq [id_simps]:
```
```    38   "sum_rel (op =) (op =) = (op =)"
```
```    39   by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
```
```    40
```
```    41 lemma sum_reflp:
```
```    42   "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)
```
```    44
```
```    45 lemma sum_symp:
```
```    46   "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)
```
```    48
```
```    49 lemma sum_transp:
```
```    50   "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)
```
```    52
```
```    53 lemma sum_equivp [quot_equiv]:
```
```    54   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
```
```    55   by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
```
```    56
```
```    57 lemma sum_quotient [quot_thm]:
```
```    58   assumes q1: "Quotient R1 Abs1 Rep1"
```
```    59   assumes q2: "Quotient R2 Abs2 Rep2"
```
```    60   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
```
```    61   apply (rule QuotientI)
```
```    62   apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
```
```    63     Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
```
```    64   using Quotient_rel [OF q1] Quotient_rel [OF q2]
```
```    65   apply (simp add: sum_rel_unfold comp_def split: sum.split)
```
```    66   done
```
```    67
```
```    68 declare [[map sum = (sum_rel, sum_quotient)]]
```
```    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
```