src/HOL/Library/Quotient_Option.thy
author haftmann
Fri Nov 01 18:51:14 2013 +0100 (2013-11-01)
changeset 54230 b1d955791529
parent 53026 e1a548c11845
child 55466 786edc984c98
permissions -rw-r--r--
more simplification rules on unary and binary minus
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:
haftmann@40820
    14
  "option_rel R (Option.map 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:
haftmann@40820
    18
  "option_rel R x (Option.map 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
haftmann@40820
    21
lemma option_map_id [id_simps]:
haftmann@40820
    22
  "Option.map id = id"
haftmann@40820
    23
  by (simp add: id_def Option.map.identity fun_eq_iff)
haftmann@40820
    24
kuncar@53012
    25
lemma option_rel_eq [id_simps]:
haftmann@40820
    26
  "option_rel (op =) = (op =)"
traytel@53026
    27
  by (simp add: option_rel_def fun_eq_iff split: option.split)
haftmann@40820
    28
haftmann@40820
    29
lemma option_symp:
haftmann@40820
    30
  "symp R \<Longrightarrow> symp (option_rel R)"
traytel@53026
    31
  unfolding symp_def split_option_all option_rel_simps by fast
haftmann@40820
    32
haftmann@40820
    33
lemma option_transp:
haftmann@40820
    34
  "transp R \<Longrightarrow> transp (option_rel R)"
traytel@53026
    35
  unfolding transp_def split_option_all option_rel_simps by fast
haftmann@40820
    36
haftmann@40820
    37
lemma option_equivp [quot_equiv]:
haftmann@40820
    38
  "equivp R \<Longrightarrow> equivp (option_rel R)"
kuncar@51994
    39
  by (blast intro: equivpI reflp_option_rel option_symp option_transp elim: equivpE)
haftmann@40820
    40
haftmann@40820
    41
lemma option_quotient [quot_thm]:
kuncar@47308
    42
  assumes "Quotient3 R Abs Rep"
kuncar@47308
    43
  shows "Quotient3 (option_rel R) (Option.map Abs) (Option.map Rep)"
kuncar@47308
    44
  apply (rule Quotient3I)
kuncar@47308
    45
  apply (simp_all add: Option.map.compositionality comp_def Option.map.identity option_rel_eq option_rel_map1 option_rel_map2 Quotient3_abs_rep [OF assms] Quotient3_rel_rep [OF assms])
kuncar@47308
    46
  using Quotient3_rel [OF assms]
traytel@53026
    47
  apply (simp add: option_rel_def split: option.split)
kaliszyk@35222
    48
  done
kaliszyk@35222
    49
kuncar@47308
    50
declare [[mapQ3 option = (option_rel, option_quotient)]]
kuncar@47094
    51
haftmann@40820
    52
lemma option_None_rsp [quot_respect]:
kuncar@47308
    53
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    54
  shows "option_rel R None None"
huffman@47624
    55
  by (rule None_transfer)
kaliszyk@35222
    56
haftmann@40820
    57
lemma option_Some_rsp [quot_respect]:
kuncar@47308
    58
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    59
  shows "(R ===> option_rel R) Some Some"
huffman@47624
    60
  by (rule Some_transfer)
kaliszyk@35222
    61
haftmann@40820
    62
lemma option_None_prs [quot_preserve]:
kuncar@47308
    63
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    64
  shows "Option.map Abs None = None"
kaliszyk@35222
    65
  by simp
kaliszyk@35222
    66
haftmann@40820
    67
lemma option_Some_prs [quot_preserve]:
kuncar@47308
    68
  assumes q: "Quotient3 R Abs Rep"
kaliszyk@35222
    69
  shows "(Rep ---> Option.map Abs) Some = Some"
nipkow@39302
    70
  apply(simp add: fun_eq_iff)
kuncar@47308
    71
  apply(simp add: Quotient3_abs_rep[OF q])
kaliszyk@35222
    72
  done
kaliszyk@35222
    73
kaliszyk@35222
    74
end