I’m wondering if there is an efficient way to build a tuple recursively. I’m working with a three-term recurrence relationship (specifically, this one).
The first and second terms are known. From them, all the other terms can be computed, one-by-one. The number of terms is known at run time.
I can allocate a vector and fill in the sequence, but I’m wondering if there might be tricks to avoid doing such an allocation. I tried a recursive splatting (slurping?) approach to build the tuple,
function Tₖ(T::Tuple, ξ, n::Int)
if length(T) == n
return T
else
return Tₖ((T..., 2*ξ*T[end] - T[end-1]), ξ, n)
end
end
but this results in horrible type instability when indexing the tuple.
Any ideas would be appreciated!