Re: Complex -> List does not work
- To: mathgroup@smc.vnet.net
- Subject: [mg10589] Re: [mg10495] Complex -> List does not work
- From: jpk@max.mpae.gwdg.de
- Date: Mon, 26 Jan 1998 04:42:22 -0500
> Hello! > > I naively tried the following way of turning a complex number into a > couple of real numbers: > > 2 + 3 I /. Complex -> List > > but it gives me back > > 2 + 3 I > > even though the full form of 2+3I is Complex[2,3]. The reverse however > is possible: > > {2,3}/.List->Complex gives 2+3I > > The help browser says that "you have to use Re and Im to extract parts > of Complex numbers". > > Why this exception to the basic principles of replacement rules? Simply becuse a complex number is a atom, like a real or integer. ReplaceAll[old,new] works by seraching the expression for new. A atomic expression has not really a Head[] -- like a nonatomic one. It is printed in that way but in fact the atom Complex[2,3] does not contain the symbol Complex. Try the same with 1 /. Integer -> List 1.2 /. Real -> List 2/3 /. Rational ->List a=.; a /. Symbol -> List if any of this works as You expect is impossible to represent the results by Mathematica or cause a infinite recursion Hope that helps Jens