Working Through the Derivative of Tangent
I keep running into people who treat the derivative of tan x as if it's just another formula to memorize, which is unfortunate because the actual mechanics behind it reveal why the result is what it is. When you're sitting down to actually derive it from first principles, you start with the definition of the tangent function as sine over cosine, then apply the quotient rule. That gives you (cos x times cos x minus negative sin x times sin x), all over cosine squared x. Simplify the numerator, you get cos squared x plus sin squared x, which equals one by the Pythagorean identity. The denominator stays cosine squared x. So the derivative of tan x is one over cosine squared x, or secant squared x. It's one of those results where the beauty is in how cleanly everything collapses, not in the answer itself. Here's where most explanations get lazy and skip ahead. Let me walk through the quotient rule application in full. If f(x) equals tan x, then f(x) equals sin x over cos x. Set u equal sin x and v equal cos x. The quotient rule says the derivative is (v times du minus u times dv) divided by v squared. Compute du, that's cos x. Compute dv, that's negative sin x. Substitute everything in: (cos x times cos x minus sin x times negative sin x) divided by cos squared x. The double negative in the numerator becomes a positive, so you have cos squared x plus sin squared x over cos squared x. That top expression collapses to exactly one. Result is 1 over cos squared x. Which we also write as sec squared x. I don't repeat this enough in practice, but writing it out by hand each time actually trains your intuition for harder cases like cotangent or the other reciprocal functions. I remember dealing with an optimization problem a few years back involving a rational trigonometric function where the objective was to minimize cos x divided by the quantity one plus tan squared x over sin x. Most people would try expanding tan immediately and getting lost in algebra. I recognized that 1 plus tan squared x is literally sec squared x from the Pythagorean identity, so I substituted that first and the expression collapsed to cos x times cos squared x divided by sin x, which is just cos cubed x over sin x. Taking the derivative then was straightforward because I already knew d over dx of tan x equals sec squared x, and the chain rule on cos cubed came naturally from there. The whole problem that would have taken twenty minutes of expansion got cut down to roughly five minutes once I stopped fighting the identities and started using them.
One thing nobody warns you about is the domain restriction. The derivative of tan x only exists wherever tan x itself exists. At x equals pi over two plus any integer multiple of pi, the function has vertical asymptotes, and the derivative blows up to infinity at those points too. I've seen students write sec squared x as the final answer and then plug in x equals pi over two without checking. It's a trivial oversight but it shows up constantly on exams and in actual computational work where you might be setting up numerical methods and assume smoothness everywhere. Always note that the derivative formula is valid only on the domain of the tangent function. Another nuance that comes up in practice involves the derivative of tangent to some function, not just x itself. Say you need the derivative of tan of three x squared plus one. The chain rule applies here and the outer derivative is sec squared of the inner function, multiplied by the derivative of the inner function. So it becomes sec squared of three x squared plus one times six x. People routinely forget to multiply by the derivative of the inside. I catch myself making this mistake when I'm working quickly through a long problem set, and I've learned to circle the inner function every single time before differentiating, even if it's just mental. That small habit has saved me more times than I can count. If you're looking at the derivative of tan x from a computational standpoint, like implementing this in code, there's a practical detail worth noting. Computing sec squared x by evaluating 1 over cos squared x can introduce floating point errors near the asymptotes where cosine approaches zero. A better approach in numerical work is to compute tan squared x plus one instead, since sec squared x equals one plus tan squared x, and that avoids the division entirely. It's a minor optimization but it keeps your calculations stable when you're evaluating near those singularities.