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