# Trouble evaluating an integral expression

Consider the sequence of functions defined as,

$f_n(x)=-1$ if $x\le1-1/n$

and

$f_n(x)=2nx-2n+1$ if $1-1/n\le x\le1$

and evaluate the expression,

$$f_n(x)-\int_0^1f_n(s)ds$$ Now, I know that I should obtain $$f_n(x)-\int_0^1f_n(s)ds=f_n(x)+1-1/n$$ but am unable to do so and don't know what I am doing wrong. Here is what I have done so far: $$f_n(x)-\int_0^1f_n(s)ds=f_n(x)-(\int_0^{1-1/n}f_n(s)ds+\int_{1-1/n}^1f_n(s)ds)$$ $$=f_n(x)-(-\int_0^{1-1/n}ds+\int_{1-1/n}^1(2ns-2n+1)ds$$ $$=f_n(x)+(1-1/n)-\int_{1-1/n}^1f_n(s)ds$$ $$=f_n(x)+1-1/n+n-2/n+1$$

What am I doing wrong?

You made a mistake in the last passage, it should be $$\begin{array}{l} \int_{1 - 1/n}^1 {\left( {2ns - 2n + 1} \right)ds} = \left. {\left( {ns^2 + \left( {1 - 2n} \right)s} \right)\,} \right|_{1 - 1/n}^1 = \\ = \left( {n + \left( {1 - 2n} \right)} \right) - \left( {1 - 1/n} \right)\left( {n\left( {1 - 1/n} \right) + \left( {1 - 2n} \right)} \right) = \\ = \left( {1 - n} \right) - \left( {1 - 1/n} \right)\left( {n - 1 + 1 - 2n} \right) = \\ = \left( {1 - n} \right) + \left( {1 - 1/n} \right)n = \\ = 0 \\ \end{array}$$
$$=f_n(x)-(-\int_0^{1-1/n}ds+\int_{1-1/n}^1(2ns-2n+1)ds=f_n(x)+1-1/n+2n \frac{s^2}{2}\Big|_{1-1/n}^1+(1-2n)s\Big|_{1-1/n}^1$$ $$=f_n(x)+1-1/n+n-n (1-1/n)^2+1-2n-(1-2n)(1-1/n)=f_n(x)+1-1/n\ .$$