Edit: I'm looking for a continuous function. Note also that $f(x)$ is continuous, but it depends on it's summation limit being rounded up (ceil). I changed the limit, previously it was not clear how many terms would there be.
$\lvert x \rvert$ is the absolute value function
$\lfloor x \rfloor$ denotes the floor function
This is a triangle wave function with period of 2 $$T(x) = \left\lvert x - 2\left\lfloor\frac {x + 1}{2}\right\rfloor\right\rvert$$
What I am trying to do is generalizing the summation, because the it's limit may not be an integer. I know the the summation can be expressed without iteration, like $\sum_{k = 1}^{n} k$ can be generalized to $ \frac {n(n+1)}{2}$.
My attempts have not produced correct results.
$$f(x) = xT(x) + \sum_{k = 1}^{\lceil x/2 \rceil} (x + T(x + 1) - 2k + 1)(x + T(x + 1) - 2k)$$
$f(x)$ calculates the following sequence:
$1\cdot2 + 3\cdot4 + \dots + (n-1)\cdot n$
For example:
$f(5) = 1\cdot2 + 3\cdot4 + 5$
$f(6) = 1\cdot2 + 3\cdot4 + 5\cdot6$
This sequence alternates between addition and multiplication (or can be interpreted as so). If $n$ is odd it will be added unpaired, and if it is even it will be added multiplied by $(n - 1)$. It is always the last number.
Describing more formally:
$m \in \Bbb Z$
$f(2m) = 1\cdot2 + 3\cdot4 + \dots + (2m - 1)(2m)$
$f(2m + 1) = 1\cdot2 + 3\cdot4 + \dots + (2m + 1) $
Edit 2: It turns out the closed-form expression is: $$f(x) = xT(x) + \left\lceil \frac x2 \right\rceil\left[x(x + 1) + T(x + 1)\left(2\left(x - \left\lceil \frac x2 \right\rceil\right) + T(x + 1) - 1\right) + \left\lceil \frac x2 + 1 \right\rceil \left(-1 - 2x + \frac 23 \left(2 \left\lceil \frac x2 \right\rceil + 1\right)\right)\right]$$
Thank you for the help and tips.