src/HOL/Library/Quotient_Sum.thy
author haftmann
Tue Nov 30 15:58:09 2010 +0100 (2010-11-30)
changeset 40820 fd9c98ead9a9
parent 40610 70776ecfe324
child 41372 551eb49a6e91
permissions -rw-r--r--
more systematic and compact proofs on type relation operators using natural deduction rules
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@37678
    19
declare [[map sum = (sum_map, sum_rel)]]
kaliszyk@35222
    20
haftmann@40820
    21
lemma sum_rel_unfold:
haftmann@40820
    22
  "sum_rel R1 R2 x y = (case (x, y) of (Inl x, Inl y) \<Rightarrow> R1 x y
haftmann@40820
    23
    | (Inr x, Inr y) \<Rightarrow> R2 x y
haftmann@40820
    24
    | _ \<Rightarrow> False)"
haftmann@40820
    25
  by (cases x) (cases y, simp_all)+
kaliszyk@35222
    26
haftmann@40820
    27
lemma sum_rel_map1:
haftmann@40820
    28
  "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
    29
  by (simp add: sum_rel_unfold split: sum.split)
haftmann@40820
    30
haftmann@40820
    31
lemma sum_rel_map2:
haftmann@40820
    32
  "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
    33
  by (simp add: sum_rel_unfold split: sum.split)
haftmann@40820
    34
haftmann@40820
    35
lemma sum_map_id [id_simps]:
haftmann@40820
    36
  "sum_map id id = id"
haftmann@40820
    37
  by (simp add: id_def sum_map.identity fun_eq_iff)
kaliszyk@35222
    38
haftmann@40820
    39
lemma sum_rel_eq [id_simps]:
haftmann@40820
    40
  "sum_rel (op =) (op =) = (op =)"
haftmann@40820
    41
  by (simp add: sum_rel_unfold fun_eq_iff split: sum.split)
haftmann@40820
    42
haftmann@40820
    43
lemma sum_reflp:
haftmann@40820
    44
  "reflp R1 \<Longrightarrow> reflp R2 \<Longrightarrow> reflp (sum_rel R1 R2)"
haftmann@40820
    45
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: reflpI elim: reflpE)
kaliszyk@35222
    46
haftmann@40820
    47
lemma sum_symp:
haftmann@40820
    48
  "symp R1 \<Longrightarrow> symp R2 \<Longrightarrow> symp (sum_rel R1 R2)"
haftmann@40820
    49
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: sympI elim: sympE)
haftmann@40820
    50
haftmann@40820
    51
lemma sum_transp:
haftmann@40820
    52
  "transp R1 \<Longrightarrow> transp R2 \<Longrightarrow> transp (sum_rel R1 R2)"
haftmann@40820
    53
  by (auto simp add: sum_rel_unfold split: sum.splits intro!: transpI elim: transpE)
haftmann@40820
    54
haftmann@40820
    55
lemma sum_equivp [quot_equiv]:
haftmann@40820
    56
  "equivp R1 \<Longrightarrow> equivp R2 \<Longrightarrow> equivp (sum_rel R1 R2)"
haftmann@40820
    57
  by (blast intro: equivpI sum_reflp sum_symp sum_transp elim: equivpE)
haftmann@40820
    58
  
haftmann@40820
    59
lemma sum_quotient [quot_thm]:
kaliszyk@35222
    60
  assumes q1: "Quotient R1 Abs1 Rep1"
kaliszyk@35222
    61
  assumes q2: "Quotient R2 Abs2 Rep2"
kaliszyk@35222
    62
  shows "Quotient (sum_rel R1 R2) (sum_map Abs1 Abs2) (sum_map Rep1 Rep2)"
haftmann@40820
    63
  apply (rule QuotientI)
haftmann@40820
    64
  apply (simp_all add: sum_map.compositionality sum_map.identity sum_rel_eq sum_rel_map1 sum_rel_map2
haftmann@40820
    65
    Quotient_abs_rep [OF q1] Quotient_rel_rep [OF q1] Quotient_abs_rep [OF q2] Quotient_rel_rep [OF q2])
haftmann@40820
    66
  using Quotient_rel [OF q1] Quotient_rel [OF q2]
haftmann@40820
    67
  apply (simp add: sum_rel_unfold split: sum.split)
kaliszyk@35222
    68
  done
kaliszyk@35222
    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