A hash is a numeric value that can be computed from a given piece of text. Modern computers use hashes because it is faster to compare numbers than text in computers. So all applications, databases, etc store text in the form of hashes and compare the hashes first while comparing the texts.
A hashing algorithm is any method that is used to convert text into a number. For example, we can have a simple hashing algorithm where each alphabet represents a number, like A=1, B=2, C=3 etc. In this case, the hash of CAB becomes 312.
In ancient India, a similar method existed to convert numbers into text – it was called the Katapayadi Sankhya scheme. Note that converting numbers into text is the reverse process of hashing. So, under the Katapayadi scheme each consonant was assigned a number. See the chart below.
The rule was any numeric sequence could be represented using the above table. Note that a single digit has multiple possible consonant values. So this flexibility allowed one to create meaningful word combinations that are easy to memorize, so this was a great mnemonic tool. One could create an infinite number of mnemonics to represent any numeric sequence using Katapayadi!
The name Katapayadi as you can see is derived from the consonants that have a value of 1 in the algorithm i.e. Ka, Ta, Pa, Ya.
Katapayadi as a mnemonic creating algorithm
खलजीवितखाताव गलहालारसंधर ॥
The above is a verse that is written in praise of Krishna and it means
Oh Krishna, the fortune of the Gopis, the destoryer of daemon Madhu, protector of cattle, the one who ventured into the ocean-depths, destroyer of evildoers, one with plough on the shoulder and the bearer of nectar, may (you) protect (us)!
Please note that this is not an ancient hymn as many think, but a recent one probably composed by Bharati Krishna Tirthaji. However, what this hymn shows is the amazing power of the Katapayadi scheme when combined with the beautiful grammar of Sanskrit that makes creating great combinations of meaningful words.
By applying the Katapayadi scheme to the above verse and reversing the digits, we get the sequence 314159265358979324. This is the value of pi to 17 decimal places with the last digit rounded off!! So, the beauty of the Katapayadi system is you can remember a large mathematical value as a hymn in praise of your favorite deity!
Ok, but why did we have to reverse the digits? That is because, in ancient India, in Sanskrit, the numbers are written in the reverse order of what we write today, like 123 is written as 321. So to read it in the order we use today, the numbers had to be reversed.
The table of trigonometric sines of angles constructed by the famous mathematician and astronomer from Kerala, Madhava, in the 14th century is also written in Katapayadi scheme! In other words, you learn a few lines of text, and then you know the trigonometric sine values of different angles!
Katapayadi as a hashing algorithm
The most famous use case that has applied Katapayadi scheme as a hashing algorithm is the classical Indian music system where the 72 base melakartha ragas are named such that, just by looking at the first two consonants in the name of the Raga one can quickly compute the Raga number!
But why should we compute the number of a raga? Because, the raga number is designed such that, using the Raga number one can find out the notes (Swaras) of that raga! So, the Katapayadi based naming of the melakartha ragas enables one to identify all the notes of that raga by just looking at its name!
This is one of the earliest and probably very few applications of hashing algorithms outside the world of computers. The names of the ragas are like a hash table.
Consider the raga Mayamalavagowla. Its first two consonants are M and Y. The value of M is 5 and that of Y is 1 in the Katapayadi Sankhya scheme. Note that in the Indian system numbers are written in the reverse order. So, the number we have here is 15 and 15 is the melakartha number of Mayamalavagowla!! As simple as that.
So the students of classical music in India learn the Katapayadi scheme and this helps them to quickly identify the Raga number and hence the notations of that raga. As you guessed, there is another rule that helps one arrive at the raga notations using the raga number. That is for another article another day 🙂
Oldest known use of Katapayadi algorithm
Vararuchi is a famous astronomer from the India state of Kerala who lived in 4th century. He is also the author of Chandravakyas (meaning lunar sentences). It contains the longitudes of the Moon at different intervals of time and these numbers are encoded using the Katapayadi system. This being the oldest known work using Katapayadi algorithm, it is believed that Vararuchi himself was the inventor of this algorithm.