src/HOL/Map.ML
author oheimb
Wed Jan 31 10:15:55 2001 +0100 (2001-01-31)
changeset 11008 f7333f055ef6
parent 10973 5b0d04078d2a
child 11015 55d95834c815
permissions -rw-r--r--
improved theory reference in comment
nipkow@3981
     1
(*  Title:      HOL/Map.ML
nipkow@3981
     2
    ID:         $Id$
nipkow@3981
     3
    Author:     Tobias Nipkow
nipkow@3981
     4
    Copyright   1997 TU Muenchen
nipkow@3981
     5
wenzelm@10973
     6
Map lemmas.
nipkow@3981
     7
*)
nipkow@3981
     8
oheimb@5300
     9
section "empty";
oheimb@5300
    10
wenzelm@5069
    11
Goalw [empty_def] "empty k = None";
wenzelm@4423
    12
by (Simp_tac 1);
nipkow@3981
    13
qed "empty_def2";
nipkow@3981
    14
Addsimps [empty_def2];
nipkow@3981
    15
wenzelm@10973
    16
Goal "empty(x := None) = empty";
wenzelm@10973
    17
by (rtac ext 1);
wenzelm@10973
    18
by (Simp_tac 1);
wenzelm@10973
    19
qed "empty_upd_none";
wenzelm@10973
    20
Addsimps [empty_upd_none];
wenzelm@10973
    21
oheimb@9342
    22
Goal "sum_case empty empty = empty";
oheimb@9342
    23
by (rtac ext 1);
oheimb@9342
    24
by (simp_tac (simpset() addsplits [sum.split]) 1);
oheimb@9342
    25
qed "sum_case_empty_empty";
oheimb@9342
    26
Addsimps [sum_case_empty_empty];
oheimb@9342
    27
oheimb@5300
    28
oheimb@5300
    29
section "map_upd";
oheimb@5300
    30
paulson@8529
    31
Goal "t k = Some x ==> t(k|->x) = t";
paulson@8529
    32
by (rtac ext 1);
paulson@8529
    33
by (Asm_simp_tac 1);
paulson@8529
    34
qed "map_upd_triv";
oheimb@5300
    35
oheimb@9400
    36
Goal "t(k|->x) ~= empty";
oheimb@9400
    37
by Safe_tac;
oheimb@9400
    38
by (dres_inst_tac [("x","k")] fun_cong 1);
oheimb@9400
    39
by (Full_simp_tac 1);
oheimb@9400
    40
qed "map_upd_nonempty";
oheimb@9400
    41
Addsimps[map_upd_nonempty];
oheimb@9400
    42
oheimb@8160
    43
Goalw [image_def] "finite (range f) ==> finite (range (f(a|->b)))";
oheimb@8160
    44
by (full_simp_tac (simpset() addsimps [full_SetCompr_eq]) 1);
paulson@8254
    45
by (rtac finite_subset 1);
paulson@8254
    46
by (assume_tac 2);
oheimb@8160
    47
by Auto_tac;
oheimb@8160
    48
qed "finite_range_updI";
oheimb@8160
    49
oheimb@5300
    50
oheimb@5300
    51
section "map_upds";
nipkow@3981
    52
oheimb@5300
    53
Goal "a ~: set as --> (!m bs. (m(a|->b)(as[|->]bs)) = (m(as[|->]bs)(a|->b)))";
oheimb@5300
    54
by (induct_tac "as" 1);
oheimb@5300
    55
by  (auto_tac (claset(), simpset() delsimps[fun_upd_apply]));
oheimb@5300
    56
by (REPEAT(dtac spec 1));
oheimb@5300
    57
by (rotate_tac ~1 1);
oheimb@5300
    58
by (etac subst 1);
oheimb@5300
    59
by (etac (fun_upd_twist RS subst) 1);
oheimb@5300
    60
by (rtac refl 1);
oheimb@5300
    61
qed_spec_mp "map_upds_twist";
oheimb@5300
    62
Addsimps [map_upds_twist];
oheimb@5300
    63
oheimb@5300
    64
oheimb@5300
    65
section "chg_map";
oheimb@5300
    66
paulson@8529
    67
Goalw [chg_map_def] "m a = None   ==> chg_map f a m = m";
paulson@8529
    68
by Auto_tac;
paulson@8529
    69
qed "chg_map_new";
paulson@8529
    70
paulson@8529
    71
Goalw [chg_map_def] "m a = Some b ==> chg_map f a m = m(a|->f b)";
paulson@8529
    72
by Auto_tac;
paulson@8529
    73
qed "chg_map_upd";
paulson@8529
    74
oheimb@5300
    75
Addsimps[chg_map_new, chg_map_upd];
oheimb@5300
    76
oheimb@4526
    77
oheimb@7958
    78
section "map_of";
oheimb@7958
    79
