|
| 1 | +------------------------------------------------------------------------ |
| 2 | +-- The Agda standard library |
| 3 | +-- |
| 4 | +-- Properties of lists which contain every element of a given type |
| 5 | +------------------------------------------------------------------------ |
| 6 | + |
| 7 | +{-# OPTIONS --without-K --safe #-} |
| 8 | + |
| 9 | +open import Data.Fin hiding (_≟_) |
| 10 | +open import Data.List.Base |
| 11 | +open import Data.List.Membership.Setoid.Properties as Membership |
| 12 | +open import Data.List.Relation.Unary.Any using (index) |
| 13 | +open import Data.List.Relation.Unary.Any.Properties using (lookup-index) |
| 14 | +open import Data.List.Relation.Unary.Complete.Setoid |
| 15 | +open import Data.Sum using (inj₁; inj₂) |
| 16 | +open import Data.Sum.Relation.Binary.Pointwise |
| 17 | + using (_⊎ₛ_; inj₁; inj₂) |
| 18 | +open import Data.Product using (_,_; proj₁; proj₂) |
| 19 | +open import Data.Product.Relation.Binary.Pointwise.NonDependent |
| 20 | + using (_×ₛ_) |
| 21 | +open import Function |
| 22 | +open import Level |
| 23 | +open import Relation.Binary |
| 24 | +open import Relation.Binary.PropositionalEquality using (_≡_) |
| 25 | +open import Relation.Binary.Properties.Setoid using (respʳ-flip) |
| 26 | + |
| 27 | +module Data.List.Relation.Unary.Complete.Setoid.Properties where |
| 28 | + |
| 29 | +open Setoid |
| 30 | + |
| 31 | +private |
| 32 | + variable |
| 33 | + a b ℓ₁ ℓ₂ : Level |
| 34 | + |
| 35 | +------------------------------------------------------------------------ |
| 36 | +-- map |
| 37 | + |
| 38 | +module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) |
| 39 | + {f} (surj : IsSurjection (_≈_ S) (_≈_ T) f) |
| 40 | + where |
| 41 | + open IsSurjection surj |
| 42 | + |
| 43 | + map⁺ : ∀ {xs} → Complete S xs → Complete T (map f xs) |
| 44 | + map⁺ _∈xs y with surjective y |
| 45 | + ... | (x , fx≈y) = ∈-resp-≈ T fx≈y (∈-map⁺ S T cong (x ∈xs)) |
| 46 | + |
| 47 | +------------------------------------------------------------------------ |
| 48 | +-- _++_ |
| 49 | + |
| 50 | +module _ (S : Setoid a ℓ₁) where |
| 51 | + |
| 52 | + ++⁺ˡ : ∀ {xs} ys → Complete S xs → Complete S (xs ++ ys) |
| 53 | + ++⁺ˡ _ _∈xs v = Membership.∈-++⁺ˡ S (v ∈xs) |
| 54 | + |
| 55 | + ++⁺ʳ : ∀ xs {ys} → Complete S ys → Complete S (xs ++ ys) |
| 56 | + ++⁺ʳ _ _∈ys v = Membership.∈-++⁺ʳ S _ (v ∈ys) |
| 57 | + |
| 58 | +module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where |
| 59 | + |
| 60 | + ++⁺ : ∀ {xs ys} → Complete S xs → Complete T ys → |
| 61 | + Complete (S ⊎ₛ T) (map inj₁ xs ++ map inj₂ ys) |
| 62 | + ++⁺ _∈xs _ (inj₁ x) = ∈-++⁺ˡ (S ⊎ₛ T) (∈-map⁺ S (S ⊎ₛ T) inj₁ (x ∈xs)) |
| 63 | + ++⁺ _ _∈ys (inj₂ y) = ∈-++⁺ʳ (S ⊎ₛ T) _ (∈-map⁺ T (S ⊎ₛ T) inj₂ (y ∈ys)) |
| 64 | + |
| 65 | +------------------------------------------------------------------------ |
| 66 | +-- cartesianProduct |
| 67 | + |
| 68 | +module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where |
| 69 | + |
| 70 | + cartesianProduct⁺ : ∀ {xs ys} → Complete S xs → Complete T ys → |
| 71 | + Complete (S ×ₛ T) (cartesianProduct xs ys) |
| 72 | + cartesianProduct⁺ _∈xs _∈ys (x , y) = ∈-cartesianProduct⁺ S T (x ∈xs) (y ∈ys) |
| 73 | + |
| 74 | +------------------------------------------------------------------------ |
| 75 | +-- deduplicate |
| 76 | + |
| 77 | +module _ (S? : DecSetoid a ℓ₁) where |
| 78 | + open DecSetoid S? renaming (setoid to S) |
| 79 | + |
| 80 | + deduplicate⁺ : ∀ {xs} → Complete S xs → Complete S (deduplicate _≟_ xs) |
| 81 | + deduplicate⁺ = ∈-deduplicate⁺ S _≟_ (respʳ-flip S) ∘_ |
| 82 | + |
| 83 | +------------------------------------------------------------------------ |
| 84 | +-- lookup |
| 85 | + |
| 86 | +module _ (S : Setoid a ℓ₁) where |
| 87 | + |
| 88 | + lookup-surjective : ∀ {xs} → Complete S xs → |
| 89 | + Surjective {A = Fin (length xs)} _≡_ (_≈_ S) (lookup xs) |
| 90 | + lookup-surjective _∈xs y = index (y ∈xs) , sym S (lookup-index (y ∈xs)) |
0 commit comments