Theorem: Finset.equitableOn_iff_le_le_add_one
File: Mathlib/Data/Set/Equitable.lean

tactic: rw [Set.equitableOn_iff_exists_le_le_add_one]
state_before: α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
⊢ EquitableOn (↑s) f ↔ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: refine' ⟨_, fun h => ⟨_, h⟩⟩
state_before: α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
⊢ (∃ b, ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1) ↔
    ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: rintro ⟨b, hb⟩
state_before: α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
⊢ (∃ b, ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1) →
    ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: by_cases h : ∀ a ∈ s, f a = b + 1
state_before: case intro
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: push_neg at h
state_before: case neg
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
h : ¬∀ (a : α), a ∈ s → f a = b + 1
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: obtain ⟨x, hx₁, hx₂⟩ := h
state_before: case neg
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
h : ∃ a, a ∈ s ∧ f a ≠ b + 1
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: suffices h : b = (∑ i in s, f i) / s.card
state_before: case neg.intro.intro
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: symm
state_before: case h
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ b = (∑ i in s, f i) / card s

tactic: refine'
  Nat.div_eq_of_lt_le (le_trans (by simp [mul_comm]) (sum_le_sum fun a ha => (hb a ha).1))
    ((sum_lt_sum (fun a ha => (hb a ha).2) ⟨_, hx₁, (hb _ hx₁).2.lt_of_ne hx₂⟩).trans_le _)
state_before: case h
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ (∑ i in s, f i) / card s = b

tactic: rw [mul_comm, sum_const_nat]
state_before: case h
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ ∑ i in s, (b + 1) ≤ Nat.succ b * card s

tactic: exact fun _ _ => rfl
state_before: case h
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ ∀ (x : α), x ∈ s → b + 1 = Nat.succ b

tactic: intro a ha
state_before: case pos
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
h : ∀ (a : α), a ∈ s → f a = b + 1
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: rw [h _ ha, sum_const_nat h, Nat.mul_div_cancel_left _ (card_pos.2 ⟨a, ha⟩)]
state_before: case pos
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a✝ : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
h : ∀ (a : α), a ∈ s → f a = b + 1
a : α
ha : a ∈ s
⊢ (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: exact ⟨le_rfl, Nat.le_succ _⟩
state_before: case pos
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a✝ : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
h : ∀ (a : α), a ∈ s → f a = b + 1
a : α
ha : a ∈ s
⊢ b + 1 ≤ b + 1 ∧ b + 1 ≤ b + 1 + 1

tactic: simp_rw [← h]
state_before: case neg.intro.intro
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
h : b = (∑ i in s, f i) / card s
⊢ ∀ (a : α), a ∈ s → (∑ i in s, f i) / card s ≤ f a ∧ f a ≤ (∑ i in s, f i) / card s + 1

tactic: apply hb
state_before: case neg.intro.intro
α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
h : b = (∑ i in s, f i) / card s
⊢ ∀ (a : α), a ∈ s → b ≤ f a ∧ f a ≤ b + 1

tactic: simp [mul_comm]
state_before: α : Type u_1
β : Type ?u.8332
s : Finset α
f : α → ℕ
a : α
b : ℕ
hb : ∀ (a : α), a ∈ ↑s → b ≤ f a ∧ f a ≤ b + 1
x : α
hx₁ : x ∈ s
hx₂ : f x ≠ b + 1
⊢ b * card s ≤ ∑ i in s, b