# Questions About the FunctionExpand Function

Today, while helping someone solve a problem, I encountered an issue with the Abs function in their expression. I needed to derive the Abs function and then plot it. The original image was a curve, but the plot ended up as a discontinuous straight line, which is obviously wrong. So, I started to check my code step by step and found the problem lies with the derivative of the Abs function.

Here I used the N function, but I didn't get a numerical solution. Then, in the suggestion bar below, Mathematica suggested I use FunctionExpand. I tried this function, and it indeed worked.

I'm not sure why this is the case and I'm hoping someone can help explain it to me.

• This is a bug in FunctionExpand. According to the documentation to Abs "Abs is not a differentiable function". Apr 9 at 15:33
• I don't understand the explanation "Adding assumptions that the argument is real makes Abs differentiable" in the documentation. The correct formulation should be as "The restriction of Abs[z] on the real axis is a differentiable function of the real variable z, except z==0, and this function is denoted by RealAbs[z]". Apr 9 at 15:54
• Apr 14 at 11:37

As far as I understand the documentation to FunctionExpand, here

FunctionExpand[D[Abs[x], x], Assumptions -> x > 0]


1

is used for x == 0.9510565162951535.

\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]


As stated in the documentation, "Abs is a function of a complex variable and is therefore not differentiable." You must either use assumptions or use RealAbs. Then use PiecewiseExpand.

der[t_] = Derivative[1][RealAbs][Sin[2 Pi  t]] // PiecewiseExpand

(* Piecewise[{{-1, Sin[2*Pi*t] < 0}}, 1] *)

der[0.2]

(* 1 *)

Plot[{Abs[Sin[2 Pi  t]], der[t]}, {t, 0, 2}]


EDIT: Or using Assumptions and FullSimplify

FullSimplify[Abs'[Sin[2 Pi  t]], Assumptions -> t ∈ Reals]

(* Sign[Sin[2 π t]] *)
`