MathGroup Archive 1999

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

Search the Archive

Re: Complex Head

  • To: mathgroup at smc.vnet.net
  • Subject: [mg17638] Re: [mg17614] Complex Head
  • From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
  • Date: Fri, 21 May 1999 03:37:32 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

I am sure that this is basically right. Let me point out that one can easily
modify  the behaviour of Mathematica to make it recognize complex numeric
quantities at once. For example, consider the following test list:

In[1]:=
testlist={2,3+Sqrt[2]*I,E+Pi*I,a+b*I,2+3*I};

Normally Mathematica will give:

In[2]:=
Cases[testlist,_Complex]

Out[2]=
{2+3 I}

One can add new rules concerning the way Mathematica treats numeric
quantities in such cases:
Here is one way:

In[3]:=
Unprotect[Plus];
Plus[a_,b_*I]:=Complex[a,b]/;And[NumericQ[a],NumericQ[b],Im[a]==0,Im[b]==0];
Protect[Plus];

(To make this behave  nicely one actually needs to add rules concerning
products, powers etc for the new extended head Complex, but as I am only
trying to illustrate a point I shall not bother to do so)

Now we get:

In[4]:=
Cases[testlist,_Complex]
Out[4]=
{Complex[3, Sqrt[2]], Complex[E, Pi], 2 + 3 I}

Numerically this is still the same as before making the changes:

In[5]:=
N[%]
Out[5]=
{3. + 1.41421 I, 2.71828 + 3.14159 I, 2. + 3. I}

However, one must ask onself would would be the price of having this
behaviour built in. As pointed out by Jack Goldberg, Mathematica would have
to embark on possibly very difficult or even impossible computations every
time it acquired numeric quantities in complex expressions. It's much better
to leave such determinations to the situations when they are needed,even at
the price of the resulting "strangeness".


--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp


----------
>From: Jack Goldberg <jackgold at math.lsa.umich.edu>
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>Subject: [mg17638] [mg17614] Complex Head
>Date: Tue, May 18, 1999, 3:45 PM
>

>
> Hi Group:
>
> See mg[7605], mg[7548] and mg[7592].  The issue here is
> why does the following occur:
>
> Head[Sqrt[2]*I] -> Times
>
> while
>
> Head[2*I] -> Complex
>
> At the risk of being shot down and stripped of my medals
> from Mathematica, I offer this explanation.
>
> The answer seems to depend on how far Mathematica goes in determining the
> properties of  x  in an expression like  x*I.  For example,  Mathematica
> will simplify automatically  x = Exp[Pi*I]  to -1  and thus
>
> Head[x*I] -> Complex
>
> But the kernel will not take the time to decide that Sqrt[2] is real.
> Moreover, since  x  could be quite complicated, say some value of the
> Bessel function, it is probably impossible to decide on the correct value
> of "Head" for every Mathematica-ly sound numerical choice of x.
> Indeed, it may be that  x  has a value for which no known algorithm
> determines whether it is real or complex!  Add to this the requirement
> that Head[...] must always return something, we have an answer to
> Mittermayr's question.
>
> Jack
>
>
>
> 


  • Prev by Date: hypersurface in 3D
  • Next by Date: How invert x-axis in a plot?
  • Previous by thread: Complex Head
  • Next by thread: Looking for Partner who has access to mathematica and Time Series