Showing posts with label random number. Show all posts
Showing posts with label random number. Show all posts

Friday, 8 March 2019

Vishwanath Number

I came across this interesting number in a book I was reading on Mathematics. To quote from pages 97 and 98 of The Story of Numbers by Mallick Asok Kumar:
This, almost certainly, irrational number has been discovered recently by an Indian computer scientist — named Divakar Vishwanath. This number is related to “Randomised Fibonacci Sequence”. Just like the normal Fibonacci sequence (see Section 2.6.1), the randomised version also starts with first two numbers as 1, 1. Thereafter one tosses a fair coin at every stage and use the following formula to generate the sequence:$$F_n=F_{n−2}±F_{n−1} \text{ for }n≥3$$The plus sign is used if the coin shows a head and the minus sign is used if the coin shows a tail. Vishwanath has proved that if you start to generate such avsequence, then, with probability 1, the absolute value of the \(N\)-th number in the randomised sequence will be approximately equal to the \(N\)-th power of 1.13198824 . . . . The bigger the value of \(N\), the closer is the absolute value of the \(N\)-th number of the randomised sequence to the \(N\)-th power of Vishwanath number 1.13198824 . . . . This number is almost certainly an irrational number.
Bear in mind that the recent discovery referred to in the above quote is now about twenty years old. Using SageMathCell, I tested this out for N=1000. Here is the code that I used:


The above box sometimes works but is temperamental. Here is a permalink to the code at SageMathCell. Some results are as follows (note that even though the \(N\)-th term can be very large, the \(N\)-th root of the number always reins it in:

71635048983737736457508495785347136900241837532880818653 1.13724785289546
-3868701952168426630626609949500693480141855962812452339 1.13393344608014
-230368470580308360353351991114643286077160535687 1.11522481150615
-1294461166539244845628908128250544767526170899091979974739663 1.14844999189994


Increasing \(N\) to 100,000 gives the following results:
  • 1.13104709702409
  • 1.13203489558527
  • 1.12848774540983
  • 1.13268434714159
Increasing \(N\) to 500,000 gives the following results:
  • 1.13181606331044
  • 1.13153973067764
  • 1.1312382520834
  • 1.13181595957100
Thus we see that, as \(N\) increases, the values draw closer to 1.13198824 . . . While the Vishwanath Number is "almost certainly an irrational number", one wonders whether or not it is a transcendental number. There's a more details report from March 1999 on this constant here and here is a quote in part from report:
To give some idea of what this result says, the way the randomized Fibonacci sequence is generated is a bit like the daily weather at a particular location. Today's weather can be assumed to depend on the weather the previous two days, but there is a large element of chance. The analog of the number 1.13198824 . . . for the weather would give a quantitative measure of the unpredictability of weather. It measures the rate at which small disturbances explode exponentially in time. It would tell you for exactly how many days high-speed computers can forecast weather reliably. Unfortunately, nobody knows this number for global weather, and probably never will. 
Viswanath's result brings to an end a puzzle that has its origins in 1960. In that year, Hillel Furstenberg (now at the Hebrew University) and Harry Kesten (at Cornell University) showed that for a general class of random-sequence generating processes that includes the random Fibonacci sequence, the absolute value of the \(N\)-th member of the sequence will, with probability 1, get closer to the \(N\)-th power of some fixed number. (The exact formulation of their result is in terms of random matrix products, and is not for the faint-hearted. See Viswanath's paper -- cited below -- for an exact statement, or read the whole story in the book Random Products of Matrices With Applications to Infinite-Dimensional Schrodinger Operators, by P. Bougerol and J. Lacroix, published by Birkhauser, Basel, in 1984.) 
Since Furstenberg and Kesten's deep result applied to the randomized Fibonacci process, it followed that, with probability 1, the absolute value of the Nth number in any random Fibonacci sequence will get closer and closer to the Nth power of some fixed number K. But no one knew the value of the number K, or even how to calculate it. 
What Viswanath did was find a way to compute \(K\). At least, he computed the first eight decimal places. Almost certainly, \(K\) is irrational, so cannot be computed exactly. Viswanath presented his new result at a colloquium at MSRI last month. 
Since there is no known algorithm to compute \(K\), Viswanath had to adopt a circuitous route, showing that \(K\) equals \(e^P\), where \(P\) lies somewhere between 0.1239755980 and 0.1239755995 (and, as usual, \(e\) is the base for natural logarithms). Since those two numbers are equal in their first eight decimal places, that meant he could calculate \(K\) to eight decimal places. 
The process involved large doses of mathematics and some heavy duty computing. Since his computation made use of floating point arithmetic -- which is not exact -- Viswanath had to carry out a detailed mathematical analysis to obtain an upper bound on any possible errors in the computation. He describes the key to his new result this way: "The problem was that fractals were coming in the way of an exact analysis. What I did was to guess the fractal and use it to find \(K\). To do this, I made use of some devilishly clever work carried out by Furstenberg in the early 1960s." 
And with that computation, mathematics has a new constant, a direct descendent of a pair of rabbits in thirteenth century Italy.
There's not been much on the Internet about Vishwanath's Number over the subsequent twenty years. The number did get a brief mention in another blog last year but that's about it. Nonetheless, it's an interesting concept.

