Zulip Chat Archive
Stream: new members
Topic: Prove that inside list.foldl the item is a member of list?
aron (Mar 11 2025 at 15:25):
How can I prove that if I am folding over a list, that the 2nd param in the fold must be a member of the list we're folding over?
I'm trying to do something like list.foldl (fun acc item => ...) init -> item ∈ list
but I don't know how to write a proposition about a parameter of a function about the data structure the function should be called on
Ruben Van de Velde (Mar 11 2025 at 15:31):
Maybe something with List.attach
aron (Mar 11 2025 at 15:57):
Ah nice, yes that's exactly what I needed!
Now is there any way to do the same for a Std.HashMap
?
aron (Mar 11 2025 at 15:57):
hm actually I might have a go at attempting this myself... hopefully it won't be too complicated
Johannes Tantow (Mar 11 2025 at 16:16):
m.toList.attach.foldl
?
aron (Mar 11 2025 at 22:19):
that gets me to k ∈ m.toList
not to k ∈ m
itself
aron (Mar 11 2025 at 23:33):
I figured it out!
import Std.Data.HashMap
open Std
def HashMap.attach {k v : Type u} [DecidableEq k] [Hashable k] (map : HashMap k v) : List {key : k // key ∈ map} := by
have l := map.keys.attach
let l' : List {key : k // key ∈ map} := l.map fun ⟨key, hkey⟩ => ⟨key, HashMap.mem_keys.mp hkey⟩
exact l'
Johannes Tantow (Mar 12 2025 at 05:49):
aron schrieb:
that gets me to
k ∈ m.toList
not tok ∈ m
itself
There shoulld be lemmas simplifying this.
Last updated: May 02 2025 at 03:31 UTC