| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Documentation for pointwise lifting of relations over `List`s |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
module README.Data.List.Relation.Binary.Pointwise where |
| 8 |
|
| 9 |
open import Data.Nat using (ℕ; _<_; s≤s; z≤n) |
| 10 |
open import Data.List.Base using (List; []; _∷_; length) |
| 11 |
open import Relation.Binary.PropositionalEquality |
| 12 |
using (_≡_; refl; sym; cong; setoid) |
| 13 |
open import Relation.Nullary.Negation using (¬_) |
| 14 |
|
| 15 |
------------------------------------------------------------------------ |
| 16 |
-- Pointwise |
| 17 |
|
| 18 |
-- One of the most basic ways to form a binary relation between two |
| 19 |
-- lists of type `List A`, given a binary relation over `A`, is to say |
| 20 |
-- that two lists are related if they are the same length and: |
| 21 |
-- i) the first elements in the lists are related |
| 22 |
-- ii) the second elements in the lists are related |
| 23 |
-- iii) the third elements in the lists are related etc. |
| 24 |
-- etc. |
| 25 |
-- |
| 26 |
-- A formalisation of this "pointwise" lifting of a relation to lists |
| 27 |
-- is found in: |
| 28 |
|
| 29 |
open import Data.List.Relation.Binary.Pointwise |
| 30 |
|
| 31 |
-- The same syntax to construct a list (`[]` & `_∷_`) is used to |
| 32 |
-- construct proofs for the `Pointwise` relation. For example if you |
| 33 |
-- want to prove that one list is strictly less than another list: |
| 34 |
|
| 35 |
lem₁ : Pointwise _<_ (0 ∷ 2 ∷ 1 ∷ []) (1 ∷ 4 ∷ 2 ∷ []) |
| 36 |
lem₁ = 0<1 ∷ 2<4 ∷ 1<2 ∷ [] |
| 37 |
where |
| 38 |
0<1 = s≤s z≤n |
| 39 |
2<4 = s≤s (s≤s (s≤s z≤n)) |
| 40 |
1<2 = s≤s 0<1 |
| 41 |
|
| 42 |
-- Lists that are related by `Pointwise` must be of the same length. |
| 43 |
-- For example: |
| 44 |
|
| 45 |
lem₂ : ¬ Pointwise _<_ (0 ∷ 2 ∷ []) (1 ∷ []) |
| 46 |
lem₂ (0<1 ∷ ()) |
| 47 |
|
| 48 |
-- Proofs about pointwise, including that of the above fact are |
| 49 |
-- also included in the module: |
| 50 |
|
| 51 |
lem₃ : ∀ {xs ys} → Pointwise _<_ xs ys → length xs ≡ length ys |
| 52 |
lem₃ = Pointwise-length |