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