Quick update on the last post. I have shown a graph for the length of rhythmic canons mod 2 with motive \{0,1,k\}, and we have seen that the dependence of the length with k is everything but simple, with particular cases when k=2^p or k=2^p+1. I wanted to check what happens for values of k higher than 41, but it turns out that the computation of the length is now very slow. I managed to get the lengths for k \in \{42,43,45,47,49\}, and these are the red points in the updated graph below. I am waiting for other values of k, but the computation for k=42 (haha…) took nearly two weeks, so this won’t be for tomorrow.


What are the green points by the way ? Well, I’m sure you have noticed that the previous code can easily be adapted to get rhythmic canons for any modulus, and not only 2. Here is an improved C program for calculating the length L (and entries) of a canon mod P with motive \{0,1,k\}. Notice that you will get the version of the canon where entries may be repeated, and that you may “unravel the modulus” of any entry at position x by considering another entry at position x+L. The green points in the graph above are the length of the canons with motive \{0,1,k\} modulus 3.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
	int N,P;
	int* U;
	int i,mark=0,flag=0;
	unsigned long long L,entry=0;
	FILE* output_file=NULL;
	if(argc<3) {
		printf("Length of the motive is required !\n");
	N = atoi(argv[1]);
	P = atoi(argv[2]);
		if (output_file!=NULL)
			fprintf(output_file,"Entries for canon with motive {0,1,%d}\n",N);

	U = calloc(N+1,sizeof(int));
	if (U==NULL) {
		printf("Error during memory allocation...exiting now !\n");

	while(flag==0) {
		if (output_file!=NULL)
		U[0]= (U[0]+1) % P;
		U[1]= (U[1]+1) % P;
		U[N]= (U[N]+1) % P;

		for (mark=0; mark<N+1; mark++) {
			if (U[mark]!=1) {
		for (i=mark; i<N+1; i++)
		for (i=(N+1-mark); i<N+1; i++)
	printf("Final length of canon with motive {0,1,%d}: %llu \n",N,L);
	if (output_file!=NULL)

Interestingly, it seems that any canon with motive \{0,1,3^p\} has length 3(3^{2p}-1), and any canon with motive \{0,1,3^p+1\} has length 3(3^{2p}+3^p+1). I am guessing that for any prime modulus, a similar relation exists…


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s