       Ordering of output question

• To: mathgroup at smc.vnet.net
• Subject: [mg28226] Ordering of output question
• From: johntodd at fake.com (John Todd)
• Date: Thu, 5 Apr 2001 03:00:40 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```Hello,
I'm trying to get the output of the following to be in
standard complex number form, i.e. a + ib:

Clear[x, y, z];
Clear[fCZ, fCXY];
x /: Im[x] = 0;
x /: Re[x] = x;
y /: Im[y] = 0;
y /: Re[y] = y;
fCZ[z_] := \[ImaginaryI] z + \[ImaginaryI];
fCXY = ComplexExpand[f[x + \[ImaginaryI] y]];
Print["f(z) = ", f[z]];
Print["Let z = x + \[ImaginaryI]y"];

(* The following line is where my question pertains*)
Print["f(x + \[ImaginaryI]y) = ", fCXY, " = ", Re[fCXY],
" + \[ImaginaryI]"Im[fCXY], "."];

Print["The real part of f(z) = ", fCZ[z], " is ", Re[fCXY],
" and the imaginary part is ", Im[fCXY], "."];

If you evaluate the above, you'll find that the line directly
below the commented line has its final outpu as -y + i(x + 1) which is
what I want.  However, my means of getting it to look that way seem a
bit inelegant,, and I feel certain there is a better way.  I do
realize that looking at the expression with TreeForm[], I can extract
whatever I want out of an expression, but that also seems inelegant.
What I feel must be possible is to set up some sort of a pattern or
transformation rule which will say in effect, "Place the output in
this form, i.e. a + ib, regardless of what a and b are".  I ask this
question not only for the specific example given but also in a broader
sense because I will and have wanted to display expressions in a
certain format, but have always had to resort to the kinds of
Before submitting my question I perused the sections on Patterns
and the section on Transformation Rules in Wolfram's 4th edition Mathematica
book.  If I missed a glaring answer to my question, I apologize.

Thanks again,

JT

```

• Prev by Date: RE: complex coefficients and rules...
• Next by Date: RE: Polar Grids in Mathematica