| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Properties of membership for AVL sets |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
open import Relation.Binary.Bundles using (StrictTotalOrder) |
| 10 |
|
| 11 |
module Data.Tree.AVL.Sets.Membership.Properties |
| 12 |
{a ℓ₁ ℓ₂} (strictTotalOrder : StrictTotalOrder a ℓ₁ ℓ₂) |
| 13 |
where |
| 14 |
|
| 15 |
open import Data.Bool.Base using (true; false) |
| 16 |
open import Data.Product.Base as Product using (_,_; proj₁; proj₂) |
| 17 |
open import Data.Sum.Base as Sum using (_⊎_) |
| 18 |
open import Data.Unit.Base using (tt) |
| 19 |
open import Function.Base using (_∘_; _∘′_; const) |
| 20 |
|
| 21 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl) |
| 22 |
open import Relation.Nullary using (¬_; yes; no; Reflects) |
| 23 |
open import Relation.Nullary.Reflects using (fromEquivalence) |
| 24 |
|
| 25 |
open StrictTotalOrder strictTotalOrder renaming (Carrier to A) |
| 26 |
open import Data.Tree.AVL.Sets strictTotalOrder |
| 27 |
open import Data.Tree.AVL.Sets.Membership strictTotalOrder |
| 28 |
open import Data.Tree.AVL.Map.Membership.Propositional strictTotalOrder using (_∈ₖᵥ_) |
| 29 |
import Data.Tree.AVL.Map.Membership.Propositional.Properties strictTotalOrder as Map |
| 30 |
open import Data.Tree.AVL.Map.Relation.Unary.Any strictTotalOrder as Mapₚ |
| 31 |
|
| 32 |
private |
| 33 |
variable |
| 34 |
x y : A |
| 35 |
s : ⟨Set⟩ |
| 36 |
|
| 37 |
∈toMap : x ∈ s → (x , tt) ∈ₖᵥ s |
| 38 |
∈toMap = Mapₚ.map (_, refl) |
| 39 |
|
| 40 |
∈fromMap : (x , tt) ∈ₖᵥ s → x ∈ s |
| 41 |
∈fromMap = Mapₚ.map proj₁ |
| 42 |
|
| 43 |
------------------------------------------------------------------------ |
| 44 |
-- empty |
| 45 |
|
| 46 |
∈-empty : x ∉ empty |
| 47 |
∈-empty = Map.∈ₖᵥ-empty ∘ ∈toMap |
| 48 |
|
| 49 |
------------------------------------------------------------------------ |
| 50 |
-- singleton |
| 51 |
|
| 52 |
∈-singleton⁺ : x ∈ singleton x |
| 53 |
∈-singleton⁺ = ∈fromMap Map.∈ₖᵥ-singleton⁺ |
| 54 |
|
| 55 |
∈-singleton⁻ : x ∈ singleton y → x ≈ y |
| 56 |
∈-singleton⁻ p = proj₁ (Map.∈ₖᵥ-singleton⁻ (∈toMap p)) |
| 57 |
|
| 58 |
------------------------------------------------------------------------ |
| 59 |
-- insert |
| 60 |
|
| 61 |
∈-insert⁺ : x ∈ s → x ∈ insert y s |
| 62 |
∈-insert⁺ {x = x} {s = s} {y = y} x∈s with x ≟ y |
| 63 |
... | yes x≈y = ∈fromMap (Map.∈ₖᵥ-Respectsˡ (Eq.sym x≈y , refl) Map.∈ₖᵥ-insert⁺⁺) |
| 64 |
... | no x≉y = ∈fromMap (Map.∈ₖᵥ-insert⁺ x≉y (∈toMap x∈s)) |
| 65 |
|
| 66 |
∈-insert⁺⁺ : x ∈ insert x s |
| 67 |
∈-insert⁺⁺ = ∈fromMap Map.∈ₖᵥ-insert⁺⁺ |
| 68 |
|
| 69 |
∈-insert⁻ : x ∈ insert y s → x ≈ y ⊎ x ∈ s |
| 70 |
∈-insert⁻ = Sum.map proj₁ (∈fromMap ∘ proj₂) ∘ Map.∈ₖᵥ-insert⁻ ∘ ∈toMap |
| 71 |
|
| 72 |
------------------------------------------------------------------------ |
| 73 |
-- member |
| 74 |
|
| 75 |
∈-member : x ∈ s → member x s ≡ true |
| 76 |
∈-member = Map.∈ₖᵥ-member ∘′ ∈toMap |
| 77 |
|
| 78 |
∉-member : x ∉ s → member x s ≡ false |
| 79 |
∉-member x∉s = Map.∉ₖᵥ-member (const (x∉s ∘ ∈fromMap)) |
| 80 |
|
| 81 |
member-∈ : member x s ≡ true → x ∈ s |
| 82 |
member-∈ = ∈fromMap ∘′ proj₂ ∘′ Map.member-∈ₖᵥ |
| 83 |
|
| 84 |
member-∉ : member x s ≡ false → x ∉ s |
| 85 |
member-∉ p = Map.member-∉ₖᵥ p tt ∘ ∈toMap |
| 86 |
|
| 87 |
member-Reflects-∈ : Reflects (x ∈ s) (member x s) |
| 88 |
member-Reflects-∈ {x = x} {s = s} with member x s in eq |
| 89 |
... | true = Reflects.ofʸ (member-∈ eq) |
| 90 |
... | false = Reflects.ofⁿ (member-∉ eq) |