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