-
Notifications
You must be signed in to change notification settings - Fork 1k
feat: more API about order types #33420
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
base: master
Are you sure you want to change the base?
Changes from all commits
5811e1d
3af5434
ef47f68
148988f
9e7e23c
ff87de3
cecadc0
864c326
97c68fb
7555422
089285e
f849290
5d01cde
e9a59ad
b466815
8d7d701
65202e2
4fb4fb7
ec8396f
89322e2
0ed1ebf
1c6e1a9
5059d2f
43b7dbe
39dfd06
ee629b2
7483b63
948f1f0
33270f4
e3b1e25
0bdafa0
ad70193
1b893c1
9cef36a
6aa37fd
04ac738
e9e9e65
fce844e
0d52146
965e013
13b836f
d65ff8b
9029164
aed8c8e
40bbd28
d77f4b9
c93905b
d9e3fbb
a2ab3a2
7403c99
5c7eecb
c64b512
fb0b868
2626f35
3ffda1d
179c5c1
58f6b09
580ecfb
6bc98e1
dae7f9e
83154e2
88cf3f0
2e88771
b215430
e27e412
c9d8216
9886505
3970088
6468ea9
b235289
d1a7d79
d47b8cf
3e07307
9c47226
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I (re)opened a Zulip thread about this: #mathlib4 > Universe-heterogeneous ordinal and cardinal relations @ 💬 |
||
| 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 ℝ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
Uh oh!
There was an error while loading. Please reload this page.