Skip to content

Commit 10fd6b9

Browse files
omelkonianandreasabel
authored andcommitted
Lists: decidability of Subset+Disjoint relations (#2399)
1 parent d992900 commit 10fd6b9

File tree

6 files changed

+119
-2
lines changed

6 files changed

+119
-2
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ New modules
211211
Data.Vec.Bounded.Show
212212
```
213213

214+
* Decidability for the subset relation on lists:
215+
```agda
216+
Data.List.Relation.Binary.Subset.DecSetoid (_⊆?_)
217+
Data.List.Relation.Binary.Subset.DecPropositional
218+
```
219+
220+
* Decidability for the disjoint relation on lists:
221+
```agda
222+
Data.List.Relation.Binary.Disjoint.DecSetoid (disjoint?)
223+
Data.List.Relation.Binary.Disjoint.DecPropositional
224+
```
225+
214226
Additions to existing modules
215227
-----------------------------
216228

src/Data/List/Membership/DecSetoid.agda

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66

77
{-# OPTIONS --cubical-compatible --safe #-}
88

9-
open import Relation.Binary.Definitions using (Decidable)
109
open import Relation.Binary.Bundles using (DecSetoid)
11-
open import Relation.Nullary.Decidable using (¬?)
1210

1311
module Data.List.Membership.DecSetoid {a ℓ} (DS : DecSetoid a ℓ) where
1412

1513
open import Data.List.Relation.Unary.Any using (any?)
14+
open import Relation.Binary.Definitions using (Decidable)
15+
open import Relation.Nullary.Decidable using (¬?)
16+
1617
open DecSetoid DS
1718

1819
------------------------------------------------------------------------
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Decidability of the disjoint relation over propositional equality.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Relation.Binary.Definitions using (DecidableEquality)
10+
11+
module Data.List.Relation.Binary.Disjoint.DecPropositional
12+
{a} {A : Set a} (_≟_ : DecidableEquality A)
13+
where
14+
15+
------------------------------------------------------------------------
16+
-- Re-export core definitions and operations
17+
18+
open import Data.List.Relation.Binary.Disjoint.Propositional {A = A} public
19+
open import Relation.Binary.PropositionalEquality.Properties using (decSetoid)
20+
open import Data.List.Relation.Binary.Disjoint.DecSetoid (decSetoid _≟_) public
21+
using (disjoint?)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Decidability of the disjoint relation over setoid equality.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Relation.Binary.Bundles using (DecSetoid)
10+
11+
module Data.List.Relation.Binary.Disjoint.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where
12+
13+
open import Data.Product.Base using (_,_)
14+
open import Data.List.Relation.Unary.Any using (map)
15+
open import Data.List.Relation.Unary.All using (all?; lookupₛ)
16+
open import Data.List.Relation.Unary.All.Properties using (¬All⇒Any¬)
17+
open import Relation.Binary.Definitions using (Decidable)
18+
open import Relation.Nullary using (yes; no; decidable-stable)
19+
open DecSetoid S
20+
open import Data.List.Relation.Binary.Equality.DecSetoid S
21+
open import Data.List.Relation.Binary.Disjoint.Setoid setoid public
22+
open import Data.List.Membership.DecSetoid S
23+
24+
disjoint? : Decidable Disjoint
25+
disjoint? xs ys with all? (_∉? ys) xs
26+
... | yes xs♯ys = yes λ (v∈ , v∈′)
27+
lookupₛ setoid (λ x≈y ∉ys ∈ys ∉ys (map (trans x≈y) ∈ys)) xs♯ys v∈ v∈′
28+
... | no ¬xs♯ys = let (x , x∈ , ¬∉ys) = find (¬All⇒Any¬ (_∉? _) _ ¬xs♯ys) in
29+
no λ p p (x∈ , decidable-stable (_ ∈? _) ¬∉ys)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Decidability of the subset relation over propositional equality.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Relation.Binary.Definitions using (DecidableEquality)
10+
11+
module Data.List.Relation.Binary.Subset.DecPropositional
12+
{a} {A : Set a} (_≟_ : DecidableEquality A)
13+
where
14+
15+
------------------------------------------------------------------------
16+
-- Re-export core definitions and operations
17+
18+
open import Data.List.Relation.Binary.Subset.Propositional {A = A} public
19+
open import Relation.Binary.PropositionalEquality.Properties using (decSetoid)
20+
open import Data.List.Relation.Binary.Subset.DecSetoid (decSetoid _≟_) public
21+
using (_⊆?_)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Decidability of the subset relation over setoid equality.
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible --safe #-}
8+
9+
open import Relation.Binary.Bundles using (DecSetoid)
10+
11+
module Data.List.Relation.Binary.Subset.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where
12+
13+
open import Function.Base using (_∘_)
14+
open import Data.List.Base using ([]; _∷_)
15+
open import Data.List.Relation.Unary.Any using (here; there; map)
16+
open import Relation.Binary.Definitions using (Decidable)
17+
open import Relation.Nullary using (yes; no)
18+
open DecSetoid S
19+
open import Data.List.Relation.Binary.Equality.DecSetoid S
20+
open import Data.List.Membership.DecSetoid S
21+
22+
-- Re-export definitions
23+
open import Data.List.Relation.Binary.Subset.Setoid setoid public
24+
25+
infix 4 _⊆?_
26+
_⊆?_ : Decidable _⊆_
27+
[] ⊆? _ = yes λ ()
28+
(x ∷ xs) ⊆? ys with x ∈? ys
29+
... | no x∉ys = no λ xs⊆ys x∉ys (xs⊆ys (here refl))
30+
... | yes x∈ys with xs ⊆? ys
31+
... | no xs⊈ys = no λ xs⊆ys xs⊈ys (xs⊆ys ∘ there)
32+
... | yes xs⊆ys = yes λ where (here refl) map (trans refl) x∈ys
33+
(there x∈) xs⊆ys x∈

0 commit comments

Comments
 (0)