src/HOL/Library/Quotient_Option.thy
author bulwahn
Fri Apr 08 16:31:14 2011 +0200 (2011-04-08)
changeset 42316 12635bb655fd
parent 41372 551eb49a6e91
child 45802 b16f976db515
permissions -rw-r--r--
deactivating other compilations in quickcheck_exhaustive momentarily that only interesting for my benchmarks and experiments
wenzelm@35788
     1
(*  Title:      HOL/Library/Quotient_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
kaliszyk@35222
    19
declare [[map option = (Option.map, option_rel)]]
kaliszyk@35222
    20
haftmann@40820
    21
lemma option_rel_unfold:
haftmann@40820
    22
  "option_rel R x y = (case (x, y) of (None, None) \<Rightarrow> True
haftmann@40820
    23
    | (Some x, Some y) \<Rightarrow> R x y
haftmann@40820
    24
    | _ \<Rightarrow> False)"
haftmann@40820
    25
  by (cases x) (cases y, simp_all)+
haftmann@40820
    26
haftmann@40820
    27
lemma option_rel_map1:
haftmann@40820
    28
  "option_rel R (Option.map f x) y \<longleftrightarrow> option_rel (\<lambda>x. R (f x)) x y"
haftmann@40820
    29
  by (simp add: option_rel_unfold split: option.split)
haftmann@40820
    30
haftmann@40820
    31
lemma option_rel_map2:
haftmann@40820
    32
  "option_rel R x (Option.map f y) \<longleftrightarrow> option_rel (\<lambda>x y. R x (f y)) x y"
haftmann@40820
    33
  by (simp add: option_rel_unfold split: option.split)
haftmann@40820
    34
haftmann@40820
    35
lemma option_map_id [id_simps]:
haftmann@40820
    36
  "Option.map id = id"
haftmann@40820
    37
  by (simp add: id_def Option.map.identity fun_eq_iff)
haftmann@40820
    38
haftmann@40820
    39
lemma option_rel_eq [id_simps]:
haftmann@40820
    40
  "option_rel (op =) = (op =)"
haftmann@40820
    41
  by (simp add: option_rel_unfold fun_eq_iff split: option.split)
haftmann@40820
    42
haftmann@40820
    43
lemma option_reflp:
haftmann@40820
    44
  "reflp R \<Longrightarrow> reflp (option_rel R)"
haftmann@40820
    45
  by (auto simp add: option_rel_unfold split: option.splits intro!: reflpI elim: reflpE)
haftmann@40820
    46
haftmann@40820
    47
lemma option_symp:
haftmann@40820
    48
  "symp R \<Longrightarrow> symp (option_rel R)"
haftmann@40820
    49
  by (auto simp add: option_rel_unfold split: option.splits intro!: sympI elim: sympE)
haftmann@40820
    50
haftmann@40820
    51
lemma option_transp:
haftmann@40820
    52
  "transp R \<Longrightarrow> transp (option_rel R)"
haftmann@40820
    53
  by (auto simp add: option_rel_unfold split: option.splits intro!: transpI elim: transpE)
haftmann@40820
    54
haftmann@40820
    55
lemma option_equivp [quot_equiv]:
haftmann@40820
    56
  "equivp R \<Longrightarrow> equivp (option_rel R)"
haftmann@40820
    57
  by (blast intro: equivpI option_reflp option_symp option_transp elim: equivpE)
haftmann@40820
    58
haftmann@40820
    59
lemma option_quotient [quot_thm]:
haftmann@40820
    60
  assumes "Quotient R Abs Rep"
haftmann@40820
    61
  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
haftmann@40820
    62
  apply (rule QuotientI)
haftmann@41372
    63
  apply (simp_all add: Option.map.compositionality comp_def Option.map.identity option_rel_eq option_rel_map1 option_rel_map2 Quotient_abs_rep [OF assms] Quotient_rel_rep [OF assms])
haftmann@40820
    64
  using Quotient_rel [OF assms]
haftmann@40820
    65
  apply (simp add: option_rel_unfold split: option.split)
kaliszyk@35222
    66
  done
kaliszyk@35222
    67
haftmann@40820
    68
lemma option_None_rsp [quot_respect]:
kaliszyk@35222
    69
  assumes q: "Quotient 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]:
kaliszyk@35222
    74
  assumes q: "Quotient 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]:
kaliszyk@35222
    79
  assumes q: "Quotient 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]:
kaliszyk@35222
    84
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    85
  shows "(Rep ---> Option.map Abs) Some = Some"
nipkow@39302
    86
  apply(simp add: fun_eq_iff)
kaliszyk@35222
    87
  apply(simp add: Quotient_abs_rep[OF q])
kaliszyk@35222
    88
  done
kaliszyk@35222
    89
kaliszyk@35222
    90
end