You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lead me to conclude that we should add (!?) an irrelevant-instance version of LessThan to Data.Nat.Base, along the analogy with NonZero, and forever after use this relation for 'computational' appeals to _<_, such as in the (old/refactored; mea culpa) definition of fromN<...
... the only question being whether this can already be achieved by back-porting Positive etc. to Data.Nat, as any instance of LessThan m n (sic) defined in terms of _<ᵇ_would eventually reduce to one of Positive k for some k? or else defining Positive in terms of LessThan?
Ah!? ... I think I'd been going from _<ᵇ_ being a builtin primitive in Agda.Builtin.Nat, but then of course so too is _-_... (before being renamed to _∸_ in Data.Nat.Base). Hmm. Thanks for the nudge!
I found that working with things that were in terms of _<ᵇ_ to be quite difficult to work with, as they made it super unclear what I needed to 'nudge' to get things to reduce further. Basically because they had already reduced to things that were so incredibly far from the original "question" (involving fromN<) that I just gave up.
For my examples, I suspect that a version using _∸_ would have made 'semantic sense' to me.
In the end, I refactored absolutely everything to not use _<_ at all. [I was formalizing a notion of 'interval' in an Enumerable set. There are so so many potential design choices, it's quite ridiculous.]
Hmmmph, yes, I share your frustrations. If we can prove (we do!) that vanilla _<_ is Irrelevant, then why should we worry about whether arguments of that form are used strictly or non-strictly? But it seems we must, because back-end erasure / run-time efficiency is not the only consideration, we want also to improve compile-time type-checking efficiency. And it would seem that there are regression tests out there to detect my introduction of overly aggressive/strict approach to matching on such proofs.
And so the further I go with #2000 , the more I end up thinking that it can all be reduced to having moved the former definitions in now-deprecated Data.Nat.Properties.Core (introduced to break a dependency cycle) back into Data.Nat.Base. And reverting the former changes to Data.Fin.*... sigh.
That's (seems to be) a completely defensible position, to me at least (but not, seemingly, to prior authors/maintainers of the library? their insistence on the separation between Base and Properties seemed absolute), because Data.Nat.Base already introduces the datatype definitions of _≤_/_<_ (and their smart constructors), so adding the two inversion principles seems 'harmless', 'virtuous' even (I don't think of these as 'properties' as such; one-step inversions of inductive families, like their simply-typed counterparts, eg head and tail, are simply 'functions' on the raw data).
I might tidy up what I've done, and then not pursue this too much further. The questions there regarding DivMod seem more subtle than I quite appreciate at the moment... but it does seem a weird detour (to me) to have to go via _≤″_ in order to be able to eventually erase the equation defining division-with-remainder, if fromℕ< can be restored to its former irrelevant glory. But it seems as though that is actually a separate issue for a separate PR.
As for the 'semantic sense' regarding _<ᵇ_ and _∸_, the latter has bitten me a couple of times, because it, too, is non-strict in its first argument (when the second is zero). So in order to observe NonZeroness, sometimes an additional pattern-match is required. Whereas _<ᵇ_, which is similarly non-strict in its first argument (when the second is zero), nevertheless immediately returns a matchable constructor form, because Boolean...
... so even my enthusiasm for @Taneb's solution via _∸_ has been ... qualified somewhat.
UPDATED: PR #2000 is now based on _<ᵇ_ and seems to be a bit smoother than going via NonZero. Moreover, I didn't need a separate record declaration for LessThan (because T true is already a record?).
@JacquesCarette comments welcome on the (at-present) slightly more long-winded definition of fromℕ< now. I'm sure that lots of things could be further streamlined, but the PR is an exploration of some the choices.
TL;DR: the function is now (once again!) irrelevant in its _<_ argument, and extensionally equivalent to a version fromℕLessThan which uses an irrelevant instance of LessThan.
But it remains perhaps debatable whether any of this helps at all...
NB for @JacquesCarette : from my perspective (partial/biased), it is actually (now) easier to understand _<ᵇ_ via _<_, precisely because the new 'smart' constructors/pattern synonyms z<s and s<s are in harmony (both in form, and in strictness) with the clauses defining _<ᵇ_ (instead of the, to my mind, nonsense indirection via suc _≤_), whereas, as above, the appeal to _∸_ goes via an even-less-strict pattern analysis (as well as being a function with a complicated (in)equational theory). So I'd be interested to learn if it were possible to (re-)make a streamlined definition of interval for Enumerables which wasn't quote as painful as your previous attempt(s)?
I will dig into this, but after the POPL deadline. I've got tons of paper proofs that need formalized (they are almost all written in detailed equational style as it is, so it is feasible.)
I'm (now) less committed to working towards getting #2000 in sufficient shape for merging into v2.0, but I'm definitely still interested in this issue, for basically two reasons:
(specific, but related) whether an irrelevant definition of DivMod might thereby be obtainable without going via --with-K and the UIP-derived definitions based on _≤″_... which feels as though it would be some sort of win (would it, though?), because we wouldn't have to maintain parallel implementations of DivMod,... possibly dispense with _≤″_ altogether, cf. Redefines Data.Nat.Base._≤″_ #1948 ... etc.
So... before (thinking about) closing this issue, which has led to a lot of subsequent re-thinking of things, on my part at least, I'm left with a open design/implementation question: where the library as it stands (eg Data.Digit) uses (variations on)
True (n <? numeral)
as a precondition on functions (either as an implicit argument, or better, as an irrelevant instance to resolve by search), can/should we instead simplify to the computationally more efficient
T (n <ᵇ numeral)?
NB this is distinct from cases such as count or filter etc. on List/Vec, where we really need the decision, and its subsequent compilation to an if-then-else in the backend...
(... considering lifting this out as a fresh issue/nudge towards a possible PR. )
On the latest design question: I have no current opinions. I have not looked around that part of the design space at all. [Sometimes a null answer is better than the feeling of speaking into the void.]
Well in fact, besides Data.Digit, there is only Data.Nat.Show, Data.Fin, Data.Fin.Show, and various (Co)Data.*.Literals, so while it might be practically important in marshalling to-and-fro numerals, the footprint isn't big enough to be worth separate effort beyond dealing with #2218 ... so closing this now.
Activity
Taneb commentedon Jun 20, 2023
It's possible to define
LessThanin terms ofNonZeroand_∸_, as well, which avoids having to implement new instancesjamesmckinna commentedon Jun 20, 2023
Ah!? ... I think I'd been going from
_<ᵇ_being a builtin primitive inAgda.Builtin.Nat, but then of course so too is_-_... (before being renamed to_∸_inData.Nat.Base). Hmm. Thanks for the nudge!towards issue agda#1998: `Data.Nat.Base`; `CHANGELOG`
JacquesCarette commentedon Jun 22, 2023
I found that working with things that were in terms of
_<ᵇ_to be quite difficult to work with, as they made it super unclear what I needed to 'nudge' to get things to reduce further. Basically because they had already reduced to things that were so incredibly far from the original "question" (involvingfromN<) that I just gave up.For my examples, I suspect that a version using
_∸_would have made 'semantic sense' to me.In the end, I refactored absolutely everything to not use
_<_at all. [I was formalizing a notion of 'interval' in anEnumerableset. There are so so many potential design choices, it's quite ridiculous.]jamesmckinna commentedon Jun 22, 2023
Hmmmph, yes, I share your frustrations. If we can prove (we do!) that vanilla
_<_isIrrelevant, then why should we worry about whether arguments of that form are used strictly or non-strictly? But it seems we must, because back-end erasure / run-time efficiency is not the only consideration, we want also to improve compile-time type-checking efficiency. And it would seem that there are regression tests out there to detect my introduction of overly aggressive/strict approach to matching on such proofs.And so the further I go with #2000 , the more I end up thinking that it can all be reduced to having moved the former definitions in now-deprecated
Data.Nat.Properties.Core(introduced to break a dependency cycle) back intoData.Nat.Base. And reverting the former changes toData.Fin.*... sigh.That's (seems to be) a completely defensible position, to me at least (but not, seemingly, to prior authors/maintainers of the library? their insistence on the separation between
BaseandPropertiesseemed absolute), becauseData.Nat.Basealready introduces the datatype definitions of_≤_/_<_(and their smart constructors), so adding the two inversion principles seems 'harmless', 'virtuous' even (I don't think of these as 'properties' as such; one-step inversions of inductive families, like their simply-typed counterparts, egheadandtail, are simply 'functions' on the raw data).I might tidy up what I've done, and then not pursue this too much further. The questions there regarding
DivModseem more subtle than I quite appreciate at the moment... but it does seem a weird detour (to me) to have to go via_≤″_in order to be able to eventually erase the equation defining division-with-remainder, iffromℕ<can be restored to its former irrelevant glory. But it seems as though that is actually a separate issue for a separate PR.jamesmckinna commentedon Jun 22, 2023
As for the 'semantic sense' regarding
_<ᵇ_and_∸_, the latter has bitten me a couple of times, because it, too, is non-strict in its first argument (when the second iszero). So in order to observeNonZeroness, sometimes an additional pattern-match is required. Whereas_<ᵇ_, which is similarly non-strict in its first argument (when the second iszero), nevertheless immediately returns a matchable constructor form, becauseBoolean...... so even my enthusiasm for @Taneb's solution via
_∸_has been ... qualified somewhat.UPDATED: PR #2000 is now based on
_<ᵇ_and seems to be a bit smoother than going viaNonZero. Moreover, I didn't need a separaterecorddeclaration forLessThan(becauseT trueis already arecord?).jamesmckinna commentedon Jun 25, 2023
@JacquesCarette comments welcome on the (at-present) slightly more long-winded definition of
fromℕ<now. I'm sure that lots of things could be further streamlined, but the PR is an exploration of some the choices.TL;DR: the function is now (once again!) irrelevant in its
_<_argument, and extensionally equivalent to a versionfromℕLessThanwhich uses an irrelevant instance ofLessThan.But it remains perhaps debatable whether any of this helps at all...
jamesmckinna commentedon Jun 29, 2023
NB for @JacquesCarette : from my perspective (partial/biased), it is actually (now) easier to understand
_<ᵇ_via_<_, precisely because the new 'smart' constructors/pattern synonymsz<sands<sare in harmony (both in form, and in strictness) with the clauses defining_<ᵇ_(instead of the, to my mind, nonsense indirection viasuc _≤_), whereas, as above, the appeal to_∸_goes via an even-less-strict pattern analysis (as well as being a function with a complicated (in)equational theory). So I'd be interested to learn if it were possible to (re-)make a streamlined definition of interval forEnumerables which wasn't quote as painful as your previous attempt(s)?JacquesCarette commentedon Jun 29, 2023
I will dig into this, but after the POPL deadline. I've got tons of paper proofs that need formalized (they are almost all written in detailed equational style as it is, so it is feasible.)
JacquesCarette commentedon Jul 13, 2023
As commented on the code itself, it looks nice. I have now added an explicit task on my list to re-try my experiments with
Enumerable.jamesmckinna commentedon Aug 15, 2023
Any update on
Enumerable?JacquesCarette commentedon Aug 15, 2023
Sorry, not yet. My time slices are still thin...
jamesmckinna commentedon Sep 13, 2023
I'm (now) less committed to working towards getting #2000 in sufficient shape for merging into v2.0, but I'm definitely still interested in this issue, for basically two reasons:
_≺_inData.Fin.Base#1726 regarding thinning down the profusion of definitions of_<_on Nat;DivModmight thereby be obtainable without going via--with-Kand theUIP-derived definitions based on_≤″_... which feels as though it would be some sort of win (would it, though?), because we wouldn't have to maintain parallel implementations ofDivMod,... possibly dispense with_≤″_altogether, cf. RedefinesData.Nat.Base._≤″_#1948 ... etc.jamesmckinna commentedon Feb 16, 2024
So... before (thinking about) closing this issue, which has led to a lot of subsequent re-thinking of things, on my part at least, I'm left with a open design/implementation question: where the library as it stands (eg
Data.Digit) uses (variations on)True (n <? numeral)as a precondition on functions (either as an implicit argument, or better, as an irrelevant instance to resolve by search), can/should we instead simplify to the computationally more efficient
T (n <ᵇ numeral)?NB this is distinct from cases such as
countorfilteretc. onList/Vec, where we really need the decision, and its subsequent compilation to an if-then-else in the backend...(... considering lifting this out as a fresh issue/nudge towards a possible PR. )
JacquesCarette commentedon Feb 16, 2024
On the latest design question: I have no current opinions. I have not looked around that part of the design space at all. [Sometimes a null answer is better than the feeling of speaking into the void.]
jamesmckinna commentedon Feb 18, 2024
Well in fact, besides
Data.Digit, there is onlyData.Nat.Show,Data.Fin,Data.Fin.Show, and various(Co)Data.*.Literals, so while it might be practically important in marshalling to-and-fro numerals, the footprint isn't big enough to be worth separate effort beyond dealing with #2218 ... so closing this now.