-
Notifications
You must be signed in to change notification settings - Fork 252
Refactor Data.List.Relation.Binary.Permutation.*
, part I
#2333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7ab1da5
4ece6bb
38f22e4
9399636
c6f701f
b37ba6f
791baf9
ff7845a
a3d0b8e
2950a39
69ca8fd
5f0051a
5461356
8b44fd8
7918a8d
00a335a
91feb30
227043d
4df26ef
0bf8e38
60a1958
fd80b0b
1781ea3
7c2bc35
2e032a5
4ad9fef
83dc6c7
246bf5c
39bb784
b7dff80
ce4d72f
c8bf0a6
e5701d9
a40a26f
cbef1f8
9eb7000
a5e2849
26371ae
dd296a6
7f84607
92c14a8
901310f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,14 +10,22 @@ module Data.List.Relation.Binary.Permutation.Propositional | |
{a} {A : Set a} where | ||
|
||
open import Data.List.Base using (List; []; _∷_) | ||
open import Data.List.Relation.Binary.Equality.Propositional using (_≋_; ≋⇒≡) | ||
open import Relation.Binary.Core using (Rel; _⇒_) | ||
open import Relation.Binary.Bundles using (Setoid) | ||
open import Relation.Binary.Structures using (IsEquivalence) | ||
open import Relation.Binary.Definitions using (Reflexive; Transitive) | ||
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl) | ||
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_; refl) | ||
import Relation.Binary.Reasoning.Setoid as EqReasoning | ||
open import Relation.Binary.Reasoning.Syntax | ||
|
||
import Data.List.Relation.Binary.Permutation.Setoid as Permutation | ||
|
||
private | ||
variable | ||
x y z v w : A | ||
ws xs ys zs : List A | ||
|
||
------------------------------------------------------------------------ | ||
-- An inductive definition of permutation | ||
|
||
|
@@ -30,21 +38,32 @@ open import Relation.Binary.Reasoning.Syntax | |
infix 3 _↭_ | ||
|
||
data _↭_ : Rel (List A) a where | ||
refl : ∀ {xs} → xs ↭ xs | ||
prep : ∀ {xs ys} x → xs ↭ ys → x ∷ xs ↭ x ∷ ys | ||
swap : ∀ {xs ys} x y → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys | ||
trans : ∀ {xs ys zs} → xs ↭ ys → ys ↭ zs → xs ↭ zs | ||
refl : xs ↭ xs | ||
prep : ∀ x → xs ↭ ys → x ∷ xs ↭ x ∷ ys | ||
swap : ∀ x y → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys | ||
trans : xs ↭ ys → ys ↭ zs → xs ↭ zs | ||
|
||
-- Constructor aliases | ||
|
||
↭-refl : Reflexive _↭_ | ||
↭-refl = refl | ||
|
||
↭-prep : ∀ x → xs ↭ ys → x ∷ xs ↭ x ∷ ys | ||
↭-prep = prep | ||
|
||
↭-swap : ∀ x y → xs ↭ ys → x ∷ y ∷ xs ↭ y ∷ x ∷ ys | ||
↭-swap = swap | ||
Comment on lines
+48
to
+55
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As always I am going to be annoying and complain that I don't like prefixed The same goes for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @gallais I don't find the comment annoying! As regards |
||
|
||
------------------------------------------------------------------------ | ||
-- _↭_ is an equivalence | ||
|
||
↭-reflexive : _≡_ ⇒ _↭_ | ||
↭-reflexive refl = refl | ||
↭-reflexive refl = ↭-refl | ||
|
||
↭-refl : Reflexive _↭_ | ||
↭-refl = refl | ||
↭-reflexive-≋ : _≋_ ⇒ _↭_ | ||
↭-reflexive-≋ xs≋ys = ↭-reflexive (≋⇒≡ xs≋ys) | ||
|
||
↭-sym : ∀ {xs ys} → xs ↭ ys → ys ↭ xs | ||
↭-sym : xs ↭ ys → ys ↭ xs | ||
↭-sym refl = refl | ||
↭-sym (prep x xs↭ys) = prep x (↭-sym xs↭ys) | ||
↭-sym (swap x y xs↭ys) = swap y x (↭-sym xs↭ys) | ||
|
@@ -58,7 +77,7 @@ data _↭_ : Rel (List A) a where | |
|
||
↭-isEquivalence : IsEquivalence _↭_ | ||
↭-isEquivalence = record | ||
{ refl = refl | ||
{ refl = ↭-refl | ||
; sym = ↭-sym | ||
; trans = ↭-trans | ||
} | ||
|
@@ -68,6 +87,28 @@ data _↭_ : Rel (List A) a where | |
{ isEquivalence = ↭-isEquivalence | ||
} | ||
|
||
------------------------------------------------------------------------ | ||
-- _↭_ is equivalent to `Setoid`-based permutation | ||
JacquesCarette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private | ||
open module ↭ₛ = Permutation (≡.setoid A) | ||
using () | ||
renaming (_↭_ to _↭ₛ_) | ||
|
||
↭⇒↭ₛ : xs ↭ ys → xs ↭ₛ ys | ||
↭⇒↭ₛ refl = ↭ₛ.↭-refl | ||
↭⇒↭ₛ (prep x p) = ↭ₛ.↭-prep x (↭⇒↭ₛ p) | ||
↭⇒↭ₛ (swap x y p) = ↭ₛ.↭-swap x y (↭⇒↭ₛ p) | ||
↭⇒↭ₛ (trans p q) = ↭ₛ.↭-trans′ (↭⇒↭ₛ p) (↭⇒↭ₛ q) | ||
|
||
|
||
↭ₛ⇒↭ : _↭ₛ_ ⇒ _↭_ | ||
↭ₛ⇒↭ (↭ₛ.refl xs≋ys) = ↭-reflexive-≋ xs≋ys | ||
↭ₛ⇒↭ (↭ₛ.prep refl p) = ↭-prep _ (↭ₛ⇒↭ p) | ||
↭ₛ⇒↭ (↭ₛ.swap refl refl p) = ↭-swap _ _ (↭ₛ⇒↭ p) | ||
↭ₛ⇒↭ (↭ₛ.trans p q) = ↭-trans (↭ₛ⇒↭ p) (↭ₛ⇒↭ q) | ||
|
||
|
||
------------------------------------------------------------------------ | ||
-- A reasoning API to chain permutation proofs and allow "zooming in" | ||
-- to localised reasoning. | ||
|
@@ -89,12 +130,12 @@ module PermutationReasoning where | |
-- Skip reasoning on the first element | ||
step-prep : ∀ x xs {ys zs : List A} → (x ∷ ys) IsRelatedTo zs → | ||
xs ↭ ys → (x ∷ xs) IsRelatedTo zs | ||
step-prep x xs rel xs↭ys = relTo (trans (prep x xs↭ys) (begin rel)) | ||
step-prep x xs rel xs↭ys = ↭-go (↭-prep x xs↭ys) rel | ||
JacquesCarette marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
-- Skip reasoning about the first two elements | ||
step-swap : ∀ x y xs {ys zs : List A} → (y ∷ x ∷ ys) IsRelatedTo zs → | ||
xs ↭ ys → (x ∷ y ∷ xs) IsRelatedTo zs | ||
step-swap x y xs rel xs↭ys = relTo (trans (swap x y xs↭ys) (begin rel)) | ||
step-swap x y xs rel xs↭ys = ↭-go (↭-swap x y xs↭ys) rel | ||
|
||
syntax step-prep x xs y↭z x↭y = x ∷ xs <⟨ x↭y ⟩ y↭z | ||
syntax step-swap x y xs y↭z x↭y = x ∷ y ∷ xs <<⟨ x↭y ⟩ y↭z |
Uh oh!
There was an error while loading. Please reload this page.