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