Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
5811e1d
Squashed commit of the following:
YanYablonovskiy Jan 6, 2026
3af5434
Apply suggestions from code review
YanYablonovskiy Jan 7, 2026
ef47f68
Code review suggestions
YanYablonovskiy Jan 7, 2026
148988f
Code review suggestions
YanYablonovskiy Jan 7, 2026
9e7e23c
Fix name
YanYablonovskiy Jan 7, 2026
ff87de3
Create OrderTypes_basic.lean
YanYablonovskiy Sep 20, 2025
cecadc0
Create OrderTypes file with definition and some generalisation from O…
YanYablonovskiy Oct 14, 2025
864c326
Update OrderType.lean
YanYablonovskiy Oct 14, 2025
97c68fb
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
7555422
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
089285e
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
f849290
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
5d01cde
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
e9a59ad
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
b466815
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
8d7d701
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
65202e2
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
4fb4fb7
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
ec8396f
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
89322e2
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
0ed1ebf
Update OrderType.lean
YanYablonovskiy Dec 31, 2025
1c6e1a9
Apply suggestions from code review
YanYablonovskiy Jan 1, 2026
5059d2f
Update OrderType.lean
YanYablonovskiy Jan 1, 2026
43b7dbe
Update OrderType.lean
YanYablonovskiy Jan 1, 2026
39dfd06
Clean up imports, get rid of sorries, and address some comments
YanYablonovskiy Jan 2, 2026
ee629b2
Bump
YanYablonovskiy Jan 2, 2026
7483b63
Fix module error
YanYablonovskiy Jan 2, 2026
948f1f0
Style fix
YanYablonovskiy Jan 2, 2026
33270f4
Apply suggestions from code review
YanYablonovskiy Jan 2, 2026
e3b1e25
Finish conversation review suggestions
YanYablonovskiy Jan 4, 2026
0bdafa0
Minor typos
YanYablonovskiy Jan 4, 2026
ad70193
Add doc-string and some more typos
YanYablonovskiy Jan 4, 2026
1b893c1
Fix recommended_spellings
YanYablonovskiy Jan 4, 2026
9cef36a
Apply suggestions from code review
YanYablonovskiy Jan 4, 2026
6aa37fd
Apply suggestions
YanYablonovskiy Jan 5, 2026
04ac738
Refactor as per suggestions, back to `LinOrd`
YanYablonovskiy Jan 5, 2026
e9e9e65
Change mathlib imports from `OrderType`
YanYablonovskiy Jan 5, 2026
fce844e
Apply suggestions from code review
YanYablonovskiy Jan 6, 2026
0d52146
Changes from review
YanYablonovskiy Jan 6, 2026
965e013
Create OrderTypes_basic.lean
YanYablonovskiy Sep 20, 2025
13b836f
Create OrderTypes file with definition and some generalisation from O…
YanYablonovskiy Oct 14, 2025
d65ff8b
Update OrderType.lean
YanYablonovskiy Oct 14, 2025
9029164
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
aed8c8e
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
40bbd28
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
d77f4b9
Update OrderType.lean
YanYablonovskiy Oct 16, 2025
c93905b
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
d9e3fbb
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
a2ab3a2
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
7403c99
Update OrderType.lean
YanYablonovskiy Oct 17, 2025
5c7eecb
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
c64b512
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
fb0b868
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
2626f35
Update OrderType.lean
YanYablonovskiy Oct 20, 2025
3ffda1d
Update OrderType.lean
YanYablonovskiy Dec 31, 2025
179c5c1
Apply suggestions from code review
YanYablonovskiy Jan 1, 2026
58f6b09
Update OrderType.lean
YanYablonovskiy Jan 1, 2026
580ecfb
Update OrderType.lean
YanYablonovskiy Jan 1, 2026
6bc98e1
Clean up imports, get rid of sorries, and address some comments
YanYablonovskiy Jan 2, 2026
dae7f9e
Bump
YanYablonovskiy Jan 2, 2026
83154e2
Fix module error
YanYablonovskiy Jan 2, 2026
88cf3f0
Style fix
YanYablonovskiy Jan 2, 2026
2e88771
Apply suggestions from code review
YanYablonovskiy Jan 2, 2026
b215430
Finish conversation review suggestions
YanYablonovskiy Jan 4, 2026
e27e412
Minor typos
YanYablonovskiy Jan 4, 2026
c9d8216
Add doc-string and some more typos
YanYablonovskiy Jan 4, 2026
9886505
Fix recommended_spellings
YanYablonovskiy Jan 4, 2026
3970088
Apply suggestions from code review
YanYablonovskiy Jan 4, 2026
6468ea9
Apply suggestions
YanYablonovskiy Jan 5, 2026
b235289
Refactor as per suggestions, back to `LinOrd`
YanYablonovskiy Jan 5, 2026
d1a7d79
Change mathlib imports from `OrderType`
YanYablonovskiy Jan 5, 2026
d47b8cf
Apply suggestions from code review
YanYablonovskiy Jan 6, 2026
3e07307
Changes from review
YanYablonovskiy Jan 6, 2026
9c47226
Apply suggestion `0 < o → o ≠ 0` to `0 < o ↔ o ≠ 0`
YanYablonovskiy Jan 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Mathlib.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5652,6 +5652,8 @@ public import Mathlib.Order.SymmDiff
public import Mathlib.Order.Synonym
public import Mathlib.Order.TeichmullerTukey
public import Mathlib.Order.TransfiniteIteration
public import Mathlib.Order.Types.Defs
public import Mathlib.Order.Types.Basic
public import Mathlib.Order.TypeTags
public import Mathlib.Order.ULift
public import Mathlib.Order.UpperLower.Basic
Expand Down
16 changes: 16 additions & 0 deletions Mathlib/Data/Sum/Order.lean
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,22 @@ theorem sumLexDualAntidistrib_symm_inr :
(sumLexDualAntidistrib α β).symm (inr (toDual a)) = toDual (inl a) :=
rfl

