On the Zeroes of the Riemann Zeta Function using Von Mangoldt function
Recently I was watching a Numberphile about the solution to the Riemann Hypothesis (RH). This was the video: EET324 Class 24
One thing intrigued me when the author was talking about the explanation of the RH using the Von Mangoldt function, in particular I saw this part of the video:
There is a way to implement this function and get to an alternative view of the RH. I decided to implement the Van Mangoldt function, using some simple techniques (Sieve, Binary Search, and so on). No GAI used. The interesting part is that this number in the chart below should have an upper bound of 1/2 (green light) when X goes to infinite. Hard to see in this small example (100k), but if the calculations are right in my code and the RH is true, it will continue as an upper bound. This is the famous 1/2 line in the RH. Code down below, cheers, ACC.
using System;
using System.CodeDom;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RH
{
internal class Program
{
static List primes = null;
static void SieveOfEratosthenes(int bound)
{
bool[] notPrimes = new bool[bound + 1];
notPrimes[0] = true;
notPrimes[1] = true;
for (int i = 2; i <= Math.Sqrt(bound); i++)
{
for (int j = 2; i * j <= bound; j++)
{
notPrimes[i * j] = true;
}
}
primes = new List();
for (int i = 0; i <= bound; i++)
if (!notPrimes[i]) primes.Add(i);
}
static int[] FindClosestPrimesBinarySearch(double n)
{
//Corner cases
if (n < primes[0]) return new int[] { primes[0], primes[0] };
if (n > primes[primes.Count - 1]) return new int[] { primes[primes.Count - 1], primes[primes.Count - 1] };
//Binary Search
int left = 0;
int right = primes.Count - 1;
while (left < right)
{
int middle = (left + right) / 2;
double primeVal = primes[middle];
if (IsZero(primeVal - n)) return new int[] { primes[middle], primes[middle] };
if (n > primeVal) left = middle + 1;
else right = middle - 1;
}
int[] retVal = new int[2];
if (left == right && IsZero(primes[left] - n))
{
retVal[0] = primes[left];
retVal[1] = primes[left];
}
else if (n > primes[left])
{
retVal[0] = primes[left];
retVal[1] = primes[left + 1 < primes.Count ? left + 1 : left];
}
else
{
retVal[0] = primes[left - 1 >= 0 ? left - 1 : left];
retVal[1] = primes[left];
}
return retVal;
}
static bool IsZero(double n)
{
return Math.Abs(n) <= 0.00001;
}
static int IsPowerOfPrime(int power, int baseNumber)
{
double root = Math.Pow(baseNumber, 1.0 / power);
int[] closePrimes = FindClosestPrimesBinarySearch(root);
foreach (int prime in closePrimes)
{
if((int)Math.Pow(prime, power) == baseNumber)
return prime;
}
return -1;
}
static double VonMangoldtFunction(int input)
{
double val = 0.0;
for (int power = 1; power <= 20; power++)
{
int potentialPrime = IsPowerOfPrime(power, input);
if (potentialPrime != -1)
{
val = Math.Log(potentialPrime);
break;
}
}
return val;
}
static void RiemannHypothesisAnalysis()
{
int MAX_X = 100000;
double sumVonMangoldt = 0;
Console.WriteLine("X;Sum Von Mangoldt(X);RX;ZeroesZetaFunction");
for (int x = 2; x <= MAX_X; x++)
{
double vonMangoldtVal = VonMangoldtFunction(x);
sumVonMangoldt += vonMangoldtVal;
double rx = sumVonMangoldt - x;
double logRx = Math.Log(Math.Abs(rx));
double logX = Math.Log(x);
double zeroesZetaFunction = logRx / logX;
Console.WriteLine("{0};{1};{2};{3}", x, sumVonMangoldt, rx, zeroesZetaFunction);
}
}
static void Main(string[] args)
{
SieveOfEratosthenes(100000);
RiemannHypothesisAnalysis();
}
}
}


Comments
Post a Comment