src/HOL/Library/Quotient_Option.thy
author wenzelm
Sun Mar 14 14:31:24 2010 +0100 (2010-03-14)
changeset 35788 f1deaca15ca3
parent 35222 4f1fba00f66d
child 39198 f967a16dfcdd
permissions -rw-r--r--
observe standard header format;
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
kaliszyk@35222
    12
  option_rel
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
kaliszyk@35222
    21
text {* should probably be in Option.thy *}
kaliszyk@35222
    22
lemma split_option_all:
kaliszyk@35222
    23
  shows "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>a. P (Some a))"
kaliszyk@35222
    24
  apply(auto)
kaliszyk@35222
    25
  apply(case_tac x)
kaliszyk@35222
    26
  apply(simp_all)
kaliszyk@35222
    27
  done
kaliszyk@35222
    28
kaliszyk@35222
    29
lemma option_quotient[quot_thm]:
kaliszyk@35222
    30
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    31
  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
kaliszyk@35222
    32
  unfolding Quotient_def
kaliszyk@35222
    33
  apply(simp add: split_option_all)
kaliszyk@35222
    34
  apply(simp add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
kaliszyk@35222
    35
  using q
kaliszyk@35222
    36
  unfolding Quotient_def
kaliszyk@35222
    37
  apply(blast)
kaliszyk@35222
    38
  done
kaliszyk@35222
    39
kaliszyk@35222
    40
lemma option_equivp[quot_equiv]:
kaliszyk@35222
    41
  assumes a: "equivp R"
kaliszyk@35222
    42
  shows "equivp (option_rel R)"
kaliszyk@35222
    43
  apply(rule equivpI)
kaliszyk@35222
    44
  unfolding reflp_def symp_def transp_def
kaliszyk@35222
    45
  apply(simp_all add: split_option_all)
kaliszyk@35222
    46
  apply(blast intro: equivp_reflp[OF a])
kaliszyk@35222
    47
  apply(blast intro: equivp_symp[OF a])
kaliszyk@35222
    48
  apply(blast intro: equivp_transp[OF a])
kaliszyk@35222
    49
  done
kaliszyk@35222
    50
kaliszyk@35222
    51
lemma option_None_rsp[quot_respect]:
kaliszyk@35222
    52
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    53
  shows "option_rel R None None"
kaliszyk@35222
    54
  by simp
kaliszyk@35222
    55
kaliszyk@35222
    56
lemma option_Some_rsp[quot_respect]:
kaliszyk@35222
    57
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    58
  shows "(R ===> option_rel R) Some Some"
kaliszyk@35222
    59
  by simp
kaliszyk@35222
    60
kaliszyk@35222
    61
lemma option_None_prs[quot_preserve]:
kaliszyk@35222
    62
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    63
  shows "Option.map Abs None = None"
kaliszyk@35222
    64
  by simp
kaliszyk@35222
    65
kaliszyk@35222
    66
lemma option_Some_prs[quot_preserve]:
kaliszyk@35222
    67
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    68
  shows "(Rep ---> Option.map Abs) Some = Some"
kaliszyk@35222
    69
  apply(simp add: expand_fun_eq)
kaliszyk@35222
    70
  apply(simp add: Quotient_abs_rep[OF q])
kaliszyk@35222
    71
  done
kaliszyk@35222
    72
kaliszyk@35222
    73
lemma option_map_id[id_simps]:
kaliszyk@35222
    74
  shows "Option.map id = id"
kaliszyk@35222
    75
  by (simp add: expand_fun_eq split_option_all)
kaliszyk@35222
    76
kaliszyk@35222
    77
lemma option_rel_eq[id_simps]:
kaliszyk@35222
    78
  shows "option_rel (op =) = (op =)"
kaliszyk@35222
    79
  by (simp add: expand_fun_eq split_option_all)
kaliszyk@35222
    80
kaliszyk@35222
    81
end