-
Notifications
You must be signed in to change notification settings - Fork 236
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
Proofs in Data.Vec.Properties
take general properties as inputs
#2421
Comments
Great question! |
thanks for the link! I took a quick look at all of the comments and threads and was unable to find discussion on the also as an offtopic, shout out to @shhyou for the reasoning system, it is really nice documented and a pleasure to use! |
Thinking a little bit more about your question... it seems to me that
|
hmm, I'm struggling to see where the conflict is here 🤔 the style I'm suggesting doesn't change the fact that properties are stated as
do you have an example of a lemma that might not permit the second style? I was able to rewrite all proofs in Vec.Properties to the second style without an issue, even ones that use the combinators (such as reverse-++). also bear in mind we have many proofs already using the second style!
agreed. I would in fact derive the eq-taking (current) form from the eq-free form, as I did above, as it also simplifies the code a bit |
I think providing proofs of When I originally added some of the cast-∷ʳ : ∀ .(eq : suc n ≡ suc m) x (xs : Vec A n) →
cast eq (xs ∷ʳ x) ≡ (cast (cong pred eq) xs) ∷ʳ x
cast-++ˡ : ∀ .(eq : m ≡ o) (xs : Vec A m) {ys : Vec A n} →
cast (cong (_+ n) eq) (xs ++ ys) ≡ cast eq xs ++ ys
cast-++ʳ : ∀ .(eq : n ≡ o) (xs : Vec A m) {ys : Vec A n} →
cast (cong (m +_) eq) (xs ++ ys) ≡ xs ++ cast eq ys
lookup-cast : .(eq : m ≡ n) (xs : Vec A m) (i : Fin m) →
lookup (cast eq xs) (Fin.cast eq i) ≡ lookup xs i Of course, these are not the cases for the lemmas you observed. From what I can see, for example, these properties can also have their ++-assoc : ∀ .(eq : (m + n) + o ≡ m + (n + o)) (xs : Vec A m) (ys : Vec A n) (zs : Vec A o) →
cast eq ((xs ++ ys) ++ zs) ≡ xs ++ (ys ++ zs)
++-identityʳ : ∀ .(eq : n + zero ≡ n) (xs : Vec A n) → cast eq (xs ++ []) ≡ xs |
Naming the revised lemmas with primes (like |
There is a good reason for having the proofs be irrelevant and generic in the exact equality. The problem is that if you hard code the equality (e.g. by using the corresponding property from These lemmas were ported across from my own library, where I frequently came across places where for various reasons (e.g. the equality was sourced from another related equality upstream with a different proof, and only reduced to If people think that having the instantiated equality would be useful, then yes, it would be possible to add additional lemmas. I'm agnostic to the naming of those, i.e. would be happy with primed versions, but if someone can come up with a more meaningful version then we'd be keen to hear suggestions. |
yeah, those are handled in the rewrite
that's what I'd like to happen as well... |
@MatthewDaggitt sorry, I missed your comment!
hmm, can you point to an example? I thought irrelevancy solved this... I'm probably missing something, but I've been using the eq-free lemmas for a while now and have so far never found a situation where I needed to use the eq-generic ones in the end, I'd like us to be consistent. if there's a reason to provide eq-generic lemmas, then let's provide them everywhere (right now we have many lemmas that are eq-free) and adopt a uniform naming convention 🙏 |
Trying to navigate a path between @MatthewDaggitt and @mildsunrise ... I have the impression that both forms of the lemma statements may be useful (even: necessary), but also that the inversion of dependency which makes the Mind you, the search for a workable, consistent, naming scheme, together with a suitable deprecation strategy of the 'old ways' of doing things suggests to me that this might best be badged as a v3.0 issue? |
@MatthewDaggitt A good thing is that the exact equality here doesn't block any other equalities due to For example, ++-identityʳ-with-eq : ∀ {A : Set} {n} →
(xs : Vec A n) →
cast (+-identityʳ n) (xs ++ []) ≡ xs
++-identityʳ-with-eq {n = zero} [] = refl
++-identityʳ-with-eq {n = suc n} (x ∷ xs) = cong (x ∷_) (++-identityʳ-with-eq xs)
usage : ∀ {A : Set} {m} (xs : Vec A m) → (eq : m + zero ≡ m) → cast eq (xs ++ []) ≡ xs
usage xs _ = ++-identityʳ-with-eq xs In other words, equality-specific lemmas subsume the equality-agnostic ones due to irrelevancy. |
Ah right, yes, we're talking about the new @gallais as the author of these lemmas 2 years ago in a123840, do you remember why you made the equalities generic? |
Probably because I was thinking along the same lines as you:
But as this discussion highlights, it was probably a mistake given that irrelevance should |
given that we seem to have reached a consensus, I'd suggest this course of action:
it's the first time I deal with deprecations, but it would look something like this. WDYT? |
I'm in favour of the general tenor if your proposal, but really don't like the use of primes... might even go as far as suggesting an 'obtrusive' modifier such as |
I like the idea of being more explicit that this is transitional, but, can we pick a suffix that's a little shorter? 👉👈 |
I agree with proposal except that this:
should be:
I like the suffix |
What a wonderful discussion! My first instinct was to reply along the same lines as what @MatthewDaggitt said, as my experience of wiring in specific proofs lead to |
@MatthewDaggitt ah, I see, you want to do it in 2 steps, right?
I'm not feeling very creative today, so let's go with |
Yes... 'rename+deprecate' PRs can slightly drain the creative life out of stdlib development. |
Yes, that sounds about right. Slow and steady wins the race. |
@JacquesCarette I'm still curious about
if you ever write about this in the future, I'd be happy to read it :) |
On the 'not that simple', it starts with a simple observation: let G and H be enormous numbers (like Graham's number or TreeT(4), which are expressible in Agda but effectively impossible to write down). Then 2^G * 3^H = 3^H * 2^G is "obviously true" -- but So there are equalities that are provable in Agda, that are for decidable things, but where |
* Vec.Properties: drop eq parameter when it is a property (fixes #2421) * remove deprecated usages * use '-eqFree' as suffix instead of a prime * add changelog entry --------- Co-authored-by: MatthewDaggitt <matthewdaggitt@gmail.com>
Looking at
Data.Vec.Properties
, I see many properties accept an irrelevanteq
parameter that is actually a well-known property on naturals and has nothing relevant to the particular input. For example:Instead of requesting a proof for
suc (m + n) ≡ m + suc n
, we could fill it in ourselves with+-suc
which is already in scope:This not only makes
++-∷ʳ
easier to use, it also simplifies the code for the proof itself (no extraeq
argument, no need forrefl
andcong pred eq
). And becauseeq
is irrelevant incast
, we don't lose generality -- the original statement is justconst ++-∷ʳ
:So I wanted to ask, what's the motivation for writing properties the current way? Was it because of limitations of Agda back when these proofs were written (wrt irrelevancy and so on)? Am I myself missing limitations of irrelevancy or something else? Later in the file I can see properties that use the second style:
And the follow up question is: would it be a good idea to change the properties to the second style in the next compat-breaking version?
The text was updated successfully, but these errors were encountered: