For example, the sequence of triangular numbers can be expressed as $1/2 [n (n + 1)]$ with $n=1,2,3,4,...$ but is it possible to create a summation of everything remaining $(2,4,5,7,8,9,11,12,13,14,...)$? The problem I seem to have is the increasing amount of integers between each following triangular number.
1 Answer
ClearAll[f]
f[n_Integer] := Array[# (# + 1)/2 &, n, 1, Complement[Range[n (n + 1)/2], {##}] &]
f[5]
{2, 4, 5, 7, 8, 9, 11, 12, 13, 14}
Total @ f @ 5
85
You can get a closed form expression for the desired sum noting that (1) the sum of the first m
triangular numbers is
Sum[n (n + 1)/2, {n, 1, m}]
1/6 m (1 + m) (2 + m)
and (2) the sum of integers up to m(m+1)/2
is
m (m + 1)/2 (1 + m (m + 1)/2)/2
Taking the difference and Simplify
ing:
m (m + 1)/2 (1 + m (m + 1)/2)/2 - Sum[ n (n + 1)/2, {n, 1, m}] // FullSimplify
we get
1/24 (-1 + m) m (1 + m) (2 + 3 m)
We can get the same result by generating a list of sums using f
and using FindSequenceFunction
on the list:
t[m_] := FindSequenceFunction[Total[f @ #] & /@ Range[100]][m]
t[m]
1/24 (-1 + m) (2 m + 5 m^2 + 3 m^3)
t[5]
85