src/HOL/Map.thy
author paulson <lp15@cam.ac.uk>
Sun, 29 Mar 2020 15:44:54 +0100
changeset 71616 a9de39608b1a
parent 69593 3dda49e08b9d
child 73832 9db620f007fa
permissions -rw-r--r--
more tidying up of old apply-proofs
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
    Author:     Tobias Nipkow, based on a theory by David von Oheimb
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
     3
    Copyright   1997-2003 TU Muenchen
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     4
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
     5
The datatype of "maps"; strongly resembles maps in VDM.
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     6
*)
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
     7
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
     8
section \<open>Maps\<close>
13914
nipkow
parents: 13912
diff changeset
     9
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15110
diff changeset
    10
theory Map
67780
7655e6369c9f more abbrevs -- this makes "(=" ambiguous and thus simplifies input of "(=)" (within the context of Main HOL);
wenzelm
parents: 67091
diff changeset
    11
  imports List
7655e6369c9f more abbrevs -- this makes "(=" ambiguous and thus simplifies input of "(=)" (within the context of Main HOL);
wenzelm
parents: 67091
diff changeset
    12
  abbrevs "(=" = "\<subseteq>\<^sub>m"
15131
c69542757a4d New theory header syntax.
nipkow
parents: 15110
diff changeset
    13
begin
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    14
61069
aefe89038dd2 prefer symbols;
wenzelm
parents: 61032
diff changeset
    15
type_synonym ('a, 'b) "map" = "'a \<Rightarrow> 'b option" (infixr "\<rightharpoonup>" 0)
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19378
diff changeset
    16
19378
6cc9ac729eb5 Made "empty" an abbreviation.
nipkow
parents: 19323
diff changeset
    17
abbreviation
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
    18
  empty :: "'a \<rightharpoonup> 'b" where
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    19
  "empty \<equiv> \<lambda>x. None"
19378
6cc9ac729eb5 Made "empty" an abbreviation.
nipkow
parents: 19323
diff changeset
    20
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19378
diff changeset
    21
definition
61069
aefe89038dd2 prefer symbols;
wenzelm
parents: 61032
diff changeset
    22
  map_comp :: "('b \<rightharpoonup> 'c) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'c)"  (infixl "\<circ>\<^sub>m" 55) where
aefe89038dd2 prefer symbols;
wenzelm
parents: 61032
diff changeset
    23
  "f \<circ>\<^sub>m g = (\<lambda>k. case g k of None \<Rightarrow> None | Some v \<Rightarrow> f v)"
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19378
diff changeset
    24
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    25
definition
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    26
  map_add :: "('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b)"  (infixl "++" 100) where
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    27
  "m1 ++ m2 = (\<lambda>x. case m2 x of None \<Rightarrow> m1 x | Some y \<Rightarrow> Some y)"
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    28
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    29
definition
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    30
  restrict_map :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'a set \<Rightarrow> ('a \<rightharpoonup> 'b)"  (infixl "|`"  110) where
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    31
  "m|`A = (\<lambda>x. if x \<in> A then m x else None)"
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
    32
21210
c17fd2df4e9e renamed 'const_syntax' to 'notation';
wenzelm
parents: 20800
diff changeset
    33
notation (latex output)
19656
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19378
diff changeset
    34
  restrict_map  ("_\<restriction>\<^bsub>_\<^esub>" [111,110] 110)
09be06943252 tuned concrete syntax -- abbreviation/const_syntax;
wenzelm
parents: 19378
diff changeset
    35
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    36
definition
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    37
  dom :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'a set" where
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    38
  "dom m = {a. m a \<noteq> None}"
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    39
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    40
definition
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    41
  ran :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'b set" where
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    42
  "ran m = {b. \<exists>a. m a = Some b}"
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    43
21404
eb85850d3eb7 more robust syntax for definition/abbreviation/notation;
wenzelm
parents: 21210
diff changeset
    44
definition
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    45
  map_le :: "('a \<rightharpoonup> 'b) \<Rightarrow> ('a \<rightharpoonup> 'b) \<Rightarrow> bool"  (infix "\<subseteq>\<^sub>m" 50) where
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    46
  "(m\<^sub>1 \<subseteq>\<^sub>m m\<^sub>2) \<longleftrightarrow> (\<forall>a \<in> dom m\<^sub>1. m\<^sub>1 a = m\<^sub>2 a)"
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    47
41229
d797baa3d57c replaced command 'nonterminals' by slightly modernized version 'nonterminal';
wenzelm
parents: 39992
diff changeset
    48
nonterminal maplets and maplet
14180
d2e550609c40 Introduced new syntax for maplets x |-> y
nipkow
parents: 14134
diff changeset
    49
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    50
syntax
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    51
  "_maplet"  :: "['a, 'a] \<Rightarrow> maplet"             ("_ /\<mapsto>/ _")
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    52
  "_maplets" :: "['a, 'a] \<Rightarrow> maplet"             ("_ /[\<mapsto>]/ _")
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    53
  ""         :: "maplet \<Rightarrow> maplets"             ("_")
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    54
  "_Maplets" :: "[maplet, maplets] \<Rightarrow> maplets" ("_,/ _")
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    55
  "_MapUpd"  :: "['a \<rightharpoonup> 'b, maplets] \<Rightarrow> 'a \<rightharpoonup> 'b" ("_/'(_')" [900, 0] 900)
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    56
  "_Map"     :: "maplets \<Rightarrow> 'a \<rightharpoonup> 'b"            ("(1[_])")
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
    57
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    58
syntax (ASCII)
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    59
  "_maplet"  :: "['a, 'a] \<Rightarrow> maplet"             ("_ /|->/ _")
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    60
  "_maplets" :: "['a, 'a] \<Rightarrow> maplet"             ("_ /[|->]/ _")
14180
d2e550609c40 Introduced new syntax for maplets x |-> y
nipkow
parents: 14134
diff changeset
    61
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    62
translations
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    63
  "_MapUpd m (_Maplets xy ms)"  \<rightleftharpoons> "_MapUpd (_MapUpd m xy) ms"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    64
  "_MapUpd m (_maplet  x y)"    \<rightleftharpoons> "m(x := CONST Some y)"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    65
  "_Map ms"                     \<rightleftharpoons> "_MapUpd (CONST empty) ms"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    66
  "_Map (_Maplets ms1 ms2)"     \<leftharpoondown> "_MapUpd (_Map ms1) ms2"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    67
  "_Maplets ms1 (_Maplets ms2 ms3)" \<leftharpoondown> "_Maplets (_Maplets ms1 ms2) ms3"
14180
d2e550609c40 Introduced new syntax for maplets x |-> y
nipkow
parents: 14134
diff changeset
    68
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    69
primrec map_of :: "('a \<times> 'b) list \<Rightarrow> 'a \<rightharpoonup> 'b"
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    70
where
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    71
  "map_of [] = empty"
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    72
| "map_of (p # ps) = (map_of ps)(fst p \<mapsto> snd p)"
5300
2b1ca524ace8 defined map_upd by translation via fun_upd
oheimb
parents: 5195
diff changeset
    73
61955
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    74
definition map_upds :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'a \<rightharpoonup> 'b"
e96292f32c3c former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 61799
diff changeset
    75
  where "map_upds m xs ys = m ++ map_of (rev (zip xs ys))"
34941
156925dd67af dropped some old primrecs and some constdefs
haftmann
parents: 33635
diff changeset
    76
translations
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    77
  "_MapUpd m (_maplets x y)" \<rightleftharpoons> "CONST map_upds m x y"
