Skip to content

Commit 8bbaf40

Browse files
Add "Complete" predicate for lists that contain every element of a type (#1482)
1 parent 4d98151 commit 8bbaf40

File tree

4 files changed

+138
-4
lines changed

4 files changed

+138
-4
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ New modules
3333
Function.Metric.Rational.Bundles
3434
```
3535

36+
* Lists that contain every element of a type:
37+
```
38+
Data.List.Relation.Unary.Complete.Setoid
39+
Data.List.Relation.Unary.Complete.Setoid.Properties
40+
```
41+
3642
Other minor additions
3743
---------------------
3844

@@ -49,3 +55,9 @@ Other minor additions
4955
<-weakInduction : P zero → (∀ i → P (inject₁ i) → P (suc i)) → ∀ i → P i
5056
>-weakInduction : P (fromℕ n) → (∀ i → P (suc i) → P (inject₁ i)) → ∀ i → P i
5157
```
58+
59+
* Added new proofs to `Relation.Binary.Properties.Setoid`:
60+
```agda
61+
respʳ-flip : _≈_ Respectsʳ (flip _≈_)
62+
respˡ-flip : _≈_ Respectsˡ (flip _≈_)
63+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Lists which contain every element of a given type
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Data.List
10+
open import Level
11+
open import Relation.Binary
12+
13+
module Data.List.Relation.Unary.Complete.Setoid
14+
{a ℓ} (S : Setoid a ℓ) where
15+
16+
open Setoid S renaming (Carrier to A)
17+
open import Data.List.Membership.Setoid S
18+
19+
------------------------------------------------------------------------
20+
-- Definition
21+
22+
Complete : List A Set (a ⊔ ℓ)
23+
Complete xs = x x ∈ xs
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Properties of lists which contain every element of a given type
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --without-K --safe #-}
8+
9+
open import Data.Fin hiding (_≟_)
10+
open import Data.List.Base
11+
open import Data.List.Membership.Setoid.Properties as Membership
12+
open import Data.List.Relation.Unary.Any using (index)
13+
open import Data.List.Relation.Unary.Any.Properties using (lookup-index)
14+
open import Data.List.Relation.Unary.Complete.Setoid
15+
open import Data.Sum using (inj₁; inj₂)
16+
open import Data.Sum.Relation.Binary.Pointwise
17+
using (_⊎ₛ_; inj₁; inj₂)
18+
open import Data.Product using (_,_; proj₁; proj₂)
19+
open import Data.Product.Relation.Binary.Pointwise.NonDependent
20+
using (_×ₛ_)
21+
open import Function
22+
open import Level
23+
open import Relation.Binary
24+
open import Relation.Binary.PropositionalEquality using (_≡_)
25+
open import Relation.Binary.Properties.Setoid using (respʳ-flip)
26+
27+
module Data.List.Relation.Unary.Complete.Setoid.Properties where
28+
29+
open Setoid
30+
31+
private
32+
variable
33+
a b ℓ₁ ℓ₂ : Level
34+
35+
------------------------------------------------------------------------
36+
-- map
37+
38+
module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂)
39+
{f} (surj : IsSurjection (_≈_ S) (_≈_ T) f)
40+
where
41+
open IsSurjection surj
42+
43+
map⁺ : {xs} Complete S xs Complete T (map f xs)
44+
map⁺ _∈xs y with surjective y
45+
... | (x , fx≈y) = ∈-resp-≈ T fx≈y (∈-map⁺ S T cong (x ∈xs))
46+
47+
------------------------------------------------------------------------
48+
-- _++_
49+
50+
module _ (S : Setoid a ℓ₁) where
51+
52+
++⁺ˡ : {xs} ys Complete S xs Complete S (xs ++ ys)
53+
++⁺ˡ _ _∈xs v = Membership.∈-++⁺ˡ S (v ∈xs)
54+
55+
++⁺ʳ : xs {ys} Complete S ys Complete S (xs ++ ys)
56+
++⁺ʳ _ _∈ys v = Membership.∈-++⁺ʳ S _ (v ∈ys)
57+
58+
module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where
59+
60+
++⁺ : {xs ys} Complete S xs Complete T ys
61+
Complete (S ⊎ₛ T) (map inj₁ xs ++ map inj₂ ys)
62+
++⁺ _∈xs _ (inj₁ x) = ∈-++⁺ˡ (S ⊎ₛ T) (∈-map⁺ S (S ⊎ₛ T) inj₁ (x ∈xs))
63+
++⁺ _ _∈ys (inj₂ y) = ∈-++⁺ʳ (S ⊎ₛ T) _ (∈-map⁺ T (S ⊎ₛ T) inj₂ (y ∈ys))
64+
65+
------------------------------------------------------------------------
66+
-- cartesianProduct
67+
68+
module _ (S : Setoid a ℓ₁) (T : Setoid b ℓ₂) where
69+
70+
cartesianProduct⁺ : {xs ys} Complete S xs Complete T ys
71+
Complete (S ×ₛ T) (cartesianProduct xs ys)
72+
cartesianProduct⁺ _∈xs _∈ys (x , y) = ∈-cartesianProduct⁺ S T (x ∈xs) (y ∈ys)
73+
74+
------------------------------------------------------------------------
75+
-- deduplicate
76+
77+
module _ (S? : DecSetoid a ℓ₁) where
78+
open DecSetoid S? renaming (setoid to S)
79+
80+
deduplicate⁺ : {xs} Complete S xs Complete S (deduplicate _≟_ xs)
81+
deduplicate⁺ = ∈-deduplicate⁺ S _≟_ (respʳ-flip S) ∘_
82+
83+
------------------------------------------------------------------------
84+
-- lookup
85+
86+
module _ (S : Setoid a ℓ₁) where
87+
88+
lookup-surjective : {xs} Complete S xs
89+
Surjective {A = Fin (length xs)} _≡_ (_≈_ S) (lookup xs)
90+
lookup-surjective _∈xs y = index (y ∈xs) , sym S (lookup-index (y ∈xs))

src/Relation/Binary/Properties/Setoid.agda

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66

77
{-# OPTIONS --without-K --safe #-}
88

9+
open import Data.Product using (_,_)
10+
open import Function.Base using (_∘_; _$_; flip)
11+
open import Relation.Nullary using (¬_)
12+
open import Relation.Binary.PropositionalEquality as P using (_≡_)
913
open import Relation.Binary
1014

1115
module Relation.Binary.Properties.Setoid {a ℓ} (S : Setoid a ℓ) where
1216

1317
open Setoid S
1418

15-
open import Data.Product using (_,_)
16-
open import Function.Base using (_∘_; _$_)
17-
open import Relation.Nullary using (¬_)
18-
open import Relation.Binary.PropositionalEquality as P using (_≡_)
1919

2020
------------------------------------------------------------------------------
2121
-- Every setoid is a preorder with respect to propositional equality
@@ -46,3 +46,12 @@ preorder = record
4646

4747
≉-resp₂ : _≉_ Respects₂ _≈_
4848
≉-resp₂ = ≉-respʳ , ≉-respˡ
49+
50+
------------------------------------------------------------------------------
51+
-- Other properties
52+
53+
respʳ-flip : _≈_ Respectsʳ (flip _≈_)
54+
respʳ-flip y≈z x≈z = trans x≈z (sym y≈z)
55+
56+
respˡ-flip : _≈_ Respectsˡ (flip _≈_)
57+
respˡ-flip = trans

0 commit comments

Comments
 (0)