src/HOL/Lifting_Sum.thy
author blanchet
Wed Feb 12 08:35:57 2014 +0100 (2014-02-12)
changeset 55414 eab03e9cee8a
parent 55084 8ee9aabb2bca
child 55564 e81ee43ab290
permissions -rw-r--r--
renamed '{prod,sum,bool,unit}_case' to 'case_...'
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
blanchet@55083
     8
imports Lifting Basic_BNFs
kuncar@53012
     9
begin
kuncar@53012
    10
kuncar@53012
    11
subsection {* Relator and predicator properties *}
kuncar@53012
    12
blanchet@55414
    13
abbreviation (input) "sum_pred \<equiv> case_sum"
kuncar@53012
    14
blanchet@55084
    15
lemmas sum_rel_eq[relator_eq] = sum.rel_eq
blanchet@55084
    16
lemmas sum_rel_mono[relator_mono] = sum.rel_mono
kuncar@53012
    17
kuncar@53012
    18
lemma sum_rel_OO[relator_distr]:
kuncar@53012
    19
  "(sum_rel A B) OO (sum_rel C D) = sum_rel (A OO C) (B OO D)"
blanchet@55084
    20
  by (rule ext)+ (auto simp add: sum_rel_def OO_def split_sum_ex split: sum.split)
kuncar@53012
    21
kuncar@53012
    22
lemma Domainp_sum[relator_domain]:
kuncar@53012
    23
  assumes "Domainp R1 = P1"
kuncar@53012
    24
  assumes "Domainp R2 = P2"
kuncar@53012
    25
  shows "Domainp (sum_rel R1 R2) = (sum_pred P1 P2)"
kuncar@53012
    26
using assms
traytel@53026
    27
by (auto simp add: Domainp_iff split_sum_ex iff: fun_eq_iff split: sum.split)
kuncar@53012
    28
kuncar@53012
    29
lemma reflp_sum_rel[reflexivity_rule]:
kuncar@53012
    30
  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
traytel@53026
    31
  unfolding reflp_def split_sum_all sum_rel_simps by fast
kuncar@53012
    32
kuncar@53012
    33
lemma left_total_sum_rel[reflexivity_rule]:
kuncar@53012
    34
  "left_total R1 \<Longrightarrow> left_total R2 \<Longrightarrow> left_total (sum_rel R1 R2)"
kuncar@53012
    35
  using assms unfolding left_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    36
kuncar@53012
    37
lemma left_unique_sum_rel [reflexivity_rule]:
kuncar@53012
    38
  "left_unique R1 \<Longrightarrow> left_unique R2 \<Longrightarrow> left_unique (sum_rel R1 R2)"
kuncar@53012
    39
  using assms unfolding left_unique_def split_sum_all by simp
kuncar@53012
    40
kuncar@53012
    41
lemma right_total_sum_rel [transfer_rule]:
kuncar@53012
    42
  "right_total R1 \<Longrightarrow> right_total R2 \<Longrightarrow> right_total (sum_rel R1 R2)"
kuncar@53012
    43
  unfolding right_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    44
kuncar@53012
    45
lemma right_unique_sum_rel [transfer_rule]:
kuncar@53012
    46
  "right_unique R1 \<Longrightarrow> right_unique R2 \<Longrightarrow> right_unique (sum_rel R1 R2)"
kuncar@53012
    47
  unfolding right_unique_def split_sum_all by simp
kuncar@53012
    48
kuncar@53012
    49
lemma bi_total_sum_rel [transfer_rule]:
kuncar@53012
    50
  "bi_total R1 \<Longrightarrow> bi_total R2 \<Longrightarrow> bi_total (sum_rel R1 R2)"
kuncar@53012
    51
  using assms unfolding bi_total_def split_sum_all split_sum_ex by simp
kuncar@53012
    52
kuncar@53012
    53
lemma bi_unique_sum_rel [transfer_rule]:
kuncar@53012
    54
  "bi_unique R1 \<Longrightarrow> bi_unique R2 \<Longrightarrow> bi_unique (sum_rel R1 R2)"
kuncar@53012
    55
  using assms unfolding bi_unique_def split_sum_all by simp
kuncar@53012
    56
kuncar@53012
    57
lemma sum_invariant_commute [invariant_commute]: 
kuncar@53012
    58
  "sum_rel (Lifting.invariant P1) (Lifting.invariant P2) = Lifting.invariant (sum_pred P1 P2)"
traytel@53026
    59
  by (auto simp add: fun_eq_iff Lifting.invariant_def sum_rel_def split: sum.split)
kuncar@53012
    60
kuncar@53012
    61
subsection {* Quotient theorem for the Lifting package *}
kuncar@53012
    62
kuncar@53012
    63
lemma Quotient_sum[quot_map]:
kuncar@53012
    64
  assumes "Quotient R1 Abs1 Rep1 T1"
kuncar@53012
    65
  assumes "Quotient R2 Abs2 Rep2 T2"
kuncar@53012
    66
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2)
kuncar@53012
    67
    (sum_map Rep1 Rep2) (sum_rel T1 T2)"
kuncar@53012
    68
  using assms unfolding Quotient_alt_def
kuncar@53012
    69
  by (simp add: split_sum_all)
kuncar@53012
    70
kuncar@53012
    71
subsection {* Transfer rules for the Transfer package *}
kuncar@53012
    72
kuncar@53012
    73
context
kuncar@53012
    74
begin
kuncar@53012
    75
interpretation lifting_syntax .
kuncar@53012
    76
kuncar@53012
    77
lemma Inl_transfer [transfer_rule]: "(A ===> sum_rel A B) Inl Inl"
kuncar@53012
    78
  unfolding fun_rel_def by simp
kuncar@53012
    79
kuncar@53012
    80
lemma Inr_transfer [transfer_rule]: "(B ===> sum_rel A B) Inr Inr"
kuncar@53012
    81
  unfolding fun_rel_def by simp
kuncar@53012
    82
blanchet@55414
    83
lemma case_sum_transfer [transfer_rule]:
blanchet@55414
    84
  "((A ===> C) ===> (B ===> C) ===> sum_rel A B ===> C) case_sum case_sum"
traytel@53026
    85
  unfolding fun_rel_def sum_rel_def by (simp split: sum.split)
kuncar@53012
    86
kuncar@53012
    87
end
kuncar@53012
    88
kuncar@53012
    89
end