src/HOL/Library/Quotient_Product.thy
author kuncar
Fri Mar 08 13:21:52 2013 +0100 (2013-03-08)
changeset 51377 7da251a6c16e
parent 47982 7aa35601ff65
child 51956 a4d81cdebf8b
permissions -rw-r--r--
add [relator_mono] and [relator_distr] rules
     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_rel_mono[relator_mono]:
    31   assumes "A \<le> C"
    32   assumes "B \<le> D"
    33   shows "(prod_rel A B) \<le> (prod_rel C D)"
    34 using assms by (auto simp: prod_rel_def)
    35 
    36 lemma prod_rel_OO[relator_distr]:
    37   "(prod_rel A B) OO (prod_rel C D) = prod_rel (A OO C) (B OO D)"
    38 by (rule ext)+ (auto simp: prod_rel_def OO_def)
    39 
    40 lemma prod_reflp [reflexivity_rule]:
    41   assumes "reflp R1"
    42   assumes "reflp R2"
    43   shows "reflp (prod_rel R1 R2)"
    44 using assms by (auto intro!: reflpI elim: reflpE)
    45 
    46 lemma prod_left_total [reflexivity_rule]:
    47   assumes "left_total R1"
    48   assumes "left_total R2"
    49   shows "left_total (prod_rel R1 R2)"
    50 using assms by (auto intro!: left_totalI elim!: left_totalE)
    51 
    52 lemma prod_equivp [quot_equiv]:
    53   assumes "equivp R1"
    54   assumes "equivp R2"
    55   shows "equivp (prod_rel R1 R2)"
    56   using assms by (auto intro!: equivpI reflpI sympI transpI elim!: equivpE elim: reflpE sympE transpE)
    57 
    58 lemma right_total_prod_rel [transfer_rule]:
    59   assumes "right_total R1" and "right_total R2"
    60   shows "right_total (prod_rel R1 R2)"
    61   using assms unfolding right_total_def prod_rel_def by auto
    62 
    63 lemma right_unique_prod_rel [transfer_rule]:
    64   assumes "right_unique R1" and "right_unique R2"
    65   shows "right_unique (prod_rel R1 R2)"
    66   using assms unfolding right_unique_def prod_rel_def by auto
    67 
    68 lemma bi_total_prod_rel [transfer_rule]:
    69   assumes "bi_total R1" and "bi_total R2"
    70   shows "bi_total (prod_rel R1 R2)"
    71   using assms unfolding bi_total_def prod_rel_def by auto
    72 
    73 lemma bi_unique_prod_rel [transfer_rule]:
    74   assumes "bi_unique R1" and "bi_unique R2"
    75   shows "bi_unique (prod_rel R1 R2)"
    76   using assms unfolding bi_unique_def prod_rel_def by auto
    77 
    78 subsection {* Transfer rules for transfer package *}
    79 
    80 lemma Pair_transfer [transfer_rule]: "(A ===> B ===> prod_rel A B) Pair Pair"
    81   unfolding fun_rel_def prod_rel_def by simp
    82 
    83 lemma fst_transfer [transfer_rule]: "(prod_rel A B ===> A) fst fst"
    84   unfolding fun_rel_def prod_rel_def by simp
    85 
    86 lemma snd_transfer [transfer_rule]: "(prod_rel A B ===> B) snd snd"
    87   unfolding fun_rel_def prod_rel_def by simp
    88 
    89 lemma prod_case_transfer [transfer_rule]:
    90   "((A ===> B ===> C) ===> prod_rel A B ===> C) prod_case prod_case"
    91   unfolding fun_rel_def prod_rel_def by simp
    92 
    93 lemma curry_transfer [transfer_rule]:
    94   "((prod_rel A B ===> C) ===> A ===> B ===> C) curry curry"
    95   unfolding curry_def by transfer_prover
    96 
    97 lemma map_pair_transfer [transfer_rule]:
    98   "((A ===> C) ===> (B ===> D) ===> prod_rel A B ===> prod_rel C D)
    99     map_pair map_pair"
   100   unfolding map_pair_def [abs_def] by transfer_prover
   101 
   102 lemma prod_rel_transfer [transfer_rule]:
   103   "((A ===> B ===> op =) ===> (C ===> D ===> op =) ===>
   104     prod_rel A C ===> prod_rel B D ===> op =) prod_rel prod_rel"
   105   unfolding fun_rel_def by auto
   106 
   107 subsection {* Setup for lifting package *}
   108 
   109 lemma Quotient_prod[quot_map]:
   110   assumes "Quotient R1 Abs1 Rep1 T1"
   111   assumes "Quotient R2 Abs2 Rep2 T2"
   112   shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2)
   113     (map_pair Rep1 Rep2) (prod_rel T1 T2)"
   114   using assms unfolding Quotient_alt_def by auto
   115 
   116 definition prod_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool"
   117 where "prod_pred R1 R2 = (\<lambda>(a, b). R1 a \<and> R2 b)"
   118 
   119 lemma prod_invariant_commute [invariant_commute]: 
   120   "prod_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (prod_pred P1 P2)"
   121   apply (simp add: fun_eq_iff prod_rel_def prod_pred_def Lifting.invariant_def) 
   122   apply blast
   123 done
   124 
   125 subsection {* Rules for quotient package *}
   126 
   127 lemma prod_quotient [quot_thm]:
   128   assumes "Quotient3 R1 Abs1 Rep1"
   129   assumes "Quotient3 R2 Abs2 Rep2"
   130   shows "Quotient3 (prod_rel R1 R2) (map_pair Abs1 Abs2) (map_pair Rep1 Rep2)"
   131   apply (rule Quotient3I)
   132   apply (simp add: map_pair.compositionality comp_def map_pair.identity
   133      Quotient3_abs_rep [OF assms(1)] Quotient3_abs_rep [OF assms(2)])
   134   apply (simp add: split_paired_all Quotient3_rel_rep [OF assms(1)] Quotient3_rel_rep [OF assms(2)])
   135   using Quotient3_rel [OF assms(1)] Quotient3_rel [OF assms(2)]
   136   apply (auto simp add: split_paired_all)
   137   done
   138 
   139 declare [[mapQ3 prod = (prod_rel, prod_quotient)]]
   140 
   141 lemma Pair_rsp [quot_respect]:
   142   assumes q1: "Quotient3 R1 Abs1 Rep1"
   143   assumes q2: "Quotient3 R2 Abs2 Rep2"
   144   shows "(R1 ===> R2 ===> prod_rel R1 R2) Pair Pair"
   145   by (rule Pair_transfer)
   146 
   147 lemma Pair_prs [quot_preserve]:
   148   assumes q1: "Quotient3 R1 Abs1 Rep1"
   149   assumes q2: "Quotient3 R2 Abs2 Rep2"
   150   shows "(Rep1 ---> Rep2 ---> (map_pair Abs1 Abs2)) Pair = Pair"
   151   apply(simp add: fun_eq_iff)
   152   apply(simp add: Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   153   done
   154 
   155 lemma fst_rsp [quot_respect]:
   156   assumes "Quotient3 R1 Abs1 Rep1"
   157   assumes "Quotient3 R2 Abs2 Rep2"
   158   shows "(prod_rel R1 R2 ===> R1) fst fst"
   159   by auto
   160 
   161 lemma fst_prs [quot_preserve]:
   162   assumes q1: "Quotient3 R1 Abs1 Rep1"
   163   assumes q2: "Quotient3 R2 Abs2 Rep2"
   164   shows "(map_pair Rep1 Rep2 ---> Abs1) fst = fst"
   165   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1])
   166 
   167 lemma snd_rsp [quot_respect]:
   168   assumes "Quotient3 R1 Abs1 Rep1"
   169   assumes "Quotient3 R2 Abs2 Rep2"
   170   shows "(prod_rel R1 R2 ===> R2) snd snd"
   171   by auto
   172 
   173 lemma snd_prs [quot_preserve]:
   174   assumes q1: "Quotient3 R1 Abs1 Rep1"
   175   assumes q2: "Quotient3 R2 Abs2 Rep2"
   176   shows "(map_pair Rep1 Rep2 ---> Abs2) snd = snd"
   177   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q2])
   178 
   179 lemma split_rsp [quot_respect]:
   180   shows "((R1 ===> R2 ===> (op =)) ===> (prod_rel R1 R2) ===> (op =)) split split"
   181   by (rule prod_case_transfer)
   182 
   183 lemma split_prs [quot_preserve]:
   184   assumes q1: "Quotient3 R1 Abs1 Rep1"
   185   and     q2: "Quotient3 R2 Abs2 Rep2"
   186   shows "(((Abs1 ---> Abs2 ---> id) ---> map_pair Rep1 Rep2 ---> id) split) = split"
   187   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   188 
   189 lemma [quot_respect]:
   190   shows "((R2 ===> R2 ===> op =) ===> (R1 ===> R1 ===> op =) ===>
   191   prod_rel R2 R1 ===> prod_rel R2 R1 ===> op =) prod_rel prod_rel"
   192   by (rule prod_rel_transfer)
   193 
   194 lemma [quot_preserve]:
   195   assumes q1: "Quotient3 R1 abs1 rep1"
   196   and     q2: "Quotient3 R2 abs2 rep2"
   197   shows "((abs1 ---> abs1 ---> id) ---> (abs2 ---> abs2 ---> id) --->
   198   map_pair rep1 rep2 ---> map_pair rep1 rep2 ---> id) prod_rel = prod_rel"
   199   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   200 
   201 lemma [quot_preserve]:
   202   shows"(prod_rel ((rep1 ---> rep1 ---> id) R1) ((rep2 ---> rep2 ---> id) R2)
   203   (l1, l2) (r1, r2)) = (R1 (rep1 l1) (rep1 r1) \<and> R2 (rep2 l2) (rep2 r2))"
   204   by simp
   205 
   206 declare Pair_eq[quot_preserve]
   207 
   208 end