src/HOL/Datatype.thy
author wenzelm
Thu, 21 Feb 2002 20:08:09 +0100
changeset 12918 bca45be2d25b
parent 12029 7df1d840d01d
child 13635 c41e88151b54
permissions -rw-r--r--
theory Option has been assimilated by Datatype;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     1
(*  Title:      HOL/Datatype.thy
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     2
    ID:         $Id$
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
     3
    Author:     Stefan Berghofer and Markus Wenzel, TU Muenchen
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
     4
    License:    GPL (GNU GENERAL PUBLIC LICENSE)
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     5
*)
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
     6
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
     7
header {* Datatypes *}
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
     8
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
     9
theory Datatype = Datatype_Universe:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    10
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    11
subsection {* Finishing the datatype package setup *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    12
12029
wenzelm
parents: 11954
diff changeset
    13
text {* Belongs to theory @{text Datatype_Universe}; hides popular names. *}
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    14
hide const Node Atom Leaf Numb Lim Funs Split Case
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    15
hide type node item
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    16
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    17
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    18
subsection {* Representing primitive types *}
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
    19
5759
bf5d9e5b8cdf unit and bool are now represented as datatypes.
berghofe
parents: 5714
diff changeset
    20
rep_datatype bool
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    21
  distinct True_not_False False_not_True
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    22
  induction bool_induct
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    23
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    24
declare case_split [cases type: bool]
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    25
  -- "prefer plain propositional version"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    26
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    27
rep_datatype unit
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    28
  induction unit_induct
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
    29
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
    30
rep_datatype prod
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    31
  inject Pair_eq
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    32
  induction prod_induct
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    33
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    34
rep_datatype sum
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    35
  distinct Inl_not_Inr Inr_not_Inl
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    36
  inject Inl_eq Inr_eq
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    37
  induction sum_induct
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    38
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    39
ML {*
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    40
  val [sum_case_Inl, sum_case_Inr] = thms "sum.cases";
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    41
  bind_thm ("sum_case_Inl", sum_case_Inl);
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    42
  bind_thm ("sum_case_Inr", sum_case_Inr);
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    43
*} -- {* compatibility *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    44
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    45
lemma surjective_sum: "sum_case (%x::'a. f (Inl x)) (%y::'b. f (Inr y)) s = f(s)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    46
  apply (rule_tac s = s in sumE)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    47
   apply (erule ssubst)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    48
   apply (rule sum_case_Inl)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    49
  apply (erule ssubst)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    50
  apply (rule sum_case_Inr)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    51
  done
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    52
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    53
lemma sum_case_weak_cong: "s = t ==> sum_case f g s = sum_case f g t"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    54
  -- {* Prevents simplification of @{text f} and @{text g}: much faster. *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    55
  by (erule arg_cong)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    56
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    57
lemma sum_case_inject:
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    58
  "sum_case f1 f2 = sum_case g1 g2 ==> (f1 = g1 ==> f2 = g2 ==> P) ==> P"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    59
proof -
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    60
  assume a: "sum_case f1 f2 = sum_case g1 g2"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    61
  assume r: "f1 = g1 ==> f2 = g2 ==> P"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    62
  show P
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    63
    apply (rule r)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    64
     apply (rule ext)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    65
     apply (cut_tac x = "Inl x" in a [THEN fun_cong])
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    66
     apply simp
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    67
    apply (rule ext)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    68
    apply (cut_tac x = "Inr x" in a [THEN fun_cong])
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    69
    apply simp
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    70
    done
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    71
qed
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    72
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    73
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
    74
subsection {* Further cases/induct rules for tuples *}
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    75
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    76
lemma prod_cases3 [case_names fields, cases type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    77
    "(!!a b c. y = (a, b, c) ==> P) ==> P"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    78
  apply (cases y)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    79
  apply (case_tac b)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    80
  apply blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    81
  done
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    82
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    83
lemma prod_induct3 [case_names fields, induct type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    84
    "(!!a b c. P (a, b, c)) ==> P x"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    85
  by (cases x) blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    86
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    87
lemma prod_cases4 [case_names fields, cases type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    88
    "(!!a b c d. y = (a, b, c, d) ==> P) ==> P"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    89
  apply (cases y)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    90
  apply (case_tac c)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    91
  apply blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    92
  done
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    93
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    94
lemma prod_induct4 [case_names fields, induct type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    95
    "(!!a b c d. P (a, b, c, d)) ==> P x"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    96
  by (cases x) blast
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
    97
11954
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    98
lemma prod_cases5 [case_names fields, cases type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
    99
    "(!!a b c d e. y = (a, b, c, d, e) ==> P) ==> P"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   100
  apply (cases y)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   101
  apply (case_tac d)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   102
  apply blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   103
  done
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   104
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   105
lemma prod_induct5 [case_names fields, induct type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   106
    "(!!a b c d e. P (a, b, c, d, e)) ==> P x"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   107
  by (cases x) blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   108
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   109
lemma prod_cases6 [case_names fields, cases type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   110
    "(!!a b c d e f. y = (a, b, c, d, e, f) ==> P) ==> P"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   111
  apply (cases y)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   112
  apply (case_tac e)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   113
  apply blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   114
  done
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   115
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   116
lemma prod_induct6 [case_names fields, induct type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   117
    "(!!a b c d e f. P (a, b, c, d, e, f)) ==> P x"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   118
  by (cases x) blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   119
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   120
lemma prod_cases7 [case_names fields, cases type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   121
    "(!!a b c d e f g. y = (a, b, c, d, e, f, g) ==> P) ==> P"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   122
  apply (cases y)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   123
  apply (case_tac f)
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   124
  apply blast
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   125
  done
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   126
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   127
lemma prod_induct7 [case_names fields, induct type]:
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   128
    "(!!a b c d e f g. P (a, b, c, d, e, f, g)) ==> P x"
3d1780208bf3 made new-style theory;
wenzelm
parents: 10212
diff changeset
   129
  by (cases x) blast
5759
bf5d9e5b8cdf unit and bool are now represented as datatypes.
berghofe
parents: 5714
diff changeset
   130
12918
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   131
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   132
subsection {* The option type *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   133
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   134
datatype 'a option = None | Some 'a
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   135
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   136
lemma not_None_eq [iff]: "(x ~= None) = (EX y. x = Some y)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   137
  by (induct x) auto
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   138
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   139
lemma not_Some_eq [iff]: "(ALL y. x ~= Some y) = (x = None)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   140
  by (induct x) auto
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   141
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   142
lemma option_caseE:
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   143
  "(case x of None => P | Some y => Q y) ==>
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   144
    (x = None ==> P ==> R) ==>
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   145
    (!!y. x = Some y ==> Q y ==> R) ==> R"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   146
  by (cases x) simp_all
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   147
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   148
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   149
subsubsection {* Operations *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   150
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   151
consts
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   152
  the :: "'a option => 'a"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   153
primrec
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   154
  "the (Some x) = x"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   155
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   156
consts
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   157
  o2s :: "'a option => 'a set"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   158
primrec
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   159
  "o2s None = {}"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   160
  "o2s (Some x) = {x}"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   161
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   162
lemma ospec [dest]: "(ALL x:o2s A. P x) ==> A = Some x ==> P x"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   163
  by simp
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   164
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   165
ML_setup {* claset_ref() := claset() addSD2 ("ospec", thm "ospec") *}
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   166
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   167
lemma elem_o2s [iff]: "(x : o2s xo) = (xo = Some x)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   168
  by (cases xo) auto
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   169
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   170
lemma o2s_empty_eq [simp]: "(o2s xo = {}) = (xo = None)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   171
  by (cases xo) auto
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   172
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   173
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   174
constdefs
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   175
  option_map :: "('a => 'b) => ('a option => 'b option)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   176
  "option_map == %f y. case y of None => None | Some x => Some (f x)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   177
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   178
lemma option_map_None [simp]: "option_map f None = None"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   179
  by (simp add: option_map_def)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   180
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   181
lemma option_map_Some [simp]: "option_map f (Some x) = Some (f x)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   182
  by (simp add: option_map_def)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   183
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   184
lemma option_map_eq_Some [iff]:
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   185
    "(option_map f xo = Some y) = (EX z. xo = Some z & f z = y)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   186
  by (simp add: option_map_def split add: option.split)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   187
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   188
lemma option_map_o_sum_case [simp]:
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   189
    "option_map f o sum_case g h = sum_case (option_map f o g) (option_map f o h)"
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   190
  apply (rule ext)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   191
  apply (simp split add: sum.split)
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   192
  done
bca45be2d25b theory Option has been assimilated by Datatype;
wenzelm
parents: 12029
diff changeset
   193
5181
4ba3787d9709 New theory Datatype. Needed as an ancestor when defining datatypes.
berghofe
parents:
diff changeset
   194
end