Skip to content

Commit

Permalink
refactor(order/rel_classes): redefine is_well_order in terms of `is…
Browse files Browse the repository at this point in the history
…_well_founded` (#15729)

We redefine `is_well_order` in terms of `is_well_founded`, and remove the redundant `is_irrefl` assumption in the process.

This also replaces `is_well_order.wf` with `is_well_founded.wf`.
  • Loading branch information
vihdzp committed Aug 17, 2022
1 parent f5de6ed commit 0893158
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/analysis/inner_product_space/gram_schmidt_ortho.lean
Expand Up @@ -81,7 +81,7 @@ begin
clear h₀ a b,
intros a b h₀,
revert a,
apply well_founded.induction (@is_well_order.wf ι (<) _) b,
apply well_founded.induction (@is_well_founded.wf ι (<) _) b,
intros b ih a h₀,
simp only [gram_schmidt_def 𝕜 f b, inner_sub_right, inner_sum,
orthogonal_projection_singleton, inner_smul_right],
Expand Down
3 changes: 2 additions & 1 deletion src/data/nat/part_enat.lean
Expand Up @@ -492,7 +492,8 @@ begin
exact inv_image.wf _ (with_top.well_founded_lt nat.lt_wf)
end

instance : is_well_order part_enat (<) := ⟨lt_wf⟩
instance : well_founded_lt part_enat := ⟨lt_wf⟩
instance : is_well_order part_enat (<) := { }
instance : has_well_founded part_enat := ⟨(<), lt_wf⟩

section find
Expand Down
2 changes: 1 addition & 1 deletion src/data/pi/lex.lean
Expand Up @@ -84,7 +84,7 @@ partial_order_of_SO (<)
noncomputable instance [linear_order ι] [is_well_order ι (<)] [∀ a, linear_order (β a)] :
linear_order (lex (Π i, β i)) :=
@linear_order_of_STO' (Πₗ i, β i) (<)
{ to_is_trichotomous := is_trichotomous_lex _ _ is_well_order.wf } (classical.dec_rel _)
{ to_is_trichotomous := is_trichotomous_lex _ _ is_well_founded.wf } (classical.dec_rel _)

lemma lex.le_of_forall_le [linear_order ι] [is_well_order ι (<)] [Π a, linear_order (β a)]
{a b : lex (Π i, β i)} (h : ∀ i, a i ≤ b i) : a ≤ b :=
Expand Down
2 changes: 1 addition & 1 deletion src/data/sum/order.lean
Expand Up @@ -88,7 +88,7 @@ instance [is_trichotomous α r] [is_trichotomous β s] : is_trichotomous (α ⊕
end

instance [is_well_order α r] [is_well_order β s] : is_well_order (α ⊕ β) (sum.lex r s) :=
{ wf := sum.lex_wf is_well_order.wf is_well_order.wf }
{ wf := sum.lex_wf is_well_founded.wf is_well_founded.wf }

end lex

Expand Down
3 changes: 2 additions & 1 deletion src/order/conditionally_complete_lattice.lean
Expand Up @@ -687,7 +687,8 @@ lemma exists_lt_of_cinfi_lt [nonempty ι] {f : ι → α} (h : infi f < a) : ∃
open function
variables [is_well_order α (<)]

lemma Inf_eq_argmin_on (hs : s.nonempty) : Inf s = argmin_on id (@is_well_order.wf α (<) _) s hs :=
lemma Inf_eq_argmin_on (hs : s.nonempty) :
Inf s = argmin_on id (@is_well_founded.wf α (<) _) s hs :=
is_least.cInf_eq ⟨argmin_on_mem _ _ _ _, λ a ha, argmin_on_le id _ _ ha⟩

lemma is_least_Inf (hs : s.nonempty) : is_least s (Inf s) :=
Expand Down
18 changes: 9 additions & 9 deletions src/order/initial_seg.lean
Expand Up @@ -106,7 +106,7 @@ end⟩

instance [is_well_order β s] : subsingleton (r ≼i s) :=
⟨λ a, @subsingleton.elim _ (unique_of_trichotomous_of_irrefl
(@rel_embedding.well_founded _ _ r s a is_well_order.wf)) a⟩
(@rel_embedding.well_founded _ _ r s a is_well_founded.wf)) a⟩

protected theorem eq [is_well_order β s] (f g : r ≼i s) (a) : f a = g a :=
by rw subsingleton.elim f g
Expand All @@ -130,7 +130,7 @@ rel_iso.coe_fn_injective rfl
theorem eq_or_principal [is_well_order β s] (f : r ≼i s) :
surjective f ∨ ∃ b, ∀ x, s x b ↔ ∃ y, f y = x :=
or_iff_not_imp_right.2 $ λ h b,
acc.rec_on (is_well_order.wf.apply b : acc s b) $ λ x H IH,
acc.rec_on (is_well_founded.wf.apply b : acc s b) $ λ x H IH,
not_forall_not.1 $ λ hn,
h ⟨x, λ y, ⟨(IH _), λ ⟨a, e⟩, by rw ← e; exact
(trichotomous _ _).resolve_right
Expand Down Expand Up @@ -363,13 +363,13 @@ namespace rel_embedding
gaps, to obtain an initial segment. Here, we construct the collapsed order embedding pointwise,
but the proof of the fact that it is an initial segment will be given in `collapse`. -/
noncomputable def collapse_F [is_well_order β s] (f : r ↪r s) : Π a, {b // ¬ s (f a) b} :=
(rel_embedding.well_founded f $ is_well_order.wf).fix $ λ a IH, begin
(rel_embedding.well_founded f $ is_well_founded.wf).fix $ λ a IH, begin
let S := {b | ∀ a h, s (IH a h).1 b},
have : f a ∈ S, from λ a' h, ((trichotomous _ _)
.resolve_left $ λ h', (IH a' h).2 $ trans (f.map_rel_iff.2 h) h')
.resolve_left $ λ h', (IH a' h).2 $ h' ▸ f.map_rel_iff.2 h,
exact ⟨is_well_order.wf.min S ⟨_, this⟩,
is_well_order.wf.not_lt_min _ _ this
exact ⟨is_well_founded.wf.min S ⟨_, this⟩,
is_well_founded.wf.not_lt_min _ _ this
end

