Commit 2022-01-27 16:51 dd7b052b

View on Github →

feat: union-find data structure (#139) This was surprisingly intricate to get right, considering that the implementation in CLRS is only 11 lines for all the functions in the API put together. All the invariants here are used only to prove that accesses are in bounds and the link function terminates. The fact that (a.set ..).size is not defeq to a.size causes no end of headache. Here I've experimented with a UFModel ghost type, which has simpler defeqs based on Fin n -> A functions instead of lists

Estimated changes

added theorem UFModel.Agrees.empty
added theorem UFModel.Agrees.get_eq'
added theorem UFModel.Agrees.get_eq
added theorem UFModel.Agrees.mk'
added theorem UFModel.Agrees.push
added theorem UFModel.Agrees.set
added theorem UFModel.Agrees.size_eq
added inductive UFModel.Agrees
added theorem UFModel.Models.empty
added theorem UFModel.Models.push
added theorem UFModel.Models.rank_eq
added theorem UFModel.Models.size_eq
added def UFModel.Models
added def UFModel.empty
added def UFModel.push
added structure UFModel
added structure UFNode
added def UnionFind.empty
added def UnionFind.find
added def UnionFind.link
added theorem UnionFind.lt_rankMax'
added theorem UnionFind.lt_rankMax
added theorem UnionFind.model'
added theorem UnionFind.parent_lt
added def UnionFind.push
added def UnionFind.rank
added theorem UnionFind.rank_eq
added theorem UnionFind.rank_lt
added def UnionFind.size
added def UnionFind.union
added structure UnionFind