25965
05df64f786a4 improved code theorem setup
haftmann
parents: 25670
diff changeset
    78
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    79
lemma map_of_Cons_code [code]:
25965
05df64f786a4 improved code theorem setup
haftmann
parents: 25670
diff changeset
    80
  "map_of [] k = None"
05df64f786a4 improved code theorem setup
haftmann
parents: 25670
diff changeset
    81
  "map_of ((l, v) # ps) k = (if l = k then Some v else map_of ps k)"
05df64f786a4 improved code theorem setup
haftmann
parents: 25670
diff changeset
    82
  by simp_all
05df64f786a4 improved code theorem setup
haftmann
parents: 25670
diff changeset
    83
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    84
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
    85
subsection \<open>@{term [source] empty}\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    86
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    87
lemma empty_upd_none [simp]: "empty(x := None) = empty"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    88
  by (rule ext) simp
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    89
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    90
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
    91
subsection \<open>@{term [source] map_upd}\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    92
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    93
lemma map_upd_triv: "t k = Some x \<Longrightarrow> t(k\<mapsto>x) = t"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    94
  by (rule ext) simp
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
    95
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
    96
lemma map_upd_nonempty [simp]: "t(k\<mapsto>x) \<noteq> empty"
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    97
proof
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    98
  assume "t(k \<mapsto> x) = empty"
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
    99
  then have "(t(k \<mapsto> x)) k = None" by simp
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   100
  then show False by simp
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   101
qed
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   102
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   103
lemma map_upd_eqD1:
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   104
  assumes "m(a\<mapsto>x) = n(a\<mapsto>y)"
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   105
  shows "x = y"
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   106
proof -
41550
efa734d9b221 eliminated global prems;
wenzelm
parents: 41229
diff changeset
   107
  from assms have "(m(a\<mapsto>x)) a = (n(a\<mapsto>y)) a" by simp
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   108
  then show ?thesis by simp
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   109
qed
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   110
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   111
lemma map_upd_Some_unfold:
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   112
  "((m(a\<mapsto>b)) x = Some y) = (x = a \<and> b = y \<or> x \<noteq> a \<and> m x = Some y)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   113
  by auto
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   114
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   115
lemma image_map_upd [simp]: "x \<notin> A \<Longrightarrow> m(x \<mapsto> y) ` A = m ` A"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   116
  by auto
15303
eedbb8d22ca2 added lemmas
nipkow
parents: 15251
diff changeset
   117
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   118
lemma finite_range_updI:
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   119
  assumes "finite (range f)" shows "finite (range (f(a\<mapsto>b)))"
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   120
proof -
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   121
  have "range (f(a\<mapsto>b)) \<subseteq> insert (Some b) (range f)"
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   122
    by auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   123
  then show ?thesis
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   124
    by (rule finite_subset) (use assms in auto)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   125
qed
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   126
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   127
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   128
subsection \<open>@{term [source] map_of}\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   129
68454
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   130
lemma map_of_eq_empty_iff [simp]:
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   131
  "map_of xys = empty \<longleftrightarrow> xys = []"
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   132
proof
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   133
  show "map_of xys = empty \<Longrightarrow> xys = []"
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   134
    by (induction xys) simp_all
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   135
qed simp
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   136
68460
b047339bd11c added simp rules
nipkow
parents: 68454
diff changeset
   137
lemma empty_eq_map_of_iff [simp]:
b047339bd11c added simp rules
nipkow
parents: 68454
diff changeset
   138
  "empty = map_of xys \<longleftrightarrow> xys = []"
b047339bd11c added simp rules
nipkow
parents: 68454
diff changeset
   139
