The original code is probably fine but there is some confusing (to me) usage of x
vs. k
, possibly to emulate an indefinite integral. I made a few changes both to separate these uses and to give the definite integrals a fighting chance by understanding they are integrating along the positive real axis.
sf[1, x_] := ArcTan[Tan[x]]
sf[2, x_] := Mod[x + \[Pi]/2, \[Pi]] - \[Pi]/2
sf[3, x_] := \[Pi] SawtoothWave[x/\[Pi] - 1/2] - \[Pi]/2
ci[1, k_] = Integrate[sf[1, x], {x, 0, k}, Assumptions -> k > 0]
(* ConditionalExpression[
Piecewise[{{(1/2)*Pi^2*FractionalPart[k/Pi]^2, -(1/2) <
FractionalPart[k/Pi] < 1/2}},
(-(1/2))*
Pi*(-Pi - 2*ArcTan[Tan[k]]*FractionalPart[k/Pi] +
Pi*FractionalPart[k/Pi]^2)], 2*k >= Pi] *)
ci[2, k_] = Integrate[sf[2, x], {x, 0, k}, Assumptions -> k > 0]
(* -((k*Pi)/2) + (1/2)*Pi^2*IntegerPart[k/Pi] +
Piecewise[{{-(Pi^2/8), FractionalPart[k/Pi] == 0},
{(1/2)*
Pi^2*(1 - FractionalPart[k/Pi] + FractionalPart[k/Pi]^2),
2*FractionalPart[k/Pi] > 1}},
(1/2)*Pi^2*FractionalPart[k/Pi]*(1 + FractionalPart[k/Pi])] *)
ci[3, k_] = Integrate[sf[3, x], {x, 0, k}, Assumptions -> k > 0]
(* Out[869]= Integrate[-([Pi]/
2) + [Pi] SawtoothWave[1/2 + x/[Pi]], {x, 0, k},
Assumptions -> k > 0] *)
(Two out of three ain't bad, as a song famously put it.)
Let's do some numeric checks.
In[870]:= ci[1, 5.5]
Out[870]= 0.30669
In[871]:= ci[2, 5.5]
Out[871]= 0.30669
In[872]:= ci[3, 5.5]
Out[872]= 0.30669
In[873]:= NIntegrate[sf[1, x], {x, 0, 5.5}]
Out[873]= 0.305746