src/HOL/Library/Quotient_Option.thy
author Andreas Lochbihler
Fri Sep 20 10:09:16 2013 +0200 (2013-09-20)
changeset 53745 788730ab7da4
parent 53026 e1a548c11845
child 55466 786edc984c98
permissions -rw-r--r--
prefer Code.abort over code_abort
     1 (*  Title:      HOL/Library/Quotient_Option.thy
     2     Author:     Cezary Kaliszyk and Christian Urban
     3 *)
     4 
     5 header {* Quotient infrastructure for the option type *}
     6 
     7 theory Quotient_Option
     8 imports Main Quotient_Syntax
     9 begin
    10 
    11 subsection {* Rules for the Quotient package *}
    12 
    13 lemma option_rel_map1:
    14   "option_rel R (Option.map f x) y \<longleftrightarrow> option_rel (\<lambda>x. R (f x)) x y"
    15   by (simp add: option_rel_def split: option.split)
    16 
    17 lemma option_rel_map2:
    18   "option_rel R x (Option.map f y) \<longleftrightarrow> option_rel (\<lambda>x y. R x (f y)) x y"
    19   by (simp add: option_rel_def split: option.split)
    20 
    21 lemma option_map_id [id_simps]:
    22   "Option.map id = id"
    23   by (simp add: id_def Option.map.identity fun_eq_iff)
    24 
    25 lemma option_rel_eq [id_simps]:
    26   "option_rel (op =) = (op =)"
    27   by (simp add: option_rel_def fun_eq_iff split: option.split)
    28 
    29 lemma option_symp:
    30   "symp R \<Longrightarrow> symp (option_rel R)"
    31   unfolding symp_def split_option_all option_rel_simps by fast
    32 
    33 lemma option_transp:
    34   "transp R \<Longrightarrow> transp (option_rel R)"
    35   unfolding transp_def split_option_all option_rel_simps by fast
    36 
    37 lemma option_equivp [quot_equiv]:
    38   "equivp R \<Longrightarrow> equivp (option_rel R)"
    39   by (blast intro: equivpI reflp_option_rel option_symp option_transp elim: equivpE)
    40 
    41 lemma option_quotient [quot_thm]:
    42   assumes "Quotient3 R Abs Rep"
    43   shows "Quotient3 (option_rel R) (Option.map Abs) (Option.map Rep)"
    44   apply (rule Quotient3I)
    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])
    46   using Quotient3_rel [OF assms]
    47   apply (simp add: option_rel_def split: option.split)
    48   done
    49 
    50 declare [[mapQ3 option = (option_rel, option_quotient)]]
    51 
    52 lemma option_None_rsp [quot_respect]:
    53   assumes q: "Quotient3 R Abs Rep"
    54   shows "option_rel R None None"
    55   by (rule None_transfer)
    56 
    57 lemma option_Some_rsp [quot_respect]:
    58   assumes q: "Quotient3 R Abs Rep"
    59   shows "(R ===> option_rel R) Some Some"
    60   by (rule Some_transfer)
    61 
    62 lemma option_None_prs [quot_preserve]:
    63   assumes q: "Quotient3 R Abs Rep"
    64   shows "Option.map Abs None = None"
    65   by simp
    66 
    67 lemma option_Some_prs [quot_preserve]:
    68   assumes q: "Quotient3 R Abs Rep"
    69   shows "(Rep ---> Option.map Abs) Some = Some"
    70   apply(simp add: fun_eq_iff)
    71   apply(simp add: Quotient3_abs_rep[OF q])
    72   done
    73 
    74 end