Skip to content

Commit 7723d51

Browse files
committed
Lists: decidability of Subset+Disjoint relations
1 parent 59d7b2e commit 7723d51

File tree

5 files changed

+110
-1
lines changed

5 files changed

+110
-1
lines changed

src/Data/List/Membership/DecSetoid.agda

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
open import Relation.Binary.Definitions using (Decidable)
1010
open import Relation.Binary.Bundles using (DecSetoid)
1111
open import Relation.Nullary.Decidable using (¬?)
12+
open import Relation.Nullary using (Stable; decidable-stable)
13+
open import Data.List.Relation.Unary.Any using (any?)
1214

1315
module Data.List.Membership.DecSetoid {a ℓ} (DS : DecSetoid a ℓ) where
1416

15-
open import Data.List.Relation.Unary.Any using (any?)
1617
open DecSetoid DS
1718

1819
------------------------------------------------------------------------
@@ -30,3 +31,6 @@ x ∈? xs = any? (x ≟_) xs
3031

3132
_∉?_ : Decidable _∉_
3233
x ∉? xs = ¬? (x ∈? xs)
34+
35+
∈-stable : {xs ys} Stable (xs ∈ ys)
36+
∈-stable = decidable-stable (_ ∈? _)
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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 Function.Base using (_$_)
10+
open import Data.Product.Base using (_,_)
11+
open import Data.List.Relation.Unary.Any using (map)
12+
open import Data.List.Relation.Unary.All using (all?; lookupₛ)
13+
open import Data.List.Relation.Unary.All.Properties using (¬All⇒Any¬)
14+
open import Relation.Binary.Bundles using (DecSetoid)
15+
open import Relation.Binary.Definitions using (Decidable)
16+
open import Relation.Nullary using (yes; no)
17+
18+
module Data.List.Relation.Binary.Disjoint.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where
19+
20+
open DecSetoid S
21+
open import Data.List.Relation.Binary.Equality.DecSetoid S
22+
open import Data.List.Relation.Binary.Disjoint.Setoid setoid public
23+
open import Data.List.Membership.DecSetoid S
24+
25+
disjoint? : Decidable Disjoint
26+
disjoint? xs ys with all? (_∉? ys) xs
27+
... | yes xs♯ys = yes λ (v∈ , v∈′)
28+
lookupₛ setoid (λ x≈y ∉ys ∈ys ∉ys (map (trans x≈y) ∈ys)) xs♯ys v∈ v∈′
29+
... | no ¬xs♯ys = let (x , x∈ , ¬∉ys) = find (¬All⇒Any¬ (_∉? _) _ ¬xs♯ys) in
30+
no λ p p (x∈ , ∈-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 Function.Base using (_∘_)
10+
open import Data.List.Base using ([]; _∷_)
11+
open import Data.List.Relation.Unary.Any using (here; there; map)
12+
open import Relation.Binary.Bundles using (DecSetoid)
13+
open import Relation.Binary.Definitions using (Decidable)
14+
open import Relation.Nullary using (yes; no)
15+
16+
module Data.List.Relation.Binary.Subset.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where
17+
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)