Re: Abs[a] Sin[Abs[a]]
- To: mathgroup at smc.vnet.net
- Subject: [mg21021] Re: [mg20923] Abs[a] Sin[Abs[a]]
- From: Adam Strzebonski <adams at wolfram.com>
- Date: Thu, 2 Dec 1999 21:41:32 -0500 (EST)
- Organization: Wolfram Reasearch, Inc
- References: <B46B1939.3546%andrzej@tuins.ac.jp>
- Sender: owner-wri-mathgroup at wolfram.com
Andrzej Kozlowski wrote:
>
> Mathematica can only manage this under the assumption a>0.
> In[1]:=
> Simplify[ Abs[a] Sin[Abs[a]], a > 0]
> Out[1]=
> a Sin[a]
>
> One problem is that Simplify does not know that Abs[a] is -a for negative a.
>
> In[2]:=
> Simplify[Abs[a], a < 0]
> Out[2]=
> Abs[a]
This is a complexity function problem. Under the
default complexity function Abs[a] is simpler than
-a ( Times[-1, a] in FullForm, now it looks more
complicated than Abs[a]...) If we define a complexity
function assigning a heavier weight to Abs we can get
the simplification.
In[1]:= f[x_]:=LeafCount[x]+10 Count[x, _Abs, {0, Infinity}]
In[2]:= Simplify[Abs[a], a<0, ComplexityFunction->f]
Out[2]= -a
In[3]:= Simplify[Abs[a] Sin[Abs[a]], a<0, ComplexityFunction->f]
Out[3]= a Sin[a]
>
> In fact one would really like Simplify to manage more complicated cases
> involving Abs, e.g.:
>
> In[3]:=
> Simplify[Abs[Sin[a]], a < 0]
> Out[3]=
> Abs[Sin[a]]
I presume you meant Sin[Abs[a]]. It works
automatically, as soon as Abs[a]->-a works.
In[4]:= Simplify[Sin[Abs[a]], a<0, ComplexityFunction->f]
Out[4]= -Sin[a]
>
> Just for fun I have decided to write a quick hack that will give the right
> answer for these cases. One has to modify Simplify in two ways. Firstly, we
> add the above missing rule for Abs. This alone however is not enough. The
> second change is a general rule for Simplify[expr, Element[something,
> Reals]]. This is a more drastic change to the way Simplify works now but at
> the moment I can't see anything that would be broken by it. Here is my
> attempt:
>
> In[4]:=
> Unprotect[Simplify];
> Simplify[expr_, x_ < 0] :=
> Simplify[expr /. {Abs[x] :> -x, Abs[Sin[x]] :> -Sin[x]}]
> Simplify[expr_, Element[x_, Reals]] :=
> If[(Simplify[expr, x > 0] ===
> Simplify[expr, x < 0]) && ((Simplify[expr, x > 0] /. x :> 0) ===
> Simplify[expr, x == 0]), Simplify[expr, x > 0], Simplify[expr]]
> Protect[Simplify];
> (Really we should also give rules for Simplify[expr_,{a___,x_<0,b___}] etc).
>
> Now indeed we get:
>
> In[5]:=
> Simplify[Abs[a], a < 0]
> Out[5]=
> -a
>
> In[6]:=
> Simplify[Abs[Sin[a]], a < 0]
> Out[6]=
> -Sin[a]
>
> and finally:
>
> In[7]:=
> Simplify[ Abs[a] *Sin[Abs[a]], Element[a, Reals]]
> Out[7]=
> a Sin[a]
The path of simplification of Abs[a]*Sin[Abs[a]]
to a Sin[a] for a>0 is different than for a<0, so
to get this simplification Simplify would need to
do something similar to your second rule, i.e.
simplify the whole expression under assumptions a>0,
a==0, and a<0 separately and compare the results.
This seems to have a too high complexity to be
attempted automatically: an assumption that n
variables are real would lead to calling Simplify
with 3^n sets of assumptions (on each subexpression
of the input expression...).
A somewhat less costly version of this would be
to just try replacing Abs[a] (for a assumed real)
with a and with -a and comparing the results
(without simplifying them). It would suffice in
this example. I will experiment with adding
a rule like this to (possibly Full)Simplify.
Best regards,
Adam Strzebonski
Wolfram Research
>
> Of course there is a large number of other non-polynomial functions which
> are odd and about which Simplify doesn't know so one would like to add a
> rule for Simplify[Abs[f[a]],a<0] for all of these. Even this however would
> not work in more complicated cases where f was some non-polynomial non
> built-in function. The problem is that Simplify relies on the ability to
> solve inequalities, which can really only be done in the case of polynomial
> ones.
>
> > From: Edward Goldobin <gold at isitel1.isi.kfa-juelich.de>
To: mathgroup at smc.vnet.net
> > Organization: Research Center Juelich GmbH
> > Date: Wed, 1 Dec 1999 01:49:54 -0500 (EST)
> > To: mathgroup at smc.vnet.net
> > Subject: [mg21021] [mg20923] Abs[a] Sin[Abs[a]]
> >
> > How to compell Mathematica to simplify
> > Abs[a] Sin[Abs[a]]
> > to
> > a Sin[a]
> >
> > ?
> > Why it does not do it automatically? I also tried
> > assumptions like a :enum: Reals.
> >
> > Thanx
> > Edward
> >