Skip to content
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

[ add ] Relation.Binary._Reflects_⟶_ as a companion to _Preserves_⟶_ #2566

Closed
wants to merge 4 commits into from

Conversation

jamesmckinna
Copy link
Contributor

@jamesmckinna jamesmckinna commented Jan 28, 2025

A preparatory PR ahead of tackling #1436 in earnest.
NB:

@gallais
Copy link
Member

gallais commented Jan 28, 2025

What's the intuition for the Reflects name? Does it have any relationship to the ssreflect
style Reflects that we already have? http://agda.github.io/agda-stdlib/v2.1.1/Relation.Nullary.Reflects.html#1010

@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jan 28, 2025

What's the intuition for the Reflects name? Does it have any relationship to the ssreflect style Reflects that we already have? http://agda.github.io/agda-stdlib/v2.1.1/Relation.Nullary.Reflects.html#1010

Nothing to do with Reflects as in ssreflect, nor Relation.Nullary.Reflects!

But absolutely conventional usage in first-order logic/relational algebra (eg. discussion in McKinna&Pollack 1999 on preserving and reflecting α-conversion in λ-calculus representations...): the aim is to [DRY] reconcile Function.Definitions.Injective and Algebra.Definitions.Cancellative as specialisations of the concept...

@@ -31,7 +31,7 @@ module _
Congruent f = ∀ {x y} → x ≈₁ y → f x ≈₂ f y

Injective : (A → B) → Set _
Injective f = ∀ {x y} → f x ≈₂ f y → x ≈₁ y
Injective = _Reflects _≈₂_ ⟶ _≈₁_
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 kind of against this change personally. I read Injective f = ∀ {x y} → f x ≈₂ f y → x ≈₁ y and I understand exactly what it says.

I read Injective = _Reflects _≈₂_ ⟶ _≈₁_ and I have to do the following:

  1. Expand the missing function to Injective f = f Reflects _≈₂_ ⟶ _≈₁_ (non-trivial for beginners)
  2. Expand Reflects to (_≈₁_ on f) ⇒ _≈₂_ which is equally baffling.
  3. Expand on ...
  4. Expand _⇒_...
  5. Only now do I get to the actual definition.

All of these definitions are in different modules and Agda currently provides no easy method of expanding them. In my mind the very small benefit of this change is outweighed by the quite large decrease in usability!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MatthewDaggitt very sharp critique from the ux perspective (I think perhaps we should have ux as a new label category for tagging issues/PRs), for which all thanks.

As the preamble to this PR indicates, I wanted this concept/definition in stdlib so that (eventually) all the Cancellative properties could be rephrased in terms of it. Currently, under #1436 / #2573 we only treat the cancellative properties for equality... if you will, perhaps as another, more directly graspable concept, we should get rid of Cancellative and friends altogether in favour of saying that eg m +_ is Injective on Nat with _≡_ (that would be the other way to go).

It's perhaps the case that my ideological/reformatory zeal on [DRY] issues leads to (over-)generalisations like those considered here (or most recently, in #2581 ), and that reflects what is (probably!) the greater abstraction power of higher-order languages such as Agda's type theory relative to the abstraction power of users (esp. wrt definitional expansion across modules, as you indicate so forcefully).

Against your suggestion, my own preference would be to record as a comment, the 'conventional' usage as being a definitional expansion of the abstract one. Something like

  Injective : (A  B)  Set _
  Injective = _Reflects _≈₂_ ⟶ _≈₁_
-- i.e.  Injective f = ∀ {x y} → f x ≈₂ f y → x ≈₁ y

Of course, that would be a break from existing practice in the library, as well as opening the door to bit-rot if/when definitions change, but here I don't think we are at quite such a risk... precisely because the definition is so 'stable'?

Copy link
Contributor Author

@jamesmckinna jamesmckinna Feb 11, 2025

Choose a reason for hiding this comment

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

All of that said, happy to revert this particular instance of the definition (it was introduced above as 'illustrative'), but then what about Cancellative in all its variety?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think adding non-type checked comments is very susceptible to bit rot as you say. I would be more open to a private definition that performed an equality check.

However, I'm still not entirely sure what advantages the generalisation brings in this case. It's not like we have either a) a set of properties/theory about these kinds of definitions in general or b) lots of definitions in this form? Injective, Cancellative, anything else?

Ditto, I'm not sure that I would be keen on replacing the definitions of Cancellative for exactly the same reasons...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I would still try (but ) to justify the addition

  • on formal grounds, as the 'opposite' of Respects
  • on abstraction grounds (I clearly prefer greater degrees of abstraction, yes ,for its own sake, so I'll try to keep that in mind in future)

but this particular stone seems to be getting harder to push uphill. I'll stop!

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