Skip to content

Commit 891d50f

Browse files
jamesmckinnaandreasabel
authored andcommitted
Refactor List.Membership.* and List.Relation.Unary.Any (#2324)
* `contradiction` against `⊥-elim` * tightened `import`s * added two operations `∃∈` and `∀∈` * added to `CHANGELOG` * knock-on for the `Propositional` case * refactor `lose∘find` and `find∘lose` in terms of new lemmas `∃∈-Any∘find` and `find∘∃∈-Any` * `CHANGELOG` * reorder * knock-on viscosity * knock-on viscosity; plus refactoring of `×↔` for intelligibility * knock-on viscosity * tightened `import`s * misc. import and other tweaks * misc. import and other tweaks * misc. import and other tweaks * removed spurious module name * better definition of `find` * make intermediate terms explicit in proof of `to∘from` * tweaks * Update Setoid.agda Remove redundant import of `index` from `Any` * Update Setoid.agda Removed more redundant `import`ed operations * Update Properties.agda Another redundant `import` * Update Properties.agda Another redundant `import`ed operation * `with` into `let` * `with` into `let` * `with` into `let` * `with` into `let` * indentation * fix `universal-U` * added `map-cong` * deprecate `map-compose` in favour of `map-∘` * explicit `let` in statement of `find∘map` * knock-on viscosity: hide `map-cong` * use of `Product.map₁` * revert use of `Product.map₁` * inlined lemmas! * alpha conversion and further inlining! * correctted use of `Product.map₂` * added `syntax` declarations for the new combinators * remove`⊥-elim` * reordered `CHANGELOG` * revise combinator names * tighten `import`s * tighten `import`s * fixed merge conflict bug * removed new syntax * knock-on
1 parent 4018fef commit 891d50f

File tree

11 files changed

+319
-276
lines changed

11 files changed

+319
-276
lines changed

CHANGELOG.md

+40-24
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,9 @@ Deprecated names
8282
scanl-defn ↦ Data.List.Scans.Properties.scanl-defn
8383
```
8484

85-
* In `Data.List.NonEmpty.Base`:
86-
```agda
87-
inits : List A → List⁺ (List A)
88-
tails : List A → List⁺ (List A)
89-
```
90-
91-
* In `Data.List.NonEmpty.Properties`:
85+
* In `Data.List.Relation.Unary.All.Properties`:
9286
```agda
93-
toList-inits : toList ∘ List⁺.inits ≗ List.inits
94-
toList-tails : toList ∘ List⁺.tails ≗ List.tails
87+
map-compose ↦ map-∘
9588
```
9689

9790
* In `Data.Nat.Divisibility.Core`:
@@ -412,6 +405,12 @@ Additions to existing modules
412405
tail∘tails : List A → List (List A)
413406
```
414407

408+
* In `Data.List.Membership.Propositional.Properties.Core`:
409+
```agda
410+
find∘∃∈-Any : (p : ∃ λ x → x ∈ xs × P x) → find (∃∈-Any p) ≡ p
411+
∃∈-Any∘find : (p : Any P xs) → ∃∈-Any (find p) ≡ p
412+
```
413+
415414
* In `Data.List.Membership.Setoid.Properties`:
416415
```agda
417416
reverse⁺ : x ∈ xs → x ∈ reverse xs
@@ -424,6 +423,12 @@ Additions to existing modules
424423
tails : List A → List⁺ (List A)
425424
```
426425

426+
* In `Data.List.NonEmpty.Properties`:
427+
```agda
428+
toList-inits : toList ∘ List⁺.inits ≗ List.inits
429+
toList-tails : toList ∘ List⁺.tails ≗ List.tails
430+
```
431+
427432
* In `Data.List.Properties`:
428433
```agda
429434
length-catMaybes : length (catMaybes xs) ≤ length xs
@@ -477,6 +482,21 @@ Additions to existing modules
477482
mapMaybeIsInj₂∘mapInj₁ : mapMaybe isInj₂ (map inj₁ xs) ≡ []
478483
```
479484

485+
* In `Data.List.Relation.Binary.Pointwise.Base`:
486+
```agda
487+
unzip : Pointwise (R ; S) ⇒ (Pointwise R ; Pointwise S)
488+
```
489+
490+
* In `Data.Maybe.Relation.Binary.Pointwise`:
491+
```agda
492+
pointwise⊆any : Pointwise R (just x) ⊆ Any (R x)
493+
```
494+
495+
* In `Data.List.Relation.Binary.Sublist.Setoid`:
496+
```agda
497+
⊆-upper-bound : ∀ {xs ys zs} (τ : xs ⊆ zs) (σ : ys ⊆ zs) → UpperBound τ σ
498+
```
499+
480500
* In `Data.List.Relation.Binary.Sublist.Setoid.Properties`:
481501
```agda
482502
⊆-trans-idˡ : (trans-reflˡ : ∀ {x y} (p : x ≈ y) → trans ≈-refl p ≡ p) →
@@ -498,6 +518,11 @@ Additions to existing modules
498518
reverse⁻ : reverse as ⊆ reverse bs → as ⊆ bs
499519
```
500520

521+
* In `Data.List.Relation.Unary.All`:
522+
```agda
523+
universal-U : Universal (All U)
524+
```
525+
501526
* In `Data.List.Relation.Unary.All.Properties`:
502527
```agda
503528
All-catMaybes⁺ : All (Maybe.All P) xs → All P (catMaybes xs)
@@ -510,6 +535,12 @@ Additions to existing modules
510535
tabulate⁺-< : (i < j → R (f i) (f j)) → AllPairs R (tabulate f)
511536
```
512537

538+
* In `Data.List.Relation.Unary.Any.Properties`:
539+
```agda
540+
map-cong : (f g : P ⋐ Q) → (∀ {x} (p : P x) → f p ≡ g p) →
541+
(p : Any P xs) → Any.map f p ≡ Any.map g p
542+
```
543+
513544
* In `Data.List.Relation.Ternary.Appending.Setoid.Properties`:
514545
```agda
515546
through→ : ∃[ xs ] Pointwise _≈_ as xs × Appending xs bs cs →
@@ -536,21 +567,6 @@ Additions to existing modules
536567
∃[ xs ] Appending Y U as bs xs × Appending V R xs cs ds
537568
```
538569

539-
* In `Data.List.Relation.Binary.Pointwise.Base`:
540-
```agda
541-
unzip : Pointwise (R ; S) ⇒ (Pointwise R ; Pointwise S)
542-
```
543-
544-
* In `Data.Maybe.Relation.Binary.Pointwise`:
545-
```agda
546-
pointwise⊆any : Pointwise R (just x) ⊆ Any (R x)
547-
```
548-
549-
* In `Data.List.Relation.Binary.Sublist.Setoid`:
550-
```agda
551-
⊆-upper-bound : ∀ {xs ys zs} (τ : xs ⊆ zs) (σ : ys ⊆ zs) → UpperBound τ σ
552-
```
553-
554570
* In `Data.Nat.Divisibility`:
555571
```agda
556572
quotient≢0 : m ∣ n → .{{NonZero n}} → NonZero quotient

src/Data/List/Membership/Propositional.agda

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
module Data.List.Membership.Propositional {a} {A : Set a} where
1111

1212
open import Data.List.Relation.Unary.Any using (Any)
13-
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; subst)
13+
open import Relation.Binary.PropositionalEquality.Core using (_≡_; _≢_; resp; subst)
1414
open import Relation.Binary.PropositionalEquality.Properties using (setoid)
1515

1616
import Data.List.Membership.Setoid as SetoidMembership
@@ -32,4 +32,4 @@ _≢∈_ x∈xs y∈xs = ∀ x≡y → subst (_∈ _) x≡y x∈xs ≢ y∈xs
3232
-- Other operations
3333

3434
lose : {p} {P : A Set p} {x xs} x ∈ xs P x Any P xs
35-
lose = SetoidMembership.lose (setoid A) (subst _)
35+
lose = SetoidMembership.lose (setoid A) (resp _)

src/Data/List/Membership/Propositional/Properties.agda

+39-40
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ module Data.List.Membership.Propositional.Properties where
1010

1111
open import Algebra.Core using (Op₂)
1212
open import Algebra.Definitions using (Selective)
13-
open import Effect.Monad using (RawMonad)
14-
open import Data.Bool.Base using (Bool; false; true; T)
1513
open import Data.Fin.Base using (Fin)
1614
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)
2016
open import Data.List.Membership.Propositional
2117
using (_∈_; _∉_; mapWith∈; _≢∈_)
2218
import Data.List.Membership.Setoid.Properties as Membership
2319
open import Data.List.Relation.Binary.Equality.Propositional
2420
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; _≤?_; <⇒≢; ≰⇒>)
2827
open import Data.Product.Base using (∃; ∃₂; _×_; _,_)
2928
open import Data.Product.Properties using (×-≡,≡↔≡)
3029
open import Data.Product.Function.NonDependent.Propositional using (_×-cong_)
3130
import Data.Product.Function.Dependent.Propositional as Σ
3231
open import Data.Sum.Base as Sum using (_⊎_; inj₁; inj₂)
32+
open import Effect.Monad using (RawMonad)
3333
open import Function.Base using (_∘_; _∘′_; _$_; id; flip; _⟨_⟩_)
3434
open import Function.Definitions using (Injective)
3535
import Function.Related.Propositional as Related
@@ -40,15 +40,14 @@ open import Level using (Level)
4040
open import Relation.Binary.Core using (Rel)
4141
open import Relation.Binary.Definitions as Binary hiding (Decidable)
4242
open import Relation.Binary.PropositionalEquality.Core as ≡
43-
using (_≡_; _≢_; refl; sym; trans; cong; cong₂; subst; _≗_)
43+
using (_≡_; _≢_; refl; sym; trans; cong; cong₂; resp; _≗_)
4444
open import Relation.Binary.PropositionalEquality.Properties as ≡ using (setoid)
4545
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)
4849
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)
5251

5352
private
5453
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
@@ -128,8 +127,9 @@ module _ {v : A} where
128127
∈-insert xs = Membership.∈-insert (≡.setoid A) xs refl
129128

130129
∈-∃++ : {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
133133

134134
------------------------------------------------------------------------
135135
-- concat
@@ -147,8 +147,9 @@ module _ {v : A} where
147147
Membership.∈-concat⁺′ (≡.setoid A) v∈vs (Any.map ≡⇒≋ vs∈xss)
148148

149149
∈-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
152153

153154
concat-∈↔ : {xss : List (List A)}
154155
(∃ λ xs v ∈ xs × xs ∈ xss) ↔ v ∈ concat xss
@@ -183,8 +184,9 @@ module _ (f : A → B → C) where
183184

184185
∈-cartesianProduct⁻ : xs ys {xy@(x , y) : A × B}
185186
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
188190

189191
------------------------------------------------------------------------
190192
-- applyUpTo
@@ -205,8 +207,7 @@ module _ (f : ℕ → A) where
205207
∈-upTo⁺ = ∈-applyUpTo⁺ id
206208

207209
∈-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
210211

211212
------------------------------------------------------------------------
212213
-- applyDownFrom
@@ -227,8 +228,7 @@ module _ (f : ℕ → A) where
227228
∈-downFrom⁺ i<n = ∈-applyDownFrom⁺ id i<n
228229

229230
∈-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
232232

233233
------------------------------------------------------------------------
234234
-- tabulate
@@ -247,10 +247,10 @@ module _ {n} {f : Fin n → A} where
247247
module _ {p} {P : A Set p} (P? : Decidable P) where
248248

249249
∈-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)
251251

252252
∈-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)
254254

255255
------------------------------------------------------------------------
256256
-- derun and deduplicate
@@ -310,7 +310,7 @@ module _ (_≈?_ : DecidableEquality A) where
310310
------------------------------------------------------------------------
311311
-- length
312312

313-
∈-length : {x : A} {xs} x ∈ xs 1 length xs
313+
∈-length : {x : A} {xs} x ∈ xs 0 < length xs
314314
∈-length = Membership.∈-length (≡.setoid _)
315315

316316
------------------------------------------------------------------------
@@ -365,28 +365,27 @@ finite inj (x ∷ xs) fᵢ∈x∷xs = ¬¬-excluded-middle helper
365365
helper (yes (i , fᵢ≡x)) = finite f′-inj xs f′ⱼ∈xs
366366
where
367367
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
371371

372372
∈-if-not-i : {j} i ≢ j f j ∈ xs
373373
∈-if-not-i i≢j = not-x (i≢j ∘ f-inj ∘ trans fᵢ≡x ∘ sym)
374374

375-
lemma : {k j} i ≤ j ¬ (i ≤ k) suc j ≢ k
375+
lemma : {k j} i ≤ j i ≰ k suc j ≢ k
376376
lemma i≤j i≰1+j refl = i≰1+j (m≤n⇒m≤1+n i≤j)
377377

378378
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)
382382

383383
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
390389

391390
f′-inj : ℕ ↣ _
392391
f′-inj = record

0 commit comments

Comments
 (0)