-
Notifications
You must be signed in to change notification settings - Fork 248
Some preparatory proofs for proving sorting+permutation is equality #2724 #2725
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
base: master
Are you sure you want to change the base?
Conversation
-- Takes a permutation m → n and creates a permutation | ||
-- suc (suc m) → suc (suc n) by mapping 0 to 1 and 1 to 0 and | ||
-- then applying the input permutation to everything else | ||
swap : Permutation m n → Permutation (suc (suc m)) (suc (suc n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a special case of \oplus of two permutations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree (lift0
should be as well!), but we don't have such an operation in the library. I have added a note that we should refactor it when we add that operator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have it buried in my Rig Categories repo. I need to port the basic operations on permutations over. I've got the full semiring defined there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But also: Function.Related.TypeIsomorphisms
etc. as per #2489 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus, of course: we only need this operation because Permutation.Setoid
stipulates swap
as a constructor... ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely, there is some great stuff in Function.Related.TypeIsomorphism
. And a rather apt 'of course'.
src/Data/List/Relation/Binary/Permutation/Setoid/Properties.agda
Outdated
Show resolved
Hide resolved
Having looked at this, and its followup, in particular lemma
If so, then I think this PR and its followup may be simplifiable via the already existing UPDATED: on closer examination, maybe this is what you have! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some nitpicks.
Happy to approve, but I too have been sniped by this... would love to be able to simplify if at all possible!
_≰_ : ∀ {n} → Rel (Fin n) 0ℓ | ||
i ≰ j = ¬ (i ≤ j) | ||
|
||
_≮_ : ∀ {n} → Rel (Fin n) 0ℓ | ||
i ≮ j = ¬ (i < j) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
xs↭ys⇒|xs|≡|ys| : ∀ {xs ys} → xs ↭ ys → length xs ≡ length ys | ||
xs↭ys⇒|xs|≡|ys| (refl eq) = Pointwise.Pointwise-length eq | ||
xs↭ys⇒|xs|≡|ys| (prep eq xs↭ys) = ≡.cong suc (xs↭ys⇒|xs|≡|ys| xs↭ys) | ||
xs↭ys⇒|xs|≡|ys| (swap eq₁ eq₂ xs↭ys) = ≡.cong (λ x → suc (suc x)) (xs↭ys⇒|xs|≡|ys| xs↭ys) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
xs↭ys⇒|xs|≡|ys| (swap eq₁ eq₂ xs↭ys) = ≡.cong (λ x → suc (suc x)) (xs↭ys⇒|xs|≡|ys| xs↭ys) | |
xs↭ys⇒|xs|≡|ys| (swap eq₁ eq₂ xs↭ys) = ≡.cong 2+_ (xs↭ys⇒|xs|≡|ys| xs↭ys) |
(possibly at the cost of an additional import from Data.Nat.Base
)?
_≰_ : ∀ {n} → Rel (Fin n) 0ℓ | ||
_≮_ : ∀ {n} → Rel (Fin n) 0ℓ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we, by convention, avoid writing the ∀ {n} →
prefix here?
```agda | ||
xs↭ys⇒|xs|≡|ys| : xs ↭ ys → length xs ≡ length ys | ||
¬x∷xs↭[] : ¬ (x ∷ xs ↭ []) | ||
toFin-lookup : ∀ i → lookup xs i ≈ lookup ys (Inverse.to (toFin xs↭ys) i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be:
toFin-lookup : ∀ i → lookup xs i ≈ lookup ys (Inverse.to (toFin xs↭ys) i) | |
onIndices-lookup : ∀ i → lookup xs i ≈ lookup ys (Inverse.to (onIndices xs↭ys) i) |
and again, do we need the ∀ i →
prefix in CHANGELOG
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(explicit arguments should definitely be in the changelog - but does i
need to be explicit?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Taneb I'm surprised to learn that (is it documented?): given that CHANGELOG
isn't machine-checked, I use it to get (a sense of) the high-level gist of what's been added, and then look at the module for the exact details of the quantification/parametrisation etc.
As for whether i
needs to be explicit in this lemma, I expect so, if only by analogy with (all the) lemmas about lookup
in Data.List.Properties
...?
@@ -17,6 +17,7 @@ module Data.List.Relation.Binary.Permutation.Setoid.Properties | |||
|
|||
open import Algebra | |||
open import Data.Bool.Base using (true; false) | |||
open import Data.Fin using (zero; suc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
open import Data.Fin using (zero; suc) | |
open import Data.Fin.Base using (zero; suc) |
-- suc (suc m) → suc (suc n) by mapping 0 to 1 and 1 to 0 and | ||
-- then applying the input permutation to everything else | ||
swap : Permutation m n → Permutation (suc (suc m)) (suc (suc n)) | ||
swap {m} {n} π = permutation to from inverseˡ′ inverseʳ′ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this definition easier to describe/define indirectly, via the composition of
eval ((0F , 1F) ∷ (1F , 0F))
usingData.Fin.Permutation.Transposition.List
lift₀ {suc m} {suc n} (lift₀ {m} {n} π)
or indeed (more) directly, as transpose 0F 1F ∘ₚ lift₀ {suc m} {suc n} (lift₀ {m} {n} π)
?
I've been sniped by #2723. This is a preparatory PR for the full proof that sorting two lists that are permutations of each other result in equal lists.