src/HOL/Lifting_Sum.thy
author haftmann
Fri Nov 01 18:51:14 2013 +0100 (2013-11-01)
changeset 54230 b1d955791529
parent 53026 e1a548c11845
child 55083 0a689157e3ce
permissions -rw-r--r--
more simplification rules on unary and binary minus
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
traytel@53026
     8
imports Lifting
kuncar@53012
     9
begin
kuncar@53012
    10
kuncar@53012
    11
subsection {* Relator and predicator properties *}
kuncar@53012
    12
traytel@53026
    13
definition
traytel@53026
    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
traytel@53026
    16
   "sum_rel R1 R2 x y =
traytel@53026
    17
     (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
traytel@53026
    18
     | (Inr x, Inr y) \<Rightarrow> R2 x y
traytel@53026
    19
     | _ \<Rightarrow> False)"
kuncar@53012
    20
traytel@53026
    21
lemma sum_rel_simps[simp]:
traytel@53026
    22
  "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
traytel@53026
    23
  "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
traytel@53026
    24
  "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
traytel@53026
    25
  "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
traytel@53026
    26
  unfolding sum_rel_def by simp_all
kuncar@53012
    27
traytel@53026
    28
abbreviation (input) "sum_pred \<equiv> sum_case"
kuncar@53012
    29
kuncar@53012
    30
lemma sum_rel_eq [relator_eq]:
kuncar@53012
    31
  "sum_rel (op =) (op =) = (op =)"
traytel@53026
    32
  by (simp add: sum_rel_def fun_eq_iff split: sum.split)
kuncar@53012
    33
kuncar@53012
    34
lemma sum_rel_mono[relator_mono]:
kuncar@53012
    35
  assumes "A \<le> C"
kuncar@53012
    36
  assumes "B \<le> D"
kuncar@53012
    37
  shows "(sum_rel A B) \<le> (sum_rel C D)"
traytel@53026
    38
using assms by (auto simp: sum_rel_def split: sum.splits)
kuncar@53012
    39
kuncar@53012
    40
lemma sum_rel_OO[relator_distr]:
kuncar@53012
    41
  "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
traytel@53026
    42
by (rule ext)+ (auto simp add: sum_rel_def OO_def split_sum_ex split: sum.split)
kuncar@53012
    43
kuncar@53012
    44
lemma Domainp_sum[relator_domain]:
kuncar@53012
    45
  assumes "Domainp R1 = P1"
kuncar@53012
    46
  assumes "Domainp R2 = P2"
kuncar@53012
    47
  shows "Domainp (sum_rel R1 R2) = (sum_pred P1 P2)"
kuncar@53012
    48
using assms
traytel@53026
    49
by (auto simp add: Domainp_iff split_sum_ex iff: fun_eq_iff split: sum.split)
kuncar@53012
    50
kuncar@53012
    51
lemma reflp_sum_rel[reflexivity_rule]:
kuncar@53012
    52
  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
traytel@53026
    53
  unfolding reflp_def split_sum_all sum_rel_simps by fast
kuncar@53012
    54
kuncar@53012
    55
lemma left_total_sum_rel[reflexivity_rule]:
kuncar@53012
    56
  "left_total R1 \<Longrightarrow> left_total R2 \<Longrightarrow> left_total (sum_rel R1 R2)"
kuncar@53012
    57
  using assms unfolding left_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    58
kuncar@53012
    59
lemma left_unique_sum_rel [reflexivity_rule]:
kuncar@53012
    60
  "left_unique R1 \<Longrightarrow> left_unique R2 \<Longrightarrow> left_unique (sum_rel R1 R2)"
kuncar@53012
    61
  using assms unfolding left_unique_def split_sum_all by simp
kuncar@53012
    62
kuncar@53012
    63
lemma right_total_sum_rel [transfer_rule]:
kuncar@53012
    64
  "right_total R1 \<Longrightarrow> right_total R2 \<Longrightarrow> right_total (sum_rel R1 R2)"
kuncar@53012
    65
  unfolding right_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    66
kuncar@53012
    67
lemma right_unique_sum_rel [transfer_rule]:
kuncar@53012
    68
  "right_unique R1 \<Longrightarrow> right_unique R2 \<Longrightarrow> right_unique (sum_rel R1 R2)"
kuncar@53012
    69
  unfolding right_unique_def split_sum_all by simp
kuncar@53012
    70
kuncar@53012
    71
lemma bi_total_sum_rel [transfer_rule]:
kuncar@53012
    72
  "bi_total R1 \<Longrightarrow> bi_total R2 \<Longrightarrow> bi_total (sum_rel R1 R2)"
kuncar@53012
    73
  using assms unfolding bi_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    74
kuncar@53012
    75
lemma bi_unique_sum_rel [transfer_rule]:
kuncar@53012
    76
  "bi_unique R1 \<Longrightarrow> bi_unique R2 \<Longrightarrow> bi_unique (sum_rel R1 R2)"
kuncar@53012
    77
  using assms unfolding bi_unique_def split_sum_all by simp
kuncar@53012
    78
kuncar@53012
    79
lemma sum_invariant_commute [invariant_commute]: 
kuncar@53012
    80
  "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
traytel@53026
    81
  by (auto simp add: fun_eq_iff Lifting.invariant_def sum_rel_def split: sum.split)
kuncar@53012
    82
kuncar@53012
    83
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    84
kuncar@53012
    85
lemma Quotient_sum[quot_map]:
kuncar@53012
    86
  assumes "Quotient R1 Abs1 Rep1 T1"
kuncar@53012
    87
  assumes "Quotient R2 Abs2 Rep2 T2"
kuncar@53012
    88
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
kuncar@53012
    89
    (sum_map Rep1 Rep2) (sum_rel T1 T2)"
kuncar@53012
    90
  using assms unfolding Quotient_alt_def
kuncar@53012
    91
  by (simp add: split_sum_all)
kuncar@53012
    92
kuncar@53012
    93
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
    94
kuncar@53012
    95
context
kuncar@53012
    96
begin
kuncar@53012
    97
interpretation lifting_syntax .
kuncar@53012
    98
kuncar@53012
    99
lemma Inl_transfer [transfer_rule]: "(A ===> sum_rel A B) Inl Inl"
kuncar@53012
   100
  unfolding fun_rel_def by simp
kuncar@53012
   101
kuncar@53012
   102
lemma Inr_transfer [transfer_rule]: "(B ===> sum_rel A B) Inr Inr"
kuncar@53012
   103
  unfolding fun_rel_def by simp
kuncar@53012
   104
kuncar@53012
   105
lemma sum_case_transfer [transfer_rule]:
kuncar@53012
   106
  "((A ===> C) ===> (B ===> C) ===> sum_rel A B ===> C) sum_case sum_case"
traytel@53026
   107
  unfolding fun_rel_def sum_rel_def by (simp split: sum.split)
kuncar@53012
   108
kuncar@53012
   109
end
kuncar@53012
   110
kuncar@53012
   111
end
kuncar@53012
   112