/-- `Equiv.sumEmpty` as an `OrderIso` with the lexicographic sum. -/
def sumLexEmpty [IsEmpty β] :
Lex (α ⊕ β) ≃o α := RelIso.sumLexEmpty ..

/-- `Equiv.emptySum` as an `OrderIso` with the lexicographic sum. -/
def emptySumLex [IsEmpty β] :
Lex (β ⊕ α) ≃o α := RelIso.emptySumLex ..

@[simp]
lemma sumLexEmpty_apply_inl [IsEmpty β] (x : α) :
sumLexEmpty (β := β) (toLex <| .inl x) = x := rfl

@[simp]
lemma emptySumLex_apply_inr [IsEmpty β] (x : α) :
emptySumLex (β := β) (toLex <| .inr x) = x := rfl

end OrderIso

variable [LE α]
Expand Down
17 changes: 0 additions & 17 deletions Mathlib/Order/Category/LinOrd.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,8 @@ open CategoryTheory

universe u

/-- The category of linear orders. -/
structure LinOrd where
/-- Construct a bundled `LinOrd` from the underlying type and typeclass. -/
of ::
/-- The underlying linearly ordered type. -/
(carrier : Type*)
[str : LinearOrder carrier]

attribute [instance] LinOrd.str

initialize_simps_projections LinOrd (carrier → coe, -str)

namespace LinOrd

instance : CoeSort LinOrd (Type _) :=
⟨LinOrd.carrier⟩

attribute [coe] LinOrd.carrier

set_option backward.privateInPublic true in
/-- The type of morphisms in `LinOrd R`. -/
@[ext]
Expand Down
21 changes: 21 additions & 0 deletions Mathlib/Order/Defs/LinearOrder.lean
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,25 @@ instance : Std.LawfulBCmp (compare (α := α)) where

end Ord

/-- The category of linear orders. -/
structure LinOrd where
/-- Construct a bundled `LinOrd` from the underlying type and typeclass. -/
of ::
/-- The underlying linearly ordered type. -/
(carrier : Type*)
[str : LinearOrder carrier]

attribute [instance] LinOrd.str

initialize_simps_projections LinOrd (carrier → coe, -str)

namespace LinOrd

instance : CoeSort LinOrd (Type _) :=
⟨LinOrd.carrier⟩

attribute [coe] LinOrd.carrier

end LinOrd

end LinearOrder
11 changes: 11 additions & 0 deletions Mathlib/Order/Hom/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,13 @@ def prodComm : α × β ≃o β × α where
toEquiv := Equiv.prodComm α β
map_rel_iff' := Prod.swap_le_swap

/-- `Equiv.prodAssoc` promoted to an order isomorphism. -/
@[simps! (attr := grind =)]
def prodAssoc (α β γ : Type*) [LE α] [LE β] [LE γ] :
(α × β) × γ ≃o α × (β × γ) where
toEquiv := .prodAssoc α β γ
map_rel_iff' := @fun ⟨⟨_, _⟩, _⟩ ⟨⟨_, _⟩, _⟩ ↦ by simp [Equiv.prodAssoc, and_assoc]

