Because of a Mathematica bug (which still isn't fixed in the just
released version 6), my version 4.2 DumpSave files cannot be read by
my version 5.2. So as a result I'm trying to find a way to _exactly_
write out these numbers to a pure ascii text file from within 4.2,
then read them in as text and convert them back into number form
within 5.2 without losing any digits. Any idea's how I could
accomplish this simply?
Note that simply saving the approximate real numbers with Save[] and
retreiving them will not work in this case because Save[] 'distorts'
the numbers even if they are loaded back into the same version of
Mathematica (when it converts to base 10 and back).
Thanks in advance!
Regards,
Terry
and using the old binary package for binary import/export in 4.2
and usging BinaryImport[]/BinaryExport[] in the newer version
can't help ?
Regards
Jens
Hi Terry,
In addition, you could use BaseForm to convert the numbers in binary
form. A quick and dirty example follows (just to give you an overall
idea).
In[1]:=
expr={{1.234567987654*^6,-34.3892839,898890.7348327,-8.748328494823489*^8},{\
124567.98764,-8934.3892839,89890.7348327,-8.78907284948235*^9}}
Out[1]=
6 8
9
{{1.23457 10 , -34.3893, 898891., -8.74833 10 }, {124568., -8934.39,
89890.7, -8.78907 10 }}
In[2]:=
data = (StringReplace[#1, Characters["{ 2}"] -> ""] & ) /@
(ToString[BaseForm[NumberForm[#1, {20, 20}, NumberPadding -> {"0",
"0"}, SignPadding -> True,
ExponentFunction -> (Null & )], 2]] & ) /@ expr
Out[2]=
{0100101101011010000111.1111110011010110111001000111111,-100010.\
01100011101010000001110000010011010110111111111,011011011011101001010.\
101111000001110111111110111011101,-110100001001001110001111010001.\
011110110111101100111
,011110011010010111.1111110011010101111110011001110001,-10001011100110.\
01100011101010000001110000010011010111,010101111100100010.\
101111000001110111111110111011101001,-1000001011110111101001101111010001.\
01111011011110110100
}
HTH,
Jean-Marc
>
> --- Jean-Marc Gulliet <jeanmarc...@gmail.com>
> > ToString and NumberForm should be what you need
> > before Export. Knowing
> > nothing about the kind of numbers you are dealing
> > with and the data
> > structure, it is hard to tell more. You can check
> > the following thread
> > to see some examples of the above mentioned
> > functions in action.
> >
> >
> http://forums.wolfram.com/mathgroup/archive/2007/Apr/msg00523.html
> >
> > Regards,
> > Jean-Marc
> >
>
>
>
>
> ____________________________________________________________________________________
> Get your own web address.
> Have a HUGE year through Yahoo! Small Business.
> http://smallbusiness.yahoo.com/domains/?p=BESTDEAL
>
ToString and NumberForm should be what you need before Export. Knowing
Unfortuneately not:
From my 4.2 instance:
==============================================
In[13]:= a = targetFunction[[1]]
Out[13]= \!\(7.540873625469604946490279853`12.6348*^-897\)
In[14]:= Export["new_test", a, "Dump"]
Out[14]= new_test
From my 5.2 instance:
==============================================
In[14]:= a = Import["a:/new_test","Dump"];
In[15]:= a
Out[15]= \!
\(2.618456009313894180400204624`12.634760176636481*^-887\)
If you have both the old version and new version of Mathematica
installed on your system you can probably use MathLink to transfer the
exact expression from the old version of Mathematica to the new
version, then re-DumpSave it in the new version. Try something like
this in the *old* version, adjusting the LinkLaunch path to point to
the new version on your system.
data=Get["oldfile.mx"]
l=LinkLaunch["/Applications/Mathematica.app/Contents/MacOS/MathKernel -
mathlink"]
LinkRead[l]
LinkWrite[l,Unevaluated[
EvaluatePacket[DumpSave["newfile.mx", Evaluate[data]]]]]
LinkRead[l]
LinkClose[l]
-Rob
On 5/4/07, terry <terry...@yahoo.com> wrote:
> Dear Mathematica Guru's,
>
> Because of a Mathematica bug (which still isn't fixed in the just
> released version 6), my version 4.2 DumpSave files cannot be read by
> my version 5.2. So as a result I'm trying to find a way to _exactly_
> write out these numbers to a pure ascii text file from within 4.2,
> then read them in as text and convert them back into number form
> within 5.2 without losing any digits. Any idea's how I could
> accomplish this simply?
>
> Note that simply saving the approximate real numbers with Save[] and
> retreiving them will not work in this case because Save[] 'distorts'
> the numbers even if they are loaded back into the same version of
> Mathematica (when it converts to base 10 and back).
>
> Thanks in advance!
>
> Regards,
> Terry
>
>
>
Export[] is not the package I'd mean I mean the FadtBinary
package from MathSource
http://library.wolfram.com/infocenter/MathSource/354/
to write the data with 4.2 and than you can try to read the data
with Import[] in 5.2
Regards
Jens
Terry
P.S. Here's the code I used for testing:
x = True;
While[x,
targetFunction = 537932*Random[Real,{1,27}]^3;
targetFunction2 = targetFunction;
Save["temp",targetFunction2];
Clear[targetFunction2];
Get["temp"];
DeleteFile["temp"];
x = RealDigits[targetFunction2,2] == RealDigits[targetFunction, 2];
If[x == False,
Print[RealDigits[targetFunction,2]];
Print[RealDigits[targetFunction2,2]];
];
];