Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Replace each element of a list with the sum of the elements in the original list that are not to the left of that element
ResourceFunction["ReverseAccumulate"][list] computes the successive accumulated totals of list, proceding from right to left. |
Get the sum of elements not to the left of each element in a list:
In[1]:= |
Out[1]= |
Apply ReverseAccumulate to a symbolic array:
In[2]:= |
Out[2]= |
Actuarial computations sometimes depend on nested ReverseAccumulate operations:
In[3]:= |
Out[3]= |
The Head of an expression does not need to be List for ReverseAccumulate to work:
In[4]:= |
Out[4]= |
Where the argument is a nested list, X, ReverseAccumulate creates a nested list Y of similar dimension in which Y[[i,j]]=ReverseAccumulate[X[[All,j]]][[i]]:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
Compute the values of the actuarial commutation function S for a survival list and an annual discount value of 0.8:
In[7]:= |
Out[7]= |
The ReverseAccumulate of a list is equivalent to the Reverse of the Accumulate of the Reverse of the list:
In[8]:= |
Out[8]= |
One can generalize the idea of ReverseAccumulate to include operations that do not involve addition:
In[9]:= |
In[10]:= |
Out[10]= |
Indeed, ReverseAccumulate is a special case of the following RightFoldList:
In[11]:= |
Out[11]= |
This work is licensed under a Creative Commons Attribution 4.0 International License