Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

'm using the symbolic package sympy to store a 10X10 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.


share|cite|improve this question
It's perfectly okay to ask here. Another place you might ask is at 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). – Graphth Jul 13 '12 at 19:48
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. – user31373 Jul 13 '12 at 20:37
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? – Nick Alger Jul 18 '12 at 21:26
Can you do the computation numerically instead of symbolically? – Hurkyl Dec 31 '12 at 1:23

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.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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