strengthen the AVL tree's insertWith-just - #3087
Conversation
|
Two quick comments ahead of any proper review:
Simpler, perhaps: if we bind
|
Oh right, here's the thread where you suggested I'll give an example data structure where This is a dictionary that's implemented by logging to a list (i.e. assoc-list with repeats). The following example shows repeated
Here, Because of Consider |
Thanks for point this out. I learned this at one point but forgot. |
|
Thanks for the very detailed explanation. I think on this basis we could argue that the earlier implementation of |
This PR adds
insertWith-just-updateto strengthen the existinginsertWith-justinData.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Insert.The subject of this property is the op
insertWith k f t l<k<u, wherekis the key inserted, andf : Maybe (Val k) → Val kis applied tojust vwhen(k , v)is already int.So
insertWith-justis the "insertWith⁺" for the case wherekis already int.But the preexisting
insertWith-justignores whichvwas already intand requiresPto hold for anyv.One of the main tests for
insertWith-justis whether it can be used to prove the simple membership property:insertWith-just-updatestrengthensinsertWith-justso it can be used to prove this property.Compare this to
insert-just, which can be used to prove the analogous property:The exact comparision of the new and old properties:
You can see here that the old
prhas to hold for arbitraryv.The new
pris weakened with the assumptionP (k′ , v).The one place where
insertWith-justwas used was forinsert-just, which happens to replace and ignore the oldv.Note that the changing
insertWith-justtoinsertWith-just-updatemostly preserved the proof, simplifying it slightly.The following are some design decisions I took for the initial attempt at this PR:
My reason for the
-updatesuffix is the new property is relevant whenfactually updates the oldv.insertWith-justis deprecated.At some point another deprecation phase would replace the name
insertWith-just-updatewithinsertWith-just.For reference,
Data.Vec.Properties.∷.ʳ++-eqFreeis another deprecated name that nontrivially depends on its replacement.I kept the new
insertWith-justin its module nest so the order of implicit variables wouldn't change.Now
insertWith-justcallsinsertWith-just-updateandinsert-justcallsinsertWith-just-updateinstead ofinsertWith-just.Note that the
Qvariable I added has levelq, which is different thanP's level.This seems right, but it is different from
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Lookup'sQ, which has levelp.