Theorem: Nat.eq_properDivisors_of_subset_of_sum_eq_sum
File: Mathlib/NumberTheory/Divisors.lean

tactic: cases n
state_before: n : ℕ
s : Finset ℕ
hsub : s ⊆ properDivisors n
⊢ ∑ x in s, x = ∑ x in properDivisors n, x → s = properDivisors n

tactic: classical
  rw [← sum_sdiff hsub]
  intro h
  apply Subset.antisymm hsub
  rw [← sdiff_eq_empty_iff_subset]
  contrapose h
  rw [← Ne.def, ← nonempty_iff_ne_empty] at h
  apply ne_of_lt
  rw [← zero_add (∑ x in s, x), ← add_assoc, add_zero]
  apply add_lt_add_right
  have hlt :=
    sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_properDivisors (sdiff_subset _ _ hx)
  simp only [sum_const_zero] at hlt
  apply hlt
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
⊢ ∑ x in s, x = ∑ x in properDivisors (succ n✝), x → s = properDivisors (succ n✝)

tactic: rw [properDivisors_zero, subset_empty] at hsub
state_before: case zero
s : Finset ℕ
hsub : s ⊆ properDivisors zero
⊢ ∑ x in s, x = ∑ x in properDivisors zero, x → s = properDivisors zero

tactic: simp [hsub]
state_before: case zero
s : Finset ℕ
hsub : s = ∅
⊢ ∑ x in s, x = ∑ x in properDivisors zero, x → s = properDivisors zero

tactic: rw [← sum_sdiff hsub]
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
⊢ ∑ x in s, x = ∑ x in properDivisors (succ n✝), x → s = properDivisors (succ n✝)

tactic: intro h
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
⊢ ∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x → s = properDivisors (succ n✝)

tactic: apply Subset.antisymm hsub
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : ∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x
⊢ s = properDivisors (succ n✝)

tactic: rw [← sdiff_eq_empty_iff_subset]
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : ∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x
⊢ properDivisors (succ n✝) ⊆ s

tactic: contrapose h
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : ∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x
⊢ properDivisors (succ n✝) \ s = ∅

tactic: rw [← Ne.def, ← nonempty_iff_ne_empty] at h
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : ¬properDivisors (succ n✝) \ s = ∅
⊢ ¬∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x

tactic: apply ne_of_lt
state_before: case succ
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
⊢ ¬∑ x in s, x = ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x

tactic: rw [← zero_add (∑ x in s, x), ← add_assoc, add_zero]
state_before: case succ.h
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
⊢ ∑ x in s, x < ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x

tactic: apply add_lt_add_right
state_before: case succ.h
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
⊢ 0 + ∑ x in s, x < ∑ x in properDivisors (succ n✝) \ s, x + ∑ x in s, x

tactic: have hlt :=
  sum_lt_sum_of_nonempty h fun x hx => pos_of_mem_properDivisors (sdiff_subset _ _ hx)
state_before: case succ.h.bc
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
⊢ 0 < ∑ x in properDivisors (succ n✝) \ s, x

tactic: simp only [sum_const_zero] at hlt
state_before: case succ.h.bc
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
hlt : ∑ i in properDivisors (succ n✝) \ s, 0 < ∑ i in properDivisors (succ n✝) \ s, i
⊢ 0 < ∑ x in properDivisors (succ n✝) \ s, x

tactic: apply hlt
state_before: case succ.h.bc
s : Finset ℕ
n✝ : ℕ
hsub : s ⊆ properDivisors (succ n✝)
h : Finset.Nonempty (properDivisors (succ n✝) \ s)
hlt : 0 < ∑ i in properDivisors (succ n✝) \ s, i
⊢ 0 < ∑ x in properDivisors (succ n✝) \ s, x