I need to use the ReplaceAll function, and I don't understand why but it is extremely slow for a rather simple thing :

In[415]:= indicesSommation[[1]]

Out[415]= {k4 -> 1, k5 -> 2, k6 -> 2}

In[418]:= SixJSymbol[{1, 2, 3}, {k4, k5, k6}] /. indicesSommation[[1]]

Out[418]= $Aborted

In[413]:= SixJSymbol[{1, 2, 3}, {1, 2, 2}]

Out[413]= 1/15

Here, I aborted the output 418 but it gave me the good result (1/15) but after approximately 2 minutes, whereas the output 413 give me the correct result after few seconds.

Why is the output 418 that long?

(I am a huge beginner in mathematica I just started to learn it)


What is extremely strange is that for an other order of the parameters the replaceAll works as good as if I wrote the parameters directly by hand. This example :

In[420]:= SixJSymbol[{k4, 4, 5}, {6, k6, 2}] /. indicesSommation[[1]]

Out[420]= -(Sqrt[(7/33)]/5)

Is executed very fast.


1 Answer 1


When you apply the replacement rule to the outside of the SixJSymbol, it will first calculate the fully analytic expression first. If you put the replacement rule inside the function bracket, it will substitute the numbers in before making the calculation. So you want:

SixJSymbol[{1, 2, 3}, {k4, k5, k6} /. indicesSommation[[1]]] 

You can use Trace to see exactly what is happening. When you try with only 2 analytic values the resulting symbolic expression doesn't actually take that long to be found.


Your Answer

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

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