Skip to content

Commit 2466b4c

Browse files
authored
Add documentation for subset relation on lists (#1267)
1 parent 938571d commit 2466b4c

File tree

5 files changed

+79
-6
lines changed

5 files changed

+79
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,16 @@ Other minor additions
565565
* Added new proof to `Data.List.Relation.Binary.Subset.Setoid.Properties`:
566566
```agda
567567
xs⊆x∷xs : xs ⊆ x ∷ xs
568-
∷⁺ʳ : xs ⊆ ys → x ∷ xs ⊆ x ∷ ys
568+
∷⁺ʳ : xs ⊆ ys → x ∷ xs ⊆ x ∷ ys
569+
∈-∷⁺ʳ : x ∈ ys → xs ⊆ ys → x ∷ xs ⊆ ys
569570
applyUpTo⁺ : m ≤ n → applyUpTo f m ⊆ applyUpTo f n
570571
```
571572

572573
* Added new proof to `Data.List.Relation.Binary.Subset.Propositional.Properties`:
573574
```agda
574575
xs⊆x∷xs : xs ⊆ x ∷ xs
575576
∷⁺ʳ : xs ⊆ ys → x ∷ xs ⊆ x ∷ ys
577+
∈-∷⁺ʳ : x ∈ ys → xs ⊆ ys → x ∷ xs ⊆ ys
576578
applyUpTo⁺ : m ≤ n → applyUpTo f m ⊆ applyUpTo f n
577579
```
578580

README/Data/List.agda

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,15 @@ import README.Data.List.Relation.Binary.Equality
141141

142142
import README.Data.List.Relation.Binary.Permutation
143143

144+
------------------------------------------------------------------------
145+
-- Subsets
146+
147+
-- Instead one might want to order lists by the subset relation which
148+
-- forms a partial order over lists. One list is a subset of another if
149+
-- every element in the first list occurs at least once in the second.
150+
151+
import README.Data.List.Relation.Binary.Subset
152+
144153
------------------------------------------------------------------------
145154
-- Other binary relations
146155

@@ -155,11 +164,7 @@ import Data.List.Relation.Binary.Lex.Strict
155164

156165
import Data.List.Relation.Binary.BagAndSetEquality
157166

158-
-- 3. the subset relations.
159-
160-
import Data.List.Relation.Binary.Subset.Propositional
161-
162-
-- 4. the sublist relations
167+
-- 3. the sublist relations
163168

164169
import Data.List.Relation.Binary.Sublist.Propositional
165170

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Documentation for subset relations over `List`s
5+
------------------------------------------------------------------------
6+
7+
open import Data.List using (List; _∷_; [])
8+
open import Data.List.Membership.Propositional.Properties
9+
using (∈-++⁺ˡ; ∈-insert)
10+
open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_)
11+
open import Data.List.Relation.Unary.Any using (here; there)
12+
open import Relation.Binary.PropositionalEquality using (refl)
13+
14+
module README.Data.List.Relation.Binary.Subset where
15+
16+
------------------------------------------------------------------------
17+
-- Subset Relation
18+
19+
-- The Subset relation is a wrapper over `Any` and so is parameterized
20+
-- over an equality relation. Thus to use the subset relation we must
21+
-- tell Agda which equality relation to use.
22+
23+
-- Decidable equality over Strings
24+
open import Data.String using (String; _≟_)
25+
26+
-- Open the decidable membership module using Decidable ≡ over Strings
27+
open import Data.List.Membership.DecPropositional _≟_
28+
29+
30+
-- Simple cases are inductive proofs
31+
32+
lem₁ : {xs : List String} xs ⊆ xs
33+
lem₁ p = p
34+
35+
lem₂ : "A" ∷ [] ⊆ "B""A" ∷ []
36+
lem₂ p = there p
37+
38+
-- Or directly use the definition of subsets
39+
40+
lem₃₀ : "E""S""B" ∷ [] ⊆ "S""U""B""S""E""T" ∷ []
41+
lem₃₀ (here refl) = there (there (there (there (here refl)))) -- "E"
42+
lem₃₀ (there (here refl)) = here refl -- "S"
43+
lem₃₀ (there (there (here refl))) = there (there (here refl)) -- "B"
44+
45+
-- Or use proofs from `Data.List.Membership.Propositional.Properties`
46+
47+
lem₄ : "A" ∷ [] ⊆ "B""A""C" ∷ []
48+
lem₄ p = ∈-++⁺ˡ (there p)
49+
50+
lem₅ : "B""S""E" ∷ [] ⊆ "S""U""B""S""E""T" ∷ []
51+
lem₅ p = ∈-++⁺ˡ (there (there p))
52+
53+
lem₃₁ : "E""S""B" ∷ [] ⊆ "S""U""B""S""E""T" ∷ []
54+
lem₃₁ (here refl) = ∈-insert ("S""U""B""S" ∷ [])
55+
lem₃₁ (there (here refl)) = here refl
56+
lem₃₁ (there (there (here refl))) = ∈-insert ("S""U" ∷ [])

src/Data/List/Relation/Binary/Subset/Propositional/Properties.agda

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ xs⊆x∷xs = Setoidₚ.xs⊆x∷xs (setoid _)
142142
∷⁺ʳ : x xs ⊆ ys x ∷ xs ⊆ x ∷ ys
143143
∷⁺ʳ = Setoidₚ.∷⁺ʳ (setoid _)
144144

145+
∈-∷⁺ʳ : {x} x ∈ ys xs ⊆ ys x ∷ xs ⊆ ys
146+
∈-∷⁺ʳ = Setoidₚ.∈-∷⁺ʳ (setoid _)
147+
145148
------------------------------------------------------------------------
146149
-- _++_
147150

src/Data/List/Relation/Binary/Subset/Setoid/Properties.agda

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ module _ (S : Setoid a ℓ) where
175175

176176
module _ (S : Setoid a ℓ) where
177177

178+
open Setoid S
178179
open Subset S
180+
open Membership S
179181

180182
xs⊆x∷xs : xs x xs ⊆ x ∷ xs
181183
xs⊆x∷xs xs x = there
@@ -184,6 +186,11 @@ module _ (S : Setoid a ℓ) where
184186
∷⁺ʳ x xs⊆ys (here p) = here p
185187
∷⁺ʳ x xs⊆ys (there p) = there (xs⊆ys p)
186188

189+
∈-∷⁺ʳ : {xs ys x} x ∈ ys xs ⊆ ys x ∷ xs ⊆ ys
190+
∈-∷⁺ʳ x∈ys _ (here v≈x) = ∈-resp-≈ S (sym v≈x) x∈ys
191+
∈-∷⁺ʳ _ xs⊆ys (there x∈xs) = xs⊆ys x∈xs
192+
193+
------------------------------------------------------------------------
187194
-- ++
188195

189196
module _ (S : Setoid a ℓ) where

0 commit comments

Comments
 (0)