Skip to content

chore: add typeclasses to unify various add_top, add_eq_top, etc. - #14598

Closed
Command-Master wants to merge 58 commits into
masterfrom
CommandMaster_topTypeclasses
Closed

Command-Master wants to merge 58 commits into
masterfrom
CommandMaster_topTypeclasses

Conversation

@Command-Master

@Command-Master Command-Master commented Jul 10, 2024 •

Copy link
Copy Markdown
Collaborator

Add the four typeclasses IsTopAbsorbing, IsBotAbsorbing, NoTopSum, NoBotSum, as additive equivalents for MulZeroClass and NoZeroDivisors. Add instances of these for ENNReal, WithTop α, WithBot α, PUnit, EReal, PartENat, Measure, Interval and Filter.
Also split Algebra/Order/AddGroupWithTop to Algebra/Order/Group/WithTop and Algebra/Order/Monoid/WithTop


Previous usages of lemmas with quantified names like WithTop.add_top have to be changed to just add_top.
add_lt_top is @[simp], in accordance with ENNReal.add_lt_top being @[simp]. This affects WithTop.add_lt_top which previously hadn't been @[simp].

Open in Gitpod

@github-actions github-actions Bot removed the large-import Automatically added label for PRs with a significant increase in transitive imports label Oct 25, 2024
@Command-Master Command-Master removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Oct 25, 2024

@YaelDillies YaelDillies left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry, I am not yet convinced these classes are worth having. Can you remind me:

  1. What instances you want to have that involve these new typeclasses.
  2. What lemmas you expect these classes to generalise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you make these cleanups be a separate PR?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Which cleanups? The instOrderTopAdditiveOrderDual and instLinearOrderedAddCommMonoidWithTopAdditiveOrderDual changes are due to the changed definition of LinearOrderedAddCommMonoidWithTop, and I changed instLinearOrderedCommMonoidWithZeroMultiplicativeOrderDual because the previous version didn't work

Comment thread Mathlib/Data/Nat/PartENat.lean Resolved
@Command-Master

Copy link
Copy Markdown
Collaborator Author

Sorry, I am not yet convinced these classes are worth having. Can you remind me:

1. What instances you want to have that involve these new typeclasses.

