Quot/QuotOption.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Wed, 10 Feb 2010 17:02:29 +0100
changeset 1122 d1eaed018e5d
parent 937 60dd70913b44
permissions -rw-r--r--
Changes from Makarius's code review + some noticed fixes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
     1
(*  Title:      QuotOption.thy
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
     2
    Author:     Cezary Kaliszyk and Christian Urban
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
     3
*)
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
theory QuotOption
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
imports QuotMain
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
begin
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
937
Christian Urban <urbanc@in.tum.de>
parents: 936
diff changeset
     8
section {* Quotient infrastructure for the option type. *}
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
     9
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
fun
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
  option_rel
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
where
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
  "option_rel R None None = True"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
| "option_rel R (Some x) None = False"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
| "option_rel R None (Some x) = False"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
| "option_rel R (Some x) (Some y) = R x y"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
    18
declare [[map option = (Option.map, option_rel)]]
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    19
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    20
text {* should probably be in Option.thy *}
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    21
lemma split_option_all: 
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    22
  shows "(\<forall>x. P x) \<longleftrightarrow> P None \<and> (\<forall>a. P (Some a))"
937
Christian Urban <urbanc@in.tum.de>
parents: 936
diff changeset
    23
  apply(auto)
Christian Urban <urbanc@in.tum.de>
parents: 936
diff changeset
    24
  apply(case_tac x)
Christian Urban <urbanc@in.tum.de>
parents: 936
diff changeset
    25
  apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents: 936
diff changeset
    26
  done
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    27
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    28
lemma option_quotient[quot_thm]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    29
  assumes q: "Quotient R Abs Rep"
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
    30
  shows "Quotient (option_rel R) (Option.map Abs) (Option.map Rep)"
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
    31
  unfolding Quotient_def
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    32
  apply(simp add: split_option_all)
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    33
  apply(simp add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    34
  using q
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    35
  unfolding Quotient_def
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    36
  apply(blast)
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    37
  done
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    38
  
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
lemma option_equivp[quot_equiv]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    40
  assumes a: "equivp R"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    41
  shows "equivp (option_rel R)"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    42
  apply(rule equivpI)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    43
  unfolding reflp_def symp_def transp_def
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    44
  apply(simp_all add: split_option_all)
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    45
  apply(blast intro: equivp_reflp[OF a])
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    46
  apply(blast intro: equivp_symp[OF a])
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    47
  apply(blast intro: equivp_transp[OF a])
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
  done
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    49
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    50
lemma option_None_rsp[quot_respect]:
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    51
  assumes q: "Quotient R Abs Rep"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    52
  shows "option_rel R None None"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    53
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    54
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    55
lemma option_Some_rsp[quot_respect]:
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    56
  assumes q: "Quotient R Abs Rep"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    57
  shows "(R ===> option_rel R) Some Some"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    58
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    59
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    60
lemma option_None_prs[quot_preserve]:
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    61
  assumes q: "Quotient R Abs Rep"
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
    62
  shows "Option.map Abs None = None"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    63
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    64
1122
d1eaed018e5d Changes from Makarius's code review + some noticed fixes.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 937
diff changeset
    65
lemma option_Some_prs[quot_preserve]:
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    66
  assumes q: "Quotient R Abs Rep"
932
7781c7cbd27e used the internal Option.map instead of custom option_map
Christian Urban <urbanc@in.tum.de>
parents: 925
diff changeset
    67
  shows "(Rep ---> Option.map Abs) Some = Some"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    68
  apply(simp add: expand_fun_eq)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    69
  apply(simp add: Quotient_abs_rep[OF q])
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    70
  done
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    71
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    72
lemma option_map_id[id_simps]: 
936
Christian Urban <urbanc@in.tum.de>
parents: 933 927
diff changeset
    73
  shows "Option.map id = id"
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    74
  by (simp add: expand_fun_eq split_option_all)
829
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    75
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    76
lemma option_rel_eq[id_simps]: 
927
04ef4bd3b936 more eq_reflection & other cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 925
diff changeset
    77
  shows "option_rel (op =) = (op =)"
933
762f0eae88fd used split_option_all lemma
Christian Urban <urbanc@in.tum.de>
parents: 932
diff changeset
    78
  by (simp add: expand_fun_eq split_option_all)
829
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    79
42b90994ac77 map and rel simps for all quotients; needed when changing the relations to aggregate ones.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 779
diff changeset
    80
end