src/HOL/Library/Quotient_Sum.thy
author kuncar
Fri Mar 23 14:20:09 2012 +0100 (2012-03-23)
changeset 47094 1a7ad2601cb5
parent 45802 b16f976db515
child 47308 9caab698dbe4
permissions -rw-r--r--
store the relational theorem for every relator
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@40820
    19
lemma sum_rel_unfold:
haftmann@40820
    20
  "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
haftmann@40820
    21
    | (Inr x, Inr y) \<Rightarrow> R2 x y
haftmann@40820
    22
    | _ \<Rightarrow> False)"
haftmann@40820
    23
  by (cases x) (cases y, simp_all)+
kaliszyk@35222
    24
haftmann@40820
    25
lemma sum_rel_map1:
haftmann@40820
    26
  "sum_rel R1 R2 (sum_map f1 f2 x) y \<longleftrightarrow> sum_rel (\<lambda>x. R1 (f1 x)) (\<lambda>x. R2 (f2 x)) x y"
haftmann@40820
    27
  by (simp add: sum_rel_unfold split: sum.split)
haftmann@40820
    28
haftmann@40820
    29
lemma sum_rel_map2:
haftmann@40820
    30
  "sum_rel R1 R2 x (sum_map f1 f2 y) \<longleftrightarrow> sum_rel (\<lambda>x y. R1 x (f1 y)) (\<lambda>x y. R2 x (f2 y)) x y"
haftmann@40820
    31
  by (simp add: sum_rel_unfold split: sum.split)
haftmann@40820
    32
haftmann@40820
    33
lemma sum_map_id [id_simps]:
haftmann@40820
    34
  "sum_map id id = id"
haftmann@40820
    35
  by (simp add: id_def sum_map.identity fun_eq_iff)
kaliszyk@35222
    36
haftmann@40820
    37
lemma sum_rel_eq [id_simps]:
haftmann@40820
    38
  "sum_rel (op =) (op =) = (op =)"
haftmann@40820
    39
  by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
haftmann@40820
    40
haftmann@40820
    41
lemma sum_reflp:
haftmann@40820
    42
  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
haftmann@40820
    43
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: reflpI elim: reflpE)
kaliszyk@35222
    44
haftmann@40820
    45
lemma sum_symp:
haftmann@40820
    46
  "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
haftmann@40820
    47
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: sympI elim: sympE)
haftmann@40820
    48
haftmann@40820
    49
lemma sum_transp:
haftmann@40820
    50
  "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
haftmann@40820
    51
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: transpI elim: transpE)
haftmann@40820
    52
haftmann@40820
    53
lemma sum_equivp [quot_equiv]:
haftmann@40820
    54
  "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
haftmann@40820
    55
  by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
haftmann@40820
    56
  
haftmann@40820
    57
lemma sum_quotient [quot_thm]:
kaliszyk@35222
    58
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    59
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    60
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
haftmann@40820
    61
  apply (rule QuotientI)
haftmann@41372
    62
  apply (simp_all add: sum_map.compositionality comp_def sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
haftmann@40820
    63
    Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
haftmann@40820
    64
  using Quotient_rel [OF q1] Quotient_rel [OF q2]
haftmann@41372
    65
  apply (simp add: sum_rel_unfold comp_def split: sum.split)
kaliszyk@35222
    66
  done
kaliszyk@35222
    67
kuncar@47094
    68
declare [[map sum = (sum_rel, sum_quotient)]]
kuncar@47094
    69
haftmann@40820
    70
lemma sum_Inl_rsp [quot_respect]:
kaliszyk@35222
    71
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    72
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    73
  shows "(R1 ===> sum_rel R1 R2) Inl Inl"
haftmann@40465
    74
  by auto
kaliszyk@35222
    75
haftmann@40820
    76
lemma sum_Inr_rsp [quot_respect]:
kaliszyk@35222
    77
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    78
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    79
  shows "(R2 ===> sum_rel R1 R2) Inr Inr"
haftmann@40465
    80
  by auto
kaliszyk@35222
    81
haftmann@40820
    82
lemma sum_Inl_prs [quot_preserve]:
kaliszyk@35222
    83
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    84
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    85
  shows "(Rep1 ---> sum_map Abs1 Abs2) Inl = Inl"
nipkow@39302
    86
  apply(simp add: fun_eq_iff)
kaliszyk@35222
    87
  apply(simp add: Quotient_abs_rep[OF q1])
kaliszyk@35222
    88
  done
kaliszyk@35222
    89
haftmann@40820
    90
lemma sum_Inr_prs [quot_preserve]:
kaliszyk@35222
    91
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    92
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    93
  shows "(Rep2 ---> sum_map Abs1 Abs2) Inr = Inr"
nipkow@39302
    94
  apply(simp add: fun_eq_iff)
kaliszyk@35222
    95
  apply(simp add: Quotient_abs_rep[OF q2])
kaliszyk@35222
    96
  done
kaliszyk@35222
    97
kaliszyk@35222
    98
end