Skip to content

Commit 743d325

Browse files
chore(Interval): minor golfing (#546)
Golfed two lemmas that were claimed to be significantly golfable. This is not particularly enlightening content but I had it locally so I made a PR. Co-authored-by: Aristotle (Harmonic) <aristotle-harmonic@harmonic.fun>
1 parent e7e40ea commit 743d325

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

Carleson/ToMathlib/Interval.lean

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Mathlib.Order.SuccPred.Basic
33
import Mathlib.Tactic.Common
44

55
-- Upstreaming status: results seem useful in general, some should be generalised
6-
-- Proofs can probaby be polished and golfed significantly
76

87
open Function Order Set
98

@@ -34,69 +33,41 @@ section LinearOrder
3433
variable [LinearOrder α]
3534

3635
-- TODO: can or should these lemmas take a more general indexing type?
37-
-- TODO: the proofs below can probably be golfed significantly, do so!
3836
theorem iUnion_Ico_eq_Ici {f : ℕ → α} (hf : ∀ n, f 0 ≤ f n) (h2f : ¬BddAbove (range f)) :
3937
⋃ (i : Nat), Ico (f i) (f (i+1)) = Ici (f 0) := by
4038
apply subset_antisymm
4139
· exact iUnion_subset fun i ↦ Ico_subset_Ici (hf i)
4240
· intro a ha
4341
by_contra! hcontra
44-
apply h2f
45-
rw [bddAbove_def]
46-
use a
47-
suffices ∀ i, f i ≤ a by simp [this]
48-
intro i
49-
induction i with
50-
| zero => exact ha
51-
| succ i hind => simp_all
42+
simp only [mem_iUnion, mem_Ico, not_exists, not_and, not_lt] at hcontra
43+
exact h2f ⟨a, forall_mem_range.mpr (Nat.rec ha hcontra)⟩
5244

5345
theorem iUnion_Ioc_eq_Ioi {f : ℕ → α} (hf : ∀ n, f 0 ≤ f n) (h2f : ¬BddAbove (range f)) :
5446
⋃ (i : Nat), Ioc (f i) (f (i+1)) = Ioi (f 0) := by
5547
apply subset_antisymm
5648
· exact iUnion_subset fun i ↦ Ioc_subset_Ioi (hf i)
5749
· intro a ha
5850
by_contra! hcontra
59-
apply h2f
60-
use a
61-
suffices ∀ i, f i < a by
62-
intro y hy
63-
obtain ⟨i, rfl⟩ := hy
64-
exact (this i).le
65-
intro i
66-
induction i with
67-
| zero => exact ha
68-
| succ i hind => simp_all
51+
simp only [mem_iUnion, mem_Ioc, not_exists, not_and, not_le] at hcontra
52+
exact h2f ⟨a, forall_mem_range.mpr (fun i ↦ le_of_lt (Nat.rec ha hcontra i))⟩
6953

7054
variable {ι : Type*} [LinearOrder ι] [SuccOrder ι]
7155

7256
theorem pairwise_disjoint_Ico_monotone {f : ι → α} (hf : Monotone f) :
7357
Pairwise (Function.onFun Disjoint fun (i : ι) => Ico (f i) (f (Order.succ i))) := by
74-
unfold Function.onFun
75-
simp_rw [Set.disjoint_iff]
76-
intro i j hinej
77-
wlog! hij : i < j generalizing i j
78-
· have := this hinej.symm (hij.lt_of_ne hinej.symm)
79-
rwa [inter_comm]
80-
intro a
81-
push _ ∈ _
82-
simp only [imp_false, not_and, not_lt, and_imp]
83-
intro ha ha2 ha3
84-
have : ¬f j ≤ a := not_le.mpr (lt_of_lt_of_le ha2 (hf (SuccOrder.succ_le_of_lt hij)))
85-
contradiction
58+
intro i j hij
59+
wlog h : i < j with H
60+
· exact (H hf hij.symm (hij.lt_or_gt.resolve_left h)).symm
61+
exact disjoint_left.mpr fun _a hai haj ↦
62+
not_le.mpr (hai.2.trans_le (hf (Order.succ_le_of_lt h))) haj.1
8663

8764
theorem pairwise_disjoint_Ioc_monotone {f : ι → α} (hf : Monotone f) :
8865
Pairwise (Function.onFun Disjoint fun (i : ι) ↦ Ioc (f i) (f (Order.succ i))) := by
89-
unfold Function.onFun
90-
simp_rw [Set.disjoint_iff]
91-
intro i j hinej
92-
wlog! hij : i < j generalizing i j
93-
· have := this hinej.symm (hij.lt_of_ne hinej.symm)
94-
rwa [inter_comm]
95-
intro a
96-
push _ ∈ _
97-
simp only [imp_false, not_and, and_imp]
98-
intro ha ha2 ha3
99-
simp_all [not_lt.mpr (ha2.trans (hf (SuccOrder.succ_le_of_lt hij)))]
66+
intro i j hij
67+
wlog h : i < j with H
68+
· exact (H hf hij.symm (hij.lt_or_gt.resolve_left h)).symm
69+
exact disjoint_left.mpr fun _a hai haj ↦
70+
not_lt.mpr (hai.2.trans (hf (Order.succ_le_of_lt h))) haj.1
10071

10172
end LinearOrder
10273

0 commit comments

Comments
 (0)