Function Repository Resource:

UlamSequence

Source Notebook

Starting with the third term, give the least integer expressible uniquely as the sum of two distinct earlier terms

Contributed by: Wolfram Staff

ResourceFunction["UlamSequence"][n,{u,v}]

gives the sequence starting with u,v, continuing up to at most n, where the general term is the least integer greater than the previous term that is expressible uniquely as the sum of two distinct earlier terms.

Details and Options

The sequence consists of all possible terms up to n, the first argument.

Examples

Basic Examples (2) 

Let u=1 and v=1. Call the sequence sn. Then s1=1 and s2=2 :

In[1]:=
ResourceFunction["UlamSequence"][2, {1, 2}]
Out[1]=

For term 3, there is only one sum, 3=1+2, so s3=3 :

In[2]:=
ResourceFunction["UlamSequence"][3, {1, 2}]
Out[2]=

For term 4, only the sum 1+3 gives 4, so s4=4. The sum 2+2 is not a sum of unique previous terms:

In[3]:=
ResourceFunction["UlamSequence"][4, {1, 2}]
Out[3]=

For term 5, the two sums 1+4 and 2+3 give 5, so s5 5 . The sum 2+4 is 6; the sum 1+2+3=6 has more than one summand, so s5=6:

In[4]:=
ResourceFunction["UlamSequence"][6, {1, 2}]
Out[4]=

Here are the terms up to 1000:

In[5]:=
ResourceFunction["UlamSequence"][1000, {1, 2}]
Out[5]=

The plot is wrinkly:

In[6]:=
ListLinePlot[%]
Out[6]=

Scope (2) 

This sequence starts with 1, 3 instead of 1, 2:

In[7]:=
ResourceFunction["UlamSequence"][1000, {1, 3}]
Out[7]=

More wrinkles:

In[8]:=
ListLinePlot@%
Out[8]=

Publisher

George Beck

Requirements

Wolfram Language 11.3 (March 2018) or above

Version History

  • 1.0.0 – 12 April 2019

License Information