Blog Entry Monday, July 15, 2024, (c) James Pate Williams, Jr. Some Values of the Riemann Zeta Function Computed with Fast and Very Slow Algorithms

The slow computations used 999,999,999 terms. I seem to recall from my first numerical analysis (Scientific Computing I) course in the Mathematics Department at the Georgia Institute of Technology with Professor Gunter Meyer in the Summer of 1982 that computing a truncated infinite series is more accurate to start with the smallest terms.

// RiemannZetaFunctionWin32Console.c (c) Saturday, July 13-15, 2024
// James Pate Williams, Jr. some computations use 999,999,998 terms

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

typedef signed long long sll;

// https://en.wikipedia.org/wiki/Particular_values_of_the_Riemann_zeta_function#cite_note-7

long double EvenZeta(int n)
{
    sll A[12] = { 0ll,
        6ll, 90ll, 945ll, 9450ll, 93555ll, 638512875ll,
        18243225ll, 325641566250ll, 38979295480125ll,
        1531329465290625ll, 13447856940643125ll };
    sll B[12] = { 0ll, 1ll, 1ll, 1ll, 1ll, 1ll, 691ll, 2ll,
        3617ll, 43867ll, 174611ll, 155366ll };
    long double pi = 4.0 * atan(1.0);

    return (long double)B[n / 2] * powl(pi, n) / (long double)A[n / 2];
}

long double Zeta(long s, long *terms)
{
    int n = 0;
    long double sum = 0.0;

    *terms = 0;

    for (n = 1000000000; n >= 2; n--)
    {
        sum += 1.0 / powl(n, s);
        (*terms)++;
    }

    return sum + 1.0;
}

void PrintEvenZetaValue(int n)
{
    clock_t time0 = clock();
    long double ez = EvenZeta(n);
    clock_t time1 = clock();
    double runtime = ((double)time1 - time0) / CLOCKS_PER_SEC;
    printf_s("Runtime in seconds to compute Zeta(%ld) = %16.15Lf: %Lf\n",
        n, ez, runtime);
}

void PrintZetaValue(int n)
{
    clock_t time0 = clock();
    long terms = 0;
    long double zeta = Zeta(n, &terms);
    clock_t time1 = clock();
    double runtime = ((double)time1 - time0) / CLOCKS_PER_SEC;
    printf_s("Runtime in seconds to compute Zeta(%ld) = %16.15Lf terms = %ld: time = %Lf\n",
        n, zeta, terms, runtime);
}

int main()
{
    PrintEvenZetaValue(2);
    PrintEvenZetaValue(4);
    PrintEvenZetaValue(6);
    PrintEvenZetaValue(8);
    PrintZetaValue(2);
    PrintZetaValue(4);
    PrintZetaValue(6);
    PrintZetaValue(8);
    PrintZetaValue(3);
    PrintZetaValue(5);
    PrintZetaValue(7);
    PrintZetaValue(9);
    return 0;
}
Unknown's avatar

Author: jamespatewilliamsjr

My whole legal name is James Pate Williams, Jr. I was born in LaGrange, Georgia approximately 70 years ago. I barely graduated from LaGrange High School with low marks in June 1971. Later in June 1979, I graduated from LaGrange College with a Bachelor of Arts in Chemistry with a little over a 3 out 4 Grade Point Average (GPA). In the Spring Quarter of 1978, I taught myself how to program a Texas Instruments desktop programmable calculator and in the Summer Quarter of 1978 I taught myself Dayton BASIC (Beginner's All-purpose Symbolic Instruction Code) on LaGrange College's Data General Eclipse minicomputer. I took courses in BASIC in the Fall Quarter of 1978 and FORTRAN IV (Formula Translator IV) in the Winter Quarter of 1979. Professor Kenneth Cooper, a genius poly-scientist taught me a course in the Intel 8085 microprocessor architecture and assembly and machine language. We would hand assemble our programs and insert the resulting machine code into our crude wooden box computer which was designed and built by Professor Cooper. From 1990 to 1994 I earned a Bachelor of Science in Computer Science from LaGrange College. I had a 4 out of 4 GPA in the period 1990 to 1994. I took courses in C, COBOL, and Pascal during my BS work. After graduating from LaGrange College a second time in May 1994, I taught myself C++. In December 1995, I started using the Internet and taught myself client-server programming. I created a website in 1997 which had C and C# implementations of algorithms from the "Handbook of Applied Cryptography" by Alfred J. Menezes, et. al., and some other cryptography and number theory textbooks and treatises.

Leave a comment