oheimb@7958
    80
Goal "map_of xs k = Some y --> (k,y):set xs";
oheimb@7958
    81
by (induct_tac "xs" 1);
oheimb@9018
    82
by  Auto_tac;
oheimb@7958
    83
qed_spec_mp "map_of_SomeD";
oheimb@7958
    84
oheimb@9018
    85
Goal "inj f ==> map_of t k = Some x --> \
oheimb@9018
    86
\  map_of (map (split (%k. Pair (f k))) t) (f k) = Some x";
oheimb@9018
    87
by (induct_tac "t" 1);
oheimb@9018
    88
by  (auto_tac (claset(),simpset()addsimps[inj_eq]));
oheimb@9018
    89
qed_spec_mp "map_of_mapk_SomeI";
oheimb@9018
    90
oheimb@9018
    91
Goal "(k, x) : set l --> (? x. map_of l k = Some x)";
oheimb@9018
    92
by (induct_tac "l" 1);
oheimb@9018
    93
by  Auto_tac;
oheimb@9018
    94
qed_spec_mp "weak_map_of_SomeI";
oheimb@9018
    95
oheimb@7958
    96
Goal "[| map_of xs k = Some z; P z |] ==> map_of [(k,z):xs . P z] k = Some z";
paulson@7961
    97
by (rtac mp 1);
paulson@7961
    98
by (assume_tac 2);
oheimb@7958
    99
by (etac thin_rl 1);
oheimb@7958
   100
by (induct_tac "xs" 1);
oheimb@7958
   101
by  Auto_tac;
oheimb@7958
   102
qed "map_of_filter_in";
oheimb@7958
   103
oheimb@8160
   104
Goal "finite (range (map_of l))";
oheimb@8160
   105
by (induct_tac "l" 1);
oheimb@8160
   106
by  (ALLGOALS (simp_tac (simpset() addsimps [image_constant])));
paulson@8254
   107
by (rtac finite_subset 1);
paulson@8254
   108
by (assume_tac 2);
oheimb@8160
   109
by Auto_tac;
oheimb@8160
   110
qed "finite_range_map_of";
oheimb@7958
   111
oheimb@9018
   112
oheimb@7958
   113
section "option_map related";
oheimb@4990
   114
paulson@8529
   115
Goal "option_map f o empty = empty";
paulson@8529
   116
by (rtac ext 1);
paulson@8529
   117
by (Simp_tac 1);
paulson@8529
   118
qed "option_map_o_empty";
oheimb@4990
   119
paulson@8529
   120
Goal "option_map f o m(a|->b) = (option_map f o m)(a|->f b)";
paulson@8529
   121
by (rtac ext 1);
paulson@8529
   122
by (Simp_tac 1);
paulson@8529
   123
qed "option_map_o_map_upd";
paulson@8529
   124
nipkow@5195
   125
Addsimps[option_map_o_empty, option_map_o_map_upd];
oheimb@4883
   126
nipkow@3981
   127
section "++";
nipkow@3981
   128
wenzelm@5069
   129
Goalw [override_def] "m ++ empty = m";
wenzelm@4423
   130
by (Simp_tac 1);
nipkow@3981
   131
qed "override_empty";
nipkow@3981
   132
Addsimps [override_empty];
nipkow@3981
   133
wenzelm@5069
   134
Goalw [override_def] "empty ++ m = m";
wenzelm@4423
   135
by (Simp_tac 1);
wenzelm@4423
   136
by (rtac ext 1);
berghofe@5183
   137
by (split_tac [option.split] 1);
wenzelm@4423
   138
by (Simp_tac 1);
nipkow@3981
   139
qed "empty_override";
nipkow@3981
   140
Addsimps [empty_override];
nipkow@3981
   141
wenzelm@5069
   142
Goalw [override_def]
nipkow@3981
   143
 "((m ++ n) k = Some x) = (n k = Some x | n k = None & m k = Some x)";
berghofe@5183
   144
by (simp_tac (simpset() addsplits [option.split]) 1);
nipkow@3981
   145
qed_spec_mp "override_Some_iff";
nipkow@3981
   146
oheimb@4926
   147
bind_thm ("override_SomeD", standard(override_Some_iff RS iffD1));
oheimb@5444
   148
AddSDs[override_SomeD];
nipkow@3981
   149
oheimb@7958
   150
Goal "!!xx. n k = Some xx ==> (m ++ n) k = Some xx";
oheimb@7958
   151
by (stac override_Some_iff 1);
oheimb@7958
   152
by (Fast_tac 1);
oheimb@7958
   153
qed "override_find_right";
oheimb@7958
   154
Addsimps[override_find_right];
oheimb@7958
   155
oheimb@5444
   156
Goalw [override_def] "((m ++ n) k = None) = (n k = None & m k = None)";
berghofe@5183
   157
