Skip to content

Commit 651a6b6

Browse files
Add various lemmas about list relations (#1382)
1 parent b0cb9b3 commit 651a6b6

File tree

17 files changed

+352
-57
lines changed

17 files changed

+352
-57
lines changed

CHANGELOG.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ New modules
236236
Data.List.Relation.Binary.Suffix.Homogeneous.Properties
237237
```
238238

239+
* Properties of lists with decidably unique elements:
240+
```
241+
Data.List.Relation.Unary.Unique.DecSetoid
242+
Data.List.Relation.Unary.Unique.DecSetoid.Properties
243+
Data.List.Relation.Unary.Unique.DecPropositional
244+
Data.List.Relation.Unary.Unique.DecPropositional.Properties
245+
```
246+
239247
* Added bindings for Haskell's `System.Environment`:
240248
```
241249
System.Environment
@@ -429,12 +437,12 @@ Other minor additions
429437
xs ⊉ ys = ¬ xs ⊇ ys
430438
```
431439

432-
* Added new proofs in `Data.List.Relation.Binary.Subset.Propositional.Properties`:
440+
* Added new proofs in `Data.List.Relation.Binary.Subset.Setoid.Properties`:
433441
```agda
434442
⊆-respʳ-≋ : _⊆_ Respectsʳ _≋_
435443
⊆-respˡ-≋ : _⊆_ Respectsˡ _≋_
436444
437-
↭⇒⊆ : _↭_ ⇒ _⊆_
445+
⊆-reflexive-↭ : _↭_ ⇒ _⊆_
438446
⊆-respʳ-↭ : _⊆_ Respectsʳ _↭_
439447
⊆-respˡ-↭ : _⊆_ Respectsˡ _↭_
440448
⊆-↭-isPreorder : IsPreorder _↭_ _⊆_
@@ -448,23 +456,36 @@ Other minor additions
448456
++⁺ʳ : xs ⊆ ys → zs ++ xs ⊆ zs ++ ys
449457
++⁺ˡ : xs ⊆ ys → xs ++ zs ⊆ ys ++ zs
450458
++⁺ : ws ⊆ xs → ys ⊆ zs → ws ++ ys ⊆ xs ++ zs
459+
460+
filter⁺′ : P ⋐ Q → xs ⊆ ys → filter P? xs ⊆ filter Q? ys
451461
```
452462

453463
* Added new proofs in `Data.List.Relation.Binary.Subset.Propositional.Properties`:
454464
```agda
455-
↭⇒⊆ : _↭_ ⇒ _⊆_
465+
⊆-reflexive-↭ : _↭_ ⇒ _⊆_
456466
⊆-respʳ-↭ : _⊆_ Respectsʳ _↭_
457467
⊆-respˡ-↭ : _⊆_ Respectsˡ _↭_
458468
⊆-↭-isPreorder : IsPreorder _↭_ _⊆_
459469
⊆-↭-preorder : Preorder _ _ _
460470
461471
Any-resp-⊆ : (Any P) Respects _⊆_
462472
All-resp-⊇ : (All P) Respects _⊇_
473+
Sublist⇒Subset : xs ⊑ ys → xs ⊆ ys
463474
464475
xs⊆xs++ys : xs ⊆ xs ++ ys
465476
xs⊆ys++xs : xs ⊆ ys ++ xs
466477
++⁺ʳ : xs ⊆ ys → zs ++ xs ⊆ zs ++ ys
467478
++⁺ˡ : xs ⊆ ys → xs ++ zs ⊆ ys ++ zs
479+
480+
filter⁺′ : P ⋐ Q → xs ⊆ ys → filter P? xs ⊆ filter Q? ys
481+
```
482+
483+
* Added new relations to `Data.List.Relation.Binary.Sublist.(Setoid/Propositional)`:
484+
```agda
485+
xs ⊂ ys = xs ⊆ ys × ¬ (xs ≋ ys)
486+
xs ⊃ ys = ys ⊂ xs
487+
xs ⊄ ys = ¬ (xs ⊂ ys)
488+
xs ⊅ ys = ¬ (xs ⊃ ys)
468489
```
469490

470491
* Added new proof in `Data.List.Relation.Binary.Permutation.Propositional.Properties`:
@@ -477,6 +498,40 @@ Other minor additions
477498
++↭ʳ++ : xs ++ ys ↭ xs ʳ++ ys
478499
```
479500

501+
* Added new proofs in `Data.List.Extrema`:
502+
```agda
503+
min-mono-⊆ : ⊥₁ ≤ ⊥₂ → xs ⊇ ys → min ⊥₁ xs ≤ min ⊥₂ ys
504+
max-mono-⊆ : ⊥₁ ≤ ⊥₂ → xs ⊆ ys → max ⊥₁ xs ≤ max ⊥₂ ys
505+
```
506+
507+
* Added new operator in `Data.List.Membership.DecSetoid`:
508+
```agda
509+
_∉?_ : Decidable _∉_
510+
```
511+
512+
* Added new proofs in `Data.List.Relation.Unary.Any.Properties`:
513+
```agda
514+
lookup-index : (p : Any P xs) → P (lookup xs (index p))
515+
applyDownFrom⁺ : P (f i) → i < n → Any P (applyDownFrom f n)
516+
applyDownFrom⁻ : Any P (applyDownFrom f n) → ∃ λ i → i < n × P (f i)
517+
```
518+
519+
* Added new proofs in `Data.List.Membership.Setoid.Properties`:
520+
```agda
521+
∈-applyDownFrom⁺ : i < n → f i ∈ applyDownFrom f n
522+
∈-applyDownFrom⁻ : v ∈ applyDownFrom f n → ∃ λ i → i < n × v ≈ f i
523+
```
524+
525+
* Added new proofs in `Data.List.Membership.Propositional.Properties`:
526+
```agda
527+
∈-applyDownFrom⁺ : i < n → f i ∈ applyDownFrom f n
528+
∈-applyDownFrom⁻ : v ∈ applyDownFrom f n → ∃ λ i → i < n × v ≡ f i
529+
∈-upTo⁺ : i < n → i ∈ upTo n
530+
∈-upTo⁻ : i ∈ upTo n → i < n
531+
∈-downFrom⁺ : i < n → i ∈ downFrom n
532+
∈-downFrom⁻ : i ∈ downFrom n → i < n
533+
```
534+
480535
* Added new definition in `Data.Nat.Base`:
481536
```agda
482537
_≤ᵇ_ : (m n : ℕ) → Bool
@@ -657,3 +712,8 @@ Other minor additions
657712
intersection : ⟨Set⟩ → ⟨Set⟩ → ⟨Set⟩
658713
intersections : List ⟨Set⟩ → ⟨Set⟩
659714
```
715+
716+
* Added new proof to `Relation.Binary.PropositionalEquality`:
717+
```agda
718+
resp : (P : Pred A ℓ) → P Respects _≡_
719+
```

src/Data/List/Base.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ applyUpTo f zero = []
200200
applyUpTo f (suc n) = f zero ∷ applyUpTo (f ∘ suc) n
201201

202202
applyDownFrom : (ℕ A) List A
203-
applyDownFrom f zero = []
203+
applyDownFrom f zero = []
204204
applyDownFrom f (suc n) = f n ∷ applyDownFrom f n
205205

206206
tabulate : {n} (f : Fin n A) List A

src/Data/List/Extrema.agda

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ open import Data.List.Relation.Unary.All using (All; []; _∷_; lookup; map; tab
1919
open import Data.List.Membership.Propositional using (_∈_; lose)
2020
open import Data.List.Membership.Propositional.Properties
2121
using (foldr-selective)
22-
open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_)
22+
open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_; _⊇_)
2323
open import Data.List.Properties
2424
open import Data.Sum.Base using (_⊎_; inj₁; inj₂)
25-
open import Function.Base using (id; flip; _on_)
25+
open import Function.Base using (id; flip; _on_; _∘_)
2626
open import Level using (Level)
2727
open import Relation.Unary using (Pred)
2828
import Relation.Binary.Construct.NonStrictToStrict as NonStrictToStrict
@@ -205,6 +205,10 @@ min[xs]<min[ys]⁺ : ∀ ⊤₁ {⊤₂} xs {ys} → (⊤₁ < ⊤₂) ⊎ Any (
205205
min ⊤₁ xs < min ⊤₂ ys
206206
min[xs]<min[ys]⁺ = argmin[xs]<argmin[ys]⁺
207207

208+
min-mono-⊆ : {⊥₁ ⊥₂ xs ys} ⊥₁ ≤ ⊥₂ xs ⊇ ys min ⊥₁ xs ≤ min ⊥₂ ys
209+
min-mono-⊆ ⊥₁≤⊥₂ ys⊆xs = min[xs]≤min[ys]⁺ _ _ (inj₁ ⊥₁≤⊥₂)
210+
(tabulate (inj₂ ∘ Any.map (λ {≡-refl refl}) ∘ ys⊆xs))
211+
208212
------------------------------------------------------------------------------
209213
-- Properties of max
210214

@@ -238,3 +242,7 @@ max[xs]<max[ys]⁺ : ∀ {⊥₁} ⊥₂ {xs} ys → ⊥₁ < ⊥₂ ⊎ Any (
238242
All (λ x x < ⊥₂ ⊎ Any (x <_) ys) xs
239243
max ⊥₁ xs < max ⊥₂ ys
240244
max[xs]<max[ys]⁺ = argmax[xs]<argmax[ys]⁺
245+
246+
max-mono-⊆ : {⊥₁ ⊥₂ xs ys} ⊥₁ ≤ ⊥₂ xs ⊆ ys max ⊥₁ xs ≤ max ⊥₂ ys
247+
max-mono-⊆ ⊥₁≤⊥₂ xs⊆ys = max[xs]≤max[ys]⁺ _ _ (inj₁ ⊥₁≤⊥₂)
248+
(tabulate (inj₂ ∘ Any.map (λ {≡-refl refl}) ∘ xs⊆ys))

src/Data/List/Membership/DecPropositional.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ module Data.List.Membership.DecPropositional
1717

1818
open import Data.List.Membership.Propositional {A = A} public
1919
open import Data.List.Membership.DecSetoid (decSetoid _≟_) public
20-
using (_∈?_)
20+
using (_∈?_; _∉?_)
2121

src/Data/List/Membership/DecSetoid.agda

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
{-# OPTIONS --without-K --safe #-}
88

99
open import Relation.Binary using (Decidable; DecSetoid)
10+
open import Relation.Nullary.Negation using (¬?)
1011

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

@@ -21,7 +22,10 @@ open import Data.List.Membership.Setoid (DecSetoid.setoid DS) public
2122
------------------------------------------------------------------------
2223
-- Other operations
2324

24-
infix 4 _∈?_
25+
infix 4 _∈?_ _∉?_
2526

2627
_∈?_ : Decidable _∈_
2728
x ∈? xs = any? (x ≟_) xs
29+
30+
_∉?_ : Decidable _∉_
31+
x ∉? xs = ¬? (x ∈? xs)

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,38 @@ module _ (f : ℕ → A) where
185185
λ i i < n × v ≡ f i
186186
∈-applyUpTo⁻ = Membershipₛ.∈-applyUpTo⁻ (P.setoid _) f
187187

188+
------------------------------------------------------------------------
189+
-- upTo
190+
191+
∈-upTo⁺ : {n i} i < n i ∈ upTo n
192+
∈-upTo⁺ = ∈-applyUpTo⁺ id
193+
194+
∈-upTo⁻ : {n i} i ∈ upTo n i < n
195+
∈-upTo⁻ p with ∈-applyUpTo⁻ id p
196+
... | _ , i<n , refl = i<n
197+
198+
------------------------------------------------------------------------
199+
-- applyDownFrom
200+
201+
module _ (f : A) where
202+
203+
∈-applyDownFrom⁺ : {i n} i < n f i ∈ applyDownFrom f n
204+
∈-applyDownFrom⁺ = Membershipₛ.∈-applyDownFrom⁺ (P.setoid _) f
205+
206+
∈-applyDownFrom⁻ : {v n} v ∈ applyDownFrom f n
207+
λ i i < n × v ≡ f i
208+
∈-applyDownFrom⁻ = Membershipₛ.∈-applyDownFrom⁻ (P.setoid _) f
209+
210+
------------------------------------------------------------------------
211+
-- downFrom
212+
213+
∈-downFrom⁺ : {n i} i < n i ∈ downFrom n
214+
∈-downFrom⁺ i<n = ∈-applyDownFrom⁺ id i<n
215+
216+
∈-downFrom⁻ : {n i} i ∈ downFrom n i < n
217+
∈-downFrom⁻ p with ∈-applyDownFrom⁻ id p
218+
... | _ , i<n , refl = i<n
219+
188220
------------------------------------------------------------------------
189221
-- tabulate
190222

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,16 @@ module _ (S : Setoid c ℓ) where
255255
λ i i < n × v ≈ f i
256256
∈-applyUpTo⁻ = Any.applyUpTo⁻
257257

258+
------------------------------------------------------------------------
259+
-- applyDownFrom
260+
261+
∈-applyDownFrom⁺ : f {i n} i < n f i ∈ applyDownFrom f n
262+
∈-applyDownFrom⁺ f = Any.applyDownFrom⁺ f refl
263+
264+
∈-applyDownFrom⁻ : {v} f {n} v ∈ applyDownFrom f n
265+
λ i i < n × v ≈ f i
266+
∈-applyDownFrom⁻ = Any.applyDownFrom⁻
267+
258268
------------------------------------------------------------------------
259269
-- tabulate
260270

src/Data/List/Relation/Binary/Sublist/Setoid.agda

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import Data.List.Relation.Binary.Sublist.Heterogeneous.Core
2323
as HeterogeneousCore
2424
import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties
2525
as HeterogeneousProperties
26-
open import Data.Product using (∃; ∃₂; _,_; proj₂)
26+
open import Data.Product using (∃; ∃₂; _×_; _,_; proj₂)
2727

2828
open import Relation.Binary
2929
open import Relation.Binary.PropositionalEquality as P using (_≡_)
@@ -35,30 +35,50 @@ open SetoidEquality S
3535
------------------------------------------------------------------------
3636
-- Definition
3737

38-
infix 4 _⊆_ _⊇_ _⊈_ _⊉_
38+
infix 4 _⊆_ _⊇_ _⊂_ _⊃_ _⊈_ _⊉_ _⊄_ _⊅_
3939

4040
_⊆_ : Rel (List A) (c ⊔ ℓ)
4141
_⊆_ = Heterogeneous.Sublist _≈_
4242

4343
_⊇_ : Rel (List A) (c ⊔ ℓ)
4444
xs ⊇ ys = ys ⊆ xs
4545

46+
_⊂_ : Rel (List A) (c ⊔ ℓ)
47+
xs ⊂ ys = xs ⊆ ys × ¬ (xs ≋ ys)
48+
49+
_⊃_ : Rel (List A) (c ⊔ ℓ)
50+
xs ⊃ ys = ys ⊂ xs
51+
4652
_⊈_ : Rel (List A) (c ⊔ ℓ)
4753
xs ⊈ ys = ¬ (xs ⊆ ys)
4854

4955
_⊉_ : Rel (List A) (c ⊔ ℓ)
5056
xs ⊉ ys = ¬ (xs ⊇ ys)
5157

58+
_⊄_ : Rel (List A) (c ⊔ ℓ)
59+
xs ⊄ ys = ¬ (xs ⊂ ys)
60+
61+
_⊅_ : Rel (List A) (c ⊔ ℓ)
62+
xs ⊅ ys = ¬ (xs ⊃ ys)
63+
5264
------------------------------------------------------------------------
5365
-- Re-export definitions and operations from heterogeneous sublists
5466

55-
open HeterogeneousCore _≈_ using ([]; _∷_; _∷ʳ_) public
56-
open Heterogeneous {R = _≈_} hiding (Sublist; []; _∷_; _∷ʳ_) public
67+
open HeterogeneousCore _≈_ public
68+
using ([]; _∷_; _∷ʳ_)
69+
70+
open Heterogeneous {R = _≈_} public
71+
hiding (Sublist; []; _∷_; _∷ʳ_)
5772
renaming
58-
(toAny to to∈; fromAny to from∈)
73+
( toAny to to∈
74+
; fromAny to from∈
75+
)
76+
77+
open Disjoint public
78+
using ([])
5979

60-
open Disjoint public using ([])
61-
open DisjointUnion public using ([])
80+
open DisjointUnion public
81+
using ([])
6282

6383
------------------------------------------------------------------------
6484
-- Relational properties holding for Setoid case

src/Data/List/Relation/Binary/Subset/Propositional/Properties.agda

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ open import Function.Inverse as Inv using (_↔_; module Inverse)
3333
open import Function.Equivalence using (module Equivalence)
3434
open import Level using (Level)
3535
open import Relation.Nullary using (¬_; yes; no)
36-
open import Relation.Unary using (Decidable; Pred)
36+
open import Relation.Unary using (Decidable; Pred) renaming (_⊆_ to _⋐_)
3737
open import Relation.Binary using (_⇒_; _Respects_)
3838
open import Relation.Binary.PropositionalEquality
39-
using (_≡_; _≗_; isEquivalence; subst; refl; setoid; module ≡-Reasoning)
39+
using (_≡_; _≗_; isEquivalence; subst; resp; refl; setoid; module ≡-Reasoning)
4040
import Relation.Binary.Reasoning.Preorder as PreorderReasoning
4141

4242
private
4343
open module ListMonad {ℓ} = RawMonad (monad {ℓ = ℓ})
4444

4545
variable
46-
a b p : Level
46+
a b p q : Level
4747
A : Set a
4848
B : Set b
4949
ws xs ys zs : List A
@@ -80,8 +80,8 @@ module _ (A : Set a) where
8080
------------------------------------------------------------------------
8181
-- See issue #1354 for why these proofs can't be taken from `Setoidₚ`
8282

83-
↭⇒⊆ : _↭_ {A = A} ⇒ _⊆_
84-
↭⇒⊆ xs↭ys = Permutation.∈-resp-↭ xs↭ys
83+
⊆-reflexive-↭ : _↭_ {A = A} ⇒ _⊆_
84+
⊆-reflexive-↭ xs↭ys = Permutation.∈-resp-↭ xs↭ys
8585

8686
⊆-respʳ-↭ : _⊆_ {A = A} Respectsʳ _↭_
8787
⊆-respʳ-↭ xs↭ys = Permutation.∈-resp-↭ xs↭ys ∘_
@@ -94,7 +94,7 @@ module _ (A : Set a) where
9494
⊆-↭-isPreorder : IsPreorder {A = List A} _↭_ _⊆_
9595
⊆-↭-isPreorder = record
9696
{ isEquivalence = ↭-isEquivalence
97-
; reflexive = ↭⇒⊆
97+
; reflexive = ⊆-reflexive-↭
9898
; trans = ⊆-trans
9999
}
100100

@@ -231,6 +231,10 @@ module _ {P : Pred A p} (P? : Decidable P) where
231231
filter-⊆ : xs filter P? xs ⊆ xs
232232
filter-⊆ = Setoidₚ.filter-⊆ (setoid A) P?
233233

234+
module _ {Q : Pred A q} (Q? : Decidable Q) where
235+
236+
filter⁺′ : P ⋐ Q {xs ys} xs ⊆ ys filter P? xs ⊆ filter Q? ys
237+
filter⁺′ = Setoidₚ.filter⁺′ (setoid A) P? (resp P) Q? (resp Q)
234238

235239

236240
------------------------------------------------------------------------

0 commit comments

Comments
 (0)