Sum
and Table
do exactly the same thing
In[1]:= Table[{i, j}, {i, 2, 9}, {j, 0, 5 - i}]
Out[1]= {{{2, 0}, {2, 1}, {2, 2}, {2, 3}}, {{3, 0}, {3, 1}, {3, 2}}, {{4, 0}, {4, 1}}, {{5, 0}}, {}, {}, {}, {}}
if
$j_{max} < j_{min}$ the element is skipped. Now for Sum
in symbolic form
In[7]:= Sum[{f[i], g[j]}, {i, 2, 9}, {j, 0, 5 - i}]
Out[7]= {4 f[2] + 3 f[3] + 2 f[4] + f[5], 4 g[0] + 3 g[1] + 2 g[2] + g[3]}
In[8]:= (* {f,g} *)
{4 2 + 3 3 + 2 4 + 5, 4 0 + 3 1 + 2 2 + 3}
Out[8]= {30, 10}
The iterator step is by default 1 and with that step one cannot reach -1 starting from 0.
If in
Table[{i, j}, {i, 2, 9}, {j, 0, 5 - i}]
j
should step down too one takes that into account by typing
In[11]:= Table[{i, j}, {i, 2, 9}, {j, 0, 5 - i, Sign[5 - i]}]
Out[11]= {{{2, 0}, {2, 1}, {2, 2}, {2, 3}},
{{3, 0}, {3, 1}, {3, 2}},
{{4, 0}, {4, 1}},
{{5, 0}},
{{6, 0}, {6, -1}},
{{7, 0}, {7, -1}, {7, -2}},
{{8, 0}, {8, -1}, {8, -2}, {8, -3}},
{{9, 0}, {9, -1}, {9, -2}, {9, -3}, {9, -4}}}
which fits to the expectations
In[15]:= Plus @@@ Transpose[Flatten[Table[{i, j}, {i, 2, 9}, {j, 0, 5 - i, Sign[5 - i]}], 1]]
Out[15]= {140, -10}
And, yes
In[16]:= Sum[{i, j}, {i, 2, 9}, {j, 0, 5 - i, Sign[5 - i]}]
Out[16]= {140, -10}
And yes
If you program ... without care
you do not program, but merely type. It is the same thing as the infamous wrong proof in mathematics.