Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 8ea5598

Browse files
chore(set_theory/ordinal/basic): golf (#18547)
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
1 parent bf2428c commit 8ea5598

File tree

2 files changed

+35
-42
lines changed

2 files changed

+35
-42
lines changed

src/order/initial_seg.lean

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Floris van Doorn
55
-/
66

7+
import logic.equiv.set
78
import order.rel_iso.set
89
import order.well_founded
910

@@ -311,6 +312,22 @@ def of_element {α : Type*} (r : α → α → Prop) (a : α) : subrel r {b | r
311312
@[simp] theorem of_element_top {α : Type*} (r : α → α → Prop) (a : α) :
312313
(of_element r a).top = a := rfl
313314

315+
/-- For any principal segment `r ≺i s`, there is a `subrel` of `s` order isomorphic to `r`. -/
316+
@[simps symm_apply]
317+
noncomputable def subrel_iso (f : r ≺i s) : subrel s {b | s b f.top} ≃r r :=
318+
rel_iso.symm
319+
{ to_equiv := ((equiv.of_injective f f.injective).trans (equiv.set_congr
320+
(funext (λ x, propext f.down.symm)))),
321+
map_rel_iff' := λ a₁ a₂, f.map_rel_iff }
322+
323+
@[simp] theorem apply_subrel_iso (f : r ≺i s) (b : {b | s b f.top}) :
324+
f (f.subrel_iso b) = b :=
325+
equiv.apply_of_injective_symm f.injective _
326+
327+
@[simp] theorem subrel_iso_apply (f : r ≺i s) (a : α) :
328+
f.subrel_iso ⟨f a, f.down.mpr ⟨a, rfl⟩⟩ = a :=
329+
equiv.of_injective_symm_apply f.injective _
330+
314331
/-- Restrict the codomain of a principal segment -/
315332
def cod_restrict (p : set β) (f : r ≺i s)
316333
(H : ∀ a, f a ∈ p) (H₂ : f.top ∈ p) : r ≺i subrel s p :=

src/set_theory/ordinal/basic.lean

Lines changed: 18 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -358,28 +358,29 @@ injective_of_increasing r (<) (typein r) (λ x y, (typein_lt_typein r).2)
358358
{a b} : typein r a = typein r b ↔ a = b :=
359359
(typein_injective r).eq_iff
360360

361+
/-- Principal segment version of the `typein` function, embedding a well order into
362+
ordinals as a principal segment. -/
363+
def typein.principal_seg (r : α → α → Prop) [is_well_order α r] :
364+
r ≺i ((<) : ordinal → ordinal → Prop) :=
365+
⟨⟨⟨typein r, typein_injective r⟩, λ a b, typein_lt_typein r⟩, type r,
366+
λ o, ⟨typein_surj r, λ ⟨a, h⟩, h ▸ typein_lt_type r a⟩⟩
367+
368+
@[simp] theorem typein.principal_seg_coe (r : α → α → Prop) [is_well_order α r] :
369+
(typein.principal_seg r : α → ordinal) = typein r := rfl
370+
361371
/-! ### Enumerating elements in a well-order with ordinals. -/
362372

363373
/-- `enum r o h` is the `o`-th element of `α` ordered by `r`.
364374
That is, `enum` maps an initial segment of the ordinals, those
365375
less than the order type of `r`, to the elements of `α`. -/
366-
def enum (r : α → α → Prop) [is_well_order α r] (o) : o < type r → α :=
367-
quot.rec_on o (λ ⟨β, s, _⟩ h, (classical.choice h).top) $
368-
λ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨h⟩, begin
369-
resetI, refine funext (λ (H₂ : type t < type r), _),
370-
have H₁ : type s < type r, {rwa type_eq.2 ⟨h⟩},
371-
have : ∀ {o e} (H : o < type r), @@eq.rec
372-
(λ (o : ordinal), o < type r → α)
373-
(λ (h : type s < type r), (classical.choice h).top)
374-
e H = (classical.choice H₁).top, {intros, subst e},
375-
exact (this H₂).trans (principal_seg.top_eq h
376-
(classical.choice H₁) (classical.choice H₂))
377-
end
376+
def enum (r : α → α → Prop) [is_well_order α r] (o) (h : o < type r) : α :=
377+
(typein.principal_seg r).subrel_iso ⟨o, h⟩
378378

379379
theorem enum_type {α β} {r : α → α → Prop} {s : β → β → Prop}
380380
[is_well_order α r] [is_well_order β s] (f : s ≺i r)
381381
{h : type s < type r} : enum r (type s) h = f.top :=
382-
principal_seg.top_eq (rel_iso.refl _) _ _
382+
(typein.principal_seg r).injective $
383+
((typein.principal_seg r).apply_subrel_iso _).trans (typein_top _).symm
383384

384385
@[simp] theorem enum_typein (r : α → α → Prop) [is_well_order α r] (a : α) :
385386
enum r (typein r a) (typein_lt_type r a) = a :=
@@ -412,13 +413,8 @@ lemma rel_iso_enum {α β : Type u} {r : α → α → Prop} {s : β → β →
412413
rel_iso_enum' _ _ _ _
413414

414415
theorem lt_wf : @well_founded ordinal (<) :=
415-
⟨λ a, induction_on a $ λ α r wo, by exactI
416-
suffices ∀ a, acc (<) (typein r a), from
417-
⟨_, λ o h, let ⟨a, e⟩ := typein_surj r h in e ▸ this a⟩,
418-
λ a, acc.rec_on (wo.wf.apply a) $ λ x H IH, ⟨_, λ o h, begin
419-
rcases typein_surj r (lt_trans h (typein_lt_type r _)) with ⟨b, rfl⟩,
420-
exact IH _ ((typein_lt_typein r).1 h)
421-
end⟩⟩
416+
well_founded_iff_well_founded_subrel.mpr $ λ a, induction_on a $ λ α r wo, by exactI
417+
rel_hom_class.well_founded (typein.principal_seg r).subrel_iso wo.wf
422418

423419
instance : has_well_founded ordinal := ⟨(<), lt_wf⟩
424420

@@ -428,18 +424,6 @@ lemma induction {p : ordinal.{u} → Prop} (i : ordinal.{u})
428424
(h : ∀ j, (∀ k, k < j → p k) → p j) : p i :=
429425
lt_wf.induction i h
430426

431-
/-- Principal segment version of the `typein` function, embedding a well order into
432-
ordinals as a principal segment. -/
433-
def typein.principal_seg {α : Type u} (r : α → α → Prop) [is_well_order α r] :
434-
@principal_seg α ordinal.{u} r (<) :=
435-
⟨rel_embedding.of_monotone (typein r)
436-
(λ a b, (typein_lt_typein r).2), type r, λ b,
437-
⟨λ h, ⟨enum r _ h, typein_enum r h⟩,
438-
λ ⟨a, e⟩, e ▸ typein_lt_type _ _⟩⟩
439-
440-
@[simp] theorem typein.principal_seg_coe (r : α → α → Prop) [is_well_order α r] :
441-
(typein.principal_seg r : α → ordinal) = typein r := rfl
442-
443427
/-! ### Cardinality of ordinals -/
444428

445429
/-- The cardinal of an ordinal is the cardinality of any type on which a relation with that order
@@ -820,21 +804,13 @@ by { rw [←enum_typein (<) a, enum_le_enum', ←lt_succ_iff], apply typein_lt_s
820804

821805
@[simp] theorem enum_inj {r : α → α → Prop} [is_well_order α r] {o₁ o₂ : ordinal} (h₁ : o₁ < type r)
822806
(h₂ : o₂ < type r) : enum r o₁ h₁ = enum r o₂ h₂ ↔ o₁ = o₂ :=
823-
⟨λ h, begin
824-
by_contra hne,
825-
cases lt_or_gt_of_ne hne with hlt hlt;
826-
apply (is_well_order.is_irrefl r).1,
827-
{ rwa [←@enum_lt_enum α r _ o₁ o₂ h₁ h₂, h] at hlt },
828-
{ change _ < _ at hlt, rwa [←@enum_lt_enum α r _ o₂ o₁ h₂ h₁, h] at hlt }
829-
end, λ h, by simp_rw h⟩
807+
(typein.principal_seg r).subrel_iso.injective.eq_iff.trans subtype.mk_eq_mk
830808

831809
/-- A well order `r` is order isomorphic to the set of ordinals smaller than `type r`. -/
832810
@[simps] def enum_iso (r : α → α → Prop) [is_well_order α r] : subrel (<) (< type r) ≃r r :=
833811
{ to_fun := λ x, enum r x.1 x.2,
834812
inv_fun := λ x, ⟨typein r x, typein_lt_type r x⟩,
835-
left_inv := λ ⟨o, h⟩, subtype.ext_val (typein_enum _ _),
836-
right_inv := λ h, enum_typein _ _,
837-
map_rel_iff' := by { rintros ⟨a, _⟩ ⟨b, _⟩, apply enum_lt_enum } }
813+
..(typein.principal_seg r).subrel_iso }
838814

839815
/-- The order isomorphism between ordinals less than `o` and `o.out.α`. -/
840816
@[simps] noncomputable def enum_iso_out (o : ordinal) : set.Iio o ≃o o.out.α :=

0 commit comments

Comments
 (0)