Skip to content

[ refactor ] make i ≢ j argument to Data.Fin.Base.punchOut irrelevant #2790

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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

jamesmckinna
Copy link
Contributor

@jamesmckinna jamesmckinna commented Jul 28, 2025

Another downstream consequence of #2785 .
This time the ergonomics are slightly less clear as to whether this improves matters, but the definitional proof-irrelevance pays off in a couple of places, but with a corresponding need to be explicit about the exact proof of inequality in others. Perhaps these proofs can all be simplified further, but I went for the minimal fixes necessary.
UPDATED Perhaps they can! (See below)

I think, as @JacquesCarette touches on below, the real reason this might be problematic is that we end up with a function of three arguments, two of which are implicit, and the third of which is now irrelevant, so it's perhaps not so surprising that in various places, Agda needs a nudge to be able to figure things out...

UPDATED: wait on the merge of #2794 in order to be able to simplify proofs of monotonicity as well...? DONE

@jamesmckinna jamesmckinna added status: blocked-by-issue Progress on this issue or PR is blocked by another issue. refactoring labels Jul 28, 2025
Copy link
Contributor

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn over this one. The code is fine. It's the pain that goes along with the design that's causing me to have doubts.

It seems that Agda is much weaker at inferring irrelevant things, so by explicitly making some things irrelevant, we're making our lives harder. So I wonder if the extra precision is worth the pain.

@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jul 28, 2025

I'm torn over this one. The code is fine. It's the pain that goes along with the design that's causing me to have doubts.

It seems that Agda is much weaker at inferring irrelevant things, so by explicitly making some things irrelevant, we're making our lives harder. So I wonder if the extra precision is worth the pain.

I, too, am torn. I think that it is in any case instructive to uncover such gnarly cases... but on balance, I think the equations proofs that do fall to refl outweigh the cost. But you might be right!

UPDATED: some sleep, and reconsideration, shows that the old proofs can be simplified! Indeed, I've begun to wonder if the right refactoring would go all the way, and simply have

punchOut-cong :  (i : Fin (suc n)) {j k} .{i≢j : i ≢ j} .{i≢k : i ≢ k} 
                j ≡ k  punchOut i≢j ≡ punchOut i≢k
punchOut-cong i refl = refl

and with it the deprecation of punchOut-cong′, instead of the ornate case analysis currently, which nevertheless (still?) seems necessary for punchOut-injective etc.

@jamesmckinna jamesmckinna added this to the v2.4 milestone Jul 31, 2025
Copy link
Contributor

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleaned up proofs are very nice. But still dubious overall.

@jamesmckinna
Copy link
Contributor Author

The cleaned up proofs are very nice. But still dubious overall.

Well, do matters improve if instead we deprecate the existing version of punchOut in favour of one of type

punchOut :  (i j : Fin (suc n))  .(i ≢ j)  Fin n

or even

punchOut-< :  (i j : Fin (suc n))  .(i < j)  Fin n

?

@jamesmckinna jamesmckinna removed the status: blocked-by-issue Progress on this issue or PR is blocked by another issue. label Aug 3, 2025
@MatthewDaggitt MatthewDaggitt modified the milestones: v2.4, v3.0 Aug 5, 2025
@MatthewDaggitt
Copy link
Contributor

This is definitely a breaking change right as you're forced to change the types of e.g. punchOut-cong?

Is there anyway we can see the actual breaking changes (i.e. those that we're forced to make from this change) vs the additional refactoring that is unlocked by this?

@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Aug 5, 2025

@MatthewDaggitt writes:

This is definitely a breaking change right as you're forced to change the types of e.g. punchOut-cong?

Well, on that basis, so too is the type of the function itself changed?

I think that this is (yet) another instance where the line between

  • bug fix (the type was too specific before, and this was a mistake)
  • non-backwards-compatible (the type was too specific before, and we've changed it, with... consequences)
  • breaking (we changed it, and client code actually breaks)

seems a bit hard for me to draw, and hence whether it should be v2.4 or v3.0?

Is there anyway we can see the actual breaking changes (i.e. those that we're forced to make from this change) vs the additional refactoring that is unlocked by this?

Oooh, that's tricky. Hmmm... scratches head!? I might have make a clean version, and see what breaks?
The additional refactoring is in fact quite small: two steps of equational reasoning become ≡⟨⟩ (corresponding to a punchOut-cong ... refl), but that's because I didn't (yet) push harder on what else might be possible?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants