| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Documentation for the `All` predicate over `List` |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
module README.Data.List.Relation.Unary.All where |
| 8 |
|
| 9 |
open import Data.List.Base using ([]; _∷_) |
| 10 |
open import Data.Nat using (ℕ; s≤s; z≤n; _≤_) |
| 11 |
open import Data.Nat.Properties using (≤-trans; n≤1+n) |
| 12 |
|
| 13 |
------------------------------------------------------------------------ |
| 14 |
-- All |
| 15 |
|
| 16 |
-- The dual to `Any` is the predicate `All` which encodes the idea that |
| 17 |
-- every element in a given list satisfies a given property. |
| 18 |
|
| 19 |
open import Data.List.Relation.Unary.All |
| 20 |
|
| 21 |
-- Proofs for `All` are constructed using exactly the same syntax as |
| 22 |
-- is used to construct lists ("[]" & "_∷_"). For example to prove |
| 23 |
-- that every element in a list is less than or equal to one: |
| 24 |
|
| 25 |
lem₁ : All (_≤ 1) (1 ∷ 0 ∷ 1 ∷ []) |
| 26 |
lem₁ = 1≤1 ∷ 0≤1 ∷ 1≤1 ∷ [] |
| 27 |
where |
| 28 |
0≤1 = z≤n |
| 29 |
1≤1 = s≤s z≤n |
| 30 |
|
| 31 |
-- As with `Any`, the module also provides the standard operators |
| 32 |
-- `map`, `zip` etc. to manipulate proofs for `All`. |
| 33 |
|
| 34 |
import Data.List.Relation.Unary.All as All |
| 35 |
|
| 36 |
lem₂ : All (_≤ 2) (1 ∷ 0 ∷ 1 ∷ []) |
| 37 |
lem₂ = All.map ≤1⇒≤2 lem₁ |
| 38 |
where |
| 39 |
≤1⇒≤2 : ∀ {x} → x ≤ 1 → x ≤ 2 |
| 40 |
≤1⇒≤2 x≤1 = ≤-trans x≤1 (n≤1+n 1) |
| 41 |
|
| 42 |
-- Properties of how list functions interact with `All` can be |
| 43 |
-- found in: |
| 44 |
|
| 45 |
import Data.List.Relation.Unary.All.Properties |