SOLVED

Ways of performing Accumulation with Dynamic Arrays

%3CLINGO-SUB%20id%3D%22lingo-sub-2329035%22%20slang%3D%22en-US%22%3EWays%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2329035%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20welcome%20your%20review%20of%20the%20following%20ideas%2C%20to%20identify%20errors%2C%20spot%20improvements%20or%20advise%20if%20I%20am%20following%20ideas%20that%20are%20already%20standard%20fare%20for%20others.%26nbsp%3B%20My%20objective%20is%20to%20develop%20a%20series%20of%20workbooks%20that%20are%20comprised%20entirely%20of%20dynamic%20arrays%3B%20no%20more%20'and%20fill%20down'.%26nbsp%3B%20The%20problems%20I%20identified%20when%20DA%20first%20appeared%20were%20the%20problem%20of%20using%20dynamic%20arrays%20for%20accumulations%20without%20allowing%20circular%20references%20and%20problems%20handling%20'arrays%20of%20arrays'%20(sum%20each%20column%20for%20example).%26nbsp%3B%20Recursion%20and%20lambda%20functions%20appear%20to%20offer%20a%20way%20forward%2C%20but%20I%20do%20not%20find%20it%20intuitive.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F278600iD3A63C0EDF261E40%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22The%20purpose%20of%20the%20proposed%20approach%20is%20to%20accumulate%20a%20sequence%20of%20values%20as%20a%20dynamic%20array.%20Examples%20include%20the%20flow%20variables%20in%20a%20running%20balance%20or%20series%20returned%20from%20a%20difference%20equation.%20The%20key%20feature%20of%20the%20calculation%20is%20that%20each%20term%20depends%20upon%20the%20preceding%20value%20of%20the%20same%20array%3B%20this%20makes%20Excel%20report%20the%20calculation%20as%20a%20circular%20reference.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20calculation%20developed%20here%20uses%20recursion%20to%20work%20around%20this%20problem%20by%20exploiting%20the%20fact%20that%20the%20recursion%20introduces%20a%20new%20set%20of%20operands%20at%20every%20level%20of%20the%20stack.%20In%20order%20to%20avoid%20replicating%20the%20flow%20variables%20at%20every%20level%20of%20the%20recursion%20stack%2C%20they%20are%20passed%20as%20a%20lambda%20function%20rather%20than%20an%20array.%20A%20similar%20consideration%20also%20applies%20to%20the%20results.%20Rather%20than%20accumulating%20the%20results%20as%20they%20are%20calculated%2C%20assembly%20is%20left%20to%20the%20tail%20end%20of%20the%20calculation%20as%20control%20is%20returned%20back%20though%20the%20stack.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20709px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F278609iE7529BFA79C4EEF8%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20the%20obvious%20linear%20sequence%20of%20calls%20from%20term%20to%20term%20can%20easily%20fail%20because%20of%20the%20limit%20on%20the%20size%20of%20the%20operand%20stack.%26nbsp%3B%20In%20order%20to%20circumvent%20this%20problem%2C%20I%20have%20traversed%20the%20data%20as%20a%20binary%20tree%2C%20as%20shown%20in%20the%20figure.%20Although%20twice%20as%20many%20nodes%20are%20visited%20in%20such%20a%20scheme%2C%20the%20maximum%20levels%20of%20recursion%20for%20N%20values%20is%20log%E2%82%82(N).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3E%3D%20LAMBDA(%CE%BBfunction%2CstartValue%2Cr%2Cp%2Cn%2C%0A%20%20%20%20%20%20IF(n%26gt%3B1%2C%0A%20%20%20%20%20%20%20%20%20LET(%0A%20%20%20%20%20%20%20%20%20%20%20%20%E2%84%93%2C%20n%20-%20QUOTIENT(n%2C2)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20b%E2%82%81%2C%20XACC%CE%BB(%CE%BBfunction%2CstartValue%2Cr%2Cp%2C%E2%84%93)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20b%E2%82%82%2C%20XACC%CE%BB(%CE%BBfunction%2CMAX(b%E2%82%81)%2Cr%2Cp%2B%E2%84%93%2Cn-%E2%84%93)%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20balance%2C%20COMBINE%CE%BB(b%E2%82%81%2C%20b%E2%82%82)%2C%0A%20%20%20%20%20%20%20%20%20%20%20balance)%2C%0A%20%20%20%20%20%20%20%20%20%CE%BBfunction(p)%2B(1%2Br)*startValue)%0A%20%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tested%20the%20Lambda%20function%20for%20up%20to%2016%2C000%20terms%20(pretty%20much%20the%20width%20of%20an%20Excel%20sheet)%20and%20it%20has%20worked%2C%20but%20is%20slow.%20The%20approach%20took%2015sec%2C%20more%20than%201000%20times%20slower%20than%20Charles%20Williams's%20FastExcel%20paid%20add-in!%20%26nbsp%3BThat%20said%2C%20for%20more%20reasonably%20sized%20timelines%20the%20calculation%20worked%20well.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENote%3A%20%3CEM%3EOther%20approaches%20to%20the%20accumulation%20of%20flow%20variables%20(sometimes%20known%20as%20corkscrews%20from%20the%20way%20a%20hand-calculation%20may%20be%20laid%20out)%20include%20the%20use%20of%20%3C%2FEM%3EMMULT%20%3CEM%3Eand%20%3C%2FEM%3ESUMIFS%3CEM%3E.%20In%20each%20case%2C%20the%20idea%20is%20to%20calculate%20the%20balances%20directly%20from%20the%20flow%20variables%20without%20any%20recursive%20calls%20to%20previously%20calculated%20values.%20In%20the%20case%20of%20%3C%2FEM%3EMMULT%3CEM%3E%2C%20the%20calculation%20requires%20an%20upper%20triangular%20matrix%20of%20%3C%2FEM%3E1%3CEM%3E's%20to%20be%20assembled.%20Although%20there%20is%20no%20formal%20limit%20of%20array%20size%20in%20Excel%2C%20%3C%2FEM%3E16000%20x%2016000%20%3CEM%3Estruck%20me%20as%20uncomfortably%20large%3C%2FEM%3E.%22%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2329035%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2332054%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2332054%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F137306%22%20target%3D%22_blank%22%3E%40Charles%20Williams%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20be%20pleased%20to%20know%20that%20your%20FastExcel%20functions%20absolutely%20thrashed%20recursion%20when%20it%20came%20to%2016%2C000%20time%20periods%3B%20but%20then%20it%20should.%26nbsp%3B%20I%20like%20VSTACK%20and%20HSTACK%20but%2C%20If%20I%20had%20to%20pick%20one%20function%20from%20your%20add-in%20it%20would%20be%20ACCUMULATE.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2337666%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2337666%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESorry%2C%20I%20appear%20to%20have%20missed%20some%20of%20your%20posts.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Flambda-recursive-lists-and-understanding-recursion-limits-of%2Fm-p%2F2199690%22%20target%3D%22_blank%22%3ELAMBDA%3A%20Recursive%20Lists%20and%20Understanding%20Recursion%20Limits%20of%20LAMBDA%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FP%3E%3CP%3EYou%20have%20been%20busy!%26nbsp%3B%20I%20still%20find%20the%20functional%20calculus%20notation%20pretty%20opaque.%26nbsp%3B%20Even%20where%20I%20think%20I%20understand%20the%20concept%2C%20expressing%20it%20in%20the%20lambda%20notation%20and%20manipulating%20the%20formula%20does%20not%20come%20naturally.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20idea%20of%20the%20binary%20tree%20evolved%20during%20the%20work.%26nbsp%3B%20At%20first%20my%20idea%20was%20simply%20to%20accumulate%20over%20single%20years%20and%20then%20nest%20the%20annual%20result%20to%20apply%20the%20formula%20to%20multiple%20years.%26nbsp%3B%20I%20then%20decided%20that%20it%20is%20not%20necessary%20to%20identify%20such%20natural%20grouping%20within%20the%20dataset%20and%20instead%20to%20simply%20bisect%20the%20it%20to%20the%20required%20depth.%26nbsp%3B%20Only%20then%20did%20I%20realise%20I%20do%20not%20need%20to%20actually%20split%20the%20array%20but%2C%20rather%2C%20I%20could%20merely%20pass%20a%20pointer%20and%20array%20length%20to%20the%20internal%20Lambda%20function.%26nbsp%3B%20The%20result%20was%20the%20binary%20tree%20but%20that%20wasn't%20in%20mind%20at%20the%20outset!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20link%20to%20Andy%20Gordon's%20talk.%26nbsp%3B%20I%20had%20not%20seen%20some%20of%20the%20later%20material%20before%20and%20noted%20his%20invitation%20to%20make%20contact%2C%20but%20no%20contact%20details%20were%20provided.%26nbsp%3B%20Do%20you%20have%20an%20email%20address%20for%20Andy%20to%20request%20access%20to%20the%20Lambda%20editor%3F%26nbsp%3B%20I%20sent%20an%20email%20to%20the%20seminar%20organisers%20to%20forward%20so%20we%20will%20see%20what%20comes%20of%20that.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2337708%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2337708%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.linkedin.com%2Fin%2Fandrew-d-gordon%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.linkedin.com%2Fin%2Fandrew-d-gordon%2F%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2338076%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2338076%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20sharing%2C%20I%20will%20be%20able%20to%20test%20when%20LAMBDA%20goes%20live%20-%20whenever%20that%20will%20be...%26nbsp%3B%20I'm%20not%20familiar%20with%20the%20details%20but%20this%20appears%20to%20be%20similar%20to%20the%3CSTRONG%3E%26nbsp%3Bpipelined%20binary%20tree%3C%2FSTRONG%3E%26nbsp%3Bsection%20of%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPrefix_sum%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EPrefix%20sum%20-%20Wikipedia%3C%2FA%3E%26nbsp%3B-%20all%20the%20more%20impressive%20that%20you%20have%20come%20up%20with%20this%20type%20of%20implementation%20independently.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20discussed%20elsewhere%2C%20I%20hope%20we%20get%20capability%20for%20running%20totals%20built%20in%20soon%20-%20functions%20like%20map%2C%20reduce%2C%20fold%20and%20scan%20have%20been%20mentioned%20in%20a%20recent%20MS%20research%20%3CA%20href%3D%22https%3A%2F%2Fwww.microsoft.com%2Fen-us%2Fresearch%2Fpodcast%2Fadvancing-excel-as-a-programming-language-with-andy-gordon-and-simon-peyton-jones%2F%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Epodcast%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2338244%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2338244%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3EI%20tried%20to%20ask%20about%20map%2Ffold%2Fetc.%20timing%20as%20part%20of%20the%20YouTube%20livestream%20I%20linked%20to%20up-thread%2C%20however%20the%20moderator%20didn't%20include%20part%202%20of%20my%20question%2C%20only%20the%20LAMBDA%20Playground%2FEditor%20was%20addressed.%20Perhaps%20if%20Andy%20replies%20to%20me%20about%20LAMBDA%20playground%20I%20can%20ask%20about%20the%20timing%20of%20those%20as%20well.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2338247%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2338247%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20leads.%20I%20will%20give%20it%20a%20bit%20before%20following%20up%20to%20avoid%20the%20risk%20of%20duplication.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2350992%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2350992%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20took%20me%20some%20time%20to%20understand%20the%20points%20you%20raise%20here.%20I%20think%20I%20get%20it%20now%2C%20translating%20into%20functional%20programming%20terminology%20one%20might%20want%20as%20an%20accumulator%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3ELAMBDA(x%2Cy%2Cx%2Bz*y)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ewith%20z%20%3D%201.1%2C%20say%2C%20for%20compound%20interest.%20One%20could%20also%20extend%20to%20array%20inputs%20using%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-excel%22%3E%3CCODE%3ELAMBDA(x%2Cy%2Cx%2BMMULT(z%2Cy))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESetting%20z%20%3D%20%7B1%2C1%3B1%2C0%7D%20together%20with%20an%20input%20list%20consisting%20of%20pairs%20%7B1%3B0%7D%2C%20%7B0%3B0%7D%2C%20%7B0%3B0%7D%2C%20%7B0%3B0%7D%2C%20...%3C%2FP%3E%3CP%3Ewould%20give%20rise%20to%20a%20sequence%20of%20Fibonacci%20pairs%20%7B1%3B1%7D%2C%20%7B2%3B1%7D%2C%20%7B3%3B2%7D%2C%20%7B5%3B3%7D%2C%20...%3C%2FP%3E%3CP%3ESince%20arrays%20cannot%20be%20nested%20they%20would%20need%20to%20be%20passed%20as%20individual%20arguments%20though%2C%20one%20possible%20approach%20for%20that%20was%20mentioned%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Flambda-examples-count-words-in-a-text-string%2Fm-p%2F2068666%2Fhighlight%2Ftrue%23M86225%22%20target%3D%22_self%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2353153%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353153%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYes%2C%20though%20I%20apologise%20for%20causing%20you%20to%20devote%20time%20chasing%20that%20particular%20rabbit%20down%20its%20burrow!%26nbsp%3B%20It%20was%20just%20a%20thought%20that%20the%20second-order%20difference%20equation%20could%20be%20reduced%20to%20first-order%20matrix%20form%20by%20introducing%20an%20additional%20variable.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2353454%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2353454%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20been%20a%20little%20busy%20playing%20with%20melding%20Andy%20Gordon's%20fold%20implementation%20and%20Peter's%20tree%20traversal%20(_tt)%2C%20and%20have%20put%20together%20versions%20of%20reduce%2Ffold%2Fscan%20(left%20and%20right)%20using%20both%20methodologies%3B%20well%2C%20almost%2C%20I've%20gone%20cross-eyed%20on%20doing%20the%20tree%20traversal%20for%20scan%2C%20so%20tabling%20it%20for%20now.%20Please%20see%20attached!%20I've%20even%20got%20reduce%2Ffold%20on%20columns%20and%20rows!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBased%20on%20my%20studying%2C%20we%20basically%20only%20need%20one%20of%20the%20three%20to%20get%20the%20other%20two%3B%20I've%20done%20this%20with%20reduce_tt%20using%20fold_tt.%20I%20think%20we%20should%20be%20able%20to%20make%20scan%20from%20reduce%20and%20Peter's%20COMBINE%CE%BB%2C%20however%20its%20going%20slightly%20wrong.%20I'm%20sure%20its%20an%20oversight%20on%20my%20part%20somewhere%2C%20but%20I%20thought%20I%20might%20let%20others%20play%20with%20these%20while%20I%20uncross%20my%20eyes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2358865%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2358865%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20downloaded%20your%20file%20and%20plan%20to%20work%20through%20it.%26nbsp%3B%20Some%20education%20regarding%20the%20higher-order%20functions%20will%20not%20go%20amiss!%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20things%20stand%20though%2C%20it%20is%20my%20belief%20that%20Excel%20still%20needs%20a%20high%20performance%20ACCUMULATE%20function%20as%20a%20built-in%20function%20in%20order%20to%20achieve%20the%20goal%20of%20fully-dynamic%20modelling%20with%20Excel.%26nbsp%3B%20Corkscrews%20represent%20a%20very%20common%20construct%20in%20financial%20modelling%20and%20suggesting%20the%20solution%20lies%20in%20recursive%20programming%20is%20not%20a%20way%20forward.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2358977%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2358977%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGreat%20news!%20I%20got%20the%20LAMBDA%20Editor%20add-in%20as%20a%20beta-tester%20on%20Friday%20and%20have%20been%20re-working%20my%20original%20functions%20using%20the%20editor%3B%20I%20hope%20you%20were%20able%20to%20get%20on%20the%20list%20for%20it%20as%20well!%20Note%20that%20if%20you%20haven't%2C%20it%20works%20on%20same%20principle%20to%20your%20VBA%20solution%2C%20but%20with%20a%20proper%20editor%20and%20a%20few%20diffs.%20It%20loads%20its%20session%20data%20to%20a%20hidden%20sheet%20and%20you%20can%20export%2Fimport%20to%20JSON%20file.%20Not%20sure%20if%20this%20is%20best%20way%20for%20sharing%2C%20but%20will%20have%20to%20see.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20also%20implemented%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E%20Fibonacci%20matrix%20calc%20example%20using%20scan%20from%20above%20(see%20%22Examples%22%20tab).%20I'm%20starting%20to%20see%20how%20powerful%20fold%20can%20be%2C%20I've%20implemented%20my%20reduce%2Fscan%20functions%20leveraging%20fold%20as%20the%20workhorse.%20And%20you%20can%20do%20lots%20of%20other%20tasks%20just%20by%20providing%20the%20right%20function%20to%20fold%2Freduce%2Fscan.%20Will%20update%20later%20with%20more%20of%20these%20extended%20examples.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2361248%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2361248%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E(...%20continued)%3C%2FP%3E%3CP%3EAs%20an%20aside%2C%20I%20added%20the%20Greek%20%CE%BBs%20simply%20as%20a%20flag%20to%20assist%20me%20in%20reading%20the%20formulas.%26nbsp%3B%20I%20also%20note%20that%20you%20appear%20to%20have%20tidied%20up%20the%20MAKEARRAY%20function%20and%20I%20recognise%20the%20code%20fragments%20showing%20where%20you%20have%20incorporated%20the%20binary%20tree.%3C%2FP%3E%3CP%3ELooking%20at%20the%20amortisation%20problem%2C%20I%20note%20that%20you%20have%20calculated%20the%20repayment%20using%20the%20PMT%20function%20at%20each%20step%20of%20the%20calculation.%26nbsp%3B%20I%20think%20this%20opens%20up%20the%20possibility%20of%20taking%20interest%20rate%20variability%20into%20account%20with%20the%20repayment%20being%20adjusted%20based%20on%20the%20remaining%20repayment%20period%20and%20the%20outstanding%20balance.%3C%2FP%3E%3CP%3EOverall%2C%20I%20have%20some%20serious%20work%20to%20do%20to%20try%20to%20keep%20up%20with%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2375115%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2375115%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20love%20your%20final%20thought%20of%3C%2FP%3E%3CP%3E%22my%20commitment%20to%20my%20recent%20progress%20is%20hindering%20my%20continued%20progress%22!%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EI%20am%20now%20up%20and%20going%20with%20the%20Lambda%20editor.%20It%20was%20just%20a%20case%20of%20not%20noticing%20SHARED%20FOLDER%20under%20Get%20Add-ins.%20I%20now%20need%20time%20to%20run%20through%20the%20set-piece%20examples%20to%20bring%20it%20together%20with%20the%20results%20of%20my%20own%20experimentation.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAt%20the%20moment%2C%20I%20find%20a%20strange%20contrast%20between%20basic%20spreadsheet%20development%20and%20the%20world%20of%20Lambda%20functions.%20The%20first%20assumes%20one%20is%20too%20idle%20to%20define%20ones%20terms%20and%20can%20handle%20only%20the%20most%20primitive%20computing%20concepts%20but%2C%20by%20way%20of%20contrast%2C%20has%20an%20elephantine%20memory%20for%20'tips%20and%20tricks'%20that%20allow%20one%20to%20apply%20'go%20faster%20stripes'%20to%20the%20solution%20process.%26nbsp%3B%20The%20second%20appears%20so%20convoluted%20that%20I%20am%20finding%20it%20tricky%20to%20thread%20my%20Fortran%20IV%20trained%20brain%20through%20the%20twists%20and%20turns.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOf%20all%20the%20MAPS%2FFOLDS%2FSCANS%20that%20might%20be%20technically%20possible%2C%20I%20wonder%20which%20form%20the%20'core%20irreducible%20set'%20that%20must%20be%20present%20to%20meet%20the%20major%20demands%20of%20user%20problems.%26nbsp%3B%20Whichever%20make%20the%20transition%20to%20built-in%20functions%20will%20need%20careful%20presentation%20if%20it%20is%20to%20fit%20into%20standard%20practice.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2375500%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2375500%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3E%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMAP%20and%20FOLD%20could%20be%20combined%20to%20give%20SCAN%20though%20ideally%20scalable%20versions%20of%20all%20these%20functions%20would%20be%20available.%20For%20comparison%20Power%20Query%20and%20Python%20both%20have%20Accumulate%20available%20as%20a%20standard%20function%20capable%20of%20processing%20large%20lists%20via%20buffers%20%2F%20iterators.%26nbsp%3B%26nbsp%3BMany%20useful%20functions%20could%20be%20derived%20from%20these%20three.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20a%20typical%20example%2C%20to%20sum%20over%20columns%20one%20might%20use%20something%20like%2C%3C%2FP%3E%3CP%3E%3DCOLMAP(%20SUM%2C%20TABLE%20)%3C%2FP%3E%3CP%3Ewhere%20SUM%20or%20LAMBDA(%20x%2C%20SUM(%20x%20)%20)%20is%20the%20aggregation%20function%20and%3C%2FP%3E%3CP%3ECOLMAP%3A%3DLAMBDA(f%2CT%2CMAP(LAMBDA(i%2Cf(INDEX(T%2C%2Ci))%2CSEQUENCE(%2CCOLUMNS(T)))))%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2376281%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2376281%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20clarification%20that%20list%20aggregation%20in%20PQ%20is%20quite%20inefficient%20-%20that's%20good%20to%20be%20aware%20of.%20I%20do%20not%20really%20know%20PQ%20well%20and%20using%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fwww.myonlinetraininghub.com%2Fquickly-create-running-totals-in-power-query%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3EList.Buffer%3C%2FA%3E%26nbsp%3Bfor%20running%20totals%26nbsp%3Bis%20likely%20still%20not%20that%20much%20of%20an%20improvement.%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EPython%20-%20which%20I%20am%20more%20familiar%20with%20-%20uses%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FIterator%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eiterators%3C%2FA%3E%26nbsp%3Bfor%20list%20operations.%20The%20itertools%20accumulate%20function%20processes%20a%20million%20rows%20in%20a%20fraction%20of%20a%20second%20and%20I'm%20hoping%20we%20could%20see%20similar%20performance%20in%20Excel%20if%20the%20propose%20new%20functions%20are%20well%20optimised.%20For%20reference%2C%20the%20suggested%20formula%20above%20was%20prototyped%20in%20Python%20using%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-python%22%3E%3CCODE%3Efrom%20numpy%20import%20array%2C%20shape%2C%20sum%0Acolmap%3Dlambda%20f%2CT%3Amap(lambda%20i%3Af(T%5B%3A%2Ci%5D)%2Crange(T.shape%5B0%5D))%0A%0A%26gt%3B%26gt%3B%26gt%3BA%3Darray(%5B%5B1%2C2%5D%2C%5B3%2C4%5D%5D)%0A%26gt%3B%26gt%3B%26gt%3Blist(colmap(sum%2CA))%0A%5B4%2C6%5D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2382289%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2382289%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F214174%22%20target%3D%22_blank%22%3E%40Peter%20Bartholomew%3C%2FA%3Ere%3A%20%22Of%20all%20the%20MAPS%2FFOLDS%2FSCANS%20that%20might%20be%20technically%20possible%2C%20I%20wonder%20which%20form%20the%20'core%20irreducible%20set'%20that%20must%20be%20present%20to%20meet%20the%20major%20demands%20of%20user%20problems.%20Whichever%20make%20the%20transition%20to%20built-in%20functions%20will%20need%20careful%20presentation%20if%20it%20is%20to%20fit%20into%20standard%20practice.%22%20--%20Based%20on%20my%20experimentation%2C%20and%20the%20varying%20implementations%20I've%20tried%2C%20I%20suspect%20we'll%20end%20up%20with%20element-wise%2C%20and%20row-wise%2Fcolumn-wise%20versions%2C%20and%20we'll%20need%20a%20proper%20conception%20of%20an%20empty%20array%20to%20work%20with.%20I%20think%20much%20of%20my%20trouble%20with%20my%20previous%20fold%20examples%20was%20trying%20to%20work%20around%20not%20having%20an%20empty%20array%20primitive%20as%20a%20%22natural%20zero%22.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETaking%20myself%20at%20my%20word%20and%20reworking%20my%20fold%2Freduce%2Fscans%20for%20a%203rd%20time%2C%20and%20after%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E's%20COLMAP%20example%2C%20I've%20done%20implementations%20of%20vMap%20and%20hMap%20doing%20row-wise%20and%20column-wise%20mapping%20respectively.%20I%20may%20have%20been%20trying%20to%20squeeze%20too%20much%20out%20of%20fold%20and%20many%20of%20my%20failing%20examples%20have%20yielded%20to%20an%20application%20of%20one%20of%20these%20maps.%20I'm%20pretty%20happy%20that%20I%20got%20bubble-sort%20figured%20out%20finally%20though.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EIf%20I%20rework%20things%20again%2C%20it%20may%20be%20to%20take%20what%20I%20think%20may%20be%20the%20more%20functional%20approach%20and%20make%20everything%20unary%20so%20that%20I%20can%20get%20better%20acquainted%20with%20currying%2Fpartial%20application.%20I've%20gotten%20some%20inspiration%20recently%20from%20whoever%20is%20posting%20%3CA%20href%3D%22https%3A%2F%2Frosettacode.org%2Fwiki%2FCategory%3AExcel%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ELAMBDAs%20on%20Rosetta%20Code%3C%2FA%3E%26nbsp%3B%20and%20%3CA%20href%3D%22https%3A%2F%2Frosettacode.org%2Fwiki%2FFibonacci_sequence%23LAMBDA%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Eseem%20to%20know%20what%20they're%20doing%3C%2FA%3E!%20Could%20be%20fun%20to%20pick%20through%20some%20of%20the%20things%20%3CA%20href%3D%22https%3A%2F%2Frosettacode.org%2Fwiki%2FReports%3ATasks_not_implemented_in_Excel%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Enot%20yet%20implemented%3C%2FA%3E%20and%20give%20them%20a%20swing.%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EAs%20for%20the%20LAMBDA%20editor%2C%20thus%20far%20I'm%20really%20enjoying%20it!%20Whereas%20previously%20I%20tried%20not%20to%20clutter%20things%20up%20too%20much%2C%20I've%20not%20minded%20the%20explosion%20of%20functions%20that%20do%20%22one%22%20thing%20that%20really%20are%20part%20of%20a%20swiss-army%20knife%20approach%20that%20makes%20more%20intractable%20problems%20easier.%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3EAnd%20as%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%20mentions%2C%20usability%20will%20be%20the%20ultimate%20arbiter%3B%20I'm%20having%20fun%20with%20it%20now%2C%20but%20nothing%20in%20my%20work%20life%20relies%20on%20it%2C%20so%20we'll%20see%20what%20the%20team%20can%20make%20for%20us.%20I%20know%20that%20Peter's%20tree%20traverse%20has%20essentially%20removed%20the%20stack%20depth%20issues%2C%20but%20it%20does%20slow%20thing%20down%20considerably%20when%20getting%20into%20larger%20tree%20structures.%20Nothing%20to%20do%20but%20play%20around%20until%20the%20next%20thing%20is%20brought%20down%20from%20the%20mountain-top.%3C%2FP%3E%3CP%20data-unlink%3D%22true%22%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2383674%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2383674%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20links%20and%20sample%20workbook%20-%20all%20sounds%20like%20great%20progress%20given%20what%20is%20available%20currently.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20now%20also%20have%20access%20to%20Lambda%20Editor%20but%2C%20as%20I'm%20restricted%20to%20current%20channel%20on%20corporate%20licence%2C%20it's%20not%20much%20use%20without%20LAMBDA!%20I%20presume%20one%20can%20make%20names%20containing%20lambdas%20appear%20as%20functions%20in%20tooltips%20and%20also%20create%20function%20categories%20for%20them%20by%20opening%20name%20manager%20from%20a%20macro%20sheet%20(ctrl%2Bf11)%20or%20by%20using%20the%20VBE%20Names%20properties.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20interesting%20what%20you%20say%20about%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2F-calc-error-empty-array-7060a577-8635-4934-acb2-a534a42b3ba4%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Eempty%20arrays%3C%2FA%3E%20being%20a%20stumbling%20block.%20An%20alternative%20might%20be%20to%20use%20an%20array%20containing%20a%20single%20blank%20value%20which%20can%20be%20returned%20as%20an%20intermediate%20result%20eg%20if%20blank%3DSORT(%2C)%20then%20ISBLANK(blank)%20returns%20%7BTRUE%7D.%20The%20INDEX%20function%20can%20preserve%20blank%20values%20like%20these%20in%20results%20but%20many%20other%20functions%20can't%20which%20makes%20them%20tricky%20to%20manipulate%20however.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2384081%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2384081%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20believe%20we%20shall%20have%20something%20more%20civilized%20to%20check%20missing%2Foptional%20parameters.%20Excel%20team%20has%20lot%20of%20feedback%20from%20pre-lambda%20stage%2C%20hope%20many%20of%20wishes%20will%20be%20implemented%20in%20v.1.0%20(or%202.0%20if%20exclude%20production%20from%20versioning).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2410179%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410179%22%20slang%3D%22en-US%22%3E%3CP%3EI%20haven't%20found%20as%20much%20time%20as%20I%20had%20hoped%20for%20to%20work%20with%20the%20Lambda%20editor.%26nbsp%3B%20How%20about%20everyone%20else%3F%26nbsp%3B%20I%20find%20the%20editor%20works%20well%20and%20both%20error%20checking%20and%20the%20context%20specific%20prompts%20also%20work%20well.%26nbsp%3B%20That%20said%2C%20I%20find%20there%20is%20a%20curious%20disconnect%20between%20the%20add-in's%20side%20panel%20and%20the%20worksheet%20formulas%20one%20is%20trying%20to%20construct.%26nbsp%3B%20I%20have%20yet%20to%20develop%20a%20work%20practice%20that%20allows%20me%20to%20progressively%20develop%20the%20formula%2C%20checking%20each%20step%20of%20the%20calculation%20as%20it%20is%20created.%26nbsp%3B%20When%20I%20am%20in%20a%20VBA%20environment%2C%20the%20ability%20to%20step%20through%20the%20calculation%20using%20F8%20is%20a%20lifesaver%20--%20which%20probably%20demonstrates%20my%20shortcomings%20as%20a%20coder.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20do%20wonder%20whether%20the%20environment%20for%20creating%20Lambda%20functions%20on%20the%20worksheet%20could%20also%20be%20improved.%26nbsp%3B%20After%20all%2C%20creating%20formula-local%20names%20using%20LET%20is%20now%20second%20nature.%26nbsp%3B%20Would%20it%20be%20possible%20to%20allow%20workbook-scoped%20names%20to%20be%20defined%20in%20a%20similar%20manner%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDoes%20anyone%20have%20insight%20as%20to%20the%20reason%20that%20the%20performance%20of%20the%20Lambda%20functions%20can%20be%20underwhelming%3F%26nbsp%3B%20It%20could%20simply%20be%20the%20lack%20of%2035%20years%20of%20optimisation%20but%20I%20also%20wonder%20whether%20the%20memory%20management%20required%20to%20support%20recursion%20is%20the%20source%20of%20problems.%26nbsp%3B%20Certainly%20Charles%20William's%20ACCUMULATE%20function%20was%20lightyears%20ahead%20in%20performance%20and%2C%20since%20converting%20flows%20to%20balances%20is%20so%20central%20to%20modelling%2C%20I%20would%20like%20to%20see%20it%20as%20an%20Excel%20built-in%20function.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETalking%20of%20FastExcel%2C%20Charles%20Williams%20has%20given%20me%20permission%20to%20upload%20a%20newly%20developed%20runtime%20version%20of%20the%20addin%2C%20if%20anyone%20is%20interested%20in%20trying%20it.%26nbsp%3B%20It%20appears%20that%20the%20addin%20and%20the%20Excel%20workbook%20should%20be%20packaged%20as%20a%20zipfile%20and%20used%20within%20the%20same%20folder%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2410838%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2410838%22%20slang%3D%22en-US%22%3ETrue%20to%20my%20word%2C%20I've%20gone%20through%20with%20the%20unary%20reworking%2C%20and%20I%20think%20the%20only%20reason%20I%20have%20the%20patience%20for%20it%20is%20because%20of%20the%20editor.%20I%20think%20there%20are%20some%20issues%20and%20bugs%2C%20but%20I've%20not%20made%20a%20concerted%20effort%20to%20catalog%20them%20methodically.%20And%20I've%20had%20my%20Windows%20crash%20this%20week%2C%20seemingly%20beyond%20repair%2C%20so%20I'm%20out%20of%20commission%20for%20a%20few%20more%20days.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20agree%20that%20it%20would%20be%20very%20nice%20to%20be%20able%20to%20step%20through%20much%20like%20in%20VBA%3B%20even%20having%20the%20Evaluate%20formula%20step-through%20would%20be%20a%20welcome%20improvement.%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20for%20performance%2C%20I%20would%20think%20it%20is%20probably%20due%20to%20the%20feature%20being%20strapped%20on%20rather%20than%20properly%20integrated.%20I%20also%20wonder%20if%20the%20Calc.ts%20work%20paves%20the%20way%20for%20this%20optimization%2C%20but%20may%20rely%20on%20being%20Javascript%2Fweb-based%2C%20and%20its%20not%20super%20compatible%20with%20legacy%20Excel%20recalc%20paradigm%3F%20Uneducated%20musings%20on%20my%20part.%3CBR%20%2F%3E%3CBR%20%2F%3EAnd%20I'd%20love%20to%20try%20out%20FastExcel%20once%20I%20get%20a%20working%20machine%20again!%20How%20do%20I%20sign%20up%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2414002%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2414002%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F933333%22%20target%3D%22_blank%22%3E%40tboulden%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPutting%20the%20ingredients%20together%20to%20create%20a%20slightly%20different%20dish!%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20Lambda%20editor%20and%20Calc.ts%20should%20be%20a%20pretty%20good%20fit.%26nbsp%3B%20The%20editor%20checks%20syntax%20but%20if%20that%20is%20OK%20why%20not%20a%20form%20to%20accept%20a%20set%20of%20test%20parameters%20and%20display%20results%20on%20a%20small%20grid%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%20for%20FastExcel%20it%20is%20possible%20to%20download%20a%20time%20limited%20test%20copy.%26nbsp%3B%20What%20I%20was%20suggesting%20was%20slightly%20different.%26nbsp%3B%20I%20would%20use%20my%20license%20to%20download%20a%20runtime%20version%20of%20the%20add-in%20and%20use%20zip%20to%20package%20it%20along%20with%20the%20Excel%20file%20for%20distribution.%26nbsp%3B%20Apparently%20the%20idea%20is%20that%20the%20add-in%26nbsp%3B%20works%20on%20the%20target%20machine%2C%20provided%20it%20is%20held%20in%20the%20same%20folder%20and%20the%20macro%20is%20run%20to%20load%20it%20on%20open.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2416323%22%20slang%3D%22en-US%22%3ERe%3A%20Ways%20of%20performing%20Accumulation%20with%20Dynamic%20Arrays%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2416323%22%20slang%3D%22en-US%22%3EAhh%2C%20that%20makes%20sense%20then%2C%20would%20love%20to%20see%20ACCUMULATE%20in%20action!%3CBR%20%2F%3E%3CBR%20%2F%3EI've%20got%20a%20new%20Windows%20install%20running%20in%20a%20VM%2C%20and%20I've%20still%20got%20access%20to%20LAMBDA%20and%20the%20LAMBDA%20editor%2C%20so%20more%20to%20come!%3C%2FLINGO-BODY%3E
Trusted Contributor

I would welcome your review of the following ideas, to identify errors, spot improvements or advise if I am following ideas that are already standard fare for others.  My objective is to develop a series of workbooks that are comprised entirely of dynamic arrays; no more 'and fill down'.  The problems I identified when DA first appeared were the problem of using dynamic arrays for accumulations without allowing circular references and problems handling 'arrays of arrays' (sum each column for example).  Recursion and lambda functions appear to offer a way forward, but I do not find it intuitive. 

 

image.png

 

"The purpose of the proposed approach is to accumulate a sequence of values as a dynamic array. Examples include the flow variables in a running balance or series returned from a difference equation. The key feature of the calculation is that each term depends upon the preceding value of the same array; this makes Excel report the calculation as a circular reference.

 

The calculation developed here uses recursion to work around this problem by exploiting the fact that the recursion introduces a new set of operands at every level of the stack. In order to avoid replicating the flow variables at every level of the recursion stack, they are passed as a lambda function rather than an array. A similar consideration also applies to the results. Rather than accumulating the results as they are calculated, assembly is left to the tail end of the calculation as control is returned back though the stack.

image.png

 

Unfortunately the obvious linear sequence of calls from term to term can easily fail because of the limit on the size of the operand stack.  In order to circumvent this problem, I have traversed the data as a binary tree, as shown in the figure. Although twice as many nodes are visited in such a scheme, the maximum levels of recursion for N values is log₂(N).

 

= LAMBDA(λfunction,startValue,r,p,n,
      IF(n>1,
         LET(
            ℓ, n - QUOTIENT(n,2),
            b₁, XACCλ(λfunction,startValue,r,p,ℓ),
            b₂, XACCλ(λfunction,MAX(b₁),r,p+ℓ,n-ℓ),
            balance, COMBINEλ(b₁, b₂),
           balance),
         λfunction(p)+(1+r)*startValue)
   )

 

I have tested the Lambda function for up to 16,000 terms (pretty much the width of an Excel sheet) and it has worked, but is slow. The approach took 15sec, more than 1000 times slower than Charles Williams's FastExcel paid add-in!  That said, for more reasonably sized timelines the calculation worked well.

 

Note: Other approaches to the accumulation of flow variables (sometimes known as corkscrews from the way a hand-calculation may be laid out) include the use of MMULT and SUMIFS. In each case, the idea is to calculate the balances directly from the flow variables without any recursive calls to previously calculated values. In the case of MMULT, the calculation requires an upper triangular matrix of 1's to be assembled. Although there is no formal limit of array size in Excel, 16000 x 16000 struck me as uncomfortably large."

39 Replies

@Charles Williams 

You may be pleased to know that your FastExcel functions absolutely thrashed recursion when it came to 16,000 time periods; but then it should.  I like VSTACK and HSTACK but, If I had to pick one function from your add-in it would be ACCUMULATE.

Very nice, @Peter Bartholomew! I went down a rabbit hole trying to use thunks and trampolining to get over the stack depth issue with recursion, but with little success. I think I may be misunderstanding something essential, however the examples all used a WHILE loop to prevent running out of stack and trying to replicate that with LAMBDA is self-defeating. This is an interesting approach with traversing a binary tree, will look at it in more depth.

 

On a related note: https://www.youtube.com/watch?v=7tFq-9Zvk3M Check 54:19 for Andy Gordon's fold implementation. Also, he mentions LAMBDA editor should be getting released to a small group early, and he invites folks to reach out if interested.

@tboulden 

Sorry, I appear to have missed some of your posts.

LAMBDA: Recursive Lists and Understanding Recursion Limits of LAMBDA - Microsoft Tech Community

You have been busy!  I still find the functional calculus notation pretty opaque.  Even where I think I understand the concept, expressing it in the lambda notation and manipulating the formula does not come naturally.

 

The idea of the binary tree evolved during the work.  At first my idea was simply to accumulate over single years and then nest the annual result to apply the formula to multiple years.  I then decided that it is not necessary to identify such natural grouping within the dataset and instead to simply bisect the it to the required depth.  Only then did I realise I do not need to actually split the array but, rather, I could merely pass a pointer and array length to the internal Lambda function.  The result was the binary tree but that wasn't in mind at the outset!

 

Thanks for the link to Andy Gordon's talk.  I had not seen some of the later material before and noted his invitation to make contact, but no contact details were provided.  Do you have an email address for Andy to request access to the Lambda editor?  I sent an email to the seminar organisers to forward so we will see what comes of that.

In addition Sergei's LinkedIn link, I used the microsoft.com address found here: https://www.microsoft.com/en-us/research/people/adg/.

@Peter Bartholomew 

Thanks for sharing, I will be able to test when LAMBDA goes live - whenever that will be...  I'm not familiar with the details but this appears to be similar to the pipelined binary tree section of Prefix sum - Wikipedia - all the more impressive that you have come up with this type of implementation independently.

 

As discussed elsewhere, I hope we get capability for running totals built in soon - functions like map, reduce, fold and scan have been mentioned in a recent MS research podcast.

@lori_mI tried to ask about map/fold/etc. timing as part of the YouTube livestream I linked to up-thread, however the moderator didn't include part 2 of my question, only the LAMBDA Playground/Editor was addressed. Perhaps if Andy replies to me about LAMBDA playground I can ask about the timing of those as well.

@tboulden @Sergei Baklan 

Thanks for the leads. I will give it a bit before following up to avoid the risk of duplication.

@lori_m 

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.

image.png 

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

image.png

give rise to the Fibonacci series.

 

I gather both you and @Sergei Baklan 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!

@Peter Bartholomew 

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.

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}

