2
$\begingroup$

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
$\endgroup$
3
  • $\begingroup$ 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? $\endgroup$
    – MarcoB
    Apr 26, 2018 at 22:39
  • $\begingroup$ 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) $\endgroup$ Apr 26, 2018 at 23:54
  • $\begingroup$ OddQ on symbolic input will evaluate to False. Might be able to achieve the desired effect using Piecewise instead. $\endgroup$ Apr 27, 2018 at 14:24

1 Answer 1

2
$\begingroup$

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}} *)
$\endgroup$
4
  • $\begingroup$ How did you get that to evaluate? What version are you using? $\endgroup$ Apr 27, 2018 at 1:09
  • 1
    $\begingroup$ @user1543042 I didn't get it to evaluate; I calculated the sum myself. $\endgroup$ Apr 27, 2018 at 1:25
  • $\begingroup$ What method did you use to calculate this? $\endgroup$ May 11, 2018 at 19:22
  • $\begingroup$ @user1543042 You should ask on math.SE. You will get much better answers than here. $\endgroup$ May 11, 2018 at 20:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.