I have a module 'L' that reads:
L[f0_,n_]:=Module[{ft=f0}, a[t]={}; Do[AppendTo[a[t], Inr[f0,ft]];
ft=U@ft, {n}]];
It takes an input function f0, applies unitary operator U repeatedly n-times, i.e. it is a n-fold composition of U on f0. The resulting function after each single composition step is evaluated with Inr (Inr is the inner product here). Finally, the value is added to a list a[t], and so on.
What I am looking to achieve is instead of applying U n-times, (U[U[U...[f0]..], I want to construct an action of a repeated sequence of different operators A,B. For example, A[A[A[B[B[B[A[A[A[B...[f0]..], that likewise amounts to a total of n-fold composition. The list a[t] then should be constructed via Inr employing ft's obtained from each single application of A or B along the composition sequence.
Could anyone provide suggestions how to implement this with Do command, or in some other way! Building a list of the operator sequences and using NestList does not seem to be permissible due to memory constraints since all intermediate values ft are retained. Only a[t]'s are of interest here.
The functions are defined as:
U@ft_:=UV InverseFourier[UK Fourier[ft]];
i.e. Going between position/momentum-spaces to evaluate application of a potential energy term UV and momentum UK term, where:
UV:=Exp[-I V dt];
UK:=Exp[-I K dt];
This is the split-operator method solution of a 't'-dependent 2D Schrodinger eq. on a lattice grid. f0 -initial is any discretized 2D function, say a Gaussian. Difference between U and A and B is due to different 'V' terms of 'UV's. Inr on the spatial grid:
Inr[f0_,ft_]:=Dot[Flatten[Conjugate[f0]],Flatten[ft]]dxdy;
Composition
, maybe? Either that, orComposeList
. $\endgroup$G[f0, #] & /@ NestList[H, f0, 4]
? $\endgroup$G[f0, #] & /@ ComposeList[{A, A, B, A, B, B}, x]
? Which of these is closest to what you want? $\endgroup$Sow
/Reap
construction, becauseAppendTo
is notoriously slow, and usingSow
/Reap
allows you to gather desired outputs at any time during aDo
loop. However, I think it will be hard to determine if it's useful without a minimal example showing the actual format of your functions/matrices/etc. Obviously, don't post a 1024X1024 grid, but perhaps you could give an example grid (4x4?) with exampleA
andB
, and your expression forG
. $\endgroup$