Skip to content

Commit cafc3db

Browse files
Transfer across some proofs to Permutation.Setoid and deprecate Permutation.Inductive (#820)
1 parent ec8ace1 commit cafc3db

File tree

14 files changed

+974
-574
lines changed

14 files changed

+974
-574
lines changed

CHANGELOG.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ New modules
121121
Data.List.Relation.Binary.Disjoint.Setoid
122122
Data.List.Relation.Binary.Disjoint.Setoid.Properties
123123
124-
Data.List.Relation.Binary.Permutation.Setoid
125124
Data.List.Relation.Binary.Permutation.Homogeneous
125+
Data.List.Relation.Binary.Permutation.Setoid
126+
Data.List.Relation.Binary.Permutation.Setoid.Properties
126127
127128
Data.List.Relation.Unary.AllPairs
128129
Data.List.Relation.Unary.AllPairs.Properties
@@ -201,6 +202,10 @@ been attached to all deprecated names.
201202
moved to `Data.Vec.Recursive` to make place for properly heterogeneous
202203
n-ary products in `Data.Product.Nary`.
203204

205+
* The modules `Data.List.Relation.Binary.Permutation.Inductive(.Properties)`
206+
have been renamed `Data.List.Relation.Binary.Permutation.Propositional(.Properties)`
207+
to match the rest of the library.
208+
204209
#### Names
205210

206211
* In `Algebra.Properties.BooleanAlgebra`:
@@ -552,11 +557,17 @@ Other minor additions
552557
foldr-preservesᵒ : (P x ⊎ P y → P (f x y)) → P e ⊎ Any P xs → P (foldr f e xs)
553558
```
554559

555-
* Defined a new utility in `Data.List.Relation.Binary.Permutation.Inductive.Properties`:
560+
* Added a new proof in `Data.List.Relation.Binary.Permutation.Propositional.Properties`:
556561
```agda
557562
shifts : xs ++ ys ++ zs ↭ ys ++ xs ++ zs
558563
```
559564

565+
* Added new proofs to `Data.List.Relation.Binary.Pointwise`:
566+
```agda
567+
++-cancelˡ : Pointwise _∼_ (xs ++ ys) (xs ++ zs) → Pointwise _∼_ ys zs
568+
++-cancelʳ : Pointwise _∼_ (ys ++ xs) (zs ++ xs) → Pointwise _∼_ ys zs
569+
```
570+
560571
* Added new proof to `Data.List.Relation.Binary.Sublist.Heterogeneous.Properties`:
561572
```agda
562573
concat⁺ : Sublist (Sublist R) ass bss → Sublist R (concat ass) (concat bss)
@@ -597,7 +608,7 @@ Other minor additions
597608
```agda
598609
Any-Σ⁺ʳ : (∃ λ x → Any (_~ x) xs) → Any (∃ ∘ _~_) xs
599610
Any-Σ⁻ʳ : Any (∃ ∘ _~_) xs → ∃ λ x → Any (_~ x) xs
600-
gmap : P ⋐ Q ∘ f → Any P ⋐ Any Q ∘ map f
611+
gmap : P ⋐ Q ∘ f → Any P ⋐ Any Q ∘ map f
601612
```
602613

603614
* Added new functions to `Data.Maybe.Base`:

src/Data/List/Relation/BagAndSetEquality.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-- The Agda standard library
33
--
44
-- This module is DEPRECATED. Please use
5-
-- Data.List.Relation.Unary.Any.Properties directly.
5+
-- Data.List.Relation.Binary.BagAndSetEquality directly.
66
------------------------------------------------------------------------
77

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

src/Data/List/Relation/Binary/Equality/DecPropositional.agda

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- Decidable equality over lists using propositional equality
4+
-- Decidable pointwise equality over lists using propositional equality
55
------------------------------------------------------------------------
66

7+
-- Note think carefully about using this module as pointwise
8+
-- propositional equality can usually be replaced with propositional
9+
-- equality.
10+
711
{-# OPTIONS --without-K --safe #-}
812

913
open import Relation.Binary

src/Data/List/Relation/Binary/Equality/DecSetoid.agda

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- Decidable equality over lists parameterised by some setoid
4+
-- Pointwise decidable equality over lists parameterised by a setoid
55
------------------------------------------------------------------------
66

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

src/Data/List/Relation/Binary/Equality/Propositional.agda

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- Equality over lists using propositional equality
4+
-- Pointwise equality over lists using propositional equality
55
------------------------------------------------------------------------
66

7+
-- Note think carefully about using this module as pointwise
8+
-- propositional equality can usually be replaced with propositional
9+
-- equality.
10+
711
{-# OPTIONS --without-K --safe #-}
812

913
open import Relation.Binary
@@ -15,7 +19,7 @@ import Data.List.Relation.Binary.Equality.Setoid as SetoidEquality
1519
open import Relation.Binary.PropositionalEquality as P using (_≡_)
1620

1721
------------------------------------------------------------------------
18-
-- Publically re-export everything from setoid equality
22+
-- Re-export everything from setoid equality
1923

2024
open SetoidEquality (P.setoid A) public
2125

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

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- Equality over lists parameterised by some setoid
4+
-- Pointwise equality over lists parameterised by a setoid
55
------------------------------------------------------------------------
66

77
{-# OPTIONS --without-K --safe #-}
@@ -10,26 +10,36 @@ open import Relation.Binary using (Setoid)
1010

1111
module Data.List.Relation.Binary.Equality.Setoid {a ℓ} (S : Setoid a ℓ) where
1212

13-
open import Data.List.Base using (List)
13+
open import Data.Fin
14+
open import Data.List.Base
15+
open import Data.List.Relation.Binary.Pointwise as PW using (Pointwise)
16+
open import Function using (_∘_)
1417
open import Level
1518
open import Relation.Binary renaming (Rel to Rel₂)
1619
open import Relation.Binary.PropositionalEquality as P using (_≡_)
17-
open import Data.List.Relation.Binary.Pointwise as PW using (Pointwise)
20+
open import Relation.Unary as U using (Pred)
1821

1922
open Setoid S renaming (Carrier to A)
2023

24+
private
25+
variable
26+
p q : Level
27+
2128
------------------------------------------------------------------------
2229
-- Definition of equality
30+
------------------------------------------------------------------------
2331

2432
infix 4 _≋_
2533

2634
_≋_ : Rel₂ (List A) (a ⊔ ℓ)
2735
_≋_ = Pointwise _≈_
2836

29-
open Pointwise public using ([]; _∷_)
37+
open Pointwise public
38+
using ([]; _∷_)
3039

3140
------------------------------------------------------------------------
3241
-- Relational properties
42+
------------------------------------------------------------------------
3343

3444
≋-refl : Reflexive _≋_
3545
≋-refl = PW.refl refl
@@ -50,11 +60,68 @@ open Pointwise public using ([]; _∷_)
5060
≋-setoid = PW.setoid S
5161

5262
------------------------------------------------------------------------
53-
-- Operations
63+
-- List Operations
64+
------------------------------------------------------------------------
65+
66+
------------------------------------------------------------------------
67+
-- length
68+
69+
≋-length : {xs ys} xs ≋ ys length xs ≡ length ys
70+
≋-length = PW.Pointwise-length
71+
72+
------------------------------------------------------------------------
73+
-- map
74+
75+
module _ {b ℓ₂} (T : Setoid b ℓ₂) where
76+
77+
open Setoid T using () renaming (_≈_ to _≈′_)
78+
private
79+
_≋′_ = Pointwise _≈′_
80+
81+
map⁺ : {f} f Preserves _≈_ ⟶ _≈′_
82+
{xs ys} xs ≋ ys map f xs ≋′ map f ys
83+
map⁺ {f} pres xs≋ys = PW.map⁺ f f (PW.map pres xs≋ys)
84+
85+
------------------------------------------------------------------------
86+
-- _++_
87+
88+
++⁺ : {ws xs ys zs} ws ≋ xs ys ≋ zs ws ++ ys ≋ xs ++ zs
89+
++⁺ = PW.++⁺
90+
91+
++-cancelˡ : xs {ys zs} xs ++ ys ≋ xs ++ zs ys ≋ zs
92+
++-cancelˡ = PW.++-cancelˡ
93+
94+
++-cancelʳ : {xs} ys zs ys ++ xs ≋ zs ++ xs ys ≋ zs
95+
++-cancelʳ = PW.++-cancelʳ
96+
97+
------------------------------------------------------------------------
98+
-- concat
99+
100+
concat⁺ : {xss yss} Pointwise _≋_ xss yss concat xss ≋ concat yss
101+
concat⁺ = PW.concat⁺
102+
103+
------------------------------------------------------------------------
104+
-- tabulate
105+
106+
tabulate⁺ : {n} {f : Fin n A} {g : Fin n A}
107+
( i f i ≈ g i) tabulate f ≋ tabulate g
108+
tabulate⁺ = PW.tabulate⁺
109+
110+
tabulate⁻ : {n} {f : Fin n A} {g : Fin n A}
111+
tabulate f ≋ tabulate g ( i f i ≈ g i)
112+
tabulate⁻ = PW.tabulate⁻
113+
114+
------------------------------------------------------------------------
115+
-- filter
116+
117+
module _ {P : Pred A p} (P? : U.Decidable P) (resp : P Respects _≈_)
118+
where
119+
120+
filter⁺ : {xs ys} xs ≋ ys filter P? xs ≋ filter P? ys
121+
filter⁺ xs≋ys = PW.filter⁺ P? P? resp (resp ∘ sym) xs≋ys
122+
123+
------------------------------------------------------------------------
124+
-- filter
54125

55-
open PW public using
56-
( tabulate⁺
57-
; tabulate⁻
58-
; ++⁺
59-
; concat⁺
60-
)
126+
reverse⁺ : {xs ys} xs ≋ ys reverse xs ≋ reverse ys
127+
reverse⁺ = PW.reverse⁺

src/Data/List/Relation/Binary/Permutation/Homogeneous.agda

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,38 @@ private
1717
a r s : Level
1818
A : Set a
1919

20-
data Permutation (R : Rel {a} A r) : Rel (List A) (a ⊔ r) where
21-
refl : {xs} Permutation R xs xs
22-
prep : {xs ys} {x} {x'} (eq : R x x') Permutation R xs ys
23-
Permutation R (x ∷ xs) (x' ∷ ys)
24-
swap : {xs ys} {x} {y} {x'} {y'} (eq₁ : R x x') (eq₂ : R y y')
25-
Permutation R xs ys Permutation R (x ∷ y ∷ xs) (y' ∷ x' ∷ ys)
20+
data Permutation {A : Set a} (R : Rel A r) : Rel (List A) (a ⊔ r) where
21+
refl : {xs} Permutation R xs xs
22+
prep : {xs ys x y} (eq : R x y) Permutation R xs ys Permutation R (x ∷ xs) (y ∷ ys)
23+
swap : {xs ys x y x' y'} (eq₁ : R x x') (eq₂ : R y y') Permutation R xs ys Permutation R (x ∷ y ∷ xs) (y' ∷ x' ∷ ys)
2624
trans : {xs ys zs} Permutation R xs ys Permutation R ys zs Permutation R xs zs
2725

2826
------------------------------------------------------------------------
2927
-- The Permutation relation is an equivalence
3028

31-
module _ {R : Rel A r} (R-sym : Symmetric R) where
29+
module _ {R : Rel A r} where
3230

33-
sym : Symmetric (Permutation R)
34-
sym refl = refl
35-
sym (prep x∼x' xs↭ys) = prep (R-sym x∼x') (sym xs↭ys)
36-
sym (swap x∼x' y∼y' xs↭ys) = swap (R-sym y∼y') (R-sym x∼x') (sym xs↭ys)
37-
sym (trans xs↭ys ys↭zs) = trans (sym ys↭zs) (sym xs↭ys)
31+
sym : Symmetric R Symmetric (Permutation R)
32+
sym R-sym refl = refl
33+
sym R-sym (prep x∼x' xs↭ys) = prep (R-sym x∼x') (sym R-sym xs↭ys)
34+
sym R-sym (swap x∼x' y∼y' xs↭ys) = swap (R-sym y∼y') (R-sym x∼x') (sym R-sym xs↭ys)
35+
sym R-sym (trans xs↭ys ys↭zs) = trans (sym R-sym ys↭zs) (sym R-sym xs↭ys)
3836

39-
isEquivalence : IsEquivalence (Permutation R)
40-
isEquivalence = record
37+
isEquivalence : Symmetric R IsEquivalence (Permutation R)
38+
isEquivalence R-sym = record
4139
{ refl = refl
42-
; sym = sym
40+
; sym = sym R-sym
4341
; trans = trans
4442
}
4543

46-
setoid : Setoid _ _
47-
setoid = record
48-
{ isEquivalence = isEquivalence
44+
setoid : Symmetric R Setoid _ _
45+
setoid R-sym = record
46+
{ isEquivalence = isEquivalence R-sym
4947
}
5048

5149
map : {R : Rel A r} {S : Rel A s}
5250
(R ⇒ S) (Permutation R ⇒ Permutation S)
53-
map R⇒S refl = refl
54-
map R⇒S (prep eq xs∼ys) = prep (R⇒S eq) (map R⇒S xs∼ys)
55-
map R⇒S (swap eq₁ eq₂ xs∼ys) = swap (R⇒S eq₁) (R⇒S eq₂) (map R⇒S xs∼ys)
56-
map R⇒S (trans xs∼ys ys∼zs) = trans (map R⇒S xs∼ys) (map R⇒S ys∼zs)
51+
map R⇒S refl = refl
52+
map R⇒S (prep e xs∼ys) = prep (R⇒S e) (map R⇒S xs∼ys)
53+
map R⇒S (swap e₁ e₂ xs∼ys) = swap (R⇒S e₁) (R⇒S e₂) (map R⇒S xs∼ys)
54+
map R⇒S (trans xs∼ys ys∼zs) = trans (map R⇒S xs∼ys) (map R⇒S ys∼zs)
Lines changed: 4 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,12 @@
11
------------------------------------------------------------------------
22
-- The Agda standard library
33
--
4-
-- An inductive definition for the permutation relation
4+
-- This module is DEPRECATED. Please use
5+
-- Data.List.Relation.Binary.Permutation.Propositional directly.
56
------------------------------------------------------------------------
67

78
{-# OPTIONS --without-K --safe #-}
89

9-
module Data.List.Relation.Binary.Permutation.Inductive
10-
{a} {A : Set a} where
10+
module Data.List.Relation.Binary.Permutation.Inductive where
1111

12-
open import Data.List using (List; []; _∷_)
13-
open import Relation.Binary
14-
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
15-
import Relation.Binary.Reasoning.Setoid as EqReasoning
16-
17-
------------------------------------------------------------------------
18-
-- An inductive definition of permutation
19-
20-
infix 3 _↭_
21-
22-
data _↭_ : Rel (List A) a where
23-
refl : {xs} xs ↭ xs
24-
prep : {xs ys} x xs ↭ ys x ∷ xs ↭ x ∷ ys
25-
swap : {xs ys} x y xs ↭ ys x ∷ y ∷ xs ↭ y ∷ x ∷ ys
26-
trans : {xs ys zs} xs ↭ ys ys ↭ zs xs ↭ zs
27-
28-
------------------------------------------------------------------------
29-
-- _↭_ is an equivalence
30-
31-
↭-reflexive : _≡_ ⇒ _↭_
32-
↭-reflexive refl = refl
33-
34-
↭-refl : Reflexive _↭_
35-
↭-refl = refl
36-
37-
↭-sym : {xs ys} xs ↭ ys ys ↭ xs
38-
↭-sym refl = refl
39-
↭-sym (prep x xs↭ys) = prep x (↭-sym xs↭ys)
40-
↭-sym (swap x y xs↭ys) = swap y x (↭-sym xs↭ys)
41-
↭-sym (trans xs↭ys ys↭zs) = trans (↭-sym ys↭zs) (↭-sym xs↭ys)
42-
43-
↭-trans : Transitive _↭_
44-
↭-trans = trans
45-
46-
↭-isEquivalence : IsEquivalence _↭_
47-
↭-isEquivalence = record
48-
{ refl = refl
49-
; sym = ↭-sym
50-
; trans = trans
51-
}
52-
53-
↭-setoid : Setoid _ _
54-
↭-setoid = record
55-
{ isEquivalence = ↭-isEquivalence
56-
}
57-
58-
------------------------------------------------------------------------
59-
-- A reasoning API to chain permutation proofs and allow "zooming in"
60-
-- to localised reasoning.
61-
62-
module PermutationReasoning where
63-
64-
open EqReasoning ↭-setoid
65-
using (_IsRelatedTo_; relTo)
66-
67-
open EqReasoning ↭-setoid public
68-
using (begin_ ; _∎ ; _≡⟨⟩_; _≡⟨_⟩_)
69-
renaming (_≈⟨_⟩_ to _↭⟨_⟩_; _≈˘⟨_⟩_ to _↭˘⟨_⟩_)
70-
71-
infixr 2 _∷_<⟨_⟩_ _∷_∷_<<⟨_⟩_
72-
73-
-- Skip reasoning on the first element
74-
_∷_<⟨_⟩_ : x xs {ys zs : List A} xs ↭ ys
75-
(x ∷ ys) IsRelatedTo zs (x ∷ xs) IsRelatedTo zs
76-
x ∷ xs <⟨ xs↭ys ⟩ rel = relTo (trans (prep x xs↭ys) (begin rel))
77-
78-
-- Skip reasoning about the first two elements
79-
_∷_∷_<<⟨_⟩_ : x y xs {ys zs : List A} xs ↭ ys
80-
(y ∷ x ∷ ys) IsRelatedTo zs (x ∷ y ∷ xs) IsRelatedTo zs
81-
x ∷ y ∷ xs <<⟨ xs↭ys ⟩ rel = relTo (trans (swap x y xs↭ys) (begin rel))
12+
open import Data.List.Relation.Binary.Permutation.Propositional public

0 commit comments

Comments
 (0)