       Re: declaring variables

• To: mathgroup at smc.vnet.net
• Subject: [mg4800] Re: declaring variables
• From: danl (Daniel Lichtblau)
• Date: Mon, 16 Sep 1996 23:51:24 -0400
• Organization: Wolfram Research, Inc.
• Sender: owner-wri-mathgroup at wolfram.com

```> Burkhardt Goedde wrote:
> >
> > Dear math users,
> > just a simple problem, but I got no answer from thew book.
> >
> > Re[x + I y] gives
> >
> > Re[x + I y]
> >
> > whereas
> >
> > Re[2 + 3 I]
> >
> > gives 2
> >
> > How could I tell Mathematica that x and y are real numbers?
> >

I think this is in some FAQ file. Where it lives I do not know. Anyway,
I've seen a response posted that uses ComplexExpand

In:= ComplexExpand[Re[x + I y]]
Out= x

and also a method that uses the standard package Algebra`ReIm`. I think
the former method is to be preferred. let me explain why. First, we really
do not maintain Algebra`ReIm` any more. If it works, fine. If not, we may
look into bug reports but we will not look very hard.

Second, it tends to be much slower on problems of any difficulty.

In:= Timing[ComplexExpand[Re[(x-I*y)^3/(Exp[x]*(x^3-x*y+y^2)^2)]]] //
InputForm
Out//InputForm=
{0.15626*Second, x^3/(E^x*(x^3 - x*y + y^2)^2) -
(3*x*y^2)/(E^x*(x^3 - x*y + y^2)^2)}

vs. (different session)

In:= Needs["Algebra`ReIm`"]

In:= Im[x]^=0;

In:= Im[y]^=0;

In:= Re[x + I y]
Out= x

In:= Timing[Re[(x-I*y)^3/(Exp[x]*(x^3-x*y+y^2)^2)]] // InputForm
Out//InputForm=
{12.41520599999999*Second, (-2*x*y^2 + x*(x^2 - y^2))/
(E^x*(x^3 - x*y + y^2)^2)}

Third, Algebra`ReIm` is not as powerful as ComplexExpand. For example,

In:= ComplexExpand[Log[Exp[x]]]
Out= x

In:= ComplexExpand[Sign[x^2+1]]
Out= 1

vs (in session with Algebra`ReIm` loaded and Im[x]^=0)

In:= Log[Exp[x]]
x
Out= Log[E ]

In:= Sign[x^2+1]
2
Out= Sign[1 + x ]

Fourth, I've seen at least one bug report to the effect that Algebra`ReIm`
Algebra`ReIm` caused a seemingly benign ComplexExpand invocation to go
into infinite recursion.

Finally, my opinion (not necessarily shared by others) is that global
assumptions are dangerous. Once we make declarations about variables e.g.
x^=0, these may be used elsewhere, or not, depending on what code is
invoked. Worse still, we may forget we made the assumptions and have later
code perform "simplifications" we do not want. ComplexExpand localizes
assumptions, regarding which variables are real, to its arguments. Once it
returns the assumptions are no longer valid.

Daniel Lichtblau
Wolfram Research, Inc.
danl at wolfram.com

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: Re: Unable to load kernel
• Next by Date: r^2 for non linear fits
• Previous by thread: Re: declaring variables
• Next by thread: batch mathematica under win95