Skip to content

Conversation

@YanYablonovskiy
Copy link
Contributor

@YanYablonovskiy YanYablonovskiy commented Dec 31, 2025

Adding OrderTypes, equivalence classes of linear orders up to order isomorphism.


Open in Gitpod

@github-actions github-actions bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Dec 31, 2025
@github-actions
Copy link

github-actions bot commented Dec 31, 2025

PR summary b79634a5c1

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Order.Types.Defs (new file) 137
Mathlib.Order.Types.Basic (new file) 537

Declarations diff

+ OrderType
+ OrderType.instSetoid
+ _root_.RelIso.orderType_eq
+ bot_eq_zero
+ card
+ card_le_card
+ card_mono
+ card_one
+ card_type
+ card_zero
+ emptySumLex
+ emptySumLex_apply_inr
+ eta
+ inductionOn
+ inductionOn₂
+ inductionOn₃
+ inhabited
+ instNeZeroOne
+ instOrdBot
+ instance (n : Nat) : OfNat OrderType n
+ instance (o : OrderType) : LinearOrder o.ToType
+ instance : Add OrderType.{u}
+ instance : AddMonoid OrderType
+ instance : HAdd OrderType.{u} OrderType.{v} OrderType.{max u v}
+ instance : HMul OrderType.{u} OrderType.{v} OrderType.{max u v}
+ instance : LeftDistribClass OrderType
+ instance : Monoid OrderType
+ instance : Mul OrderType
+ instance : One OrderType
+ instance : Preorder OrderType
+ instance : ZeroLEOneClass OrderType
+ isEmpty_toType_iff
+ isEmpty_toType_zero
+ liftOn
+ liftOn_type
+ nonempty_toType_iff
+ nontrivial
+ not_lt_zero
+ ofIsEmpty
+ one_def
+ one_ne_zero
+ pos_iff_ne_zero
+ prodAssoc
+ prodLexAssoc
+ prodLexCongr
+ sumLexEmpty
+ sumLexEmpty_apply_inl
+ sumLexProdLexDistrib
+ theta
+ type
+ type_add
+ type_eq
+ type_eq_one
+ type_eq_zero
+ type_le_type
+ type_le_type_iff
+ type_mul
+ type_ne_zero
+ type_ne_zero_iff
+ type_of_isEmpty
+ type_of_unique
+ type_toType
+ zero
+ zero_le

You can run this locally as follows
## summary with just the declaration names:
./scripts/declarations_diff.sh <optional_commit>

## more verbose report:
./scripts/declarations_diff.sh long <optional_commit>

The doc-module for script/declarations_diff.sh contains some details about this script.


No changes to technical debt.

You can run this locally as

./scripts/technical-debt-metrics.sh 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).

@github-actions github-actions bot added the t-order Order theory label Dec 31, 2025
Copy link
Collaborator

@vihdzp vihdzp 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 working on this! I've got lots of small suggestions/improvements, and a few larger ones.

Copy link
Collaborator

@vihdzp vihdzp 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 working on this! I've got lots of small suggestions/improvements, and a few larger ones.

Comment on lines 294 to 301
/-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/
def omega0 : OrderType := type ℕ

/-- The order type of the rational numbers. -/
def eta : OrderType := type ℚ

