Wolfram Research

Function Repository Resource:

GenerateSmoothNumbers

Source Notebook

Generate smooth numbers up to some maximum

Contributed by: Sander Huisman

ResourceFunction["GenerateSmoothNumbers"][max]

generates all positive integers up to max whose prime factors are equal to or less than 7.

ResourceFunction["GenerateSmoothNumbers"][max,p]

generates all positive integers up to max whose prime factors are equal to or less than p.

Details

ResourceFunction["GenerateSmoothNumbers"][max,p] generates p-smooth numbers.
ResourceFunction["GenerateSmoothNumbers"][max] generates the so-called humble numbers.

Examples

Basic Examples (2) 

Generate the numbers up to 100 that have factors that are 13 or less:

In[1]:=
ResourceFunction["GenerateSmoothNumbers"][100, 13]
Out[1]=

Generate the numbers up to 100 that have factors that are 7 or less—so-called humble numbers:

In[2]:=
ResourceFunction["GenerateSmoothNumbers"][100]
Out[2]=

Scope (2) 

The second argument does not have to be an integer:

In[3]:=
gen = ResourceFunction["GenerateSmoothNumbers"][10^3, 6.5]
Out[3]=

Check that the prime factors are all below 6.5:

In[4]:=
Union[Flatten[FactorInteger[#][[All, 1]] & /@ gen]]
Out[4]=

Properties and Relations (2) 

Smooth numbers can be found by sieving:

In[5]:=
ResourceFunction["GenerateSmoothNumbers"][10^5, 7] == Select[Range[10^5], FactorInteger[#][[-1, 1]] <= 7 &]
Out[5]=

The algorithm used by GenerateSmoothNumbers is much faster though:

In[6]:=
{AbsoluteTiming[ResourceFunction["GenerateSmoothNumbers"][10^5, 7];], AbsoluteTiming[
  Select[Range[10^5], FactorInteger[#][[-1, 1]] <= 7 &];]}
Out[6]=

Neat Examples (1) 

The argument of GenerateSmoothNumbers can be really large—much larger than practical for a method based on sieving:

In[7]:=
ResourceFunction["GenerateSmoothNumbers"][10^50] // Length
Out[7]=

Resource History

Related Resources

License Information