Skip to content

[Merged by Bors] - feat: OrderSupSet - #38328

Closed
astrainfinita wants to merge 17 commits into
leanprover-community:masterfrom
astrainfinita:ordersup_def
Closed

astrainfinita wants to merge 17 commits into
leanprover-community:masterfrom
astrainfinita:ordersup_def

Conversation

@astrainfinita

@astrainfinita astrainfinita commented Apr 21, 2026 •

Copy link
Copy Markdown
Collaborator

This PR introduces OrderSupSet and OrderInfSet, which are typeclasses expressing that sSup (resp., sInf) returns the least upper bound (resp., the greatest lower bound) of a set whenever one exists.

This allows us to prove properties about the sSup of specific sets (such as ∅, singletons, finite sets, and univ) without any typeclasses asserting the existence of LUBs. For example, sSup ∅ = ⊥ holds for any type equipped with OrderBot OrderSupSet, no longer requiring typeclasses like ConditionallyCompleteLinearOrderBot.

For a general set s, this gives a uniform way to extend results about IsLUB s a → motive a to motive (sSup s), motive (⨆ i, f i), motive (a ⊔ b), etc., which allows proof reuse for basic API such as csSup_insert, iSup_insert, and sSup_insert and downstream code like csSup_add, sSup_add, and sup_add.

Furthermore, this allows us to refactor incrementally, reducing the dependency of results about various completeness typeclasses on the specific implementation of sSup.


Zulip

Open in Gitpod

@github-actions

github-actions Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

PR summary 063c5accb9

Import changes for modified files

Dependency changes

File Base Count Head Count Change
Mathlib.Order.SetNotation 170 171 +1 (+0.59%)
Mathlib.Order.Bounds.Basic 328 329 +1 (+0.30%)
Import changes for all files
Files Import difference
86 files Mathlib.Algebra.BigOperators.Group.Finset.Basic Mathlib.Algebra.BigOperators.Group.Finset.Lemmas Mathlib.Algebra.BigOperators.Group.Finset.Pi Mathlib.Algebra.BigOperators.Group.Finset.Piecewise Mathlib.Algebra.BigOperators.Option Mathlib.Algebra.GradedMonoid Mathlib.Algebra.GradedMulAction Mathlib.Algebra.Group.EvenFunction Mathlib.Algebra.Group.Pointwise.Set.BigOperators Mathlib.Algebra.Group.Pointwise.Set.Finite Mathlib.Algebra.Order.Field.Basic Mathlib.Algebra.Order.Group.Bounds Mathlib.Algebra.Order.Group.Pointwise.Interval Mathlib.Algebra.Order.GroupWithZero.Bounds Mathlib.Basic.Finite.Prod Mathlib.Basic.Finite.Sum Mathlib.Basic.Rel.Cover Mathlib.Basic.Rel.Separated Mathlib.Basic.Rel Mathlib.Combinatorics.HalesJewett Mathlib.Computability.StateTransition Mathlib.Computability.TuringMachine.PostTuringMachine Mathlib.Computability.TuringMachine.StackTuringMachine Mathlib.Control.LawfulFix Mathlib.Data.DFinsupp.FiniteInfinite Mathlib.Data.Fin.Tuple.Curry Mathlib.Data.Fin.Tuple.Finset Mathlib.Data.FinEnum.Option Mathlib.Data.Finite.Prod Mathlib.Data.Finite.Sum Mathlib.Data.Finset.NoncommProd Mathlib.Data.Finset.Option Mathlib.Data.Finset.PImage Mathlib.Data.Finset.Pi Mathlib.Data.Finset.Prod Mathlib.Data.Finset.Union Mathlib.Data.Finset.Update Mathlib.Data.Fintype.Option Mathlib.Data.Fintype.Pi Mathlib.Data.Fintype.Pigeonhole Mathlib.Data.Fintype.Prod Mathlib.Data.Fintype.Sum Mathlib.Data.Fintype.WithTopBot Mathlib.Data.FunLike.Fintype Mathlib.Data.Holor Mathlib.Data.Multiset.Fintype Mathlib.Data.Nat.Cast.Order.Field Mathlib.Data.Nat.Prime.Infinite Mathlib.Data.PFun Mathlib.Data.Rel.Cover Mathlib.Data.Rel.Separated Mathlib.Data.Rel Mathlib.Dynamics.BirkhoffSum.Average Mathlib.Dynamics.BirkhoffSum.Basic Mathlib.GroupTheory.Perm.List Mathlib.GroupTheory.Perm.Support Mathlib.LinearAlgebra.ConvexSpace.AffineSpace Mathlib.Logic.Embedding.Set Mathlib.Logic.Equiv.Embedding Mathlib.Logic.Equiv.Fin.Basic Mathlib.Logic.Equiv.Fin.Rotate Mathlib.NumberTheory.Harmonic.Defs Mathlib.Order.Antichain Mathlib.Order.Bounds.Basic Mathlib.Order.Bounds.Image Mathlib.Order.Bounds.OrderIso Mathlib.Order.Interval.Set.Fin Mathlib.Order.Interval.Set.IsoIoo Mathlib.Order.Interval.Set.OrderEmbedding Mathlib.Order.Interval.Set.UnorderedInterval Mathlib.Order.LatticeIntervals Mathlib.Order.Monotone.Odd Mathlib.Order.Monotone.Union Mathlib.Order.OmegaCompletePartialOrder Mathlib.Order.Rel.GaloisConnection Mathlib.Order.RelIso.Set Mathlib.Order.ScottContinuity Mathlib.Order.SetNotation Mathlib.Order.UpperLower.Relative Mathlib.RingTheory.FilteredAlgebra.Basic Mathlib.RingTheory.Prime Mathlib.SetTheory.ZFC.Basic Mathlib.SetTheory.ZFC.PSet Mathlib.Tactic.NormNum.BigOperators Mathlib.Topology.ContinuousMap.Defs Mathlib.Topology.Defs.Basic
1

