# The simplification of complex functions containing Abs and the calculation of its derivatives

In Mathematica, function Abs is not differentiable unless you make an extra assumption that the argument is real

FullSimplify[D[Abs[x], x], Assumptions->{x \[Element] Real}]


This code will give the result Sign[x]. However, what should I do if the argument is complex. Let me give an example.(Where F is a matrix function of 4 variables Omega, omega, qx and qy, I don't show its explicit form here, which is not important, just focus on the result)

FullSimplify[Normalize[Eigenvectors[F[omega, Omega, qx, qy]][[3]]

/.{Omega->0.4}][[1]],Assumptions->{{omega, qx, qy} \[Element] Reals}]


The above code will give a tedious expression

Look at its denominator, which contains an abs function

Abs[(1+E^{I qx})/(1+E^{I qy})]^2


As we know, when the argument is complex, Abs means modulus. So the above expression should be equal to(1+Cos[x])/(1+Cos[y]) But why Mathematica cannot simplify it?

Someone told me to add ComplexExpand within the FullSimplify function, it does work for a simple expression like Abs[1+E^{I qx}].But when applying this to a complicated expression like I gave above, it failed. It took my computer more than 12 hours to evaluate, and it is still running now... ...

So what can I do now? I must get the fully simplified version of the abs function. Because I need to calculate the gradient of that tedious expression in {qx,qy} space. If I just do this to that expression, it will give me something like Abs', which is a desirable result.

If someone is willing to help, I will be very grateful, and I can provide more details of this problem if needed.

## 1 Answer

fun = Abs[(1 + E^{I qx})/(1 + E^{I qy})]^2;

ComplexExpand[fun, TargetFunctions -> {Re, Im}] // FullSimplify


• I know ComplexExand works for simple function Abs[1+E^{I qx}], but when I do this to that long tedious expression, it fails. Is there any other clever way to deal with it or it is simply because the expression is too complicated for Mathematica to simplify ? – Fred Jul 14 '17 at 22:57
• I think you need to post tje whole formula to get an answer – eldo Jul 14 '17 at 23:07