Skip to content

Commit bc975b3

Browse files
Add properties that characterize Data.Tree.AVL.Indexed.delete. (#2961)
* Add properties that characterize `Data.Tree.AVL.Indexed.delete`. 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. * telescoped arguments in Singleton.agda * removed unused vars, merged cases using Any.toSum for JoinConstFuns.agda * addressed review comments on Join.agda * addressed comments in Insert.agda * addressed review comments for HeadTail.agda * addressed review comments for Delete.agda * Moved Data.Tree.AVL.Indexed.Relation.Unary.Any.* into Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.* * Simplified proofs by removing subterms that recapitulate the subject function. * Changed whitespace to align matches. * More alignment. * addressed review comments to use var in let and moved implicits to variable block * Recorded changes in CHANGELOG.md. Addressed review comments for AnyLookup. * Apply suggestion from @jamesmckinna Cosmetic tweak to text --------- Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
1 parent 82b007f commit bc975b3

11 files changed

Lines changed: 1091 additions & 405 deletions

File tree

CHANGELOG.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ Minor improvements
6767
`refl`, `sym`, and `trans` have been weakened to allow relations of different
6868
levels to be used.
6969

70+
* Due to becoming large, `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties`
71+
has been split into small modules
72+
`Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.*`
73+
that are reexported by the original `Properties`.
74+
7075
Deprecated modules
7176
------------------
7277

@@ -171,6 +176,19 @@ New modules
171176
Data.List.NonEmpty.Membership.Setoid
172177
```
173178

179+
* Refactoring of `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties` as smaller modules:
180+
```
181+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Lookup
182+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Cast
183+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Delete
184+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.HeadTail
185+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Insert
186+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.JoinConstFuns
187+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Join
188+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.LookupFun
189+
Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Singleton
190+
```
191+
174192
* `Relation.Binary.Morphism.Construct.On`: given a relation `_∼_` on `B`,
175193
and a function `f : A → B`, construct the canonical `IsRelMonomorphism`
176194
between `_∼_ on f` and `_∼_`, witnessed by `f` itself.
@@ -397,6 +415,87 @@ Additions to existing modules
397415
showAtPrecision : ℕ → ℚᵘ → String
398416
```
399417

418+
* In `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Cast`:
419+
```agda
420+
castʳ⁺ : Any P lm → Any P (castʳ lm m<u)
421+
castʳ⁻ : Any P (castʳ lm m<u) → Any P lm
422+
```
423+
424+
* In `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.Delete`:
425+
```agda
426+
delete⁺ : (t : Tree V l u h) (seg : l < k < u) →
427+
(p : Any P t) → lookupKey p ≉ k →
428+
Any P (proj₂ (delete k t seg))
429+
delete-tree⁻ : (t : Tree V l u h) (seg : l < k < u) →
430+
Any P (proj₂ (delete k t seg)) →
431+
Any P t
432+
delete-key-∈⁻ : (t : Tree V l u h) (seg : l < k < u) →
433+
{kp : Key} →
434+
Any ((kp ≈_) ∘′ key) (proj₂ (delete k t seg)) →
435+
kp ≉ k
436+
delete-key⁻ : (t : Tree V l u h) (seg : l < k < u) →
437+
(p : Any P (proj₂ (delete k t seg))) →
438+
Any.lookupKey p ≉ k
439+
```
440+
441+
* In `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.HeadTail`:
442+
```
443+
headTail⁺ : (t : Tree V l u (1 + h)) →
444+
let kv , _ , _ , t⁻ = headTail t in
445+
Any P t → P kv ⊎ Any P t⁻
446+
headTail-head⁻ : (t : Tree V l u (suc h)) →
447+
P (proj₁ (headTail t)) → Any P t
448+
headTail-tail⁻ : (t : Tree V l u (1 + h)) →
449+
let _ , _ , _ , t⁻ = headTail t in
450+
Any P t⁻ → Any P t
451+
```
452+
453+
* In `Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.JoinConstFuns`:
454+
```
455+
joinˡ⁻-here⁺ : (kv : K& V) →
456+
(l : ∃ λ i → Tree V l [ kv .key ] pred[ i ⊕ hˡ ]) →
457+
(r : Tree V [ kv .key ] u hʳ) →
458+
(bal : hˡ ∼ hʳ ⊔ h) →
459+
P kv → Any P (proj₂ (joinˡ⁻ hˡ kv l r bal))
460+
joinˡ⁻-left⁺ : (kv : K& V) →
461+
(l : ∃ λ i → Tree V l [ kv .key ] pred[ i ⊕ hˡ ]) →
462+
(r : Tree V [ kv .key ] u hʳ) →
463+
(bal : hˡ ∼ hʳ ⊔ h) →
464+
Any P (proj₂ l) → Any P (proj₂ (joinˡ⁻ hˡ kv l r bal))
465+
joinˡ⁻-right⁺ : (kv : K& V) →
466+
(l : ∃ λ i → Tree V l [ kv .key ] pred[ i ⊕ hˡ ]) →
467+
(r : Tree V [ kv .key ] u hʳ) →
468+
(bal : hˡ ∼ hʳ ⊔ h) →
469+
Any P r → Any P (proj₂ (joinˡ⁻ hˡ kv l r bal))
470+
joinˡ⁻⁻ : (kv : K& V) →
471+
(l : ∃ λ i → Tree V l [ kv .key ] pred[ i ⊕ hˡ ]) →
472+
(r : Tree V [ kv .key ] u hʳ) →
473+
(bal : hˡ ∼ hʳ ⊔ h) →
474+
Any P (proj₂ (joinˡ⁻ hˡ kv l r bal)) →
475+
P kv ⊎ Any P (proj₂ l) ⊎ Any P r
476+
joinʳ⁻-here⁺ : (kv : K& V) →
477+
(l : Tree V l [ kv .key ] hˡ) →
478+
(r : ∃ λ i → Tree V [ kv .key ] u pred[ i ⊕ hʳ ]) →
479+
(bal : hˡ ∼ hʳ ⊔ h) →
480+
P kv → Any P (proj₂ (joinʳ⁻ hʳ kv l r bal))
481+
joinʳ⁻-left⁺ : (kv : K& V) →
482+
(l : Tree V l [ kv .key ] hˡ) →
483+
(r : ∃ λ i → Tree V [ kv .key ] u pred[ i ⊕ hʳ ]) →
484+
(bal : hˡ ∼ hʳ ⊔ h) →
485+
Any P l → Any P (proj₂ (joinʳ⁻ hʳ kv l r bal))
486+
joinʳ⁻-right⁺ : (kv : K& V) →
487+
(l : Tree V l [ kv .key ] hˡ) →
488+
(r : ∃ λ i → Tree V [ kv .key ] u pred[ i ⊕ hʳ ]) →
489+
(bal : hˡ ∼ hʳ ⊔ h) →
490+
Any P (proj₂ r) → Any P (proj₂ (joinʳ⁻ hʳ kv l r bal))
491+
joinʳ⁻⁻ : (kv : K& V) →
492+
(l : Tree V l [ kv .key ] hˡ) →
493+
(r : ∃ λ i → Tree V [ kv .key ] u pred[ i ⊕ hʳ ]) →
494+
(bal : hˡ ∼ hʳ ⊔ h) →
495+
Any P (proj₂ (joinʳ⁻ hʳ kv l r bal)) →
496+
P kv ⊎ Any P l ⊎ Any P (proj₂ r)
497+
```
498+
400499
* In `Data.Vec.Properties`:
401500
```agda
402501
map-removeAt : ∀ (f : A → B) (xs : Vec A (suc n)) (i : Fin (suc n)) →

0 commit comments

Comments
 (0)