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