[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1219.0. "what is this function?" by AQUA::GRUNDMANN () Thu Apr 12 1990 14:49

Has anyone studied a function like the following? I ran across this when I
needed a quick and dirty "random" number generator, and modified a game
algorithm I had used before. I am using this for algorithmic music generation,
and for an interactive electronic kaliedoscope game. The patterns that come out
don't seem totally random, but they are not completely repetitive either. They
have a kind of esthetic appeal... 

You call generate() repeatedly to obtain a sequence of values.

	int generate(mask)
	  int mask;
	{
	  for (n=1; n<9; n++) table[n-1] += table[n];
	  return mask & table[0];
	}

table[] is initialized to "interesting" values, table[8] must be non zero. mask
is typically something like 31, or 63, (of the form 2^n-1). The table size of 9
is just for illustration. 

This algorithm came from a generalization of a quick way to simulate a
cannonball flying through the air in an electronic game: 

	positionY += velocityY;
	velocityY += accelerationY;

You calculate the position, plot it on the screen, and repeat. The acceleration
represents gravity and is set to -1. The X coordinate has 0 acceleration.

By going to larger derivatives, and masking with small numbers, the function
goes through interesting patterns, things that repeat with varying offsets,
little sweeps of values that plot out like parabolas, etc. Visually and
musically they have a certain strange appeal. 

Is there anything mathematically interesting about this function? 
I can post an example C program if anyone is interested...

thanks in advance ---- Bill
    
T.RTitleUserPersonal
Name
DateLines
1219.1polynomial approximation plus a maskingCSSE::NEILSENI used to be PULSAR::WALLYFri Apr 13 1990 17:0432
Looks to me like you've got a discrete approximation to nth order ordinary
differential equation

	d^n x / dt^n = constant

which has as solution a polynomial of degree n

	a0 + a1 * x + ... an * x^n 

and then your mask takes this polynomial modulo 2^m.  Sure enough, the low 
order bits of a complicated function look sort of random but not quite.


I once saw a practical use for these pseudo-random numbers.  Take the special
case where a0 = 0 and n = 1, which generates a sequence

	yk = (a * k) mod 2^m       where k = 0, 1, 2 ...

now consider a set of N of these sequences with different j

	yjk = (aj * k) mod 2^m     where j = 1, 2 ... N; k = 0, 1 ...

these yjk can be interpreted as points in N-space, in a N-cube of size 2^m.  For
a reasonable choice of the aj, they 'randomly' cover the cube.  Because they 
are not truly random, they actually do a better job of covering the cube than
truly random numbers.  So they can be used in numerical integration, and give
usually a smaller error term than the usual Monte Carlo integration.  There is 
a slight danger of 'resonance' between these numbers and the integrand, but if 
you know the form of your integrand you can judge this risk.

This technique is called Conroy or Conway or something integration, after its 
inventor.  No, he is not the famous British mathematician.