# Do not understand expression returned by FullSimplify

Why Mathematica returns (sec x)^2?

(Tan[x]^2 + 1 - Sec[x]^2)/(Sin[x]^2 + Cos[x]^2 - 1) // FullSimplify

Sec[x]^2


Because this? Then differentiate？

Integrate[(Tan[x]^2 + 1 - Sec[x]^2)/(Sin[x]^2 + Cos[x]^2 - 1), x]

Tan[x]


And WolframAlpha returns several answers

Why these happened？It's strange。

-
@Kuba I guess OP is suspecting that Simplify has internally Integrateed the expression and then differentiated it. – xzczd May 13 '14 at 7:53
Oh,I know,next time I will post as few images as I can.And,is this a bug?The answer obvious wrong. – czp May 13 '14 at 9:02
In mma8,the answer is Indeterminate,In mma9 the answer is (sec x)^2 – czp May 13 '14 at 9:50

I am not sure, but I think Mathematica use the L'Hospital's Rule to handle $0/0$ or $\infty/\infty$. For Example consider $Sin[x]/x$ which should be indeterminate at $x=0$, but it is well known that the value is $1$ (you can use the Plot to convince yourself). The key is, at the limiting case you can replace the denominator and numerator (see the webpage for details) by their derivative, and then it becomes Cos[x] which is 1 for x=0.

Now coming to your problem let,

a[x_, y_] := (Tan[x]^2 + 1 - Sec[x + y]^2)
b[x_, y_] := (Sin[x]^2 + Cos[x + y]^2 - 1)


then you are interested in a[x,0]/b[x,0] which should have an answer $0/0$ for any value of x. Now use the L'Hospital's Rule.

And then I am in a trouble. D[a[x,y],y]/D[b[x,y] gives $Sec[x+y]^4$ which for y=0 is $Sec[x]^4$. But There can be further modification for multivariable L'Hospital's Rule which I am not aware of (I am not a mathematician, honestly) and which can lead to the answer. The limiting value always depends on how you are approaching to the point and depending on that you can get multiple answer.

Anyway, this can be one of the reasons behind getting such results. I hope someone will come up with a better answer.

-