Is Put - Get cycle in Mathematica always deterministic?
- To: mathgroup at smc.vnet.net
- Subject: [mg119977] Is Put - Get cycle in Mathematica always deterministic?
- From: Alexey Popkov <lehin.p at gmail.com>
- Date: Sun, 3 Jul 2011 04:10:40 -0400 (EDT)
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 restored numbers are identical to the exported numbers in all binary RealDigits but their Precisions may differ even in Equal sense. test := (Put[list, "test.txt"]; list2 = Get["test.txt"]; {Order[list, list2] === 0, Order[Total@Abs[list - list2], 0.] === 0, Total[Order @@@ RealDigits[Transpose[{list, list2}], 2]], Total[Order @@@ Map[Precision, Transpose[{list, list2}], {-1}]], Total[1 - Boole[Equal @@@ Map[Precision, Transpose[{list, list2}], {-1}]]]}) In[8]:= list=RandomReal[NormalDistribution[],10000]^1001; test Out[9]= {False,True,0,1,3} In[6]:= list=RandomReal[NormalDistribution[],10000,WorkingPrecision->50]^1001; test Out[7]= {False,False,0,-2174,1} It seems the the Put - Get cycle always restores the original numbers exactly and only Precision may be little different. But may be I am missing something?