src/HOL/Library/Quotient_Sum.thy
author haftmann
Mon Nov 15 14:59:21 2010 +0100 (2010-11-15)
changeset 40542 9a173a22771c
parent 40465 2989f9f3aa10
child 40610 70776ecfe324
permissions -rw-r--r--
re-generalized type of option_rel and sum_rel (accident from 2989f9f3aa10)
wenzelm@35788
     1
(*  Title:      HOL/Library/Quotient_Sum.thy
kaliszyk@35222
     2
    Author:     Cezary Kaliszyk and Christian Urban
kaliszyk@35222
     3
*)
wenzelm@35788
     4
wenzelm@35788
     5
header {* Quotient infrastructure for the sum type *}
wenzelm@35788
     6
kaliszyk@35222
     7
theory Quotient_Sum
kaliszyk@35222
     8
imports Main Quotient_Syntax
kaliszyk@35222
     9
begin
kaliszyk@35222
    10
kaliszyk@35222
    11
fun
haftmann@40542
    12
  sum_rel :: "('a \<Rightarrow> 'c \<Rightarrow> bool) \<Rightarrow> ('b \<Rightarrow> 'd \<Rightarrow> bool) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd \<Rightarrow> bool"
kaliszyk@35222
    13
where
kaliszyk@35222
    14
  "sum_rel R1 R2 (Inl a1) (Inl b1) = R1 a1 b1"
kaliszyk@35222
    15
| "sum_rel R1 R2 (Inl a1) (Inr b2) = False"
kaliszyk@35222
    16
| "sum_rel R1 R2 (Inr a2) (Inl b1) = False"
kaliszyk@35222
    17
| "sum_rel R1 R2 (Inr a2) (Inr b2) = R2 a2 b2"
kaliszyk@35222
    18
haftmann@40465
    19
primrec
haftmann@40465
    20
  sum_map :: "('a \<Rightarrow> 'c) \<Rightarrow> ('b \<Rightarrow> 'd) \<Rightarrow> 'a + 'b \<Rightarrow> 'c + 'd"
kaliszyk@35222
    21
where
kaliszyk@35222
    22
  "sum_map f1 f2 (Inl a) = Inl (f1 a)"
kaliszyk@35222
    23
| "sum_map f1 f2 (Inr a) = Inr (f2 a)"
kaliszyk@35222
    24
haftmann@37678
    25
declare [[map sum = (sum_map, sum_rel)]]
kaliszyk@35222
    26
kaliszyk@35222
    27
wenzelm@35243
    28
text {* should probably be in @{theory Sum_Type} *}
kaliszyk@35222
    29
lemma split_sum_all:
kaliszyk@35222
    30
  shows "(\<forall>x. P x) \<longleftrightarrow> (\<forall>x. P (Inl x)) \<and> (\<forall>x. P (Inr x))"
kaliszyk@35222
    31
  apply(auto)
kaliszyk@35222
    32
  apply(case_tac x)
kaliszyk@35222
    33
  apply(simp_all)
kaliszyk@35222
    34
  done
kaliszyk@35222
    35
kaliszyk@35222
    36
lemma sum_equivp[quot_equiv]:
kaliszyk@35222
    37
  assumes a: "equivp R1"
kaliszyk@35222
    38
  assumes b: "equivp R2"
kaliszyk@35222
    39
  shows "equivp (sum_rel R1 R2)"
kaliszyk@35222
    40
  apply(rule equivpI)
kaliszyk@35222
    41
  unfolding reflp_def symp_def transp_def
kaliszyk@35222
    42
  apply(simp_all add: split_sum_all)
kaliszyk@35222
    43
  apply(blast intro: equivp_reflp[OF a] equivp_reflp[OF b])
kaliszyk@35222
    44
  apply(blast intro: equivp_symp[OF a] equivp_symp[OF b])
kaliszyk@35222
    45
  apply(blast intro: equivp_transp[OF a] equivp_transp[OF b])
kaliszyk@35222
    46
  done
kaliszyk@35222
    47
kaliszyk@35222
    48
lemma sum_quotient[quot_thm]:
kaliszyk@35222
    49
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    50
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    51
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
kaliszyk@35222
    52
  unfolding Quotient_def
kaliszyk@35222
    53
  apply(simp add: split_sum_all)
kaliszyk@35222
    54
  apply(simp_all add: Quotient_abs_rep[OF q1] Quotient_rel_rep[OF q1])
kaliszyk@35222
    55
  apply(simp_all add: Quotient_abs_rep[OF q2] Quotient_rel_rep[OF q2])
kaliszyk@35222
    56
  using q1 q2
kaliszyk@35222
    57
  unfolding Quotient_def
kaliszyk@35222
    58
  apply(blast)+
kaliszyk@35222
    59
  done
kaliszyk@35222
    60
kaliszyk@35222
    61
lemma sum_Inl_rsp[quot_respect]:
kaliszyk@35222
    62
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    63
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    64
  shows "(R1 ===> sum_rel R1 R2) Inl Inl"
haftmann@40465
    65
  by auto
kaliszyk@35222
    66
kaliszyk@35222
    67
lemma sum_Inr_rsp[quot_respect]:
kaliszyk@35222
    68
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    69
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    70
  shows "(R2 ===> sum_rel R1 R2) Inr Inr"
haftmann@40465
    71
  by auto
kaliszyk@35222
    72
kaliszyk@35222
    73
lemma sum_Inl_prs[quot_preserve]:
kaliszyk@35222
    74
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    75
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    76
  shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
nipkow@39302
    77
  apply(simp add: fun_eq_iff)
kaliszyk@35222
    78
  apply(simp add: Quotient_abs_rep[OF q1])
kaliszyk@35222
    79
  done
kaliszyk@35222
    80
kaliszyk@35222
    81
lemma sum_Inr_prs[quot_preserve]:
kaliszyk@35222
    82
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    83
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    84
  shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
nipkow@39302
    85
  apply(simp add: fun_eq_iff)
kaliszyk@35222
    86
  apply(simp add: Quotient_abs_rep[OF q2])
kaliszyk@35222
    87
  done
kaliszyk@35222
    88
kaliszyk@35222
    89
lemma sum_map_id[id_simps]:
kaliszyk@35222
    90
  shows "sum_map id id = id"
nipkow@39302
    91
  by (simp add: fun_eq_iff split_sum_all)
kaliszyk@35222
    92
kaliszyk@35222
    93
lemma sum_rel_eq[id_simps]:
kaliszyk@35222
    94
  shows "sum_rel (op =) (op =) = (op =)"
nipkow@39302
    95
  by (simp add: fun_eq_iff split_sum_all)
kaliszyk@35222
    96
kaliszyk@35222
    97
end