theorem collapse_F.lt [is_well_order β s] (f : r ↪r s) {a : α}
Expand All @@ -393,15 +393,15 @@ noncomputable def collapse [is_well_order β s] (f : r ↪r s) : r ≼i s :=
by haveI := rel_embedding.is_well_order f; exact
⟨rel_embedding.of_monotone
(λ a, (collapse_F f a).1) (λ a b, collapse_F.lt f),
λ a b, acc.rec_on (is_well_order.wf.apply b : acc s b) (λ b H IH a h, begin
λ a b, acc.rec_on (is_well_founded.wf.apply b : acc s b) (λ b H IH a h, begin
let S := {a | ¬ s (collapse_F f a).1 b},
have : S.nonempty := ⟨_, asymm h⟩,
existsi (is_well_order.wf : well_founded r).min S this,
existsi (is_well_founded.wf : well_founded r).min S this,
refine ((@trichotomous _ s _ _ _).resolve_left _).resolve_right _,
{ exact (is_well_order.wf : well_founded r).min_mem S this },
{ exact (is_well_founded.wf : well_founded r).min_mem S this },
{ refine collapse_F.not_lt f _ (λ a' h', _),
by_contradiction hn,
exact is_well_order.wf.not_lt_min S this hn h' }
exact is_well_founded.wf.not_lt_min S this hn h' }
end) a⟩

theorem collapse_apply [is_well_order β s] (f : r ↪r s)
Expand Down
13 changes: 6 additions & 7 deletions src/order/rel_classes.lean
Expand Up @@ -278,10 +278,12 @@ theorem well_founded_lt_dual_iff (α : Type*) [has_lt α] : well_founded_lt α

/-- A well order is a well-founded linear order. -/
@[algebra] class is_well_order (α : Type u) (r : α → α → Prop)
extends is_strict_total_order' α r : Prop :=
(wf : well_founded r)
extends is_trichotomous α r, is_trans α r, is_well_founded α r : Prop

@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_strict_total_order' {α} (r : α → α → Prop) [is_well_order α r] :
is_strict_total_order' α r := { }
@[priority 100] -- see Note [lower instance priority]
instance is_well_order.is_strict_total_order {α} (r : α → α → Prop) [is_well_order α r] :
is_strict_total_order α r := by apply_instance
@[priority 100] -- see Note [lower instance priority]
Expand Down Expand Up @@ -370,7 +372,6 @@ subsingleton.is_well_order _
@[priority 100]
instance is_empty.is_well_order [is_empty α] (r : α → α → Prop) : is_well_order α r :=
{ trichotomous := is_empty_elim,
irrefl := is_empty_elim,
trans := is_empty_elim,
wf := well_founded_of_empty r }

Expand All @@ -390,8 +391,6 @@ instance prod.lex.is_well_order [is_well_order α r] [is_well_order β s] :
| or.inr (or.inl e) := e ▸ or.inr $ or.inl rfl
end
end,
irrefl := λ ⟨a₁, a₂⟩ h, by cases h with _ _ _ _ h _ _ _ h;
[exact irrefl _ h, exact irrefl _ h],
trans := λ a b c h₁ h₂, begin
cases h₁ with a₁ a₂ b₁ b₂ ab a₁ b₁ b₂ ab;
cases h₂ with _ _ c₁ c₂ bc _ _ c₂ bc,
Expand All @@ -400,7 +399,7 @@ instance prod.lex.is_well_order [is_well_order α r] [is_well_order β s] :
{ exact prod.lex.left _ _ bc },
{ exact prod.lex.right _ (trans ab bc) }
end,
wf := prod.lex_wf is_well_order.wf is_well_order.wf }
wf := prod.lex_wf is_well_founded.wf is_well_founded.wf }

