Skip to content

∸-suc lemma for natural numbers #2757

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pmbittner
Copy link
Contributor

@pmbittner pmbittner commented Jul 1, 2025

These lemmata wereThis lemma was useful in inductive proofs involving and and it seems these two lemmata are this lemma is not yet part of the standard library.

Copy link
Contributor

@jamesmckinna jamesmckinna left a comment

Choose a reason for hiding this comment

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

Thanks for this.
Please remove the duplicate lemma, and fix the other one.

CHANGELOG.md Outdated
@@ -251,6 +251,12 @@ Additions to existing modules
∙-cong-∣ : x ∣ y → a ∣ b → x ∙ a ∣ y ∙ b
```

* In `Data.Nat.Properties`:
```agda
∸-suc : n ≤ m → suc m ∸ n ≡ suc (m ∸ n)
Copy link
Contributor

Choose a reason for hiding this comment

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

This might better be called suc-∸ (we tend to favour L-R reading order for lemmas about composition of functions).

Also, following the style-guide precepts about alphabetical mention of specimen names, esp. those bound in variable declarations, the (name and) type of this lemma should probably be

Suggested change
∸-suc : nm → suc mn ≡ suc (mn)
suc-∸ : mn → suc nm ≡ suc (nm)

Copy link
Contributor Author

@pmbittner pmbittner Jul 1, 2025

Choose a reason for hiding this comment

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

I chose ∸-suc as a symmetric name to +-suc and *-suc which look quite similar. I have no problem with a renaming though.

Sorry for getting the variable names wrong, fixed now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's see what our colleagues say about names!

Copy link
Contributor

Choose a reason for hiding this comment

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

Tricky: I prefer James' suggestion, but it's also true that this is consistent with pre-existing names! So I don't know.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes,... maybe I was being too doctrinaire, moreover for a doctrine which is more often honoured in the breach... sigh.

@pmbittner pmbittner changed the title ∸-suc and ≤-suc lemmas for natural numbers ∸-suc lemma for natural numbers Jul 1, 2025
@MatthewDaggitt MatthewDaggitt added this to the v2.4 milestone Jul 2, 2025
@pmbittner
Copy link
Contributor Author

I rebased onto master and now an internal CI error occurred (i.e., something in the pipeline, not the agda standard library failed).

@pmbittner
Copy link
Contributor Author

It seems that ∸-suc is already part of the standard library in terms of +-∸-assoc 1 as well. Sometimes it is not easy to spot whether a theorem you need is already there.... 😅

@jamesmckinna
Copy link
Contributor

jamesmckinna commented Jul 4, 2025

It seems that ∸-suc is already part of the standard library in terms of +-∸-assoc 1 as well. Sometimes it is not easy to spot whether a theorem you need is already there.... 😅

Ah! Yes! Good catch.but indeed the combination you describe us a common case, so I'm wondering if it is worth the Fairbairn threshold penalty to include your version as precisely thus instantiating the general case? Not sure, but suggest we perhaps in any case push to c2.4 to allow us all more time to discuss?

@jamesmckinna
Copy link
Contributor

Suggestion:

  • we add your lemma (under whatever name ;-))
  • we refactor the subsequent proof of +-∸-assoc as follows:
    +-∸-assoc :  m {n o}  o ≤ n  (m + n) ∸ o ≡ m + (n ∸ o)
    +-∸-assoc zero    {n = _} {o = _} _  = refl
    +-∸-assoc (suc m) {n = n} {o = o} le = begin-equality
      suc (m + n) ∸ o   ≡⟨ ∸-suc (m≤n⇒m≤o+n m le) ⟩
      suc ((m + n) ∸ o) ≡⟨ cong suc (+-∸-assoc m le) ⟩
      suc (m + (n ∸ o)) ∎
    which I think is a modest improvement, and the instantiation at m = 1 which occurs twice elsewhere in Data.Nat.Properties can be refactored to use your new lemma.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants