Skip to content

Commit

Permalink
feat(data/finset/basic): strengthen finset.nonempty.cons_induction (#…
Browse files Browse the repository at this point in the history
…11452)

This change makes it strong enough to be used in three other lemmas.
  • Loading branch information
eric-wieser committed Jan 15, 2022
1 parent ff19c95 commit 0d1d4c9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
8 changes: 3 additions & 5 deletions src/analysis/seminorm.lean
Expand Up @@ -387,11 +387,9 @@ by simp_rw [ball, ←set.set_of_and, coe_sup, pi.sup_apply, sup_lt_iff]
lemma ball_finset_sup' (p : ι → seminorm 𝕜 E) (s : finset ι) (H : s.nonempty) (e : E) (r : ℝ) :
ball (s.sup' H p) e r = s.inf' H (λ i, ball (p i) e r) :=
begin
induction s using finset.cons_induction_on with a s ha ih,
{ exact false.elim (not_nonempty_empty H), },
{ rcases s.eq_empty_or_nonempty with rfl | hs,
{ classical, simp },
{ rw [finset.sup'_cons hs, finset.inf'_cons hs, ball_sup, inf_eq_inter, ih] } },
induction H using finset.nonempty.cons_induction with a a s ha hs ih,
{ classical, simp },
{ rw [finset.sup'_cons hs, finset.inf'_cons hs, ball_sup, inf_eq_inter, ih] },
end

end has_scalar
Expand Down
13 changes: 7 additions & 6 deletions src/data/finset/basic.lean
Expand Up @@ -654,18 +654,19 @@ theorem induction_on' {α : Type*} {p : finset α → Prop} [decidable_eq α]
let ⟨hS, sS⟩ := finset.insert_subset.1 hs in h₂ hS sS has (hqs sS)) (finset.subset.refl S)

/-- To prove a proposition about a nonempty `s : finset α`, it suffices to show it holds for all
singletons and that if it holds for `t : finset α`, then it also holds for the `finset` obtained by
inserting an element in `t`. -/
singletons and that if it holds for nonempty `t : finset α`, then it also holds for the `finset`
obtained by inserting an element in `t`. -/
@[elab_as_eliminator]
lemma nonempty.cons_induction {α : Type*} {s : finset α} (hs : s.nonempty) {p : finset α → Prop}
(h₀ : ∀ a, p {a}) (h₁ : ∀ ⦃a⦄ s (h : a ∉ s), p s → p (finset.cons a s h)) :
p s :=
lemma nonempty.cons_induction {α : Type*} {p : Π s : finset α, s.nonempty → Prop}
(h₀ : ∀ a, p {a} (singleton_nonempty _))
(h₁ : ∀ ⦃a⦄ s (h : a ∉ s) hs, p s hs → p (finset.cons a s h) (nonempty_cons h))
{s : finset α} (hs : s.nonempty) : p s hs :=
begin
induction s using finset.cons_induction with a t ha h,
{ exact (not_nonempty_empty hs).elim, },
obtain rfl | ht := t.eq_empty_or_nonempty,
{ exact h₀ a },
{ exact h₁ t ha (h ht) }
{ exact h₁ t ha ht (h ht) }
end

/-- Inserting an element to a finite set is equivalent to the option type. -/
Expand Down
20 changes: 9 additions & 11 deletions src/data/finset/lattice.lean
Expand Up @@ -368,7 +368,7 @@ lemma inf_sdiff_left {α β : Type*} [boolean_algebra α] {s : finset β} (hs :
(a : α) :
s.inf (λ b, a \ f b) = a \ s.sup f :=
begin
refine hs.cons_induction (λ b, _) (λ b t _ h, _),
induction hs using finset.nonempty.cons_induction with b b t _ _ h,
{ rw [sup_singleton, inf_singleton] },
{ rw [sup_cons, inf_cons, h, sdiff_sup] }
end
Expand All @@ -377,7 +377,7 @@ lemma inf_sdiff_right {α β : Type*} [boolean_algebra α] {s : finset β} (hs :
(a : α) :
s.inf (λ b, f b \ a) = s.inf f \ a :=
begin
refine hs.cons_induction (λ b, _) (λ b t _ h, _),
induction hs using finset.nonempty.cons_induction with b b t _ _ h,
{ rw [inf_singleton, inf_singleton] },
{ rw [inf_cons, inf_cons, h, inf_sdiff] }
end
Expand Down Expand Up @@ -522,15 +522,13 @@ end

lemma exists_mem_eq_sup' [is_total α (≤)] : ∃ b, b ∈ s ∧ s.sup' H f = f b :=
begin
induction s using finset.cons_induction with c s hc ih,
{ exact false.elim (not_nonempty_empty H), },
{ rcases s.eq_empty_or_nonempty with rfl | hs,
{ exact ⟨c, mem_singleton_self c, rfl⟩, },
{ rcases ih hs with ⟨b, hb, h'⟩,
rw [sup'_cons hs, h'],
cases total_of (≤) (f b) (f c) with h h,
{ exact ⟨c, mem_cons.2 (or.inl rfl), sup_eq_left.2 h⟩, },
{ exact ⟨b, mem_cons.2 (or.inr hb), sup_eq_right.2 h⟩, }, }, },
refine H.cons_induction (λ c, _) (λ c s hc hs ih, _),
{ exact ⟨c, mem_singleton_self c, rfl⟩, },
{ rcases ih with ⟨b, hb, h'⟩,
rw [sup'_cons hs, h'],
cases total_of (≤) (f b) (f c) with h h,
{ exact ⟨c, mem_cons.2 (or.inl rfl), sup_eq_left.2 h⟩, },
{ exact ⟨b, mem_cons.2 (or.inr hb), sup_eq_right.2 h⟩, }, },
end

lemma sup'_mem
Expand Down
13 changes: 5 additions & 8 deletions src/data/real/ennreal.lean
Expand Up @@ -858,14 +858,11 @@ theorem sum_lt_sum_of_nonempty {s : finset α} (hs : s.nonempty)
{f g : α → ℝ≥0∞} (Hlt : ∀ i ∈ s, f i < g i) :
∑ i in s, f i < ∑ i in s, g i :=
begin
classical,
induction s using finset.induction_on with a s as IH,
{ exact (finset.not_nonempty_empty hs).elim },
{ rcases finset.eq_empty_or_nonempty s with rfl|h's,
{ simp [Hlt _ (finset.mem_singleton_self _)] },
{ simp only [as, finset.sum_insert, not_false_iff],
exact ennreal.add_lt_add (Hlt _ (finset.mem_insert_self _ _))
(IH h's (λ i hi, Hlt _ (finset.mem_insert_of_mem hi))) } }
induction hs using finset.nonempty.cons_induction with a a s as hs IH,
{ simp [Hlt _ (finset.mem_singleton_self _)] },
{ simp only [as, finset.sum_cons, not_false_iff],
exact ennreal.add_lt_add (Hlt _ (finset.mem_cons_self _ _))
(IH (λ i hi, Hlt _ (finset.mem_cons.2 $ or.inr hi))) }
end

theorem exists_le_of_sum_le {s : finset α} (hs : s.nonempty)
Expand Down

0 comments on commit 0d1d4c9

Please sign in to comment.