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

list2[n_, L_]:=
  ParallelTable[ρ[n,L][[i,j]]->a[i,j],{i,L^n},{j,L^n}]/.
   {a[i_,j_]:>ToExpression["a"<>ToString[i]]}//Flatten;

p1[n_, L_] := 
  Sum[
    Subscript[ρ, L, L][k]*
    Product[
     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_]:=
  ParallelProduct[
    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]
$\endgroup$

1 Answer 1

0
$\begingroup$

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;
$\endgroup$

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.