14 |
14 |
15 types ('a,'b) "~=>" = "'a => 'b option" (infixr 0) |
15 types ('a,'b) "~=>" = "'a => 'b option" (infixr 0) |
16 translations (type) "a ~=> b " <= (type) "a => b option" |
16 translations (type) "a ~=> b " <= (type) "a => b option" |
17 |
17 |
18 consts |
18 consts |
19 chg_map :: "('b => 'b) => 'a => ('a ~=> 'b) => ('a ~=> 'b)" |
|
20 map_add :: "('a ~=> 'b) => ('a ~=> 'b) => ('a ~=> 'b)" (infixl "++" 100) |
19 map_add :: "('a ~=> 'b) => ('a ~=> 'b) => ('a ~=> 'b)" (infixl "++" 100) |
21 restrict_map :: "('a ~=> 'b) => 'a set => ('a ~=> 'b)" (infixl "|`" 110) |
20 restrict_map :: "('a ~=> 'b) => 'a set => ('a ~=> 'b)" (infixl "|`" 110) |
22 dom :: "('a ~=> 'b) => 'a set" |
21 dom :: "('a ~=> 'b) => 'a set" |
23 ran :: "('a ~=> 'b) => 'b set" |
22 ran :: "('a ~=> 'b) => 'b set" |
24 map_of :: "('a * 'b)list => 'a ~=> 'b" |
23 map_of :: "('a * 'b)list => 'a ~=> 'b" |
25 map_upds:: "('a ~=> 'b) => 'a list => 'b list => |
24 map_upds:: "('a ~=> 'b) => 'a list => 'b list => ('a ~=> 'b)" |
26 ('a ~=> 'b)" |
|
27 map_upd_s::"('a ~=> 'b) => 'a set => 'b => |
|
28 ('a ~=> 'b)" ("_/'(_{|->}_/')" [900,0,0]900) |
|
29 map_subst::"('a ~=> 'b) => 'b => 'b => |
|
30 ('a ~=> 'b)" ("_/'(_~>_/')" [900,0,0]900) |
|
31 map_le :: "('a ~=> 'b) => ('a ~=> 'b) => bool" (infix "\<subseteq>\<^sub>m" 50) |
25 map_le :: "('a ~=> 'b) => ('a ~=> 'b) => bool" (infix "\<subseteq>\<^sub>m" 50) |
32 |
26 |
33 constdefs |
27 constdefs |
34 map_comp :: "('b ~=> 'c) => ('a ~=> 'b) => ('a ~=> 'c)" (infixl "o'_m" 55) |
28 map_comp :: "('b ~=> 'c) => ('a ~=> 'b) => ('a ~=> 'c)" (infixl "o'_m" 55) |
35 "f o_m g == (\<lambda>k. case g k of None \<Rightarrow> None | Some v \<Rightarrow> f v)" |
29 "f o_m g == (\<lambda>k. case g k of None \<Rightarrow> None | Some v \<Rightarrow> f v)" |
36 |
30 |
|
31 syntax |
|
32 empty :: "'a ~=> 'b" |
|
33 translations |
|
34 "empty" => "%_. None" |
|
35 "empty" <= "%x. None" |
|
36 |
37 nonterminals |
37 nonterminals |
38 maplets maplet |
38 maplets maplet |
39 |
39 |
40 syntax |
40 syntax |
41 empty :: "'a ~=> 'b" |
|
42 "_maplet" :: "['a, 'a] => maplet" ("_ /|->/ _") |
41 "_maplet" :: "['a, 'a] => maplet" ("_ /|->/ _") |
43 "_maplets" :: "['a, 'a] => maplet" ("_ /[|->]/ _") |
42 "_maplets" :: "['a, 'a] => maplet" ("_ /[|->]/ _") |
44 "" :: "maplet => maplets" ("_") |
43 "" :: "maplet => maplets" ("_") |
45 "_Maplets" :: "[maplet, maplets] => maplets" ("_,/ _") |
44 "_Maplets" :: "[maplet, maplets] => maplets" ("_,/ _") |
46 "_MapUpd" :: "['a ~=> 'b, maplets] => 'a ~=> 'b" ("_/'(_')" [900,0]900) |
45 "_MapUpd" :: "['a ~=> 'b, maplets] => 'a ~=> 'b" ("_/'(_')" [900,0]900) |
52 map_comp :: "('b ~=> 'c) => ('a ~=> 'b) => ('a ~=> 'c)" (infixl "\<circ>\<^sub>m" 55) |
51 map_comp :: "('b ~=> 'c) => ('a ~=> 'b) => ('a ~=> 'c)" (infixl "\<circ>\<^sub>m" 55) |
53 |
52 |
54 "_maplet" :: "['a, 'a] => maplet" ("_ /\<mapsto>/ _") |
53 "_maplet" :: "['a, 'a] => maplet" ("_ /\<mapsto>/ _") |
55 "_maplets" :: "['a, 'a] => maplet" ("_ /[\<mapsto>]/ _") |
54 "_maplets" :: "['a, 'a] => maplet" ("_ /[\<mapsto>]/ _") |
56 |
55 |
57 map_upd_s :: "('a ~=> 'b) => 'a set => 'b => ('a ~=> 'b)" |
|
58 ("_/'(_/{\<mapsto>}/_')" [900,0,0]900) |
|
59 map_subst :: "('a ~=> 'b) => 'b => 'b => |
|
60 ('a ~=> 'b)" ("_/'(_\<leadsto>_/')" [900,0,0]900) |
|
61 "@chg_map" :: "('a ~=> 'b) => 'a => ('b => 'b) => ('a ~=> 'b)" |
|
62 ("_/'(_/\<mapsto>\<lambda>_. _')" [900,0,0,0] 900) |
|
63 |
|
64 syntax (latex output) |
56 syntax (latex output) |
65 restrict_map :: "('a ~=> 'b) => 'a set => ('a ~=> 'b)" ("_\<restriction>\<^bsub>_\<^esub>" [111,110] 110) |
57 restrict_map :: "('a ~=> 'b) => 'a set => ('a ~=> 'b)" ("_\<restriction>\<^bsub>_\<^esub>" [111,110] 110) |
66 --"requires amssymb!" |
58 --"requires amssymb!" |
67 |
59 |
68 translations |
60 translations |
69 "empty" => "%_. None" |
|
70 "empty" <= "%x. None" |
|
71 |
|
72 "m(x\<mapsto>\<lambda>y. f)" == "chg_map (\<lambda>y. f) x m" |
|
73 |
|
74 "_MapUpd m (_Maplets xy ms)" == "_MapUpd (_MapUpd m xy) ms" |
61 "_MapUpd m (_Maplets xy ms)" == "_MapUpd (_MapUpd m xy) ms" |
75 "_MapUpd m (_maplet x y)" == "m(x:=Some y)" |
62 "_MapUpd m (_maplet x y)" == "m(x:=Some y)" |
76 "_MapUpd m (_maplets x y)" == "map_upds m x y" |
63 "_MapUpd m (_maplets x y)" == "map_upds m x y" |
77 "_Map ms" == "_MapUpd empty ms" |
64 "_Map ms" == "_MapUpd empty ms" |
78 "_Map (_Maplets ms1 ms2)" <= "_MapUpd (_Map ms1) ms2" |
65 "_Map (_Maplets ms1 ms2)" <= "_MapUpd (_Map ms1) ms2" |
79 "_Maplets ms1 (_Maplets ms2 ms3)" <= "_Maplets (_Maplets ms1 ms2) ms3" |
66 "_Maplets ms1 (_Maplets ms2 ms3)" <= "_Maplets (_Maplets ms1 ms2) ms3" |
80 |
67 |
81 defs |
68 defs |
82 chg_map_def: "chg_map f a m == case m a of None => m | Some b => m(a|->f b)" |
|
83 |
|
84 map_add_def: "m1++m2 == %x. case m2 x of None => m1 x | Some y => Some y" |
69 map_add_def: "m1++m2 == %x. case m2 x of None => m1 x | Some y => Some y" |
85 restrict_map_def: "m|`A == %x. if x : A then m x else None" |
70 restrict_map_def: "m|`A == %x. if x : A then m x else None" |
86 |
71 |
87 map_upds_def: "m(xs [|->] ys) == m ++ map_of (rev(zip xs ys))" |
72 map_upds_def: "m(xs [|->] ys) == m ++ map_of (rev(zip xs ys))" |
88 map_upd_s_def: "m(as{|->}b) == %x. if x : as then Some b else m x" |
|
89 map_subst_def: "m(a~>b) == %x. if m x = Some a then Some b else m x" |
|
90 |
73 |
91 dom_def: "dom(m) == {a. m a ~= None}" |
74 dom_def: "dom(m) == {a. m a ~= None}" |
92 ran_def: "ran(m) == {b. EX a. m a = Some b}" |
75 ran_def: "ran(m) == {b. EX a. m a = Some b}" |
93 |
76 |
94 map_le_def: "m\<^isub>1 \<subseteq>\<^sub>m m\<^isub>2 == ALL a : dom m\<^isub>1. m\<^isub>1 a = m\<^isub>2 a" |
77 map_le_def: "m\<^isub>1 \<subseteq>\<^sub>m m\<^isub>2 == ALL a : dom m\<^isub>1. m\<^isub>1 a = m\<^isub>2 a" |
95 |
78 |
96 primrec |
79 primrec |
97 "map_of [] = empty" |
80 "map_of [] = empty" |
98 "map_of (p#ps) = (map_of ps)(fst p |-> snd p)" |
81 "map_of (p#ps) = (map_of ps)(fst p |-> snd p)" |
99 |
82 |
|
83 (* special purpose constants that should be defined somewhere else and |
|
84 whose syntax is a bit odd as well: |
|
85 |
|
86 "@chg_map" :: "('a ~=> 'b) => 'a => ('b => 'b) => ('a ~=> 'b)" |
|
87 ("_/'(_/\<mapsto>\<lambda>_. _')" [900,0,0,0] 900) |
|
88 "m(x\<mapsto>\<lambda>y. f)" == "chg_map (\<lambda>y. f) x m" |
|
89 |
|
90 map_upd_s::"('a ~=> 'b) => 'a set => 'b => |
|
91 ('a ~=> 'b)" ("_/'(_{|->}_/')" [900,0,0]900) |
|
92 map_subst::"('a ~=> 'b) => 'b => 'b => |
|
93 ('a ~=> 'b)" ("_/'(_~>_/')" [900,0,0]900) |
|
94 |
|
95 map_upd_s_def: "m(as{|->}b) == %x. if x : as then Some b else m x" |
|
96 map_subst_def: "m(a~>b) == %x. if m x = Some a then Some b else m x" |
|
97 |
|
98 map_upd_s :: "('a ~=> 'b) => 'a set => 'b => ('a ~=> 'b)" |
|
99 ("_/'(_/{\<mapsto>}/_')" [900,0,0]900) |
|
100 map_subst :: "('a ~=> 'b) => 'b => 'b => |
|
101 ('a ~=> 'b)" ("_/'(_\<leadsto>_/')" [900,0,0]900) |
|
102 |
|
103 |
|
104 subsection {* @{term [source] map_upd_s} *} |
|
105 |
|
106 lemma map_upd_s_apply [simp]: |
|
107 "(m(as{|->}b)) x = (if x : as then Some b else m x)" |
|
108 by (simp add: map_upd_s_def) |
|
109 |
|
110 lemma map_subst_apply [simp]: |
|
111 "(m(a~>b)) x = (if m x = Some a then Some b else m x)" |
|
112 by (simp add: map_subst_def) |
|
113 |
|
114 *) |
100 |
115 |
101 subsection {* @{term [source] empty} *} |
116 subsection {* @{term [source] empty} *} |
102 |
117 |
103 lemma empty_upd_none[simp]: "empty(x := None) = empty" |
118 lemma empty_upd_none[simp]: "empty(x := None) = empty" |
104 apply (rule ext) |
119 apply (rule ext) |
162 lemma sum_case_map_upd_map_upd[simp]: |
177 lemma sum_case_map_upd_map_upd[simp]: |
163 "sum_case (m1(k1|->y1)) (m2(k2|->y2)) = (sum_case (m1(k1|->y1)) m2)(Inr k2|->y2)" |
178 "sum_case (m1(k1|->y1)) (m2(k2|->y2)) = (sum_case (m1(k1|->y1)) m2)(Inr k2|->y2)" |
164 apply (rule ext) |
179 apply (rule ext) |
165 apply (simp (no_asm) split add: sum.split) |
180 apply (simp (no_asm) split add: sum.split) |
166 done |
181 done |
167 |
|
168 |
|
169 subsection {* @{term [source] chg_map} *} |
|
170 |
|
171 lemma chg_map_new[simp]: "m a = None ==> chg_map f a m = m" |
|
172 by (unfold chg_map_def, auto) |
|
173 |
|
174 lemma chg_map_upd[simp]: "m a = Some b ==> chg_map f a m = m(a|->f b)" |
|
175 by (unfold chg_map_def, auto) |
|
176 |
|
177 lemma chg_map_other [simp]: "a \<noteq> b \<Longrightarrow> chg_map f a m b = m b" |
|
178 by (auto simp: chg_map_def split add: option.split) |
|
179 |
182 |
180 |
183 |
181 subsection {* @{term [source] map_of} *} |
184 subsection {* @{term [source] map_of} *} |
182 |
185 |
183 lemma map_of_eq_None_iff: |
186 lemma map_of_eq_None_iff: |
459 apply(simp add:Diff_insert[symmetric] insert_absorb) |
462 apply(simp add:Diff_insert[symmetric] insert_absorb) |
460 apply(simp add: map_upd_upds_conv_if) |
463 apply(simp add: map_upd_upds_conv_if) |
461 done |
464 done |
462 |
465 |
463 |
466 |
464 subsection {* @{term [source] map_upd_s} *} |
|
465 |
|
466 lemma map_upd_s_apply [simp]: |
|
467 "(m(as{|->}b)) x = (if x : as then Some b else m x)" |
|
468 by (simp add: map_upd_s_def) |
|
469 |
|
470 lemma map_subst_apply [simp]: |
|
471 "(m(a~>b)) x = (if m x = Some a then Some b else m x)" |
|
472 by (simp add: map_subst_def) |
|
473 |
|
474 subsection {* @{term [source] dom} *} |
467 subsection {* @{term [source] dom} *} |
475 |
468 |
476 lemma domI: "m a = Some b ==> a : dom m" |
469 lemma domI: "m a = Some b ==> a : dom m" |
477 by (unfold dom_def, auto) |
470 by (unfold dom_def, auto) |
478 (* declare domI [intro]? *) |
471 (* declare domI [intro]? *) |