leanprover / leanprover/lean4

Add getElem?_mergeWith lemma for TreeMap/DTreeMap

Open
#11,807 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lean
Stars
9.2k
Forks
990
Avg merge
1d 17h
Merged PRs (30d)
175

Description

Summary

TreeMap and DTreeMap are missing a semantic lemma for mergeWith that specifies the behavior of getElem? after merging.

Proposed Lemma

@[simp] theorem getElem?_mergeWith [TransCmp cmp] [LawfulEqCmp cmp] 
    {t₁ t₂ : TreeMap α β cmp} {f : α → β → β → β} {k : α} :
    (t₁.mergeWith f t₂)[k]? =
      match t₁[k]?, t₂[k]? with
      | some v1, some v2 => some (f k v1 v2)
      | some v1, none => some v1
      | none, some v2 => some v2
      | none, none => none

Motivation

This lemma is needed for proving properties about maps used as heaps in separation logic (specifically for the Iris proof mode in Lean). Currently, users must prove this from scratch using internal implementation details.

The existing mergeWith lemmas only cover congruence for the ~m equivalence relation, not semantic behavior.

Implementation Notes

A proof exists in https://github.com/alok/iris-lean/blob/feat/heap-instances-105/src/Iris/Std/HeapInstances.lean using:

  • foldl_alter_getElem? helper lemma
  • Connection through internal Impl.Const.mergeWith!
  • Case analysis on membership in both trees

The lemma should ideally be added at all levels: DTreeMap.Internal, DTreeMap, TreeMap, and ExtTreeMap.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing mergeWith lemmas and the foldl_alter_getElem? helper, then trace the connection through Impl.Const.mergeWith!. Use the proof in Iris/Std/HeapInstances.lean as a reference and handle membership in both trees across DTreeMap.Internal, DTreeMap, TreeMap, and ExtTreeMap. Done means the proposed semantic getElem? lemma is available at all listed levels.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.