author  oheimb 
Wed, 12 Aug 1998 15:00:46 +0200  
changeset 5293  4ce5539aa969 
parent 5183  89f162de39cf 
child 5445  3905974ad555 
permissions  rwrr 
2019  1 
(* Title: Option.ML 
2 
ID: $Id$ 

3 
Author: Tobias Nipkow 

4 
Copyright 1996 TU Muenchen 

5 

6 
Derived rules 

7 
*) 

4133  8 
open Option; 
9 

10 
qed_goal "not_None_eq" thy "(x ~= None) = (? y. x = Some y)" 

5183  11 
(K [induct_tac "x" 1, Auto_tac]); 
4133  12 

13 
section "case analysis in premises"; 

14 

15 
val optionE = prove_goal thy 

16 
"[ opt = None ==> P; !!x. opt = Some x ==> P ] ==> P" (fn prems => [ 

17 
case_tac "opt = None" 1, 

18 
eresolve_tac prems 1, 

19 
dtac (not_None_eq RS iffD1) 1, 

20 
etac exE 1, 

21 
eresolve_tac prems 1]); 

5293  22 
fun optionE_tac s = res_inst_tac [("opt",s)] optionE THEN_ALL_NEW hyp_subst_tac; 
4133  23 

24 
qed_goal "option_caseE" thy "[case x of None => P  Some y => Q y; \ 

25 
\ [x = None; P ] ==> R; \ 

26 
\ !!y. [x = Some y; Q y] ==> R] ==> R" (fn prems => [ 

27 
cut_facts_tac prems 1, 

28 
res_inst_tac [("opt","x")] optionE 1, 

29 
forward_tac prems 1, 

30 
forward_tac prems 3, 

4477
b3e5857d8d99
New Auto_tac (by Oheimb), and new syntax (without parens), and expandshort
paulson
parents:
4133
diff
changeset

31 
Auto_tac]); 
4133  32 
fun option_case_tac i = EVERY [ 
33 
etac option_caseE i, 

34 
hyp_subst_tac (i+1), 

35 
hyp_subst_tac i]; 

36 

37 

38 
section "the"; 

39 

40 
qed_goalw "the_Some" thy [the_def] 

41 
"the (Some x) = x" (K [Simp_tac 1]); 

42 
Addsimps [the_Some]; 

43 

44 

45 
section "option_map"; 

46 

47 
qed_goalw "option_map_None" thy [option_map_def] 

48 
"option_map f None = None" (K [Simp_tac 1]); 

49 
qed_goalw "option_map_Some" thy [option_map_def] 

50 
"option_map f (Some x) = Some (f x)" (K [Simp_tac 1]); 

51 
Addsimps [option_map_None, option_map_Some]; 

52 

4800
97c3a45d092b
replaced option_map_SomeD by option_map_eq_Some (RS iffD1)
oheimb
parents:
4752
diff
changeset

53 
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

54 
"(option_map f xo = Some y) = (? z. xo = Some z & f z = y)" 
5183  55 
(K [asm_full_simp_tac (simpset() addsplits [option.split]) 1]); 
4836  56 
AddIffs[option_map_eq_Some]; 
4752  57 

58 
section "o2s"; 

59 

5293  60 
qed_goal "ospec" thy 
61 
"!!x. [ !x:o2s A. P x; A = Some x ] ==> P x" (K [Auto_tac]); 

62 
claset_ref() := claset() addSaltern ("ospec", dtac ospec THEN' atac); 

63 

4752  64 
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

65 
(K [optionE_tac "xo" 1, Auto_tac]); 
5293  66 
AddIffs [elem_o2s]; 
4752  67 

68 
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

69 
(K [optionE_tac "xo" 1, Auto_tac]); 
4752  70 
Addsimps [o2s_empty_eq]; 
5293  71 