src/HOL/Library/Quotient_Product.thy
author kuncar
Wed May 15 12:10:39 2013 +0200 (2013-05-15)
changeset 51994 82cc2aeb7d13
parent 51956 a4d81cdebf8b
child 53012 cb82606b8215
permissions -rw-r--r--
stronger reflexivity prover
     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 reflp_prod_rel [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 left_total_prod_rel [reflexivity_rule]:
    60   assumes "left_total R1"
    61   assumes "left_total R2"
    62   shows "left_total (prod_rel R1 R2)"
    63   using assms unfolding left_total_def prod_rel_def by auto
    64 
    65 lemma left_unique_prod_rel [reflexivity_rule]:
    66   assumes "left_unique R1" and "left_unique R2"
    67   shows "left_unique (prod_rel R1 R2)"
    68   using assms unfolding left_unique_def prod_rel_def by auto
    69 
    70 lemma prod_equivp [quot_equiv]:
    71   assumes "equivp R1"
    72   assumes "equivp R2"
    73   shows "equivp (prod_rel R1 R2)"
    74   using assms by (auto intro!: equivpI reflpI sympI transpI elim!: equivpE elim: reflpE sympE transpE)
    75 
    76 lemma right_total_prod_rel [transfer_rule]:
    77   assumes "right_total R1" and "right_total R2"
    78   shows "right_total (prod_rel R1 R2)"
    79   using assms unfolding right_total_def prod_rel_def by auto
    80 
    81 lemma right_unique_prod_rel [transfer_rule]:
    82   assumes "right_unique R1" and "right_unique R2"
    83   shows "right_unique (prod_rel R1 R2)"
    84   using assms unfolding right_unique_def prod_rel_def by auto
    85 
    86 lemma bi_total_prod_rel [transfer_rule]:
    87   assumes "bi_total R1" and "bi_total R2"
    88   shows "bi_total (prod_rel R1 R2)"
    89   using assms unfolding bi_total_def prod_rel_def by auto
    90 
    91 lemma bi_unique_prod_rel [transfer_rule]:
    92   assumes "bi_unique R1" and "bi_unique R2"
    93   shows "bi_unique (prod_rel R1 R2)"
    94   using assms unfolding bi_unique_def prod_rel_def by auto
    95 
    96 subsection {* Transfer rules for transfer package *}
    97 
    98 lemma Pair_transfer [transfer_rule]: "(A ===> B ===> prod_rel A B) Pair Pair"
    99   unfolding fun_rel_def prod_rel_def by simp
   100 
   101 lemma fst_transfer [transfer_rule]: "(prod_rel A B ===> A) fst fst"
   102   unfolding fun_rel_def prod_rel_def by simp
   103 
   104 lemma snd_transfer [transfer_rule]: "(prod_rel A B ===> B) snd snd"
   105   unfolding fun_rel_def prod_rel_def by simp
   106 
   107 lemma prod_case_transfer [transfer_rule]:
   108   "((A ===> B ===> C) ===> prod_rel A B ===> C) prod_case prod_case"
   109   unfolding fun_rel_def prod_rel_def by simp
   110 
   111 lemma curry_transfer [transfer_rule]:
   112   "((prod_rel A B ===> C) ===> A ===> B ===> C) curry curry"
   113   unfolding curry_def by transfer_prover
   114 
   115 lemma map_pair_transfer [transfer_rule]:
   116   "((A ===> C) ===> (B ===> D) ===> prod_rel A B ===> prod_rel C D)
   117     map_pair map_pair"
   118   unfolding map_pair_def [abs_def] by transfer_prover
   119 
   120 lemma prod_rel_transfer [transfer_rule]:
   121   "((A ===> B ===> op =) ===> (C ===> D ===> op =) ===>
   122     prod_rel A C ===> prod_rel B D ===> op =) prod_rel prod_rel"
   123   unfolding fun_rel_def by auto
   124 
   125 subsection {* Setup for lifting package *}
   126 
   127 lemma Quotient_prod[quot_map]:
   128   assumes "Quotient R1 Abs1 Rep1 T1"
   129   assumes "Quotient R2 Abs2 Rep2 T2"
   130   shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2)
   131     (map_pair Rep1 Rep2) (prod_rel T1 T2)"
   132   using assms unfolding Quotient_alt_def by auto
   133 
   134 lemma prod_invariant_commute [invariant_commute]: 
   135   "prod_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (prod_pred P1 P2)"
   136   apply (simp add: fun_eq_iff prod_rel_def prod_pred_def Lifting.invariant_def) 
   137   apply blast
   138 done
   139 
   140 subsection {* Rules for quotient package *}
   141 
   142 lemma prod_quotient [quot_thm]:
   143   assumes "Quotient3 R1 Abs1 Rep1"
   144   assumes "Quotient3 R2 Abs2 Rep2"
   145   shows "Quotient3 (prod_rel R1 R2) (map_pair Abs1 Abs2) (map_pair Rep1 Rep2)"
   146   apply (rule Quotient3I)
   147   apply (simp add: map_pair.compositionality comp_def map_pair.identity
   148      Quotient3_abs_rep [OF assms(1)] Quotient3_abs_rep [OF assms(2)])
   149   apply (simp add: split_paired_all Quotient3_rel_rep [OF assms(1)] Quotient3_rel_rep [OF assms(2)])
   150   using Quotient3_rel [OF assms(1)] Quotient3_rel [OF assms(2)]
   151   apply (auto simp add: split_paired_all)
   152   done
   153 
   154 declare [[mapQ3 prod = (prod_rel, prod_quotient)]]
   155 
   156 lemma Pair_rsp [quot_respect]:
   157   assumes q1: "Quotient3 R1 Abs1 Rep1"
   158   assumes q2: "Quotient3 R2 Abs2 Rep2"
   159   shows "(R1 ===> R2 ===> prod_rel R1 R2) Pair Pair"
   160   by (rule Pair_transfer)
   161 
   162 lemma Pair_prs [quot_preserve]:
   163   assumes q1: "Quotient3 R1 Abs1 Rep1"
   164   assumes q2: "Quotient3 R2 Abs2 Rep2"
   165   shows "(Rep1 ---> Rep2 ---> (map_pair Abs1 Abs2)) Pair = Pair"
   166   apply(simp add: fun_eq_iff)
   167   apply(simp add: Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   168   done
   169 
   170 lemma fst_rsp [quot_respect]:
   171   assumes "Quotient3 R1 Abs1 Rep1"
   172   assumes "Quotient3 R2 Abs2 Rep2"
   173   shows "(prod_rel R1 R2 ===> R1) fst fst"
   174   by auto
   175 
   176 lemma fst_prs [quot_preserve]:
   177   assumes q1: "Quotient3 R1 Abs1 Rep1"
   178   assumes q2: "Quotient3 R2 Abs2 Rep2"
   179   shows "(map_pair Rep1 Rep2 ---> Abs1) fst = fst"
   180   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1])
   181 
   182 lemma snd_rsp [quot_respect]:
   183   assumes "Quotient3 R1 Abs1 Rep1"
   184   assumes "Quotient3 R2 Abs2 Rep2"
   185   shows "(prod_rel R1 R2 ===> R2) snd snd"
   186   by auto
   187 
   188 lemma snd_prs [quot_preserve]:
   189   assumes q1: "Quotient3 R1 Abs1 Rep1"
   190   assumes q2: "Quotient3 R2 Abs2 Rep2"
   191   shows "(map_pair Rep1 Rep2 ---> Abs2) snd = snd"
   192   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q2])
   193 
   194 lemma split_rsp [quot_respect]:
   195   shows "((R1 ===> R2 ===> (op =)) ===> (prod_rel R1 R2) ===> (op =)) split split"
   196   by (rule prod_case_transfer)
   197 
   198 lemma split_prs [quot_preserve]:
   199   assumes q1: "Quotient3 R1 Abs1 Rep1"
   200   and     q2: "Quotient3 R2 Abs2 Rep2"
   201   shows "(((Abs1 ---> Abs2 ---> id) ---> map_pair Rep1 Rep2 ---> id) split) = split"
   202   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   203 
   204 lemma [quot_respect]:
   205   shows "((R2 ===> R2 ===> op =) ===> (R1 ===> R1 ===> op =) ===>
   206   prod_rel R2 R1 ===> prod_rel R2 R1 ===> op =) prod_rel prod_rel"
   207   by (rule prod_rel_transfer)
   208 
   209 lemma [quot_preserve]:
   210   assumes q1: "Quotient3 R1 abs1 rep1"
   211   and     q2: "Quotient3 R2 abs2 rep2"
   212   shows "((abs1 ---> abs1 ---> id) ---> (abs2 ---> abs2 ---> id) --->
   213   map_pair rep1 rep2 ---> map_pair rep1 rep2 ---> id) prod_rel = prod_rel"
   214   by (simp add: fun_eq_iff Quotient3_abs_rep[OF q1] Quotient3_abs_rep[OF q2])
   215 
   216 lemma [quot_preserve]:
   217   shows"(prod_rel ((rep1 ---> rep1 ---> id) R1) ((rep2 ---> rep2 ---> id) R2)
   218   (l1, l2) (r1, r2)) = (R1 (rep1 l1) (rep1 r1) \<and> R2 (rep2 l2) (rep2 r2))"
   219   by simp
   220 
   221 declare Pair_eq[quot_preserve]
   222 
   223 end