How to resolve the algorithm Euclid-Mullin sequence step by step in the Mathematica/Wolfram Language programming language

Published on 22 June 2024 08:30 PM

How to resolve the algorithm Euclid-Mullin sequence step by step in the Mathematica/Wolfram Language programming language

Table of Contents

Problem Statement

The Euclid–Mullin sequence is an infinite sequence of distinct prime numbers, in which each element is the least prime factor of one plus the product of all earlier elements. The first element is usually assumed to be 2. So the second element is : (2) + 1 = 3 and the third element is : (2 x 3) + 1 = 7 as this is prime. Although intermingled with smaller elements, the sequence can produce very large elements quite quickly and only the first 51 have been computed at the time of writing. Compute and show here the first 16 elements of the sequence or, if your language does not support arbitrary precision arithmetic, as many as you can. Compute the next 11 elements of the sequence. OEIS sequence A000945

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Euclid-Mullin sequence step by step in the Mathematica/Wolfram Language programming language

Overview:

This Wolfram code generates a list of integers and performs certain operations on them.

Implementation:

  1. Initialization:

    • list = {2}: Initializes a list containing a single element, which is 2.
  2. For Loop:

    • Do[... , {21 - 1}]: Executes the following block of code 20 times, from 1 to 20 (excluding 21).
  3. Operations Inside the Loop:

    • prod = Times @@ list: Calculates the product of all elements in the list.
    • prod++: Increments the prod by 1.
    • new = Min[FactorInteger[prod][[All, 1]]];:
      • FactorInteger[prod]: Factors the prod into its prime factors.
      • [[All, 1]]: Extracts the smallest prime factor.
      • Min[]: Gets the minimum of the extracted prime factor.
    • AppendTo[list, new]: Adds the new value to the list.
  4. Output:

    • list: After the loop completes, the code prints the final value of the list.

Explanation:

The code starts by initializing a list with a single element, 2. It then iteratively generates a sequence of integers by performing the following operations:

  1. Multiplies all elements in the list to get the prod.
  2. Increments prod by 1.
  3. Factors prod into prime factors and takes the smallest one (new).
  4. Adds new to the list.

This process is repeated 20 times. The resulting list contains the sequence 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71.

Source code in the wolfram programming language

list = {2};
Do[
  prod = Times @@ list;
  prod++;
  new = Min[FactorInteger[prod][[All, 1]]];
  AppendTo[list, new]
  ,
  {21 - 1}
  ];
list


  

You may also check:How to resolve the algorithm Animate a pendulum step by step in the Clojure programming language
You may also check:How to resolve the algorithm Sort numbers lexicographically step by step in the MiniScript programming language
You may also check:How to resolve the algorithm Repeat a string step by step in the Euphoria programming language
You may also check:How to resolve the algorithm Cholesky decomposition step by step in the Ada programming language
You may also check:How to resolve the algorithm Create an object at a given address step by step in the Raku programming language