MathGroup Archive 2008

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

Search the Archive

Re: bug --

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84547] Re: bug --
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Thu, 3 Jan 2008 20:25:06 -0500 (EST)
  • References: <200801031035.FAA15853@smc.vnet.net>

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?

I'm not sure and don't have a lot of time to experiment. I'll sidestep 
by showing how to determine whether z is always positive subject to the 
stated assumptions.

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);

Timing[inst = FindInstance[{z<0,rx>0,w>0,rvt>0,dc>0},
   {rx,w,rvt,dc}, Complexes]]

Out[49]= {48.663, {{rx -> 84, w -> 67, rvt -> 5, dc -> 54137}}}

Apparently it is not always positive. Let's check this result in fact 
makes z negative.

In[55]:= InputForm[N[z/.inst,25]]

Out[55]//InputForm=
{-1.168820703869009026079768871334810389758`25.15051499783199*^30 +
   0``-4.917232898024117*I}


> =============================================================================
> 
> (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.
> 

Version 6 will give a shorter result.

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);

InputForm[igral = Integrate[igrand, {theta,0,Pi/2},
     Assumptions -> {rx>0, rvt>0, w>0, dc>0}]]

Out[19]//InputForm=
(dc*(Pi*Sqrt[-2*dc + I*rx^2*w]*(16*Sqrt[2]*dc^3*rvt^5*(rvt^2 + rx^2)^(3/2)*
       w^2 - (24*I)*Sqrt[2]*dc^2*rvt^5*(rvt^2 + rx^2)^(5/2)*w^3 -
      12*Sqrt[2]*dc*rvt^5*(rvt^2 + rx^2)^(7/2)*w^4 +
      (2*I)*Sqrt[2]*rvt^5*(rvt^2 + rx^2)^(9/2)*w^5 +
      16*dc^(9/2)*rx^2*(4*rvt^2 + 3*rx^2)*Sqrt[2*dc + I*rx^2*w] +
      8*dc^(5/2)*(-4*rvt^8 + 15*rvt^4*rx^4 + 14*rvt^2*rx^6 + 3*rx^8)*w^2*
       Sqrt[2*dc + I*rx^2*w] + 3*(rvt^2 + rx^2)^4*(8*rvt^4 + 4*rvt^2*rx^2 +
        rx^4)*w^4*Sqrt[dc*(2*dc + I*rx^2*w)]) + 2*rvt^5*(rvt^2 + 
rx^2)^(3/2)*
     w^2*Sqrt[4*dc + (2*I)*rx^2*w]*(2*dc + I*(rvt^2 + rx^2)*w)^3*
     Log[-(1/Sqrt[-2 + (I*rx^2*w)/dc])] + rvt^5*(rvt^2 + rx^2)^(3/2)*w^2*
     Sqrt[4*dc + (2*I)*rx^2*w]*(2*dc + I*(rvt^2 + rx^2)*w)^3*
     Log[-2 + (I*rx^2*w)/dc]))/(16*rvt^5*(rvt^2 + rx^2)^(3/2)*
   Sqrt[dc*(-2*dc + I*rx^2*w)]*Sqrt[2*dc + I*rx^2*w]*
   (4*dc^2 + (rvt^2 + rx^2)^2*w^2)^3)

We'll check at a set of valid parameter values, and compare to a 
quadrature result at same.

In[20]:= igral /. {rx->3.2,rvt->1.8,w->.7,dc->2.1}

                                 -20
Out[20]= 0.00327507 - 5.05848 10    I

In[21]:= NIntegrate[igrand /. {rx->3.2,rvt->1.8,w->.7,dc->2.1},
   {theta,0,Pi/2}]

Out[21]= 0.00327507

So it passes a basic sanity test.

Daniel Lichtblau
Wolfram Research



  • Prev by Date: Re: Tensor Contraction
  • Next by Date: Re: bug -- advice sought
  • Previous by thread: Re: bug -- advice sought
  • Next by thread: Re: Re: bug --