Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to compare between Sqrt[3.] and Sqrt[3]. To display the result, I mapped HoldForm to display the expressions on the left hand column (code at end), but it seems like Sqrt[3.] had been evaluated before it was mapped on to. Is there any way to stop that to happen?

Mapping HoldForm

Grid[Prepend[{HoldForm[#], Precision[#], 
     MachineNumberQ[#]} & /@ {Sqrt[3.], Sqrt[3]}, {"Number", 
   "Precision[]", "MachineNumberQ[]"}],
 Frame -> All]
share|improve this question

1 Answer 1

up vote 4 down vote accepted
Grid[Prepend[{HoldForm[#], Precision[#], 
     MachineNumberQ[#]} & /@ {Unevaluated@Sqrt[3.], 
    Sqrt[3]}, {"Number", "Precision[]", "MachineNumberQ[]"}], 
 Frame -> All]

enter image description here

share|improve this answer
    
Thank you so much for your help rasher. If you're able to, could you help me explain why HoldForm@Unevaluated@Sqrt[3.] would return Unevaluated[Sqrt[3.]] instead of just Sqrt[3.]? It seems that if a method works directly, it may not work using Map and vice versa. –  seismatica Jun 21 at 10:28
    
@seismatica: That's because Sqrt[3] evaluated is displayed as Sqrt[3] - its value. Try replacing it with Sqrt[4] with and without the Unevaluated - I'm sure the lightbulb will come on, if not comment back. edit: hang on - I may have misread your comment question... if so, I'll delete this comment reply. - In any case, look at details in the docs for Map - note that it constructs/evaluates the expressions. –  rasher Jun 21 at 10:45
    
@seismatica: If my comment reply didn't get it for you, I'll give it another shot later if no one else replies - it's nearly 04:00 here, gotta hit the hay... –  rasher Jun 21 at 10:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.