instance inv_image.is_well_founded (r : α → α → Prop) [is_well_founded α r] (f : β → α) :
is_well_founded _ (inv_image r f) :=
Expand Down Expand Up @@ -620,7 +619,7 @@ instance order_dual.is_total_le [has_le α] [is_total α (≤)] : is_total αᵒ
@is_total.swap α _ _

instance : well_founded_lt ℕ := ⟨nat.lt_wf⟩
instance nat.lt.is_well_order : is_well_order ℕ (<) := ⟨nat.lt_wf⟩
instance nat.lt.is_well_order : is_well_order ℕ (<) := { }

instance [linear_order α] [h : is_well_order α (<)] : is_well_order αᵒᵈ (>) := h
instance [linear_order α] [h : is_well_order α (>)] : is_well_order αᵒᵈ (<) := h
2 changes: 1 addition & 1 deletion src/order/well_founded_set.lean
Expand Up @@ -895,7 +895,7 @@ begin
{ intros f hf, existsi rel_embedding.refl (≤),
simp only [is_empty.forall_iff, implies_true_iff, forall_const, finset.not_mem_empty], },
{ intros x s hx ih f hf,
obtain ⟨g, hg⟩ := (is_well_order.wf.is_wf (set.univ : set _)).is_pwo.exists_monotone_subseq
obtain ⟨g, hg⟩ := (is_well_founded.wf.is_wf (set.univ : set _)).is_pwo.exists_monotone_subseq
((λ mo : Π s : σ, α s, mo x) ∘ f) (set.subset_univ _),
obtain ⟨g', hg'⟩ := ih (f ∘ g) (set.subset_univ _),
refine ⟨g'.trans g, λ a b hab, _⟩,
Expand Down
4 changes: 2 additions & 2 deletions src/set_theory/cardinal/basic.lean
Expand Up @@ -532,8 +532,8 @@ protected theorem lt_wf : @well_founded cardinal.{u} (<) :=
end

instance : has_well_founded cardinal.{u} := ⟨(<), cardinal.lt_wf⟩

instance wo : @is_well_order cardinal.{u} (<) := ⟨cardinal.lt_wf⟩
instance : well_founded_lt cardinal.{u} := ⟨cardinal.lt_wf⟩
instance wo : @is_well_order cardinal.{u} (<) := { }

instance : conditionally_complete_linear_order_bot cardinal :=
is_well_order.conditionally_complete_linear_order_bot _
Expand Down
6 changes: 3 additions & 3 deletions src/set_theory/cardinal/cofinality.lean
Expand Up @@ -172,11 +172,11 @@ begin
exact irrefl _ h } },
{ intro a,
have : {b : S | ¬ r b a}.nonempty := let ⟨b, bS, ba⟩ := hS a in ⟨⟨b, bS⟩, ba⟩,
let b := (is_well_order.wf).min _ this,
have ba : ¬r b a := (is_well_order.wf).min_mem _ this,
let b := (is_well_founded.wf).min _ this,
have ba : ¬r b a := (is_well_founded.wf).min_mem _ this,
refine ⟨b, ⟨b.2, λ c, not_imp_not.1 $ λ h, _⟩, ba⟩,
rw [show ∀b:S, (⟨b, b.2⟩:S) = b, by intro b; cases b; refl],
exact (is_well_order.wf).not_lt_min _ this
exact (is_well_founded.wf).not_lt_min _ this
(is_order_connected.neg_trans h ba) }
end

Expand Down
11 changes: 5 additions & 6 deletions src/set_theory/ordinal/basic.lean
Expand Up @@ -678,7 +678,8 @@ instance : linear_order ordinal :=
decidable_le := classical.dec_rel _,
..ordinal.partial_order }

instance : is_well_order ordinal (<) := ⟨lt_wf⟩
instance : well_founded_lt ordinal := ⟨lt_wf⟩
instance : is_well_order ordinal (<) := { }

