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 19 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
@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.

@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.

@jamesmckinna
Copy link
Contributor Author

Last addition: dual version of searchMin so that client use doesn't have to figure out the DNE...

@jamesmckinna jamesmckinna marked this pull request as ready for review June 27, 2025 07:53
@jamesmckinna
Copy link
Contributor Author

@JacquesCarette If you are happy with the revisions, then we could add this to the v2.3 docket?

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.

Not thrilled with where the Effectful have ended up, but not a hill I'm willing to die on.

@JacquesCarette JacquesCarette added this to the v2.3 milestone Jun 30, 2025

{-# OPTIONS --cubical-compatible --safe #-}

module Data.Fin.Relation.Unary.Decidable 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 do we need Decidable in the name? Isn't everything over Fin going to be decidable?


{-# OPTIONS --cubical-compatible --safe #-}

module Data.Fin.Relation.Unary.Base 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 do we need this Base module?


------------------------------------------------------------------------
-- search
-- a Decidable predicate is either always true, or has a smallest counterexample
Copy link
Contributor

Choose a reason for hiding this comment

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

Capitalisation and formatting of this header could be better?

syntax Universal< (λ j → P) i = ∀[ j < i ] P

ExistsMinimalCounterexample : (P : Pred (Fin n) p) → Set p
ExistsMinimalCounterexample P = ∃[ i ] ¬ P i × ∀[ j < i ] P j
Copy link
Contributor

Choose a reason for hiding this comment

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

We could just call this MinimalCounterexample? Making this a record with named fields would make it easier to read as well?

ExistsMinimalCounterexample : (P : Pred (Fin n) p) → Set p
ExistsMinimalCounterexample P = ∃[ i ] ¬ P i × ∀[ j < i ] P j

syntax ExistsMinimalCounterexample 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.

I'm still kind of against this for readability reasons, but why does this have to be a syntax declaration rather than an ordinary infix declaration?


------------------------------------------------------------------------
-- Fin
------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this and Bundles have been moved? To be they logically make sense to live at the top of the file as they related to the type itself, rather than functions or relations over it.

------------------------------------------------------------------------

open import Data.Fin.Relation.Unary.Base public
open import Data.Fin.Relation.Unary.Decidable public
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not convinced about this direction of dependencies.



Universal< : Pred (Fin n) p → Pred (Fin n) p
Universal< P i = (j : Fin′ i) → P (inject j)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we use Fin' and inject here rather than an explicit j < i proof? Generally Fin' is quite difficult to work with.


syntax ExistsMinimalCounterexample P = μ⟨¬ P ⟩

searchMin : Decidable P → (∀ i → P i) ⊎ ∃[ i ] ¬ P i × ∀[ j < i ] P j
Copy link
Contributor

Choose a reason for hiding this comment

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

How about calling this searchForCounterexample and the one below searchForWitness?

@MatthewDaggitt
Copy link
Contributor

Again has merge conflicts, no one waiting on it particularly and @jamesmckinna is away so bumping to v2.4

@MatthewDaggitt MatthewDaggitt modified the milestones: v2.3, v2.4 Jul 3, 2025
@jamesmckinna
Copy link
Contributor Author

Happy to bump! There was enough feedback/pushback on some of the choices I'd made that this one deserves a bit more time/energy/thought.

@jamesmckinna jamesmckinna marked this pull request as draft July 3, 2025 07:16
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