I have extremely large .txt file (around 180 MB in the MathML form). This .txt file contains simplified expression in polynomial form and can not be reduced more. After starting the import process, after two days Mathematica 11 is still working. Is there any solution how to speed up it. Ram memory is 10% used all the time.

Large file is uploading long time (few days and nothing) MathML .txt:


Small .txt with the same MathML structure is uploading fast (few swconds):


imp = Import["num.txt"];
eq = ImportString[imp, "Expression"];
  • 1
    $\begingroup$ Try "HeldExpression" or "InactiveExpression". Is it possible that any of the variables in the expression had values assigned to them when ImportString was run? This would cause Mathematica to substitute those values into the expression and then calculate to resolve eq. Depending on what they are this could take a while. $\endgroup$
    – Edmund
    Dec 1, 2016 at 11:25
  • 1
    $\begingroup$ This is very hard to answer without knowing more details on what the file contains. One suggestion I have is using Streams to do a line by line read/write, as this can be more efficient that attempting to process all 180MB at a time (though of course this depends on the structure of the file) $\endgroup$
    – lowriniak
    Dec 1, 2016 at 11:25
  • $\begingroup$ Did you export the expression with Mathematica and was it fast to do so? $\endgroup$
    – Szabolcs
    Dec 1, 2016 at 11:32
  • 1
    $\begingroup$ This takes less than 10 seconds: ToExpression[ ToString@Expand[(1 + x)^20000], InputForm, HoldComplete ]; // AbsoluteTiming. The data it produces is ~170 MB. As Edmund said, try str = Import["num.txt", "String"]; expr = ToExpression[str, InputForm, HoldComplete];. It can't be the parsing that's slow, it must be the evaluation. Your first Import should specify the format. Don't leave it to chance. $\endgroup$
    – Szabolcs
    Dec 1, 2016 at 11:36
  • $\begingroup$ I did not write that .txt is in MathML form. Because of that Szabolic's suggestion does not work. I edited the question. Sorry because of forgotten information about .txt notation. $\endgroup$ Dec 1, 2016 at 13:07


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.