src/HOL/Lifting_Sum.thy
author kuncar
Tue Aug 13 15:59:22 2013 +0200 (2013-08-13)
changeset 53012 cb82606b8215
child 53026 e1a548c11845
permissions -rw-r--r--
move Lifting/Transfer relevant parts of Library/Quotient_* to Main
kuncar@53012
     1
(*  Title:      HOL/Lifting_Sum.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 sum type *}
kuncar@53012
     6
kuncar@53012
     7
theory Lifting_Sum
kuncar@53012
     8
imports Lifting FunDef
kuncar@53012
     9
begin
kuncar@53012
    10
kuncar@53012
    11
subsection {* Relator and predicator properties *}
kuncar@53012
    12
kuncar@53012
    13
fun
kuncar@53012
    14
  sum_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
kuncar@53012
    15
where
kuncar@53012
    16
  "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
kuncar@53012
    17
| "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
kuncar@53012
    18
| "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
kuncar@53012
    19
| "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
kuncar@53012
    20
kuncar@53012
    21
lemma sum_rel_unfold:
kuncar@53012
    22
  "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
kuncar@53012
    23
    | (Inr x, Inr y) \<Rightarrow> R2 x y
kuncar@53012
    24
    | _ \<Rightarrow> False)"
kuncar@53012
    25
  by (cases x) (cases y, simp_all)+
kuncar@53012
    26
kuncar@53012
    27
fun sum_pred :: "('a \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> bool"
kuncar@53012
    28
where
kuncar@53012
    29
  "sum_pred P1 P2 (Inl a) = P1 a"
kuncar@53012
    30
| "sum_pred P1 P2 (Inr a) = P2 a"
kuncar@53012
    31
kuncar@53012
    32
lemma sum_pred_unfold:
kuncar@53012
    33
  "sum_pred P1 P2 x = (case x of Inl x \<Rightarrow> P1 x
kuncar@53012
    34
    | Inr x \<Rightarrow> P2 x)"
kuncar@53012
    35
by (cases x) simp_all
kuncar@53012
    36
kuncar@53012
    37
lemma sum_rel_eq [relator_eq]:
kuncar@53012
    38
  "sum_rel (op =) (op =) = (op =)"
kuncar@53012
    39
  by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
kuncar@53012
    40
kuncar@53012
    41
lemma sum_rel_mono[relator_mono]:
kuncar@53012
    42
  assumes "A \<le> C"
kuncar@53012
    43
  assumes "B \<le> D"
kuncar@53012
    44
  shows "(sum_rel A B) \<le> (sum_rel C D)"
kuncar@53012
    45
using assms by (auto simp: sum_rel_unfold split: sum.splits)
kuncar@53012
    46
kuncar@53012
    47
lemma sum_rel_OO[relator_distr]:
kuncar@53012
    48
  "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
kuncar@53012
    49
by (rule ext)+ (auto simp add: sum_rel_unfold OO_def split_sum_ex split: sum.split)
kuncar@53012
    50
kuncar@53012
    51
lemma Domainp_sum[relator_domain]:
kuncar@53012
    52
  assumes "Domainp R1 = P1"
kuncar@53012
    53
  assumes "Domainp R2 = P2"
kuncar@53012
    54
  shows "Domainp (sum_rel R1 R2) = (sum_pred P1 P2)"
kuncar@53012
    55
using assms
kuncar@53012
    56
by (auto simp add: Domainp_iff split_sum_ex sum_pred_unfold iff: fun_eq_iff split: sum.split)
kuncar@53012
    57
kuncar@53012
    58
lemma reflp_sum_rel[reflexivity_rule]:
kuncar@53012
    59
  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
kuncar@53012
    60
  unfolding reflp_def split_sum_all sum_rel.simps by fast
kuncar@53012
    61
kuncar@53012
    62
lemma left_total_sum_rel[reflexivity_rule]:
kuncar@53012
    63
  "left_total R1 \<Longrightarrow> left_total R2 \<Longrightarrow> left_total (sum_rel R1 R2)"
kuncar@53012
    64
  using assms unfolding left_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    65
kuncar@53012
    66
lemma left_unique_sum_rel [reflexivity_rule]:
kuncar@53012
    67
  "left_unique R1 \<Longrightarrow> left_unique R2 \<Longrightarrow> left_unique (sum_rel R1 R2)"
kuncar@53012
    68
  using assms unfolding left_unique_def split_sum_all by simp
kuncar@53012
    69
kuncar@53012
    70
lemma right_total_sum_rel [transfer_rule]:
kuncar@53012
    71
  "right_total R1 \<Longrightarrow> right_total R2 \<Longrightarrow> right_total (sum_rel R1 R2)"
kuncar@53012
    72
  unfolding right_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    73
kuncar@53012
    74
lemma right_unique_sum_rel [transfer_rule]:
kuncar@53012
    75
  "right_unique R1 \<Longrightarrow> right_unique R2 \<Longrightarrow> right_unique (sum_rel R1 R2)"
kuncar@53012
    76
  unfolding right_unique_def split_sum_all by simp
kuncar@53012
    77
kuncar@53012
    78
lemma bi_total_sum_rel [transfer_rule]:
kuncar@53012
    79
  "bi_total R1 \<Longrightarrow> bi_total R2 \<Longrightarrow> bi_total (sum_rel R1 R2)"
kuncar@53012
    80
  using assms unfolding bi_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    81
kuncar@53012
    82
lemma bi_unique_sum_rel [transfer_rule]:
kuncar@53012
    83
  "bi_unique R1 \<Longrightarrow> bi_unique R2 \<Longrightarrow> bi_unique (sum_rel R1 R2)"
kuncar@53012
    84
  using assms unfolding bi_unique_def split_sum_all by simp
kuncar@53012
    85
kuncar@53012
    86
lemma sum_invariant_commute [invariant_commute]: 
kuncar@53012
    87
  "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
kuncar@53012
    88
  by (auto simp add: fun_eq_iff Lifting.invariant_def sum_rel_unfold sum_pred_unfold split: sum.split)
kuncar@53012
    89
kuncar@53012
    90
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    91
kuncar@53012
    92
lemma Quotient_sum[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 (sum_rel R1 R2) (sum_map Abs1 Abs2)
kuncar@53012
    96
    (sum_map Rep1 Rep2) (sum_rel T1 T2)"
kuncar@53012
    97
  using assms unfolding Quotient_alt_def
kuncar@53012
    98
  by (simp add: split_sum_all)
kuncar@53012
    99
kuncar@53012
   100
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
   101
kuncar@53012
   102
context
kuncar@53012
   103
begin
kuncar@53012
   104
interpretation lifting_syntax .
kuncar@53012
   105
kuncar@53012
   106
lemma Inl_transfer [transfer_rule]: "(A ===> sum_rel A B) Inl Inl"
kuncar@53012
   107
  unfolding fun_rel_def by simp
kuncar@53012
   108
kuncar@53012
   109
lemma Inr_transfer [transfer_rule]: "(B ===> sum_rel A B) Inr Inr"
kuncar@53012
   110
  unfolding fun_rel_def by simp
kuncar@53012
   111
kuncar@53012
   112
lemma sum_case_transfer [transfer_rule]:
kuncar@53012
   113
  "((A ===> C) ===> (B ===> C) ===> sum_rel A B ===> C) sum_case sum_case"
kuncar@53012
   114
  unfolding fun_rel_def sum_rel_unfold by (simp split: sum.split)
kuncar@53012
   115
kuncar@53012
   116
end
kuncar@53012
   117
kuncar@53012
   118
end
kuncar@53012
   119