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