Zulip Chat Archive

Stream: new members

Topic: rw in a sum


Harold Cooper (Nov 07 2021 at 21:31):

I came back to working on this proof and am stuck again, any tips would be appreciated.

Overall I'm trying to prove k=1nk(nk)=nk=1nkk=1nk2=nn(n+1)2n(n+1)(2n+1)6=(n+13)\sum_{k=1}^n k (n - k) = n \sum_{k=1}^n k - \sum_{k=1}^n k^2 = n \frac{n(n+1)}{2} - \frac{n(n+1)(2n+1)}{6} = {n + 1 \choose 3}

I'm able to rewrite k2\sum k^2 using docs#sum_range_pow

But my attempts to rewrite k\sum k using either sum_range_pow again or docs#finset.sum_range_id are failing.

Here are my two attempts. In the first, I'm unable to use rw ← pow_one to rewrite k\sum k as k1\sum k^1 so I can apply sum_range_pow. And in the second, I'm unable to use sum_range_id.

import algebra.big_operators.basic
import data.rat.basic
import number_theory.bernoulli

open_locale big_operators
open finset (range)

example {n : } :  k in range (n+1), (k*(n-k) : ) = (n+1).choose 3 :=
begin
  simp_rw mul_sub,
  rw [finset.sum_sub_distrib,  finset.sum_mul],
  conv { congr, congr, skip, congr, skip, funext, rw  sq, },
  rw sum_range_pow,
  conv { congr, congr, congr, congr, skip, funext, rw  pow_one, },
end

example {n : } :  k in range (n+1), (k*(n-k) : ) = (n+1).choose 3 :=
begin
  simp_rw mul_sub,
  rw [finset.sum_sub_distrib,  finset.sum_mul],
  simp_rw  sq,
  rw sum_range_pow,
  simp_rw finset.sum_range_id,
end

(I know I could probably also prove this by induction, but I think fixing these will teach me some stuff.)

Notification Bot (Nov 07 2021 at 21:34):

Harold Cooper has marked this topic as unresolved.

Kevin Buzzard (Nov 07 2021 at 21:34):

rw ← pow_one (x : ℚ) works for the first one

Kevin Buzzard (Nov 07 2021 at 21:37):

For the second one I don't understand the question. sum_range_id is about i<ni\sum_{i<n}i which I don't see in your goal, so the rewrite fails as expected.

Harold Cooper (Nov 07 2021 at 21:42):

here's a shorter example of the second issue. the goal contains (∑ (x : ℕ) in range (n + 1), ↑x) which I was hoping sum_range_id could do something with

import algebra.big_operators.basic
import data.rat.basic
import number_theory.bernoulli

open_locale big_operators
open finset (range)

example {n : } :  k in range (n+1), (k*(n-k) : ) = (n+1).choose 3 :=
begin
  simp_rw mul_sub,
  rw [finset.sum_sub_distrib,  finset.sum_mul],
  rw finset.sum_range_id,
end

maybe the coercion is the issue? or that the sum is being multiplied by something?

Kevin Buzzard (Nov 07 2021 at 21:43):

No, ↑x is not equal to x, so the rewrite will fail. Theorem provers are picky! The lemma is about a sum of naturals, you have a sum of rationals.

Harold Cooper (Nov 07 2021 at 21:43):

okay yeah that's fair

Kevin Buzzard (Nov 07 2021 at 21:44):

You'll first have to rewrite the lemma saying that the sum of the coercions equals the coercion of the sums.

Kevin Buzzard (Nov 07 2021 at 21:45):

but finset.sum_range_id is evil, because it contains natural division. You'd be better off proving the result you want (the sum of the rationals is what it is) yourself (by induction) and then rewriting that.

Harold Cooper (Nov 07 2021 at 21:45):

haha yeah it is starting to look like this will all be much easier with induction

Harold Cooper (Nov 07 2021 at 21:46):

thanks for the help!

Kevin Buzzard (Nov 07 2021 at 21:46):

If you rewrite "sum of coercions equals coercion of sums" and then sum_range_id you then won't be able to put the coercion back, because natural division and rational division don't commute with the coercion.

Kevin Buzzard (Nov 07 2021 at 22:01):

I would say that this question, whether you do it over the rationals or naturals, is quite tricky to do in Lean for a beginner. You'll need to know how to do algebra under a sum -- the easy rearrangements which humans do can be done by automation like ring -- but rewrites won't work under a binder which makes this one a bit annoying.

Kevin Buzzard (Nov 07 2021 at 22:07):

My (pretty messy) solution


Last updated: Dec 20 2023 at 11:08 UTC