# Sum using variables then evaluated with values gives different result than sum with values

I'm trying to do a sum symbolically. However, Mathematica is giving me a different result if I do the sum with numbers or symbols. What's causing this error?

$Assumptions = m \[Element] Integers && n \[Element] Integers && m >= 0 && n >= 0; f[i_, j_] := If[OddQ[Min[i, j]], (Min[i, j] + (-1)^Max[i, j])/2, Ceiling[Min[i, j]/2]]; Table[f[i, j], {i, 0, 1}, {j, 0, 4}] // TableForm F = Sum[f[i, j], {i, 0, m}, {j, 0, n}]; F /. {m -> 1, n -> 4} Sum[f[i, j], {i, 0, 1}, {j, 0, 4}]  Result 0 0 0 0 0 0 0 1 0 1 4 2  • If you don't mind me asking, what do you intend to do with the symbolic result, if one can be obtained? I tried running your symbolic calculation, but it ran for minutes, after which I aborted it. How long did it take to run on your system? – MarcoB Apr 26 '18 at 22:39 • About 1-2 minutes. And it's just for fun, I'm trying to come up with an analytical expression to count the number of triangles in this rug (youtube.com/watch?v=HViA6N3VeHw&t=12s) – user1543042 Apr 26 '18 at 23:54 • OddQ on symbolic input will evaluate to False. Might be able to achieve the desired effect using Piecewise instead. – Daniel Lichtblau Apr 27 '18 at 14:24 ## 1 Answer I'm not entirely sure why MMA is ignoring the $Assumptions, but here is the correct expression:

Table[
Sum[f[i, j], {i, 0, n}, {j, 0, m}] ==
1/48 (-3 (-1 + (-1)^m) (-1 + (-1)^n) + 12 m n +
2 Min[m, n] (2 + 3 (-1)^m + 3 (-1)^n - 2 Min[m, n]^2 + 6 m n))
, {n, 0, 12}, {m, 0, 12}] // Flatten // Tally
(* {{True, 169}} *)

• How did you get that to evaluate? What version are you using? – user1543042 Apr 27 '18 at 1:09
• @user1543042 I didn't get it to evaluate; I calculated the sum myself. – AccidentalFourierTransform Apr 27 '18 at 1:25
• What method did you use to calculate this? – user1543042 May 11 '18 at 19:22
• @user1543042 You should ask on math.SE. You will get much better answers than here. – AccidentalFourierTransform May 11 '18 at 20:51