Debian Codegraph @

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

raw
1 ------------------------------------------------------------------------
2 -- The Agda standard library
3 --
4 -- Properties of disjoint lists (setoid equality)
5 ------------------------------------------------------------------------
6
7 {-# OPTIONS --cubical-compatible --safe #-}
8
9 module Data.List.Relation.Binary.Disjoint.Setoid.Properties where
10
11 open import Function.Base using (_∘_)
12 open import Function.Bundles using (_⇔_; mk⇔)
13 open import Data.List.Base
14 open import Data.List.Relation.Binary.Disjoint.Setoid
15 import Data.List.Relation.Unary.Any as Any
16 open import Data.List.Relation.Unary.All as All
17 open import Data.List.Relation.Unary.All.Properties using (¬Any⇒All¬)
18 open import Data.List.Relation.Unary.Any.Properties using (++⁻)
19 import Data.List.Membership.Setoid.Properties as Mem
20 open import Data.Product.Base as Product using (_,_)
21 open import Data.Sum.Base using (inj₁; inj₂)
22 open import Relation.Binary.Bundles using (Setoid)
23 open import Relation.Binary.Definitions using (Symmetric; DecidableEquality)
24 open import Relation.Binary.PropositionalEquality.Core using (_≡_)
25 open import Relation.Nullary.Negation using (¬_)
26
27 module _ {c ℓ} (S : Setoid c ℓ) where
28
29 open Setoid S using (_≉_; reflexive) renaming (Carrier to A)
30
31 ------------------------------------------------------------------------
32 -- Relational properties
33 ------------------------------------------------------------------------
34
35 sym : Symmetric (Disjoint S)
36 sym xs#ys (v∈ys , v∈xs) = xs#ys (v∈xs , v∈ys)
37
38 ------------------------------------------------------------------------
39 -- Relationship with other predicates
40 ------------------------------------------------------------------------
41
42 Disjoint⇒AllAll : ∀ {xs ys} → Disjoint S xs ys →
43 All (λ x → All (x ≉_) ys) xs
44 Disjoint⇒AllAll xs#ys = All.map (¬Any⇒All¬ _)
45 (All.tabulate (λ v∈xs v∈ys → xs#ys (Any.map reflexive v∈xs , v∈ys)))
46
47 ------------------------------------------------------------------------
48 -- Introduction (⁺) and elimination (⁻) rules for list operations
49 ------------------------------------------------------------------------
50 -- concat
51
52 concat⁺ʳ : ∀ {vs xss} → All (Disjoint S vs) xss → Disjoint S vs (concat xss)
53 concat⁺ʳ {xss = xs ∷ xss} (vs#xs ∷ vs#xss) (v∈vs , v∈xs++concatxss)
54 with ++⁻ xs v∈xs++concatxss
55 ... | inj₁ v∈xs = vs#xs (v∈vs , v∈xs)
56 ... | inj₂ v∈xss = concat⁺ʳ vs#xss (v∈vs , v∈xss)
57
58 -- deduplicate
59 module _ (_≟_ : DecidableEquality A) where
60
61 deduplicate⁺ : ∀ {xs ys} → Disjoint S xs ys →
62 Disjoint S (deduplicate _≟_ xs) (deduplicate _≟_ ys)
63 deduplicate⁺ = let ∈-dedup⁻ = Mem.∈-deduplicate⁻ S _≟_ in
64 _∘ Product.map (∈-dedup⁻ _) (∈-dedup⁻ _)