|
| 1 | +------------------------------------------------------------------------ |
| 2 | +-- The Agda standard library |
| 3 | +-- |
| 4 | +-- Properties of the heterogeneous prefix relation |
| 5 | +------------------------------------------------------------------------ |
| 6 | + |
| 7 | +module Data.List.Relation.Prefix.Heterogeneous.Properties where |
| 8 | + |
| 9 | +open import Data.List.Base as List using (List; []; _∷_) |
| 10 | +open import Data.List.Relation.Pointwise using (Pointwise; []; _∷_) |
| 11 | +open import Data.List.Relation.Prefix.Heterogeneous |
| 12 | +open import Relation.Binary |
| 13 | + |
| 14 | +module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where |
| 15 | + |
| 16 | + refl : Pointwise R ⇒ Prefix R |
| 17 | + refl [] = [] |
| 18 | + refl (x ∷ xs) = x ∷ refl xs |
| 19 | + |
| 20 | + infixl 5 _++_ |
| 21 | + _++_ : ∀ {as bs cs ds} → Pointwise R as bs → Prefix R cs ds → |
| 22 | + Prefix R (as List.++ cs) (bs List.++ ds) |
| 23 | + [] ++ cs⊆ds = cs⊆ds |
| 24 | + (a∼b ∷ as∼bs) ++ cs⊆ds = a∼b ∷ (as∼bs ++ cs⊆ds) |
| 25 | + |
| 26 | +module _ {a b c r s t} {A : Set a} {B : Set b} {C : Set c} |
| 27 | + {R : REL A B r} {S : REL B C s} {T : REL A C t} where |
| 28 | + |
| 29 | + trans : Trans R S T → Trans (Prefix R) (Prefix S) (Prefix T) |
| 30 | + trans rs⇒t [] bs~cs = [] |
| 31 | + trans rs⇒t (a∼b ∷ as∼bs) (b∼c ∷ bs∼cs) = rs⇒t a∼b b∼c ∷ trans rs⇒t as∼bs bs∼cs |
| 32 | + |
| 33 | +module _ {a b c d r} {A : Set a} {B : Set b} {C : Set c} {D : Set d} |
| 34 | + {R : REL C D r} where |
| 35 | + |
| 36 | + map⁺ : ∀ {as bs} (f : A → C) (g : B → D) → |
| 37 | + Prefix (λ a b → R (f a) (g b)) as bs → |
| 38 | + Prefix R (List.map f as) (List.map g bs) |
| 39 | + map⁺ f g [] = [] |
| 40 | + map⁺ f g (x ∷ xs) = x ∷ map⁺ f g xs |
| 41 | + |
| 42 | + map⁻ : ∀ {as bs} (f : A → C) (g : B → D) → |
| 43 | + Prefix R (List.map f as) (List.map g bs) → |
| 44 | + Prefix (λ a b → R (f a) (g b)) as bs |
| 45 | + map⁻ {[]} {bs} f g xs = [] |
| 46 | + map⁻ {a ∷ as} {[]} f g () |
| 47 | + map⁻ {a ∷ as} {b ∷ bs} f g (x ∷ xs) = x ∷ map⁻ f g xs |
0 commit comments