@lori_m 

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.

@Peter Bartholomew@lori_m 

 

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.

 

Sleep helped sort out the scan=reduceLeft & COMBINEλ problem; needed to update reduceLeft to have a check for AND(a=FALSE,TYPE(a)<>64) like in scanLeft and that worked! Maybe I'll get scan_tt today!

@tboulden 

I have downloaded your file and plan to work through it.  Some education regarding the higher-order functions will not go amiss! 

 

As things stand though, it is my belief that Excel still needs a high performance ACCUMULATE function as a built-in function in order to achieve the goal of fully-dynamic modelling with Excel.  Corkscrews represent a very common construct in financial modelling and suggesting the solution lies in recursive programming is not a way forward.

@Peter Bartholomew 

Great news! I got the LAMBDA Editor add-in as a beta-tester on Friday and have been re-working my original functions using the editor; I hope you were able to get on the list for it as well! Note that if you haven't, it works on same principle to your VBA solution, but with a proper editor and a few diffs. It loads its session data to a hidden sheet and you can export/import to JSON file. Not sure if this is best way for sharing, but will have to see.

 

I've also implemented @lori_m Fibonacci matrix calc example using scan from above (see "Examples" tab). I'm starting to see how powerful fold can be, I've implemented my reduce/scan functions leveraging fold as the workhorse. And you can do lots of other tasks just by providing the right function to fold/reduce/scan. Will update later with more of these extended examples.

