2
$\begingroup$

I'm using the symbolic package sympy to store a $10 \times 10$ antisymmetric matrix in terms of $10$ variables, and then at every iteration step, I substitute numerical values into the entries of the matrix. however, it's taking too long to substitute values because the symbolic expressions are very complicated. It takes around $100$ seconds for the every substitution and I need at least $10,000$ iterations to get a meaningful result.

So, I was wondering whether there is any speedy way to substitute the values. Right now, I'm just substituting values into the top diagonal half of the matrix, which halves the number of substitutions, but it's still taking too long.

Thanks!

$\endgroup$
  • $\begingroup$ It's perfectly okay to ask here. Another place you might ask is at ask.sagemath.org. Sage is built on Python and it has sympy built into it as well. Therefore, the percentage of users there that might use this same software would be much higher. If nothing else, maybe using Sage itself is better. I have no idea, but they could tell you there. Also, you'd probably want to provide a bit more detail... what formulas (at least one example). $\endgroup$ – Graphth Jul 13 '12 at 19:48
  • 2
    $\begingroup$ This issue does not look like it has much to do with the matrix. You want to evaluate 45 complicated expressions 10000 times. It is natural to look at those 45 expressions to see if they have common parts, and if they do, eliminate the repetition. $\endgroup$ – user31373 Jul 13 '12 at 20:37
  • 1
    $\begingroup$ If you provide more information about the matrix you're trying to generate and what it's entries are supposed to mean, perhaps people here could help with a more direct attack on speeding it up? $\endgroup$ – Nick Alger Jul 18 '12 at 21:26
  • $\begingroup$ Can you do the computation numerically instead of symbolically? $\endgroup$ – Hurkyl Dec 31 '12 at 1:23
2
$\begingroup$

If the elements do indeed contain common terms or subexpressions, then you can use the cse() function to help you eliminate them, so you only do repetitive evaluations once.

$\endgroup$

Your Answer

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

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