How to find the primitive/ antiderivative of a discontinuous function I have the following function before me:
$$f(x)=\left\{\begin{array}{ll}\phantom{-}x^2, &x\leq 0\\-x^2+2,&x>0\end{array} \right .$$
I have to find a function $g(x)$ such that $g'(x)=f(x)$. Clearly, $f(x)$ is not continuous at $x=0$, as there is a jump discontinuity at that point.
Do such functions admit any antiderivative. And if they do, is that antiderivative unique?
Will taking $g(x)=\dfrac{x^3}{3}$ when $x\leq0$ and $g(x)=-\dfrac{x^3}{3}+2x$ when $x>0$ work? Clearly $g(x)$ is  continuous which is a pre-requisite for it to be differentiable.
 A: For sufficiently nice functions $f$ like the one in this example (e.g., functions that are continuous on some interval except perhaps at a finite number of jump discontinuities) and any $a$ in the domain of $f$, $$F(x) := \int_a^x f(t) \,dt$$ (1) is continuous and (2) satisfies $$F'(x) = f(x)$$ everywhere except at those discontinuities, where $F'(x)$ is not defined. As usual, $F$ is not unique: For any constant $C$ we also have $(F(x) + C)' = f(x)$ everywhere except again at the discontinuities of $f$.
To compute an explicit formula for such an $F$, it's enough to compute an antiderivative of $f$ on each interval bounded by discontinuities and, roughly speaking, (by choosing constants of integration appropriately) patch them together into a single continuous function $F$.
In the case of our function, taking the lower bound of the above integral to be $a = 0$ yields the candidate you suggest:
$$F(x) = \left\{\begin{array}{ll}\phantom{-}\frac{1}{3} x^3, &x \leq 0 \\ -\frac{1}{3} x^3 + 2 x, & x \geq 0\end{array}\right. .$$
A: Antiderivative just refers to a function whose derivative will be this function. But since this function is discontinuous at $x=0$ the antiderivative you will compute will not be differentiable at $x=0$.
However, you can still think of a function whose derivative will be this function, like
For $x\leq0$, we can have
$$g(x)=\frac{x^3}{3}+C_1$$
For $x>0$, we can have
$$g(x)=-\frac{x^3}{3}+2x+C_2$$
Antiderivative is never unique there are a whole lot differing by a constant. But in this case, it has two variables which can assume any values however if you impose the condition of continuity on $g(x)$ then this reduces to only one variable as $C_1$ must equal $C_2$ in that case.