by(subst eq_commute) simp
b047339bd11c added simp rules
nipkow
parents: 68454
diff changeset
   140
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   141
lemma map_of_eq_None_iff:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   142
  "(map_of xys x = None) = (x \<notin> fst ` (set xys))"
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   143
by (induct xys) simp_all
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   144
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   145
lemma map_of_eq_Some_iff [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   146
  "distinct(map fst xys) \<Longrightarrow> (map_of xys x = Some y) = ((x,y) \<in> set xys)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   147
proof (induct xys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   148
  case (Cons xy xys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   149
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   150
    by (cases xy) (auto simp flip: map_of_eq_None_iff)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   151
qed auto
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   152
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   153
lemma Some_eq_map_of_iff [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   154
  "distinct(map fst xys) \<Longrightarrow> (Some y = map_of xys x) = ((x,y) \<in> set xys)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   155
by (auto simp del: map_of_eq_Some_iff simp: map_of_eq_Some_iff [symmetric])
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   156
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   157
lemma map_of_is_SomeI [simp]: 
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   158
  "\<lbrakk>distinct(map fst xys); (x,y) \<in> set xys\<rbrakk> \<Longrightarrow> map_of xys x = Some y"
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   159
  by simp
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   160
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   161
lemma map_of_zip_is_None [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   162
  "length xs = length ys \<Longrightarrow> (map_of (zip xs ys) x = None) = (x \<notin> set xs)"
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   163
by (induct rule: list_induct2) simp_all
15110
78b5636eabc7 Added a number of new thms and the new function remove1
nipkow
parents: 14739
diff changeset
   164
26443
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   165
lemma map_of_zip_is_Some:
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   166
  assumes "length xs = length ys"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   167
  shows "x \<in> set xs \<longleftrightarrow> (\<exists>y. map_of (zip xs ys) x = Some y)"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   168
using assms by (induct rule: list_induct2) simp_all
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   169
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   170
lemma map_of_zip_upd:
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   171
  fixes x :: 'a and xs :: "'a list" and ys zs :: "'b list"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   172
  assumes "length ys = length xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   173
    and "length zs = length xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   174
    and "x \<notin> set xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   175
    and "map_of (zip xs ys)(x \<mapsto> y) = map_of (zip xs zs)(x \<mapsto> z)"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   176
  shows "map_of (zip xs ys) = map_of (zip xs zs)"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   177
proof
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   178
  fix x' :: 'a
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   179
  show "map_of (zip xs ys) x' = map_of (zip xs zs) x'"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   180
  proof (cases "x = x'")
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   181
    case True
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   182
    from assms True map_of_zip_is_None [of xs ys x']
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   183
      have "map_of (zip xs ys) x' = None" by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   184
    moreover from assms True map_of_zip_is_None [of xs zs x']
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   185
      have "map_of (zip xs zs) x' = None" by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   186
    ultimately show ?thesis by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   187
  next
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   188
    case False from assms
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   189
      have "(map_of (zip xs ys)(x \<mapsto> y)) x' = (map_of (zip xs zs)(x \<mapsto> z)) x'" by auto
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   190
    with False show ?thesis by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   191
  qed
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   192
qed
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   193
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   194
lemma map_of_zip_inject:
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   195
  assumes "length ys = length xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   196
    and "length zs = length xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   197
    and dist: "distinct xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   198
    and map_of: "map_of (zip xs ys) = map_of (zip xs zs)"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   199
  shows "ys = zs"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   200
  using assms(1) assms(2)[symmetric]
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   201
  using dist map_of
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   202
proof (induct ys xs zs rule: list_induct3)
26443
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   203
  case Nil show ?case by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   204
next
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   205
  case (Cons y ys x xs z zs)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   206
  from \<open>map_of (zip (x#xs) (y#ys)) = map_of (zip (x#xs) (z#zs))\<close>
26443
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   207
    have map_of: "map_of (zip xs ys)(x \<mapsto> y) = map_of (zip xs zs)(x \<mapsto> z)" by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   208
  from Cons have "length ys = length xs" and "length zs = length xs"
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   209
    and "x \<notin> set xs" by simp_all
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   210
  then have "map_of (zip xs ys) = map_of (zip xs zs)" using map_of by (rule map_of_zip_upd)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   211
  with Cons.hyps \<open>distinct (x # xs)\<close> have "ys = zs" by simp
26443
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   212
  moreover from map_of have "y = z" by (rule map_upd_eqD1)
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   213
  ultimately show ?case by simp
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   214
qed
cae9fa186541 lemmas about map_of (zip _ _)
haftmann
parents: 25965
diff changeset
   215
66584
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   216
lemma map_of_zip_nth:
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   217
  assumes "length xs = length ys"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   218
  assumes "distinct xs"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   219
  assumes "i < length ys"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   220
  shows "map_of (zip xs ys) (xs ! i) = Some (ys ! i)"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   221
using assms proof (induct arbitrary: i rule: list_induct2)
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   222
  case Nil
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   223
  then show ?case by simp
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   224
next
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   225
  case (Cons x xs y ys)
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   226
  then show ?case
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   227
    using less_Suc_eq_0_disj by auto
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   228
qed
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   229
33635
dcaada178c6f moved lemma map_of_zip_map to Map.thy
haftmann
parents: 32236
diff changeset
   230
lemma map_of_zip_map:
dcaada178c6f moved lemma map_of_zip_map to Map.thy
haftmann
parents: 32236
diff changeset
   231
  "map_of (zip xs (map f xs)) = (\<lambda>x. if x \<in> set xs then Some (f x) else None)"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   232
  by (induct xs) (simp_all add: fun_eq_iff)
33635
dcaada178c6f moved lemma map_of_zip_map to Map.thy
haftmann
parents: 32236
diff changeset
   233
15110
78b5636eabc7 Added a number of new thms and the new function remove1
nipkow
parents: 14739
diff changeset
   234
lemma finite_range_map_of: "finite (range (map_of xys))"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   235
proof (induct xys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   236
  case (Cons a xys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   237
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   238
    using finite_range_updI by fastforce
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   239
qed auto
15110
78b5636eabc7 Added a number of new thms and the new function remove1
nipkow
parents: 14739
diff changeset
   240
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   241
lemma map_of_SomeD: "map_of xs k = Some y \<Longrightarrow> (k, y) \<in> set xs"
60841
144523e0678e eliminated clone;
wenzelm
parents: 60839
diff changeset
   242
  by (induct xs) (auto split: if_splits)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   243
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   244
lemma map_of_mapk_SomeI:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   245
  "inj f \<Longrightarrow> map_of t k = Some x \<Longrightarrow>
61032
b57df8eecad6 standardized some occurences of ancient "split" alias
haftmann
parents: 60841
diff changeset
   246
   map_of (map (case_prod (\<lambda>k. Pair (f k))) t) (f k) = Some x"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   247
by (induct t) (auto simp: inj_eq)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   248
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   249
lemma weak_map_of_SomeI: "(k, x) \<in> set l \<Longrightarrow> \<exists>x. map_of l k = Some x"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   250
by (induct l) auto
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   251
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   252
lemma map_of_filter_in:
61032
b57df8eecad6 standardized some occurences of ancient "split" alias
haftmann
parents: 60841
diff changeset
   253
  "map_of xs k = Some z \<Longrightarrow> P k z \<Longrightarrow> map_of (filter (case_prod P) xs) k = Some z"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   254
by (induct xs) auto
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   255
35607
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   256
lemma map_of_map:
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 53820
diff changeset
   257
  "map_of (map (\<lambda>(k, v). (k, f v)) xs) = map_option f \<circ> map_of xs"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   258
  by (induct xs) (auto simp: fun_eq_iff)
35607
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   259
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 53820
diff changeset
   260
lemma dom_map_option:
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 53820
diff changeset
   261
  "dom (\<lambda>k. map_option (f k) (m k)) = dom m"
35607
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   262
  by (simp add: dom_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   263
56545
8f1e7596deb7 more operations and lemmas
haftmann
parents: 55466
diff changeset
   264
lemma dom_map_option_comp [simp]:
8f1e7596deb7 more operations and lemmas
haftmann
parents: 55466
diff changeset
   265
  "dom (map_option g \<circ> m) = dom m"
8f1e7596deb7 more operations and lemmas
haftmann
parents: 55466
diff changeset
   266
  using dom_map_option [of "\<lambda>_. g" m] by (simp add: comp_def)
8f1e7596deb7 more operations and lemmas
haftmann
parents: 55466
diff changeset
   267
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   268
69593
3dda49e08b9d isabelle update -u control_cartouches;
wenzelm
parents: 68460
diff changeset
   269
subsection \<open>\<^const>\<open>map_option\<close> related\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   270
67091
1393c2340eec more symbols;
wenzelm
parents: 67051
diff changeset
   271
lemma map_option_o_empty [simp]: "map_option f \<circ> empty = empty"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   272
by (rule ext) simp
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   273
55466
786edc984c98 merged 'Option.map' and 'Option.map_option'
blanchet
parents: 53820
diff changeset
   274
lemma map_option_o_map_upd [simp]:
67091
1393c2340eec more symbols;
wenzelm
parents: 67051
diff changeset
   275
  "map_option f \<circ> m(a\<mapsto>b) = (map_option f \<circ> m)(a\<mapsto>f b)"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   276
by (rule ext) simp
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   277
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   278
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   279
subsection \<open>@{term [source] map_comp} related\<close>
17391
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   280
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   281
lemma map_comp_empty [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   282
  "m \<circ>\<^sub>m empty = empty"
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   283
  "empty \<circ>\<^sub>m m = empty"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   284
by (auto simp: map_comp_def split: option.splits)
17391
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   285
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   286
lemma map_comp_simps [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   287
  "m2 k = None \<Longrightarrow> (m1 \<circ>\<^sub>m m2) k = None"
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   288
  "m2 k = Some k' \<Longrightarrow> (m1 \<circ>\<^sub>m m2) k = m1 k'"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   289
by (auto simp: map_comp_def)
17391
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   290
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   291
lemma map_comp_Some_iff:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   292
  "((m1 \<circ>\<^sub>m m2) k = Some v) = (\<exists>k'. m2 k = Some k' \<and> m1 k' = Some v)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   293
by (auto simp: map_comp_def split: option.splits)
17391
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   294
c6338ed6caf8 removed syntax fun_map_comp;
schirmer
parents: 15695
diff changeset
   295
lemma map_comp_None_iff:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   296
  "((m1 \<circ>\<^sub>m m2) k = None) = (m2 k = None \<or> (\<exists>k'. m2 k = Some k' \<and> m1 k' = None)) "
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   297
by (auto simp: map_comp_def split: option.splits)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   298
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   299
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61069
diff changeset
   300
subsection \<open>\<open>++\<close>\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   301
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   302
lemma map_add_empty[simp]: "m ++ empty = m"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   303
by(simp add: map_add_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   304
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   305
lemma empty_map_add[simp]: "empty ++ m = m"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   306
by (rule ext) (simp add: map_add_def split: option.split)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   307
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   308
lemma map_add_assoc[simp]: "m1 ++ (m2 ++ m3) = (m1 ++ m2) ++ m3"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   309
by (rule ext) (simp add: map_add_def split: option.split)
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   310
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   311
lemma map_add_Some_iff:
67091
1393c2340eec more symbols;
wenzelm
parents: 67051
diff changeset
   312
  "((m ++ n) k = Some x) = (n k = Some x \<or> n k = None \<and> m k = Some x)"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   313
by (simp add: map_add_def split: option.split)
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   314
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   315
lemma map_add_SomeD [dest!]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   316
  "(m ++ n) k = Some x \<Longrightarrow> n k = Some x \<or> n k = None \<and> m k = Some x"
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   317
by (rule map_add_Some_iff [THEN iffD1])
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   318
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   319
lemma map_add_find_right [simp]: "n k = Some xx \<Longrightarrow> (m ++ n) k = Some xx"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   320
by (subst map_add_Some_iff) fast
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   321
67091
1393c2340eec more symbols;
wenzelm
parents: 67051
diff changeset
   322
lemma map_add_None [iff]: "((m ++ n) k = None) = (n k = None \<and> m k = None)"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   323
by (simp add: map_add_def split: option.split)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   324
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   325
lemma map_add_upd[simp]: "f ++ g(x\<mapsto>y) = (f ++ g)(x\<mapsto>y)"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   326
by (rule ext) (simp add: map_add_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   327
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   328
lemma map_add_upds[simp]: "m1 ++ (m2(xs[\<mapsto>]ys)) = (m1++m2)(xs[\<mapsto>]ys)"
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   329
by (simp add: map_upds_def)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   330
32236
0203e1006f1b some lemmas about maps (contributed by Peter Lammich)
krauss
parents: 31380
diff changeset
   331
lemma map_add_upd_left: "m\<notin>dom e2 \<Longrightarrow> e1(m \<mapsto> u1) ++ e2 = (e1 ++ e2)(m \<mapsto> u1)"
0203e1006f1b some lemmas about maps (contributed by Peter Lammich)
krauss
parents: 31380
diff changeset
   332
by (rule ext) (auto simp: map_add_def dom_def split: option.split)
0203e1006f1b some lemmas about maps (contributed by Peter Lammich)
krauss
parents: 31380
diff changeset
   333
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   334
lemma map_of_append[simp]: "map_of (xs @ ys) = map_of ys ++ map_of xs"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   335
  unfolding map_add_def
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   336
proof (induct xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   337
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   338
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   339
    by (force split: option.split)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   340
qed auto
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   341
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   342
lemma finite_range_map_of_map_add:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   343
  "finite (range f) \<Longrightarrow> finite (range (f ++ map_of l))"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   344
proof (induct l)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   345
case (Cons a l)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   346
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   347
    by (metis finite_range_updI map_add_upd map_of.simps(2))
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   348
qed auto
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   349
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   350
lemma inj_on_map_add_dom [iff]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   351
  "inj_on (m ++ m') (dom m') = inj_on m' (dom m')"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   352
  by (fastforce simp: map_add_def dom_def inj_on_def split: option.splits)
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   353
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   354
lemma map_upds_fold_map_upd:
35552
364cb98a3e4e more uniform naming conventions
haftmann
parents: 35159
diff changeset
   355
  "m(ks[\<mapsto>]vs) = foldl (\<lambda>m (k, v). m(k \<mapsto> v)) m (zip ks vs)"
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   356
unfolding map_upds_def proof (rule sym, rule zip_obtain_same_length)
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   357
  fix ks :: "'a list" and vs :: "'b list"
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   358
  assume "length ks = length vs"
35552
364cb98a3e4e more uniform naming conventions
haftmann
parents: 35159
diff changeset
   359
  then show "foldl (\<lambda>m (k, v). m(k\<mapsto>v)) m (zip ks vs) = m ++ map_of (rev (zip ks vs))"
364cb98a3e4e more uniform naming conventions
haftmann
parents: 35159
diff changeset
   360
    by(induct arbitrary: m rule: list_induct2) simp_all
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   361
qed
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   362
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   363
lemma map_add_map_of_foldr:
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   364
  "m ++ map_of ps = foldr (\<lambda>(k, v) m. m(k \<mapsto> v)) ps m"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   365
  by (induct ps) (auto simp: fun_eq_iff map_add_def)
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   366
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   367
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   368
subsection \<open>@{term [source] restrict_map}\<close>
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   369
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   370
lemma restrict_map_to_empty [simp]: "m|`{} = empty"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   371
  by (simp add: restrict_map_def)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   372
31380
f25536c0bb80 added/moved lemmas by Andreas Lochbihler
haftmann
parents: 31080
diff changeset
   373
lemma restrict_map_insert: "f |` (insert a A) = (f |` A)(a := f a)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   374
  by (auto simp: restrict_map_def)
31380
f25536c0bb80 added/moved lemmas by Andreas Lochbihler
haftmann
parents: 31080
diff changeset
   375
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   376
lemma restrict_map_empty [simp]: "empty|`D = empty"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   377
  by (simp add: restrict_map_def)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   378
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   379
lemma restrict_in [simp]: "x \<in> A \<Longrightarrow> (m|`A) x = m x"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   380
  by (simp add: restrict_map_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   381
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   382
lemma restrict_out [simp]: "x \<notin> A \<Longrightarrow> (m|`A) x = None"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   383
  by (simp add: restrict_map_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   384
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   385
lemma ran_restrictD: "y \<in> ran (m|`A) \<Longrightarrow> \<exists>x\<in>A. m x = Some y"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   386
  by (auto simp: restrict_map_def ran_def split: if_split_asm)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   387
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   388
lemma dom_restrict [simp]: "dom (m|`A) = dom m \<inter> A"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   389
  by (auto simp: restrict_map_def dom_def split: if_split_asm)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   390
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   391
lemma restrict_upd_same [simp]: "m(x\<mapsto>y)|`(-{x}) = m|`(-{x})"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   392
  by (rule ext) (auto simp: restrict_map_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   393
15693
3a67e61c6e96 tuned Map, renamed lex stuff in List.
nipkow
parents: 15691
diff changeset
   394
lemma restrict_restrict [simp]: "m|`A|`B = m|`(A\<inter>B)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   395
  by (rule ext) (auto simp: restrict_map_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   396
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   397
lemma restrict_fun_upd [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   398
  "m(x := y)|`D = (if x \<in> D then (m|`(D-{x}))(x := y) else m|`D)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   399
  by (simp add: restrict_map_def fun_eq_iff)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   400
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   401
lemma fun_upd_None_restrict [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   402
  "(m|`D)(x := None) = (if x \<in> D then m|`(D - {x}) else m|`D)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   403
  by (simp add: restrict_map_def fun_eq_iff)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   404
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   405
lemma fun_upd_restrict: "(m|`D)(x := y) = (m|`(D-{x}))(x := y)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   406
  by (simp add: restrict_map_def fun_eq_iff)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   407
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   408
lemma fun_upd_restrict_conv [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   409
  "x \<in> D \<Longrightarrow> (m|`D)(x := y) = (m|`(D-{x}))(x := y)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   410
  by (rule fun_upd_restrict)
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   411
35159
df38e92af926 added lemma map_of_map_restrict; generalized lemma dom_const
haftmann
parents: 35115
diff changeset
   412
lemma map_of_map_restrict:
df38e92af926 added lemma map_of_map_restrict; generalized lemma dom_const
haftmann
parents: 35115
diff changeset
   413
  "map_of (map (\<lambda>k. (k, f k)) ks) = (Some \<circ> f) |` set ks"
39302
d7728f65b353 renamed lemmas: ext_iff -> fun_eq_iff, set_ext_iff -> set_eq_iff, set_ext -> set_eqI
nipkow
parents: 39198
diff changeset
   414
  by (induct ks) (simp_all add: fun_eq_iff restrict_map_insert)
35159
df38e92af926 added lemma map_of_map_restrict; generalized lemma dom_const
haftmann
parents: 35115
diff changeset
   415
35619
b5f6481772f3 lemma restrict_complement_singleton_eq
haftmann
parents: 35607
diff changeset
   416
lemma restrict_complement_singleton_eq:
b5f6481772f3 lemma restrict_complement_singleton_eq
haftmann
parents: 35607
diff changeset
   417
  "f |` (- {x}) = f(x := None)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   418
  by auto
35619
b5f6481772f3 lemma restrict_complement_singleton_eq
haftmann
parents: 35607
diff changeset
   419
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   420
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   421
subsection \<open>@{term [source] map_upds}\<close>
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   422
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   423
lemma map_upds_Nil1 [simp]: "m([] [\<mapsto>] bs) = m"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   424
  by (simp add: map_upds_def)
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   425
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   426
lemma map_upds_Nil2 [simp]: "m(as [\<mapsto>] []) = m"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   427
  by (simp add:map_upds_def)
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   428
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   429
lemma map_upds_Cons [simp]: "m(a#as [\<mapsto>] b#bs) = (m(a\<mapsto>b))(as[\<mapsto>]bs)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   430
  by (simp add:map_upds_def)
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   431
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   432
lemma map_upds_append1 [simp]:
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   433
  "size xs < size ys \<Longrightarrow> m(xs@[x] [\<mapsto>] ys) = m(xs [\<mapsto>] ys)(x \<mapsto> ys!size xs)"
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   434
proof (induct xs arbitrary: ys m)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   435
  case Nil
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   436
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   437
    by (auto simp: neq_Nil_conv)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   438
next
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   439
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   440
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   441
    by (cases ys) auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   442
qed
14187
26dfcd0ac436 Added new theorems
nipkow
parents: 14186
diff changeset
   443
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   444
lemma map_upds_list_update2_drop [simp]:
46588
4895d7f1be42 removing some unnecessary premises from Map theory
bulwahn
parents: 44921
diff changeset
   445
  "size xs \<le> i \<Longrightarrow> m(xs[\<mapsto>]ys[i:=y]) = m(xs[\<mapsto>]ys)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   446
proof (induct xs arbitrary: m ys i)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   447
  case Nil
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   448
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   449
    by auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   450
next
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   451
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   452
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   453
    by (cases ys) (use Cons in \<open>auto split: nat.split\<close>)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   454
qed
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   455
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   456
text \<open>Something weirdly sensitive about this proof, which needs only four lines in apply style\<close>
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   457
lemma map_upd_upds_conv_if:
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   458
  "(f(x\<mapsto>y))(xs [\<mapsto>] ys) =
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   459
   (if x \<in> set(take (length ys) xs) then f(xs [\<mapsto>] ys)
60838
2d7eea27ceec more symbols;
wenzelm
parents: 60758
diff changeset
   460
                                    else (f(xs [\<mapsto>] ys))(x\<mapsto>y))"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   461
proof (induct xs arbitrary: x y ys f)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   462
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   463
  show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   464
  proof (cases ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   465
    case (Cons z zs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   466
    then show ?thesis
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   467
      using Cons.hyps
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   468
      apply (auto split: if_split simp: fun_upd_twist)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   469
      using Cons.hyps apply fastforce+
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   470
      done
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   471
  qed auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   472
qed auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   473
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   474
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   475
lemma map_upds_twist [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   476
  "a \<notin> set as \<Longrightarrow> m(a\<mapsto>b)(as[\<mapsto>]bs) = m(as[\<mapsto>]bs)(a\<mapsto>b)"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 42163
diff changeset
   477
using set_take_subset by (fastforce simp add: map_upd_upds_conv_if)
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   478
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   479
lemma map_upds_apply_nontin [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   480
  "x \<notin> set xs \<Longrightarrow> (f(xs[\<mapsto>]ys)) x = f x"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   481
proof (induct xs arbitrary: ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   482
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   483
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   484
    by (cases ys) (auto simp: map_upd_upds_conv_if)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   485
qed auto
14025
d9b155757dc8 *** empty log message ***
nipkow
parents: 13937
diff changeset
   486
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   487
lemma fun_upds_append_drop [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   488
  "size xs = size ys \<Longrightarrow> m(xs@zs[\<mapsto>]ys) = m(xs[\<mapsto>]ys)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   489
proof (induct xs arbitrary: ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   490
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   491
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   492
    by (cases ys) (auto simp: map_upd_upds_conv_if)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   493
qed auto
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 14208
diff changeset
   494
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   495
lemma fun_upds_append2_drop [simp]:
24331
76f7a8c6e842 Made UN_Un simp
nipkow
parents: 22744
diff changeset
   496
  "size xs = size ys \<Longrightarrow> m(xs[\<mapsto>]ys@zs) = m(xs[\<mapsto>]ys)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   497
proof (induct xs arbitrary: ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   498
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   499
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   500
    by (cases ys) (auto simp: map_upd_upds_conv_if)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   501
qed auto
14300
bf8b8c9425c3 *** empty log message ***
nipkow
parents: 14208
diff changeset
   502
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   503
lemma restrict_map_upds[simp]:
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   504
  "\<lbrakk> length xs = length ys; set xs \<subseteq> D \<rbrakk>
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   505
    \<Longrightarrow> m(xs [\<mapsto>] ys)|`D = (m|`(D - set xs))(xs [\<mapsto>] ys)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   506
proof (induct xs arbitrary: m ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   507
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   508
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   509
  proof (cases ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   510
    case (Cons z zs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   511
    with Cons.hyps Cons.prems show ?thesis
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   512
      apply (simp add: insert_absorb flip: Diff_insert)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   513
      apply (auto simp add: map_upd_upds_conv_if)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   514
      done
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   515
  qed auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   516
qed auto
14186
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   517
6d2a494e33be Added a number of thms about map restriction.
nipkow
parents: 14180
diff changeset
   518
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   519
subsection \<open>@{term [source] dom}\<close>
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   520
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   521
lemma dom_eq_empty_conv [simp]: "dom f = {} \<longleftrightarrow> f = empty"
44921
58eef4843641 tuned proofs
huffman
parents: 44890
diff changeset
   522
  by (auto simp: dom_def)
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   523
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   524
lemma domI: "m a = Some b \<Longrightarrow> a \<in> dom m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   525
  by (simp add: dom_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   526
(* declare domI [intro]? *)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   527
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   528
lemma domD: "a \<in> dom m \<Longrightarrow> \<exists>b. m a = Some b"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   529
  by (cases "m a") (auto simp add: dom_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   530
66010
2f7d39285a1a executable domain membership checks
haftmann
parents: 63834
diff changeset
   531
lemma domIff [iff, simp del, code_unfold]: "a \<in> dom m \<longleftrightarrow> m a \<noteq> None"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   532
  by (simp add: dom_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   533
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   534
lemma dom_empty [simp]: "dom empty = {}"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   535
  by (simp add: dom_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   536
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   537
lemma dom_fun_upd [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   538
  "dom(f(x := y)) = (if y = None then dom f - {x} else insert x (dom f))"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   539
  by (auto simp: dom_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   540
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   541
lemma dom_if:
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   542
  "dom (\<lambda>x. if P x then f x else g x) = dom f \<inter> {x. P x} \<union> dom g \<inter> {x. \<not> P x}"
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   543
  by (auto split: if_splits)
13937
e9d57517c9b1 added a thm
nipkow
parents: 13914
diff changeset
   544
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   545
lemma dom_map_of_conv_image_fst:
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   546
  "dom (map_of xys) = fst ` set xys"
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   547
  by (induct xys) (auto simp add: dom_if)
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   548
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   549
lemma dom_map_of_zip [simp]: "length xs = length ys \<Longrightarrow> dom (map_of (zip xs ys)) = set xs"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   550
  by (induct rule: list_induct2) (auto simp: dom_if)
15110
78b5636eabc7 Added a number of new thms and the new function remove1
nipkow
parents: 14739
diff changeset
   551
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   552
lemma finite_dom_map_of: "finite (dom (map_of l))"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   553
  by (induct l) (auto simp: dom_def insert_Collect [symmetric])
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   554
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   555
lemma dom_map_upds [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   556
  "dom(m(xs[\<mapsto>]ys)) = set(take (length ys) xs) \<union> dom m"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   557
proof (induct xs arbitrary: ys)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   558
  case (Cons a xs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   559
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   560
    by (cases ys) (auto simp: map_upd_upds_conv_if)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   561
qed auto
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   562
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   563
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   564
lemma dom_map_add [simp]: "dom (m ++ n) = dom n \<union> dom m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   565
  by (auto simp: dom_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   566
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   567
lemma dom_override_on [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   568
  "dom (override_on f g A) =
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   569
    (dom f  - {a. a \<in> A - dom g}) \<union> {a. a \<in> A \<inter> dom g}"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   570
  by (auto simp: dom_def override_on_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   571
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   572
lemma map_add_comm: "dom m1 \<inter> dom m2 = {} \<Longrightarrow> m1 ++ m2 = m2 ++ m1"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   573
  by (rule ext) (force simp: map_add_def dom_def split: option.split)
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   574
32236
0203e1006f1b some lemmas about maps (contributed by Peter Lammich)
krauss
parents: 31380
diff changeset
   575
lemma map_add_dom_app_simps:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   576
  "m \<in> dom l2 \<Longrightarrow> (l1 ++ l2) m = l2 m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   577
  "m \<notin> dom l1 \<Longrightarrow> (l1 ++ l2) m = l2 m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   578
  "m \<notin> dom l2 \<Longrightarrow> (l1 ++ l2) m = l1 m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   579
  by (auto simp add: map_add_def split: option.split_asm)
32236
0203e1006f1b some lemmas about maps (contributed by Peter Lammich)
krauss
parents: 31380
diff changeset
   580
29622
2eeb09477ed3 lemmas dom_const, dom_if
haftmann
parents: 28790
diff changeset
   581
lemma dom_const [simp]:
35159
df38e92af926 added lemma map_of_map_restrict; generalized lemma dom_const
haftmann
parents: 35115
diff changeset
   582
  "dom (\<lambda>x. Some (f x)) = UNIV"
29622
2eeb09477ed3 lemmas dom_const, dom_if
haftmann
parents: 28790
diff changeset
   583
  by auto
2eeb09477ed3 lemmas dom_const, dom_if
haftmann
parents: 28790
diff changeset
   584
22230
bdec4a82f385 a few additions and deletions
nipkow
parents: 21404
diff changeset
   585
(* Due to John Matthews - could be rephrased with dom *)
bdec4a82f385 a few additions and deletions
nipkow
parents: 21404
diff changeset
   586
lemma finite_map_freshness:
bdec4a82f385 a few additions and deletions
nipkow
parents: 21404
diff changeset
   587
  "finite (dom (f :: 'a \<rightharpoonup> 'b)) \<Longrightarrow> \<not> finite (UNIV :: 'a set) \<Longrightarrow>
bdec4a82f385 a few additions and deletions
nipkow
parents: 21404
diff changeset
   588
   \<exists>x. f x = None"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   589
  by (bestsimp dest: ex_new_if_finite)
14027
68d247b7b14b *** empty log message ***
nipkow
parents: 14026
diff changeset
   590
28790
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   591
lemma dom_minus:
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   592
  "f x = None \<Longrightarrow> dom f - insert x A = dom f - A"
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   593
  unfolding dom_def by simp
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   594
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   595
lemma insert_dom:
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   596
  "f x = Some y \<Longrightarrow> insert x (dom f) = dom f"
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   597
  unfolding dom_def by auto
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   598
35607
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   599
lemma map_of_map_keys:
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   600
  "set xs = dom m \<Longrightarrow> map_of (map (\<lambda>k. (k, the (m k))) xs) = m"
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   601
  by (rule ext) (auto simp add: map_of_map_restrict restrict_map_def)
896f01fe825b added dom_option_map, map_of_map_keys
haftmann
parents: 35565
diff changeset
   602
39379
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   603
lemma map_of_eqI:
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   604
  assumes set_eq: "set (map fst xs) = set (map fst ys)"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   605
  assumes map_eq: "\<forall>k\<in>set (map fst xs). map_of xs k = map_of ys k"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   606
  shows "map_of xs = map_of ys"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   607
proof (rule ext)
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   608
  fix k show "map_of xs k = map_of ys k"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   609
  proof (cases "map_of xs k")
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   610
    case None
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   611
    then have "k \<notin> set (map fst xs)" by (simp add: map_of_eq_None_iff)
39379
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   612
    with set_eq have "k \<notin> set (map fst ys)" by simp
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   613
    then have "map_of ys k = None" by (simp add: map_of_eq_None_iff)
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   614
    with None show ?thesis by simp
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   615
  next
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   616
    case (Some v)
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   617
    then have "k \<in> set (map fst xs)" by (auto simp add: dom_map_of_conv_image_fst [symmetric])
39379
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   618
    with map_eq show ?thesis by auto
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   619
  qed
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   620
qed
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   621
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   622
lemma map_of_eq_dom:
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   623
  assumes "map_of xs = map_of ys"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   624
  shows "fst ` set xs = fst ` set ys"
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   625
proof -
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   626
  from assms have "dom (map_of xs) = dom (map_of ys)" by simp
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   627
  then show ?thesis by (simp add: dom_map_of_conv_image_fst)
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   628
qed
ab1b070aa412 moved lemmas map_of_eqI and map_of_eq_dom to Map.thy
haftmann
parents: 39302
diff changeset
   629
53820
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   630
lemma finite_set_of_finite_maps:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   631
  assumes "finite A" "finite B"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   632
  shows "finite {m. dom m = A \<and> ran m \<subseteq> B}" (is "finite ?S")
53820
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   633
proof -
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   634
  let ?S' = "{m. \<forall>x. (x \<in> A \<longrightarrow> m x \<in> Some ` B) \<and> (x \<notin> A \<longrightarrow> m x = None)}"
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   635
  have "?S = ?S'"
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   636
  proof
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   637
    show "?S \<subseteq> ?S'" by (auto simp: dom_def ran_def image_def)
53820
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   638
    show "?S' \<subseteq> ?S"
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   639
    proof
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   640
      fix m assume "m \<in> ?S'"
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   641
      hence 1: "dom m = A" by force
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   642
      hence 2: "ran m \<subseteq> B" using \<open>m \<in> ?S'\<close> by (auto simp: dom_def ran_def)
53820
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   643
      from 1 2 show "m \<in> ?S" by blast
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   644
    qed
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   645
  qed
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   646
  with assms show ?thesis by(simp add: finite_set_of_finite_funs)
9c7e97d67b45 added lemmas
nipkow
parents: 53374
diff changeset
   647
qed
28790
2efba7b18c5b lemmas about dom and minus / insert
haftmann
parents: 28562
diff changeset
   648
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   649
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   650
subsection \<open>@{term [source] ran}\<close>
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   651
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   652
lemma ranI: "m a = Some b \<Longrightarrow> b \<in> ran m"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   653
  by (auto simp: ran_def)
14100
804be4c4b642 added map_image, restrict_map, some thms
oheimb
parents: 14033
diff changeset
   654
(* declare ranI [intro]? *)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   655
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   656
lemma ran_empty [simp]: "ran empty = {}"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   657
  by (auto simp: ran_def)
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   658
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   659
lemma ran_map_upd [simp]:  "m a = None \<Longrightarrow> ran(m(a\<mapsto>b)) = insert b (ran m)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   660
  unfolding ran_def
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   661
  by force
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   662
66583
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   663
lemma ran_map_add:
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   664
  assumes "dom m1 \<inter> dom m2 = {}"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   665
  shows "ran (m1 ++ m2) = ran m1 \<union> ran m2"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   666
proof
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   667
  show "ran (m1 ++ m2) \<subseteq> ran m1 \<union> ran m2"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   668
    unfolding ran_def by auto
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   669
next
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   670
  show "ran m1 \<union> ran m2 \<subseteq> ran (m1 ++ m2)"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   671
  proof -
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   672
    have "(m1 ++ m2) x = Some y" if "m1 x = Some y" for x y
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   673
      using assms map_add_comm that by fastforce
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   674
    moreover have "(m1 ++ m2) x = Some y" if "m2 x = Some y" for x y
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   675
      using assms that by auto
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   676
    ultimately show ?thesis
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   677
      unfolding ran_def by blast
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   678
  qed
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   679
qed
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   680
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   681
lemma finite_ran:
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   682
  assumes "finite (dom p)"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   683
  shows "finite (ran p)"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   684
proof -
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   685
  have "ran p = (\<lambda>x. the (p x)) ` dom p"
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   686
    unfolding ran_def by force
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   687
  from this \<open>finite (dom p)\<close> show ?thesis by auto
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   688
qed
ac183ddc9fef more facts on Map.ran
bulwahn
parents: 66010
diff changeset
   689
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   690
lemma ran_distinct:
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   691
  assumes dist: "distinct (map fst al)"
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   692
  shows "ran (map_of al) = snd ` set al"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   693
  using assms
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   694
proof (induct al)
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   695
  case Nil
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   696
  then show ?case by simp
34979
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   697
next
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   698
  case (Cons kv al)
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   699
  then have "ran (map_of al) = snd ` set al" by simp
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   700
  moreover from Cons.prems have "map_of al (fst kv) = None"
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   701
    by (simp add: map_of_eq_None_iff)
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   702
  ultimately show ?case by (simp only: map_of.simps ran_map_upd) simp
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   703
qed
8cb6e7a42e9c more correspondence lemmas between related operations
haftmann
parents: 34941
diff changeset
   704
66584
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   705
lemma ran_map_of_zip:
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   706
  assumes "length xs = length ys" "distinct xs"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   707
  shows "ran (map_of (zip xs ys)) = set ys"
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   708
using assms by (simp add: ran_distinct set_map[symmetric])
acb02fa48ef3 more facts on Map.map_of and List.zip
bulwahn
parents: 66583
diff changeset
   709
60057
86fa63ce8156 add lemmas
Andreas Lochbihler
parents: 58889
diff changeset
   710
lemma ran_map_option: "ran (\<lambda>x. map_option f (m x)) = f ` ran m"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   711
  by (auto simp add: ran_def)
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   712
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   713
61799
4cf66f21b764 isabelle update_cartouches -c -t;
wenzelm
parents: 61069
diff changeset
   714
subsection \<open>\<open>map_le\<close>\<close>
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   715
13912
3c0a340be514 fixed document
kleing
parents: 13910
diff changeset
   716
lemma map_le_empty [simp]: "empty \<subseteq>\<^sub>m g"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   717
  by (simp add: map_le_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   718
17724
e969fc0a4925 simprules need names
paulson
parents: 17399
diff changeset
   719
lemma upd_None_map_le [simp]: "f(x := None) \<subseteq>\<^sub>m f"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   720
  by (force simp add: map_le_def)
14187
26dfcd0ac436 Added new theorems
nipkow
parents: 14186
diff changeset
   721
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   722
lemma map_le_upd[simp]: "f \<subseteq>\<^sub>m g ==> f(a := b) \<subseteq>\<^sub>m g(a := b)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   723
  by (fastforce simp add: map_le_def)
13910
f9a9ef16466f Added thms
nipkow
parents: 13909
diff changeset
   724
17724
e969fc0a4925 simprules need names
paulson
parents: 17399
diff changeset
   725
lemma map_le_imp_upd_le [simp]: "m1 \<subseteq>\<^sub>m m2 \<Longrightarrow> m1(x := None) \<subseteq>\<^sub>m m2(x \<mapsto> y)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   726
  by (force simp add: map_le_def)
14187
26dfcd0ac436 Added new theorems
nipkow
parents: 14186
diff changeset
   727
20800
69c82605efcf tuned specifications and proofs;
wenzelm
parents: 19947
diff changeset
   728
lemma map_le_upds [simp]:
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   729
  "f \<subseteq>\<^sub>m g \<Longrightarrow> f(as [\<mapsto>] bs) \<subseteq>\<^sub>m g(as [\<mapsto>] bs)"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   730
proof (induct as arbitrary: f g bs)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   731
  case (Cons a as)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   732
  then show ?case
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   733
    by (cases bs) (use Cons in auto)
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   734
qed auto
13908
4bdfa9f77254 Map.ML integrated into Map.thy
webertj
parents: 13890
diff changeset
   735
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   736
lemma map_le_implies_dom_le: "(f \<subseteq>\<^sub>m g) \<Longrightarrow> (dom f \<subseteq> dom g)"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   737
  by (fastforce simp add: map_le_def dom_def)
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   738
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   739
lemma map_le_refl [simp]: "f \<subseteq>\<^sub>m f"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   740
  by (simp add: map_le_def)
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   741
14187
26dfcd0ac436 Added new theorems
nipkow
parents: 14186
diff changeset
   742
lemma map_le_trans[trans]: "\<lbrakk> m1 \<subseteq>\<^sub>m m2; m2 \<subseteq>\<^sub>m m3\<rbrakk> \<Longrightarrow> m1 \<subseteq>\<^sub>m m3"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   743
  by (auto simp add: map_le_def dom_def)
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   744
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   745
lemma map_le_antisym: "\<lbrakk> f \<subseteq>\<^sub>m g; g \<subseteq>\<^sub>m f \<rbrakk> \<Longrightarrow> f = g"
71616
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   746
  unfolding map_le_def
a9de39608b1a more tidying up of old apply-proofs
paulson <lp15@cam.ac.uk>
parents: 69593
diff changeset
   747
  by (metis ext domIff)
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   748
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   749
lemma map_le_map_add [simp]: "f \<subseteq>\<^sub>m g ++ f"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   750
  by (fastforce simp: map_le_def)
14033
bc723de8ec95 Added a few lemmas about map_le
webertj
parents: 14027
diff changeset
   751
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   752
lemma map_le_iff_map_add_commute: "f \<subseteq>\<^sub>m f ++ g \<longleftrightarrow> f ++ g = g ++ f"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   753
  by (fastforce simp: map_add_def map_le_def fun_eq_iff split: option.splits)
15304
3514ca74ac54 Added more lemmas
nipkow
parents: 15303
diff changeset
   754
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   755
lemma map_add_le_mapE: "f ++ g \<subseteq>\<^sub>m h \<Longrightarrow> g \<subseteq>\<^sub>m h"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   756
  by (fastforce simp: map_le_def map_add_def dom_def)
15303
eedbb8d22ca2 added lemmas
nipkow
parents: 15251
diff changeset
   757
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   758
lemma map_add_le_mapI: "\<lbrakk> f \<subseteq>\<^sub>m h; g \<subseteq>\<^sub>m h \<rbrakk> \<Longrightarrow> f ++ g \<subseteq>\<^sub>m h"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   759
  by (auto simp: map_le_def map_add_def dom_def split: option.splits)
15303
eedbb8d22ca2 added lemmas
nipkow
parents: 15251
diff changeset
   760
63828
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   761
lemma map_add_subsumed1: "f \<subseteq>\<^sub>m g \<Longrightarrow> f++g = g"
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   762
by (simp add: map_add_le_mapI map_le_antisym)
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   763
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   764
lemma map_add_subsumed2: "f \<subseteq>\<^sub>m g \<Longrightarrow> g++f = g"
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   765
by (metis map_add_subsumed1 map_le_iff_map_add_commute)
ca467e73f912 added lemmas
nipkow
parents: 63648
diff changeset
   766
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   767
lemma dom_eq_singleton_conv: "dom f = {x} \<longleftrightarrow> (\<exists>v. f = [x \<mapsto> v])"
63834
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   768
  (is "?lhs \<longleftrightarrow> ?rhs")
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   769
proof
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   770
  assume ?rhs
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   771
  then show ?lhs by (auto split: if_split_asm)
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   772
next
63834
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   773
  assume ?lhs
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   774
  then obtain v where v: "f x = Some v" by auto
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   775
  show ?rhs
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   776
  proof
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   777
    show "f = [x \<mapsto> v]"
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   778
    proof (rule map_le_antisym)
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   779
      show "[x \<mapsto> v] \<subseteq>\<^sub>m f"
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   780
        using v by (auto simp add: map_le_def)
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   781
      show "f \<subseteq>\<^sub>m [x \<mapsto> v]"
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   782
        using \<open>dom f = {x}\<close> \<open>f x = Some v\<close> by (auto simp add: map_le_def)
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   783
    qed
6a757f36997e tuned proofs;
wenzelm
parents: 63828
diff changeset
   784
  qed
31080
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   785
qed
21ffc770ebc0 lemmas by Andreas Lochbihler
nipkow
parents: 30935
diff changeset
   786
68454
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   787
lemma map_add_eq_empty_iff[simp]:
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   788
  "(f++g = empty) \<longleftrightarrow> f = empty \<and> g = empty"
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   789
by (metis map_add_None)
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   790
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   791
lemma empty_eq_map_add_iff[simp]:
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   792
  "(empty = f++g) \<longleftrightarrow> f = empty \<and> g = empty"
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   793
by(subst map_add_eq_empty_iff[symmetric])(rule eq_commute)
f35aa0e7255d moved lemmas from AFP
nipkow
parents: 68450
diff changeset
   794
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   795
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   796
subsection \<open>Various\<close>
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   797
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   798
lemma set_map_of_compr:
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   799
  assumes distinct: "distinct (map fst xs)"
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   800
  shows "set xs = {(k, v). map_of xs k = Some v}"
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   801
  using assms
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   802
proof (induct xs)
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   803
  case Nil
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   804
  then show ?case by simp
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   805
next
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   806
  case (Cons x xs)
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   807
  obtain k v where "x = (k, v)" by (cases x) blast
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   808
  with Cons.prems have "k \<notin> dom (map_of xs)"
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   809
    by (simp add: dom_map_of_conv_image_fst)
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   810
  then have *: "insert (k, v) {(k, v). map_of xs k = Some v} =
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   811
    {(k', v'). (map_of xs(k \<mapsto> v)) k' = Some v'}"
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   812
    by (auto split: if_splits)
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   813
  from Cons have "set xs = {(k, v). map_of xs k = Some v}" by simp
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   814
  with * \<open>x = (k, v)\<close> show ?case by simp
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   815
qed
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   816
67051
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   817
lemma eq_key_imp_eq_value:
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   818
  "v1 = v2"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   819
  if "distinct (map fst xs)" "(k, v1) \<in> set xs" "(k, v2) \<in> set xs"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   820
proof -
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   821
  from that have "inj_on fst (set xs)"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   822
    by (simp add: distinct_map)
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   823
  moreover have "fst (k, v1) = fst (k, v2)"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   824
    by simp
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   825
  ultimately have "(k, v1) = (k, v2)"
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   826
    by (rule inj_onD) (fact that)+
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   827
  then show ?thesis
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   828
    by simp
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   829
qed
e7e54a0b9197 dedicated definition for coprimality
haftmann
parents: 66584
diff changeset
   830
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   831
lemma map_of_inject_set:
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   832
  assumes distinct: "distinct (map fst xs)" "distinct (map fst ys)"
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   833
  shows "map_of xs = map_of ys \<longleftrightarrow> set xs = set ys" (is "?lhs \<longleftrightarrow> ?rhs")
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   834
proof
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   835
  assume ?lhs
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   836
  moreover from \<open>distinct (map fst xs)\<close> have "set xs = {(k, v). map_of xs k = Some v}"
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   837
    by (rule set_map_of_compr)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   838
  moreover from \<open>distinct (map fst ys)\<close> have "set ys = {(k, v). map_of ys k = Some v}"
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   839
    by (rule set_map_of_compr)
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   840
  ultimately show ?rhs by simp
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   841
next
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53015
diff changeset
   842
  assume ?rhs show ?lhs
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53015
diff changeset
   843
  proof
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   844
    fix k
60839
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   845
    show "map_of xs k = map_of ys k"
422ec7a3c18a more symbols;
wenzelm
parents: 60838
diff changeset
   846
    proof (cases "map_of xs k")
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   847
      case None
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   848
      with \<open>?rhs\<close> have "map_of ys k = None"
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   849
        by (simp add: map_of_eq_None_iff)
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53015
diff changeset
   850
      with None show ?thesis by simp
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   851
    next
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   852
      case (Some v)
60758
d8d85a8172b5 isabelle update_cartouches;
wenzelm
parents: 60057
diff changeset
   853
      with distinct \<open>?rhs\<close> have "map_of ys k = Some v"
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   854
        by simp
53374
a14d2a854c02 tuned proofs -- clarified flow of facts wrt. calculation;
wenzelm
parents: 53015
diff changeset
   855
      with Some show ?thesis by simp
35565
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   856
    qed
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   857
  qed
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   858
qed
56b070cd7ab3 lemmas set_map_of_compr, map_of_inject_set
haftmann
parents: 35553
diff changeset
   859
68450
41de07c7a0f3 Map.empty now qualified to avoid name clashes
nipkow
parents: 67780
diff changeset
   860
hide_const (open) Map.empty
41de07c7a0f3 Map.empty now qualified to avoid name clashes
nipkow
parents: 67780
diff changeset
   861
3981
b4f93a8da835 Added the new theory Map.
nipkow
parents:
diff changeset
   862
end