Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: RE: question on changing 'type' of numbers

  • To: mathgroup at smc.vnet.net
  • Subject: [mg69534] Re: [mg69495] RE: [mg69473] question on changing 'type' of numbers
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Fri, 15 Sep 2006 06:44:41 -0400 (EDT)

On 14 Sep 2006, at 19:55, David Park wrote:

> Nasser,
>
> You can't change the Head of anything that gives True to AtomQ. You  
> cannot
> access the stored data of an atom and in most cases this is for  
> good reason.
>
> However, there seem to be cases where this is only partly true. For  
> example
> with complex numbers...
>
> AtomQ[2 + 3 I]
> True
>
> We can't change the Head
>
> Head[List @@ (2 + 3 I)]
> Complex
>
> but we can certainly access the parts
>
> 2 + I 3 /. Complex[a_, b_] -> {a, b}
> {2, 3}
>
> Maybe others will point out other 'in between' objects.
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/


I would not actually call them "in between" objects. Many, or perhaps  
most, atoms have special functions for accessing "parts" of them, in  
particular:


AtomQ[z=Complex[2,3]]


True


{Re[#],Im[#]}&[z]


{2,3}


AtomQ[r=Rational[2,3]]


True


{Denominator[#],Numerator[#]}&[r]


{3,2}


AtomQ[str="my dog"]

True


StringTake[str,1]

m


This is also an atom:


AtomQ[s=SparseArray[IdentityMatrix[5]]]


True

Unlike with other atoms you can use Part on it, but it does not give  
what you might expect:


Last[s]//InputForm


SparseArray[Automatic, {5}, 0, {1, {{0, 1}, {{5}}}, {1}}]


To get the "last part" in the usual (non-atomic) sense you have to  
use something like:


s/.SparseArray[a_,b_,c_,d_]->d//InputForm


{1, {{0, 1, 2, 3, 4, 5}, {{1}, {2}, {3}, {4}, {5}}},
{1, 1, 1, 1, 1}}


Andrzej Kozlowski




  • Prev by Date: Re: Animation crash
  • Next by Date: RE: partials of Sum[x[i]^2, {i,1,n}] (e.g.)
  • Previous by thread: Re: question on changing 'type' of numbers
  • Next by thread: oscillatory integrals