src/HOL/Map.ML
author oheimb
Wed, 12 Aug 1998 16:04:27 +0200
changeset 5300 2b1ca524ace8
parent 5195 277831ae7eac
child 5444 ffc64812a70b
permissions -rw-r--r--
defined map_upd by translation via fun_upd changed syntax of map_upd to be consistent with that of fun_upd added chg_map, map_upds
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/Map.ML
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     2
    ID:         $Id$
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     3
    Author:     Tobias Nipkow
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     4
    Copyright   1997 TU Muenchen
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     5
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     6
Map lemmas
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     7
*)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     8
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
     9
section "empty";
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    10
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    11
Goalw [empty_def] "empty k = None";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    12
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    13
qed "empty_def2";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    14
Addsimps [empty_def2];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    15
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    16
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    17
section "map_upd";
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    18
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    19
qed_goal "map_upd_triv" thy "!!X. t k = Some x ==> t(k|->x) = t"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    20
	(K [rtac ext 1, Asm_simp_tac 1]);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    21
(*Addsimps [map_upd_triv];*)
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    22
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    23
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    24
section "map_upds";
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    25
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    26
Goal "a ~: set as --> (!m bs. (m(a|->b)(as[|->]bs)) = (m(as[|->]bs)(a|->b)))";
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    27
by (induct_tac "as" 1);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    28
by  (auto_tac (claset(), simpset() delsimps[fun_upd_apply]));
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    29
by (REPEAT(dtac spec 1));
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    30
by (rotate_tac ~1 1);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    31
by (etac subst 1);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    32
by (etac (fun_upd_twist RS subst) 1);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    33
by (rtac refl 1);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    34
qed_spec_mp "map_upds_twist";
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    35
Addsimps [map_upds_twist];
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    36
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    37
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    38
section "chg_map";
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    39
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    40
qed_goalw "chg_map_new" thy [chg_map_def]
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    41
	"!!s. m a = None   ==> chg_map f a m = m"          (K [Auto_tac]);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    42
qed_goalw "chg_map_upd" thy [chg_map_def]
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    43
	"!!s. m a = Some b ==> chg_map f a m = m(a|->f b)" (K [Auto_tac]);
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    44
Addsimps[chg_map_new, chg_map_upd];
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    45
4526
6be35399125a added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents: 4423
diff changeset
    46
4990
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    47
section "option_map";
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    48
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    49
qed_goal "option_map_o_empty" thy 
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    50
         "option_map f o empty = empty" (K [rtac ext 1, Simp_tac 1]);
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    51
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    52
qed_goal "option_map_o_map_upd" thy 
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    53
	 "option_map f o m(a|->b) = (option_map f o m)(a|->f b)" 
4990
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    54
	(K [rtac ext 1, Simp_tac 1]);
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    55
Addsimps[option_map_o_empty, option_map_o_map_upd];
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
    56
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    57
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    58
section "++";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    59
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    60
Goalw [override_def] "m ++ empty = m";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    61
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    62
qed "override_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    63
Addsimps [override_empty];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    64
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    65
Goalw [override_def] "empty ++ m = m";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    66
by (Simp_tac 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    67
by (rtac ext 1);
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    68
by (split_tac [option.split] 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    69
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    70
qed "empty_override";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    71
Addsimps [empty_override];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    72
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    73
Goalw [override_def]
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    74
 "((m ++ n) k = Some x) = (n k = Some x | n k = None & m k = Some x)";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    75
by (simp_tac (simpset() addsplits [option.split]) 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    76
qed_spec_mp "override_Some_iff";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    77
4926
0fd0b3f3bc25 added option_map_o_update
oheimb
parents: 4883
diff changeset
    78
bind_thm ("override_SomeD", standard(override_Some_iff RS iffD1));
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    79
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    80
Goalw [override_def]
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    81
 "((m ++ n) k = None) = (n k = None & m k = None)";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    82
by (simp_tac (simpset() addsplits [option.split]) 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    83
qed "override_None";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    84
AddIffs [override_None];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    85
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    86
Goalw [override_def] "map_of(xs@ys) = map_of ys ++ map_of xs";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    87
by (induct_tac "xs" 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    88
by (Simp_tac 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    89
by (rtac ext 1);
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    90
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    91
qed "map_of_append";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    92
Addsimps [map_of_append];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    93
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    94
Goal "map_of xs k = Some y --> (k,y):set xs";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    95
by (induct_tac "xs" 1);
4526
6be35399125a added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents: 4423
diff changeset
    96
by  (Simp_tac 1);
4838
196100237656 cleanup for split_all_tac as wrapper in claset()
oheimb
parents: 4686
diff changeset
    97
by (split_all_tac 1);
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4526
diff changeset
    98
by (Asm_simp_tac 1);
4526
6be35399125a added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents: 4423
diff changeset
    99
qed_spec_mp "map_of_SomeD";
6be35399125a added update_same, update_other, update_triv, and map_of_SomeD
oheimb
parents: 4423
diff changeset
   100
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   101
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   102
section "dom";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   103
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   104
Goalw [dom_def] "dom empty = {}";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   105
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   106
qed "dom_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   107
Addsimps [dom_empty];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   108
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   109
Goalw [dom_def] "dom(m(a|->b)) = insert a (dom m)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4526
diff changeset
   110
by (Simp_tac 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   111
by (Blast_tac 1);
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   112
qed "dom_map_upd";
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   113
Addsimps [dom_map_upd];
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   114
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   115
qed_goalw "finite_dom_map_of" Map.thy [dom_def] "finite (dom (map_of l))" (K[
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   116
	induct_tac "l" 1,
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   117
	 ALLGOALS Simp_tac,
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   118
	stac (insert_Collect RS sym) 1,
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   119
	Asm_simp_tac 1]);
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   120
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   121
Goalw [dom_def] "dom(m++n) = dom n Un dom m";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   122
by (Blast_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   123
qed "dom_override";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   124
Addsimps [dom_override];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   125
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   126
section "ran";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   127
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   128
Goalw [ran_def] "ran empty = {}";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   129
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   130
qed "ran_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   131
Addsimps [ran_empty];
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   132
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   133
Goalw [ran_def] "m a = None ==> ran(m(a|->b)) = insert b (ran m)";
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   134
by Auto_tac;
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   135
by (subgoal_tac "~(aa = a)" 1);
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   136
by Auto_tac;
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   137
qed "ran_map_upd";
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   138
Addsimps [ran_map_upd];