@@ -10,6 +10,7 @@ module Data.List.Membership.Propositional.Properties where
10
10
11
11
open import Algebra.Core using (Op₂)
12
12
open import Algebra.Definitions using (Selective)
13
+ open import Data.Empty using (⊥-elim)
13
14
open import Data.Fin.Base using (Fin)
14
15
open import Data.List.Base as List
15
16
open import Data.List.Effectful using (monad)
@@ -24,13 +25,13 @@ open import Data.List.Relation.Unary.Any.Properties
24
25
open import Data.Nat.Base using (ℕ; suc; s≤s; _≤_; _<_; _≰_)
25
26
open import Data.Nat.Properties
26
27
using (suc-injective; m≤n⇒m≤1+n; _≤?_; <⇒≢; ≰⇒>)
27
- open import Data.Product.Base using (∃; ∃₂; _×_; _,_; ∃-syntax)
28
+ open import Data.Product.Base using (∃; ∃₂; _×_; _,_; ∃-syntax; -,_; map₂ )
28
29
open import Data.Product.Properties using (×-≡,≡↔≡)
29
30
open import Data.Product.Function.NonDependent.Propositional using (_×-cong_)
30
31
import Data.Product.Function.Dependent.Propositional as Σ
31
32
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
32
33
open import Effect.Monad using (RawMonad)
33
- open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_)
34
+ open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_; _∋_ )
34
35
open import Function.Definitions using (Injective)
35
36
import Function.Related.Propositional as Related
36
37
open import Function.Bundles using (_↔_; _↣_; Injection; _⇔_; mk⇔)
@@ -40,7 +41,7 @@ open import Level using (Level)
40
41
open import Relation.Binary.Core using (Rel)
41
42
open import Relation.Binary.Definitions as Binary hiding (Decidable)
42
43
open import Relation.Binary.PropositionalEquality.Core as ≡
43
- using (_≡_; _≢_; refl; sym; trans; cong; cong₂; resp; _≗_)
44
+ using (_≡_; _≢_; refl; sym; trans; cong; cong₂; resp; _≗_; subst )
44
45
open import Relation.Binary.PropositionalEquality.Properties as ≡ using (setoid)
45
46
import Relation.Binary.Properties.DecTotalOrder as DTOProperties
46
47
open import Relation.Nullary.Decidable.Core
@@ -55,6 +56,9 @@ private
55
56
variable
56
57
ℓ : Level
57
58
A B C : Set ℓ
59
+ x y v : A
60
+ xs ys : List A
61
+ xss : List (List A)
58
62
59
63
------------------------------------------------------------------------
60
64
-- Publicly re-export properties from Core
@@ -64,10 +68,10 @@ open import Data.List.Membership.Propositional.Properties.Core public
64
68
------------------------------------------------------------------------
65
69
-- Equality
66
70
67
- ∈-resp-≋ : ∀ {x : A} → (x ∈_) Respects _≋_
71
+ ∈-resp-≋ : (x ∈_) Respects _≋_
68
72
∈-resp-≋ = Membership.∈-resp-≋ (≡.setoid _)
69
73
70
- ∉-resp-≋ : ∀ {x : A} → (x ∉_) Respects _≋_
74
+ ∉-resp-≋ : (x ∉_) Respects _≋_
71
75
∉-resp-≋ = Membership.∉-resp-≋ (≡.setoid _)
72
76
73
77
------------------------------------------------------------------------
@@ -96,14 +100,14 @@ map-mapWith∈ = Membership.map-mapWith∈ (≡.setoid _)
96
100
97
101
module _ (f : A → B) where
98
102
99
- ∈-map⁺ : ∀ {x xs} → x ∈ xs → f x ∈ map f xs
103
+ ∈-map⁺ : x ∈ xs → f x ∈ map f xs
100
104
∈-map⁺ = Membership.∈-map⁺ (≡.setoid A) (≡.setoid B) (cong f)
101
105
102
- ∈-map⁻ : ∀ {y xs} → y ∈ map f xs → ∃ λ x → x ∈ xs × y ≡ f x
106
+ ∈-map⁻ : y ∈ map f xs → ∃ λ x → x ∈ xs × y ≡ f x
103
107
∈-map⁻ = Membership.∈-map⁻ (≡.setoid A) (≡.setoid B)
104
108
105
- map-∈↔ : ∀ {y xs} → (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ map f xs
106
- map-∈↔ {y} {xs } =
109
+ map-∈↔ : (∃ λ x → x ∈ xs × y ≡ f x) ↔ y ∈ map f xs
110
+ map-∈↔ {xs}{y } =
107
111
(∃ λ x → x ∈ xs × y ≡ f x) ↔⟨ Any↔ ⟩
108
112
Any (λ x → y ≡ f x) xs ↔⟨ map↔ ⟩
109
113
y ∈ List.map f xs ∎
@@ -114,7 +118,7 @@ module _ (f : A → B) where
114
118
115
119
module _ {v : A} where
116
120
117
- ∈-++⁺ˡ : ∀ {xs ys} → v ∈ xs → v ∈ xs ++ ys
121
+ ∈-++⁺ˡ : v ∈ xs → v ∈ xs ++ ys
118
122
∈-++⁺ˡ = Membership.∈-++⁺ˡ (≡.setoid A)
119
123
120
124
∈-++⁺ʳ : ∀ xs {ys} → v ∈ ys → v ∈ xs ++ ys
@@ -123,13 +127,13 @@ module _ {v : A} where
123
127
∈-++⁻ : ∀ xs {ys} → v ∈ xs ++ ys → (v ∈ xs) ⊎ (v ∈ ys)
124
128
∈-++⁻ = Membership.∈-++⁻ (≡.setoid A)
125
129
126
- ∈-++ : ∀ {xs ys} → v ∈ xs ++ ys ⇔ (v ∈ xs ⊎ v ∈ ys)
130
+ ∈-++ : v ∈ xs ++ ys ⇔ (v ∈ xs ⊎ v ∈ ys)
127
131
∈-++ = mk⇔ (∈-++⁻ _) Sum.[ ∈-++⁺ˡ , ∈-++⁺ʳ _ ]
128
132
129
133
∈-insert : ∀ xs {ys} → v ∈ xs ++ [ v ] ++ ys
130
134
∈-insert xs = Membership.∈-insert (≡.setoid A) xs refl
131
135
132
- ∈-∃++ : ∀ {xs} → v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs
136
+ ∈-∃++ : v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs
133
137
∈-∃++ v∈xs
134
138
with ys , zs , _ , refl , eq ← Membership.∈-∃++ (≡.setoid A) v∈xs
135
139
= ys , zs , ≋⇒≡ eq
@@ -139,7 +143,7 @@ module _ {v : A} where
139
143
140
144
module _ {v : A} where
141
145
142
- ∈-concat⁺ : ∀ {xss} → Any (v ∈_) xss → v ∈ concat xss
146
+ ∈-concat⁺ : Any (v ∈_) xss → v ∈ concat xss
143
147
∈-concat⁺ = Membership.∈-concat⁺ (≡.setoid A)
144
148
145
149
∈-concat⁻ : ∀ xss → v ∈ concat xss → Any (v ∈_) xss
@@ -154,8 +158,7 @@ module _ {v : A} where
154
158
let xs , v∈xs , xs∈xss = Membership.∈-concat⁻′ (≡.setoid A) xss v∈c
155
159
in xs , v∈xs , Any.map ≋⇒≡ xs∈xss
156
160
157
- concat-∈↔ : ∀ {xss : List (List A)} →
158
- (∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss
161
+ concat-∈↔ : (∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss
159
162
concat-∈↔ {xss} =
160
163
(∃ λ xs → v ∈ xs × xs ∈ xss) ↔⟨ Σ.cong (↔-id _) $ ×-comm _ _ ⟩
161
164
(∃ λ xs → xs ∈ xss × v ∈ xs) ↔⟨ Any↔ ⟩
@@ -262,10 +265,10 @@ module _ {n} {f : Fin n → A} where
262
265
263
266
module _ {p} {P : A → Set p} (P? : Decidable P) where
264
267
265
- ∈-filter⁺ : ∀ {x xs} → x ∈ xs → P x → x ∈ filter P? xs
268
+ ∈-filter⁺ : x ∈ xs → P x → x ∈ filter P? xs
266
269
∈-filter⁺ = Membership.∈-filter⁺ (≡.setoid A) P? (≡.resp P)
267
270
268
- ∈-filter⁻ : ∀ {v xs} → v ∈ filter P? xs → v ∈ xs × P v
271
+ ∈-filter⁻ : v ∈ filter P? xs → v ∈ xs × P v
269
272
∈-filter⁻ = Membership.∈-filter⁻ (≡.setoid A) P? (≡.resp P)
270
273
271
274
------------------------------------------------------------------------
@@ -339,13 +342,13 @@ module _ (_≈?_ : DecidableEquality A) where
339
342
------------------------------------------------------------------------
340
343
-- length
341
344
342
- ∈-length : ∀ {x : A} {xs} → x ∈ xs → 0 < length xs
345
+ ∈-length : x ∈ xs → 0 < length xs
343
346
∈-length = Membership.∈-length (≡.setoid _)
344
347
345
348
------------------------------------------------------------------------
346
349
-- lookup
347
350
348
- ∈-lookup : ∀ {xs : List A} i → lookup xs i ∈ xs
351
+ ∈-lookup : ∀ i → lookup xs i ∈ xs
349
352
∈-lookup {xs = xs} i = Membership.∈-lookup (≡.setoid _) xs i
350
353
351
354
------------------------------------------------------------------------
@@ -366,7 +369,7 @@ module _ {_•_ : Op₂ A} where
366
369
------------------------------------------------------------------------
367
370
-- inits
368
371
369
- []∈inits : ∀ {a} {A : Set a} (as : List A) → [] ∈ inits as
372
+ []∈inits : (as : List A) → [] ∈ inits as
370
373
[]∈inits _ = here refl
371
374
372
375
------------------------------------------------------------------------
@@ -443,3 +446,26 @@ module _ {R : A → A → Set ℓ} where
443
446
∈-AllPairs₂ (p ∷ _) (here refl) (there y∈) = inj₂ $ inj₁ $ All.lookup p y∈
444
447
∈-AllPairs₂ (p ∷ _) (there x∈) (here refl) = inj₂ $ inj₂ $ All.lookup p x∈
445
448
∈-AllPairs₂ (_ ∷ ps) (there x∈) (there y∈) = ∈-AllPairs₂ ps x∈ y∈
449
+
450
+ ------------------------------------------------------------------------
451
+ -- nested lists
452
+
453
+ []∉map∷ : (List A ∋ []) ∉ map (x ∷_) xss
454
+ []∉map∷ {xss = _ ∷ _} (there p) = []∉map∷ p
455
+
456
+ map∷-decomp∈ : (List A ∋ x ∷ xs) ∈ map (y ∷_) xss → x ≡ y × xs ∈ xss
457
+ map∷-decomp∈ {xss = _ ∷ _} = λ where
458
+ (here refl) → refl , here refl
459
+ (there p) → map₂ there $ map∷-decomp∈ p
460
+
461
+ map∷-decomp : xs ∈ map (y ∷_) xss → ∃[ ys ] ys ∈ xss × y ∷ ys ≡ xs
462
+ map∷-decomp {xss = _ ∷ _} (here refl) = -, here refl , refl
463
+ map∷-decomp {xs = []} {xss = _ ∷ _} (there xs∈) = ⊥-elim ([]∉map∷ xs∈)
464
+ map∷-decomp {xs = x ∷ xs} {xss = _ ∷ _} (there xs∈) =
465
+ let eq , p = map∷-decomp∈ xs∈
466
+ in -, there p , subst (λ ◆ → ◆ ∷ _ ≡ _) eq refl
467
+
468
+ ∈-map∷⁻ : xs ∈ map (x ∷_) xss → x ∈ xs
469
+ ∈-map∷⁻ {xss = _ ∷ _} = λ where
470
+ (here refl) → here refl
471
+ (there p) → ∈-map∷⁻ p
0 commit comments