Mathematica Stack Exchange is a question and answer site for users of Mathematica. 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
ρ[n_, L_]:=
    ArrayFlatten,TensorProduct@@Table[Subscript[ρ, l,m][k],{k,n},{l,L},{m,L}]];

list2[n_, L_]:=

p1[n_, L_] := 
    Subscript[ρ, L, L][k]*
     If[k == k1, 1, 
         ParallelSum[Subscript[ρ, l, l][k1], {l, L - 1}]], {k1, n}], {k, n}]//Expand;

P1[n_, L_]:= P1[n,L]= p1[n,L] /. list2[n,L];

p0[n_, L_]:=
    Sum[Subscript[ρ, l, l][k], {l, L - 1}], {k, n}] // Expand;

P0[n_, L_]:=P0[n,L]= p0[n,L] /. list2[n,L];

Easy to evaluate...

P0[4, 3]-P0[3, 3]
P1[4, 3]-P1[3, 3]

What kind of changes are needed to speed up this calculation...

P0[5, 3]-P0[4, 3]
P1[5, 3]-P1[4, 3]
share|improve this question
up vote 0 down vote accepted

By using the command Rho[n_, L_] := Rho[n, L] = ..., we can make it faster:

Rho[n_, L_] := Rho[n, L] = FixedPoint[
        ArrayFlatten, TensorProduct@@Table[
            Subscript[\[Rho], l, m][k],{k, n}, {l, L}, {m, L}]];

list2[n_, L_] := list2[n, L] = ParallelTable[
        Rho[n, L][[i, j]] -> a[i, j], {i, L^n}, {j, L^n}] /. {a[i_, j_]  
            :> ToExpression["a" <> ToString[i]]} // Flatten;
share|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.