| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Existential lifting of predicates over Vectors |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Vec.Functional.Relation.Unary.Any where |
| 10 |
|
| 11 |
open import Data.Fin.Base using (zero; suc) |
| 12 |
open import Data.Fin.Properties using (any?) |
| 13 |
open import Data.Nat.Base using (ℕ) |
| 14 |
open import Data.Product.Base as Σ using (Σ; ∃; _×_; _,_; proj₁; proj₂) |
| 15 |
open import Data.Vec.Functional as VF hiding (map) |
| 16 |
open import Function.Base using (id) |
| 17 |
open import Level using (Level) |
| 18 |
open import Relation.Unary using (Pred; _⊆_; Decidable) |
| 19 |
|
| 20 |
private |
| 21 |
variable |
| 22 |
a b p q ℓ : Level |
| 23 |
A : Set a |
| 24 |
B : Set b |
| 25 |
|
| 26 |
------------------------------------------------------------------------ |
| 27 |
-- Definition |
| 28 |
|
| 29 |
Any : Pred A ℓ → ∀ {n} → Vector A n → Set ℓ |
| 30 |
Any P xs = ∃ λ i → P (xs i) |
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- Operations |
| 34 |
|
| 35 |
module _ {P : Pred A p} where |
| 36 |
|
| 37 |
here : ∀ {x n} {v : Vector A n} → P x → Any P (x ∷ v) |
| 38 |
here px = zero , px |
| 39 |
|
| 40 |
there : ∀ {x n} {v : Vector A n} → Any P v → Any P (x ∷ v) |
| 41 |
there = Σ.map suc id |
| 42 |
|
| 43 |
module _ {P : Pred A p} {Q : Pred A q} where |
| 44 |
|
| 45 |
map : P ⊆ Q → ∀ {n} → Any P {n = n} ⊆ Any Q |
| 46 |
map p⊆q = Σ.map id p⊆q |
| 47 |
|
| 48 |
------------------------------------------------------------------------ |
| 49 |
-- Properties of predicates preserved by Any |
| 50 |
|
| 51 |
module _ {P : Pred A p} where |
| 52 |
|
| 53 |
any : Decidable P → ∀ {n} → Decidable (Any P {n = n}) |
| 54 |
any p? xs = any? λ i → p? (xs i) |