Sunday, 20 January 2019

The Mersenne Twister

I stumbled upon the Mersenne Twister after investigating Pseudorandom Number Generators (PRNGs) stimulated by an article about a hacker who had made a speciality of exploiting weaknesses in the PRNGs incorporated into certain types of slot machines.

Here is an excerpt from the article:
In the course of reverse engineering Novomatic’s software, Alex encountered his first PRNG. He was instantly fascinated by the elegance of this sort of algorithm, which is designed to spew forth an endless series of results that appear impossible to forecast. It does this by taking an initial number, known as a seed, and then mashing it together with various hidden and shifting inputs—the time from a machine’s internal clock, for example. Writing such algorithms requires tremendous mathematical skill, since they’re supposed to produce an output that defies human comprehension; ideally, a PRNG should approximate the utter unpredictability of radioactive decay.
The intriguingly named Mersenne Twister is described thus by Wikipedia:
The Mersenne Twister is a pseudorandom number generator (PRNG). It is by far the most widely used general-purpose PRNG. Its name derives from the fact that its period length is chosen to be a Mersenne prime. 
The Mersenne Twister was developed in 1997 by Makoto Matsumoto and Takuji Nishimura. It was designed specifically to rectify most of the flaws found in older PRNGs. 
The most commonly used version of the Mersenne Twister algorithm is based on the Mersenne prime \(2^{19937}−1\). The standard implementation of that, MT19937, uses a 32-bit word length. 
The Mersenne Twister is the default PRNG for the following software systems: Microsoft Excel, GAUSS,  GLib, GNU Multiple Precision Arithmetic Library, GNU Octave, GNU Scientific Library, gretl, IDL, Julia,  CMU Common Lisp, Embeddable Common Lisp, Steel Bank Common Lisp, Maple, MATLAB, Free Pascal, PHP, Python, R, Ruby, SageMath, Scilab, Stata.
I don't want to delve too deeply into the how the Mersenne Twister actually generates its random numbers. However, the following article provides a simple overview of how it works.

How does the Mersenne Twister work?

Posted February 2016

Someone asked that question on reddit, and so I replied with a high level answer that should provide a clear enough view of the algorithm:

From a high level, here's what a PRNG is supposed to look like (DIAGRAM 1):


DIAGRAM 1

You start with a seed (if you re-use the same seed you will obtain the same random numbers), you initialise it into a state. Then, every time you want to obtain a random number, you transform that state with a one-way function \(g\). This is because you don't want people to find out the state out of the random output.

You want another random number? You first transform the state with a one way function
\(f\): this is because you don't want people who found out the state to be able to retrieve past states (forward secrecy). And then you use your function \(g\) again to output a random number.

Mersenne Twister (MT) is like that, except:
  • your first state is not used to output any random numbers
  • a state allows you to output not only one, but 624 random numbers (although this could be thought as one big random number)
  • the \(g\) function is reversible, it's not a one-way function, so MT it is not a cryptographically secure PRNG.
With more details, here's what MT looks like (DIAGRAM 2):


DIAGRAM 2

The \(f\) function is called "twist", the \(g\) function is called "temper". You can find out how each functions work by looking at the working code on the wikipedia page of MT.

*********************************

The slot machine hacking via knowledge of the PRNG within got me thinking about my own gambling on Lotto, a vice I indulge in weekly. How are the lotto numbers selected? Are there physical, numbered balls involved or is a PRNG used? There's no shortage of sites that will generate random numbers for you to enter in any lottery of your choosing but how are the actual winning numbers generated? Well it seems that the numbers are physically selected in Australian lotteries as shown in the following video:


However, Lucky Lotteries is different.


To quote from the website:
Lucky Lotteries is a raffle style jackpot game that guarantees over 10,000 prizes in every draw! Unlike other lottery games, each number is unique so there is no sharing of prizes. 
There are two Lucky Lotteries games – Super Jackpot and Mega Jackpot. 
Each game has a set amount of numbers per draw and once all available numbers are sold, the winning numbers are drawn using a random number generator.
So clearly a PRNG is used in certain lotteries. Of course, I use SageMath extensively and so it's of interest to know about what PRNG it uses. SageMath documentation explains that:
It is possible to select which random number generator drives the sampling as well as the seed. The default is the Mersenne twister. Also available are the RANDLXS algorithm and the Tausworthe generator (see the gsl reference manual for more details). These are all supposed to be simulation quality generators. For RANDLXS use rng = 'luxury' and for tausworth use rng = 'taus': 
sage: T = RealDistribution('gaussian', 1, rng = 'luxury', seed = 10)