Declarations diff (regex)

+ IsLUB.isLUB_sSup
+ OrderDual.orderSupSet
+ OrderInfSet
+ OrderInfSet.ofOrderSupSet
+ OrderSupSet
+ OrderSupSet.choose
+ exists_isLUB_iff_isLUB_sSup
+ instance (priority := 100) CompleteSemilatticeSup.toOrderSupSet :
+ instance [Preorder α] [OrderSupSet α] [Preorder β] [OrderSupSet β] : OrderSupSet (α × β)
+ instance {α : Type*} {β : α → Type*} [∀ i, Preorder (β i)] [∀ i, OrderSupSet (β i)] :

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.

Declarations diff (Lean)

✅ Lean-aware diff — post-build, computed from the Lean environment (commit 063c5ac).

  • +38 new declarations
  • −0 removed declarations
+CompleteSemilatticeInf.toOrderInfSet
+CompleteSemilatticeSup.toOrderSupSet
+IsGLB.isGLB_sInf
+IsLUB.isLUB_sSup
+OrderDual.orderInfSet
+OrderDual.orderSupSet
+OrderInfSet
+OrderInfSet.casesOn
+OrderInfSet.choose
+OrderInfSet.ctorIdx
+OrderInfSet.isGLB_sInf_of_isGLB
+OrderInfSet.mk
+OrderInfSet.mk.noConfusion
+OrderInfSet.noConfusion
+OrderInfSet.noConfusionType
+OrderInfSet.ofOrderSupSet
+OrderInfSet.rec
+OrderInfSet.recOn
+OrderInfSet.toInfSet
+OrderSupSet
+OrderSupSet.casesOn
+OrderSupSet.choose
+OrderSupSet.ctorIdx
+OrderSupSet.isLUB_sSup_of_isLUB
+OrderSupSet.mk
+OrderSupSet.mk.noConfusion
+OrderSupSet.noConfusion
+OrderSupSet.noConfusionType
+OrderSupSet.ofOrderInfSet
+OrderSupSet.rec
+OrderSupSet.recOn
+OrderSupSet.toSupSet
+Prod.instOrderInfSet
+Prod.instOrderSupSet
+exists_isGLB_iff_isGLB_sInf
+exists_isLUB_iff_isLUB_sSup
+instOrderInfSetForall
+instOrderSupSetForall

