1
$\begingroup$

I was going over a question and need your opinion about solution of the sum of the absolute values as

$$S_n = |0-a|+|1-a|+|2-a|+ \dots + |(n-1)-a|+|n-a|$$

where a is a constant term. What could be the general sum of this series?

$\endgroup$

1 Answer 1

0
$\begingroup$

The general sum of the series, assuming $a$ is real, is easily expressed in terms of the auxiliary function $s(n,a) := \sum_{k=0}^n (n-a) = (n+1)(\frac n2 - a)$. Then $$ S_n = \begin{cases} s(n,a) - 2s(\lfloor a \rfloor, a), & 0 < a< n; \\ s(n,a), & 0 \ge a; \\ -s(n,a), & a \ge n. \end{cases}$$

$\endgroup$
2
  • $\begingroup$ Thanks for the answer. Can you clarify how to get or prove that $S_n = s(n,a) - 2s(\lfloor a \rfloor, a)$. Because in my case $0 < a < n$. $\endgroup$
    – Zizu006
    Commented Oct 14, 2019 at 7:33
  • $\begingroup$ @Zizu006 The terms $|k-a|$ where $k\le \lfloor a \rfloor$ need to be treated as $a-k$ rather than $k-a$. We already have a notation to capture the sum of all such terms. To flip a $+B$ into a $-B$ you subtract $2B$. $\endgroup$
    – Erick Wong
    Commented Oct 14, 2019 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .