48 "ran m = {b. EX a. m a = Some b}" |
48 "ran m = {b. EX a. m a = Some b}" |
49 |
49 |
50 definition |
50 definition |
51 map_le :: "('a ~=> 'b) => ('a ~=> 'b) => bool" (infix "\<subseteq>\<^sub>m" 50) where |
51 map_le :: "('a ~=> 'b) => ('a ~=> 'b) => bool" (infix "\<subseteq>\<^sub>m" 50) where |
52 "(m\<^isub>1 \<subseteq>\<^sub>m m\<^isub>2) = (\<forall>a \<in> dom m\<^isub>1. m\<^isub>1 a = m\<^isub>2 a)" |
52 "(m\<^isub>1 \<subseteq>\<^sub>m m\<^isub>2) = (\<forall>a \<in> dom m\<^isub>1. m\<^isub>1 a = m\<^isub>2 a)" |
53 |
|
54 consts |
|
55 map_of :: "('a * 'b) list => 'a ~=> 'b" |
|
56 map_upds :: "('a ~=> 'b) => 'a list => 'b list => ('a ~=> 'b)" |
|
57 |
53 |
58 nonterminals |
54 nonterminals |
59 maplets maplet |
55 maplets maplet |
60 |
56 |
61 syntax |
57 syntax |
71 "_maplets" :: "['a, 'a] => maplet" ("_ /[\<mapsto>]/ _") |
67 "_maplets" :: "['a, 'a] => maplet" ("_ /[\<mapsto>]/ _") |
72 |
68 |
73 translations |
69 translations |
74 "_MapUpd m (_Maplets xy ms)" == "_MapUpd (_MapUpd m xy) ms" |
70 "_MapUpd m (_Maplets xy ms)" == "_MapUpd (_MapUpd m xy) ms" |
75 "_MapUpd m (_maplet x y)" == "m(x:=Some y)" |
71 "_MapUpd m (_maplet x y)" == "m(x:=Some y)" |
76 "_MapUpd m (_maplets x y)" == "map_upds m x y" |
|
77 "_Map ms" == "_MapUpd (CONST empty) ms" |
72 "_Map ms" == "_MapUpd (CONST empty) ms" |
78 "_Map (_Maplets ms1 ms2)" <= "_MapUpd (_Map ms1) ms2" |
73 "_Map (_Maplets ms1 ms2)" <= "_MapUpd (_Map ms1) ms2" |
79 "_Maplets ms1 (_Maplets ms2 ms3)" <= "_Maplets (_Maplets ms1 ms2) ms3" |
74 "_Maplets ms1 (_Maplets ms2 ms3)" <= "_Maplets (_Maplets ms1 ms2) ms3" |
80 |
75 |
81 primrec |
76 primrec |
82 "map_of [] = empty" |
77 map_of :: "('a \<times> 'b) list \<Rightarrow> 'a \<rightharpoonup> 'b" where |
83 "map_of (p#ps) = (map_of ps)(fst p |-> snd p)" |
78 "map_of [] = empty" |
84 |
79 | "map_of (p # ps) = (map_of ps)(fst p \<mapsto> snd p)" |
85 declare map_of.simps [code del] |
80 |
|
81 definition |
|
82 map_upds :: "('a \<rightharpoonup> 'b) \<Rightarrow> 'a list \<Rightarrow> 'b list \<Rightarrow> 'a \<rightharpoonup> 'b" where |
|
83 "map_upds m xs ys = m ++ map_of (rev (zip xs ys))" |
|
84 |
|
85 translations |
|
86 "_MapUpd m (_maplets x y)" == "CONST map_upds m x y" |
86 |
87 |
87 lemma map_of_Cons_code [code]: |
88 lemma map_of_Cons_code [code]: |
88 "map_of [] k = None" |
89 "map_of [] k = None" |
89 "map_of ((l, v) # ps) k = (if l = k then Some v else map_of ps k)" |
90 "map_of ((l, v) # ps) k = (if l = k then Some v else map_of ps k)" |
90 by simp_all |
91 by simp_all |
91 |
|
92 defs |
|
93 map_upds_def [code]: "m(xs [|->] ys) == m ++ map_of (rev(zip xs ys))" |
|
94 |
92 |
95 |
93 |
96 subsection {* @{term [source] empty} *} |
94 subsection {* @{term [source] empty} *} |
97 |
95 |
98 lemma empty_upd_none [simp]: "empty(x := None) = empty" |
96 lemma empty_upd_none [simp]: "empty(x := None) = empty" |