/-- The order type of the real numbers on the interval `(0,1)`. -/
def theta : OrderType := type (Set.Ioo (0 : ℝ) 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would be good to double-check these notations are the literature-approved ones

Copy link
Collaborator

Choose a reason for hiding this comment

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

I can vouch for omega and eta, I'd have to check for theta.

Copy link
Collaborator

@YaelDillies YaelDillies Dec 31, 2025

Choose a reason for hiding this comment

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

Also surely type (Set.Ioo (0 : ℝ) 1) = type ℝ, no?

Copyright (c) _
-/
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.SetTheory.Ordinal.Basic
Copy link
Collaborator

Choose a reason for hiding this comment

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

We already talked about this, but IMO ordinals should import order types, not the other way around

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Dec 31, 2025
@vihdzp
Copy link
Collaborator

vihdzp commented Jan 1, 2026

(once you've applied all/most suggestions, remove the awaiting author tag and please make sure to notify me!)

@YanYablonovskiy
Copy link
Contributor Author

YanYablonovskiy commented Jan 4, 2026

(once you've applied all/most suggestions, remove the awaiting author tag and please make sure to notify me!)

@vihdzp I believe i have addressed almost all of the points, some things still need to be moved but the monoid definition prevents imports of Ordertype from cardinal (for now) , and certain missing instances made it hard to move the empty sum order iso parts.

The other file changes will be made into separate small PRs i imagine.

@YanYablonovskiy
Copy link
Contributor Author

-awaiting-author

@github-actions github-actions bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Jan 4, 2026
Copy link
Collaborator

@YaelDillies YaelDillies left a comment

Choose a reason for hiding this comment

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

Could you make a preliminary PR for the order isos?

Comment on lines 63 to 68
/-- An auxiliary structure representing a linearly ordered type. -/
@[ext]
structure LinearOrderedType : Type (u + 1) where
carrier : Type u
le : LE carrier
isLinearOrder_carrier : Std.IsLinearOrder carrier
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason not to use LinOrd here?

Copy link
Collaborator

@vihdzp vihdzp Jan 4, 2026

Choose a reason for hiding this comment

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

I suggested this design and gave an argument against LinOrd in this reply. In particular:

  • I think the categorical properties of LinOrd are irrelevant here.
  • We don't need the extra structure that LinearOrder comes bundled with to define an order type. Don't agree with this part anymore, see here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

  • I think the categorical properties of LinOrd are irrelevant here.

Sure, but we are free to ignore those categorical properties? I am worried about two definitions doing the exact same thing.

Copy link
Collaborator

Choose a reason for hiding this comment

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

LinOrd is a category of mathematical interest. LinearOrderedType is an auxiliary structure which should have no public API that exists only to declare a much more interesting quotient on. Compare WellOrder.

@YaelDillies YaelDillies added the awaiting-author A reviewer has asked the author a question or requested changes. label Jan 4, 2026
@vihdzp
Copy link
Collaborator

vihdzp commented Jan 4, 2026

You know, I thought about the Std.IsLinearOrder thing a bit more, and I'm no longer sure that was a good idea. I looked throughout the code for examples of using Ordinal.type on anything that didn't already have a LinearOrder + WellFoundedLT instance and found nothing. We do care about the rank function in general well-founded relations (which is what I was remembering), but that can be implemented regardless.

So yeah, I think we could just define OrderType as a quotient of LinearOrders, and later redefine Ordinal.type so that it accepts only a LinearOrder + WellFoundedLT type rather than an unbundled IsWellOrdered relation. In fact, we could very well deprecate the IsWellOrder typeclass altogether.

But maybe wait for Yaël's opinion before you change anything, I don't want you to have to undo your work all over again!

@YaelDillies
Copy link
Collaborator

wait for Yaël's opinion before you change anything

I do think we should use LinearOrder here. Furthermore, I don't buy the argument that we shouldn't use LinOrd. If your issue with it is that it would needlessly import category theory, then we should split the file where it is defined into a category-less part.

@vihdzp
Copy link
Collaborator

vihdzp commented Jan 5, 2026

All we actually need from LinOrd is the definition. But if we can move it out into some defs file then sure, we might as well use it.

@YaelDillies
Copy link
Collaborator

I think it's reasonable to move it to Order.Defs

@YanYablonovskiy
Copy link
Contributor Author

Order/Type/... ended up highlighting Type as a keyword, Types sounds strange. Order/OrderType is echoing Order. So not sure what to name it.

@YanYablonovskiy
Copy link
Contributor Author

-awaiting-author

@github-actions github-actions bot removed the awaiting-author A reviewer has asked the author a question or requested changes. label Jan 5, 2026
Copy link
Collaborator

@vihdzp vihdzp left a comment

Choose a reason for hiding this comment

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

Small nitpicks of mine. This PR is shaping up quite nicely!

You could already start properly PRing the first pieces of this. The material on Order.Hom looks quite good (modulo some small suggestions) and I'd like to use it to golf the analogous proofs on Ordinal. You could then PR the Order.Types.Defs file, and at that point we can start thinking about what kind of API to add where and how to eventually link this to Ordinal.

@@ -0,0 +1,229 @@
/-
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think Type would be a better name for the folder. We generally don't pluralize names of mathematical objects in the file structure (we have Order.CompleteSublattice say, rather than Order.CompleteSublattices).

Copy link
Collaborator

Choose a reason for hiding this comment

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

or OrderType?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The Order part of OrderType seems redundant given that we're already in the Order folder.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But Order.Type sounds like it should be about order properties of Type

Copy link
Collaborator

@vihdzp vihdzp Jan 5, 2026

Choose a reason for hiding this comment

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

I guess we can also just keep the folder named Order.Types. Matches ModelTheory.Types, for instance.

le_trans a b c :=
Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ ↦ ⟨f.trans g⟩

instance instNeZeroOne : NeZero (1 : OrderType) :=
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather not be naming instances unless we have a legitimate reason to.

Suggested change
instance instNeZeroOne : NeZero (1 : OrderType) :=
instance : NeZero (1 : OrderType) :=

Copy link
Collaborator

Choose a reason for hiding this comment

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

Disagree. I'd rather make sure the instances can be found by name

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the default name given here a bad one?

add := Quotient.map₂ (fun r s ↦ ⟨(r ⊕ₗ s)⟩)
fun _ _ ha _ _ hb ↦ ⟨OrderIso.sumLexCongr (Classical.choice ha) (Classical.choice hb)⟩

instance : HAdd OrderType.{u} OrderType.{v} OrderType.{max u v} where
Copy link
Collaborator

Choose a reason for hiding this comment

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

def eta : OrderType := type ℚ

/-- The order type of the real numbers. -/
def theta : OrderType := type ℝ
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll reiterate my suggestion that I'd like to see this in another file, probably one dedicated to η-orders entirely. We shouldn't be importing the real numbers on what's really quite basic order theory.

@vihdzp
Copy link
Collaborator

vihdzp commented Jan 5, 2026

🌶️ take incoming: should we eventually move the Ordinal folder to Order or even to Order.Type? It feels kind of silly to categorize it as "set theory" when our development is not even based on ZFC sets. And it'd be nice to keep these parallel developments (general order types, ordinals) close together.

@YaelDillies YaelDillies changed the title feat: OrderTypes feat: order types Jan 5, 2026
@YanYablonovskiy
Copy link
Contributor Author

Still need to move some of the OrderTypes , and will open a seperate pr for the OrderIso/Lex lemmas.

-awaiting-author

commit d51b84d
Author: YanYablonovskiy <[email protected]>
Date:   Tue Jan 6 20:13:26 2026 +1100

    OrderIso prod lemmas adjustment

commit 4c41035
Merge: b88c734 15f6691
Author: Yan Yablonovskiy <[email protected]>
Date:   Tue Jan 6 20:04:32 2026 +1100

    Merge branch 'master' into master

commit b88c734
Author: YanYablonovskiy <[email protected]>
Date:   Tue Jan 6 19:33:15 2026 +1100

    Changes from review

commit 8252446
Author: Yan Yablonovskiy <[email protected]>
Date:   Tue Jan 6 16:00:09 2026 +1100

    Apply suggestions from code review

    Co-authored-by: Violeta Hernández Palacios <[email protected]>

commit 8ac8458
Author: YanYablonovskiy <[email protected]>
Date:   Tue Jan 6 01:11:04 2026 +1100

    Change mathlib imports from `OrderType`

    `OrderType.lean` no longer exists

commit f353fe8
Merge: 30bd77d 959c852
Author: Yan Yablonovskiy <[email protected]>
Date:   Mon Jan 5 23:17:21 2026 +1100

    Merge branch 'leanprover-community:master' into master

commit 30bd77d
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 21:49:57 2026 +1100

    Refactor as per suggestions, back to `LinOrd`

commit f8cd844
Merge: f04b327 a57b343
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 21:49:30 2026 +1100

    Merge branch 'master' of https://github.com/YanYablonovskiy/mathlib4_Order-types-Issue28278

commit f04b327
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 11:36:50 2026 +1100

    Apply suggestions

commit a57b343
Merge: 5937b50 8c8bf56
Author: Yan Yablonovskiy <[email protected]>
Date:   Mon Jan 5 11:30:56 2026 +1100

    Merge branch 'leanprover-community:master' into master

commit 5937b50
Merge: 07abc73 2330302
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 10:21:08 2026 +1100

    Merge branch 'master' of https://github.com/YanYablonovskiy/mathlib4_Order-types-Issue28278

commit 2330302
Author: Yan Yablonovskiy <[email protected]>
Date:   Mon Jan 5 10:20:45 2026 +1100

    Apply suggestions from code review

    Co-authored-by: Yaël Dillies <[email protected]>
    Co-authored-by: Violeta Hernández Palacios <[email protected]>

commit 07abc73
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 00:44:02 2026 +1100

    Fix recommended_spellings

commit b25cb4c
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 00:37:52 2026 +1100

    Add doc-string and some more typos

commit 067b8cd
Author: YanYablonovskiy <[email protected]>
Date:   Mon Jan 5 00:31:32 2026 +1100

    Minor typos

commit 4b5a837
Author: YanYablonovskiy <[email protected]>
Date:   Sun Jan 4 22:26:24 2026 +1100

    Finish conversation review suggestions

commit 5429c1b
Author: Yan Yablonovskiy <[email protected]>
Date:   Fri Jan 2 23:31:29 2026 +1100

    Apply suggestions from code review

    [skip ci]

    Co-authored-by: Yaël Dillies <[email protected]>
    Co-authored-by: Violeta Hernández Palacios <[email protected]>

commit 630f0ea
Author: YanYablonovskiy <[email protected]>
Date:   Fri Jan 2 23:14:37 2026 +1100

    Style fix

commit bf5166d
Author: YanYablonovskiy <[email protected]>
Date:   Fri Jan 2 22:58:10 2026 +1100

    Fix module error

commit 2f0a005
Merge: 44753fe 519f454
Author: Yan Yablonovskiy <[email protected]>
Date:   Fri Jan 2 20:11:02 2026 +1100

    Merge branch 'leanprover-community:master' into master

commit 44753fe
Author: YanYablonovskiy <[email protected]>
Date:   Fri Jan 2 19:42:27 2026 +1100

    Bump

commit 43b7d68
Author: YanYablonovskiy <[email protected]>
Date:   Fri Jan 2 19:18:34 2026 +1100

    Clean up imports, get rid of sorries, and address some comments

commit f888e2b
Author: YanYablonovskiy <[email protected]>
Date:   Thu Jan 1 22:12:33 2026 +1100

    Update OrderType.lean

    Add copyright
    [skip actions]

commit 9848662
Author: YanYablonovskiy <[email protected]>
Date:   Thu Jan 1 21:56:01 2026 +1100

    Update OrderType.lean

commit b8acc2e
Author: Yan Yablonovskiy <[email protected]>
Date:   Thu Jan 1 20:15:25 2026 +1100

    Apply suggestions from code review

    Co-authored-by: Violeta Hernández Palacios <[email protected]>
    Co-authored-by: Yaël Dillies <[email protected]>

commit a5e62be
Merge: 6aa39b3 de80207
Author: YanYablonovskiy <[email protected]>
Date:   Wed Dec 31 16:34:44 2025 +1100

    Merge branch 'master' of https://github.com/YanYablonovskiy/mathlib4_Order-types-Issue28278

commit 6aa39b3
Author: YanYablonovskiy <[email protected]>
Date:   Wed Dec 31 16:34:33 2025 +1100

    Update OrderType.lean

commit de80207
Merge: 669a1d3 6dc6d70
Author: Yan Yablonovskiy <[email protected]>
Date:   Wed Dec 31 16:34:24 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit 669a1d3
Merge: a90d529 6371049
Author: Yan Yablonovskiy <[email protected]>
Date:   Mon Dec 29 10:38:08 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit a90d529
Merge: 24bb5b0 cc5691d
Author: Yan Yablonovskiy <[email protected]>
Date:   Mon Dec 22 13:06:26 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit 24bb5b0
Merge: 4985680 5334b1e
Author: Yan Yablonovskiy <[email protected]>
Date:   Wed Nov 26 18:44:18 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit 4985680
Merge: 711df94 3f87ea8
Author: Yan Yablonovskiy <[email protected]>
Date:   Sun Nov 23 12:48:18 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit 711df94
Merge: 6534400 b3cf7a0
Author: Yan Yablonovskiy <[email protected]>
Date:   Sat Nov 22 13:48:50 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit 6534400
Merge: bb1a642 56c98a5
Author: Yan Yablonovskiy <[email protected]>
Date:   Thu Nov 20 18:46:50 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit bb1a642
Author: YanYablonovskiy <[email protected]>
Date:   Mon Oct 20 21:27:21 2025 +1100

    Update OrderType.lean

commit f427a91
Author: YanYablonovskiy <[email protected]>
Date:   Mon Oct 20 18:25:16 2025 +1100

    Update OrderType.lean

commit f6c13a0
Author: YanYablonovskiy <[email protected]>
Date:   Mon Oct 20 17:59:56 2025 +1100

    Update OrderType.lean

commit 78e4c9a
Author: YanYablonovskiy <[email protected]>
Date:   Mon Oct 20 16:29:31 2025 +1100

    Update OrderType.lean

commit e827b3c
Author: YanYablonovskiy <[email protected]>
Date:   Sat Oct 18 00:41:45 2025 +1100

    Update OrderType.lean

commit f5d5427
Author: YanYablonovskiy <[email protected]>
Date:   Sat Oct 18 00:23:18 2025 +1100

    Update OrderType.lean

commit 871acb9
Author: YanYablonovskiy <[email protected]>
Date:   Fri Oct 17 22:32:05 2025 +1100

    Update OrderType.lean

commit 803ced6
Author: YanYablonovskiy <[email protected]>
Date:   Fri Oct 17 20:45:37 2025 +1100

    Update OrderType.lean

commit 2883e90
Author: YanYablonovskiy <[email protected]>
Date:   Thu Oct 16 23:04:21 2025 +1100

    Update OrderType.lean

commit 971c382
Author: Yan Yablonovskiy <[email protected]>
Date:   Thu Oct 16 23:02:18 2025 +1100

    Update OrderType.lean

commit 3db4465
Author: Yan Yablonovskiy <[email protected]>
Date:   Thu Oct 16 23:01:46 2025 +1100

    Update OrderType.lean

commit 3e7c325
Author: YanYablonovskiy <[email protected]>
Date:   Thu Oct 16 22:59:05 2025 +1100

    Update OrderType.lean

commit ce284fa
Author: Yan Yablonovskiy <[email protected]>
Date:   Tue Oct 14 20:26:41 2025 +1100

    Update OrderType.lean

commit e0e79c8
Author: YanYablonovskiy <[email protected]>
Date:   Tue Oct 14 19:02:32 2025 +1100

    Create OrderTypes file with definition and some generalisation from Ordinal

commit e78fa58
Merge: aa54d18 3aa3aca
Author: Yan Yablonovskiy <[email protected]>
Date:   Tue Oct 14 19:02:04 2025 +1100

    Merge branch 'leanprover-community:master' into master

commit aa54d18
Merge: 3742a3b efcc0aa
Author: Yan Yablonovskiy <[email protected]>
Date:   Sun Sep 21 15:21:45 2025 +1000

    Merge branch 'leanprover-community:master' into master

commit 3742a3b
Author: YanYablonovskiy <[email protected]>
Date:   Sat Sep 20 22:28:23 2025 +1000

    Create OrderTypes_basic.lean
@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 Jan 16, 2026
@YaelDillies YaelDillies changed the title feat: order types feat: more API about order types Jan 17, 2026
@mathlib4-dependent-issues-bot mathlib4-dependent-issues-bot added the blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) label Jan 17, 2026
@mathlib4-dependent-issues-bot
Copy link
Collaborator

This PR/issue depends on:

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

Labels

blocked-by-other-PR This PR depends on another PR (this label is automatically managed by a bot) new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! t-order Order theory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants