1

I just have discovered the fundamental difference between two input forms for floating-point numbers:

In[8]:= 1.5*^-334355//Hold//FullForm
1.5*10^-334355//Hold//FullForm
Out[8]//FullForm= Hold[1.5000000000000000000000000000000001`15.954589770191005*^-334355]
Out[9]//FullForm= Hold[Times[1.5`,Power[10,-334355]]]

These two forms differ very much in memory and time consumption:

In[7]:= start = MaxMemoryUsed[];
1.5*^-33432242 // Timing
start = MaxMemoryUsed[] - start
1.5*10^-33432242 // Timing
MaxMemoryUsed[] - start

Out[8]= {1.67401*10^-16, 1.500000000000000*10^-33432242}

Out[9]= 0

Out[10]= {7.741, 1.500000000000000*10^-33432242}

Out[11]= 34274192

But I cannot find out where the form *^ is documented. Is it a real basic input form for floating-point numbers? How is about numbers in other bases?

And why the second form is so much expensive?

Alexey Popkov
  • 9,355
  • 4
  • 42
  • 93

1 Answers1

4

Regarding the time and memory consumption - these are the consequences of evaluation, have nothing to do with different forms. You use integer arithmetic for the power of 10 when 10 is present explicitly, thus the time/memory inefficiency. When we use machine precision from the start, the effect disappears:

In[1]:= MaxMemoryUsed[]
1.5*^-33432242 // Timing
MaxMemoryUsed[]
1.5*10.^-33432242 // Timing
MaxMemoryUsed[]

Out[1]= 17417696

Out[2]= {0., 1.500000000000000*10^-33432242}

Out[3]= 17417696

Out[4]= {0., 1.500000000043239*10^-33432242}

Out[5]= 17417696

HTH

Leonid Shifrin
  • 22,449
  • 4
  • 68
  • 100
  • I understand but `1.5*10.^-33432242` is not equivalent to `1.5*^-33432242`. I'm wondering why such an important thing as the `*^` form is not emphasized in the documentation? – Alexey Popkov Feb 09 '11 at 00:28
  • 1
    Well, I agree, but docs can not be perfect. Why aren't the two numbers equivalent? Both are machine precision, and since both are way smaller than `$MinMachineNumber`, I don't think that the actual values displayed make much sense - from the computational viewpoint, I think they are equivalent, and we could as well replace both by zero. – Leonid Shifrin Feb 09 '11 at 00:36