Zulip Chat Archive

Stream: new members

Topic: sum of n and n^2 in Icc


Sabbir Rahman (Mar 14 2025 at 10:59):

how to prove icc sum formulas like below

import Mathlib

example : ( i  Finset.Icc 1 1000, i) = 1000 * 1001 / 2 := by sorry
example : ( i  Finset.Icc 1 1000, i^2) = 1000 * 1001 * 2001 / 6 := by sorry

I know there is a version for Finset.range for first one, but I haven't worked with big operators or finset much so not sure how to proceed

Kevin Buzzard (Mar 14 2025 at 11:05):

The natural division makes things a little harder -- would you be happy with (i^2 : \Q) etc as your summands? Such a formalization would be closer to the traditional mathematical meaning; for example 1^2+2^2=31/6 in naturals, so this would be provable in Lean, but it wouldn't be true if you coerced to rationals. In particular, proving the things you suggest above doesn't immediately imply them for ratioals.

Aaron Liu (Mar 14 2025 at 11:09):

This is probably not what you meant, but these are also just rfl, since there are no free variables.

import Mathlib

set_option maxRecDepth 5000
example : ( i  Finset.Icc 1 1000, i) = 1000 * 1001 / 2 := rfl
example : ( i  Finset.Icc 1 1000, i^2) = 1000 * 1001 * 2001 / 6 := rfl

Sabbir Rahman (Mar 14 2025 at 11:10):

Kevin Buzzard said:

The natural division makes things a little harder -- would you be happy with (i^2 : \Q) etc as your summands? Such a formalization would be closer to the traditional mathematical meaning; for example 1^2+2^2=31/6 in naturals, so this would be provable in Lean, but it wouldn't be true if you coerced to rationals. In particular, proving the things you suggest above doesn't immediately imply them for ratioals.

Yes sure. best case scenario would be I somehow get existing mathlib theorems to do the work for me

Sabbir Rahman (Mar 14 2025 at 11:10):

Aaron Liu said:

This is probably not what you meant, but these are also just rfl, since there are no free variables.

ah that does solve it :D, but you're right the 1000 is not really my goal, rather it's how to transform those to known theorems

Zhang Qinchuan (Mar 14 2025 at 13:10):

Notice that Finset.Icc a b equals to Finset.Ico a (b+1).

variable (a b : )

#check (Nat.Ico_succ_right :  a b : , Finset.Ico a (b + 1) = Finset.Icc a b)

You can use Finset.sum_Ico_eq_sum_range to transform these Finset.sum.

import Mathlib

example :  i  Finset.Icc 1 1000, i =  i  Finset.range 1001, i := by
  rw [Finset.sum_range_succ', add_zero,  Nat.Ico_succ_right, Finset.sum_Ico_eq_sum_range]
  apply Finset.sum_congr rfl
  intros; rw [add_comm]

Last updated: May 02 2025 at 03:31 UTC