Quot/QuotOption.thy
author Cezary Kaliszyk <kaliszyk@in.tum.de>
Tue, 26 Jan 2010 07:42:52 +0100
changeset 927 04ef4bd3b936
parent 925 8d51795ef54d
child 936 da5e4b8317c7
permissions -rw-r--r--
more eq_reflection & other cleaning.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     1
theory QuotOption
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     2
imports QuotMain
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     5
fun
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
  option_rel
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
where
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     8
  "option_rel R None None = True"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     9
| "option_rel R (Some x) None = False"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    10
| "option_rel R None (Some x) = False"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    11
| "option_rel R (Some x) (Some y) = R x y"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    12
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    13
fun
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    14
  option_map
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    15
where
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    16
  "option_map f None = None"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    17
| "option_map f (Some x) = Some (f x)"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    18
779
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 698
diff changeset
    19
declare [[map option = (option_map, option_rel)]]
3b21b24a5fb6 corrected map declarations for Sum and Prod; moved absrep_fun examples in separate file
Christian Urban <urbanc@in.tum.de>
parents: 698
diff changeset
    20
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    21
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    22
lemma option_quotient[quot_thm]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    23
  assumes q: "Quotient R Abs Rep"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    24
  shows "Quotient (option_rel R) (option_map Abs) (option_map Rep)"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    25
  apply(unfold Quotient_def)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    26
  apply(auto)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    27
  apply(case_tac a, simp_all add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    28
  apply(case_tac a, simp_all add: Quotient_abs_rep[OF q] Quotient_rel_rep[OF q])
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    29
  apply(case_tac [!] r)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    30
  apply(case_tac [!] s)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    31
  apply(simp_all 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
    32
  using q
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    33
  unfolding Quotient_def
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    34
  apply(blast)+
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    35
  done
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    36
  
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    37
lemma option_equivp[quot_equiv]:
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    38
  assumes a: "equivp R"
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    39
  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
    40
  apply(rule equivpI)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    41
  unfolding reflp_def symp_def transp_def
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    42
  apply(auto)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    43
  apply(case_tac [!] x)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    44
  apply(simp_all add: equivp_reflp[OF a])
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    45
  apply(case_tac [!] y)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    46
  apply(simp_all add: equivp_symp[OF a])
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    47
  apply(case_tac [!] z)
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    48
  apply(simp_all)
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    49
  apply(clarify)
698
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    50
  apply(rule equivp_transp[OF a])
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    51
  apply(assumption)+
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    52
  done
ed44eaaea63e Option and Sum quotients.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
    53
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    54
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
    55
  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
    56
  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
    57
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    58
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    59
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
    60
  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
    61
  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
    62
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    63
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    64
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
    65
  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
    66
  shows "option_map Abs None = None"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    67
  by simp
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    68
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    69
lemma option_Some_prs[quot_respect]:
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    70
  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
    71
  shows "(Rep ---> option_map Abs) Some = Some"
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    72
  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
    73
  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
    74
  done
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    75
927
04ef4bd3b936 more eq_reflection & other cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 925
diff changeset
    76
lemma option_map_id[id_simps]:
04ef4bd3b936 more eq_reflection & other cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 925
diff changeset
    77
  shows "option_map id = id"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    78
  apply (auto simp add: expand_fun_eq)
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
  apply (case_tac x)
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
  apply (auto)
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
    81
  done
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
    82
927
04ef4bd3b936 more eq_reflection & other cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 925
diff changeset
    83
lemma option_rel_eq[id_simps]:
04ef4bd3b936 more eq_reflection & other cleaning.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 925
diff changeset
    84
  shows "option_rel (op =) = (op =)"
923
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    85
  apply(auto 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
    86
  apply(case_tac x)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    87
  apply(case_tac [!] xa)
0419b20ee83c added prs and rsp lemmas for Some and None
Christian Urban <urbanc@in.tum.de>
parents: 829
diff changeset
    88
  apply(auto)
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
    89
  done
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
    90
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
    91
end