Zulip Chat Archive

Stream: Is there code for X?

Topic: Showing `((m : Std.HashMap).map f).keys = m.keys`


Dillon Shaffer (Apr 01 2025 at 23:43):

I'm sorry if this is a dumb question but I'm fairly sure that it's a missing theorem in the standard library. I feel like it should be fairly simple but I'm not adept with solving techniques yet and haven't been able to crack it myself.

Eric Wieser (Apr 02 2025 at 00:03):

Is docs#Std.HashMap.keys defined such that the equality is actually true?

Eric Wieser (Apr 02 2025 at 00:04):

It looks like your equation could in principle have the LHS as a permutation of the RHS, rather than as an equality

Dillon Shaffer (Apr 02 2025 at 01:13):

Ha, no the equality is not defined as true but I do want it to be. A permutation would definitely work, then I would only have to figure out how to do transitive membership between an original and updated map.

Dillon Shaffer (Apr 02 2025 at 01:15):

If I understand, the proposition m.keys = (m.map f).keys could be the empty proposition (in which it is untrue) and to enforce truthiness I would need to write (m.keys = (m.map f).keys) = true?

apparently not xd. Now I'm assuming that the empty proposition is a bottom value that can't exist.

Markus Himmel (Apr 02 2025 at 05:27):

There are currently no lemmas for docs#Std.HashMap.map, but there is work in progress on this and full lemma coverage for map, filterMap and filter will (most likely) be part of Lean 4.20.0.

As Eric points out, the two lists will only be equal up to permutation:

import Std

#eval (Std.HashMap.ofList [(0, 0), (16, 0)]).keys -- [16, 0]
#eval ((Std.HashMap.ofList [(0, 0), (16, 0)]).map (fun _ v => v + 1)).keys -- [0, 16]

Johannes Tantow (Apr 17 2025 at 11:47):

The lemma got now merged into the master. In at most a day there should be a nightly available with the results if you need them now. Keep in mind that this nightly version might not be as stable as a release.


Last updated: May 02 2025 at 03:31 UTC