This is a continuation of this question regarding number formatting, and related to my earlier question about obtaining very specific Mathematica output to text files.
I frequently have to use high precision in Mathematica for data generation but only need relatively low precision for visualization purposes. I also want to store the data for later use with all Symbol names and Array structures intact. For this I have been using Save[]
, but there are two related problems.
The high precision "pollutes" my results with superfluous digits which are very hard to get rid of:
In[1] := b = SetPrecision[7, 50]; a = Pi/b Out[1] := 0.44879895051282760549466334046850041202816705705358654585356351318683091518373`50. In[2] := InputForm @ N[a, 6] Out[2] := 0.44879895051282760549466334046850041203`6.
where I really only need 0.448799.
- Sometimes even the number indicating precision is corrupted and I get values like
4.72642364528438598726943'5.9999999999999999999999
where I don't generally need the precision and4.72642
would suffice.
Both of these introduce significant overhead to the file size, and while hard disk storage is cheap, file size makes a huge difference when later loading the files back into Mathematica.
So, starting with, e.g., aa
that contains 50 digit arbitrary precision numbers in an irregular array, is there a built in way for me to get a text file that would read something like this
aa = {{2.0437`4, 4.7276`4, ...}, ...}
EDIT: To clarify, I am not having problems with the display of numbers or with tracking the precision of numbers or with changing the precision of numbers. What I am having trouble with is controlling how a number is written to a file.
Using N
, NumberForm
, OutputForm
, InputForm
, *Form
, etc, all do not work properly with Save
. And Save
is the only exporting option I can find that exports the symbol and array structure. Export
and Put*
can be used to control the formatting better but they don't include the symbol (and in the case of Export
the array structure is lost as well).
, 6]]] to get six digits printed in your file. Can use Save or Put depending on specifics of what you need.
– Daniel Lichtblau Feb 10 '11 at 20:14