Discontinuous function with continuous derivative Differentiability implies continuity, but what in this case ?
$$
  f(x) = \frac{1}{\sqrt{2}}\arctan\left(\sqrt{2} \tan{x}\right)
$$
It's discontinuous at $x = \pi/2 + n\pi$, $n$ is integer. But,
$$
  g(x) = \frac{1}{1+\sin^2{x}}
$$
It's continuous over real numbers and it's the derivative of $f(x)$.
How could it be?
When I make the definite integral of $g(x)$ from $1.5$ to $4$ using the formal definition of definite integral:
$f(4) - f(1.5) = -0.352255$, which is totally wrong. but when I make Riemann sum to approximate it, I get $1.86919$.
So what I miss ??

The question may be asked in inverse manner.
g(x) is a continuous positive function over all real numbers, so its anti-derivative MUST be an increasing continuous function.
 A: The derivative of $f$ at $x$ is, by definition,
$$f'(x) = \lim_{h \to 0}\frac{f(x+h)-f(x)}{h}.$$
This definition is meaningless when $f(x)$ is not defined. The expression for the derivative you gave is meaningful when $x \neq \pi/2 +  n\pi$, $n \in \mathbb{Z}\setminus\{0\}$.
A: Differentiability implies continuity on the domain of the function. And the domain of a function is not necessarily the whole of $\mathbf R$.
A: 
The moral is, a discontinuous periodic function can have continuous derivative. (More precisely, a periodic function whose left- and right-hand limits are unequal at some points can, nonetheless, have derivative with removable discontinuities.)
The trig functions and the principal branches of their inverses are good at creating this type of behavior. While it's true that
$$
\tan(\arctan x) = x\quad\text{for all real $x$,}
$$
it's not true that
$$
\arctan(\tan x) = x\quad\text{for all real $x$,}
$$
only that
$$
\arctan(\tan x) = x\quad\text{for all real $x$ with $|x| < \pi/2$.}
$$

Edit: The arctangent function (also known as "the principal branch of arctan"), shown bold in the graph below, is single-valued. The tangent function, however, is periodic with period $\pi$, so there are infinitely many branches of inverse tangent, any two differing by an integer multiple of $\pi$. For every integer $n$, we have
$$
x = \arctan(\tan x) + n\pi\quad\text{for $(n - \tfrac{1}{2})\pi < x < (n + \tfrac{1}{2})\pi$.}
$$

Consider the functions
$$
f(x) = \frac{1}{\sqrt{2}} \arctan(\sqrt{2} \tan x),\qquad
F(x) = \int_{0}^{x} \frac{dt}{1 + \sin^{2} t}.
$$

These functions have the same derivative $g$ for all real $x$ unless $x = (n + \frac{1}{2})\pi$ for some integer $n$; for these $x$, the value $f(x)$ is undefined, because $\tan(n + \frac{1}{2})\pi$ is undefined. Call these points poles of the tangent function.
As $x$ runs over the period interval $(n - \frac{1}{2})\pi < x < (n + \frac{1}{2})\pi$ between two poles of the tangent function, $\sqrt{2}\tan x$ runs once over the entire real line, so $\arctan(\sqrt{2}\tan x)$ runs once over the interval $(-\frac{1}{2}\pi, \frac{1}{2}\pi)$. The graph of $f$ consists of "repeated units", with a "jump" at each point $(n + \frac{1}{2})\pi$; the function $f$ "forgets" how many poles of tan lie between $0$ and $x$.
By contrast, the graph of $F$ "remembers" how many poles lie between $0$ and $x$. When $x$ crosses a pole of tan, $\sqrt{2}\tan x$ "jumps" from being "near $+\infty$" to being "near $-\infty$". Because area under the graph of $g$ accumulates continuously, the value of $F$ "continues" using the "next-highest" branch of arctan. Loosely, instead of "returning to $-\infty$ and re-using the same branch of arctan" (as $f$ does), $F$ continues by "following a dashed line from right to left" and starting on the next branch of arctan.
That is how $f$ and $F$ manage to have the same derivative (except at the poles of tan, where $f$ is undefined), but $f$ is periodic while $F$ extends continuously over the poles.
In the extended real numbers $[-\infty, \infty]$, in fact, arctan has a continuous extension, defined by
$$
\arctan(\pm\infty) = \lim_{x \to \pm\infty} \arctan x = \pm\tfrac{1}{2}\pi.
$$
This isn't much help with $f$, because now $f$ gets two values at each pole of tan, namely $\pm \frac{\pi}{2\sqrt{2}}$, but it does dictate why each time $x$ crosses a pole of tan, $F$ "climbs" to the next branch of arctan, and it shows why $F$ is continuous at the poles of tan.
A: $g(x)$ is NOT the derivative of $f(x)$ at points of discontinuity because $f(x)$ isn't differentiable there! 
A: To obtain this derivative you need to use the chain rule. Essentially, $$\frac{d}{dx}\arctan(\sqrt{2}\tan(x))=\left(\frac{d}{dx}\sqrt{2}\tan(x)\right)\left(\frac{d}{d(\sqrt{2}\tan(x))}\arctan(\sqrt{2}\tan(x))\right).$$ But the chain rule only applies when both of these derivatives exist. The first of these two doesn't exist at certain points (as you have noted), so the derivative you have given does not apply at these points. So in fact the derivative is $$f'(x)=\cases{\frac{1}{1+\sin^2(x)} & \text{ if $x\neq \pi/2+n\pi$}\\ \text{d.n.e.} & \text{otherwise.}}$$ Thus, the function is not differentiable at these points, even if these are removable singularities in the derivative.
A: In the paper "Rectifying Transformations for the Integration of
Rational Trigonometric Functions" by D. J. Jeffrey, he writes:
$$\int \frac{2\, \mathrm{d}z}{1+\cos^2 z} = \sqrt{2} z + \arctan \frac{\cos{z}}{\sin{z} + \sqrt{2} + 1} + \arctan \frac{\cos{z}}{\sin{z} - \sqrt{2} - 1}$$
And this primitive is continuous over all $\mathbb{C} \setminus \{ z \in \mathbb{C} \, \vert \, 1+\cos^2 z = 0 \}$
You can obtain your integral by using the complementary angle identity for $\cos z$.
For more reading, see:
The Importance of Being Continuous, D. J. Jeffrey
The Evaluation of Trigonometric Integrals Avoiding Spurious Discontinuities, D. J. Jeffrey
and the references in those papers.
