| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Universal lifting of predicates over Vectors |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 8 |
|
| 9 |
module Data.Vec.Functional.Relation.Unary.All where |
| 10 |
|
| 11 |
open import Data.Fin.Properties using (all?) |
| 12 |
open import Data.Product.Base using (_,_) |
| 13 |
open import Data.Vec.Functional as VF hiding (map) |
| 14 |
open import Level using (Level) |
| 15 |
open import Relation.Unary using (Pred; _⊆_; Decidable; Universal; Satisfiable) |
| 16 |
|
| 17 |
private |
| 18 |
variable |
| 19 |
a p q ℓ : Level |
| 20 |
A : Set a |
| 21 |
|
| 22 |
------------------------------------------------------------------------ |
| 23 |
-- Definition |
| 24 |
|
| 25 |
All : Pred A ℓ → ∀ {n} → Vector A n → Set ℓ |
| 26 |
All P xs = ∀ i → P (xs i) |
| 27 |
|
| 28 |
------------------------------------------------------------------------ |
| 29 |
-- Operations |
| 30 |
|
| 31 |
module _ {P : Pred A p} {Q : Pred A q} where |
| 32 |
|
| 33 |
map : P ⊆ Q → ∀ {n} → All P {n = n} ⊆ All Q |
| 34 |
map p⊆q ps i = p⊆q (ps i) |
| 35 |
|
| 36 |
------------------------------------------------------------------------ |
| 37 |
-- Properties of predicates preserved by All |
| 38 |
|
| 39 |
module _ {P : Pred A p} where |
| 40 |
|
| 41 |
all : Decidable P → ∀ {n} → Decidable (All P {n = n}) |
| 42 |
all p? xs = all? λ i → p? (xs i) |
| 43 |
|
| 44 |
universal : Universal P → ∀ {n} → Universal (All P {n = n}) |
| 45 |
universal uni xs i = uni (xs i) |
| 46 |
|
| 47 |
satisfiable : Satisfiable P → ∀ {n} → Satisfiable (All P {n = n}) |
| 48 |
satisfiable (x , px) = (λ _ → x) , (λ _ → px) |