[Date Index]
[Thread Index]
[Author Index]
Re: Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}, eta<1]
*To*: mathgroup at smc.vnet.net
*Subject*: [mg50636] Re: [mg50617] Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}, eta<1]
*From*: Adam Strzebonski <adams at wolfram.com>
*Date*: Wed, 15 Sep 2004 01:49:37 -0400 (EDT)
*References*: <200409130619.CAA14342@smc.vnet.net> <8C2E6168-0558-11D9-A0AA-000A95B4967A@akikoz.net> <00bc01c49991$4d2d5260$4f604ed5@lap5100> <656B2636-0588-11D9-A0AA-000A95B4967A@akikoz.net>
*Reply-to*: adams at wolfram.com
*Sender*: owner-wri-mathgroup at wolfram.com
This is because what looks simpler (and is simpler from
the mathematical point of view) is not necessarily simpler
when measured by Simplify's built-in complexity function.
Simplify's measure of complextity is based on the number
of leaves in the FullForm of the expression (and also on
the size of integers involved).
In[1]:= Im[Sqrt[-1 + eta^2]]//LeafCount
Out[1]= 10
In[2]:= Sqrt[1 - eta^2]//LeafCount
Out[2]= 11
The second form is computed by Simplify, but is rejected
because it has a higher complexity than the first form.
When the input is a pair, the complexity gain from transformation
Im[Sqrt[-1 + eta^2]] -> Sqrt[1 - eta^2] is offset by complexity
loss from transformation Re[Sqrt[-1 + eta^2]] -> 0.
Both transformations are made in the same simplification step,
namely the "evaluation with assumptions" (a.k.a. Refine).
In[3]:= Refine[{Re[Sqrt[-1+eta^2]],Im[Sqrt[-1+eta^2]]},-1<eta<1]
2
Out[3]= {0, Sqrt[1 - eta ]}
In[4]:= Refine[Re[Sqrt[-1+eta^2]],-1<eta<1]
Out[4]= 0
In[5]:= Refine[Im[Sqrt[-1+eta^2]],-1<eta<1]
2
Out[5]= Sqrt[1 - eta ]
Refine is designed to find a "standard" form of the input
expression, rather than the "simplest" one. It uses a much
smaller set of transformation rules than Simplify, and its
transformations are so chosen that they do not reverse each
other. Hence Refine does not need to use any complexity
criteria, it simply uses all its transformation rules that
apply under the given assumptions.
I would suggest using Refine in addition to Simplify.
Another possibility is to change the ComplexityFunction
used by Simplify.
In[8]:= cf[e_] := LeafCount[e]+10 Count[e, _Im, {0, Infinity}]
In[9]:= Simplify[Im[Sqrt[-1 + eta^2]], -1<eta<1, ComplexityFunction->cf]
2
Out[9]= Sqrt[1 - eta ]
My experience with changing the ComplexityFunction suggests
that for each complexity function there are examples where
an "obvious" simplification does not have a lower complexity
as measured by the given complexity function. However,
for a specific application, using a custom complexity function
may be a good idea.
For completeness let me give a Mathematica implementation
of the "Automatic" complexity function used by Simplify.
SimplifyCount[p_] :=
If[Head[p]===Symbol, 1,
If[IntegerQ[p],
If[p==0, 1, Floor[N[Log[2, Abs[p]]/Log[2, 10]]]+If[p>0, 1, 2]],
If[Head[p]===Rational,
SimplifyCount[Numerator[p]]+SimplifyCount[Denominator[p]]+1,
If[Head[p]===Complex,
SimplifyCount[Re[p]]+SimplifyCount[Im[p]]+1,
If[NumberQ[p], 2,
SimplifyCount[Head[p]]+If[Length[p]==0, 0,
Plus@@(SimplifyCount/@(List@@p))]]]]]]
In[11]:= SimplifyCount/@{Im[Sqrt[-1 + eta^2]], Sqrt[1 - eta^2]}
Out[11]= {11, 12}
Best Regards,
Adam Strzebonski
Wolfram Research
Andrzej Kozlowski wrote:
> *This message was transferred with a trial version of CommuniGate(tm) Pro*
> This is indeed most peculiar and looks like a bug. However as a
> workaround I suggest adding ComplexExpand as follows:
>
>
> FullSimplify[ComplexExpand[Im[Sqrt[-1 + eta^2]]],
> -1 < eta < 1]
>
>
> Sqrt[1 - eta^2]
>
> This also works in version 4.2.
>
> Andrzej
>
> On 13 Sep 2004, at 21:56, Peter S Aptaker wrote:
>
>> Sadly it does not work in M4.2 which I tend to use "for varous reasons"
>>
>>
>> Back to M5 for now:
>>
>> Simplify[{Re[Sqrt[-1+eta^2]],Im[Sqrt[-1+eta^2]]},-1<eta<1] is fine
>>
>> Unfortunately:
>>
>>
>> Simplify[Im[Sqrt[-1 + eta^2]],-1<eta<1]
>>
>> and
>>
>> Simplify[{Im[Sqrt[-1+eta^2]],Im[Sqrt[-1+eta^2]]},-1<eta<1]
>>
>> both leave the Im[]
>>
>> Thanks
>> Peter
>> ----- Original Message -----
>> From: "Andrzej Kozlowski" <andrzej at akikoz.net>
To: mathgroup at smc.vnet.net
>> To: "peteraptaker" <psa at laplacian.co.uk>
>> Cc: <mathgroup at smc.vnet.net>
>> Sent: Monday, September 13, 2004 8:43 AM
>> Subject: [mg50636] Re: [mg50617] Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 +
>> eta^2]]}, eta<1]
>>
>> > *This message was transferred with a trial version of
>> CommuniGate(tm) Pro*
>> > On 13 Sep 2004, at 15:19, peteraptaker wrote:
>> >
>> > > *This message was transferred with a trial version of CommuniGate(tm)
>> > > Pro*
>> > > Have I missed something - my apologies if this is answered in a FAQ
>> > > I want to make the simple Re and Im parts simplify properly?
>> > >
>> > > test =
>> > > {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}
>> > >
>> > > FullSimplify[test, eta > 1]
>> > > gives*{Sqrt[-1 + eta^2], 0}
>> > >
>> > > But
>> > > FullSimplify[test, eta < 1]
>> > > gives
>> > > {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}
>> > >
>> > > Needs["Algebra`ReIm`"] does not seem to help
>> > >
>> > > Real numbers demonstrate what should happen:
>> > > test) /. {{eta -> 0.1}, {eta -> 2}}
>> > > {{0., 0.99498743710662}, {Sqrt[3], 0}}
>> > >
>> > >
>> >
>> > There is nothing really strange here, Mathematica simply can't give a
>> > single simple expression that would cover all the cases that arise. So
>> > you have to split it yourself, for example:
>> >
>> >
>> > FullSimplify[test, eta < -1]
>> >
>> >
>> > {Sqrt[eta^2 - 1], 0}
>> >
>> > FullSimplify[test, eta == -1]
>> >
>> > {0, 0}
>> >
>> >
>> > FullSimplify[test, -1 < eta < 1]
>> >
>> > {0, Sqrt[1 - eta^2]}
>> >
>> >
>> > FullSimplify[test, eta == 1]
>> >
>> >
>> > {0, 0}
>> >
>> >
>> > FullSimplify[test, 1 <= eta]
>> >
>> >
>> > {Sqrt[eta^2 - 1], 0}
>> >
>> >
>> > or, you can combine everything into just two cases:
>> >
>> > FullSimplify[test, eta $B":(B Reals && Abs[eta] < 1]
>> >
>> > {Re[Sqrt[eta^2 - 1]], Im[Sqrt[eta^2 - 1]]}
>> >
>> >
>> > FullSimplify[test, eta $B":(B Reals && Abs[eta] >= 1]
>> >
>> > {Sqrt[eta^2 - 1], 0}
>> >
>> > In fact you do not really need FullSimplify, simple Simplify will do
>> > just as well.
>> >
>> >
>> > Andrzej Kozlowski
>> > Chiba, Japan
>> > http://www.akikoz.net/~andrzej/
>> > http://www.mimuw.edu.pl/~akoz/
>> >
>> >
>
>
Prev by Date:
**Re: Re: Smallest enclosing circle**
Next by Date:
**Re: Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}, eta<1]**
Previous by thread:
**Re: Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}, eta<1]**
Next by thread:
**Re: Simplify[ {Re[Sqrt[-1 + eta^2]], Im[Sqrt[-1 + eta^2]]}, eta<1]**
| |