Skip to content

[ refactor ] (more) decidable Data.Fin.Properties #2744

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

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

jamesmckinna
Copy link
Contributor

@jamesmckinna jamesmckinna commented Jun 23, 2025

This PR refactors some proofs about Decidable predicates on Fin n, to clarify some, and to add others, including some additional syntax, around a independently interesting minimisation principle from which certain others follow.

A downstream refactoring might reconsider these things in terms of specialisation of lemmas in Induction.InfiniteDescent.

Outstanding issue: could be more systematic about use of variables to clean the whole module up?

@jamesmckinna jamesmckinna added this to the v2.3 milestone Jun 23, 2025
@jamesmckinna jamesmckinna changed the title [ refactor ] decidable Data.Fin.Properties [ refactor ] (more) decidable Data.Fin.Properties Jun 24, 2025
Q⊆P⇒Q∘suc⊆P∘suc f {x} = f {suc x}
dec[Q⊆P] : Dec (Q ⊆ P)
dec[Q⊆P] with Q? zero
... | false because [¬Q0] = let ¬q₀ = invert [¬Q0] in
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we not just use yes and no here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it's my obsessive avoidance of yes and no in favour of their lazier versions... as discussed at length in previous PRs...


syntax MinimalCounterexample P = μ⟨¬ P ⟩

min? : {p} {P : Pred (Fin n) p} Decidable P Π[ P ] ⊎ μ⟨¬ P ⟩
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be able to come up with a better name for this. I guess find minimum?

This return type is also going to be somewhat baffling. Is writing Π[ P ] ⊎ μ⟨¬ P ⟩ really more informative than Universal P ⊎ MinimalCounterexample P?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding naming, the analogous proof for List is Data.List.Relation.Unary.All.search, but doesn't have a minimality property (we don't prove that it returns the first counterexample)

Regarding the type, yes, I'm aware that not everyone likes the Unary quantifiers Π[_] etc., whereas I find them convenient shorthand. Will reconsider...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Regarding min? itself as a name:

  • postfix ? to denote that this is a decision procedure (but maybe we should reserve such usage for functions returning Dec _ results?)
  • min/μ by association with Kleene's minimisation operator.

Copy link
Contributor

Choose a reason for hiding this comment

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

findMinimum seems like a good name. searchForMin is another viable option. postfix ? to me always indicates Dec.

@jamesmckinna
Copy link
Contributor Author

Thanks @MatthewDaggitt for the feedback:

  • regarding lifting out these properties to a new module, that does seem like a good idea
  • regarding naming/(use of) syntax, indeed there are lots of stylistic questions about the current version.

I'll move to DRAFT for the time being, and remove from v2.3, while I reconsider things.

@jamesmckinna jamesmckinna marked this pull request as draft June 25, 2025 11:21
@MatthewDaggitt MatthewDaggitt removed this from the v2.3 milestone Jun 25, 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.

All the code seems fine. Only issues are that things seem to have moved without a good reason to.

-- Quantification
------------------------------------------------------------------------

module _ {P : Pred (Fin (suc n)) p} where
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are these here? None of these are about a decidable predicate. I think these should be either in the main file or, at worst, a .Core version, but not here.



------------------------------------------------------------------------
-- Effectful
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise, there does not seem to be a good reason to move these here from the main file. This almost feels like a cut-and-paste error?

@jamesmckinna
Copy link
Contributor Author

Hmmm... @JacquesCarette the code motion was in response to earlier review comments from @MatthewDaggitt , but maybe I misunderstood his intention. Nevertheless, the Quantification section is necessary for the subsequent decFinSubset and all?/any? definitions... so it seemed cognate to keep them together (esp. given the public re-export in Data.Fin.Properties...)

@JacquesCarette
Copy link
Contributor

I had seen some of the conversation. This is why maybe a larger break up (Data.Fin.Properties.Quantification too?) might make more sense. Same with the Effectful stuff, it most definitely does not belong in .Properties.Decidable. The main code motion does make a lot of sense, it just has knock-on consequences.

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