MathGroup Archive 2006

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

Search the Archive

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


On Sep 14, 2006, at 6:55 AM, David Park wrote:

> 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.

I think this is a side effect of how different atoms are  
represented.  FullForm[9] is 9 but FullForm[9+I] is Complex[9,1], so  
the pattern Complex[a_,b_] will match a complex number but Integer 
[x_] will not match an integer.  I'm too lazy to search for atoms  
whose FullForm contains a pattern that I can match to, but that would  
be the strategy for finding 'in between' objects.

Incidentally though there's no fundamental difference between

2 + I 3 /. Complex[a_, b_] -> {a, b}

and

9/.x_->{x,x}

the head isn't actually changing in either case.

Regards,

Ssezi


  • Prev by Date: Re: Summing elements within a List or Array
  • Next by Date: Re: Summing elements within a List or Array
  • Previous by thread: RE: question on changing 'type' of numbers
  • Next by thread: Re: question on changing 'type' of numbers