No changes to strong technical debt.
No changes to weak technical debt.

Current commit 063c5accb9
Reference commit f71bd379b2

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.py pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@astrainfinita astrainfinita added the t-order Order theory label Apr 21, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 21, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 22, 2026
Comment thread Mathlib/Order/SetNotation.lean Resolved
Comment thread Mathlib/Order/SetNotation.lean Outdated

/-- `OrderSupSet α` expresses that `α` is equipped with the operation `sSup` that returns
the least upper bound of a set whenever one exists. -/
class OrderSupSet (α : Type*) [LE α] extends SupSet α where

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIUC, only this and OrderInfSet need to live in this file, the rest can be further down the import hierarchy.

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.

The file is only meant for notation, so arguably nothing should be added here in this PR

@vihdzp vihdzp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I really like this new design. Not sure if the conversation has quite converged on whether we want it, but I do personally find it to be an improvement.

@astrainfinita
astrainfinita marked this pull request as ready for review April 23, 2026 10:02
Comment thread Mathlib/Order/SetNotation.lean Resolved
@b-mehta

b-mehta commented Apr 26, 2026

Copy link
Copy Markdown
Contributor

Can you add something to the PR description here describing the motivation? The linked Zulip thread is (very) long and discusses a number of other things.

@openendings

Copy link
Copy Markdown

Can you add something to the PR description here describing the motivation? The linked Zulip thread is (very) long and discusses a number of other things.

@astrainfinita I've just suggested a rough outline in Zulip; feel free to use / not use at your leisure

Comment on lines +84 to +87
/-- `OrderSupSet α` expresses that `α` is equipped with the operation `sSup` that returns
the least upper bound of a set whenever one exists. -/
class OrderSupSet (α : Type*) [LE α] extends SupSet α where
protected isLUB_sSup_of_isLUB s a : IsLUB s a → IsLUB s (sSup s)

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.

The problem with OrderSupSet using extends is that you either have to add it into all the order classes (ConditionallyCompletePartialOrder, ConditionallyCompleteLinearOrder, etc.) or else you can't have any theorems about those classes which assume OrderSupSet because taking both as arguments will give you 2 distinct SupSet instances.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The problem with OrderSupSet using extends is that you either have to add it into all the order classes

I think the idea is to eventually redefine the order classes so as to extend OrderSupSet and OrderInfSet, and instead of characterizing the functions sSup and sInf directly, we characterize what sets have suprema and infima.

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.

Yes, I expect their usage to be similar to OrderBot. Any typeclass that provides sSup should either directly extend OrderSupSet or imply it.

@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Apr 30, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label May 9, 2026
@mathlib-merge-conflicts mathlib-merge-conflicts Bot added the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Aug 10, 2026
@mathlib-merge-conflicts

Copy link
Copy Markdown

This pull request has conflicts, please merge master and resolve them.

@Vierkantor Vierkantor 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.

Overall I think this is the right way to go. Do you have any followup PRs so I can see the effects of this PR in action?

Comment thread Mathlib/Order/SetNotation.lean Resolved
Comment thread Mathlib/Order/Bounds/Basic.lean Resolved
Comment thread Mathlib/Order/Bounds/Basic.lean Resolved
Comment thread Mathlib/Order/Bounds/Basic.lean Resolved
(∃ a, IsLUB s a) → IsLUB s (sSup s) :=
fun ⟨_, h⟩ ↦ h.isLUB_sSup

@[to_dual]

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.

This seems like a good simp lemma, replacing an arbitrary witness a with a specific value sSup s.

Suggested change
@[to_dual]
@[to_dual (attr := simp)]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't know if I agree with this. We might have a scenario where the LUB of s has an explicit characterization, so that the LHS is easier to work with then the RHS.

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.

