Function Repository Resource:

AdditivePersistence

Source Notebook

Compute the additive persistence, in any base, of an integer

Contributed by: Christopher Stover

ResourceFunction["AdditivePersistence"][n,b]

gives the additive persistence of the non-negative integer n when expressed in the base b.

ResourceFunction["AdditivePersistence"][n]

gives the base-10 additive persistence of n.

Details

Starting with a non-negative integer n, add its base-b digits, then add the digits of the resulting number, etc., until the result has only one digit. The number of additions required to reach the single digit stopping point is called the additive persistence of n.
As an example in base-10, consider n=1191:
Adding its digits yields 1+1+9+1=12.
Adding the digits of the result yields 1+2=3. Because 3 is a single-digit number, the process stops.
Because it took two steps to reach the stopping point, ResourceFunction["AdditivePersistence"][1191] returns 2.
ResourceFunction["AdditivePersistence"] threads elementwise over lists.

Examples

Basic Examples (2) 

Find the additive persistence of 1191:

In[1]:=
ResourceFunction["AdditivePersistence"][1191]
Out[1]=

Carrying out the iterated digit sum confirms this result:

In[2]:=
NestWhileList[Plus @@ IntegerDigits[#] &, 1191, # >= 10 &]
Out[2]=

Compute the additive digital root of 1899, base-14:

In[3]:=
ResourceFunction["AdditivePersistence"][1899, 14]
Out[3]=

Scope (2) 

AdditivePersistence threads elementwise over lists:

In[4]:=
listIn = {1234, 54321, 66677, 8989109898};
ResourceFunction["AdditivePersistence"][listIn]
Out[5]=
In[6]:=
ResourceFunction["AdditivePersistence"][listIn, 5]
Out[6]=

Compute the additive persistence of the first 100 integers (OEIS A031286):

In[7]:=
ResourceFunction["AdditivePersistence"] /@ Range[0, 99]
Out[7]=

Properties and Relations (3) 

The result returned by AdditivePersistence can be iteratively computed using NestWhileList:

In[8]:=
With[{n = RandomInteger[10^9], b = RandomInteger[{2, 20}]}, ResourceFunction["AdditivePersistence"][n, b] == Length[NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= b &]] - 1]
Out[8]=

The single-digit integer that marks the end of the digit addition process is called the additive digital root and is returned by the resource function AdditiveDigitalRoot:

In[9]:=
n = RandomInteger[10^7]
Out[9]=
In[10]:=
list = NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= 10 &]
Out[10]=
In[11]:=
ResourceFunction["AdditivePersistence"][n] == Length[list] - 1
Out[11]=
In[12]:=
ResourceFunction["AdditiveDigitalRoot"][n] == list[[-1]]
Out[12]=

The multiplicative analogue of additive persistence is called multiplicative persistence and is returned by the resource function MultiplicativePersistence:

In[13]:=
n = RandomInteger[10^7]
Out[13]=
In[14]:=
{add, mult} = Function[f, NestWhileList[f @@ IntegerDigits[#] &, n, # >= 10 &]] /@ {Plus, Times}
Out[14]=
In[15]:=
ResourceFunction["MultiplicativePersistence"][n] == Length[mult] - 1
Out[15]=

Possible Issues (1) 

AdditivePersistence requires its input to be non-negative:

In[16]:=
ResourceFunction["AdditivePersistence"][-234545]
Out[16]=

Neat Examples (1) 

The smallest integers with (base-10) additive persistences equal to 0,1,2,3,4, (OEIS A006050) are:

In[17]:=
ResourceFunction[
 "AdditivePersistence"][{0, 10, 19, 199, 19999999999999999999999}]
Out[17]=

The smallest integer with additive persistence 5 is known to equal 1 followed by 2222222222222222222222 9’s.

Version History

  • 1.1.0 – 25 May 2023
  • 1.0.0 – 09 August 2022

Related Resources

Author Notes

Future versions of this will likely contain expansion to allow for integers in bases other than 10.

License Information