src/HOL/Library/Quotient_Option.thy
author wenzelm
Sat Nov 04 15:24:40 2017 +0100 (21 months ago)
changeset 67003 49850a679c2c
parent 62954 c5d0fdc260fa
permissions -rw-r--r--
more robust sorted_entries;
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@60500
     5
section \<open>Quotient infrastructure for the option type\<close>
wenzelm@35788
     6
kaliszyk@35222
     7
theory Quotient_Option
wenzelm@62954
     8
imports Quotient_Syntax
kaliszyk@35222
     9
begin
kaliszyk@35222
    10
wenzelm@60500
    11
subsection \<open>Rules for the Quotient package\<close>
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]
kuncar@56525
    23
  option.rel_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)
kuncar@56525
    47
  apply (simp_all add: option.map_comp comp_def option.map_id[unfolded id_def] option.rel_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"
traytel@58916
    57
  by (rule option.ctr_transfer(1))
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"
traytel@58916
    62
  by (rule option.ctr_transfer(2))
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