2. What lemmas you expect these classes to generalise.
  1. There are the instances in this PR, for ENNReal, WithTop α, WithBot α, PUnit, EReal, PartENat, Measure and Filter. Additionally, every canonically ordered monoid is a NoBotSum, as is PNat, but I'm not sure if that's useful. (I now see I missed Interval in this PR I'll add it soon).
  2. There are add_top/top_add/add_bot/bot_add, which currently exist for LinearOrderedAddCommMonoidWithTop, WithTop, PartENat, Measure, WithBot, Filter, Interval, EReal. There are add_eq_top/add_eq_bot, which exist for WithTop, PartENat, ENNReal, WithBot, Filter, EReal (and could exist for LinearOrderedAddCommMonoidWithTop but is missing), as well as add_eq_zero_iff for canonical monoids (although that should probably remain separate). Additionally, I think it might generalize Filter.bot_sub with EReal.bot_sub and Filter.sub_bot with Interval.sub_bot, although I'm not quite sure about that.

@YaelDillies

YaelDillies commented Oct 27, 2024 •

Copy link
Copy Markdown
Contributor
  1. So no instance is parametric? no instance depends on the new typeclasses? (as in take in one of the new typeclasses as an argument, rather than as an output)
  2. Why can't we just add the missing lemmas for the specific types? Is it that you are trying to avoid a name clash?

It's really important that we can justify every typeclass we add to mathlib because, once a typeclass exists, people feel encouraged to generalise lemmas to it even when it is not mathematically useful to do so, and this makes those typeclasses look crucial when they are not, and also hard to remove.

I worry that the typeclasses in the present PR generalise few lemmas (< 10) from few types (< 10) which are very different mathematically very different (in particular are not thought to be different incarnations of the same algebraic structure, the way eg ℤ and ℝ are rings), meaning that those typeclasses have no backing on paper. Further, the list of generalised lemmas seems very sparse among the lemmas about top in the API of the respective types, meaning that people will find themselves using top lemmas specific to their types, except sometimes where the lemma they want just happens to be generalisable to one of your new typeclasses. This is cognitive overload.

@Command-Master

Command-Master commented Oct 28, 2024 •

Copy link
Copy Markdown
Collaborator Author
  1. There are a bunch of potential instances for the order dual (NoTopSum <-> NoBotSum, IsTopAbsorbing <-> IsBotAbsorbing), and for a bunch of type synonyms, but that's all I can think of.
  2. I think wanting to avoid a name clash is one of the main reasons for this, yes.

Additionally, looking at MulZeroClass and NoZeroDivisors many of the multiplicative lemmas for them have additive equivalences here, which I think is also part of my reason for this, although probably many of them aren't useful.
Not direct equivalence:

  • MulZeroClass.negZeroClass is equivalent to stating that in a IsTopAbsorbing SubtractionMonoid we have -⊤= ⊤ (and the same for bottom).
  • WithZero.mulZeroClass, WithBot.instMulZeroClass, WithTop.instMulZeroClass, WithBot.instNoZeroDivisors, WithTop.instNoZeroDivisors: these are mostly the contents of this PR, except for WithZero preserving IsTopAbsorbing/IsBotAbsorbing/NoTopSum/NoBotSum

Directly equivalent:

  • mul_eq_zero_of_left, mul_eq_zero_of_right
  • eq_zero_of_mul_self_eq_zero
  • mul_self_eq_zero, mul_self_ne_zero
  • zero_eq_mul_self, zero_ne_mul_self
  • mul_eq_zero_comm, mul_ne_zero_comm
  • mul_eq_zero, mul_ne_zero, mul_ne_zero_iff
  • mul_zero_eq_const, zero_mul_eq_const
  • eq_zero_of_ne_zero_of_mul_left_eq_zero, eq_zero_of_ne_zero_of_mul_right_eq_zero
  • left_ne_zero_of_mul, right_ne_zero_of_mul
  • mul_eq_zero_of_ne_zero_imp_eq_zero
  • ne_zero_and_ne_zero_of_mul
  • ite_zero_mul, mul_ite_zero
  • ite_zero_mul_ite_zero
  • SemiconjBy.zero_left, SemiconjBy.zero_right
  • Commute.zero_left, Commute.zero_right
  • instMulZeroClassLex
  • instMulZeroClassOrderDual
  • IsLeftRegular.subsingleton, IsRegular.subsingleton, IsRightRegular.subsingleton
  • isLeftRegular_zero_iff_subsingleton, isRegular_iff_subsingleton, isRightRegular_zero_iff_subsingleton
  • more regular stuff
  • Pi.mulZeroClass
  • pow_eq_zero, pow_ne_zero
  • sq_eq_zero_iff
  • pow_eq_zero_iff, pow_ne_zero_iff, pow_eq_zero_iff'
  • List.prod_eq_zero_iff, List.prod_ne_zero
  • Multiset.prod_eq_zero_iff, Multiset.prod_ne_zero
  • Finsupp.prod_ne_zero_iff, Finsupp.prod_eq_zero_iff
  • isSquare_zero

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Oct 29, 2024
@Command-Master

Command-Master commented Nov 2, 2024 •

Copy link
Copy Markdown
Collaborator Author

Another instance of this I just noticed is that Multisets are a NoBotSum

@leanprover-community-bot-assistant leanprover-community-bot-assistant removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 2, 2024
@YaelDillies

Copy link
Copy Markdown
Contributor

Another instance of this I just noticed is that Multisets are a NoBotSum

That's already covered by the fact that they are a canonically ordered monoid

Do you still need this PR now that your SubtractionMonoid instance is merged?

@Command-Master

Copy link
Copy Markdown
Collaborator Author

I don't need it, but I still think it's good

@leanprover-community-bot-assistant leanprover-community-bot-assistant added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Nov 6, 2024
@joneugster

Copy link
Copy Markdown
Member

Mathlib has moved to PRs from forks. This PR is still from a branch of the main repository and will soon be closed! Please migrate the content to a fork and reopen a PR from there if you wish to do so. See Zulip topic for more instructions. Thank you for contributing to mathlib!

@joneugster joneugster added the will-close-soon Unless something changes, we will close this PR soon label Sep 19, 2026
@joneugster joneugster closed this Oct 24, 2026
@YaelDillies
YaelDillies deleted the CommandMaster_topTypeclasses branch October 24, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-algebra Algebra (groups, rings, fields, etc) t-order Order theory will-close-soon Unless something changes, we will close this PR soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants