Wolfram Research

Function Repository Resource:

AdditiveDigitalRoot (1.0.0) current version: 1.1.0 »

Source Notebook

Compute the additive digital root of an integer

Contributed by: Christopher Stover

ResourceFunction["AdditiveDigitalRoot"][n]

returns the additive digital root of n.

Details

Starting with a non-negative integer n, add its 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, 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 of a non-negative integer n is sometimes called its digital root (sans "additive"), which is denoted dr(n). It is also sometimes referred to as the repeated digital sum of n.
ResourceFunction["AdditiveDigitalRoot"] threads elementwise over lists.

Examples

Basic Examples (1) 

Compute the additive digital root of 1191:

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

Scope (2) 

AdditiveDigitalRoot threads elementwise over lists:

In[2]:=
ResourceFunction["AdditiveDigitalRoot", ResourceVersion->"1.0.0"][{1234, 54321, 66677, 8989109898}]
Out[2]=

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

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

Properties and Relations (5) 

The result returned by AdditiveDigitalRoot can be manually computed using NestWhileList:

In[4]:=
With[{n = 8675309}, ResourceFunction["AdditiveDigitalRoot"][n] == NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= 10 &][[-1]]]
Out[4]=

There is a well-known closed formula for the additive digital root:

In[5]:=
With[{n = RandomInteger[{10^6, 10^9}]}, ResourceFunction["AdditiveDigitalRoot"][n] == 1 + Mod[n - 1, 9]]
Out[5]=

The additive digital root of an integer can also be manually computed with no high-level functions:

In[6]:=
testint1 = 1234
Out[6]=
In[7]:=
digits1 = IntegerDigits[testint1]
Out[7]=
In[8]:=
testint2 = Plus @@ digits1
Out[8]=
In[9]:=
digits2 = IntegerDigits[testint2]
Out[9]=
In[10]:=
testint3 = Plus @@ digits2
Out[10]=

Because testint3 is a single-digit integer, the process terminates here, and because testint3 equals 1, the additive digital root of testint1=1234 is equal to 1:

In[11]:=
ResourceFunction["AdditiveDigitalRoot"][testint1]
Out[11]=

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[12]:=
n = 13579
Out[12]=
In[13]:=
list = NestWhileList[Plus @@ IntegerDigits[#] &, n, # >= 10 &]
Out[13]=
In[14]:=
ResourceFunction["AdditiveDigitalRoot"][n] == list[[-1]]
Out[14]=
In[15]:=
ResourceFunction["AdditivePersistence"][n] == Length[list] - 1
Out[15]=

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

In[16]:=
n2 = 2111971
Out[16]=
In[17]:=
{add, mult} = Function[f, NestWhileList[f @@ IntegerDigits[#] &, n2, # >= 10 &]] /@ {Plus, Times}
Out[17]=
In[18]:=
ResourceFunction["AdditiveDigitalRoot"][n2] == add[[-1]]
Out[18]=
In[19]:=
ResourceFunction["MultiplicativeDigitalRoot"][n2] == mult[[-1]]
Out[19]=

Possible Issues (1) 

AdditiveDigitalRoot requires its input to be non-negative:

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

Publisher

therealcstover

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