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

Commit ff716d2

Browse files
committed
chore(order/bounds): golf (#5401)
1 parent 3685146 commit ff716d2

File tree

2 files changed

+34
-48
lines changed

2 files changed

+34
-48
lines changed

src/order/bounds.lean

Lines changed: 31 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,29 @@ section linear_order
635635
variables [linear_order α] {s : set α} {a b : α}
636636

637637
lemma lt_is_lub_iff (h : is_lub s a) : b < a ↔ ∃ c ∈ s, b < c :=
638-
by haveI := classical.dec;
639-
simpa [upper_bounds, not_ball] using
640-
not_congr (@is_lub_le_iff _ _ _ _ b h)
638+
by simp only [← not_le, is_lub_le_iff h, mem_upper_bounds, not_forall]
641639

642640
lemma is_glb_lt_iff (h : is_glb s a) : a < b ↔ ∃ c ∈ s, c < b :=
643641
@lt_is_lub_iff (order_dual α) _ _ _ _ h
644642

643+
lemma is_lub.exists_between (h : is_lub s a) (hb : b < a) :
644+
∃ c ∈ s, b < c ∧ c ≤ a :=
645+
let ⟨c, hcs, hbc⟩ := (lt_is_lub_iff h).1 hb in ⟨c, hcs, hbc, h.1 hcs⟩
646+
647+
lemma is_lub.exists_between' (h : is_lub s a) (h' : a ∉ s) (hb : b < a) :
648+
∃ c ∈ s, b < c ∧ c < a :=
649+
let ⟨c, hcs, hbc, hca⟩ := h.exists_between hb
650+
in ⟨c, hcs, hbc, hca.lt_of_ne $ λ hac, h' $ hac ▸ hcs⟩
651+
652+
lemma is_glb.exists_between (h : is_glb s a) (hb : a < b) :
653+
∃ c ∈ s, a ≤ c ∧ c < b :=
654+
let ⟨c, hcs, hbc⟩ := (is_glb_lt_iff h).1 hb in ⟨c, hcs, h.1 hcs, hbc⟩
655+
656+
lemma is_glb.exists_between' (h : is_glb s a) (h' : a ∉ s) (hb : a < b) :
657+
∃ c ∈ s, a < c ∧ c < b :=
658+
let ⟨c, hcs, hac, hcb⟩ := h.exists_between hb
659+
in ⟨c, hcs, hac.lt_of_ne $ λ hac, h' $ hac.symm ▸ hcs, hcb⟩
660+
645661
end linear_order
646662

647663
/-!
@@ -650,52 +666,22 @@ end linear_order
650666

651667
section linear_ordered_add_comm_group
652668

653-
variables [linear_ordered_add_comm_group α] {s : set α} {a ε : α} (h₃ : 0 < ε)
654-
include h₃
669+
variables [linear_ordered_add_comm_group α] {s : set α} {a ε : α}
655670

656-
lemma is_glb.exists_between_self_add (h₁ : is_glb s a) : ∃ b, b ∈ s ∧ a ≤ b ∧ b < a + ε :=
657-
begin
658-
have h' : a + ε ∉ lower_bounds s,
659-
{ set A := a + ε,
660-
have : a < A := by { simp [A, h₃] },
661-
intros hA,
662-
exact lt_irrefl a (lt_of_lt_of_le this (h₁.2 hA)) },
663-
obtain ⟨b, hb, hb'⟩ : ∃ b ∈ s, b < a + ε, by simpa [lower_bounds] using h',
664-
exact ⟨b, hb, h₁.1 hb, hb'⟩
665-
end
671+
lemma is_glb.exists_between_self_add (h : is_glb s a) (hε : 0 < ε) :
672+
∃ b ∈ s, a ≤ b ∧ b < a + ε :=
673+
h.exists_between $ lt_add_of_pos_right _ hε
666674

