MathGroup Archive 2011

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

Search the Archive

Is Put - Get cycle in Mathematica always deterministic?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg119874] Is Put - Get cycle in Mathematica always deterministic?
  • From: Alexey Popkov <lehin.p at gmail.com>
  • Date: Mon, 27 Jun 2011 07:31:50 -0400 (EDT)
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

In Mathematica as in other systems of computer math the numbers are internally stored in binary form. However when exporting them with such functions as Put and PutAppend they are converted into approximate decimals. When we import them back with such functions as Get they are restored backward from this approximate decimal representation to binary form. The question is: whether the recovered number is always identical to the original binary number and, if not always, in which cases it is not and how great can be the difference? I am particularly interested in the Put - Get cycle (on the same computer system).

I am aware of DumpSave which is guaranteed to restore original definitions exactly but I am interested in exporting expressions in human-readable format. I am quite satisfied with the default ASCII-based representation created by Put and PutAppend.

The following two simple experiments show that probably the Put - Get cycle in Mathematica always restores original numbers exactly both for machine precision and for arbitrary precision numbers. I rely in these experiments on the Order function for expression comparison instead of SameQ because the latter "still considers Real numbers equal if they differ in their last binary digit" while the former returns 0 only if the expressions are exactly the same.

In[1]:= list=RandomReal[{-10^6,10^6},10000];
Put[list,"test.txt"];
list2=Get["test.txt"];
Order[list,list2]===0
Order[Total@Abs[list-list2],0.]===0

Out[4]= True
Out[5]= True


In[6]:= list=SetPrecision[RandomReal[{-10^6,10^6},10000],50];
Put[list,"test.txt"];
list2=Get["test.txt"];
Order[list,list2]===0
Total@Abs[list-list2]//InputForm

Out[9]= True
Out[10]//InputForm=
0``39.999515496936205

It seems the the Put - Get cycle always restores the original numbers exactly. But may be I am missing something?


  • Prev by Date: error FrontEndObject
  • Next by Date: Re: Assigning part of indexed object
  • Previous by thread: error FrontEndObject
  • Next by thread: C code generation