src/HOL/Option.ML
author oheimb
Wed Sep 09 17:23:42 1998 +0200 (1998-09-09)
changeset 5445 3905974ad555
parent 5293 4ce5539aa969
child 5520 e2484f1786b7
permissions -rw-r--r--
AddIffs[not_None_eq];
made wrapper ospec really safe
nipkow@2019
     1
(*  Title:      Option.ML
nipkow@2019
     2
    ID:         $Id$
nipkow@2019
     3
    Author:     Tobias Nipkow
nipkow@2019
     4
    Copyright   1996  TU Muenchen
nipkow@2019
     5
nipkow@2019
     6
Derived rules
nipkow@2019
     7
*)
oheimb@4133
     8
open Option;
oheimb@4133
     9
oheimb@4133
    10
qed_goal "not_None_eq" thy "(x ~= None) = (? y. x = Some y)"
berghofe@5183
    11
	(K [induct_tac "x" 1, Auto_tac]);
oheimb@5445
    12
AddIffs[not_None_eq];
oheimb@5445
    13
oheimb@4133
    14
oheimb@4133
    15
section "case analysis in premises";
oheimb@4133
    16
oheimb@4133
    17
val optionE = prove_goal thy 
oheimb@4133
    18
	"[| opt = None ==> P;  !!x. opt = Some x ==> P |] ==> P" (fn prems => [
oheimb@4133
    19
	case_tac "opt = None" 1,
oheimb@4133
    20
	 eresolve_tac prems 1,
oheimb@4133
    21
	dtac (not_None_eq RS iffD1) 1,
oheimb@4133
    22
	etac exE 1,
oheimb@4133
    23
	eresolve_tac prems 1]);
oheimb@5293
    24
fun optionE_tac s = res_inst_tac [("opt",s)] optionE THEN_ALL_NEW hyp_subst_tac;
oheimb@4133
    25
oheimb@4133
    26
qed_goal "option_caseE" thy "[|case x of None => P | Some y => Q y; \
oheimb@4133
    27
\                  [|x = None;   P  |] ==> R; \
oheimb@4133
    28
\             !!y. [|x = Some y; Q y|] ==> R|] ==> R" (fn prems => [
oheimb@4133
    29
	cut_facts_tac prems 1,
oheimb@4133
    30
	res_inst_tac [("opt","x")] optionE 1,
oheimb@4133
    31
	 forward_tac prems 1,
oheimb@4133
    32
	  forward_tac prems 3, 
paulson@4477
    33
	   Auto_tac]);
oheimb@4133
    34
fun option_case_tac i = EVERY [
oheimb@4133
    35
	etac option_caseE i,
oheimb@4133
    36
	 hyp_subst_tac (i+1),
oheimb@4133
    37
	hyp_subst_tac i];
oheimb@4133
    38
oheimb@4133
    39
oheimb@4133
    40
section "the";
oheimb@4133
    41
oheimb@4133
    42
qed_goalw "the_Some" thy [the_def]
oheimb@4133
    43
	"the (Some x) = x" (K [Simp_tac 1]);
oheimb@4133
    44
Addsimps [the_Some];
oheimb@4133
    45
oheimb@4133
    46
oheimb@5445
    47
oheimb@4133
    48
section "option_map";
oheimb@4133
    49
oheimb@4133
    50
qed_goalw "option_map_None" thy [option_map_def] 
oheimb@4133
    51
	"option_map f None = None" (K [Simp_tac 1]);
oheimb@4133
    52
qed_goalw "option_map_Some" thy [option_map_def] 
oheimb@4133
    53
	"option_map f (Some x) = Some (f x)" (K [Simp_tac 1]);
oheimb@4133
    54
Addsimps [option_map_None, option_map_Some];
oheimb@4133
    55
oheimb@4800
    56
val option_map_eq_Some = prove_goalw thy [option_map_def]
oheimb@4800
    57
	"(option_map f xo = Some y) = (? z. xo = Some z & f z = y)" 
berghofe@5183
    58
 (K [asm_full_simp_tac (simpset() addsplits [option.split]) 1]);
oheimb@4836
    59
AddIffs[option_map_eq_Some];
oheimb@4752
    60
oheimb@5445
    61
oheimb@4752
    62
section "o2s";
oheimb@4752
    63
oheimb@5293
    64
qed_goal "ospec" thy 
oheimb@5293
    65
	"!!x. [| !x:o2s A. P x; A = Some x |] ==> P x" (K [Auto_tac]);
oheimb@5445
    66
claset_ref() := claset() addSaltern ("ospec", 
oheimb@5445
    67
				dmatch_tac [ospec] THEN' eq_assume_tac);
oheimb@5445
    68
oheimb@5293
    69
oheimb@4752
    70
val elem_o2s = prove_goal thy "!!X. x : o2s xo = (xo = Some x)"
oheimb@4800
    71
 (K [optionE_tac "xo" 1, Auto_tac]);
oheimb@5293
    72
AddIffs [elem_o2s];
oheimb@4752
    73
oheimb@4752
    74
val o2s_empty_eq = prove_goal thy "(o2s xo = {}) = (xo = None)"
oheimb@4800
    75
 (K [optionE_tac "xo" 1, Auto_tac]);
oheimb@4752
    76
Addsimps [o2s_empty_eq];
oheimb@5293
    77