instance : conditionally_complete_linear_order_bot ordinal :=
is_well_order.conditionally_complete_linear_order_bot _
Expand All @@ -705,18 +706,16 @@ private theorem succ_le_iff' {a b : ordinal} : a + 1 ≤ b ↔ a < b :=
(λ x, ⟨λ _, ⟨x, rfl⟩, λ _, sum.lex.sep _ _⟩)
(λ x, sum.lex_inr_inr.trans ⟨false.elim, λ ⟨x, H⟩, sum.inl_ne_inr H⟩)⟩⟩),
induction_on a $ λ α r hr, induction_on b $ λ β s hs ⟨⟨f, t, hf⟩⟩, begin
refine ⟨⟨@rel_embedding.of_monotone (α ⊕ punit) β _ _
(@sum.lex.is_well_order _ _ _ _ hr _).1.1
(@is_asymm_of_is_trans_of_is_irrefl _ _ hs.1.2.2 hs.1.2.1)
(sum.rec _ _) (λ a b, _), λ a b, _⟩⟩,
haveI := hs,
refine ⟨⟨@rel_embedding.of_monotone (α ⊕ punit) β _ _ _ _ (sum.rec _ _) (λ a b, _), λ a b, _⟩⟩,
{ exact f }, { exact λ _, t },
{ rcases a with a|_; rcases b with b|_,
{ simpa only [sum.lex_inl_inl] using f.map_rel_iff.2 },
{ intro _, rw hf, exact ⟨_, rfl⟩ },
{ exact false.elim ∘ sum.lex_inr_inl },
{ exact false.elim ∘ sum.lex_inr_inr.1 } },
{ rcases a with a|_,
{ intro h, have := @principal_seg.init _ _ _ _ hs.1.2.2 ⟨f, t, hf⟩ _ _ h,
{ intro h, have := @principal_seg.init _ _ _ _ _ ⟨f, t, hf⟩ _ _ h,
cases this with w h, exact ⟨sum.inl w, h⟩ },
{ intro h, cases (hf b).1 h with w h, exact ⟨sum.inl w, h⟩ } }
end
Expand Down
1 change: 1 addition & 0 deletions src/set_theory/ordinal/natural_ops.lean
Expand Up @@ -66,6 +66,7 @@ variables {a b c : nat_ordinal.{u}}
@[simp] theorem to_ordinal_to_nat_ordinal (a : nat_ordinal) : a.to_ordinal.to_nat_ordinal = a := rfl

theorem lt_wf : @well_founded nat_ordinal (<) := ordinal.lt_wf
instance : well_founded_lt nat_ordinal := ordinal.well_founded_lt
instance : is_well_order nat_ordinal (<) := ordinal.has_lt.lt.is_well_order

@[simp] theorem to_ordinal_zero : to_ordinal 0 = 0 := rfl
Expand Down
3 changes: 2 additions & 1 deletion src/set_theory/ordinal/notation.lean
Expand Up @@ -1020,6 +1020,7 @@ instance : has_zero nonote := ⟨⟨0, NF.zero⟩⟩
instance : inhabited nonote := ⟨0

theorem lt_wf : @well_founded nonote (<) := inv_image.wf repr ordinal.lt_wf
instance : well_founded_lt nonote := ⟨lt_wf⟩
instance : has_well_founded nonote := ⟨(<), lt_wf⟩

/-- Convert a natural number to an ordinal notation -/
Expand All @@ -1038,7 +1039,7 @@ theorem cmp_compares : ∀ a b : nonote, (cmp a b).compares a b
end

instance : linear_order nonote := linear_order_of_compares cmp cmp_compares
instance : is_well_order nonote (<) := ⟨lt_wf⟩
instance : is_well_order nonote (<) := { }

/-- Asserts that `repr a < ω ^ repr b`. Used in `nonote.rec_on` -/
def below (a b : nonote) : Prop := NF_below a.1 (repr b)
Expand Down
2 changes: 1 addition & 1 deletion src/topology/metric_space/emetric_paracompact.lean
Expand Up @@ -47,7 +47,7 @@ begin
simp only [Union_eq_univ_iff] at hcov,
-- choose a well founded order on `S`
letI : linear_order ι := linear_order_of_STO' well_ordering_rel,
have wf : well_founded ((<) : ι → ι → Prop) := @is_well_order.wf ι well_ordering_rel _,
have wf : well_founded ((<) : ι → ι → Prop) := @is_well_founded.wf ι well_ordering_rel _,
-- Let `ind x` be the minimal index `s : S` such that `x ∈ s`.
set ind : α → ι := λ x, wf.min {i : ι | x ∈ s i} (hcov x),
have mem_ind : ∀ x, x ∈ s (ind x), from λ x, wf.min_mem _ (hcov x),
Expand Down

0 comments on commit 0893158

Please sign in to comment.