Calculating integral of step function My question is from Apostol's Vol. 1: One-variable calculus with introduction to linear algebra textbook.

Page 70. Exercise 10. Given a positive integer $p$. A step function $s$ is defined on the interval $[0,p]$ as follows: $s(x)=(-1)^nn$ if $x$ lies in the interval $n\le x<n+1$, where $n=0,1,2,\cdots,p-1;$ $s(p)=0$. Let $f(p)=\int_0^ps(x)\mathrm dx.$
a) Calculate $f(3),f(4)$ and $f(f(3)).$
b) For what value (or values) of $p$ is $|f(p)|=7$?

The attempt at a solution. As I understood, $s(x)=(-1)^nn$ can also be expressed as $s(x)=(-1)^{\lfloor x\rfloor}\lfloor x\rfloor$, and graph of that step function is:

Here, $$f(3)=\int_0^3((-1)^{\lfloor x\rfloor}\lfloor x\rfloor)\mathrm dx=2-1=1,$$ $$f(4)=\int_0^4((-1)^{\lfloor x\rfloor}\lfloor x\rfloor)\mathrm dx=2-1-3=-2,$$ $$f(f(3))=\int_0^1((-1)^{\lfloor x\rfloor}\lfloor x\rfloor)\mathrm dx=0,$$
But answers in the book say that $f(4)=-1$, where am I making mistake or what am I misunderstanding?
 A: The floor function is an example of a discontinuous integral. This means it can be done by splitting the integral. However, just to beef up this question let's compute the indefinite integral. Then we'll be forced to deal with the discontinuity.
First off, floor itself is level everywhere. That means that we can use a sort of preliminary integral to get a function closer to our end result by simply holding floor fixed during integration. If you don't know what it means to hold something fixed, that's fine. You'll see in my calculations. Afterwards, we'll want to remove the jumps from the graph of the improper integral. This will consist purely of me iterating through the points of discontinuity with a piecewise summation. The formula itself won't necessarily make sense without looking closely for a while (depending on your level of understanding in calculus), but it is the formula for removing discontinuity from step functions.
First we take the "integral"):
$$\int (-1)^{\lfloor x \rfloor} \lfloor x \rfloor = x(-1)^{\lfloor x \rfloor} \lfloor x \rfloor$$
Now we remove the discontinuity:
We use a notation called the iverson for this. It's just piecewise. Basically, it returns 1 when a math statement is fulfilled aka true, and 0 when not fulfilled aka false. It's literally just "[]".
Don't use it on your homework without putting a note that it's an indicator function, though. The teacher's will nail to the wall for violating notation. Better yet, just ask them if you can use it and how they want it written.
$$x(-1)^{\lfloor x \rfloor} \lfloor x \rfloor - [x > 0] \sum^{\lfloor x \rfloor}_{n=0} (\lim_{a \to n^+} (a(-1)^{\lfloor a \rfloor} \lfloor a \rfloor)-\lim_{a \to n^-} (a(-1)^{\lfloor a \rfloor} \lfloor a \rfloor)) + [x < 0] \sum^{\lfloor x \rfloor}_{n=0} (\lim_{a \to n^-} (a(-1)^{\lfloor a \rfloor} \lfloor a \rfloor)-\lim_{a \to n^+} (a(-1)^{\lfloor a \rfloor} \lfloor a \rfloor))$$
Distribute limits:
$$x(-1)^{\lfloor x \rfloor} \lfloor x \rfloor - [x > 0] \sum^{\lfloor x \rfloor}_{n=0} ((n(-1)^{n}n)-(n(-1)^{n-1}(n-1))) + [x < 0] \sum^{\lfloor x \rfloor}_{n=0} ((n(-1)^{n-1}(n-1))-(n(-1)^{n}n))$$
$$x(-1)^{\lfloor x \rfloor} \lfloor x \rfloor - [x > 0] \sum^{\lfloor x \rfloor}_{n=0} ((n(-1)^{n}n)+(n(-1)^{n}(n-1))) + [x < 0] \sum^{\lfloor x \rfloor}_{n=0} (-(n(-1)^{n}(n-1))-(n(-1)^{n}n))$$
$$x(-1)^{\lfloor x \rfloor} \lfloor x \rfloor - [x > 0] \sum^{\lfloor x \rfloor}_{n=0} (n(-1)^{n}(2n-1))) + [x < 0] \sum^{\lfloor x \rfloor}_{n=0} (-(n(-1)^{n}(2n-1)))$$
if one could please provide with the equation for that series, I can complete this integral. Otherwise, here is the indefinite integral. You can simply plug in values to solve your parts. As for part b.. The floor function has no inverse. So you'd have to play with it.
