src/HOL/Map.ML
author paulson
Thu, 11 Nov 1999 10:25:17 +0100
changeset 8005 b64d86018785
parent 7961 422ac6888c7f
child 8160 837a6b515005
permissions -rw-r--r--
new-style infix declaration for "image"
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
7958
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    47
section "map_of";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    48
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    49
Goal "map_of xs k = Some y --> (k,y):set xs";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    50
by (induct_tac "xs" 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    51
by  (Simp_tac 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    52
by (split_all_tac 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    53
by (Asm_simp_tac 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    54
qed_spec_mp "map_of_SomeD";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    55
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    56
Goal "[| map_of xs k = Some z; P z |] ==> map_of [(k,z):xs . P z] k = Some z";
7961
422ac6888c7f expandshort
paulson
parents: 7958
diff changeset
    57
by (rtac mp 1);
422ac6888c7f expandshort
paulson
parents: 7958
diff changeset
    58
by (assume_tac 2);
7958
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    59
by (etac thin_rl 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    60
by (induct_tac "xs" 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    61
by  Auto_tac;
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    62
qed "map_of_filter_in";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    63
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    64
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    65
section "option_map related";
4990
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    66
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    67
qed_goal "option_map_o_empty" thy 
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    68
         "option_map f o empty = empty" (K [rtac ext 1, Simp_tac 1]);
25da60d0a20b added option_map_o_empty
oheimb
parents: 4926
diff changeset
    69
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    70
qed_goal "option_map_o_map_upd" thy 
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    71
	 "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
    72
	(K [rtac ext 1, Simp_tac 1]);
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
    73
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
    74
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    75
section "++";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    76
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    77
Goalw [override_def] "m ++ empty = m";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    78
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    79
qed "override_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    80
Addsimps [override_empty];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    81
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    82
Goalw [override_def] "empty ++ m = m";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    83
by (Simp_tac 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    84
by (rtac ext 1);
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
    85
by (split_tac [option.split] 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
    86
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    87
qed "empty_override";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    88
Addsimps [empty_override];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    89
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
    90
Goalw [override_def]
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    91
 "((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
    92
by (simp_tac (simpset() addsplits [option.split]) 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    93
qed_spec_mp "override_Some_iff";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    94
4926
0fd0b3f3bc25 added option_map_o_update
oheimb
parents: 4883
diff changeset
    95
bind_thm ("override_SomeD", standard(override_Some_iff RS iffD1));
5444
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
    96
AddSDs[override_SomeD];
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    97
7958
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    98
Goal "!!xx. n k = Some xx ==> (m ++ n) k = Some xx";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
    99
by (stac override_Some_iff 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
   100
by (Fast_tac 1);
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
   101
qed "override_find_right";
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
   102
Addsimps[override_find_right];
f531589c9fc1 added various little lemmas
oheimb
parents: 6301
diff changeset
   103
5444
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   104
Goalw [override_def] "((m ++ n) k = None) = (n k = None & m k = None)";
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   105
by (simp_tac (simpset() addsplits [option.split]) 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   106
qed "override_None";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   107
AddIffs [override_None];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   108
5444
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   109
Goalw [override_def] "map_of ys ++ map_of xs = map_of (xs@ys)";
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   110
by (rtac sym 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   111
by (induct_tac "xs" 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   112
by (Simp_tac 1);
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   113
by (rtac ext 1);
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 5143
diff changeset
   114
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
5444
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   115
qed "map_of_override";
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   116
Addsimps [map_of_override];
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   117
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   118
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   119
section "dom";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   120
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   121
Goalw [dom_def] "dom empty = {}";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   122
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   123
qed "dom_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   124
Addsimps [dom_empty];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   125
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   126
Goalw [dom_def] "dom(m(a|->b)) = insert a (dom m)";
4686
74a12e86b20b Removed `addsplits [expand_if]'
nipkow
parents: 4526
diff changeset
   127
by (Simp_tac 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   128
by (Blast_tac 1);
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   129
qed "dom_map_upd";
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   130
Addsimps [dom_map_upd];
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   131
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   132
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
   133
	induct_tac "l" 1,
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   134
	 ALLGOALS Simp_tac,
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   135
	stac (insert_Collect RS sym) 1,
5444
ffc64812a70b AddSDs[override_SomeD];
oheimb
parents: 5300
diff changeset
   136
	Asm_full_simp_tac 1]);
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   137
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   138
Goalw [dom_def] "dom(m++n) = dom n Un dom m";
6301
08245f5a436d expandshort
paulson
parents: 5444
diff changeset
   139
by (Simp_tac 1);
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   140
by (Blast_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   141
qed "dom_override";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   142
Addsimps [dom_override];
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   143
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   144
section "ran";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   145
5069
3ea049f7979d isatool fixgoal;
wenzelm
parents: 4990
diff changeset
   146
Goalw [ran_def] "ran empty = {}";
4423
a129b817b58a expandshort;
wenzelm
parents: 4089
diff changeset
   147
by (Simp_tac 1);
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   148
qed "ran_empty";
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   149
Addsimps [ran_empty];
4883
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   150
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
   151
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
   152
by Auto_tac;
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   153
by (subgoal_tac "~(aa = a)" 1);
c1aec06d1dca added finite_dom_map_of and ran_update
oheimb
parents: 4838
diff changeset
   154
by Auto_tac;
5195
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   155
qed "ran_map_upd";
277831ae7eac Map.update -> map_upd, Unpdate.update -> fun_upd
nipkow
parents: 5183
diff changeset
   156
Addsimps [ran_map_upd];