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