src/HOL/Option.ML
author wenzelm
Tue, 24 Nov 1998 12:03:09 +0100
changeset 5953 d6017ce6b93e
parent 5520 e2484f1786b7
child 7030 53934985426a
permissions -rw-r--r--
setup Blast.setup; setup Clasimp.setup;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2019
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     1
(*  Title:      Option.ML
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     2
    ID:         $Id$
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     4
    Copyright   1996  TU Muenchen
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     5
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     6
Derived rules
b45d9f2042e0 Moved Option out of IOA into core HOL
nipkow
parents:
diff changeset
     7
*)
4133
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
     8
open Option;
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
     9
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    10
qed_goal "not_None_eq" thy "(x ~= None) = (? y. x = Some y)"
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 4836
diff changeset
    11
	(K [induct_tac "x" 1, Auto_tac]);
5445
3905974ad555 AddIffs[not_None_eq];
oheimb
parents: 5293
diff changeset
    12
AddIffs[not_None_eq];
3905974ad555 AddIffs[not_None_eq];
oheimb
parents: 5293
diff changeset
    13
5520
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    14
qed_goal "not_Some_eq" thy "(!y. x ~= Some y) = (x = None)"
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    15
	(K [induct_tac "x" 1, Auto_tac]);
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    16
AddIffs[not_Some_eq];
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    17
4133
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    18
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    19
section "case analysis in premises";
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    20
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    21
val optionE = prove_goal thy 
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    22
	"[| opt = None ==> P;  !!x. opt = Some x ==> P |] ==> P" (fn prems => [
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    23
	case_tac "opt = None" 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    24
	 eresolve_tac prems 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    25
	dtac (not_None_eq RS iffD1) 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    26
	etac exE 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    27
	eresolve_tac prems 1]);
5293
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    28
fun optionE_tac s = res_inst_tac [("opt",s)] optionE THEN_ALL_NEW hyp_subst_tac;
4133
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    29
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    30
qed_goal "option_caseE" thy "[|case x of None => P | Some y => Q y; \
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    31
\                  [|x = None;   P  |] ==> R; \
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    32
\             !!y. [|x = Some y; Q y|] ==> R|] ==> R" (fn prems => [
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    33
	cut_facts_tac prems 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    34
	res_inst_tac [("opt","x")] optionE 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    35
	 forward_tac prems 1,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    36
	  forward_tac prems 3, 
4477
b3e5857d8d99 New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents: 4133
diff changeset
    37
	   Auto_tac]);
4133
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    38
fun option_case_tac i = EVERY [
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    39
	etac option_caseE i,
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    40
	 hyp_subst_tac (i+1),
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    41
	hyp_subst_tac i];
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    42
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    43
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    44
section "the";
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    45
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    46
qed_goalw "the_Some" thy [the_def]
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    47
	"the (Some x) = x" (K [Simp_tac 1]);
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    48
Addsimps [the_Some];
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    49
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    50
5445
3905974ad555 AddIffs[not_None_eq];
oheimb
parents: 5293
diff changeset
    51
4133
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    52
section "option_map";
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    53
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    54
qed_goalw "option_map_None" thy [option_map_def] 
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    55
	"option_map f None = None" (K [Simp_tac 1]);
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    56
qed_goalw "option_map_Some" thy [option_map_def] 
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    57
	"option_map f (Some x) = Some (f x)" (K [Simp_tac 1]);
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    58
Addsimps [option_map_None, option_map_Some];
0a08c2b9b1ed added the, option_map, and case analysis theorems
oheimb
parents: 4071
diff changeset
    59
4800
97c3a45d092b replaced option_map_SomeD by option_map_eq_Some (RS iffD1)
oheimb
parents: 4752
diff changeset
    60
val option_map_eq_Some = prove_goalw thy [option_map_def]
97c3a45d092b replaced option_map_SomeD by option_map_eq_Some (RS iffD1)
oheimb
parents: 4752
diff changeset
    61
	"(option_map f xo = Some y) = (? z. xo = Some z & f z = y)" 
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 4836
diff changeset
    62
 (K [asm_full_simp_tac (simpset() addsplits [option.split]) 1]);
4836
fc5773ae2790 added option_map_eq_Some via AddIffs
oheimb
parents: 4800
diff changeset
    63
AddIffs[option_map_eq_Some];
4752
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    64
5445
3905974ad555 AddIffs[not_None_eq];
oheimb
parents: 5293
diff changeset
    65
4752
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    66
section "o2s";
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    67
5293
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    68
qed_goal "ospec" thy 
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    69
	"!!x. [| !x:o2s A. P x; A = Some x |] ==> P x" (K [Auto_tac]);
5520
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    70
AddDs[ospec];
e2484f1786b7 added addD2, addE2, addSD2, and addSE2
oheimb
parents: 5445
diff changeset
    71
claset_ref() := claset() addSD2 ("ospec", ospec);
5445
3905974ad555 AddIffs[not_None_eq];
oheimb
parents: 5293
diff changeset
    72
5293
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    73
4752
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    74
val elem_o2s = prove_goal thy "!!X. x : o2s xo = (xo = Some x)"
4800
97c3a45d092b replaced option_map_SomeD by option_map_eq_Some (RS iffD1)
oheimb
parents: 4752
diff changeset
    75
 (K [optionE_tac "xo" 1, Auto_tac]);
5293
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    76
AddIffs [elem_o2s];
4752
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    77
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    78
val o2s_empty_eq = prove_goal thy "(o2s xo = {}) = (xo = None)"
4800
97c3a45d092b replaced option_map_SomeD by option_map_eq_Some (RS iffD1)
oheimb
parents: 4752
diff changeset
    79
 (K [optionE_tac "xo" 1, Auto_tac]);
4752
1c334bd00038 added o2s
oheimb
parents: 4477
diff changeset
    80
Addsimps [o2s_empty_eq];
5293
4ce5539aa969 added ospec
oheimb
parents: 5183
diff changeset
    81