Skip to content

Commit e4927f1

Browse files
committed
[ re #517 ] First steps towards formalizing Prefix
1 parent 90e0b29 commit e4927f1

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- An inductive definition of the heterogeneous prefix relation
5+
------------------------------------------------------------------------
6+
7+
module Data.List.Relation.Prefix.Heterogeneous where
8+
9+
open import Data.List.Base as List using (List; []; _∷_)
10+
open import Data.List.Relation.Pointwise using (Pointwise; []; _∷_)
11+
open import Relation.Binary using (REL; _⇒_)
12+
13+
data Prefix {a b r} {A : Set a} {B : Set b} (R : REL A B r)
14+
: REL (List A) (List B) r where
15+
[] : {bs} Prefix R [] bs
16+
_∷_ : {a b as bs} R a b Prefix R as bs Prefix R (a ∷ as) (b ∷ bs)
17+
18+
module _ {a b r s} {A : Set a} {B : Set b} {R : REL A B r} {S : REL A B s} where
19+
20+
map : R ⇒ S Prefix R ⇒ Prefix S
21+
map f [] = []
22+
map f (x ∷ xs) = f x ∷ map f xs
23+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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

Comments
 (0)