4

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]
seismatica
  • 5,101
  • 1
  • 22
  • 33

1 Answers1

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

enter image description here

ciao
  • 25,774
  • 2
  • 58
  • 139
  • 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 '14 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. – ciao Jun 21 '14 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... – ciao Jun 21 '14 at 10:53