src/HOL/Map.thy
author webertj
Fri, 11 Apr 2003 23:11:13 +0200
changeset 13908 4bdfa9f77254
parent 13890 90611b4e0054
child 13909 a5247a49c85e
permissions -rw-r--r--
Map.ML integrated into Map.thy
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.thy
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, based on a theory by David von Oheimb
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
     4
    Copyright   1997-2003 TU Muenchen
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     5
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     6
The datatype of `maps' (written ~=>); strongly resembles maps in VDM.
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     7
*)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     8
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
     9
theory Map = List:
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    10
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    11
types ('a,'b) "~=>" = "'a => 'b option" (infixr 0)
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    12
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    13
consts
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    14
chg_map	:: "('b => 'b) => 'a => ('a ~=> 'b) => ('a ~=> 'b)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    15
override:: "('a ~=> 'b) => ('a ~=> 'b) => ('a ~=> 'b)" (infixl "++" 100)
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    16
dom	:: "('a ~=> 'b) => 'a set"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    17
ran	:: "('a ~=> 'b) => 'b set"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    18
map_of	:: "('a * 'b)list => 'a ~=> 'b"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    19
map_upds:: "('a ~=> 'b) => 'a list => 'b list => 
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    20
	    ('a ~=> 'b)"			 ("_/'(_[|->]_/')" [900,0,0]900)
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    21
syntax
13890
90611b4e0054 Made empty a translation rather than a constant.
nipkow
parents: 12919
diff changeset
    22
empty	::  "'a ~=> 'b"
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    23
map_upd	:: "('a ~=> 'b) => 'a => 'b => ('a ~=> 'b)"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    24
					         ("_/'(_/|->_')"   [900,0,0]900)
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    25
12114
a8e860c86252 eliminated old "symbols" syntax, use "xsymbols" instead;
wenzelm
parents: 10137
diff changeset
    26
syntax (xsymbols)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    27
  "~=>"     :: "[type, type] => type"    (infixr "\<leadsto>" 0)
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    28
  map_upd   :: "('a ~=> 'b) => 'a      => 'b      => ('a ~=> 'b)"
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    29
					  ("_/'(_/\<mapsto>/_')"  [900,0,0]900)
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    30
  map_upds  :: "('a ~=> 'b) => 'a list => 'b list => ('a ~=> 'b)"
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    31
				         ("_/'(_/[\<mapsto>]/_')" [900,0,0]900)
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    32
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    33
translations
13890
90611b4e0054 Made empty a translation rather than a constant.
nipkow
parents: 12919
diff changeset
    34
  "empty"    => "_K None"
90611b4e0054 Made empty a translation rather than a constant.
nipkow
parents: 12919
diff changeset
    35
  "empty"    <= "%x. None"
5300
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
  "m(a|->b)" == "m(a:=Some b)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    38
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    39
defs
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    40
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    41
chg_map_def:  "chg_map f a m == case m a of None => m | Some b => m(a|->f b)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    42
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    43
override_def: "m1++m2 == %x. case m2 x of None => m1 x | Some y => Some y"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    44
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    45
dom_def: "dom(m) == {a. m a ~= None}"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    46
ran_def: "ran(m) == {b. ? a. m a = Some b}"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    47
5183
89f162de39cf Adapted to new datatype package.
berghofe
parents: 3981
diff changeset
    48
primrec
89f162de39cf Adapted to new datatype package.
berghofe
parents: 3981
diff changeset
    49
  "map_of [] = empty"
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    50
  "map_of (p#ps) = (map_of ps)(fst p |-> snd p)"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    51
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    52
primrec "t([]  [|->]bs) = t"
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    53
        "t(a#as[|->]bs) = t(a|->hd bs)(as[|->]tl bs)"
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    54
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    55
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    56
section "empty"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    57
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    58
lemma empty_upd_none: "empty(x := None) = empty"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    59
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    60
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    61
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    62
declare empty_upd_none [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    63
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    64
(* FIXME: what is this sum_case nonsense?? *)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    65
lemma sum_case_empty_empty: "sum_case empty empty = empty"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    66
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    67
apply (simp (no_asm) split add: sum.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    68
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    69
declare sum_case_empty_empty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    70
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    71
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    72
section "map_upd"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    73
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    74
lemma map_upd_triv: "t k = Some x ==> t(k|->x) = t"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    75
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    76
apply (simp (no_asm_simp))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    77
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    78
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    79
lemma map_upd_nonempty: "t(k|->x) ~= empty"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    80
apply safe
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    81
apply (drule_tac x = "k" in fun_cong)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    82
apply (simp (no_asm_use))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    83
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    84
declare map_upd_nonempty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    85
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    86
lemma finite_range_updI: "finite (range f) ==> finite (range (f(a|->b)))"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    87
apply (unfold image_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    88
apply (simp (no_asm_use) add: full_SetCompr_eq)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    89
apply (rule finite_subset)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    90
prefer 2 apply (assumption)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    91
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    92
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    93
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    94
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    95
(* FIXME: what is this sum_case nonsense?? *)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    96
section "sum_case and empty/map_upd"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    97
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    98
lemma sum_case_map_upd_empty: "sum_case (m(k|->y)) empty =  (sum_case m empty)(Inl k|->y)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    99
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   100
apply (simp (no_asm) split add: sum.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   101
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   102
declare sum_case_map_upd_empty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   103
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   104
lemma sum_case_empty_map_upd: "sum_case empty (m(k|->y)) =  (sum_case empty m)(Inr k|->y)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   105
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   106
apply (simp (no_asm) split add: sum.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   107
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   108
declare sum_case_empty_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   109
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   110
lemma sum_case_map_upd_map_upd: "sum_case (m1(k1|->y1)) (m2(k2|->y2)) = (sum_case (m1(k1|->y1)) m2)(Inr k2|->y2)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   111
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   112
apply (simp (no_asm) split add: sum.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   113
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   114
declare sum_case_map_upd_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   115
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   116
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   117
section "map_upds"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   118
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   119
lemma map_upds_twist [rule_format (no_asm)]: "a ~: set as --> (!m bs. (m(a|->b)(as[|->]bs)) = (m(as[|->]bs)(a|->b)))"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   120
apply (induct_tac "as")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   121
apply  (auto simp del: fun_upd_apply)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   122
apply (drule spec)+
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   123
apply (rotate_tac -1)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   124
apply (erule subst)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   125
apply (erule fun_upd_twist [THEN subst])
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   126
apply (rule refl)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   127
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   128
declare map_upds_twist [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   129
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   130
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   131
section "chg_map"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   132
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   133
lemma chg_map_new: "m a = None   ==> chg_map f a m = m"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   134
apply (unfold chg_map_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   135
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   136
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   137
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   138
lemma chg_map_upd: "m a = Some b ==> chg_map f a m = m(a|->f b)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   139
apply (unfold chg_map_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   140
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   141
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   142
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   143
declare chg_map_new [simp] chg_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   144
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   145
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   146
section "map_of"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   147
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   148
lemma map_of_SomeD [rule_format (no_asm)]: "map_of xs k = Some y --> (k,y):set xs"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   149
apply (induct_tac "xs")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   150
apply  auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   151
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   152
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   153
lemma map_of_mapk_SomeI [rule_format (no_asm)]: "inj f ==> map_of t k = Some x -->  
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   154
   map_of (map (split (%k. Pair (f k))) t) (f k) = Some x"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   155
apply (induct_tac "t")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   156
apply  (auto simp add: inj_eq)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   157
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   158
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   159
lemma weak_map_of_SomeI [rule_format (no_asm)]: "(k, x) : set l --> (? x. map_of l k = Some x)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   160
apply (induct_tac "l")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   161
apply  auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   162
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   163
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   164
lemma map_of_filter_in: 
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   165
"[| map_of xs k = Some z; P k z |] ==> map_of (filter (split P) xs) k = Some z"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   166
apply (rule mp)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   167
prefer 2 apply (assumption)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   168
apply (erule thin_rl)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   169
apply (induct_tac "xs")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   170
apply  auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   171
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   172
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   173
lemma finite_range_map_of: "finite (range (map_of l))"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   174
apply (induct_tac "l")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   175
apply  (simp_all (no_asm) add: image_constant)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   176
apply (rule finite_subset)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   177
prefer 2 apply (assumption)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   178
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   179
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   180
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   181
lemma map_of_map: "map_of (map (%(a,b). (a,f b)) xs) x = option_map f (map_of xs x)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   182
apply (induct_tac "xs")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   183
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   184
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   185
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   186
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   187
section "option_map related"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   188
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   189
lemma option_map_o_empty: "option_map f o empty = empty"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   190
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   191
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   192
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   193
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   194
lemma option_map_o_map_upd: "option_map f o m(a|->b) = (option_map f o m)(a|->f b)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   195
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   196
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   197
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   198
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   199
declare option_map_o_empty [simp] option_map_o_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   200
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   201
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   202
section "++"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   203
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   204
lemma override_empty: "m ++ empty = m"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   205
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   206
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   207
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   208
declare override_empty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   209
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   210
lemma empty_override: "empty ++ m = m"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   211
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   212
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   213
apply (simp split add: option.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   214
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   215
declare empty_override [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   216
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   217
lemma override_Some_iff [rule_format (no_asm)]: 
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   218
 "((m ++ n) k = Some x) = (n k = Some x | n k = None & m k = Some x)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   219
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   220
apply (simp (no_asm) split add: option.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   221
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   222
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   223
lemmas override_SomeD = override_Some_iff [THEN iffD1, standard]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   224
declare override_SomeD [dest!]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   225
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   226
lemma override_find_right: "!!xx. n k = Some xx ==> (m ++ n) k = Some xx"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   227
apply (subst override_Some_iff)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   228
apply fast
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   229
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   230
declare override_find_right [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   231
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   232
lemma override_None: "((m ++ n) k = None) = (n k = None & m k = None)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   233
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   234
apply (simp (no_asm) split add: option.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   235
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   236
declare override_None [iff]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   237
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   238
lemma override_upd: "f ++ g(x|->y) = (f ++ g)(x|->y)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   239
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   240
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   241
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   242
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   243
declare override_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   244
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   245
lemma map_of_override: "map_of ys ++ map_of xs = map_of (xs@ys)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   246
apply (unfold override_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   247
apply (rule sym)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   248
apply (induct_tac "xs")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   249
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   250
apply (rule ext)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   251
apply (simp (no_asm_simp) split add: option.split)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   252
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   253
declare map_of_override [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   254
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   255
declare fun_upd_apply [simp del]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   256
lemma finite_range_map_of_override: "finite (range f) ==> finite (range (f ++ map_of l))"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   257
apply (induct_tac "l")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   258
apply  auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   259
apply (erule finite_range_updI)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   260
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   261
declare fun_upd_apply [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   262
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   263
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   264
section "dom"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   265
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   266
lemma domI: "m a = Some b ==> a : dom m"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   267
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   268
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   269
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   270
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   271
lemma domD: "a : dom m ==> ? b. m a = Some b"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   272
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   273
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   274
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   275
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   276
lemma domIff: "(a : dom m) = (m a ~= None)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   277
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   278
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   279
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   280
declare domIff [iff]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   281
declare domIff [simp del]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   282
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   283
lemma dom_empty: "dom empty = {}"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   284
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   285
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   286
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   287
declare dom_empty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   288
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   289
lemma dom_map_upd: "dom(m(a|->b)) = insert a (dom m)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   290
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   291
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   292
apply blast
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   293
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   294
declare dom_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   295
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   296
lemma finite_dom_map_of: "finite (dom (map_of l))"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   297
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   298
apply (induct_tac "l")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   299
apply (auto simp add: insert_Collect [symmetric])
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   300
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   301
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   302
lemma dom_override: "dom(m++n) = dom n Un dom m"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   303
apply (unfold dom_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   304
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   305
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   306
declare dom_override [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   307
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   308
section "ran"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   309
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   310
lemma ran_empty: "ran empty = {}"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   311
apply (unfold ran_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   312
apply (simp (no_asm))
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   313
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   314
declare ran_empty [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   315
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   316
lemma ran_empty': "ran (%u. None) = {}"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   317
apply (unfold ran_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   318
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   319
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   320
declare ran_empty' [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   321
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   322
lemma ran_map_upd: "m a = None ==> ran(m(a|->b)) = insert b (ran m)"
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   323
apply (unfold ran_def)
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   324
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   325
apply (subgoal_tac "~ (aa = a) ")
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   326
apply auto
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   327
done
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   328
declare ran_map_upd [simp]
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   329
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   330
end