Function Repository Resource:

AdditiveDigitalRoot

Source Notebook

Compute the additive digital root, in any base, of an integer

Contributed by: Christopher Stover

ResourceFunction["AdditiveDigitalRoot"][n,b]

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

ResourceFunction["AdditiveDigitalRoot"][n]

gives the base-10 additive digital root 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 one-digit integer marking the stopping point of this process is called the additive digital root 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 the integer marking the termination of the process is 3, ResourceFunction["AdditiveDigitalRoot"][1191] returns 3.
The additive digital root is sometimes called the digital root (sans "additive"), and is denoted drb(n). It is also sometimes referred to as the repeated digital sum of n.
ResourceFunction["AdditiveDigitalRoot"] threads elementwise over lists.

Examples

Basic Examples (2) 

Compute the additive digital root of 1191:

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

Compute the additive digital root of 182, base-14 (note that the result has two digits base-10, but only a single base-14 digit):

In[2]:=
ResourceFunction["AdditiveDigitalRoot"][182, 14]
Out[2]=

Scope (2) 

AdditiveDigitalRoot threads elementwise over lists:

In[3]:=
listIn = {1234, 54321, 66677, 8989109898};
ResourceFunction["AdditiveDigitalRoot"][listIn]
Out[4]=
In[5]:=
ResourceFunction["AdditiveDigitalRoot"][listIn, 7]
Out[5]=

Compute the base-10 additive digital roots of the first 100 integers (OEIS A010888):

In[6]:=
ResourceFunction["AdditiveDigitalRoot"] /@ Range[0, 99]
Out[6]=

Properties and Relations (5) 

The additive digital root can be computed iteratively using NestWhile:

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

The additive digital root can be computed using Floor:

In[8]:=
With[{n = RandomInteger[10^9], b = RandomInteger[{2, 20}]}, ResourceFunction["AdditiveDigitalRoot"][n, b] == n - (b - 1) Floor[(n - 1)/(b - 1)]]
Out[8]=

There is a well-known closed formula for the additive digital root in terms of Mod:

In[9]:=
With[{n = RandomInteger[10^9], b = RandomInteger[{2, 20}]}, ResourceFunction["AdditiveDigitalRoot"][n, b] == Mod[n, b - 1, 1]]
Out[9]=

The number of iterations required to reach the end of the digit addition process is called the additive persistence and is returned by the resource function AdditivePersistence:

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

The multiplicative analogue of the additive digital root is called the multiplicative digital root and is returned by the resource function MultiplicativeDigitalRoot:

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["MultiplicativeDigitalRoot"][n] == mult[[-1]]
Out[15]=

Possible Issues (1) 

AdditiveDigitalRoot requires its input to be non-negative:

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

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