# Fast Destructuring

This might be a XY problem. I first post my immediate question and some background below.

Question: What's the fastest way to pass arguments matching PatternSequence[a_List,{b_?NumericQ,c_List}] to a (compiled) function that takes PatternSequence[a_List,b_?NumericQ,c_List]?

Of course I can just do somthing along the lines of

foo[a_List,{b_?NumericQ,c_List}]:=bar[a,b,c]
foo=bar[#1,Sequence@@#2]&


but if bar is very fast then this introduces a considerable overhead. Is there a better way?

Background: I'm using FoldList to simulate a linear stochastic differential equation with time dependent coefficients. For speed I want to compile the function that generates a time step. One example for this is

NT = 1000; dt = 0.01;
{tvec, nvec} = {Table[t, {t, dt, NT, dt}], Sqrt[2 dt]*Map[List,RandomVariate[NormalDistribution[], NT/dt]]};
uf = With[{AM = IdentityMatrix[2] + {{0, 1}, {-1, -t/10}}*dt, LM = {{0}, {Sqrt[t/10]}}}, Compile[{{x, _Real, 1}, {t, _Real}, {n, _Real, 1}}, AM.x + LM.n]];
xt = FoldList[uf[#1, Sequence @@ #2] &, {100, 0}, Transpose[{tvec, nvec}]];

• Have you measured the overhead? How significant is it? Sep 16, 2016 at 19:20
• @rcollyer I have to double check (can't do right now) but I think around a factor of 4... Sep 16, 2016 at 19:23