How to resolve the algorithm Meissel–Mertens constant step by step in the PARI/GP programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Meissel–Mertens constant step by step in the PARI/GP programming language

Table of Contents

Problem Statement

Calculate Meissel–Mertens constant up to a precision your language can handle.

Analogous to Euler's constant, which is important in determining the sum of reciprocal natural numbers, Meissel-Mertens' constant is important in calculating the sum of reciprocal primes.

We consider the finite sum of reciprocal natural numbers: 1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n this sum can be well approximated with: log(n) + E where E denotes Euler's constant: 0.57721... log(n) denotes the natural logarithm of n.

Now consider the finite sum of reciprocal primes: 1/2 + 1/3 + 1/5 + 1/7 + 1/11 ... 1/p this sum can be well approximated with: log( log(p) ) + M where M denotes Meissel-Mertens constant: 0.26149...

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Meissel–Mertens constant step by step in the PARI/GP programming language

Source code in the pari/gp programming language

{
MM(t)=
  my(s=0);
  forprime(p = 2, t,
    s += log(1.-1./p)+1./p
  );
  Euler+s
};

{
Meissel_Mertens(d)=
  default(realprecision, d);
  my(prec = default(realprecision), z = 0, y = 0, q);
  forprime(p = 2 , 7, 
    z += log(1.-1./p)+1./p
  );
  for(k = 2, prec,
    q = 1;
    forprime(p = 2, 7, 
      q *= 1.-p^-k
    );
    y += moebius(k)*log(zeta(k)*q)/k
  );
  Euler+z+y
};

  

You may also check:How to resolve the algorithm Padovan n-step number sequences step by step in the Sidef programming language
You may also check:How to resolve the algorithm First class environments step by step in the REXX programming language
You may also check:How to resolve the algorithm Strip control codes and extended characters from a string step by step in the Lua programming language
You may also check:How to resolve the algorithm String length step by step in the Elixir programming language
You may also check:How to resolve the algorithm Extreme floating point values step by step in the Pascal programming language