src/HOL/Library/Quotient_Option.thy
author blanchet
Fri Feb 14 07:53:46 2014 +0100 (2014-02-14)
changeset 55466 786edc984c98
parent 53026 e1a548c11845
child 55525 70b7e91fa1f9
permissions -rw-r--r--
merged 'Option.map' and 'Option.map_option'
wenzelm@47455
     1
(*  Title:      HOL/Library/Quotient_Option.thy
kuncar@53012
     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
kuncar@53012
    11
subsection {* Rules for the Quotient package *}
kuncar@51956
    12
haftmann@40820
    13
lemma option_rel_map1:
blanchet@55466
    14
  "option_rel R (map_option f x) y \<longleftrightarrow> option_rel (\<lambda>x. R (f x)) x y"
traytel@53026
    15
  by (simp add: option_rel_def split: option.split)
haftmann@40820
    16
haftmann@40820
    17
lemma option_rel_map2:
blanchet@55466
    18
  "option_rel R x (map_option f y) \<longleftrightarrow> option_rel (\<lambda>x y. R x (f y)) x y"
traytel@53026
    19
  by (simp add: option_rel_def split: option.split)
haftmann@40820
    20
blanchet@55466
    21
declare
blanchet@55466
    22
  map_option.id [id_simps]
blanchet@55466
    23
  option_rel_eq [id_simps]
haftmann@40820
    24
haftmann@40820
    25
lemma option_symp:
haftmann@40820
    26
  "symp R \<Longrightarrow> symp (option_rel R)"
traytel@53026
    27
  unfolding symp_def split_option_all option_rel_simps by fast
haftmann@40820
    28
haftmann@40820
    29
lemma option_transp:
haftmann@40820
    30
  "transp R \<Longrightarrow> transp (option_rel R)"
traytel@53026
    31
  unfolding transp_def split_option_all option_rel_simps by fast
haftmann@40820
    32
haftmann@40820
    33
lemma option_equivp [quot_equiv]:
haftmann@40820
    34
  "equivp R \<Longrightarrow> equivp (option_rel R)"
kuncar@51994
    35
  by (blast intro: equivpI reflp_option_rel option_symp option_transp elim: equivpE)
haftmann@40820
    36
haftmann@40820
    37
lemma option_quotient [quot_thm]:
kuncar@47308
    38
  assumes "Quotient3 R Abs Rep"
blanchet@55466
    39
  shows "Quotient3 (option_rel R) (map_option Abs) (map_option Rep)"
kuncar@47308
    40
  apply (rule Quotient3I)
blanchet@55466
    41
  apply (simp_all add: option.map_comp comp_def option.map_id[unfolded id_def] option_rel_eq option_rel_map1 option_rel_map2 Quotient3_abs_rep [OF assms] Quotient3_rel_rep [OF assms])
kuncar@47308
    42
  using Quotient3_rel [OF assms]
traytel@53026
    43
  apply (simp add: option_rel_def split: option.split)
kaliszyk@35222
    44
  done
kaliszyk@35222
    45
kuncar@47308
    46
declare [[mapQ3 option = (option_rel, option_quotient)]]
kuncar@47094
    47
haftmann@40820
    48
lemma option_None_rsp [quot_respect]:
kuncar@47308
    49
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    50
  shows "option_rel R None None"
huffman@47624
    51
  by (rule None_transfer)
kaliszyk@35222
    52
haftmann@40820
    53
lemma option_Some_rsp [quot_respect]:
kuncar@47308
    54
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    55
  shows "(R ===> option_rel R) Some Some"
huffman@47624
    56
  by (rule Some_transfer)
kaliszyk@35222
    57
haftmann@40820
    58
lemma option_None_prs [quot_preserve]:
kuncar@47308
    59
  assumes q: "Quotient3 R Abs Rep"
blanchet@55466
    60
  shows "map_option Abs None = None"
kaliszyk@35222
    61
  by simp
kaliszyk@35222
    62
haftmann@40820
    63
lemma option_Some_prs [quot_preserve]:
kuncar@47308
    64
  assumes q: "Quotient3 R Abs Rep"
blanchet@55466
    65
  shows "(Rep ---> map_option Abs) Some = Some"
nipkow@39302
    66
  apply(simp add: fun_eq_iff)
kuncar@47308
    67
  apply(simp add: Quotient3_abs_rep[OF q])
kaliszyk@35222
    68
  done
kaliszyk@35222
    69
kaliszyk@35222
    70
end