Debian Codegraph @

src/Data/List/Relation/Binary/Pointwise/Properties.agda

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of pointwise lifting of relations to lists
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.List.Relation.Binary.Pointwise.Properties where
10
11 open import Data.Nat.Base using (ℕ)
12 open import Data.Fin.Base using (zero; suc; cast)
13 open import Data.Product.Base using (_,_; uncurry)
14 open import Data.List.Base using (List; []; _∷_; length; lookup)
15 open import Level
16 open import Relation.Binary.Core using (REL; _⇒_)
17 open import Relation.Binary.Definitions
18 open import Relation.Binary.PropositionalEquality.Core as ≡ using (_≡_)
19 open import Relation.Nullary using (yes; no; _×-dec_)
20 import Relation.Nullary.Decidable as Dec
21
22 open import Data.List.Relation.Binary.Pointwise.Base
23
24 private
25 variable
26 a b ℓ : Level
27 A : Set a
28 B : Set b
29 R S T : REL A B ℓ
30
31 ------------------------------------------------------------------------
32 -- Relational properties
33 ------------------------------------------------------------------------
34
35 reflexive : R ⇒ S → Pointwise R ⇒ Pointwise S
36 reflexive = map
37
38 refl : Reflexive R → Reflexive (Pointwise R)
39 refl rfl {[]} = []
40 refl rfl {x ∷ xs} = rfl ∷ refl rfl
41
42 symmetric : Sym R S → Sym (Pointwise R) (Pointwise S)
43 symmetric sym [] = []
44 symmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys
45
46 transitive : Trans R S T →
47 Trans (Pointwise R) (Pointwise S) (Pointwise T)
48 transitive trans [] [] = []
49 transitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
50 trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs
51
52 antisymmetric : Antisym R S T →
53 Antisym (Pointwise R) (Pointwise S) (Pointwise T)
54 antisymmetric antisym [] [] = []
55 antisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =
56 antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs
57
58 respʳ : R Respectsʳ S → (Pointwise R) Respectsʳ (Pointwise S)
59 respʳ resp [] [] = []
60 respʳ resp (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) = resp x≈y z∼x ∷ respʳ resp xs≈ys zs∼xs
61
62 respˡ : R Respectsˡ S → (Pointwise R) Respectsˡ (Pointwise S)
63 respˡ resp [] [] = []
64 respˡ resp (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) = resp x≈y x∼z ∷ respˡ resp xs≈ys xs∼zs
65
66 respects₂ : R Respects₂ S → (Pointwise R) Respects₂ (Pointwise S)
67 respects₂ (rʳ , rˡ) = respʳ rʳ , respˡ rˡ
68
69 decidable : Decidable R → Decidable (Pointwise R)
70 decidable _ [] [] = yes []
71 decidable _ [] (y ∷ ys) = no λ()
72 decidable _ (x ∷ xs) [] = no λ()
73 decidable R? (x ∷ xs) (y ∷ ys) = Dec.map′ (uncurry _∷_) uncons
74 (R? x y ×-dec decidable R? xs ys)
75
76 irrelevant : Irrelevant R → Irrelevant (Pointwise R)
77 irrelevant irr [] [] = ≡.refl
78 irrelevant irr (r ∷ rs) (r₁ ∷ rs₁) =
79 ≡.cong₂ _∷_ (irr r r₁) (irrelevant irr rs rs₁)
80
81 Pointwise-length : ∀ {xs ys} → Pointwise R xs ys → length xs ≡ length ys
82 Pointwise-length [] = ≡.refl
83 Pointwise-length (x∼y ∷ xs∼ys) = ≡.cong ℕ.suc (Pointwise-length xs∼ys)
84
85 lookup-cast : ∀ {xs ys} →
86 Pointwise R xs ys →
87 .(∣xs∣≡∣ys∣ : length xs ≡ length ys) →
88 ∀ i →
89 R (lookup xs i) (lookup ys (cast ∣xs∣≡∣ys∣ i))
90 lookup-cast (Rxy ∷ Rxsys) _ zero = Rxy
91 lookup-cast (Rxy ∷ Rxsys) _ (suc i) = lookup-cast Rxsys _ i