Q:

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

A:

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}} *)

