Message Boards Message Boards

1
|
4848 Views
|
2 Replies
|
6 Total Likes
View groups...
Share
Share this post:

[?] Evaluate this constant expression?

Posted 6 years ago

Is this a bug or a feature? I can't figure out how to get Mathematica to evaluate this constant expression, Out[16]. If I apply N[ ] to it, it stays the same (Out[17]). Strangely, though, if I paste the same expression manually into a new line, In[18], it evaluates fine. Why? (I'm using Mathematica 10.3.1 for Linux x86.)

In[16]:= wHexToDec["3FFBB67AE8584CAA"]        

Out[16]= + 2^(0) + 2^(-1) + 2^(-3) + 2^(-4) + 2^(-5) + 2^(-7) + 2^(-8) +\
     >    2^(-10) + 2^(-11) + 2^(-14) + 2^(-15) + 2^(-16) + 2^(-17) + 2^(-19) +\
     >    2^(-21) + 2^(-22) + 2^(-23) + 2^(-25) + 2^(-30) + 2^(-32) + 2^(-33) +\
     >    2^(-38) + 2^(-41) + 2^(-42) + 2^(-45) + 2^(-47) + 2^(-49) + 2^(-51)

In[17]:= N[In[16]]                                                              

Out[17]= + 2^(0) + 2^(-1) + 2^(-3) + 2^(-4) + 2^(-5) + 2^(-7) + 2^(-8) +\
     >    2^(-10) + 2^(-11) + 2^(-14) + 2^(-15) + 2^(-16) + 2^(-17) + 2^(-19) +\
     >    2^(-21) + 2^(-22) + 2^(-23) + 2^(-25) + 2^(-30) + 2^(-32) + 2^(-33) +\
     >    2^(-38) + 2^(-41) + 2^(-42) + 2^(-45) + 2^(-47) + 2^(-49) + 2^(-51)

In[18]:= + 2^(0) + 2^(-1) + 2^(-3) + 2^(-4) + 2^(-5) + 2^(-7) + 2^(-8) +\       
         2^(-10) + 2^(-11) + 2^(-14) + 2^(-15) + 2^(-16) + 2^(-17) + 2^(-19) +\ 
         2^(-21) + 2^(-22) + 2^(-23) + 2^(-25) + 2^(-30) + 2^(-32) + 2^(-33) +\ 
         2^(-38) + 2^(-41) + 2^(-42) + 2^(-45) + 2^(-47) + 2^(-49) + 2^(-51)    

         3900231685776981
Out[18]= ----------------
         2251799813685248

In[19]:= N[Out[18]]                                                             

Out[19]= 1.73205

screenshot

POSTED BY: Robert Enenkel
2 Replies
Posted 6 years ago

Thanks, Ilian. You hit the nail on the head!

n[23]:= FullForm[wHexToDec["3FFBB67AE8584CAA"]]                                

Out[23]//FullForm= "+ 2^(0) + 2^(-1) + 2^(-3) + 2^(-4) + 2^(-5) + 2^(-7) +\
 >    2^(-8) + 2^(-10) + 2^(-11) + 2^(-14) + 2^(-15) + 2^(-16) + 2^(-17) +\
 >    2^(-19) + 2^(-21) + 2^(-22) + 2^(-23) + 2^(-25) + 2^(-30) + 2^(-32) +\
 >    2^(-33) + 2^(-38) + 2^(-41) + 2^(-42) + 2^(-45) + 2^(-47) + 2^(-49) +\
 >    2^(-51)"

If I apply ToExpression[ ] to it, I get what I wanted...

In[24]:= ToExpression[wHexToDec["3FFBB67AE8584CAA"]]                            

         3900231685776981
Out[24]= ----------------
         2251799813685248

Problem solved, thanks again!

POSTED BY: Robert Enenkel

Take a look at FullForm[wHexToDec[...]].

I wouldn't be surprised if it is, say a string, and of course N will leave strings unchanged.

POSTED BY: Ilian Gachevski
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract