Skip to content

Add properties that characterize Data.Tree.AVL.Indexed.delete.#2961

Open
mikedelorimier wants to merge 1 commit intoagda:masterfrom
mikedelorimier:delete-multi
Open

Add properties that characterize Data.Tree.AVL.Indexed.delete.#2961
mikedelorimier wants to merge 1 commit intoagda:masterfrom
mikedelorimier:delete-multi

Conversation

@mikedelorimier
Copy link

These are properties for the core delete on AVL trees and are similar to the preexisting properties of insert.

Lemmas added for delete are delete⁺, delete-tree⁻, delete-key-∈⁻ and delete-key⁻. Together these can be used to prove (k′ ∈ delete k t) ⇔ (k′ ≉ k × k′ ∈ t), which fully characterizes delete.

delete⁺, delete-tree⁻, and delete-key⁻ correspond to Coq.FSets.FSetInterface's remove_2, remove_3, and remove_1, respectively.

Just like other lemmas in Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties, delete⁺, delete-tree⁻, delete-key⁻ generalize k′ ∈ t to Any P t. delete-key-∈⁻ is essentally a helper for delete-key⁻, which would be difficult to prove directly.

Many more lemmas were added for AVL functions that delete depends on. These additional lemmas characterize the functions castʳ, joinˡ⁺, joinʳ⁺, joinˡ⁻, joinʳ⁻, headTail, and join. Adding all this code to Properties.agda caused make test to overflow past the 4096 MB default heap size. This was solved by breaking Properties.agda into multiple files, with roughly one file for each AVL function.

Added proofs are a similar style the preexisting proofs in Properties.agda.

These are properties for the core delete on AVL trees and similar to the prexisting properties of `insert`.

Lemmas added for `delete` are `delete⁺`, `delete-tree⁻`, `delete-key-∈⁻` and `delete-key⁻`.
Together these can be used to prove `(k′ ∈ delete k t) ⇔ (k′ ≉ k × k′ ∈ t)`, which fully characterizes `delete`.

`delete⁺`, `delete-tree⁻`, and `delete-key⁻` correspond to Coq.FSets.FSetInterface's `remove_2`, `remove_3`, and `remove_1`, respectively.

Just like other lemmas in this file, `delete⁺`, `delete-tree⁻`, `delete-key⁻` generalize `k′ ∈ t` to `Any P t`.
`delete-key-∈⁻` is essentally a helper for `delete-key⁻`, which would be difficult to prove directly.

Many more lemmas were added for AVL functions that `delete` depends on.
These additional lemmas characterize the functions `castʳ`, `joinˡ⁺`, `joinʳ⁺`, `joinˡ⁻`, `joinʳ⁻`, `headTail`, and `join`.
Adding all this code to Properties.agda caused `make test` to overflow past the 4096 MB default heap size.
This was solved by breaking Properties.agda into multiple files, with roughly one file for each AVL function.

Added proofs are a similar style the preexisting proofs in Properties.agda.
Copy link
Collaborator

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic work. But a few things may need tweaked.


castʳ⁻ : {l m u h} {lm : Tree V l m h} {m<u : m <⁺ u}
Any P (castʳ lm m<u) Any P lm
castʳ⁻ {lm = node _ _ _ _} (here p) = here p
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to 'force' ln to a node for this to work?

(p : Any P t) lookupKey p ≉ k
Any P (proj₂ (delete k t seg))
delete⁺ (leaf _) _ p _ = p
delete⁺ (node (k′ , v) lk′ k′u bal) (l<k , k<u) p p≉k
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you uniformly do with on both compare and p, I recommend that you do both of them at once.

Any P t₁ Any P (proj₂ (join t₁ t₂ bal))
join-left⁺ _ (leaf _) ∼- p = castʳ⁺ p
join-left⁺ {hʳ = suc _} t₁ t₂₃@(node _ _ _ _) bal p
with headTail t₂₃
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

irrefutable with ?

(r : Tree V [ kv .key ] u hʳ)
(bal : hˡ ∼ hʳ ⊔ h)
P kv Any P (proj₂ (joinˡ⁺ kv l r bal))
joinˡ⁺-here⁺ k₂ (0# , t₁) t₃ bal p = here p
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For further clarify, don't bother naming all the things you don't use in the rhs.

joinˡ⁺-here⁺ k₄ (1# , node k₂ t₁ t₃ ∼0) t₅ ∼- p = right (here p)
joinˡ⁺-here⁺ k₆ (1# , node⁺ k₂ t₁ k₄ t₃ t₅ bal) t₇ ∼- p = right (here p)

joinˡ⁺-left⁺ : {l u hˡ hʳ h}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment throughout this file: don't name unused arguments.

joinˡ⁺⁻ k₂ (0# , t₁) t₃ ba = Any.toSum
joinˡ⁺⁻ k₂ (1# , t₁) t₃ ∼0 = Any.toSum
joinˡ⁺⁻ k₂ (1# , t₁) t₃ ∼+ = Any.toSum
joinˡ⁺⁻ k₄ (1# , node k₂ t₁ t₃ ∼-) t₅ ∼- = λ where
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sub-function is used twice -- name it?

joinʳ⁺-here⁺ k₂ t₁ (0# , t₃) bal p = here p
joinʳ⁺-here⁺ k₂ t₁ (1# , t₃) ∼0 p = here p
joinʳ⁺-here⁺ k₂ t₁ (1# , t₃) ∼- p = here p
joinʳ⁺-here⁺ k₂ t₁ (1# , node k₄ t₃ t₅ ∼+) ∼+ p = left (here p)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do these 2 cases need to be separate?

joinʳ⁺-left⁺ k₂ t₁ (0# , t₃) bal p = left p
joinʳ⁺-left⁺ k₂ t₁ (1# , t₃) ∼0 p = left p
joinʳ⁺-left⁺ k₂ t₁ (1# , t₃) ∼- p = left p
joinʳ⁺-left⁺ k₂ t₁ (1# , node k₄ t₃ t₅ ∼+) ∼+ p = left (left p)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here: merge those 2 cases?

private
Val = Value.family V

singleton⁺ : {P : Pred (K& V) p}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the next two functions, should some of the arguments be implicit?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants