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