Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
ρ[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

1 Answer 1

By using "Rho[n_, L_]:=Rho[n_,L_]=..." command. 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.