src/HOL/Library/Quotient_Option.thy
author kuncar
Tue Apr 03 16:26:48 2012 +0200 (2012-04-03)
changeset 47308 9caab698dbe4
parent 47094 1a7ad2601cb5
child 47455 26315a545e26
permissions -rw-r--r--
new package Lifting - initial commit
kuncar@47308
     1
(*  Title:      HOL/Library/Quotient3_Option.thy
kaliszyk@35222
     2
    Author:     Cezary Kaliszyk and Christian Urban
kaliszyk@35222
     3
*)
wenzelm@35788
     4
wenzelm@35788
     5
header {* Quotient infrastructure for the option type *}
wenzelm@35788
     6
kaliszyk@35222
     7
theory Quotient_Option
kaliszyk@35222
     8
imports Main Quotient_Syntax
kaliszyk@35222
     9
begin
kaliszyk@35222
    10
kaliszyk@35222
    11
fun
haftmann@40542
    12
  option_rel :: "('a \<Rightarrow> 'b \<Rightarrow> bool) \<Rightarrow> 'a option \<Rightarrow> 'b option \<Rightarrow> bool"
kaliszyk@35222
    13
where
kaliszyk@35222
    14
  "option_rel R None None = True"
kaliszyk@35222
    15
| "option_rel R (Some x) None = False"
kaliszyk@35222
    16
| "option_rel R None (Some x) = False"
kaliszyk@35222
    17
| "option_rel R (Some x) (Some y) = R x y"
kaliszyk@35222
    18
haftmann@40820
    19
lemma option_rel_unfold:
haftmann@40820
    20
  "option_rel R x y = (case (x, y) of (None, None) \<Rightarrow> True
haftmann@40820
    21
    | (Some x, Some y) \<Rightarrow> R x y
haftmann@40820
    22
    | _ \<Rightarrow> False)"
haftmann@40820
    23
  by (cases x) (cases y, simp_all)+
haftmann@40820
    24
haftmann@40820
    25
lemma option_rel_map1:
haftmann@40820
    26
  "option_rel R (Option.map f x) y \<longleftrightarrow> option_rel (\<lambda>x. R (f x)) x y"
haftmann@40820
    27
  by (simp add: option_rel_unfold split: option.split)
haftmann@40820
    28
haftmann@40820
    29
lemma option_rel_map2:
haftmann@40820
    30
  "option_rel R x (Option.map f y) \<longleftrightarrow> option_rel (\<lambda>x y. R x (f y)) x y"
haftmann@40820
    31
  by (simp add: option_rel_unfold split: option.split)
haftmann@40820
    32
haftmann@40820
    33
lemma option_map_id [id_simps]:
haftmann@40820
    34
  "Option.map id = id"
haftmann@40820
    35
  by (simp add: id_def Option.map.identity fun_eq_iff)
haftmann@40820
    36
haftmann@40820
    37
lemma option_rel_eq [id_simps]:
haftmann@40820
    38
  "option_rel (op =) = (op =)"
haftmann@40820
    39
  by (simp add: option_rel_unfold fun_eq_iff split: option.split)
haftmann@40820
    40
haftmann@40820
    41
lemma option_reflp:
haftmann@40820
    42
  "reflp R \<Longrightarrow> reflp (option_rel R)"
haftmann@40820
    43
  by (auto simp add: option_rel_unfold split: option.splits intro!: reflpI elim: reflpE)
haftmann@40820
    44
haftmann@40820
    45
lemma option_symp:
haftmann@40820
    46
  "symp R \<Longrightarrow> symp (option_rel R)"
haftmann@40820
    47
  by (auto simp add: option_rel_unfold split: option.splits intro!: sympI elim: sympE)
haftmann@40820
    48
haftmann@40820
    49
lemma option_transp:
haftmann@40820
    50
  "transp R \<Longrightarrow> transp (option_rel R)"
haftmann@40820
    51
  by (auto simp add: option_rel_unfold split: option.splits intro!: transpI elim: transpE)
haftmann@40820
    52
haftmann@40820
    53
lemma option_equivp [quot_equiv]:
haftmann@40820
    54
  "equivp R \<Longrightarrow> equivp (option_rel R)"
haftmann@40820
    55
  by (blast intro: equivpI option_reflp option_symp option_transp elim: equivpE)
haftmann@40820
    56
haftmann@40820
    57
lemma option_quotient [quot_thm]:
kuncar@47308
    58
  assumes "Quotient3 R Abs Rep"
kuncar@47308
    59
  shows "Quotient3 (option_rel R) (Option.map Abs) (Option.map Rep)"
kuncar@47308
    60
  apply (rule Quotient3I)
kuncar@47308
    61
  apply (simp_all add: Option.map.compositionality comp_def Option.map.identity option_rel_eq option_rel_map1 option_rel_map2 Quotient3_abs_rep [OF assms] Quotient3_rel_rep [OF assms])
kuncar@47308
    62
  using Quotient3_rel [OF assms]
haftmann@40820
    63
  apply (simp add: option_rel_unfold split: option.split)
kaliszyk@35222
    64
  done
kaliszyk@35222
    65
kuncar@47308
    66
declare [[mapQ3 option = (option_rel, option_quotient)]]
kuncar@47094
    67
haftmann@40820
    68
lemma option_None_rsp [quot_respect]:
kuncar@47308
    69
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    70
  shows "option_rel R None None"
kaliszyk@35222
    71
  by simp
kaliszyk@35222
    72
haftmann@40820
    73
lemma option_Some_rsp [quot_respect]:
kuncar@47308
    74
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    75
  shows "(R ===> option_rel R) Some Some"
haftmann@40464
    76
  by auto
kaliszyk@35222
    77
haftmann@40820
    78
lemma option_None_prs [quot_preserve]:
kuncar@47308
    79
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    80
  shows "Option.map Abs None = None"
kaliszyk@35222
    81
  by simp
kaliszyk@35222
    82
haftmann@40820
    83
lemma option_Some_prs [quot_preserve]:
kuncar@47308
    84
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    85
  shows "(Rep ---> Option.map Abs) Some = Some"
nipkow@39302
    86
  apply(simp add: fun_eq_iff)
kuncar@47308
    87
  apply(simp add: Quotient3_abs_rep[OF q])
kaliszyk@35222
    88
  done
kaliszyk@35222
    89
kaliszyk@35222
    90
end