src/HOL/Lifting_Product.thy
author wenzelm
Tue Sep 03 01:12:40 2013 +0200 (2013-09-03)
changeset 53374 a14d2a854c02
parent 53012 cb82606b8215
child 55083 0a689157e3ce
permissions -rw-r--r--
tuned proofs -- clarified flow of facts wrt. calculation;
kuncar@53012
     1
(*  Title:      HOL/Lifting_Product.thy
kuncar@53012
     2
    Author:     Brian Huffman and Ondrej Kuncar
kuncar@53012
     3
*)
kuncar@53012
     4
kuncar@53012
     5
header {* Setup for Lifting/Transfer for the product type *}
kuncar@53012
     6
kuncar@53012
     7
theory Lifting_Product
kuncar@53012
     8
imports Lifting
kuncar@53012
     9
begin
kuncar@53012
    10
kuncar@53012
    11
subsection {* Relator and predicator properties *}
kuncar@53012
    12
kuncar@53012
    13
definition
kuncar@53012
    14
  prod_rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> ('c \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'c \<Rightarrow> 'b \<times> 'd \<Rightarrow> bool"
kuncar@53012
    15
where
kuncar@53012
    16
  "prod_rel R1 R2 = (\<lambda>(a, b) (c, d). R1 a c \<and> R2 b d)"
kuncar@53012
    17
kuncar@53012
    18
definition prod_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a \<times> 'b \<Rightarrow> bool"
kuncar@53012
    19
where "prod_pred R1 R2 = (\<lambda>(a, b). R1 a \<and> R2 b)"
kuncar@53012
    20
kuncar@53012
    21
lemma prod_rel_apply [simp]:
kuncar@53012
    22
  "prod_rel R1 R2 (a, b) (c, d) \<longleftrightarrow> R1 a c \<and> R2 b d"
kuncar@53012
    23
  by (simp add: prod_rel_def)
kuncar@53012
    24
kuncar@53012
    25
lemma prod_pred_apply [simp]:
kuncar@53012
    26
  "prod_pred P1 P2 (a, b) \<longleftrightarrow> P1 a \<and> P2 b"
kuncar@53012
    27
  by (simp add: prod_pred_def)
kuncar@53012
    28
kuncar@53012
    29
lemma prod_rel_eq [relator_eq]:
kuncar@53012
    30
  shows "prod_rel (op =) (op =) = (op =)"
kuncar@53012
    31
  by (simp add: fun_eq_iff)
kuncar@53012
    32
kuncar@53012
    33
lemma prod_rel_mono[relator_mono]:
kuncar@53012
    34
  assumes "A \<le> C"
kuncar@53012
    35
  assumes "B \<le> D"
kuncar@53012
    36
  shows "(prod_rel A B) \<le> (prod_rel C D)"
kuncar@53012
    37
using assms by (auto simp: prod_rel_def)
kuncar@53012
    38
kuncar@53012
    39
lemma prod_rel_OO[relator_distr]:
kuncar@53012
    40
  "(prod_rel A B) OO (prod_rel C D) = prod_rel (A OO C) (B OO D)"
kuncar@53012
    41
by (rule ext)+ (auto simp: prod_rel_def OO_def)
kuncar@53012
    42
kuncar@53012
    43
lemma Domainp_prod[relator_domain]:
kuncar@53012
    44
  assumes "Domainp T1 = P1"
kuncar@53012
    45
  assumes "Domainp T2 = P2"
kuncar@53012
    46
  shows "Domainp (prod_rel T1 T2) = (prod_pred P1 P2)"
kuncar@53012
    47
using assms unfolding prod_rel_def prod_pred_def by blast
kuncar@53012
    48
kuncar@53012
    49
lemma reflp_prod_rel [reflexivity_rule]:
kuncar@53012
    50
  assumes "reflp R1"
kuncar@53012
    51
  assumes "reflp R2"
kuncar@53012
    52
  shows "reflp (prod_rel R1 R2)"
kuncar@53012
    53
using assms by (auto intro!: reflpI elim: reflpE)
kuncar@53012
    54
kuncar@53012
    55
lemma left_total_prod_rel [reflexivity_rule]:
kuncar@53012
    56
  assumes "left_total R1"
kuncar@53012
    57
  assumes "left_total R2"
kuncar@53012
    58
  shows "left_total (prod_rel R1 R2)"
kuncar@53012
    59
  using assms unfolding left_total_def prod_rel_def by auto
kuncar@53012
    60
kuncar@53012
    61
lemma left_unique_prod_rel [reflexivity_rule]:
kuncar@53012
    62
  assumes "left_unique R1" and "left_unique R2"
kuncar@53012
    63
  shows "left_unique (prod_rel R1 R2)"
kuncar@53012
    64
  using assms unfolding left_unique_def prod_rel_def by auto
kuncar@53012
    65
kuncar@53012
    66
lemma right_total_prod_rel [transfer_rule]:
kuncar@53012
    67
  assumes "right_total R1" and "right_total R2"
kuncar@53012
    68
  shows "right_total (prod_rel R1 R2)"
kuncar@53012
    69
  using assms unfolding right_total_def prod_rel_def by auto
kuncar@53012
    70
kuncar@53012
    71
lemma right_unique_prod_rel [transfer_rule]:
kuncar@53012
    72
  assumes "right_unique R1" and "right_unique R2"
kuncar@53012
    73
  shows "right_unique (prod_rel R1 R2)"
kuncar@53012
    74
  using assms unfolding right_unique_def prod_rel_def by auto
kuncar@53012
    75
kuncar@53012
    76
lemma bi_total_prod_rel [transfer_rule]:
kuncar@53012
    77
  assumes "bi_total R1" and "bi_total R2"
kuncar@53012
    78
  shows "bi_total (prod_rel R1 R2)"
kuncar@53012
    79
  using assms unfolding bi_total_def prod_rel_def by auto
kuncar@53012
    80
kuncar@53012
    81
lemma bi_unique_prod_rel [transfer_rule]:
kuncar@53012
    82
  assumes "bi_unique R1" and "bi_unique R2"
kuncar@53012
    83
  shows "bi_unique (prod_rel R1 R2)"
kuncar@53012
    84
  using assms unfolding bi_unique_def prod_rel_def by auto
kuncar@53012
    85
kuncar@53012
    86
lemma prod_invariant_commute [invariant_commute]: 
kuncar@53012
    87
  "prod_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (prod_pred P1 P2)"
kuncar@53012
    88
  by (simp add: fun_eq_iff prod_rel_def prod_pred_def Lifting.invariant_def) blast
kuncar@53012
    89
kuncar@53012
    90
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    91
kuncar@53012
    92
lemma Quotient_prod[quot_map]:
kuncar@53012
    93
  assumes "Quotient R1 Abs1 Rep1 T1"
kuncar@53012
    94
  assumes "Quotient R2 Abs2 Rep2 T2"
kuncar@53012
    95
  shows "Quotient (prod_rel R1 R2) (map_pair Abs1 Abs2)
kuncar@53012
    96
    (map_pair Rep1 Rep2) (prod_rel T1 T2)"
kuncar@53012
    97
  using assms unfolding Quotient_alt_def by auto
kuncar@53012
    98
kuncar@53012
    99
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
   100
kuncar@53012
   101
context
kuncar@53012
   102
begin
kuncar@53012
   103
interpretation lifting_syntax .
kuncar@53012
   104
kuncar@53012
   105
lemma Pair_transfer [transfer_rule]: "(A ===> B ===> prod_rel A B) Pair Pair"
kuncar@53012
   106
  unfolding fun_rel_def prod_rel_def by simp
kuncar@53012
   107
kuncar@53012
   108
lemma fst_transfer [transfer_rule]: "(prod_rel A B ===> A) fst fst"
kuncar@53012
   109
  unfolding fun_rel_def prod_rel_def by simp
kuncar@53012
   110
kuncar@53012
   111
lemma snd_transfer [transfer_rule]: "(prod_rel A B ===> B) snd snd"
kuncar@53012
   112
  unfolding fun_rel_def prod_rel_def by simp
kuncar@53012
   113
kuncar@53012
   114
lemma prod_case_transfer [transfer_rule]:
kuncar@53012
   115
  "((A ===> B ===> C) ===> prod_rel A B ===> C) prod_case prod_case"
kuncar@53012
   116
  unfolding fun_rel_def prod_rel_def by simp
kuncar@53012
   117
kuncar@53012
   118
lemma curry_transfer [transfer_rule]:
kuncar@53012
   119
  "((prod_rel A B ===> C) ===> A ===> B ===> C) curry curry"
kuncar@53012
   120
  unfolding curry_def by transfer_prover
kuncar@53012
   121
kuncar@53012
   122
lemma map_pair_transfer [transfer_rule]:
kuncar@53012
   123
  "((A ===> C) ===> (B ===> D) ===> prod_rel A B ===> prod_rel C D)
kuncar@53012
   124
    map_pair map_pair"
kuncar@53012
   125
  unfolding map_pair_def [abs_def] by transfer_prover
kuncar@53012
   126
kuncar@53012
   127
lemma prod_rel_transfer [transfer_rule]:
kuncar@53012
   128
  "((A ===> B ===> op =) ===> (C ===> D ===> op =) ===>
kuncar@53012
   129
    prod_rel A C ===> prod_rel B D ===> op =) prod_rel prod_rel"
kuncar@53012
   130
  unfolding fun_rel_def by auto
kuncar@53012
   131
kuncar@53012
   132
end
kuncar@53012
   133
kuncar@53012
   134
end
kuncar@53012
   135