by (simp_tac (simpset() addsplits [option.split]) 1);
nipkow@3981
   158
qed "override_None";
nipkow@3981
   159
AddIffs [override_None];
nipkow@3981
   160
oheimb@8160
   161
Goalw [override_def] "f ++ g(x|->y) = (f ++ g)(x|->y)";
paulson@8254
   162
by (rtac ext 1);
wenzelm@9357
   163
by Auto_tac;
oheimb@8160
   164
qed "override_upd";
oheimb@8160
   165
Addsimps[override_upd];
oheimb@8160
   166
oheimb@5444
   167
Goalw [override_def] "map_of ys ++ map_of xs = map_of (xs@ys)";
oheimb@5444
   168
by (rtac sym 1);
wenzelm@4423
   169
by (induct_tac "xs" 1);
wenzelm@4423
   170
by (Simp_tac 1);
wenzelm@4423
   171
by (rtac ext 1);
berghofe@5183
   172
by (asm_simp_tac (simpset() addsplits [option.split]) 1);
oheimb@5444
   173
qed "map_of_override";
oheimb@5444
   174
Addsimps [map_of_override];
nipkow@3981
   175
oheimb@8160
   176
Delsimps[fun_upd_apply];
oheimb@8160
   177
Goal "finite (range f) ==> finite (range (f ++ map_of l))";
oheimb@8160
   178
by (induct_tac "l" 1);
oheimb@8160
   179
by  Auto_tac;
oheimb@8160
   180
by  (fold_goals_tac [empty_def]);
oheimb@8160
   181
by  (Asm_simp_tac 1);
oheimb@8160
   182
by (etac finite_range_updI 1);
oheimb@8160
   183
qed "finite_range_map_of_override";
oheimb@8160
   184
Addsimps [fun_upd_apply];
oheimb@8160
   185
oheimb@5300
   186
nipkow@3981
   187
section "dom";
nipkow@3981
   188
oheimb@8259
   189
Goalw [dom_def] "m a = Some b ==> a : dom m";
oheimb@8259
   190
by Auto_tac;
oheimb@8259
   191
qed "domI";
oheimb@8259
   192
oheimb@8259
   193
Goalw [dom_def] "a : dom m ==> ? b. m a = Some b";
oheimb@8259
   194
by Auto_tac;
oheimb@8259
   195
qed "domD";
oheimb@8259
   196
AddSDs [domD];
oheimb@8259
   197
wenzelm@5069
   198
Goalw [dom_def] "dom empty = {}";
wenzelm@4423
   199
by (Simp_tac 1);
nipkow@3981
   200
qed "dom_empty";
nipkow@3981
   201
Addsimps [dom_empty];
nipkow@3981
   202
oheimb@5300
   203
Goalw [dom_def] "dom(m(a|->b)) = insert a (dom m)";
nipkow@4686
   204
by (Simp_tac 1);
wenzelm@4423
   205
by (Blast_tac 1);
nipkow@5195
   206
qed "dom_map_upd";
nipkow@5195
   207
Addsimps [dom_map_upd];
nipkow@3981
   208
paulson@8529
   209
Goalw [dom_def] "finite (dom (map_of l))";
paulson@8529
   210
by (induct_tac "l" 1);
wenzelm@10973
   211
by (auto_tac (claset(),
wenzelm@10973
   212
              simpset() addsimps [insert_Collect RS sym]));
paulson@8529
   213
qed "finite_dom_map_of";
oheimb@4883
   214
wenzelm@5069
   215
Goalw [dom_def] "dom(m++n) = dom n Un dom m";
paulson@8529
   216
by Auto_tac;
nipkow@3981
   217
qed "dom_override";
nipkow@3981
   218
Addsimps [dom_override];
nipkow@3981
   219
nipkow@3981
   220
section "ran";
nipkow@3981
   221
wenzelm@5069
   222
Goalw [ran_def] "ran empty = {}";
wenzelm@4423
   223
by (Simp_tac 1);
nipkow@3981
   224
qed "ran_empty";
nipkow@3981
   225
Addsimps [ran_empty];
oheimb@4883
   226
oheimb@8160
   227
Goalw [ran_def] "ran (%u. None) = {}";
oheimb@8160
   228
by Auto_tac;
oheimb@8160
   229
qed "ran_empty'";
oheimb@8160
   230
Addsimps[ran_empty'];
oheimb@8160
   231
oheimb@5300
   232
Goalw [ran_def] "m a = None ==> ran(m(a|->b)) = insert b (ran m)";
oheimb@4883
   233
by Auto_tac;
oheimb@4883
   234
by (subgoal_tac "~(aa = a)" 1);
oheimb@4883
   235
by Auto_tac;
nipkow@5195
   236
qed "ran_map_upd";
nipkow@5195
   237
Addsimps [ran_map_upd];