Re: Union[{0},{0.}] = {0,0.}?
- To: mathgroup at smc.vnet.net
- Subject: [mg12719] Re: [mg12662] Union[{0},{0.}] = {0,0.}?
- From: "Tomas Gargz" <tgarza at mail.internet.com.mx>
- Date: Wed, 3 Jun 1998 02:21:08 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Chris Farr wrote: >Union[{0},{0.}] ÿ0,0.}. >Why? >I would like the above to return only {0}. >The root of the problem is that Mathematica thinks they are the same: >SameQ[{0},{0.}] ÿalse >How can I get around this? The following doesn't help either. >Union[{ N[0] },{0.}] ÿ0,0.} >Any ides out there? Chris: For one thing, 0 and 0. are distinct elements, so Mathematica is giving ÿhe right answer. In[1]:ÿead[0] Out[1]ÿnteger In[2]:ÿead[0.] Out[2]ÿeal Now. N[0] will not give 0. as you might like it to. It produces a real, ÿowever, for any nonzero number. You could get round the problem by ÿransforming every real 0. to an integer 0 in the list you are operating ÿpon with Union (or viceversa). If your list is b, say, In[3]:ûÿ0},{0.}}; then In[4]:ÿ Union[b/.{x_}->If[xð.,ToExpression[StringTake[ToString[0.], 1]]]] Out[4]ÿ0} I hope I did understand your problem. Tomas Garza Mexico City