If the LUB has an explicit characterisation, then why would we be writing down the statement ∃ a, IsLUB s a which hides any characterisation?

@vihdzp vihdzp Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Because you can use your explicit characterization, rather than having to show that sSup s, which might or might not have useful def-eqs, equals this characterization.

To put it another way, the LHS is more syntactically general.

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.

I'm not totally convinced by that reasoning (for example, mul_zero would be an unhelpful simp lemma when you have a characterization of (. * .)). But I'm not that much attached to the idea of making this @[simp] that I want to block the PR over this discussion. Let's instead see what happens downstream when this PR gets merged!

Comment thread Mathlib/Order/Bounds/Basic.lean Resolved
@Vierkantor Vierkantor added the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Aug 10, 2026
@github-actions github-actions Bot removed the merge-conflict The PR has a merge conflict with master, and needs manual merging. (this label is managed by a bot) label Sep 18, 2026
@astrainfinita astrainfinita removed the awaiting-author Reply -awaiting-author to remove the label on your PR once you have addressed all comments. label Sep 18, 2026
@Vierkantor

Copy link
Copy Markdown
Contributor

Thank you, let's get it merged! 🎉

bors r+

@mathlib-bors mathlib-bors Bot added the ready-to-merge This PR has been sent to bors. label Sep 24, 2026
mathlib-bors Bot pushed a commit that referenced this pull request Sep 24, 2026
This PR introduces `OrderSupSet` and `OrderInfSet`, which are typeclasses expressing that `sSup` (resp., `sInf`) returns the least upper bound (resp., the greatest lower bound) of a set whenever one exists.

This allows us to prove properties about the `sSup` of specific sets (such as `∅`, singletons, finite sets, and `univ`) without any typeclasses asserting the existence of LUBs. For example, `sSup ∅ = ⊥` holds for any type equipped with `OrderBot` `OrderSupSet`, no longer requiring typeclasses like `ConditionallyCompleteLinearOrderBot`.

For a general set `s`, this gives a uniform way to extend results about `IsLUB s a → motive a` to `motive (sSup s)`, `motive (⨆ i, f i)`, `motive (a ⊔ b)`, etc., which allows proof reuse for basic API such as [`csSup_insert`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Order/ConditionallyCompleteLattice/Basic.html#csSup_insert), [`iSup_insert`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Order/CompleteLattice/Basic.html#iSup_insert), and [`sSup_insert`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Order/CompleteLattice/Basic.html#sSup_insert) and downstream code like [`csSup_add`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Algebra/Order/Group/Pointwise/CompleteLattice.html#csSup_add), [`sSup_add`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Algebra/Order/Group/Pointwise/CompleteLattice.html#sSup_add), and [`sup_add`](https://leanprover-community.github.io/mathlib4_docs/Mathlib/Algebra/Order/Group/Lattice.html#sup_add).

Furthermore, this allows us to refactor incrementally, reducing the dependency of results about various completeness typeclasses on the specific implementation of `sSup`.
@mathlib-bors mathlib-bors Bot added the bors-staging This PR is currently being built by bors on the staging branch. label Sep 24, 2026
@mathlib-bors

mathlib-bors Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Pull request successfully merged into master.

Build succeeded:

@mathlib-bors mathlib-bors Bot changed the title feat: OrderSupSet [Merged by Bors] - feat: OrderSupSet Sep 24, 2026
@mathlib-bors mathlib-bors Bot closed this Sep 24, 2026
the greatest lower bound of a set whenever one exists. -/
@[to_dual existing]
class OrderInfSet (α : Type*) [LE α] extends InfSet α where
protected isGLB_sInf_of_isGLB s a : IsGLB s a → IsGLB s (sInf s)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we usually prefer explicit types:

Suggested change
protected isGLB_sInf_of_isGLB s a : IsGLB s a → IsGLB s (sInf s)
protected isGLB_sInf_of_isGLB (s : Set α) (a : α) : IsGLB s a → IsGLB s (sInf s)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bors-staging This PR is currently being built by bors on the staging branch. ready-to-merge This PR has been sent to bors. t-order Order theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants