Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2013

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

Search the Archive

Re: How to remove the "0." from "0. + 1.41774i"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg131272] Re: How to remove the "0." from "0. + 1.41774i"
  • From: Christoph Lhotka <christoph.lhotka at univie.ac.at>
  • Date: Sat, 22 Jun 2013 20:46:48 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <20130620084452.627F569EF@smc.vnet.net> <58732FA6-FDFE-4100-8637-926219C678F6@gmail.com> <CAJxy_SqurCkArZaLNQDN+35u3YT8XjAL7g7wsL9cvnSOV9MLKg@mail.gmail.com> <kq17bv$goc$1@smc.vnet.net> <20130622073348.7FA386A20@smc.vnet.net> <51C5C551.30109@univie.ac.at> <51C60767.4000404@eecs.berkeley.edu>

Hello,

On 06/22/2013 10:21 PM, Richard Fateman wrote:
> On 6/22/2013 8:40 AM, Christoph Lhotka wrote:
>> Dear mathgroup,
>>
>>   there is indeed a very elegant solution to these kind of problems. 
>> It took
>> me some while (looking up the documentation center) but I think this 
>> works fine:
> Well, there are lots of little problems with this solution, some of 
> which have to do
> with the semantics of N, so that 1/2+2I  looks like floats, and 
> 2^5000+2I looks like
> 1.4124...x10^1505 + 0. I.   with a red box around the 0.
>

of course my definition of format did not take your cases into account (it was meant to work on realistic approximate complex numbers), but for sure you can modify the definition to satisfy your needs.

> but also there is an issue that FullForm[%] is peculiar.
>

FullForm works as expected, also pattern matching works (in terms of the
interpreted expression).

> So the idea of changing the display format in $Post processing is a 
> possibility,
> it rapidly becomes less elegant if you expect it to cover every 
> eventuality, and
> probably not possible if you want FullForm to work.
> RJF
>

I think, that you did not see the main point. It is not the definition of format it is the mechanism that allows to implement any output format in terms of interpreted expressions.

Here I merge your approach of a previous post with mine to work in a more
elegant way:

In[1]:= format[c_Complex]:=
Interpretation[
Re[c]+i Im[c],c]

In[2]:= $Post=#/.c_Complex:>format[c]&
Out[2]= #1/. c_Complex:>format[c]&

In[3]:= c1=1/2+2I
Out[3]= 1/2+2 i

In[4]:= c1^2
Out[4]= -(15/4)+2 i

In[5]:= c1=2^5000+2I;

In[6]:= Im[c1]
Out[6]= 2

In[7]:= FullForm[0.+1.i]
Out[7]//FullForm= Plus[0.`,Times[1.`,i]]

In[8]:= c1/.c_Complex:>Im[c]
Out[8]= 2

In[9]:= Clear[$Post]

I like this!




  • Prev by Date: vertices of a rectangle
  • Next by Date: Re: labeling clustered data
  • Previous by thread: Re: How to remove the "0." from "0. + 1.41774i"
  • Next by thread: Re: How to remove the "0." from "0. + 1.41774i"