Add function `map_kmap` that transforms the keys of a finite map.
This function map_kmap f
allows one to turn maps with keys K1
(e.g., gmap K1 A
) into maps with keys K2
(e.g., gmap K2 A
), where f : K1 → K2
.
Notes:
- The function
f
should be injective, otherwisemap_kmap f
is ill-behaved. Considermap_kmap (λ _, 0) {[ 0 := 10, 1 := 20 ]}
. What's the result of that? Well, that depends on how the map is exactly represented (forgmap
that depends on how exactly theCountable
instances are defined). - There are tons of generalizations of this function possible, e.g., with functions
f
that go tooption K2
so that elements can be dropped, etc (similar toomap
versusfmap
), or that could also take the values into account (similar toimap
versusfmap
). I think the version in this MR is useful because it enjoys nice lemmas. Maybe in the future we could define a generic version and define the one in this MR in terms of a more generic version. - Some of the lemmas hold without
Inj
(e.g.lookup_map_kmap_None
). I don't think there's a point in doing that because then I can no longer use the generic lemmas aboutlist_to_map
, alsomap_kmap f
wheref
is not injective is ill-behaved (as previously stated).
Thanks @jules for the suggestion and feedback.