Skip to content

Lists: decidability of Subset+Disjoint relations #2399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,18 @@ New modules
Data.Vec.Bounded.Show
```

* Decidability for the subset relation on lists:
```agda
Data.List.Relation.Binary.Subset.DecSetoid (_⊆?_)
Data.List.Relation.Binary.Subset.DecPropositional
```

* Decidability for the disjoint relation on lists:
```agda
Data.List.Relation.Binary.Disjoint.DecSetoid (disjoint?)
Data.List.Relation.Binary.Disjoint.DecPropositional
```

Additions to existing modules
-----------------------------

Expand Down
5 changes: 3 additions & 2 deletions src/Data/List/Membership/DecSetoid.agda
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

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

open import Relation.Binary.Definitions using (Decidable)
open import Relation.Binary.Bundles using (DecSetoid)
open import Relation.Nullary.Decidable using (¬?)

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

open import Data.List.Relation.Unary.Any using (any?)
open import Relation.Binary.Definitions using (Decidable)
open import Relation.Nullary.Decidable using (¬?)

open DecSetoid DS

------------------------------------------------------------------------
Expand Down
21 changes: 21 additions & 0 deletions src/Data/List/Relation/Binary/Disjoint/DecPropositional.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidability of the disjoint relation over propositional equality.
------------------------------------------------------------------------

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

open import Relation.Binary.Definitions using (DecidableEquality)

module Data.List.Relation.Binary.Disjoint.DecPropositional
{a} {A : Set a} (_≟_ : DecidableEquality A)
where

------------------------------------------------------------------------
-- Re-export core definitions and operations

open import Data.List.Relation.Binary.Disjoint.Propositional {A = A} public
open import Relation.Binary.PropositionalEquality.Properties using (decSetoid)
open import Data.List.Relation.Binary.Disjoint.DecSetoid (decSetoid _≟_) public
using (disjoint?)
29 changes: 29 additions & 0 deletions src/Data/List/Relation/Binary/Disjoint/DecSetoid.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidability of the disjoint relation over setoid equality.
------------------------------------------------------------------------

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

open import Relation.Binary.Bundles using (DecSetoid)

module Data.List.Relation.Binary.Disjoint.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where

open import Data.Product.Base using (_,_)
open import Data.List.Relation.Unary.Any using (map)
open import Data.List.Relation.Unary.All using (all?; lookupₛ)
open import Data.List.Relation.Unary.All.Properties using (¬All⇒Any¬)
open import Relation.Binary.Definitions using (Decidable)
open import Relation.Nullary using (yes; no; decidable-stable)
open DecSetoid S
open import Data.List.Relation.Binary.Equality.DecSetoid S
open import Data.List.Relation.Binary.Disjoint.Setoid setoid public
open import Data.List.Membership.DecSetoid S

disjoint? : Decidable Disjoint
disjoint? xs ys with all? (_∉? ys) xs
... | yes xs♯ys = yes λ (v∈ , v∈′) →
lookupₛ setoid (λ x≈y ∉ys ∈ys → ∉ys (map (trans x≈y) ∈ys)) xs♯ys v∈ v∈′
... | no ¬xs♯ys = let (x , x∈ , ¬∉ys) = find (¬All⇒Any¬ (_∉? _) _ ¬xs♯ys) in
no λ p → p (x∈ , decidable-stable (_ ∈? _) ¬∉ys)
21 changes: 21 additions & 0 deletions src/Data/List/Relation/Binary/Subset/DecPropositional.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidability of the subset relation over propositional equality.
------------------------------------------------------------------------

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

open import Relation.Binary.Definitions using (DecidableEquality)

module Data.List.Relation.Binary.Subset.DecPropositional
{a} {A : Set a} (_≟_ : DecidableEquality A)
where

------------------------------------------------------------------------
-- Re-export core definitions and operations

open import Data.List.Relation.Binary.Subset.Propositional {A = A} public
open import Relation.Binary.PropositionalEquality.Properties using (decSetoid)
open import Data.List.Relation.Binary.Subset.DecSetoid (decSetoid _≟_) public
using (_⊆?_)
33 changes: 33 additions & 0 deletions src/Data/List/Relation/Binary/Subset/DecSetoid.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidability of the subset relation over setoid equality.
------------------------------------------------------------------------

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

open import Relation.Binary.Bundles using (DecSetoid)

module Data.List.Relation.Binary.Subset.DecSetoid {c ℓ} (S : DecSetoid c ℓ) where

open import Function.Base using (_∘_)
open import Data.List.Base using ([]; _∷_)
open import Data.List.Relation.Unary.Any using (here; there; map)
open import Relation.Binary.Definitions using (Decidable)
open import Relation.Nullary using (yes; no)
open DecSetoid S
open import Data.List.Relation.Binary.Equality.DecSetoid S
open import Data.List.Membership.DecSetoid S

-- Re-export definitions
open import Data.List.Relation.Binary.Subset.Setoid setoid public

infix 4 _⊆?_
_⊆?_ : Decidable _⊆_
[] ⊆? _ = yes λ ()
(x ∷ xs) ⊆? ys with x ∈? ys
... | no x∉ys = no λ xs⊆ys → x∉ys (xs⊆ys (here refl))
... | yes x∈ys with xs ⊆? ys
... | no xs⊈ys = no λ xs⊆ys → xs⊈ys (xs⊆ys ∘ there)
... | yes xs⊆ys = yes λ where (here refl) → map (trans refl) x∈ys
(there x∈) → xs⊆ys x∈