       Re: Question about the derivative of Abs

• To: mathgroup at smc.vnet.net
• Subject: [mg106118] Re: [mg106097] Question about the derivative of Abs
• From: Leonid Shifrin <lshifr at gmail.com>
• Date: Sat, 2 Jan 2010 05:03:41 -0500 (EST)
• References: <201001011036.FAA05264@smc.vnet.net>

```Sam,

The problem seems to be that Abs is defined generally on complex numbers.
Once you specify that your argument is real, it works:

In:= FullSimplify[Abs'[x], Assumptions -> {Element[x, Reals]}]

Out= Sign[x]

In fact, it works also for specific integer arguments (although not
automatically)

In:= FullSimplify[Abs']

Out= 1

For a reason I don't understand, this does not work for specific real
arguments however:

In:= FullSimplify[Abs'[2.0]]

Out= (Abs^\[Prime])[2.]

I don't see a good reason for this and think that it should be fixed to also
simplify just like in the case of integers. On the other hand, the above
simplification with FullSimplify seems to be rather a point-like solution -
a result of some specific rule that has been added to the kernel. For
example, the second derivative would not simplify:

In:= FullSimplify[Abs'']

Out= (Abs^\[Prime]\[Prime])

So, coming back to your specific question, here is what I would do:

1. Define your own function <abs>, for example like this:

Clear[abs];
abs[x_]:=Piecewise[{{x,x>0},{-x,x<=0}}]

you may check that it works for derivatives without any extra simplification
effort:

In:= abs'[1.5]

Out= 1

In:= abs''[1.5]

Out= 0

2. Use replacement rules to replace Abs with <abs>, in places where you need
this:

In:= Abs''[2.0]/.Abs-> abs

Out= 0

Hope this helps.

Regards,
Leonid

On Fri, Jan 1, 2010 at 2:36 AM, Sam Takoy <samtakoy at yahoo.com> wrote:

> Hi,
>
> I kind of asked this question before, but in a more confusing context,
> so now I would like to ask it by itself.
>
> In the course of my computations, I get Abs' and Abs''. It is applied to
> a positive number, so I think those values should be 1 and 0. However,
> Mathematica fails to simplify it.
>
> For example
>
> In:= Abs'[2.0]
>
> Out=
> \!\(\*SuperscriptBox["Abs", "\[Prime]",
> MultilineFunction->None]\)[2.]
>
>
> These expressions really mess up my answers. How do I get Mathematica to
> do these simplifications?
>
> Thanks
>
> Sam
>
>

```

• Prev by Date: Re: Database Challenge
• Next by Date: Re: Uninstalling/Reinstalling Mathematica 7?