src/HOL/Library/Quotient_Option.thy
author kuncar
Tue Feb 18 23:03:49 2014 +0100 (2014-02-18)
changeset 55564 e81ee43ab290
parent 55525 70b7e91fa1f9
child 56525 b5b6ad5dc2ae
permissions -rw-r--r--
delete or move now not necessary reflexivity rules due to 1726f46d2aa8
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
kuncar@55564
    25
lemma reflp_rel_option:
kuncar@55564
    26
  "reflp R \<Longrightarrow> reflp (rel_option R)"
kuncar@55564
    27
  unfolding reflp_def split_option_all by simp
kuncar@55564
    28
haftmann@40820
    29
lemma option_symp:
blanchet@55525
    30
  "symp R \<Longrightarrow> symp (rel_option R)"
blanchet@55525
    31
  unfolding symp_def split_option_all
blanchet@55525
    32
  by (simp only: option.rel_inject option.rel_distinct) fast
haftmann@40820
    33
haftmann@40820
    34
lemma option_transp:
blanchet@55525
    35
  "transp R \<Longrightarrow> transp (rel_option R)"
blanchet@55525
    36
  unfolding transp_def split_option_all
blanchet@55525
    37
  by (simp only: option.rel_inject option.rel_distinct) fast
haftmann@40820
    38
haftmann@40820
    39
lemma option_equivp [quot_equiv]:
blanchet@55525
    40
  "equivp R \<Longrightarrow> equivp (rel_option R)"
blanchet@55525
    41
  by (blast intro: equivpI reflp_rel_option option_symp option_transp elim: equivpE)
haftmann@40820
    42
haftmann@40820
    43
lemma option_quotient [quot_thm]:
kuncar@47308
    44
  assumes "Quotient3 R Abs Rep"
blanchet@55525
    45
  shows "Quotient3 (rel_option R) (map_option Abs) (map_option Rep)"
kuncar@47308
    46
  apply (rule Quotient3I)
blanchet@55525
    47
  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
    48
  using Quotient3_rel [OF assms]
blanchet@55525
    49
  apply (simp add: rel_option_iff split: option.split)
kaliszyk@35222
    50
  done
kaliszyk@35222
    51
blanchet@55525
    52
declare [[mapQ3 option = (rel_option, option_quotient)]]
kuncar@47094
    53
haftmann@40820
    54
lemma option_None_rsp [quot_respect]:
kuncar@47308
    55
  assumes q: "Quotient3 R Abs Rep"
blanchet@55525
    56
  shows "rel_option R None None"
huffman@47624
    57
  by (rule None_transfer)
kaliszyk@35222
    58
haftmann@40820
    59
lemma option_Some_rsp [quot_respect]:
kuncar@47308
    60
  assumes q: "Quotient3 R Abs Rep"
blanchet@55525
    61
  shows "(R ===> rel_option R) Some Some"
huffman@47624
    62
  by (rule Some_transfer)
kaliszyk@35222
    63
haftmann@40820
    64
lemma option_None_prs [quot_preserve]:
kuncar@47308
    65
  assumes q: "Quotient3 R Abs Rep"
blanchet@55466
    66
  shows "map_option Abs None = None"
blanchet@55525
    67
  by (rule Option.option.map(1))
kaliszyk@35222
    68
haftmann@40820
    69
lemma option_Some_prs [quot_preserve]:
kuncar@47308
    70
  assumes q: "Quotient3 R Abs Rep"
blanchet@55466
    71
  shows "(Rep ---> map_option Abs) Some = Some"
nipkow@39302
    72
  apply(simp add: fun_eq_iff)
kuncar@47308
    73
  apply(simp add: Quotient3_abs_rep[OF q])
kaliszyk@35222
    74
  done
kaliszyk@35222
    75
kaliszyk@35222
    76
end