Function Repository Resource:

BinomialNumberSystemTriplet

Source Notebook

Represent a non-negative integer as the sum of three binomial coefficients

Contributed by: Shenghui Yang

ResourceFunction["BinomialNumberSystemTriplet"][n]

returns an ordered non-negative triplet {a,b,c} such that n=Binomial[a,1]+Binomial[b,2]+Binomial[c,3] and 0<=a<b<c.

Details

This number system is known as the binomial number system (BNS) involving three items.
The uniqueness of this representation comes from the requirement that the elements in the triplets are ordered.

Examples

Basic Examples (2) 

Find the binomial number representation for the first twenty integers:

In[1]:=
ResourceFunction["BinomialNumberSystemTriplet"][#] & /@ Range[20]
Out[1]=

Find the binomial number representation for a larger non-negative integer:

In[2]:=
ResourceFunction["BinomialNumberSystemTriplet"][123456789]
Out[2]=

Verify that the following sum gives back the original input:

In[3]:=
(Binomial[#, 1] + Binomial[#2, 2] + Binomial[#3, 3]) & @@ %
Out[3]=

Scope (1) 

By determining a tight bound for each item in the triplet before initiating the solution search, the internal algorithm allows the function to process large inputs efficiently:

In[4]:=
AbsoluteTiming[
 res = ResourceFunction["BinomialNumberSystemTriplet"][10^200]]
Out[4]=
In[5]:=
Log10[(Binomial[#, 1] + Binomial[#2, 2] + Binomial[#3, 3]) & @@ res]
Out[5]=

Properties and Relations (4) 

There is a unique representation for zero:

In[6]:=
ResourceFunction["BinomialNumberSystemTriplet"][0]
Out[6]=

It is based on the fact that Binomial[n,k] vanishes for integers n and k such that n<k:

In[7]:=
Binomial[2, 3]
Out[7]=

For those input values exactly equal to Binomial[k,3], the returned triplets always begin with a=0 and b=1:

In[8]:=
ResourceFunction["BinomialNumberSystemTriplet"][Binomial[99, 3]]
Out[8]=

For integers from 1 to n, the subsequence formed by numbers with a=1 in the binomial number representation is OEIS A126862:

In[9]:=
With[{res = Map[ResourceFunction["BinomialNumberSystemTriplet"], Range[300]]}, Position[res[[All, 1]], 1] // Flatten]
Out[9]=
In[10]:=
ResourceFunction["OEISSequenceData"]["A126862"]
Out[10]=

The ResourceFunction SubsetFromIndex uses a similar algorithm:

In[11]:=
Table[ResourceFunction["SubsetFromIndex"][index, 3], {index, 1, 21}]
Out[11]=
In[12]:=
ResourceFunction["BinomialNumberSystemTriplet"][#] & /@ Range[0, 20]
Out[12]=

Possible Issues (2) 

The input must be a non-negative integer. Otherwise the function returns unevaluated:

In[13]:=
{ResourceFunction["BinomialNumberSystemTriplet"][-100], ResourceFunction["BinomialNumberSystemTriplet"][7.777]}
Out[13]=

The uniqueness of the representation is lost if {a,b,c} is not strictly increasing:

In[14]:=
{ToRules@
   Reduce[60 == x + y*(y - 1)/2 + z*(z - 1)*(z - 2)/6, {x, y, z}, NonNegativeIntegers]} // Short
Out[14]=

Imposing the order ensures that the solution is unique. For instance:

In[15]:=
ToRules@Reduce[
  60 == x + y*(y - 1)/2 + z*(z - 1)*(z - 2)/6 && x < y < z, {x, y, z},
   NonNegativeIntegers]
Out[15]=
In[16]:=
ResourceFunction["BinomialNumberSystemTriplet"][60]
Out[16]=

Neat Examples (2) 

Visualize the "digit sum" of the binomial number representation for some non-negative integers:

In[17]:=
ListPlot[
 Total[ResourceFunction["BinomialNumberSystemTriplet"] /@ Range[Binomial[17, 3] - 1], {2}], PlotHighlighting -> None]
Out[17]=

A graphic for the progression of triples:

In[18]:=
Graphics3D[
 Line[ResourceFunction["BinomialNumberSystemTriplet"][#] & /@ Range[60]]]
Out[18]=

Publisher

Shenghui Yang

Version History

  • 1.0.0 – 16 June 2025

Source Metadata

Related Resources

Author Notes

According to the cited paper by Borysenko, O.; Matsenko, S.; and Bobrovs, V., Binomial Number System, the binomial number system is not limited to three terms; it can be generalized to k-BNS, where k denotes the number of binomial coefficients used in the representation.

License Information