-
Notifications
You must be signed in to change notification settings - Fork 271
Adds the AVL tree's toList/Any properties #3060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+142
−35
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
262f453
Added AVL Indexed Any toList properties
mikedelorimier 31c731f
updated CHANGELOG.md
mikedelorimier 1e82f4c
Added ListLike. Changed ToList to use ListLike. Changed variable name…
mikedelorimier a74c467
Addressed review comments.
mikedelorimier 56c39ed
refined imports
mikedelorimier 54eca65
Addressed a review comment.
mikedelorimier 37f5035
Addressed review comments
mikedelorimier c6bdc3a
Fixed CHANGELOG.md with most recent changes
mikedelorimier 2eeaa21
[ cleanup ] remove useless import
gallais File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/Data/Tree/AVL/Indexed/Relation/Unary/Any/Properties/ToList.agda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| ------------------------------------------------------------------------ | ||
| -- The Agda standard library | ||
| -- | ||
| -- Properties of toList related to Any | ||
| ------------------------------------------------------------------------ | ||
|
|
||
| {-# OPTIONS --without-K --safe #-} | ||
|
|
||
| open import Relation.Binary.Bundles using (StrictTotalOrder) | ||
|
|
||
| module Data.Tree.AVL.Indexed.Relation.Unary.Any.Properties.ToList | ||
| {a ℓ₁ ℓ₂} (sto : StrictTotalOrder a ℓ₁ ℓ₂) | ||
| where | ||
|
|
||
| open import Data.DifferenceList.Base using (_∷_) | ||
| open import Data.DifferenceList.Properties | ||
| using (ListLike; []⁺; ∷⁺; ++⁺; toList-++) | ||
| import Data.List.Base as List | ||
| import Data.List.Relation.Unary.Any as List | ||
| import Data.List.Relation.Unary.Any.Properties as List | ||
| open import Data.Nat.Base using (ℕ) | ||
| open import Data.Product.Base using (_,_) | ||
| open import Data.Sum.Base using (_⊎_; inj₁; inj₂) | ||
| open import Level using (Level) | ||
| open import Relation.Binary.PropositionalEquality.Core | ||
| using (_≡_; subst; sym) | ||
| open import Relation.Unary using (Pred) | ||
|
|
||
| open import Data.Tree.AVL.Indexed sto | ||
| open import Data.Tree.AVL.Indexed.Relation.Unary.Any sto | ||
| using (Any; here; left; right) | ||
|
|
||
| private | ||
| variable | ||
| v p : Level | ||
| V : Value v | ||
| P : Pred (K& V) p | ||
| l u : Key⁺ | ||
| hˡ hʳ h : ℕ | ||
| t : Tree V l u h | ||
|
|
||
|
|
||
| listLike : (t : Tree V l u h) → ListLike (toDiffList t) | ||
| listLike (leaf l<u) = List.[] , []⁺ | ||
| listLike (node k l r bal) | ||
| with (ls , ls∼dls) ← listLike l | ||
| with (rs , rs∼drs) ← listLike r | ||
| = ls List.++ k List.∷ rs , (++⁺ ls∼dls (∷⁺ k rs∼drs)) | ||
|
|
||
| ++≡node : (kv : K& V) → | ||
| (lk : Tree V l [ kv .key ] hˡ) → | ||
| (ku : Tree V [ kv .key ] u hʳ) → | ||
| (bal : hˡ ∼ hʳ ⊔ h) → | ||
| toList lk List.++ kv List.∷ toList ku ≡ | ||
| toList (node kv lk ku bal) | ||
| ++≡node kv lk ku _ = | ||
| toList-++ (listLike lk) (kv ∷ toDiffList ku) | ||
|
|
||
| toList⁺ : Any P t → List.Any P (toList t) | ||
| toList⁺-node : {kv : K& V} → | ||
| {lk : Tree V l [ kv .key ] hˡ} → | ||
| {ku : Tree V [ kv .key ] u hʳ} → | ||
| {bal : hˡ ∼ hʳ ⊔ h} → | ||
| Any P (node kv lk ku bal) → | ||
| List.Any P (toList lk List.++ kv List.∷ toList ku) | ||
| toList⁺ {P = P} {t = node kv lk ku bal} p = | ||
| subst (List.Any P) (++≡node kv lk ku bal) (toList⁺-node p) | ||
| toList⁺-node {lk = lk} (here p) = | ||
| List.++⁺ʳ (toList lk) (List.here p) | ||
| toList⁺-node (left p) = | ||
| List.++⁺ˡ (toList⁺ p) | ||
| toList⁺-node {lk = lk} (right p) = | ||
| List.++⁺ʳ (toList lk) (List.there (toList⁺ p)) | ||
|
|
||
| toList⁻ : List.Any P (toList t) → Any P t | ||
| toList⁻-node : {kv : K& V} → | ||
| {lk : Tree V l [ kv .key ] hˡ} → | ||
| {ku : Tree V [ kv .key ] u hʳ} → | ||
| {bal : hˡ ∼ hʳ ⊔ h} → | ||
| List.Any P (toList lk) ⊎ List.Any P (kv List.∷ toList ku) → | ||
| Any P (node kv lk ku bal) | ||
| toList⁻ {P = P} {t = node kv lk ku bal} p = | ||
| toList⁻-node | ||
| (List.++⁻ (toList lk) | ||
| (subst (List.Any P) (sym (++≡node kv lk ku bal)) p)) | ||
| toList⁻-node (inj₁ p) = left (toList⁻ p) | ||
| toList⁻-node (inj₂ (List.here p)) = here p | ||
| toList⁻-node (inj₂ (List.there p)) = right (toList⁻ p) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.