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