@@ -10,26 +10,26 @@ 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 Effect.Monad using (RawMonad)
14
- open import Data.Bool.Base using (Bool; false; true; T)
15
13
open import Data.Fin.Base using (Fin)
16
14
open import Data.List.Base as List
17
- open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
18
- open import Data.List.Relation.Unary.Any.Properties
19
- using (map↔; concat↔; >>=↔; ⊛↔; Any-cong; ⊗↔′; ¬Any[])
15
+ open import Data.List.Effectful using (monad)
20
16
open import Data.List.Membership.Propositional
21
17
using (_∈_; _∉_; mapWith∈; _≢∈_)
22
18
import Data.List.Membership.Setoid.Properties as Membership
23
19
open import Data.List.Relation.Binary.Equality.Propositional
24
20
using (_≋_; ≡⇒≋; ≋⇒≡)
25
- open import Data.List.Effectful using (monad)
26
- open import Data.Nat.Base using (ℕ; zero; suc; pred; s≤s; _≤_; _<_; _≤ᵇ_)
27
- open import Data.Nat.Properties using (_≤?_; m≤n⇒m≤1+n; ≤ᵇ-reflects-≤; <⇒≢; ≰⇒>)
21
+ open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
22
+ open import Data.List.Relation.Unary.Any.Properties
23
+ using (map↔; concat↔; >>=↔; ⊛↔; Any-cong; ⊗↔′; ¬Any[])
24
+ open import Data.Nat.Base using (ℕ; suc; s≤s; _≤_; _<_; _≰_)
25
+ open import Data.Nat.Properties
26
+ using (suc-injective; m≤n⇒m≤1+n; _≤?_; <⇒≢; ≰⇒>)
28
27
open import Data.Product.Base using (∃; ∃₂; _×_; _,_)
29
28
open import Data.Product.Properties using (×-≡,≡↔≡)
30
29
open import Data.Product.Function.NonDependent.Propositional using (_×-cong_)
31
30
import Data.Product.Function.Dependent.Propositional as Σ
32
31
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
32
+ open import Effect.Monad using (RawMonad)
33
33
open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_)
34
34
open import Function.Definitions using (Injective)
35
35
import Function.Related.Propositional as Related
@@ -40,15 +40,14 @@ open import Level using (Level)
40
40
open import Relation.Binary.Core using (Rel)
41
41
open import Relation.Binary.Definitions as Binary hiding (Decidable)
42
42
open import Relation.Binary.PropositionalEquality.Core as ≡
43
- using (_≡_; _≢_; refl; sym; trans; cong; cong₂; subst ; _≗_)
43
+ using (_≡_; _≢_; refl; sym; trans; cong; cong₂; resp ; _≗_)
44
44
open import Relation.Binary.PropositionalEquality.Properties as ≡ using (setoid)
45
45
import Relation.Binary.Properties.DecTotalOrder as DTOProperties
46
- open import Relation.Unary using (_⟨×⟩_; Decidable)
47
- import Relation.Nullary.Reflects as Reflects
46
+ open import Relation.Nullary.Decidable.Core
47
+ using (Dec; yes; no; ¬¬-excluded-middle)
48
+ open import Relation.Nullary.Negation.Core using (¬_; contradiction)
48
49
open import Relation.Nullary.Reflects using (invert)
49
- open import Relation.Nullary using (¬_; Dec; does; yes; no; _because_)
50
- open import Relation.Nullary.Negation using (contradiction)
51
- open import Relation.Nullary.Decidable using (¬¬-excluded-middle)
50
+ open import Relation.Unary using (_⟨×⟩_; Decidable)
52
51
53
52
private
54
53
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
@@ -128,8 +127,9 @@ module _ {v : A} where
128
127
∈-insert xs = Membership.∈-insert (≡.setoid A) xs refl
129
128
130
129
∈-∃++ : ∀ {xs} → v ∈ xs → ∃₂ λ ys zs → xs ≡ ys ++ [ v ] ++ zs
131
- ∈-∃++ v∈xs with Membership.∈-∃++ (≡.setoid A) v∈xs
132
- ... | ys , zs , _ , refl , eq = ys , zs , ≋⇒≡ eq
130
+ ∈-∃++ v∈xs
131
+ with ys , zs , _ , refl , eq ← Membership.∈-∃++ (≡.setoid A) v∈xs
132
+ = ys , zs , ≋⇒≡ eq
133
133
134
134
------------------------------------------------------------------------
135
135
-- concat
@@ -147,8 +147,9 @@ module _ {v : A} where
147
147
Membership.∈-concat⁺′ (≡.setoid A) v∈vs (Any.map ≡⇒≋ vs∈xss)
148
148
149
149
∈-concat⁻′ : ∀ xss → v ∈ concat xss → ∃ λ xs → v ∈ xs × xs ∈ xss
150
- ∈-concat⁻′ xss v∈c with Membership.∈-concat⁻′ (≡.setoid A) xss v∈c
151
- ... | xs , v∈xs , xs∈xss = xs , v∈xs , Any.map ≋⇒≡ xs∈xss
150
+ ∈-concat⁻′ xss v∈c =
151
+ let xs , v∈xs , xs∈xss = Membership.∈-concat⁻′ (≡.setoid A) xss v∈c
152
+ in xs , v∈xs , Any.map ≋⇒≡ xs∈xss
152
153
153
154
concat-∈↔ : ∀ {xss : List (List A)} →
154
155
(∃ λ xs → v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss
@@ -183,8 +184,9 @@ module _ (f : A → B → C) where
183
184
184
185
∈-cartesianProduct⁻ : ∀ xs ys {xy@(x , y) : A × B} →
185
186
xy ∈ cartesianProduct xs ys → x ∈ xs × y ∈ ys
186
- ∈-cartesianProduct⁻ xs ys xy∈p[xs,ys] with ∈-cartesianProductWith⁻ _,_ xs ys xy∈p[xs,ys]
187
- ... | (x , y , x∈xs , y∈ys , refl) = x∈xs , y∈ys
187
+ ∈-cartesianProduct⁻ xs ys xy∈p[xs,ys]
188
+ with _ , _ , x∈xs , y∈ys , refl ← ∈-cartesianProductWith⁻ _,_ xs ys xy∈p[xs,ys]
189
+ = x∈xs , y∈ys
188
190
189
191
------------------------------------------------------------------------
190
192
-- applyUpTo
@@ -205,8 +207,7 @@ module _ (f : ℕ → A) where
205
207
∈-upTo⁺ = ∈-applyUpTo⁺ id
206
208
207
209
∈-upTo⁻ : ∀ {n i} → i ∈ upTo n → i < n
208
- ∈-upTo⁻ p with ∈-applyUpTo⁻ id p
209
- ... | _ , i<n , refl = i<n
210
+ ∈-upTo⁻ p with _ , i<n , refl ← ∈-applyUpTo⁻ id p = i<n
210
211
211
212
------------------------------------------------------------------------
212
213
-- applyDownFrom
@@ -227,8 +228,7 @@ module _ (f : ℕ → A) where
227
228
∈-downFrom⁺ i<n = ∈-applyDownFrom⁺ id i<n
228
229
229
230
∈-downFrom⁻ : ∀ {n i} → i ∈ downFrom n → i < n
230
- ∈-downFrom⁻ p with ∈-applyDownFrom⁻ id p
231
- ... | _ , i<n , refl = i<n
231
+ ∈-downFrom⁻ p with _ , i<n , refl ← ∈-applyDownFrom⁻ id p = i<n
232
232
233
233
------------------------------------------------------------------------
234
234
-- tabulate
@@ -247,10 +247,10 @@ module _ {n} {f : Fin n → A} where
247
247
module _ {p} {P : A → Set p} (P? : Decidable P) where
248
248
249
249
∈-filter⁺ : ∀ {x xs} → x ∈ xs → P x → x ∈ filter P? xs
250
- ∈-filter⁺ = Membership.∈-filter⁺ (≡.setoid A) P? (subst P)
250
+ ∈-filter⁺ = Membership.∈-filter⁺ (≡.setoid A) P? (≡.resp P)
251
251
252
252
∈-filter⁻ : ∀ {v xs} → v ∈ filter P? xs → v ∈ xs × P v
253
- ∈-filter⁻ = Membership.∈-filter⁻ (≡.setoid A) P? (subst P)
253
+ ∈-filter⁻ = Membership.∈-filter⁻ (≡.setoid A) P? (≡.resp P)
254
254
255
255
------------------------------------------------------------------------
256
256
-- derun and deduplicate
@@ -310,7 +310,7 @@ module _ (_≈?_ : DecidableEquality A) where
310
310
------------------------------------------------------------------------
311
311
-- length
312
312
313
- ∈-length : ∀ {x : A} {xs} → x ∈ xs → 1 ≤ length xs
313
+ ∈-length : ∀ {x : A} {xs} → x ∈ xs → 0 < length xs
314
314
∈-length = Membership.∈-length (≡.setoid _)
315
315
316
316
------------------------------------------------------------------------
@@ -365,28 +365,27 @@ finite inj (x ∷ xs) fᵢ∈x∷xs = ¬¬-excluded-middle helper
365
365
helper (yes (i , fᵢ≡x)) = finite f′-inj xs f′ⱼ∈xs
366
366
where
367
367
f′ : ℕ → _
368
- f′ j with does ( i ≤? j)
369
- ... | true = f (suc j)
370
- ... | false = f j
368
+ f′ j with i ≤? j
369
+ ... | yes _ = f (suc j)
370
+ ... | no _ = f j
371
371
372
372
∈-if-not-i : ∀ {j} → i ≢ j → f j ∈ xs
373
373
∈-if-not-i i≢j = not-x (i≢j ∘ f-inj ∘ trans fᵢ≡x ∘ sym)
374
374
375
- lemma : ∀ {k j} → i ≤ j → ¬ (i ≤ k) → suc j ≢ k
375
+ lemma : ∀ {k j} → i ≤ j → i ≰ k → suc j ≢ k
376
376
lemma i≤j i≰1+j refl = i≰1+j (m≤n⇒m≤1+n i≤j)
377
377
378
378
f′ⱼ∈xs : ∀ j → f′ j ∈ xs
379
- f′ⱼ∈xs j with i ≤ᵇ j | Reflects.invert (≤ᵇ-reflects-≤ i j)
380
- ... | true | p = ∈-if-not-i (<⇒≢ (s≤s p ))
381
- ... | false | p = ∈-if-not-i (<⇒≢ (≰⇒> p ) ∘ sym)
379
+ f′ⱼ∈xs j with i ≤? j
380
+ ... | yes i≤j = ∈-if-not-i (<⇒≢ (s≤s i≤j ))
381
+ ... | no i≰j = ∈-if-not-i (<⇒≢ (≰⇒> i≰j ) ∘ sym)
382
382
383
383
f′-injective′ : Injective _≡_ _≡_ f′
384
- f′-injective′ {j} {k} eq with i ≤ᵇ j | Reflects.invert (≤ᵇ-reflects-≤ i j)
385
- | i ≤ᵇ k | Reflects.invert (≤ᵇ-reflects-≤ i k)
386
- ... | true | p | true | q = ≡.cong pred (f-inj eq)
387
- ... | true | p | false | q = contradiction (f-inj eq) (lemma p q)
388
- ... | false | p | true | q = contradiction (f-inj eq) (lemma q p ∘ sym)
389
- ... | false | p | false | q = f-inj eq
384
+ f′-injective′ {j} {k} eq with i ≤? j | i ≤? k
385
+ ... | yes i≤j | yes i≤k = suc-injective (f-inj eq)
386
+ ... | yes i≤j | no i≰k = contradiction (f-inj eq) (lemma i≤j i≰k)
387
+ ... | no i≰j | yes i≤k = contradiction (f-inj eq) (lemma i≤k i≰j ∘ sym)
388
+ ... | no i≰j | no i≰k = f-inj eq
390
389
391
390
f′-inj : ℕ ↣ _
392
391
f′-inj = record
0 commit comments