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

Remove all external use of less-than-or-equal beyond Data.Nat.* #2256

Merged
merged 2 commits into from
Jan 20, 2024

Conversation

jamesmckinna
Copy link
Contributor

@jamesmckinna jamesmckinna commented Jan 14, 2024

Following up on #2216 / #2217 (and #2250 ) with a 'pure' refactoring PR (so: no CHANGELOG entry required at this stage) which localises all uses of the retained-for-backwards-compatibility pattern synonym less-than-or-equal to Data.Nat.Base, Data.Nat.Properties, Data.Nat.Properties/WithK.

Outstanding issues (maybe):

  • deprecation of the pattern synonym (in Data.Nat? or elsewhere?), which would require a CHANGELOG entry;
  • the fix-up of the various Vec lengths in padRight, padBoth etc. at present use rewrite, but it might be cleaner to use Vec.cast with the appropriate equality (shoutout to @JacquesCarette for this);
  • the ubiquity (now) of the 'pattern' of definition
f : ... (as : Vec≤ A n) ... 
f ... as@record { length = m ; vec = vs ; bound = m≤n } ...
  with ≤″-offset k  recompute (_ ℕ.≤″? _) (ℕ.≤⇒≤″ m≤n) = ...

suggests that the design of the datatype might be revisited, to optimise for computing the offset k?

@MatthewDaggitt MatthewDaggitt added this to the v2.1 milestone Jan 15, 2024
@jamesmckinna
Copy link
Contributor Author

jamesmckinna commented Jan 19, 2024

Re: revising the design

On reflection, I think the proof pattern alluded to above could be improved off-the-bat by:

  • adding to Data.Nat.Properties, replacing these proofs, with
≤⇒≤″ : _≤_ ⇒ _≤″_
≤⇒≤″ = less-than-or-equal ∘ m+[n∸m]≡n

-- corollary

≤-proof :  {m n} (le : m ≤ n)  ∃[ k ] m + k ≡ n
≤-proof le = _ , ≤″-proof (≤⇒≤″ le)

pattern ≤-offset k = k , refl
pattern <-offset k = ≤-offset k

-- equivalence to _≤_

≤″⇒≤ : _≤″_ ⇒ _≤_
≤″⇒≤ (≤″-offset k) = m≤m+n _ k
  • and then rewriting the above proof pattern in Data.Vec.Bounded.Base as
  with ℕₚ.≤-offset k  ℕₚ.≤-proof (recompute (_ ℕₚ.≤? _) m≤n)

thereby encapsulating all mention even of _≤″_ itself... not merely that of its smart constructor...

@JacquesCarette
Copy link
Contributor

I would be a definite fan of doing this in two stages, i.e. first pull this in, and then your further improvements later, when they land.

@jamesmckinna
Copy link
Contributor Author

OK, so let's merge this as it stands, and then I'll file a followup? Are you happy for me to hit 'merge'?

@JacquesCarette
Copy link
Contributor

Well, I still think it shouldn't be the author who merges - but I'm happy to do it.

@JacquesCarette JacquesCarette added this pull request to the merge queue Jan 20, 2024
@jamesmckinna
Copy link
Contributor Author

I agree re: self-merging, so I hadn't done so... ;-)

Merged via the queue into agda:master with commit bde655f Jan 20, 2024
1 check passed
andreasabel pushed a commit that referenced this pull request Jul 10, 2024
…2256)

* removed all external use of `less-than-or-equal` beyond `Data.Nat.*`

* use of `variable`s
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.

None yet

3 participants