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

*To*: mathgroup at smc.vnet.net*Subject*: [mg131268] 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:45:28 -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>

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: Step 1: define your notation (here on the output format of complex numbers): In[1]:= format[c_Complex] := Interpretation[ Which[ Re[c] == 0 && Im[c] == 0, "0", Re[c] == 0 && Im[c] != 0, ToString[Im[c] // N] <> "\[ImaginaryI]", Re[c] != 0 && Im[c] == 0, ToString[Re[c] // N], True, ToString[c // N, StandardForm]], c] Step 2: Tell Mathematica to apply this functions to any output expression In[2]:= $Post = # /. c_Complex :> format[c] & Out[2]= #1 /. c_Complex :> format[c] & Step 3: Work as usual, you will always see the format you defined in Step 1.... In[4]:= x = {0. + I, 0 + 1. I, 1 + 0. I, 1. + 2. I} Out[4]= {1.I,1.I,1.,1. +2. I} ...but you will always be able to continue your calculations independent of the format you may define: In[5]:= Total[x] Out[5]= Complex[2., 4.] Step 4: clear $Post to return to normal Mathematica behaviour: In[6]:= Clear[$Post] Hope, that helps, Christoph PS: Here is a nice joke you can implement in your friends Mathematica version: In[1]:= format[c_Complex]:= Interpretation[ Im[c]+Re[c]I,c] In[2]:= $Post=#/.c_Complex:>format[c]& Out[2]= #1/. c_Complex:>format[c]& In[3]:= x={0.+I,0+1.I,1+0.I,1.+2.I} Out[3]= {1. +0. I,1. +0. I,0. +1. I,2. +1. I} In[4]:= y=Total[x] Out[4]= 4. +2. I Do not forget to release him! With In[5]:= Clear[$Post] In[6]:= x Out[6]= {0. +1. I,0. +1. I,1. +0. I,1. +2. I} In[7]:= y Out[7]= 2. +4. I ...everything turns out to be fine ;o) On 06/22/2013 09:33 AM, Richard Fateman wrote: > 1. Mathematica 7.0 performs differently. > > 4.0*I looks like 4.I > > Mathematica 9. does this.. > 4.0*I looks like > 0.+4.I > > 2. If you want to do something different, consider something > like this: > > f[x_Complex]: If [VerySmall[Re[x]], Im[x]*i, Re[x]+Im[x]*i] > > where VerySmall is defined as you wish. Could be VerySmall(x_]:=x==0.0 > for example. > > Note that the answers are no longer complex numbers because they involve > the symbol i not I. > > You can do %/. i->I > but then you will see 0.+4.I again. > > RJF > > > > >

**References**:**How to remove the "0." from "0. + 1.41774i"***From:*Mike Bayville <mike.bayville@gmail.com>

**Re: How to remove the "0." from "0. + 1.41774i"***From:*Richard Fateman <fateman@cs.berkeley.edu>