### Theta Functions

As mentioned in the previous post, modular forms are complicated mathematical structures that follow a number of symmetry rules. One of the typical modular forms is what's called "theta functions". A theta function TF over two variables a and b is defined as:

TF(a,b) = Sum(-oo <= n <= oo) a^(n*(n+1))/2 * b^(n*(n-1))/2

Basically it is an infinite sum in both directions of a product whose variables are raised to n, which is the variable from minus infinite to positive infinite. The question is to observe the symmetrical properties of this form. One way to do that is by plotting the 3D chart for the following function:

z = Sum(-oo <= n <= oo) x^(n*(n+1))/2 * y^(n*(n-1))/2

This was we transform the form into a simple z = F(x,y) function. Given a pair (x,y), we can then generate z and have the triplet (x,y,z). Let's write some code to do that.

Code is straightforward but two simple aspects to be aware of:

1) If you do a for(int i=-oo;i<=oo;i++), it will take a considerable amount of time. Better is to replace infinite with a number. Let's replace infinite with 10. You may ask, why 10 and not 10^100? Well, the distance between 10 and +oo is the same as between 10^100 and +oo, hence we're good.
2) We have to print it in a matrix format rather than (x,y,z) per line. That way it is easier to import and manipulate in excel.

Running the code, getting the data and plotting in excel, one gets this:

One can see the modular form shaping up. For small (x,y) the curve is fairly flat and symmetric around the zero z. And then suddenly it shoots up toward infinite in the four corners of the graphic. A fun experiment is to slightly change the function so that instead of multiplication we can try other operands:

TF Modified/: z = Sum(-oo <= n <= oo) x^(n*(n+1))/2 / y^(n*(n-1))/2
TF Modified+: z = Sum(-oo <= n <= oo) x^(n*(n+1))/2 + y^(n*(n-1))/2
TF Modified-: z = Sum(-oo <= n <= oo) x^(n*(n+1))/2 - y^(n*(n-1))/2

Interestingly enough, looks like that those modifications don't alter the symmetric characteristic of the function, although I'm not sure whether they still "qualify" as proper modular forms. Here are the charts for the three modified forms:

Code is down below. And remember:
a) If you're having a great day - enjoy it deeply!
b) If you're having a meh day - it is actually a great day since it could have always been (c)!
c) If you're having a horrible day - hey, it can't get worse, so it will get better, trust me!

Cheers, Marcelo.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ThetaFunctionNS
{
class Program
{
static void Main(string[] args)
{
int N = 20;
double[,] matrix = new double[2 * N + 2, 2 * N + 2];

for (int x = -N; x <= N; x++)
{
int xIndex = x + N + 1;
matrix[xIndex, 0] = x;

for (int y = -N; y <= N; y++)
{
int yIndex = y + N + 1;
matrix[0, yIndex] = y;

double z = ThetaFunction4(x, y);
matrix[xIndex, yIndex] = z;
}
}

for (int i = 0; i < 2 * N + 2; i++)
{
for (int j = 0; j < 2 * N + 2; j++)
{
Console.Write("{0}\t", matrix[i, j]);
}
Console.WriteLine();
}
}

public static double ThetaFunction(int x, int y)
{
int N = 10;

double z = 0;
for (int i = -N; i <= N; i++)
{
z += Math.Pow(x, i * (i + 1) / 2.0) * Math.Pow(y, i * (i - 1) / 2.0);
}

return z;
}

public static double ThetaFunction2(int x, int y)
{
int N = 10;

double z = 0;
for (int i = -N; i <= N; i++)
{
z += Math.Pow(x, i * (i + 1) / 2.0) / Math.Pow(y, i * (i - 1) / 2.0);
}

return z;
}

public static double ThetaFunction3(int x, int y)
{
int N = 10;

double z = 0;
for (int i = -N; i <= N; i++)
{
z += Math.Pow(x, i * (i + 1) / 2.0) + Math.Pow(y, i * (i - 1) / 2.0);
}

return z;
}

public static double ThetaFunction4(int x, int y)
{
int N = 10;

double z = 0;
for (int i = -N; i <= N; i++)
{
z += Math.Pow(x, i * (i + 1) / 2.0) - Math.Pow(y, i * (i - 1) / 2.0);
}

return z;
}
}
}