-
Notifications
You must be signed in to change notification settings - Fork 273
/
Basic.lean
1666 lines (1372 loc) · 64.4 KB
/
Basic.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Floris van Doorn
-/
import Mathlib.Data.Sum.Order
import Mathlib.Order.InitialSeg
import Mathlib.SetTheory.Cardinal.Basic
import Mathlib.Tactic.PPWithUniv
#align_import set_theory.ordinal.basic from "leanprover-community/mathlib"@"8ea5598db6caeddde6cb734aa179cc2408dbd345"
/-!
# Ordinals
Ordinals are defined as equivalences of well-ordered sets under order isomorphism. They are endowed
with a total order, where an ordinal is smaller than another one if it embeds into it as an
initial segment (or, equivalently, in any way). This total order is well founded.
## Main definitions
* `Ordinal`: the type of ordinals (in a given universe)
* `Ordinal.type r`: given a well-founded order `r`, this is the corresponding ordinal
* `Ordinal.typein r a`: given a well-founded order `r` on a type `α`, and `a : α`, the ordinal
corresponding to all elements smaller than `a`.
* `enum r o h`: given a well-order `r` on a type `α`, and an ordinal `o` strictly smaller than
the ordinal corresponding to `r` (this is the assumption `h`), returns the `o`-th element of `α`.
In other words, the elements of `α` can be enumerated using ordinals up to `type r`.
* `Ordinal.card o`: the cardinality of an ordinal `o`.
* `Ordinal.lift` lifts an ordinal in universe `u` to an ordinal in universe `max u v`.
For a version registering additionally that this is an initial segment embedding, see
`Ordinal.lift.initialSeg`.
For a version registering that it is a principal segment embedding if `u < v`, see
`Ordinal.lift.principalSeg`.
* `Ordinal.omega` or `ω` is the order type of `ℕ`. This definition is universe polymorphic:
`Ordinal.omega.{u} : Ordinal.{u}` (contrast with `ℕ : Type`, which lives in a specific
universe). In some cases the universe level has to be given explicitly.
* `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`. The main properties of addition
(and the other operations on ordinals) are stated and proved in `Ordinal/Arithmetic.lean`. Here,
we only introduce it and prove its basic properties to deduce the fact that the order on ordinals
is total (and well founded).
* `succ o` is the successor of the ordinal `o`.
* `Cardinal.ord c`: when `c` is a cardinal, `ord c` is the smallest ordinal with this cardinality.
It is the canonical way to represent a cardinal with an ordinal.
A conditionally complete linear order with bot structure is registered on ordinals, where `⊥` is
`0`, the ordinal corresponding to the empty type, and `Inf` is the minimum for nonempty sets and `0`
for the empty set by convention.
## Notations
* `ω` is a notation for the first infinite ordinal in the locale `Ordinal`.
-/
noncomputable section
open Function Cardinal Set Equiv Order
open scoped Classical
open Cardinal InitialSeg
universe u v w
variable {α : Type u} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop}
{t : γ → γ → Prop}
/-! ### Well order on an arbitrary type -/
section WellOrderingThm
-- Porting note: `parameter` does not work
-- parameter {σ : Type u}
variable {σ : Type u}
open Function
theorem nonempty_embedding_to_cardinal : Nonempty (σ ↪ Cardinal.{u}) :=
(Embedding.total _ _).resolve_left fun ⟨⟨f, hf⟩⟩ =>
let g : σ → Cardinal.{u} := invFun f
let ⟨x, (hx : g x = 2 ^ sum g)⟩ := invFun_surjective hf (2 ^ sum g)
have : g x ≤ sum g := le_sum.{u, u} g x
not_le_of_gt (by rw [hx]; exact cantor _) this
#align nonempty_embedding_to_cardinal nonempty_embedding_to_cardinal
/-- An embedding of any type to the set of cardinals. -/
def embeddingToCardinal : σ ↪ Cardinal.{u} :=
Classical.choice nonempty_embedding_to_cardinal
#align embedding_to_cardinal embeddingToCardinal
/-- Any type can be endowed with a well order, obtained by pulling back the well order over
cardinals by some embedding. -/
def WellOrderingRel : σ → σ → Prop :=
embeddingToCardinal ⁻¹'o (· < ·)
#align well_ordering_rel WellOrderingRel
instance WellOrderingRel.isWellOrder : IsWellOrder σ WellOrderingRel :=
(RelEmbedding.preimage _ _).isWellOrder
#align well_ordering_rel.is_well_order WellOrderingRel.isWellOrder
instance IsWellOrder.subtype_nonempty : Nonempty { r // IsWellOrder σ r } :=
⟨⟨WellOrderingRel, inferInstance⟩⟩
#align is_well_order.subtype_nonempty IsWellOrder.subtype_nonempty
end WellOrderingThm
/-! ### Definition of ordinals -/
/-- Bundled structure registering a well order on a type. Ordinals will be defined as a quotient
of this type. -/
structure WellOrder : Type (u + 1) where
/-- The underlying type of the order. -/
α : Type u
/-- The underlying relation of the order. -/
r : α → α → Prop
/-- The proposition that `r` is a well-ordering for `α`. -/
wo : IsWellOrder α r
set_option linter.uppercaseLean3 false in
#align Well_order WellOrder
attribute [instance] WellOrder.wo
namespace WellOrder
instance inhabited : Inhabited WellOrder :=
⟨⟨PEmpty, _, inferInstanceAs (IsWellOrder PEmpty EmptyRelation)⟩⟩
@[simp]
theorem eta (o : WellOrder) : mk o.α o.r o.wo = o := by
cases o
rfl
set_option linter.uppercaseLean3 false in
#align Well_order.eta WellOrder.eta
end WellOrder
/-- Equivalence relation on well orders on arbitrary types in universe `u`, given by order
isomorphism. -/
instance Ordinal.isEquivalent : Setoid WellOrder
where
r := fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≃r s)
iseqv :=
⟨fun _ => ⟨RelIso.refl _⟩, fun ⟨e⟩ => ⟨e.symm⟩, fun ⟨e₁⟩ ⟨e₂⟩ => ⟨e₁.trans e₂⟩⟩
#align ordinal.is_equivalent Ordinal.isEquivalent
/-- `Ordinal.{u}` is the type of well orders in `Type u`, up to order isomorphism. -/
@[pp_with_univ]
def Ordinal : Type (u + 1) :=
Quotient Ordinal.isEquivalent
#align ordinal Ordinal
instance hasWellFoundedOut (o : Ordinal) : WellFoundedRelation o.out.α :=
⟨o.out.r, o.out.wo.wf⟩
#align has_well_founded_out hasWellFoundedOut
instance linearOrderOut (o : Ordinal) : LinearOrder o.out.α :=
IsWellOrder.linearOrder o.out.r
#align linear_order_out linearOrderOut
instance isWellOrder_out_lt (o : Ordinal) : IsWellOrder o.out.α (· < ·) :=
o.out.wo
#align is_well_order_out_lt isWellOrder_out_lt
namespace Ordinal
/-! ### Basic properties of the order type -/
/-- The order type of a well order is an ordinal. -/
def type (r : α → α → Prop) [wo : IsWellOrder α r] : Ordinal :=
⟦⟨α, r, wo⟩⟧
#align ordinal.type Ordinal.type
instance zero : Zero Ordinal :=
⟨type <| @EmptyRelation PEmpty⟩
instance inhabited : Inhabited Ordinal :=
⟨0⟩
instance one : One Ordinal :=
⟨type <| @EmptyRelation PUnit⟩
/-- The order type of an element inside a well order. For the embedding as a principal segment, see
`typein.principalSeg`. -/
def typein (r : α → α → Prop) [IsWellOrder α r] (a : α) : Ordinal :=
type (Subrel r { b | r b a })
#align ordinal.typein Ordinal.typein
@[simp]
theorem type_def' (w : WellOrder) : ⟦w⟧ = type w.r := by
cases w
rfl
#align ordinal.type_def' Ordinal.type_def'
@[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this
theorem type_def (r) [wo : IsWellOrder α r] : (⟦⟨α, r, wo⟩⟧ : Ordinal) = type r := by
rfl
#align ordinal.type_def Ordinal.type_def
@[simp]
theorem type_out (o : Ordinal) : Ordinal.type o.out.r = o := by
rw [Ordinal.type, WellOrder.eta, Quotient.out_eq]
#align ordinal.type_out Ordinal.type_out
theorem type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] :
type r = type s ↔ Nonempty (r ≃r s) :=
Quotient.eq'
#align ordinal.type_eq Ordinal.type_eq
theorem _root_.RelIso.ordinal_type_eq {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (h : r ≃r s) : type r = type s :=
type_eq.2 ⟨h⟩
#align rel_iso.ordinal_type_eq RelIso.ordinal_type_eq
@[simp]
theorem type_lt (o : Ordinal) : type ((· < ·) : o.out.α → o.out.α → Prop) = o :=
(type_def' _).symm.trans <| Quotient.out_eq o
#align ordinal.type_lt Ordinal.type_lt
theorem type_eq_zero_of_empty (r) [IsWellOrder α r] [IsEmpty α] : type r = 0 :=
(RelIso.relIsoOfIsEmpty r _).ordinal_type_eq
#align ordinal.type_eq_zero_of_empty Ordinal.type_eq_zero_of_empty
@[simp]
theorem type_eq_zero_iff_isEmpty [IsWellOrder α r] : type r = 0 ↔ IsEmpty α :=
⟨fun h =>
let ⟨s⟩ := type_eq.1 h
s.toEquiv.isEmpty,
@type_eq_zero_of_empty α r _⟩
#align ordinal.type_eq_zero_iff_is_empty Ordinal.type_eq_zero_iff_isEmpty
theorem type_ne_zero_iff_nonempty [IsWellOrder α r] : type r ≠ 0 ↔ Nonempty α := by simp
#align ordinal.type_ne_zero_iff_nonempty Ordinal.type_ne_zero_iff_nonempty
theorem type_ne_zero_of_nonempty (r) [IsWellOrder α r] [h : Nonempty α] : type r ≠ 0 :=
type_ne_zero_iff_nonempty.2 h
#align ordinal.type_ne_zero_of_nonempty Ordinal.type_ne_zero_of_nonempty
theorem type_pEmpty : type (@EmptyRelation PEmpty) = 0 :=
rfl
#align ordinal.type_pempty Ordinal.type_pEmpty
theorem type_empty : type (@EmptyRelation Empty) = 0 :=
type_eq_zero_of_empty _
#align ordinal.type_empty Ordinal.type_empty
theorem type_eq_one_of_unique (r) [IsWellOrder α r] [Unique α] : type r = 1 :=
(RelIso.relIsoOfUniqueOfIrrefl r _).ordinal_type_eq
#align ordinal.type_eq_one_of_unique Ordinal.type_eq_one_of_unique
@[simp]
theorem type_eq_one_iff_unique [IsWellOrder α r] : type r = 1 ↔ Nonempty (Unique α) :=
⟨fun h =>
let ⟨s⟩ := type_eq.1 h
⟨s.toEquiv.unique⟩,
fun ⟨h⟩ => @type_eq_one_of_unique α r _ h⟩
#align ordinal.type_eq_one_iff_unique Ordinal.type_eq_one_iff_unique
theorem type_pUnit : type (@EmptyRelation PUnit) = 1 :=
rfl
#align ordinal.type_punit Ordinal.type_pUnit
theorem type_unit : type (@EmptyRelation Unit) = 1 :=
rfl
#align ordinal.type_unit Ordinal.type_unit
@[simp]
theorem out_empty_iff_eq_zero {o : Ordinal} : IsEmpty o.out.α ↔ o = 0 := by
rw [← @type_eq_zero_iff_isEmpty o.out.α (· < ·), type_lt]
#align ordinal.out_empty_iff_eq_zero Ordinal.out_empty_iff_eq_zero
theorem eq_zero_of_out_empty (o : Ordinal) [h : IsEmpty o.out.α] : o = 0 :=
out_empty_iff_eq_zero.1 h
#align ordinal.eq_zero_of_out_empty Ordinal.eq_zero_of_out_empty
instance isEmpty_out_zero : IsEmpty (0 : Ordinal).out.α :=
out_empty_iff_eq_zero.2 rfl
#align ordinal.is_empty_out_zero Ordinal.isEmpty_out_zero
@[simp]
theorem out_nonempty_iff_ne_zero {o : Ordinal} : Nonempty o.out.α ↔ o ≠ 0 := by
rw [← @type_ne_zero_iff_nonempty o.out.α (· < ·), type_lt]
#align ordinal.out_nonempty_iff_ne_zero Ordinal.out_nonempty_iff_ne_zero
theorem ne_zero_of_out_nonempty (o : Ordinal) [h : Nonempty o.out.α] : o ≠ 0 :=
out_nonempty_iff_ne_zero.1 h
#align ordinal.ne_zero_of_out_nonempty Ordinal.ne_zero_of_out_nonempty
protected theorem one_ne_zero : (1 : Ordinal) ≠ 0 :=
type_ne_zero_of_nonempty _
#align ordinal.one_ne_zero Ordinal.one_ne_zero
instance nontrivial : Nontrivial Ordinal.{u} :=
⟨⟨1, 0, Ordinal.one_ne_zero⟩⟩
--@[simp] -- Porting note: not in simp nf, added aux lemma below
theorem type_preimage {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) :
type (f ⁻¹'o r) = type r :=
(RelIso.preimage f r).ordinal_type_eq
#align ordinal.type_preimage Ordinal.type_preimage
@[simp, nolint simpNF] -- `simpNF` incorrectly complains the LHS doesn't simplify.
theorem type_preimage_aux {α β : Type u} (r : α → α → Prop) [IsWellOrder α r] (f : β ≃ α) :
@type _ (fun x y => r (f x) (f y)) (inferInstanceAs (IsWellOrder β (↑f ⁻¹'o r))) = type r := by
convert (RelIso.preimage f r).ordinal_type_eq
@[elab_as_elim]
theorem inductionOn {C : Ordinal → Prop} (o : Ordinal)
(H : ∀ (α r) [IsWellOrder α r], C (type r)) : C o :=
Quot.inductionOn o fun ⟨α, r, wo⟩ => @H α r wo
#align ordinal.induction_on Ordinal.inductionOn
/-! ### The order on ordinals -/
instance partialOrder : PartialOrder Ordinal
where
le a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≼i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ =>
propext
⟨fun ⟨h⟩ => ⟨(InitialSeg.ofIso f.symm).trans <| h.trans (InitialSeg.ofIso g)⟩, fun ⟨h⟩ =>
⟨(InitialSeg.ofIso f).trans <| h.trans (InitialSeg.ofIso g.symm)⟩⟩
lt a b :=
Quotient.liftOn₂ a b (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => Nonempty (r ≺i s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ =>
propext
⟨fun ⟨h⟩ => ⟨PrincipalSeg.equivLT f.symm <| h.ltLe (InitialSeg.ofIso g)⟩, fun ⟨h⟩ =>
⟨PrincipalSeg.equivLT f <| h.ltLe (InitialSeg.ofIso g.symm)⟩⟩
le_refl := Quot.ind fun ⟨_, _, _⟩ => ⟨InitialSeg.refl _⟩
le_trans a b c :=
Quotient.inductionOn₃ a b c fun _ _ _ ⟨f⟩ ⟨g⟩ => ⟨f.trans g⟩
lt_iff_le_not_le a b :=
Quotient.inductionOn₂ a b fun _ _ =>
⟨fun ⟨f⟩ => ⟨⟨f⟩, fun ⟨g⟩ => (f.ltLe g).irrefl⟩, fun ⟨⟨f⟩, h⟩ =>
Sum.recOn f.ltOrEq (fun g => ⟨g⟩) fun g => (h ⟨InitialSeg.ofIso g.symm⟩).elim⟩
le_antisymm a b :=
Quotient.inductionOn₂ a b fun _ _ ⟨h₁⟩ ⟨h₂⟩ =>
Quot.sound ⟨InitialSeg.antisymm h₁ h₂⟩
-- Porting note: How can we add a doc to this?
-- /-- Ordinal less-equal is defined such that
-- well orders `r` and `s` satisfy `type r ≤ type s` if there exists
-- a function embedding `r` as an initial segment of `s`. -/
-- add_decl_doc Ordinal.partial_order.le
-- /-- Ordinal less-than is defined such that
-- well orders `r` and `s` satisfy `type r < type s` if there exists
-- a function embedding `r` as a principal segment of `s`. -/
-- add_decl_doc ordinal.partial_order.lt
theorem type_le_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ≼i s) :=
Iff.rfl
#align ordinal.type_le_iff Ordinal.type_le_iff
theorem type_le_iff' {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r ≤ type s ↔ Nonempty (r ↪r s) :=
⟨fun ⟨f⟩ => ⟨f⟩, fun ⟨f⟩ => ⟨f.collapse⟩⟩
#align ordinal.type_le_iff' Ordinal.type_le_iff'
theorem _root_.InitialSeg.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≼i s) : type r ≤ type s :=
⟨h⟩
#align initial_seg.ordinal_type_le InitialSeg.ordinal_type_le
theorem _root_.RelEmbedding.ordinal_type_le {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ↪r s) : type r ≤ type s :=
⟨h.collapse⟩
#align rel_embedding.ordinal_type_le RelEmbedding.ordinal_type_le
@[simp]
theorem type_lt_iff {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] : type r < type s ↔ Nonempty (r ≺i s) :=
Iff.rfl
#align ordinal.type_lt_iff Ordinal.type_lt_iff
theorem _root_.PrincipalSeg.ordinal_type_lt {α β} {r : α → α → Prop} {s : β → β → Prop}
[IsWellOrder α r] [IsWellOrder β s] (h : r ≺i s) : type r < type s :=
⟨h⟩
#align principal_seg.ordinal_type_lt PrincipalSeg.ordinal_type_lt
@[simp]
protected theorem zero_le (o : Ordinal) : 0 ≤ o :=
inductionOn o fun _ r _ => (InitialSeg.ofIsEmpty _ r).ordinal_type_le
#align ordinal.zero_le Ordinal.zero_le
instance orderBot : OrderBot Ordinal where
bot := 0
bot_le := Ordinal.zero_le
@[simp]
theorem bot_eq_zero : (⊥ : Ordinal) = 0 :=
rfl
#align ordinal.bot_eq_zero Ordinal.bot_eq_zero
@[simp]
protected theorem le_zero {o : Ordinal} : o ≤ 0 ↔ o = 0 :=
le_bot_iff
#align ordinal.le_zero Ordinal.le_zero
protected theorem pos_iff_ne_zero {o : Ordinal} : 0 < o ↔ o ≠ 0 :=
bot_lt_iff_ne_bot
#align ordinal.pos_iff_ne_zero Ordinal.pos_iff_ne_zero
protected theorem not_lt_zero (o : Ordinal) : ¬o < 0 :=
not_lt_bot
#align ordinal.not_lt_zero Ordinal.not_lt_zero
theorem eq_zero_or_pos : ∀ a : Ordinal, a = 0 ∨ 0 < a :=
eq_bot_or_bot_lt
#align ordinal.eq_zero_or_pos Ordinal.eq_zero_or_pos
instance zeroLEOneClass : ZeroLEOneClass Ordinal :=
⟨Ordinal.zero_le _⟩
instance NeZero.one : NeZero (1 : Ordinal) :=
⟨Ordinal.one_ne_zero⟩
#align ordinal.ne_zero.one Ordinal.NeZero.one
/-- Given two ordinals `α ≤ β`, then `initialSegOut α β` is the initial segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def initialSegOut {α β : Ordinal} (h : α ≤ β) :
InitialSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by
change α.out.r ≼i β.out.r
rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h
cases Quotient.out α; cases Quotient.out β; exact Classical.choice
#align ordinal.initial_seg_out Ordinal.initialSegOut
/-- Given two ordinals `α < β`, then `principalSegOut α β` is the principal segment embedding
of `α` to `β`, as map from a model type for `α` to a model type for `β`. -/
def principalSegOut {α β : Ordinal} (h : α < β) :
PrincipalSeg ((· < ·) : α.out.α → α.out.α → Prop) ((· < ·) : β.out.α → β.out.α → Prop) := by
change α.out.r ≺i β.out.r
rw [← Quotient.out_eq α, ← Quotient.out_eq β] at h; revert h
cases Quotient.out α; cases Quotient.out β; exact Classical.choice
#align ordinal.principal_seg_out Ordinal.principalSegOut
theorem typein_lt_type (r : α → α → Prop) [IsWellOrder α r] (a : α) : typein r a < type r :=
⟨PrincipalSeg.ofElement _ _⟩
#align ordinal.typein_lt_type Ordinal.typein_lt_type
theorem typein_lt_self {o : Ordinal} (i : o.out.α) :
@typein _ (· < ·) (isWellOrder_out_lt _) i < o := by
simp_rw [← type_lt o]
apply typein_lt_type
#align ordinal.typein_lt_self Ordinal.typein_lt_self
@[simp]
theorem typein_top {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : r ≺i s) : typein s f.top = type r :=
Eq.symm <|
Quot.sound
⟨RelIso.ofSurjective (RelEmbedding.codRestrict _ f f.lt_top) fun ⟨a, h⟩ => by
rcases f.down.1 h with ⟨b, rfl⟩; exact ⟨b, rfl⟩⟩
#align ordinal.typein_top Ordinal.typein_top
@[simp]
theorem typein_apply {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : r ≼i s) (a : α) : Ordinal.typein s (f a) = Ordinal.typein r a :=
Eq.symm <|
Quotient.sound
⟨RelIso.ofSurjective
(RelEmbedding.codRestrict _ ((Subrel.relEmbedding _ _).trans f) fun ⟨x, h⟩ => by
rw [RelEmbedding.trans_apply]; exact f.toRelEmbedding.map_rel_iff.2 h)
fun ⟨y, h⟩ => by
rcases f.init h with ⟨a, rfl⟩
exact ⟨⟨a, f.toRelEmbedding.map_rel_iff.1 h⟩,
Subtype.eq <| RelEmbedding.trans_apply _ _ _⟩⟩
#align ordinal.typein_apply Ordinal.typein_apply
@[simp]
theorem typein_lt_typein (r : α → α → Prop) [IsWellOrder α r] {a b : α} :
typein r a < typein r b ↔ r a b :=
⟨fun ⟨f⟩ => by
have : f.top.1 = a := by
let f' := PrincipalSeg.ofElement r a
let g' := f.trans (PrincipalSeg.ofElement r b)
have : g'.top = f'.top := by rw [Subsingleton.elim f' g']
exact this
rw [← this]
exact f.top.2, fun h =>
⟨PrincipalSeg.codRestrict _ (PrincipalSeg.ofElement r a) (fun x => @trans _ r _ _ _ _ x.2 h) h⟩⟩
#align ordinal.typein_lt_typein Ordinal.typein_lt_typein
theorem typein_surj (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) :
∃ a, typein r a = o :=
inductionOn o (fun _ _ _ ⟨f⟩ => ⟨f.top, typein_top _⟩) h
#align ordinal.typein_surj Ordinal.typein_surj
theorem typein_injective (r : α → α → Prop) [IsWellOrder α r] : Injective (typein r) :=
injective_of_increasing r (· < ·) (typein r) (typein_lt_typein r).2
#align ordinal.typein_injective Ordinal.typein_injective
@[simp]
theorem typein_inj (r : α → α → Prop) [IsWellOrder α r] {a b} : typein r a = typein r b ↔ a = b :=
(typein_injective r).eq_iff
#align ordinal.typein_inj Ordinal.typein_inj
/-- Principal segment version of the `typein` function, embedding a well order into
ordinals as a principal segment. -/
def typein.principalSeg {α : Type u} (r : α → α → Prop) [IsWellOrder α r] :
@PrincipalSeg α Ordinal.{u} r (· < ·) :=
⟨⟨⟨typein r, typein_injective r⟩, typein_lt_typein r⟩, type r,
fun _ ↦ ⟨typein_surj r, fun ⟨a, h⟩ ↦ h ▸ typein_lt_type r a⟩⟩
#align ordinal.typein.principal_seg Ordinal.typein.principalSeg
@[simp]
theorem typein.principalSeg_coe (r : α → α → Prop) [IsWellOrder α r] :
(typein.principalSeg r : α → Ordinal) = typein r :=
rfl
#align ordinal.typein.principal_seg_coe Ordinal.typein.principalSeg_coe
/-! ### Enumerating elements in a well-order with ordinals. -/
/-- `enum r o h` is the `o`-th element of `α` ordered by `r`.
That is, `enum` maps an initial segment of the ordinals, those
less than the order type of `r`, to the elements of `α`. -/
def enum (r : α → α → Prop) [IsWellOrder α r] (o) (h : o < type r) : α :=
(typein.principalSeg r).subrelIso ⟨o, h⟩
@[simp]
theorem typein_enum (r : α → α → Prop) [IsWellOrder α r] {o} (h : o < type r) :
typein r (enum r o h) = o :=
(typein.principalSeg r).apply_subrelIso _
#align ordinal.typein_enum Ordinal.typein_enum
theorem enum_type {α β} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s]
(f : s ≺i r) {h : type s < type r} : enum r (type s) h = f.top :=
(typein.principalSeg r).injective <| (typein_enum _ _).trans (typein_top _).symm
#align ordinal.enum_type Ordinal.enum_type
@[simp]
theorem enum_typein (r : α → α → Prop) [IsWellOrder α r] (a : α) :
enum r (typein r a) (typein_lt_type r a) = a :=
enum_type (PrincipalSeg.ofElement r a)
#align ordinal.enum_typein Ordinal.enum_typein
theorem enum_lt_enum {r : α → α → Prop} [IsWellOrder α r] {o₁ o₂ : Ordinal} (h₁ : o₁ < type r)
(h₂ : o₂ < type r) : r (enum r o₁ h₁) (enum r o₂ h₂) ↔ o₁ < o₂ := by
rw [← typein_lt_typein r, typein_enum, typein_enum]
#align ordinal.enum_lt_enum Ordinal.enum_lt_enum
theorem relIso_enum' {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (f : r ≃r s) (o : Ordinal) :
∀ (hr : o < type r) (hs : o < type s), f (enum r o hr) = enum s o hs := by
refine' inductionOn o _; rintro γ t wo ⟨g⟩ ⟨h⟩
rw [enum_type g, enum_type (PrincipalSeg.ltEquiv g f)]; rfl
#align ordinal.rel_iso_enum' Ordinal.relIso_enum'
theorem relIso_enum {α β : Type u} {r : α → α → Prop} {s : β → β → Prop} [IsWellOrder α r]
[IsWellOrder β s] (f : r ≃r s) (o : Ordinal) (hr : o < type r) :
f (enum r o hr) =
enum s o
(by
convert hr using 1
apply Quotient.sound
exact ⟨f.symm⟩) :=
relIso_enum' _ _ _ _
#align ordinal.rel_iso_enum Ordinal.relIso_enum
theorem lt_wf : @WellFounded Ordinal (· < ·) :=
/-
wellFounded_iff_wellFounded_subrel.mpr (·.induction_on fun ⟨_, r, wo⟩ ↦
RelHomClass.wellFounded (typein.principalSeg r).subrelIso wo.wf)
-/
⟨fun a =>
inductionOn a fun α r wo =>
suffices ∀ a, Acc (· < ·) (typein r a) from
⟨_, fun o h =>
let ⟨a, e⟩ := typein_surj r h
e ▸ this a⟩
fun a =>
Acc.recOn (wo.wf.apply a) fun x _ IH =>
⟨_, fun o h => by
rcases typein_surj r (lt_trans h (typein_lt_type r _)) with ⟨b, rfl⟩
exact IH _ ((typein_lt_typein r).1 h)⟩⟩
#align ordinal.lt_wf Ordinal.lt_wf
instance wellFoundedRelation : WellFoundedRelation Ordinal :=
⟨(· < ·), lt_wf⟩
/-- Reformulation of well founded induction on ordinals as a lemma that works with the
`induction` tactic, as in `induction i using Ordinal.induction with | h i IH => ?_`. -/
theorem induction {p : Ordinal.{u} → Prop} (i : Ordinal.{u}) (h : ∀ j, (∀ k, k < j → p k) → p j) :
p i :=
lt_wf.induction i h
#align ordinal.induction Ordinal.induction
/-! ### Cardinality of ordinals -/
/-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order
type is defined. -/
def card : Ordinal → Cardinal :=
Quotient.map WellOrder.α fun _ _ ⟨e⟩ => ⟨e.toEquiv⟩
#align ordinal.card Ordinal.card
@[simp]
theorem card_type (r : α → α → Prop) [IsWellOrder α r] : card (type r) = #α :=
rfl
#align ordinal.card_type Ordinal.card_type
-- Porting note: nolint, simpNF linter falsely claims the lemma never applies
@[simp, nolint simpNF]
theorem card_typein {r : α → α → Prop} [IsWellOrder α r] (x : α) :
#{ y // r y x } = (typein r x).card :=
rfl
#align ordinal.card_typein Ordinal.card_typein
theorem card_le_card {o₁ o₂ : Ordinal} : o₁ ≤ o₂ → card o₁ ≤ card o₂ :=
inductionOn o₁ fun _ _ _ => inductionOn o₂ fun _ _ _ ⟨⟨⟨f, _⟩, _⟩⟩ => ⟨f⟩
#align ordinal.card_le_card Ordinal.card_le_card
@[simp]
theorem card_zero : card 0 = 0 := mk_eq_zero _
#align ordinal.card_zero Ordinal.card_zero
@[simp]
theorem card_one : card 1 = 1 := mk_eq_one _
#align ordinal.card_one Ordinal.card_one
/-! ### Lifting ordinals to a higher universe -/
-- Porting note: Needed to add universe hint .{u} below
/-- The universe lift operation for ordinals, which embeds `Ordinal.{u}` as
a proper initial segment of `Ordinal.{v}` for `v > u`. For the initial segment version,
see `lift.initialSeg`. -/
@[pp_with_univ]
def lift (o : Ordinal.{v}) : Ordinal.{max v u} :=
Quotient.liftOn o (fun w => type <| ULift.down.{u} ⁻¹'o w.r) fun ⟨_, r, _⟩ ⟨_, s, _⟩ ⟨f⟩ =>
Quot.sound
⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩
#align ordinal.lift Ordinal.lift
-- Porting note: Needed to add universe hints ULift.down.{v,u} below
-- @[simp] -- Porting note: Not in simpnf, added aux lemma below
theorem type_uLift (r : α → α → Prop) [IsWellOrder α r] :
type (ULift.down.{v,u} ⁻¹'o r) = lift.{v} (type r) := by
simp (config := { unfoldPartialApp := true })
rfl
#align ordinal.type_ulift Ordinal.type_uLift
-- Porting note: simpNF linter falsely claims that this never applies
@[simp, nolint simpNF]
theorem type_uLift_aux (r : α → α → Prop) [IsWellOrder α r] :
@type.{max v u} _ (fun x y => r (ULift.down.{v,u} x) (ULift.down.{v,u} y))
(inferInstanceAs (IsWellOrder (ULift α) (ULift.down ⁻¹'o r))) = lift.{v} (type r) :=
rfl
theorem _root_.RelIso.ordinal_lift_type_eq {α : Type u} {β : Type v} {r : α → α → Prop}
{s : β → β → Prop} [IsWellOrder α r] [IsWellOrder β s] (f : r ≃r s) :
lift.{v} (type r) = lift.{u} (type s) :=
((RelIso.preimage Equiv.ulift r).trans <|
f.trans (RelIso.preimage Equiv.ulift s).symm).ordinal_type_eq
#align rel_iso.ordinal_lift_type_eq RelIso.ordinal_lift_type_eq
-- @[simp]
theorem type_lift_preimage {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r]
(f : β ≃ α) : lift.{u} (type (f ⁻¹'o r)) = lift.{v} (type r) :=
(RelIso.preimage f r).ordinal_lift_type_eq
#align ordinal.type_lift_preimage Ordinal.type_lift_preimage
@[simp, nolint simpNF]
theorem type_lift_preimage_aux {α : Type u} {β : Type v} (r : α → α → Prop) [IsWellOrder α r]
(f : β ≃ α) : lift.{u} (@type _ (fun x y => r (f x) (f y))
(inferInstanceAs (IsWellOrder β (f ⁻¹'o r)))) = lift.{v} (type r) :=
(RelIso.preimage f r).ordinal_lift_type_eq
/-- `lift.{max u v, u}` equals `lift.{v, u}`. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_umax : lift.{max u v, u} = lift.{v, u} :=
funext fun a =>
inductionOn a fun _ r _ =>
Quotient.sound ⟨(RelIso.preimage Equiv.ulift r).trans (RelIso.preimage Equiv.ulift r).symm⟩
#align ordinal.lift_umax Ordinal.lift_umax
/-- `lift.{max v u, u}` equals `lift.{v, u}`. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_umax' : lift.{max v u, u} = lift.{v, u} :=
lift_umax
#align ordinal.lift_umax' Ordinal.lift_umax'
/-- An ordinal lifted to a lower or equal universe equals itself. -/
-- @[simp] -- Porting note: simp lemma never applies, tested
theorem lift_id' (a : Ordinal) : lift a = a :=
inductionOn a fun _ r _ => Quotient.sound ⟨RelIso.preimage Equiv.ulift r⟩
#align ordinal.lift_id' Ordinal.lift_id'
/-- An ordinal lifted to the same universe equals itself. -/
@[simp]
theorem lift_id : ∀ a, lift.{u, u} a = a :=
lift_id'.{u, u}
#align ordinal.lift_id Ordinal.lift_id
/-- An ordinal lifted to the zero universe equals itself. -/
@[simp]
theorem lift_uzero (a : Ordinal.{u}) : lift.{0} a = a :=
lift_id' a
#align ordinal.lift_uzero Ordinal.lift_uzero
@[simp]
theorem lift_lift (a : Ordinal) : lift.{w} (lift.{v} a) = lift.{max v w} a :=
inductionOn a fun _ _ _ =>
Quotient.sound
⟨(RelIso.preimage Equiv.ulift _).trans <|
(RelIso.preimage Equiv.ulift _).trans (RelIso.preimage Equiv.ulift _).symm⟩
#align ordinal.lift_lift Ordinal.lift_lift
theorem lift_type_le {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) ≤ lift.{max u w} (type s) ↔ Nonempty (r ≼i s) :=
⟨fun ⟨f⟩ =>
⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r).symm).trans <|
f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩,
fun ⟨f⟩ =>
⟨(InitialSeg.ofIso (RelIso.preimage Equiv.ulift r)).trans <|
f.trans (InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩
#align ordinal.lift_type_le Ordinal.lift_type_le
theorem lift_type_eq {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) = lift.{max u w} (type s) ↔ Nonempty (r ≃r s) :=
Quotient.eq'.trans
⟨fun ⟨f⟩ =>
⟨(RelIso.preimage Equiv.ulift r).symm.trans <| f.trans (RelIso.preimage Equiv.ulift s)⟩,
fun ⟨f⟩ =>
⟨(RelIso.preimage Equiv.ulift r).trans <| f.trans (RelIso.preimage Equiv.ulift s).symm⟩⟩
#align ordinal.lift_type_eq Ordinal.lift_type_eq
theorem lift_type_lt {α : Type u} {β : Type v} {r s} [IsWellOrder α r] [IsWellOrder β s] :
lift.{max v w} (type r) < lift.{max u w} (type s) ↔ Nonempty (r ≺i s) := by
haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max v w} α ⁻¹'o r) r
(RelIso.preimage Equiv.ulift.{max v w} r) _
haveI := @RelEmbedding.isWellOrder _ _ (@Equiv.ulift.{max u w} β ⁻¹'o s) s
(RelIso.preimage Equiv.ulift.{max u w} s) _
exact ⟨fun ⟨f⟩ =>
⟨(f.equivLT (RelIso.preimage Equiv.ulift r).symm).ltLe
(InitialSeg.ofIso (RelIso.preimage Equiv.ulift s))⟩,
fun ⟨f⟩ =>
⟨(f.equivLT (RelIso.preimage Equiv.ulift r)).ltLe
(InitialSeg.ofIso (RelIso.preimage Equiv.ulift s).symm)⟩⟩
#align ordinal.lift_type_lt Ordinal.lift_type_lt
@[simp]
theorem lift_le {a b : Ordinal} : lift.{u,v} a ≤ lift.{u,v} b ↔ a ≤ b :=
inductionOn a fun α r _ =>
inductionOn b fun β s _ => by
rw [← lift_umax]
exact lift_type_le.{_,_,u}
#align ordinal.lift_le Ordinal.lift_le
@[simp]
theorem lift_inj {a b : Ordinal} : lift.{u,v} a = lift.{u,v} b ↔ a = b := by
simp only [le_antisymm_iff, lift_le]
#align ordinal.lift_inj Ordinal.lift_inj
@[simp]
theorem lift_lt {a b : Ordinal} : lift.{u,v} a < lift.{u,v} b ↔ a < b := by
simp only [lt_iff_le_not_le, lift_le]
#align ordinal.lift_lt Ordinal.lift_lt
@[simp]
theorem lift_zero : lift 0 = 0 :=
type_eq_zero_of_empty _
#align ordinal.lift_zero Ordinal.lift_zero
@[simp]
theorem lift_one : lift 1 = 1 :=
type_eq_one_of_unique _
#align ordinal.lift_one Ordinal.lift_one
@[simp]
theorem lift_card (a) : Cardinal.lift.{u,v} (card a)= card (lift.{u,v} a) :=
inductionOn a fun _ _ _ => rfl
#align ordinal.lift_card Ordinal.lift_card
theorem lift_down' {a : Cardinal.{u}} {b : Ordinal.{max u v}}
(h : card.{max u v} b ≤ Cardinal.lift.{v,u} a) : ∃ a', lift.{v,u} a' = b :=
let ⟨c, e⟩ := Cardinal.lift_down h
Cardinal.inductionOn c
(fun α =>
inductionOn b fun β s _ e' => by
rw [card_type, ← Cardinal.lift_id'.{max u v, u} #β, ← Cardinal.lift_umax.{u, v},
lift_mk_eq.{u, max u v, max u v}] at e'
cases' e' with f
have g := RelIso.preimage f s
haveI := (g : f ⁻¹'o s ↪r s).isWellOrder
have := lift_type_eq.{u, max u v, max u v}.2 ⟨g⟩
rw [lift_id, lift_umax.{u, v}] at this
exact ⟨_, this⟩)
e
#align ordinal.lift_down' Ordinal.lift_down'
theorem lift_down {a : Ordinal.{u}} {b : Ordinal.{max u v}} (h : b ≤ lift.{v,u} a) :
∃ a', lift.{v,u} a' = b :=
@lift_down' (card a) _ (by rw [lift_card]; exact card_le_card h)
#align ordinal.lift_down Ordinal.lift_down
theorem le_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} :
b ≤ lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' ≤ a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down h
⟨a', e, lift_le.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_le.2 h⟩
#align ordinal.le_lift_iff Ordinal.le_lift_iff
theorem lt_lift_iff {a : Ordinal.{u}} {b : Ordinal.{max u v}} :
b < lift.{v,u} a ↔ ∃ a', lift.{v,u} a' = b ∧ a' < a :=
⟨fun h =>
let ⟨a', e⟩ := lift_down (le_of_lt h)
⟨a', e, lift_lt.1 <| e.symm ▸ h⟩,
fun ⟨_, e, h⟩ => e ▸ lift_lt.2 h⟩
#align ordinal.lt_lift_iff Ordinal.lt_lift_iff
/-- Initial segment version of the lift operation on ordinals, embedding `ordinal.{u}` in
`ordinal.{v}` as an initial segment when `u ≤ v`. -/
def lift.initialSeg : @InitialSeg Ordinal.{u} Ordinal.{max u v} (· < ·) (· < ·) :=
⟨⟨⟨lift.{v}, fun _ _ => lift_inj.1⟩, lift_lt⟩, fun _ _ h => lift_down (le_of_lt h)⟩
#align ordinal.lift.initial_seg Ordinal.lift.initialSeg
@[simp]
theorem lift.initialSeg_coe : (lift.initialSeg.{u,v} : Ordinal → Ordinal) = lift.{v,u} :=
rfl
#align ordinal.lift.initial_seg_coe Ordinal.lift.initialSeg_coe
/-! ### The first infinite ordinal `omega` -/
/-- `ω` is the first infinite ordinal, defined as the order type of `ℕ`. -/
def omega : Ordinal.{u} :=
lift <| @type ℕ (· < ·) _
#align ordinal.omega Ordinal.omega
-- mathport name: ordinal.omega
@[inherit_doc]
scoped notation "ω" => Ordinal.omega
/-- Note that the presence of this lemma makes `simp [omega]` form a loop. -/
@[simp]
theorem type_nat_lt : @type ℕ (· < ·) _ = ω :=
(lift_id _).symm
#align ordinal.type_nat_lt Ordinal.type_nat_lt
@[simp]
theorem card_omega : card ω = ℵ₀ :=
rfl
#align ordinal.card_omega Ordinal.card_omega
@[simp]
theorem lift_omega : lift ω = ω :=
lift_lift _
#align ordinal.lift_omega Ordinal.lift_omega
/-!
### Definition and first properties of addition on ordinals
In this paragraph, we introduce the addition on ordinals, and prove just enough properties to
deduce that the order on ordinals is total (and therefore well-founded). Further properties of
the addition, together with properties of the other operations, are proved in
`Ordinal/Arithmetic.lean`.
-/
/-- `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that
every element of `o₁` is smaller than every element of `o₂`. -/
instance add : Add Ordinal.{u} :=
⟨fun o₁ o₂ =>
Quotient.liftOn₂ o₁ o₂ (fun ⟨_, r, _⟩ ⟨_, s, _⟩ => type (Sum.Lex r s))
fun _ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.sumLexCongr f g⟩⟩
instance addMonoidWithOne : AddMonoidWithOne Ordinal.{u} where
add := (· + ·)
zero := 0
one := 1
zero_add o :=
inductionOn o fun α r _ =>
Eq.symm <| Quotient.sound ⟨⟨(emptySum PEmpty α).symm, Sum.lex_inr_inr⟩⟩
add_zero o :=
inductionOn o fun α r _ =>
Eq.symm <| Quotient.sound ⟨⟨(sumEmpty α PEmpty).symm, Sum.lex_inl_inl⟩⟩
add_assoc o₁ o₂ o₃ :=
Quotient.inductionOn₃ o₁ o₂ o₃ fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ =>
Quot.sound
⟨⟨sumAssoc _ _ _, by
intros a b
rcases a with (⟨a | a⟩ | a) <;> rcases b with (⟨b | b⟩ | b) <;>
simp only [sumAssoc_apply_inl_inl, sumAssoc_apply_inl_inr, sumAssoc_apply_inr,
Sum.lex_inl_inl, Sum.lex_inr_inr, Sum.Lex.sep, Sum.lex_inr_inl]⟩⟩
nsmul := nsmulRec
@[simp]
theorem card_add (o₁ o₂ : Ordinal) : card (o₁ + o₂) = card o₁ + card o₂ :=
inductionOn o₁ fun _ __ => inductionOn o₂ fun _ _ _ => rfl
#align ordinal.card_add Ordinal.card_add
@[simp]
theorem type_sum_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r]
[IsWellOrder β s] : type (Sum.Lex r s) = type r + type s :=
rfl
#align ordinal.type_sum_lex Ordinal.type_sum_lex
@[simp]
theorem card_nat (n : ℕ) : card.{u} n = n := by
induction n <;> [simp; simp only [card_add, card_one, Nat.cast_succ, *]]
#align ordinal.card_nat Ordinal.card_nat
-- See note [no_index around OfNat.ofNat]
@[simp]
theorem card_ofNat (n : ℕ) [n.AtLeastTwo] :
card.{u} (no_index (OfNat.ofNat n)) = OfNat.ofNat n :=
card_nat n
-- Porting note: Rewritten proof of elim, previous version was difficult to debug
instance add_covariantClass_le : CovariantClass Ordinal.{u} Ordinal.{u} (· + ·) (· ≤ ·) where
elim := fun c a b h => by
revert h c
refine inductionOn a (fun α₁ r₁ _ ↦ ?_)
refine inductionOn b (fun α₂ r₂ _ ↦ ?_)
rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩
refine inductionOn c (fun β s _ ↦ ?_)
refine ⟨⟨⟨(Embedding.refl.{u+1} _).sumMap f, ?_⟩, ?_⟩⟩
· intros a b
match a, b with
| Sum.inl a, Sum.inl b => exact Sum.lex_inl_inl.trans Sum.lex_inl_inl.symm
| Sum.inl a, Sum.inr b => apply iff_of_true <;> apply Sum.Lex.sep
| Sum.inr a, Sum.inl b => apply iff_of_false <;> exact Sum.lex_inr_inl
| Sum.inr a, Sum.inr b => exact Sum.lex_inr_inr.trans <| fo.trans Sum.lex_inr_inr.symm
· intros a b H
match a, b, H with
| _, Sum.inl b, _ => exact ⟨Sum.inl b, rfl⟩
| Sum.inl a, Sum.inr b, H => exact (Sum.lex_inr_inl H).elim
| Sum.inr a, Sum.inr b, H =>
let ⟨w, h⟩ := fi _ _ (Sum.lex_inr_inr.1 H)
exact ⟨Sum.inr w, congr_arg Sum.inr h⟩
#align ordinal.add_covariant_class_le Ordinal.add_covariantClass_le
-- Porting note: Rewritten proof of elim, previous version was difficult to debug
instance add_swap_covariantClass_le :
CovariantClass Ordinal.{u} Ordinal.{u} (swap (· + ·)) (· ≤ ·) where
elim := fun c a b h => by
revert h c
refine inductionOn a (fun α₁ r₁ _ ↦ ?_)
refine inductionOn b (fun α₂ r₂ _ ↦ ?_)
rintro c ⟨⟨⟨f, fo⟩, fi⟩⟩
refine inductionOn c (fun β s _ ↦ ?_)
exact @RelEmbedding.ordinal_type_le _ _ (Sum.Lex r₁ s) (Sum.Lex r₂ s) _ _
⟨f.sumMap (Embedding.refl _), by
intro a b
constructor <;> intro H
· cases' a with a a <;> cases' b with b b <;> cases H <;> constructor <;>
[rwa [← fo]; assumption]
· cases H <;> constructor <;> [rwa [fo]; assumption]⟩
#align ordinal.add_swap_covariant_class_le Ordinal.add_swap_covariantClass_le
theorem le_add_right (a b : Ordinal) : a ≤ a + b := by
simpa only [add_zero] using add_le_add_left (Ordinal.zero_le b) a
#align ordinal.le_add_right Ordinal.le_add_right
theorem le_add_left (a b : Ordinal) : a ≤ b + a := by
simpa only [zero_add] using add_le_add_right (Ordinal.zero_le b) a
#align ordinal.le_add_left Ordinal.le_add_left
instance linearOrder : LinearOrder Ordinal :=
{inferInstanceAs (PartialOrder Ordinal) with
le_total := fun a b =>
match lt_or_eq_of_le (le_add_left b a), lt_or_eq_of_le (le_add_right a b) with
| Or.inr h, _ => by rw [h]; exact Or.inl (le_add_right _ _)
| _, Or.inr h => by rw [h]; exact Or.inr (le_add_left _ _)
| Or.inl h₁, Or.inl h₂ => by
revert h₁ h₂
refine inductionOn a ?_
intro α₁ r₁ _
refine inductionOn b ?_
intro α₂ r₂ _ ⟨f⟩ ⟨g⟩
rw [← typein_top f, ← typein_top g, le_iff_lt_or_eq, le_iff_lt_or_eq,
typein_lt_typein, typein_lt_typein]
rcases trichotomous_of (Sum.Lex r₁ r₂) g.top f.top with (h | h | h) <;>
[exact Or.inl (Or.inl h); (left; right; rw [h]); exact Or.inr (Or.inl h)]
decidableLE := Classical.decRel _ }
instance wellFoundedLT : WellFoundedLT Ordinal :=
⟨lt_wf⟩
instance isWellOrder : IsWellOrder Ordinal (· < ·) where
instance : ConditionallyCompleteLinearOrderBot Ordinal :=
IsWellOrder.conditionallyCompleteLinearOrderBot _
theorem max_zero_left : ∀ a : Ordinal, max 0 a = a :=
max_bot_left
#align ordinal.max_zero_left Ordinal.max_zero_left
theorem max_zero_right : ∀ a : Ordinal, max a 0 = a :=
max_bot_right
#align ordinal.max_zero_right Ordinal.max_zero_right