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