Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

complex numbers

8 views
Skip to first unread message

Jon Joseph

unread,
Dec 24, 2009, 12:19:52 AM12/24/09
to
All: Something fundamental about complex number initialization I am
failing to understand. I wish to define a complex number

z=x+ I y where x and y are both reals. Can someone tell me the
proper way to tell Mathematica that x, y are real so that Re[z] returns
x and Im[z] returns y? Much appreciated, Jon.

Murray Eisenberg

unread,
Dec 24, 2009, 9:10:34 PM12/24/09
to
Such questions have been addressed many times before in this group.

You DON'T tell Mathematica in advance that x and y are to be real.
Rather, when you want them to be interpreted as such, use ComplexExpand.
Thus:

z
ComplexExpand[Re[z]]
x
ComplexExpand[Abs[z]]
Sqrt[x^2 + y^2]

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

Bob Hanlon

unread,
Dec 24, 2009, 9:10:45 PM12/24/09
to

Presumably, because

Abs[x + I*y] // LeafCount

8

Sqrt[x^2 + y^2] // LeafCount

11


Bob Hanlon

---- Jon Joseph <josc...@gmail.com> wrote:

=============
Thanks Bob. One question on you solutions: Since you declare both x and y to be real in the following


Assuming[{Element[{x, y}, Reals]},
#[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}]


Why doesn't Abs[z] expand to Sqrt[x^2+y^2] the same way it does in ComplexExpand?

Jon

On Dec 24, 2009, at 7:24 AM, Bob Hanlon wrote:

>
> Clear[x, y, z];
> z = x + I*y;
>
> {Re[z], Im[z], Abs[z]}
>
> {Re[x] - Im[y], Im[x] + Re[y], Abs[x + I*y]}
>
> Use assumptions to target specific variables as Real
>
> Assuming[{Element[{x, y}, Reals]},
> #[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}]
>
> {{x, y, Abs[x + I*y]}, {x, y, Abs[x + I*y]}}
>
> Assuming[{Element[{x, y}, Reals]},
> #[{Re[z], Im[z], Abs[z]}] & /@ {Simplify, FullSimplify}]
>
> {{x, y, Abs[x + I*y]}, {x, y, Abs[x + I*y]}}
>
> If appropriate (i.e., all variables are Real), use ComplexExpand
>
> {Re[z], Im[z], Abs[z]} // ComplexExpand
>
> {x, y, Sqrt[x^2 + y^2]}
>
> Use TagSet for x and y
>
> x /: Im[x] = 0;
> x /: Re[x] = x;
> y /: Im[y] = 0;
> y /: Re[y] = y;
>
> {Re[z], Im[z], Abs[z]}
>
> {x, y, Abs[x + I*y]}
>
>
> Bob Hanlon
>
> ---- Jon Joseph <josc...@gmail.com> wrote:
>
> =============

Bob Hanlon

unread,
Dec 24, 2009, 9:10:55 PM12/24/09
to

David Park

unread,
Dec 24, 2009, 9:11:06 PM12/24/09
to
z = x + I y
ComplexExpand[{Re[z], Im[z]}]

x + I y
{x, y}

Mathematica assumes that all variables represent complex numbers.
ComplexExpand assumes all variables are real - unless you specify some are
complex.

Clear[z]
ComplexExpand[{Re[z], Im[z]}]

{z, 0}

ComplexExpand is practically the indispensible routine when working with
complex numbers. It seems to be overlooked by beginners. No wonder. If one
goes to Help and finds tutorial/ComplexNumbers, there is no mention of
ComplexExpand. But guide/ComplexNumbers does list it half way down the page.
Also, it ought to be mentioned in More Information on the Complex Help page.
It is listed in the See Also section, but I could not find it used anywhere
in the examples. It is used in examples on the Re Help page, but not
mentioned in More Information. Considering how many postings there are for
which ComplexExpand is the answer, it would be really nice if WRI would give
it more prominent mention.


David Park
djm...@comcast.net
http://home.comcast.net/~djmpark/

Leonid Shifrin

unread,
Dec 24, 2009, 9:11:17 PM12/24/09
to
Hi Jon,

This is perhaps the simplest:

In[1]:= ClearAll[x, y];


z = x + I*y;

ComplexExpand /@ {Re[z], Im[z]}

Out[2]= {x, y}

You can also do this:

In[3]:=
Simplify[Re[z], Assumptions -> {Element[{x, y}, Reals]}]

Out[3]= x

In[4]:= Simplify[Im[z], Assumptions -> {Element[{x, y}, Reals]}]

Out[4]= y

Alternatively, you may use Algebra`ReIm` (it is now obsolete however):

In[5]:=
<< Algebra`ReIm`;


x /: Im[x] = 0;
x /: Re[x] = x;
y /: Im[y] = 0;
y /: Re[y] = y;

During evaluation of In[5]:= General::obspkg: Algebra`ReIm` is now obsolete.
The legacy version being loaded may conflict with current Mathematica
functionality. See the Compatibility Guide for updating information. >>

In[10]:= {Re[z], Im[z]}

Out[10]= {x, y}

Note that the latter method assigns the properies to symbols x,y globally,
the previous ones
work under local assumption of x,y being real.

Regards,
Leonid

AES

unread,
Dec 26, 2009, 7:10:53 PM12/26/09
to
In article <hh16vq$4n4$1...@smc.vnet.net>,
"David Park" <djm...@comcast.net> wrote:

> ComplexExpand is practically the indispensible routine when working with
> complex numbers. It seems to be overlooked by beginners. No wonder. If one
> goes to Help and finds tutorial/ComplexNumbers, there is no mention of
> ComplexExpand. But guide/ComplexNumbers does list it half way down the page.
> Also, it ought to be mentioned in More Information on the Complex Help page.
> It is listed in the See Also section, but I could not find it used anywhere
> in the examples. It is used in examples on the Re Help page, but not
> mentioned in More Information. Considering how many postings there are for
> which ComplexExpand is the answer, it would be really nice if WRI would give
> it more prominent mention.

I enthusiastically second this statement.

There are a very large number of other situations in Mathematica as well
where adding to the Help files and other documentation just a few
carefully selected helpful comments, notes or pointers regarding common
problems and potential misunderstandings would be immensely valuable.

Given the immense sophistication, power, and wide-ranging usefulness of
Mathematica, Wolfram's continued obtuseness on this point is really sad.

0 new messages