How does one find the integrals of piecewise functions? Of course, I am interested in finding out about how one would find the result of a piecewise function if I simply integrated it.
In other words, how does one integrate a function like:
$f(x)=\{(x^2: x\le0),(x:x>0)\}$
or
$g(x) = sgn(\sin x)$
where $sgn(x)$ is the signum function
Simply put it, how does one find the antiderivative?
Not evaluated between $a$ or $b$ points, but rather the whole function.
Please, if you can, put in some sources or the steps to getting the result.
 A: The first thing to recognize is that "the" antiderivative is a misnomer, because if it exists, it is not unique: we can add any constant and the result will be another antiderivative. In particular, assuming $f$ is continuous, any integral of the form
$$\int_c^x f(t) dt$$ 
is an antiderivative of $f$. (This is one of the fundamental theorems of calculus.) Here, $c$ is any constant. A particularly easy constant to work with is $c = 0$. In this case, an antiderivative of $f$ is
$$I(x) = \int_0^x f(t) dt$$
To evaluate this, consider two cases.
Case 1 $x \leq 0$
In this case, $f(t) = t^2$ in the interval $[x,0]$, so
$$I(x) = \int_0^x f(t) dt = \int_0^x t^2 dt = \frac{x^3}{3}$$
Case 2 $x > 0$
In this case, $f(t) = t$ in the interval $[0,x]$, so
$$I(x) = \int_0^x f(t) dt = \int_0^x t dt = \frac{x^2}{2}$$
Putting the pieces together, we see that an antiderivative of $f$ is given by
$$I(x) = \begin{cases}
\displaystyle \frac{x^3}{3} \text{if }x \leq 0 \\
\displaystyle \frac{x^2}{2} \text{if }x > 0 \\
\end{cases}$$
More generally, $I(x) + C$ is an antiderivative for any constant $C$.
For the second example, 
$$g(x) = \text{sgn}(\sin x),$$
note that $g$ is not continuous at $x=0$. To see this, observe that for small positive $x$, we have $\sin x > 0$, so $g(x) = 1$, whereas for small negative $x$, we have $\sin x < 0$, so $g(x) = -1$. Finally, $g(0)$ is either $0$, $1$, or $-1$, depending on how you define $\text{sgn}$. In any case, $\lim_{x \to 0^+}g(x) = 1$ whereas $\lim_{x \to 0^-}g(x) = -1$, so $\lim_{x \to 0}g(x)$ does not exist, hence $g$ cannot be continuous at $x=0$ no matter how we define $g(0)$.
For the same reason, $g$ is not continuous at any $x$ where $\sin(x) = 0$, in other words, at any multiple of $\pi$.
Now, this means that there cannot be any function $I$ which is differentiable everywhere such that $I' = g$. This is because the derivative of a differentiable function must satisfy the intermediate value property, so $I'$ cannot have a step discontinuity.
Of course, we can find a function $I$ which is differentiable everywhere except at multiples of $\pi$, such that $I'(x) = g(x)$ for all $x \neq 0$. To do this, take an arbitrary interval $(k\pi, (k+1)\pi)$ (where $k$ is an integer), and find an antiderivative of $g$ in this interval.
Thus for $x \in (k\pi, (k+1)\pi)$, we have $\sin(x) > 0$ if $k$ is even, and $\sin(x) < 0$ if $k$ is odd, so in either case, $g(x) = \text{sgn}(\sin(x)) = (-1)^k$. Then
$$\int_{k\pi}^x g(t) dt = \int_{k\pi}^x (-1)^k dt = (-1)^k (x - k\pi)$$
Therefore, the function $I$ defined piecewise by
$$I(x) = (-1)^k(x - k\pi), \qquad x \in (k\pi, (k+1)\pi)$$
satisfies $I'(x) = g(x)$ for all $x$ except multiples of $\pi$. Note that $I$ is a periodic "triangle" function with slope $+1$ or $-1$ on intervals $(k\pi, (k+1)\pi)$ where $k$ is even or odd, respectively.
More generally, if for each integer $k$, we let $c_k$ be any constant, then
$$J(x) = 
(-1)^k(x - k\pi) + c_k, \qquad x \in (k\pi, (k+1)\pi)$$
satisfies $J'(x) = g(x)$ for all non-multiples of $\pi$.
