Mathematica giving different results from Sum when I expand the sum and evaluate some terms separately

Here we have the initial sum T1[m,n], then I removed the one term (k) and completed the exact sum and the remainder sum called T2[m,n]. T1[m,n] and T2[m,n] should be identical. The test in the table the first few values are different. What is wrong here. I am using Mathematica 12.2.

T1[m_,n_]:=Sum[k-Ceiling[(1/2)+(1/2)Sqrt[(2k-1)^2-4n]]),{k,Ceiling[(1/2)+Sqrt[n]],Ceiling[m/2]}];


Expand the sum over k and we get

(1/2) Ceiling[m/2]+(1/2)Ceiling[m/2]^2+(1/2)Ceiling[(1/2)+Sqrt[n]\-(1/2)Ceiling[(1/2)+Sqrt[n]]^2


Rewrite the T1[m,n] function as T2[m,n] where

T2[m,n]:=(1/2) Ceiling[m/2]+(1/2)Ceiling[m/2]^2+(1/2)Ceiling[(1/2)+Sqrt[n]]-(1/2)Ceiling[(1/2)+Sqrt[n]]^2-Sum[Ceiling[(1/2)+(1/2)Sqrt[(2k-1)^2-4n]]),{k,Ceiling[(1/2)+Sqrt[n]],Ceiling[m/2]}];


Now for a table of the two sums and take their difference which should be zero

So setting m = H-10, and n = H, we iterate over H as {H,11,100}. Showing the first few entries we have

So how can these two sums be different in the initial few values? If I use a different shift in the m I get similar results, the first few values are not matched then all values afterwards are correct.

• You are using Sum() ; Notational error or C&P error? Jul 12, 2023 at 7:22
• There are several errors and/or missing braces in the given definitions for T1 and T2. Please update in a copy&paste-able format Jul 12, 2023 at 7:26

T2[m,n]:=((1/2) Ceiling[m/2]+(1/2)Ceiling[m/2]^2+(1/2)Ceiling[(1/2)+Sqrt[n]]-(1/2)Ceiling[(1/2)+Sqrt[n]]^2)KroneckerDelta[True, Ceiling[(m)/2] >= Ceiling[-1/2 + Sqrt[n]]]-Sum[Ceiling[(1/2)+(1/2)Sqrt[(2k-1)^2-4n]]),{k,Ceiling[(1/2)+Sqrt[n]],Ceiling[m/2]}];