@[simp]
theorem coe_prodComm : ⇑(prodComm : α × β ≃o β × α) = Prod.swap :=
rfl
Expand Down Expand Up @@ -1069,6 +1076,10 @@ noncomputable def ofUnique
toEquiv := Equiv.ofUnique α β
map_rel_iff' := by simp

/-- `Equiv.equivOfIsEmpty` promoted to an `OrderIso`. -/
def ofIsEmpty (α β : Type*) [Preorder α] [Preorder β] [IsEmpty α] [IsEmpty β] : α ≃o β :=
⟨Equiv.equivOfIsEmpty α β, @isEmptyElim _ _ _⟩

end OrderIso

namespace Equiv
Expand Down
29 changes: 29 additions & 0 deletions Mathlib/Order/Hom/Lex.lean
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,33 @@ variable {α β} in
theorem uniqueProd_apply [Preorder α] [Unique α] [LE β] (x : α ×ₗ β) :
uniqueProd α β x = (ofLex x).2 := rfl

/-- `Equiv.prodAssoc` promoted to an order isomorphism of lexicographic products. -/
@[simps!]
def prodLexAssoc (α β γ : Type*)
[Preorder α] [Preorder β] [Preorder γ] : (α ×ₗ β) ×ₗ γ ≃o α ×ₗ β ×ₗ γ where
toEquiv := .trans ofLex <| .trans (.prodCongr ofLex <| .refl _) <|
.trans (.prodAssoc α β γ) <| .trans (.prodCongr (.refl _) toLex) <| toLex
map_rel_iff' := by
simp only [Prod.Lex.le_iff, Prod.Lex.lt_iff, Equiv.trans_apply, Equiv.prodCongr_apply,
Equiv.prodAssoc_apply]
grind [EmbeddingLike.apply_eq_iff_eq, ofLex_toLex]

/-- `Equiv.sumProdDistrib` promoted to an order isomorphism of lexicographic products.

Right distributivity doesn't hold. A counterexample is `ℕ ×ₗ (Unit ⊕ₗ Unit) ≃o ℕ`
which is not isomorphic to `ℕ ×ₗ Unit ⊕ₗ ℕ ×ₗ Unit ≃o ℕ ⊕ₗ ℕ`. -/
@[simps!]
def sumLexProdLexDistrib (α β γ : Type*)
[Preorder α] [Preorder β] [Preorder γ] : (α ⊕ₗ β) ×ₗ γ ≃o α ×ₗ γ ⊕ₗ β ×ₗ γ where
toEquiv := .trans ofLex <| .trans (.prodCongr ofLex <| .refl _) <|
.trans (.sumProdDistrib α β γ) <| .trans (.sumCongr toLex toLex) toLex
map_rel_iff' := by simp [Prod.Lex.le_iff]

/-- `Equiv.prodCongr` promoted to an order isomorphism between lexicographic products. -/
@[simps! apply]
def prodLexCongr {α β γ δ : Type*} [Preorder α] [Preorder β]
[Preorder γ] [Preorder δ] (ea : α ≃o β) (eb : γ ≃o δ) : α ×ₗ γ ≃o β ×ₗ δ where
toEquiv := ofLex.trans ((Equiv.prodCongr ea eb).trans toLex)
map_rel_iff' := by simp [Prod.Lex.le_iff]

end Prod.Lex
145 changes: 145 additions & 0 deletions Mathlib/Order/Types/Basic.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/-
Copyright (c) 2025 Yan Yablonovskiy. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yan Yablonovskiy
-/
module

public import Mathlib.Data.Real.Basic
public import Mathlib.SetTheory.Cardinal.Order
public import Mathlib.Algebra.Ring.Defs
public import Mathlib.Order.Fin.Basic
public import Mathlib.Order.Types.Defs
public import Mathlib.Order.Interval.Set.Basic

/-!

## Main definitions

* `OrderType.card o`: the cardinality of an OrderType `o`.
* `o₁ + o₂`: the lexicographic sum of order types, which forms an `AddMonoid`.
* `o₁ * o₂`: the lexicographic product of order types, which forms a `MonoidWithZero`.

## Notation

The following are notations in the `OrderType` namespace:

