0
$\begingroup$

I have a text file which is several GB in size and contains one large formula. I have created this file in another program which I use for analytical transformations. Now I need to insert numbers into this formula, which I tried to do in Mathematica so far. With my current approach it is taking extremely long. What things do I need to consider that are important for efficiency?

total = StringDelete[
           Import["Example.txt"], {" ", "\n", ";"}
        ] // ToExpression;
Table[{x, total}, {x, -180, 180, 10}]

I am just giving my general approach here since the stuff that has to be numerically inserted is way too large to paste it here.

Thank you very much.

$\endgroup$
8
  • 2
    $\begingroup$ Something tells me that you use a very inefficient approach here. Typically, it is not a good idea to numericize such large symbolic expressions. Depending on what you are actually doing, a purely numerical algorithm to compute your result may be way more efficient. E.g., think of solving a linear equation $A \, x= b$ by writing the solution down symbolically with Cramer's rule vs. using a numerical factorization directly for the numericized matrix A. For an $n \times n$ matrix the symbolic method has complexity $O(n!)$ while the numerical one has complexity at most $O(n^3)$. $\endgroup$ Mar 25, 2021 at 12:53
  • 1
    $\begingroup$ Are you sure that the equation that is the output of the other program follows Mathematica's syntax? That is, does it have function names with uppercase initial character (Sin, Log), uses square brackets for function calls, doesn't contain variables with names that are reserved (O, I, E, Pi) etc.? Also, make sure that your inputs are not all integers, as that will make calcualtions ofter very slow and memory intensive. $\endgroup$ Mar 25, 2021 at 13:24
  • 1
    $\begingroup$ You have not identified which program you used to create the formula file. Why can't you use that program to evaluate that formula with given numbers? Why do you need Mathematica instead? Please give us more details about your problem, especially why you need to use a multi GB formula. $\endgroup$
    – Somos
    Mar 25, 2021 at 14:46
  • $\begingroup$ The output of the program is in Mathematicas syntax. The program is Form, I cannot insert numerical values with Form. In the last few months, the output always was just a few MB and I did not have any problems inserting in Mathematica. The multi GB formula is just the result of the Form calculation, I have already summarized large terms to make the file as small as possible. $\endgroup$
    – Nik
    Mar 25, 2021 at 16:18
  • 1
    $\begingroup$ Could you try Table[{x, total}, {x, -180.0, 180.0, 10.0}] instead of Table[{x, total}, {x, -180, 180, 10}]? $\endgroup$ Mar 25, 2021 at 16:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.