src/HOL/Library/Quotient_Sum.thy
 author kuncar Tue Aug 13 15:59:22 2013 +0200 (2013-08-13) changeset 53010 ec5e6f69bd65 parent 51994 82cc2aeb7d13 child 53012 cb82606b8215 permissions -rw-r--r--
move useful lemmas to Main
```     1 (*  Title:      HOL/Library/Quotient_Sum.thy
```
```     2     Author:     Cezary Kaliszyk, Christian Urban and Brian Huffman
```
```     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 {* Relator for sum type *}
```
```    12
```
```    13 fun
```
```    14   sum_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
```
```    15 where
```
```    16   "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
```
```    17 | "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
```
```    18 | "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
```
```    19 | "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
```
```    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 fun sum_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> bool"
```
```    28 where
```
```    29   "sum_pred P1 P2 (Inl a) = P1 a"
```
```    30 | "sum_pred P1 P2 (Inr a) = P2 a"
```
```    31
```
```    32 lemma sum_pred_unfold:
```
```    33   "sum_pred P1 P2 x = (case x of Inl x \<Rightarrow> P1 x
```
```    34     | Inr x \<Rightarrow> P2 x)"
```
```    35 by (cases x) simp_all
```
```    36
```
```    37 lemma sum_rel_map1:
```
```    38   "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"
```
```    39   by (simp add: sum_rel_unfold split: sum.split)
```
```    40
```
```    41 lemma sum_rel_map2:
```
```    42   "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"
```
```    43   by (simp add: sum_rel_unfold split: sum.split)
```
```    44
```
```    45 lemma sum_map_id [id_simps]:
```
```    46   "sum_map id id = id"
```
```    47   by (simp add: id_def sum_map.identity fun_eq_iff)
```
```    48
```
```    49 lemma sum_rel_eq [id_simps, relator_eq]:
```
```    50   "sum_rel (op =) (op =) = (op =)"
```
```    51   by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
```
```    52
```
```    53 lemma sum_rel_mono[relator_mono]:
```
```    54   assumes "A \<le> C"
```
```    55   assumes "B \<le> D"
```
```    56   shows "(sum_rel A B) \<le> (sum_rel C D)"
```
```    57 using assms by (auto simp: sum_rel_unfold split: sum.splits)
```
```    58
```
```    59 lemma sum_rel_OO[relator_distr]:
```
```    60   "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
```
```    61 by (rule ext)+ (auto simp add: sum_rel_unfold OO_def split_sum_ex split: sum.split)
```
```    62
```
```    63 lemma Domainp_sum[relator_domain]:
```
```    64   assumes "Domainp R1 = P1"
```
```    65   assumes "Domainp R2 = P2"
```
```    66   shows "Domainp (sum_rel R1 R2) = (sum_pred P1 P2)"
```
```    67 using assms
```
```    68 by (auto simp add: Domainp_iff split_sum_ex sum_pred_unfold iff: fun_eq_iff split: sum.split)
```
```    69
```
```    70 lemma reflp_sum_rel[reflexivity_rule]:
```
```    71   "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
```
```    72   unfolding reflp_def split_sum_all sum_rel.simps by fast
```
```    73
```
```    74 lemma left_total_sum_rel[reflexivity_rule]:
```
```    75   "left_total R1 \<Longrightarrow> left_total R2 \<Longrightarrow> left_total (sum_rel R1 R2)"
```
```    76   using assms unfolding left_total_def split_sum_all split_sum_ex by simp
```
```    77
```
```    78 lemma left_unique_sum_rel [reflexivity_rule]:
```
```    79   "left_unique R1 \<Longrightarrow> left_unique R2 \<Longrightarrow> left_unique (sum_rel R1 R2)"
```
```    80   using assms unfolding left_unique_def split_sum_all by simp
```
```    81
```
```    82 lemma sum_symp:
```
```    83   "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
```
```    84   unfolding symp_def split_sum_all sum_rel.simps by fast
```
```    85
```
```    86 lemma sum_transp:
```
```    87   "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
```
```    88   unfolding transp_def split_sum_all sum_rel.simps by fast
```
```    89
```
```    90 lemma sum_equivp [quot_equiv]:
```
```    91   "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
```
```    92   by (blast intro: equivpI reflp_sum_rel sum_symp sum_transp elim: equivpE)
```
```    93
```
```    94 lemma right_total_sum_rel [transfer_rule]:
```
```    95   "right_total R1 \<Longrightarrow> right_total R2 \<Longrightarrow> right_total (sum_rel R1 R2)"
```
```    96   unfolding right_total_def split_sum_all split_sum_ex by simp
```
```    97
```
```    98 lemma right_unique_sum_rel [transfer_rule]:
```
```    99   "right_unique R1 \<Longrightarrow> right_unique R2 \<Longrightarrow> right_unique (sum_rel R1 R2)"
```
```   100   unfolding right_unique_def split_sum_all by simp
```
```   101
```
```   102 lemma bi_total_sum_rel [transfer_rule]:
```
```   103   "bi_total R1 \<Longrightarrow> bi_total R2 \<Longrightarrow> bi_total (sum_rel R1 R2)"
```
```   104   using assms unfolding bi_total_def split_sum_all split_sum_ex by simp
```
```   105
```
```   106 lemma bi_unique_sum_rel [transfer_rule]:
```
```   107   "bi_unique R1 \<Longrightarrow> bi_unique R2 \<Longrightarrow> bi_unique (sum_rel R1 R2)"
```
```   108   using assms unfolding bi_unique_def split_sum_all by simp
```
```   109
```
```   110 subsection {* Transfer rules for transfer package *}
```
```   111
```
```   112 lemma Inl_transfer [transfer_rule]: "(A ===> sum_rel A B) Inl Inl"
```
```   113   unfolding fun_rel_def by simp
```
```   114
```
```   115 lemma Inr_transfer [transfer_rule]: "(B ===> sum_rel A B) Inr Inr"
```
```   116   unfolding fun_rel_def by simp
```
```   117
```
```   118 lemma sum_case_transfer [transfer_rule]:
```
```   119   "((A ===> C) ===> (B ===> C) ===> sum_rel A B ===> C) sum_case sum_case"
```
```   120   unfolding fun_rel_def sum_rel_unfold by (simp split: sum.split)
```
```   121
```
```   122 subsection {* Setup for lifting package *}
```
```   123
```
```   124 lemma Quotient_sum[quot_map]:
```
```   125   assumes "Quotient R1 Abs1 Rep1 T1"
```
```   126   assumes "Quotient R2 Abs2 Rep2 T2"
```
```   127   shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
```
```   128     (sum_map Rep1 Rep2) (sum_rel T1 T2)"
```
```   129   using assms unfolding Quotient_alt_def
```
```   130   by (simp add: split_sum_all)
```
```   131
```
```   132 lemma sum_invariant_commute [invariant_commute]:
```
```   133   "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
```
```   134   by (auto simp add: fun_eq_iff Lifting.invariant_def sum_rel_unfold sum_pred_unfold split: sum.split)
```
```   135
```
```   136 subsection {* Rules for quotient package *}
```
```   137
```
```   138 lemma sum_quotient [quot_thm]:
```
```   139   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```   140   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```   141   shows "Quotient3 (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
```
```   142   apply (rule Quotient3I)
```
```   143   apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
```
```   144     Quotient3_abs_rep [OF q1] Quotient3_rel_rep [OF q1] Quotient3_abs_rep [OF q2] Quotient3_rel_rep [OF q2])
```
```   145   using Quotient3_rel [OF q1] Quotient3_rel [OF q2]
```
```   146   apply (simp add: sum_rel_unfold comp_def split: sum.split)
```
```   147   done
```
```   148
```
```   149 declare [[mapQ3 sum = (sum_rel, sum_quotient)]]
```
```   150
```
```   151 lemma sum_Inl_rsp [quot_respect]:
```
```   152   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```   153   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```   154   shows "(R1 ===> sum_rel R1 R2) Inl Inl"
```
```   155   by auto
```
```   156
```
```   157 lemma sum_Inr_rsp [quot_respect]:
```
```   158   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```   159   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```   160   shows "(R2 ===> sum_rel R1 R2) Inr Inr"
```
```   161   by auto
```
```   162
```
```   163 lemma sum_Inl_prs [quot_preserve]:
```
```   164   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```   165   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```   166   shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
```
```   167   apply(simp add: fun_eq_iff)
```
```   168   apply(simp add: Quotient3_abs_rep[OF q1])
```
```   169   done
```
```   170
```
```   171 lemma sum_Inr_prs [quot_preserve]:
```
```   172   assumes q1: "Quotient3 R1 Abs1 Rep1"
```
```   173   assumes q2: "Quotient3 R2 Abs2 Rep2"
```
```   174   shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
```
```   175   apply(simp add: fun_eq_iff)
```
```   176   apply(simp add: Quotient3_abs_rep[OF q2])
```
```   177   done
```
```   178
```
```   179 end
```