I am dealing with a program with Mathematica where I compute expressions that take a very long time to compute. I need these results for further computation and/or display. I would like not to have to redo all the computations all the time, so save the results in files that can be imported again, without computation. But I need Mathematica to be able to read the expressions as mathematical expressions again, not just as text files.

For example, if I export the expression GR*Gl into a file on my hard drive, and I import it later in another program and assign it the name GA, I want that, if I assign further GR = 2 and Gl = 3, GA to be equal to 2*3 = 6. In other words, I want to be able to use it for further mathematical computation, as I would do directly in the original program.

Which commands should I use for that? I am not finding how to do this very simple thing.


I believe you want to save your expression as a text file, read the text file back in as a string, then convert the string to an expression using ToExpression[], as below. Is ToExpression[] the function you were seeking? The two //FullForm's are not necessary, of course, but they show how the string is converted to a Wolfram Language expression for a multiplication using the Times[] function.

enter image description here

| improve this answer | |
  • $\begingroup$ Thanks a lot! This is exactly what I needed! Thanks, that's great! $\endgroup$ – Thomas921 May 16 '17 at 13:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.