MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: bug -- advice sought

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84545] Re: bug -- advice sought
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 3 Jan 2008 20:24:04 -0500 (EST)
  • References: <200801031035.FAA15853@smc.vnet.net>

On 3 Jan 2008, at 19:35, UHAP023 at alpha1.rhbnc.ac.uk wrote:

> Dear All,
> 	A couple of queries;
>
> (1) Regarding the following expression,
>
> z=2*Sqrt[2]*Rvt^5*(Rvt^2 + Rx^2)^(3/2)*w^2*
> (Sqrt[2*Dc - I*Rx^2*w]*(2*Dc - I*(Rvt^2 + Rx^2)*w)^3 +
>  Sqrt[2*Dc + I*Rx^2*w]*(2*Dc + I*(Rvt^2 + Rx^2)*w)^3)
>
> all the variables are of Real type and are +ve.  I do the following
> FullSimplify[],
>
> z = FullSimplify[
>    z, {Rx \[Element] Reals, Rvt \[Element] Reals, Dc \[Element] Reals,
>      w \[Element] Reals,  Rx > 0, Rvt > 0, Dc > 0,  w > 0}]
>
> and get an unchanged result.  Now I believe that this expression
> should *always* produce a real result for real, +ve parameter values.
> A simple but obviously non-rigorous test is to substitute arbitrary
> real,+ve values for the parameters and observe the numeric result,
> eg.,
>
> Rx = Random[]; Rvt = Random[]; w = Random[]; Dc = Random[]; z
>
> The result is indeed always real (ie. Im[z]==0).  Given that
> FullSimplify[] tries to return the simplest result rather than
> eliminate complex expressions as I want, I tried doing,
>
> FullSimplify[z, {Rx \[Element] Reals, Rvt \[Element] Reals,
>    Dc \[Element] Reals, w \[Element] Reals,  Rx > 0, Rvt > 0, Dc > 0,
>    w > 0}, ComplexityFunction -> (Count[{#1}, _Complex , \ 
> [Infinity]] &)]
>
> which I hoped would do what I want.  Unfortunately it returns a more
> complicated result (fair enough) but which has the same number of I's
> as the input expression (not OK).  What am I doing wrong here?  Is
> there a way to do this?

Here is one way to do this. Let


z = 2*Sqrt[2]*Rvt^5*(Rvt^2 + Rx^2)^(3/2)*w^2*
      (Sqrt[I*w*Rx^2 + 2*Dc]*
           (2*Dc + I*(Rvt^2 + Rx^2)*w)^3 +
         (2*Dc - I*(Rvt^2 + Rx^2)*w)^3*
           Sqrt[2*Dc - I*Rx^2*w])

First, let's show that your expression is always real under the  
conditions you state:

Reduce[Element[z, Reals] &&
      And @@ {Rx > 0, Rvt > 0, Dc > 0, w > 0},
    {Rx, Rvt, Dc, w, Rx, Rvt, Dc, w}]

Rx > 0 && Rvt > 0 && Dc > 0 && w > 0

This may look strange but it actually says that z is indeed real under  
the stated conditions. So now let's try to find an expression for z  
not involving I:

  p = FullSimplify[ComplexExpand[Re[z],
        TargetFunctions -> {Re, Im}],
      {Rx > 0, Rvt > 0, Dc > 0, w > 0}]

4*Sqrt[2]*Rvt^5*(Rvt^2 + Rx^2)^(3/2)*w^2*
    (w^2*Rx^4 + 4*Dc^2)^(1/4)*
    (2*Dc*(4*Dc^2 - 3*(Rvt^2 + Rx^2)^2*w^2)*
         Cos[(1/2)*ArcCot[(2*Dc)/(Rx^2*w)]] +
       (Rvt^2 + Rx^2)*w*((Rvt^2 + Rx^2)^2*w^2 - 12*Dc^2)*
         Sin[(1/2)*ArcCot[(2*Dc)/(Rx^2*w)]])

As you can see, there are no I's. Let's confirm that this is indeed  
equal to z under your conditions:


FullSimplify[z == p, {Rx > 0, Rvt > 0, Dc > 0, w > 0}]
True

In general however there is no algorithm to express a "real  
expression" without involving I's, and even the above method is not  
guaranteed to always work. In addition, even when methods like the  
above one work, as in this case, they have a very high complexity and  
therefore are not applied automatically. This, I think, answers the  
second part of your question.

Andrzej Kozlowski



>
>
> = 
> = 
> = 
> = 
> = 
> = 
> = 
> ======================================================================
>
> (2) The above query was precipitated indirectly by the following
> strangeness.  I am integrating the following integrand,
>
> igrand=(Dc*Rx^2*Cos[theta]^2)/((4*Dc^2 + Rx^4*w^2*Cos[theta]^4)*
>  (Rvt^2 + Rx^2*Sin[theta]^2)^3)
>
> Again the parameters are all of Real type and +ve.  Moreover the
> expression only contains a fraction, sums and products.  The integral
> below is definite and both Cos[] and Sin[] are +ve over the
> integration limits, so the area under the graph should also be Real
> and +ve.
>
> igral = Integrate[igrand, {theta, 0, Pi/2},
>    Assumptions -> {Rx \[Element] Reals, Rvt \[Element] Reals,
>        w \[Element] Reals, Dc \[Element] Reals, theta \[Element]  
> Reals,
>        Rx > 0, Rvt > 0, w > 0, Dc > 0, theta >= 0}]
>
> However the integral contains many complex terms which is
> understandable AIUI because Integrate[] tries many transforms/pattern
> matches to do the integration -- some of which will produce a complex
> result.  The thing that puzzles me is that the integration result
> contains lots of terms such as 'Sign[Rvt]^2'.  My point is that
> Integrate[] has been explicitly told in its Assumptions argument that
> Rvt in this case is Real and +ve, so why does it do this?  Is this a
> bug?  Admittedly a,
>
> Simplify[igral, {Rx \[Element] Reals, Rvt \[Element] Reals,
>    w \[Element] Reals, Dc \[Element] Reals, Rx > 0, Rvt > 0, w > 0,  
> Dc > 0}]
>
> will remove terms like 'Sign[Rvt]^2' but I still end up with a complex
> and unwieldy expression which is much larger that the integrand.
>
> Any suggestions?
>
> Many thanks
> Tom Crane
>
> Ps. I'm using Mathematica 4.0 and the From: field in the message  
> header is
> invalid.  It is just a spam-trap.
>
> -- 
> Tom Crane, Dept. Physics, Royal Holloway, University of London,  
> Egham Hill,
> Egham, Surrey, TW20 0EX, England.
> Email:  T.Crane at rhul dot ac dot uk
> Fax:    +44 (0) 1784 472794
>



  • Prev by Date: Re: Integrating "If"
  • Next by Date: Re: Mac OS X 10.5 Leopard - use as a server? YES
  • Previous by thread: Complex elimination and possible Integrate[] bug -- advice sought
  • Next by thread: Re: bug --