* `η` is a notation for the order type of `ℚ` with its natural order.
* `θ` is a notation for the order type of `ℝ` with its natural order.

## References

* <https://en.wikipedia.org/wiki/Order_type>
* Dauben, J. W. Georg Cantor: His Mathematics and Philosophy of the Infinite. Princeton,
NJ: Princeton University Press, 1990.
* Enderton, Herbert B. Elements of Set Theory. United Kingdom: Academic Press, 1977.

## Tags

order type, order isomorphism, linear order
-/

public noncomputable section

namespace OrderType

universe u v w w'

variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type w'}

instance : ZeroLEOneClass OrderType :=
⟨OrderType.zero_le _⟩

instance : Add OrderType.{u} where
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.

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

instance : AddMonoid OrderType where
add_assoc o₁ o₂ o₃ :=
inductionOn₃ o₁ o₂ o₃ fun α _ β _ γ _ ↦ (OrderIso.sumLexAssoc α β γ).orderType_eq
zero_add o :=
inductionOn o (fun α _ ↦ RelIso.orderType_eq OrderIso.emptySumLex)
add_zero o :=
inductionOn o (fun α _ ↦ RelIso.orderType_eq OrderIso.sumLexEmpty)
nsmul := nsmulRec

instance (n : Nat) : OfNat OrderType n where
ofNat := Fin n |> type

@[simp]
lemma type_add (α : Type u) (β : Type v) [LinearOrder α] [LinearOrder β] :
type (α ⊕ₗ β) = type α + type β := rfl

instance : Mul OrderType where
mul := Quotient.map₂ (fun r s ↦ ⟨(s ×ₗ r)⟩)
fun _ _ ha _ _ hb ↦ ⟨Prod.Lex.prodLexCongr (Classical.choice hb) (Classical.choice ha)⟩

instance : HMul OrderType.{u} OrderType.{v} OrderType.{max u v} where
hMul := Quotient.map₂ (fun r s ↦ ⟨(s ×ₗ r)⟩)
fun _ _ ha _ _ hb ↦ ⟨Prod.Lex.prodLexCongr (Classical.choice hb) (Classical.choice ha)⟩

@[simp]
lemma type_mul (α : Type u) (β : Type v) [LinearOrder α] [LinearOrder β] :
type (α ×ₗ β) = type β * type α := rfl

instance : Monoid OrderType where
mul_assoc o₁ o₂ o₃ :=
inductionOn₃ o₁ o₂ o₃ (fun α _ β _ γ _ ↦
RelIso.orderType_eq (Prod.Lex.prodLexAssoc γ β α).symm)
one_mul o := inductionOn o (fun α _ ↦ RelIso.orderType_eq (Prod.Lex.prodUnique α PUnit))
mul_one o := inductionOn o (fun α _ ↦ RelIso.orderType_eq (Prod.Lex.uniqueProd PUnit α)) --6

instance : LeftDistribClass OrderType where
left_distrib a b c := by
refine inductionOn₃ a b c (fun _ _ _ _ _ _ ↦ ?_)
simp only [←type_mul,←type_add]
exact RelIso.orderType_eq (Prod.Lex.sumLexProdLexDistrib _ _ _)

/-- The order type of the rational numbers. -/
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.


@[inherit_doc]
scoped notation "η" => OrderType.eta
recommended_spelling "eta" for "η" in [eta, «termη»]

@[inherit_doc]
scoped notation "θ" => OrderType.theta
recommended_spelling "theta" for "θ" in [theta, «termθ»]

section Cardinal

open Cardinal

/-- The cardinal of an `OrderType` is the cardinality of any type on which a relation
with that order type is defined. -/
@[expose]
def card : OrderType → Cardinal :=
Quotient.map _ fun _ _ ⟨e⟩ ↦ ⟨e.toEquiv⟩

@[simp]
theorem card_type [LinearOrder α] : card (type α) = #α :=
rfl

@[gcongr]
theorem card_le_card {o₁ o₂ : OrderType} : o₁ ≤ o₂ → card o₁ ≤ card o₂ :=
inductionOn o₁ fun _ ↦ inductionOn o₂ fun _ _ ⟨f⟩ ↦ ⟨f.toEmbedding⟩

theorem card_mono : Monotone card := by
rw [Monotone]; exact @card_le_card

@[simp]
theorem card_zero : card 0 = 0 := mk_eq_zero _

@[simp]
theorem card_one : card 1 = 1 := mk_eq_one _

end Cardinal

end OrderType
Loading
Loading