src/HOL/Library/Quotient_Option.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Fri Feb 19 13:54:19 2010 +0100 (2010-02-19)
changeset 35222 4f1fba00f66d
child 35788 f1deaca15ca3
permissions -rw-r--r--
Initial version of HOL quotient package.
kaliszyk@35222
     1
(*  Title:      Quotient_Option.thy
kaliszyk@35222
     2
    Author:     Cezary Kaliszyk and Christian Urban
kaliszyk@35222
     3
*)
kaliszyk@35222
     4
theory Quotient_Option
kaliszyk@35222
     5
imports Main Quotient_Syntax
kaliszyk@35222
     6
begin
kaliszyk@35222
     7
kaliszyk@35222
     8
section {* Quotient infrastructure for the option type. *}
kaliszyk@35222
     9
kaliszyk@35222
    10
fun
kaliszyk@35222
    11
  option_rel
kaliszyk@35222
    12
where
kaliszyk@35222
    13
  "option_rel R None None = True"
kaliszyk@35222
    14
| "option_rel R (Some x) None = False"
kaliszyk@35222
    15
| "option_rel R None (Some x) = False"
kaliszyk@35222
    16
| "option_rel R (Some x) (Some y) = R x y"
kaliszyk@35222
    17
kaliszyk@35222
    18
declare [[map option = (Option.map, option_rel)]]
kaliszyk@35222
    19
kaliszyk@35222
    20
text {* should probably be in Option.thy *}
kaliszyk@35222
    21
lemma split_option_all:
kaliszyk@35222
    22
  shows "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>a. P (Some a))"
kaliszyk@35222
    23
  apply(auto)
kaliszyk@35222
    24
  apply(case_tac x)
kaliszyk@35222
    25
  apply(simp_all)
kaliszyk@35222
    26
  done
kaliszyk@35222
    27
kaliszyk@35222
    28
lemma option_quotient[quot_thm]:
kaliszyk@35222
    29
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    30
  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
kaliszyk@35222
    31
  unfolding Quotient_def
kaliszyk@35222
    32
  apply(simp add: split_option_all)
kaliszyk@35222
    33
  apply(simp add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
kaliszyk@35222
    34
  using q
kaliszyk@35222
    35
  unfolding Quotient_def
kaliszyk@35222
    36
  apply(blast)
kaliszyk@35222
    37
  done
kaliszyk@35222
    38
kaliszyk@35222
    39
lemma option_equivp[quot_equiv]:
kaliszyk@35222
    40
  assumes a: "equivp R"
kaliszyk@35222
    41
  shows "equivp (option_rel R)"
kaliszyk@35222
    42
  apply(rule equivpI)
kaliszyk@35222
    43
  unfolding reflp_def symp_def transp_def
kaliszyk@35222
    44
  apply(simp_all add: split_option_all)
kaliszyk@35222
    45
  apply(blast intro: equivp_reflp[OF a])
kaliszyk@35222
    46
  apply(blast intro: equivp_symp[OF a])
kaliszyk@35222
    47
  apply(blast intro: equivp_transp[OF a])
kaliszyk@35222
    48
  done
kaliszyk@35222
    49
kaliszyk@35222
    50
lemma option_None_rsp[quot_respect]:
kaliszyk@35222
    51
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    52
  shows "option_rel R None None"
kaliszyk@35222
    53
  by simp
kaliszyk@35222
    54
kaliszyk@35222
    55
lemma option_Some_rsp[quot_respect]:
kaliszyk@35222
    56
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    57
  shows "(R ===> option_rel R) Some Some"
kaliszyk@35222
    58
  by simp
kaliszyk@35222
    59
kaliszyk@35222
    60
lemma option_None_prs[quot_preserve]:
kaliszyk@35222
    61
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    62
  shows "Option.map Abs None = None"
kaliszyk@35222
    63
  by simp
kaliszyk@35222
    64
kaliszyk@35222
    65
lemma option_Some_prs[quot_preserve]:
kaliszyk@35222
    66
  assumes q: "Quotient R Abs Rep"
kaliszyk@35222
    67
  shows "(Rep ---> Option.map Abs) Some = Some"
kaliszyk@35222
    68
  apply(simp add: expand_fun_eq)
kaliszyk@35222
    69
  apply(simp add: Quotient_abs_rep[OF q])
kaliszyk@35222
    70
  done
kaliszyk@35222
    71
kaliszyk@35222
    72
lemma option_map_id[id_simps]:
kaliszyk@35222
    73
  shows "Option.map id = id"
kaliszyk@35222
    74
  by (simp add: expand_fun_eq split_option_all)
kaliszyk@35222
    75
kaliszyk@35222
    76
lemma option_rel_eq[id_simps]:
kaliszyk@35222
    77
  shows "option_rel (op =) = (op =)"
kaliszyk@35222
    78
  by (simp add: expand_fun_eq split_option_all)
kaliszyk@35222
    79
kaliszyk@35222
    80
end