Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate the Ulam matrix
| ResourceFunction["UlamMatrix"][n] returns the n×n Ulam matrix. | 
A 5×5 Ulam matrix:
| In[1]:= | ![ResourceFunction["UlamMatrix"][5]](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/5e22fdd1da81f61a.png) | 
| Out[1]= |  | 
Visualize a large Ulam matrix:
| In[2]:= | ![MatrixPlot[ResourceFunction["UlamMatrix"][90]]](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/38ae652c90d5adb8.png) | 
| Out[2]= |  | 
Show the same matrix mod 7:
| In[3]:= | ![MatrixPlot[Mod[ResourceFunction["UlamMatrix"][90], 7]]](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/1d60cd644e5564ab.png) | 
| Out[3]= |  | 
By default, an exact matrix is computed:
| In[4]:= | ![ResourceFunction["UlamMatrix"][4] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/23a9797fd8960428.png) | 
| Out[4]= |  | 
Use machine precision:
| In[5]:= | ![ResourceFunction["UlamMatrix"][4, WorkingPrecision -> MachinePrecision] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/36bfa324afd89524.png) | 
| Out[5]= |  | 
Use arbitrary precision:
| In[6]:= | ![ResourceFunction["UlamMatrix"][4, WorkingPrecision -> 20] // MatrixForm](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/61eeec150470da29.png) | 
| Out[6]= |  | 
Mark the positions of prime numbers in the Ulam matrix and visualize the result:
| In[7]:= | ![ArrayPlot[
 Map[Boole@*PrimeQ, ResourceFunction["UlamMatrix"][399], {2}]]](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/7772d89c24eb642c.png) | 
| Out[7]= |  | 
Color numbers in the Ulam matrix by the number of their divisors:
| In[8]:= | ![MatrixPlot[
 Map[Length@*Divisors, ResourceFunction["UlamMatrix"][199], {2}], ColorFunction -> (ColorData[61, Clip[#, {0, 9}]] &), ColorFunctionScaling -> False]](https://www.wolframcloud.com/obj/resourcesystem/images/b6e/b6e95a00-03dd-4248-831c-b86503e58d43/1ec59a4871d51aaa.png) | 
| Out[8]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License