Forum Discussion
Ways of performing Accumulation with Dynamic Arrays
- Jul 26, 2021
This has been a great thread! Thanks to all the contributors. We just announced a new wave of lambda functions that I think will greatly help these scenarios. In particular, REDUCE, SCAN, BYROW and BYCOL.
Thanks for the Wikipedia reference, there does appear to be several point of connection. Even the statement "Prefix summation or partial summation form linear operators on the vector spaces of finite or infinite sequences; their inverses are finite difference operators" reminded me of discussions with Charles Williams where I was keen that the ACCUMULATE and DIFF functions would be capable of acting as inverses of one another, just as the matrix forms do.
Mind you, I also wanted the multiplicative factor associated with growth to be a matrix but that was a step too far in terms of usability. I thought it might be fun to see a factor of
give rise to the Fibonacci series.
I gather both you and SergeiBaklan are holding off until something more mature and stable appears in the area of Excel's Lambda functions. I have got some catching up to do. Somehow, I think maths degrees from over half a century ago and Fortran IV programming experience may not have placed me in an ideal position for getting to grips with arcane features of the world of functional programming.
With a bit of luck the higher order functions of map/scan/reduce etc. will make life easier though!
It took me some time to understand the points you raise here. I think I get it now, translating into functional programming terminology one might want as an accumulator,
LAMBDA(x,y,x+z*y)
with z = 1.1, say, for compound interest. One could also extend to array inputs using,
LAMBDA(x,y,x+MMULT(z,y))
Setting z = {1,1;1,0} together with an input list consisting of pairs {1;0}, {0;0}, {0;0}, {0;0}, ...
would give rise to a sequence of Fibonacci pairs {1;1}, {2;1}, {3;2}, {5;3}, ...
Since arrays cannot be nested they would need to be passed as individual arguments though, one possible approach for that was mentioned here.
- lori_mMay 13, 2021Iron Contributor
I realise since the arrays are only one dimensional they could be stacked which I guess was the intention for the ACCUMULATE function. So one could write a function that accumulates arrays in one dimension or other, e.g.
=VSCAN({0,1;0,0;0,0;0,0},LAMBDA(x,y,x+MMULT(y,{0,1;1,1})))
would return {1,1;1,2;2,3;3,5}
- PeterBartholomew1May 13, 2021Silver Contributor
Yes, though I apologise for causing you to devote time chasing that particular rabbit down its burrow! It was just a thought that the second-order difference equation could be reduced to first-order matrix form by introducing an additional variable.
- tbouldenMay 14, 2021Iron Contributor
I've been a little busy playing with melding Andy Gordon's fold implementation and Peter's tree traversal (_tt), and have put together versions of reduce/fold/scan (left and right) using both methodologies; well, almost, I've gone cross-eyed on doing the tree traversal for scan, so tabling it for now. Please see attached! I've even got reduce/fold on columns and rows!
Based on my studying, we basically only need one of the three to get the other two; I've done this with reduce_tt using fold_tt. I think we should be able to make scan from reduce and Peter's COMBINEλ, however its going slightly wrong. I'm sure its an oversight on my part somewhere, but I thought I might let others play with these while I uncross my eyes.