Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3352

Is Put - Get cycle in Mathematica always deterministic?

From Alexey Popkov <lehin.p@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Is Put - Get cycle in Mathematica always deterministic?
Date 2011-06-29 21:28 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <iug5dd$9e4$1@smc.vnet.net> (permalink)

Show all headers | View raw


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?

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Is Put - Get cycle in Mathematica always deterministic? Alexey Popkov <lehin.p@gmail.com> - 2011-06-29 21:28 +0000

csiph-web