667-
lemma is_glb.exists_between_self_add' (h₁ : is_glb s a) (h₂ : a ∉ s) :
668-
∃ b, b ∈ s ∧ a < b ∧ b < a + ε :=
669-
begin
670-
rcases h₁.exists_between_self_add h₃ with ⟨b, b_in, hb₁, hb₂⟩,
671-
have h₅ : a ≠ b,
672-
{ intros contra,
673-
apply h₂,
674-
rwa ← contra at b_in },
675-
exact ⟨b, b_in, lt_of_le_of_ne (h₁.1 b_in) h₅, hb₂⟩
676-
end
675+
lemma is_glb.exists_between_self_add' (h : is_glb s a) (h₂ : a ∉ s) (hε : 0 < ε) :
676+
∃ b ∈ s, a < b ∧ b < a + ε :=
677+
h.exists_between' h₂ $ lt_add_of_pos_right _ hε
677678

678-
lemma is_lub.exists_between_sub_self (h₁ : is_lub s a) : ∃ b, b ∈ s ∧ a - ε < b ∧ b ≤ a :=
679-
begin
680-
have h' : a - ε ∉ upper_bounds s,
681-
{ set A := a - ε,
682-
have : A < a := sub_lt_self a h₃,
683-
intros hA,
684-
exact lt_irrefl a (lt_of_le_of_lt (h₁.2 hA) this) },
685-
obtain ⟨b, hb, hb'⟩ : ∃ (x : α), x ∈ s ∧ a - ε < x, by simpa [upper_bounds] using h',
686-
exact ⟨b, hb, hb', h₁.1 hb⟩
687-
end
679+
lemma is_lub.exists_between_sub_self (h : is_lub s a) (hε : 0 < ε) : ∃ b ∈ s, a - ε < b ∧ b ≤ a :=
680+
h.exists_between $ sub_lt_self _ hε
688681

689-
lemma is_lub.exists_between_sub_self' (h₁ : is_lub s a) (h₂ : a ∉ s) :
690-
∃ b, b ∈ s ∧ a - ε < b ∧ b < a :=
691-
begin
692-
rcases h₁.exists_between_sub_self h₃ with ⟨b, b_in, hb₁, hb₂⟩,
693-
have h₅ : a ≠ b,
694-
{ intros contra,
695-
apply h₂,
696-
rwa ← contra at b_in },
697-
exact ⟨b, b_in, hb₁, lt_of_le_of_ne (h₁.1 b_in) h₅.symm⟩
698-
end
682+
lemma is_lub.exists_between_sub_self' (h : is_lub s a) (h₂ : a ∉ s) (hε : 0 < ε) :
683+
∃ b ∈ s, a - ε < b ∧ b < a :=
684+
h.exists_between' h₂ $ sub_lt_self _ hε
699685

700686
end linear_ordered_add_comm_group
701687

src/topology/instances/real.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ begin
351351
{ intros H,
352352
exact H' a ⟨H, ha.1⟩ },
353353
obtain ⟨g₂, g₂_in, g₂_pos, g₂_lt⟩ : ∃ g₂ : ℝ, g₂ ∈ G ∧ 0 < g₂ ∧ g₂ < ε,
354-
{ obtain ⟨b, hb, hb', hb''⟩ := ha.exists_between_self_add' ε_pos a_notin,
355-
obtain ⟨c, hc, hc', hc''⟩ := ha.exists_between_self_add' (by linarith : 0 < b - a) a_notin,
356-
refine ⟨b - c, add_subgroup.sub_mem G hb.1 hc.1, _, _⟩ ;
354+
{ obtain ⟨b, hb, hb', hb''⟩ := ha.exists_between_self_add' a_notin ε_pos,
355+
obtain ⟨c, hc, hc', hc''⟩ := ha.exists_between_self_add' a_notin (sub_pos.2 hb'),
356+
refine ⟨b - c, G.sub_mem hb.1 hc.1, _, _⟩ ;
357357
linarith },
358358
refine ⟨floor (x/g₂) * g₂, _, _⟩,
359359
{ exact add_subgroup.int_mul_mem _ g₂_in },

0 commit comments

Comments
 (0)