src/HOL/Library/Quotient_Option.thy
changeset 35222 4f1fba00f66d
child 35788 f1deaca15ca3
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/HOL/Library/Quotient_Option.thy	Fri Feb 19 13:54:19 2010 +0100
     1.3 @@ -0,0 +1,80 @@
     1.4 +(*  Title:      Quotient_Option.thy
     1.5 +    Author:     Cezary Kaliszyk and Christian Urban
     1.6 +*)
     1.7 +theory Quotient_Option
     1.8 +imports Main Quotient_Syntax
     1.9 +begin
    1.10 +
    1.11 +section {* Quotient infrastructure for the option type. *}
    1.12 +
    1.13 +fun
    1.14 +  option_rel
    1.15 +where
    1.16 +  "option_rel R None None = True"
    1.17 +| "option_rel R (Some x) None = False"
    1.18 +| "option_rel R None (Some x) = False"
    1.19 +| "option_rel R (Some x) (Some y) = R x y"
    1.20 +
    1.21 +declare [[map option = (Option.map, option_rel)]]
    1.22 +
    1.23 +text {* should probably be in Option.thy *}
    1.24 +lemma split_option_all:
    1.25 +  shows "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>a. P (Some a))"
    1.26 +  apply(auto)
    1.27 +  apply(case_tac x)
    1.28 +  apply(simp_all)
    1.29 +  done
    1.30 +
    1.31 +lemma option_quotient[quot_thm]:
    1.32 +  assumes q: "Quotient R Abs Rep"
    1.33 +  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
    1.34 +  unfolding Quotient_def
    1.35 +  apply(simp add: split_option_all)
    1.36 +  apply(simp add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
    1.37 +  using q
    1.38 +  unfolding Quotient_def
    1.39 +  apply(blast)
    1.40 +  done
    1.41 +
    1.42 +lemma option_equivp[quot_equiv]:
    1.43 +  assumes a: "equivp R"
    1.44 +  shows "equivp (option_rel R)"
    1.45 +  apply(rule equivpI)
    1.46 +  unfolding reflp_def symp_def transp_def
    1.47 +  apply(simp_all add: split_option_all)
    1.48 +  apply(blast intro: equivp_reflp[OF a])
    1.49 +  apply(blast intro: equivp_symp[OF a])
    1.50 +  apply(blast intro: equivp_transp[OF a])
    1.51 +  done
    1.52 +
    1.53 +lemma option_None_rsp[quot_respect]:
    1.54 +  assumes q: "Quotient R Abs Rep"
    1.55 +  shows "option_rel R None None"
    1.56 +  by simp
    1.57 +
    1.58 +lemma option_Some_rsp[quot_respect]:
    1.59 +  assumes q: "Quotient R Abs Rep"
    1.60 +  shows "(R ===> option_rel R) Some Some"
    1.61 +  by simp
    1.62 +
    1.63 +lemma option_None_prs[quot_preserve]:
    1.64 +  assumes q: "Quotient R Abs Rep"
    1.65 +  shows "Option.map Abs None = None"
    1.66 +  by simp
    1.67 +
    1.68 +lemma option_Some_prs[quot_preserve]:
    1.69 +  assumes q: "Quotient R Abs Rep"
    1.70 +  shows "(Rep ---> Option.map Abs) Some = Some"
    1.71 +  apply(simp add: expand_fun_eq)
    1.72 +  apply(simp add: Quotient_abs_rep[OF q])
    1.73 +  done
    1.74 +
    1.75 +lemma option_map_id[id_simps]:
    1.76 +  shows "Option.map id = id"
    1.77 +  by (simp add: expand_fun_eq split_option_all)
    1.78 +
    1.79 +lemma option_rel_eq[id_simps]:
    1.80 +  shows "option_rel (op =) = (op =)"
    1.81 +  by (simp add: expand_fun_eq split_option_all)
    1.82 +
    1.83 +end