@tboulden 

I got as far as the point of  making registry changes but was struggling with the installation process so I will return to the task when I get some more time.  What you have achieved is pretty amazing; have you come across these higher order functions before in other coding contexts?  Something that completely threw me was the output from Paste Names

image.png

I was at a loss to follow the syntax!

Fortunately the JKP name manager worked a bit better (tried that today)

image.png

The comment block appears to have been highjacked for some technical purpose!  Nothing appears as a prompt when writing formulas containing Lambda functions.

@tboulden 

(... continued)

As an aside, I added the Greek λs simply as a flag to assist me in reading the formulas.  I also note that you appear to have tidied up the MAKEARRAY function and I recognise the code fragments showing where you have incorporated the binary tree.

Looking at the amortisation problem, I note that you have calculated the repayment using the PMT function at each step of the calculation.  I think this opens up the possibility of taking interest rate variability into account with the repayment being adjusted based on the remaining repayment period and the outstanding balance.

Overall, I have some serious work to do to try to keep up with you!

@Peter BartholomewSorry to hear about the difficulties with the LAMBDA editor install! To answer your question, I've not had any "functional" experience prior to this; I put it in scare quotes because I think I'm using functional ingredients in an imperative style. I get stuck on something and step away, then come back excited again when someone shows me something that I didn't think of! Then I learn until my tools can't fix what I've built and step away again! Case in point: I promised extended examples using fold, and they are attached, however they've shown me there is a bug in my approach and I can't resolve it. I'm inclined to leave init as blank, but my logic doesn't handle it well and it bloats my result; I think I've seen having a "natural zero" for the initial value, but I think some of the helper functions for my folds may not have one. I'm about ready to start from scratch again since I think my commitment to my recent progress is hindering my continued progress.