src/HOL/Library/Quotient_Product.thy
author haftmann
Tue Feb 19 19:44:10 2013 +0100 (2013-02-19)
changeset 51188 9b5bf1a9a710
parent 47982 7aa35601ff65
child 51377 7da251a6c16e
permissions -rw-r--r--
dropped spurious left-over from 0a2371e7ced3
     1 (*  Title:      HOL/Library/Quotient_Product.thy
     2     Author:     Cezary Kaliszyk, Christian Urban and Brian Huffman
     3 *)
     4 
     5 header {* Quotient infrastructure for the product type *}
     6 
     7 theory Quotient_Product
     8 imports Main Quotient_Syntax
     9 begin
    10 
    11 subsection {* Relator for product type *}
    12 
    13 definition
    14   prod_rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('c \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'c \<Rightarrow> 'b \<times> 'd \<Rightarrow> bool"
    15 where
    16   "prod_rel R1 R2 = (\<lambda>(a, b) (c, d). R1 a c \<and> R2 b d)"
    17 
    18 lemma prod_rel_apply [simp]:
    19   "prod_rel R1 R2 (a, b) (c, d) \<longleftrightarrow> R1 a c \<and> R2 b d"
    20   by (simp add: prod_rel_def)
    21 
    22 lemma map_pair_id [id_simps]:
    23   shows "map_pair id id = id"
    24   by (simp add: fun_eq_iff)
    25 
    26 lemma prod_rel_eq [id_simps, relator_eq]:
    27   shows "prod_rel (op =) (op =) = (op =)"
    28   by (simp add: fun_eq_iff)
    29 
    30 lemma prod_reflp [reflexivity_rule]:
    31   assumes "reflp R1"
    32   assumes "reflp R2"
    33   shows "reflp (prod_rel R1 R2)"
    34 using assms by (auto intro!: reflpI elim: reflpE)
    35 
    36 lemma prod_left_total [reflexivity_rule]:
    37   assumes "left_total R1"
    38   assumes "left_total R2"
    39   shows "left_total (prod_rel R1 R2)"
    40 using assms by (auto intro!: left_totalI elim!: left_totalE)
    41 
    42 lemma prod_equivp [quot_equiv]:
    43   assumes "equivp R1"
    44   assumes "equivp R2"
    45   shows "equivp (prod_rel R1 R2)"
    46   using assms by (auto intro!: equivpI reflpI sympI transpI elim!: equivpE elim: reflpE sympE transpE)
    47 
    48 lemma right_total_prod_rel [transfer_rule]:
    49   assumes "right_total R1" and "right_total R2"
    50   shows "right_total (prod_rel R1 R2)"
    51   using assms unfolding right_total_def prod_rel_def by auto
    52 
    53 lemma right_unique_prod_rel [transfer_rule]:
    54   assumes "right_unique R1" and "right_unique R2"
    55   shows "right_unique (prod_rel R1 R2)"
    56   using assms unfolding right_unique_def prod_rel_def by auto
    57 
    58 lemma bi_total_prod_rel [transfer_rule]:
    59   assumes "bi_total R1" and "bi_total R2"
    60   shows "bi_total (prod_rel R1 R2)"
    61   using assms unfolding bi_total_def prod_rel_def by auto
    62 
    63 lemma bi_unique_prod_rel [transfer_rule]:
    64   assumes "bi_unique R1" and "bi_unique R2"
    65   shows "bi_unique (prod_rel R1 R2)"
    66   using assms unfolding bi_unique_def prod_rel_def by auto
    67 
    68 subsection {* Transfer rules for transfer package *}
    69 
    70 lemma Pair_transfer [transfer_rule]: "(A ===> B ===> prod_rel A B) Pair Pair"
    71   unfolding fun_rel_def prod_rel_def by simp
    72 
    73 lemma fst_transfer [transfer_rule]: "(prod_rel A B ===> A) fst fst"
    74   unfolding fun_rel_def prod_rel_def by simp
    75 
    76 lemma snd_transfer [transfer_rule]: "(prod_rel A B ===> B) snd snd"
    77   unfolding fun_rel_def prod_rel_def by simp
    78 
    79 lemma prod_case_transfer [transfer_rule]:
    80   "((A ===> B ===> C) ===> prod_rel A B ===> C) prod_case prod_case"
    81   unfolding fun_rel_def prod_rel_def by simp
    82 
    83 lemma curry_transfer [transfer_rule]:
    84   "((prod_rel A B ===> C) ===> A ===> B ===> C) curry curry"
    85   unfolding curry_def by transfer_prover
    86 
    87 lemma map_pair_transfer [transfer_rule]:
    88   "((A ===> C) ===> (B ===> D) ===> prod_rel A B ===> prod_rel C D)
    89     map_pair map_pair"
    90   unfolding map_pair_def [abs_def] by transfer_prover
    91 
    92 lemma prod_rel_transfer [transfer_rule]:
    93   "((A ===> B ===> op =) ===> (C ===> D ===> op =) ===>
    94     prod_rel A C ===> prod_rel B D ===> op =) prod_rel prod_rel"
    95   unfolding fun_rel_def by auto
    96 
    97 subsection {* Setup for lifting package *}
    98 
    99 lemma Quotient_prod[quot_map]:
   100   assumes "Quotient R1 Abs1 Rep1 T1"
   101   assumes "Quotient R2 Abs2 Rep2 T2"
   102   shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2)
   103     (map_pair Rep1 Rep2) (prod_rel T1 T2)"
   104   using assms unfolding Quotient_alt_def by auto
   105 
   106 definition prod_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool"
   107 where "prod_pred R1 R2 = (\<lambda>(a, b). R1 a \<and> R2 b)"
   108 
   109 lemma prod_invariant_commute [invariant_commute]: 
   110   "prod_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (prod_pred P1 P2)"
   111   apply (simp add: fun_eq_iff prod_rel_def prod_pred_def Lifting.invariant_def) 
   112   apply blast
   113 done
   114 
   115 subsection {* Rules for quotient package *}
   116 
   117 lemma prod_quotient [quot_thm]:
   118   assumes "Quotient3 R1 Abs1 Rep1"
   119   assumes "Quotient3 R2 Abs2 Rep2"
   120   shows "Quotient3 (prod_rel R1 R2) (map_pair Abs1 Abs2) (map_pair Rep1 Rep2)"
   121   apply (rule Quotient3I)
   122   apply (simp add: map_pair.compositionality comp_def map_pair.identity
   123      Quotient3_abs_rep [OF assms(1)] Quotient3_abs_rep [OF assms(2)])
   124   apply (simp add: split_paired_all Quotient3_rel_rep [OF assms(1)] Quotient3_rel_rep [OF assms(2)])
   125   using Quotient3_rel [OF assms(1)] Quotient3_rel [OF assms(2)]
   126   apply (auto simp add: split_paired_all)
   127   done
   128 
   129 declare [[mapQ3 prod = (prod_rel, prod_quotient)]]
   130 
   131 lemma Pair_rsp [quot_respect]:
   132   assumes q1: "Quotient3 R1 Abs1 Rep1"
   133   assumes q2: "Quotient3 R2 Abs2 Rep2"
   134   shows "(R1 ===> R2 ===> prod_rel R1 R2) Pair Pair"
   135   by (rule Pair_transfer)
   136 
   137 lemma Pair_prs [quot_preserve]:
   138   assumes q1: "Quotient3 R1 Abs1 Rep1"
   139   assumes q2: "Quotient3 R2 Abs2 Rep2"
   140   shows "(Rep1 ---> Rep2 ---> (map_pair Abs1 Abs2)) Pair = Pair"
   141   apply(simp add: fun_eq_iff)
   142   apply(simp add: Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   143   done
   144 
   145 lemma fst_rsp [quot_respect]:
   146   assumes "Quotient3 R1 Abs1 Rep1"
   147   assumes "Quotient3 R2 Abs2 Rep2"
   148   shows "(prod_rel R1 R2 ===> R1) fst fst"
   149   by auto
   150 
   151 lemma fst_prs [quot_preserve]:
   152   assumes q1: "Quotient3 R1 Abs1 Rep1"
   153   assumes q2: "Quotient3 R2 Abs2 Rep2"
   154   shows "(map_pair Rep1 Rep2 ---> Abs1) fst = fst"
   155   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1])
   156 
   157 lemma snd_rsp [quot_respect]:
   158   assumes "Quotient3 R1 Abs1 Rep1"
   159   assumes "Quotient3 R2 Abs2 Rep2"
   160   shows "(prod_rel R1 R2 ===> R2) snd snd"
   161   by auto
   162 
   163 lemma snd_prs [quot_preserve]:
   164   assumes q1: "Quotient3 R1 Abs1 Rep1"
   165   assumes q2: "Quotient3 R2 Abs2 Rep2"
   166   shows "(map_pair Rep1 Rep2 ---> Abs2) snd = snd"
   167   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q2])
   168 
   169 lemma split_rsp [quot_respect]:
   170   shows "((R1 ===> R2 ===> (op =)) ===> (prod_rel R1 R2) ===> (op =)) split split"
   171   by (rule prod_case_transfer)
   172 
   173 lemma split_prs [quot_preserve]:
   174   assumes q1: "Quotient3 R1 Abs1 Rep1"
   175   and     q2: "Quotient3 R2 Abs2 Rep2"
   176   shows "(((Abs1 ---> Abs2 ---> id) ---> map_pair Rep1 Rep2 ---> id) split) = split"
   177   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   178 
   179 lemma [quot_respect]:
   180   shows "((R2 ===> R2 ===> op =) ===> (R1 ===> R1 ===> op =) ===>
   181   prod_rel R2 R1 ===> prod_rel R2 R1 ===> op =) prod_rel prod_rel"
   182   by (rule prod_rel_transfer)
   183 
   184 lemma [quot_preserve]:
   185   assumes q1: "Quotient3 R1 abs1 rep1"
   186   and     q2: "Quotient3 R2 abs2 rep2"
   187   shows "((abs1 ---> abs1 ---> id) ---> (abs2 ---> abs2 ---> id) --->
   188   map_pair rep1 rep2 ---> map_pair rep1 rep2 ---> id) prod_rel = prod_rel"
   189   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   190 
   191 lemma [quot_preserve]:
   192   shows"(prod_rel ((rep1 ---> rep1 ---> id) R1) ((rep2 ---> rep2 ---> id) R2)
   193   (l1, l2) (r1, r2)) = (R1 (rep1 l1) (rep1 r1) \<and> R2 (rep2 l2) (rep2 r2))"
   194   by simp
   195 
   196 declare Pair_eq[quot_preserve]
   197 
   198 end