Home Articles Sci-Tech Hashing Algorithm in Ancient Indian Music System

Hashing Algorithm in Ancient Indian Music System

Carnatic music system is an Indian music system that is of a very ancient origin. It is probably the oldest recorded music system in the world. It is believed that it has its origins in Sama Veda – one of the four ancient vedas. Sama Veda is actually hymns derived from Rig Veda set to musical tunes! Sama Veda is the Veda of music and melodies.

Melakartha – Base Raga in the Carnatic Music System

The Carnatic music system has 72 base ragas (called Melakartha Ragas) and thousands of derived ragas. Each raga in Indian music system depicts a mood. Some ragas are suitable to be played during sun rise, some during sunset, some produce a devotional feeling, some produce a romantic feeling, and so on. After all, music is what feelings sound like!

A base raga is a raga with 7 swaras (notes) in an octave. So there are 72 Melakartha ragas in carnatic music. Derived ragas (called Janya ragas) are ragas derived from a base raga and can have any number of notes.

The 7 notes of a raga are called Sa, Re, Ga, Ma, Pa, Dha, Ni akin to Do, Re, Mi, Fa, So, La, Ti in western classica music. However, the swara of a carnatic raga is much more complex, and the frequencies of notes are relative to each other, rather than a defined or fixed one.

The names of the 7 swaras are abbreviations of their actual names – shadja, rishabha, gandhara, madhyama, panchama, dhaivata and nishada.

Now in carnatic music, except for the first and fifth swara (Sa and Pa), other swaras have more than one form. So Ma has two forms, while other four Ri, Ga, Dha and Ni have three variants each.

If we consider the first note of an octave as Sa, then see the different positions other notes can occupy in the image below. All notes have been abbreviated to their first letter, so we have Sa(S), Ri(R), Ga(G), Ma(M), Pa(P), Dha(D) and Ni(N). Notes that can have more than on variant are indicated with the variant number, like D1, D2, N1, M2 etc.

Close up of piano keys

Now, since Ri always comes after Sa, it can be either R1 or R2 or R3. If Ri is R2, since Ga always comes after Ri, Ga can be either G2 or G3, but not G1, because it is nothing but R2.

With this simple rule that two notes cannot occupy the same place, we can see that we have 2 possible combinations for Ma, 6 possible combinations for Ri and Ga, and 6 possible combinations for Dha and Ni. So in all we have 2 x 6 x 6 = 72 possible combinations of the 7 notes here. Hence, there are 72 Melakartha ragas.

Katpayadi as a Hash table to calculate Melakartha Raga number

Each Melakartha raga has a number that ranges from 1 to 72, and a raga name. Now note that one had to remember which raga has which combination of notes, and this is a very difficult thing as we have 72 different combinations.

Hence, the ancient Indian musicians came with a simple solution for the same. They named the ragas so that the raga number could be calculated from the raga name! This was done using the Katapayadi Sankhya scheme. Read about the Katapayadi algorithm.

So, if you had a Melakartha raga name like Hanumatodi, then you can instantly calculate its raga number as 8 using the Katapayadi scheme. The first two consonants of the raga name were used in the Katapayadi scheme. In other words, Melakaratha raga names acted like a hash table, and the hash number was calculated using Katapayadi algorithm!

Then the musicians went a step further and devised another rule that allowed to calculate all the 7 notes of the raga from the raga number itself! In other words, the raga name were not just mapped via an algorithm to its number, but the number itself was first carefully selected so that it was possible to find its notes using the raga number!

Calculation of Raga notes from Raga number

The rule to find the notes were simple as follows. The notes Sa and Pa were already known since they are fixed. Now we had to find Ri, Ga, Ma, Dha and Ni.

Finding the note for Ma

Since there are two possible variations of Ma, the ragas were numbered so that the first 36 ragas had M1 and the next 36 had M2. In other words, if the raga number was <= 36, then its Ma note was M1, and if it was >36 then its Ma note is M2.

Finding the notes for Ri, Ga, Dha and Ni

The possible combinations for Ri and Ga are as follows:

  1. R1 G1
  2. R1 G2
  3. R1 G3
  4. R2 G2
  5. R2 G3
  6. R3 G3

Similarly, the possible combinations for Dha and Ni are:

  1. D1 N1
  2. D1 N2
  3. D1 N3
  4. D2 N2
  5. D2 N3
  6. D3 N3

So the rule to find each of these combinations was to

  • First divide the raga number by 6.
  • If the remainder is 0, then quotient is the RG combination number and 6 is the DN combination number.
  • If the remainder is non-zero, then quotient+1 is the RG combination number and remainder is the DN combination number.

For instance, if the raga number was 12, then since remainder is 0, RG=R1 G2 (because quotient is 2) and DN=D3 N3 (combination 6)

For instance, if the raga number was 27, then since remainder is non zero, RG=R2 G3 (because quotient is 4, so quotient+1=5) and DN=D1 N3 (because remainder is 3)

This is such an amazing piece of art work, not just some mathematics. The entire base raga system of carnatic music has been so skillfully designed that just by knowing the raga name one can instantly calculate the raga number, using which can then quickly calculate all the notes of that raga. Absolutely no need to remember all the individual 72 combinations against the raga name! Wonderful, isn’t it?

Content Protection by DMCA.com

Download HitXP Mobile App

Get it on Google Play
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.


  1. Thanks to all of you for your views – especially to  the debate between the author (hitxp) and Kaushik.  It was exhilarating to read such spirited exchanges on so arcane a subject.
    If any one knows, kindly also throw some light on the mathematics involved in the process of teaching/learning the veda; I refer to the GHANAPADI and the PRASNA and other mathematical routines used.  I have had a very faint glimpse of these topics in the book containing articles and upadesas  by PUJYA PARAMACHARYAL of KANCHI .
    Thanks and regards to all,

  2. its great to see ur article.. can u tell any way to identify the raaga by extracting some features of a song..it will be great to hear from you.

  3. hitxp, hello,

    I was wondering if you could possibly post a link with extra information on all of this. I am very interested in vedic mathematics but do not know where to look for good sources!

  4. Dear Gurudev,
    Thanks for your great thoughts on Melakartha scheme. I am also one of those intrigued by the Melakartha scheme and Katapayadi Sankhya. Ofcourse there are many more amazing things about our carnatic music system.
    I have also put down my thoughts on Melakartha scheme and their coded names. I had sent them as an article to a few musicologists in Chennai for their reflection and a possible feedback. I wish to share this article with you and hopefully I will be lucky to get your feedback.
    If it is OK with you kindly give me your email ID.
    L V Nagarajan

  5. I’m confused if Ma is one of two adjacent notes surely the possible combinations for Ma include the ones where Ma is the higher note leaving five notes inbetween Sa and Ma meaning a possible combination of 10?

    Or is it the case that if Ma is the higher note, Ga can not take the place of the lower possible note of Ma in any of those ragas? And the other way round.

    Thankyou very much for your time.

    • The following are the notes in the octet. 
      Sa, Ri1, Ri2 (Ga1), Ri3(Ga2), Ga3, Ma1, Ma2, Pa, Da1, Da2 (Ni1), Da3(Ni2), Ni3, [Sa]

      For every sampoorna (Melakarta) raga, you have to choose as follows. 
      1. Exactly one Ri, Ga, Ma, Da, Ni from the above list
      2. If you choose Ri2, then you cannot choose Ga1. Similar logic applies to Ri3, Da2, and Da3.

      With these two rules you have six possibilities in choosing Ri and Ga, six possibilities in choosing Da and Ni. Thus you have 36. When you multiply the two possibilities due to Ma you have 72. 

      This is the reason why the choice of Ma splits the Melakartha Circle into two. 


  6. very beautiful.excellent find.ah to only contemplate our elders is very tough.how am i going to contemplate about the eternal truth then?

  7. Yes Ramya
    you are right that it was jagadguru shankaracharya of puri who reintroduced vedic mathematics to the masses.

    Thanks Maitreyi / destinationsrik for your comments.

    Akilan I dont have any info about gayatri mantra and PI, but it definitely is the most powerful of the vedic mantras after OM with evolutionary secrets in it, summarizing the three vedas. The famous Geneticist and evolutionary biologist Haldane once said that “”the Gayatri Mantra should be carved on the doors of every laboratory of the world””

  8. The best thing about your articles is its simplicity covering the most complex information without revealing any actual complexity of the topic being discussed

  9. Hope you know the actual vedic mathematics genius jagadguru shankaracharya of puri who was actually based from Tiruchirapalli .HIS HIGHNESS came to US for three months later died in Mumbai . I think the latest known vedic mathematician itself is this great shankaracharya.
    It seems pythagoras thereom was also originited near Kerala.
    Not only this Yoga the vedic science of physical exercise itselfs prove a lot about ancient India .

  10. Can KaTaPaYaDi scheme be applied to Gayathri Mantra in order to derive a number that signifies some mathematical explanation about the powerful mantra?

    The reason is that in one of the slokas, I have seen in the web sites that above scheme is applied to derive the meaning of Pi =3.14

  11. And can you wonder how many times would I have thanked this great nation for having me as a part of it!

    Also, thanks for your wishes Sainath, I am a born optimist :)

  12. Simply great…thanx i wonder how many times i am going to say thanx to you henceforth :)..You are just amazing….I pray you succeed in all your noble dreams….

  13. @Kaushik

    First thing. The mathematics of Aryabhata and Bhaskara is NOT vedic Mathematics. Vedic Mathematics is limited to Vedas. Yes, There have been hundreds of great mathematicians in ancient India like Aryabhatta, Bhaskara, Brahmagupta, etc after the vedic era and they all have their ROOTS in the vedic mathematics.

    Second: Why is vedic mathematics taught as mental arithmetic to young students today? Definitely because it makes calculations faster with less use of paper and pen. Why is this possible? Because there are specific formulae and rules for calculations, unlike the generic ones we are taught in western mathematics. As I said, yes there is more to learn in Vedic math than in Western math to do the same thing!! But schooling is an age of learning and once they have learnt this , they can easily beat the students who are taught western mathematics any day!! Shakuntala Devi is a classic example! I am not sure whether you have actually read vedic mathematics before saying all this!!! There is no magic in vedic mathematics, the mental maths is pure specific algebra!!

    It is very wrong to say formal mathematical theory was absent in ancient India. You are making derogatory comments against ancient Indians without knowing anything!! I take strong exception to what you have said. Please go through at least some of the the ancient Indian mathematical texts before you say something like this.

    All the rules, the conditions, the usage, examples are all EXPLICITLY mentioned in the texts. What do you mean by absence of a formal mathematical theory? They have even talked about astronomical numbers so large which even today is not used often!! So many beautiful scenarios have been described about solving different kind of problems!!
    Please dont go on hearsay and write things. Look for yourself.

    You are again doing great injustice by saying vedic mathematics is based on intuition!! Vedic mathematics is pure science, it is not guesswork as you are suggesting!!


    Western mathematicis was a a generalized version of Indian mathematics and then it got developed on the basis of the same generalization. For this you need to know a bit of history. The 10 symbols used in base 10 system today originated from the Brahmi symbols of ancient India. This number system was spread to the rest of the world by Arab merchants who came to India for trade. Which is why they are called Hindu-Arabic Numerals. They used this place value based system for trade because they found it very easy to do simple business calculations like multiplication and division in their trade, instead of using the clumsy roman number system present then. But they used only the basic calculations, generalized multiplication, division etc, and this is what entered the western world. SIMPLE GENERALIZED CALCULATIONS from the Indian society.

    The sad part is while so many western researches and scholars have appreciated the ancient Indian mathematical treasure, we Indians ourselves are yet to recognize and give the true merit it deserves. Do you think the accurate speed of light calculated in ancient Indian texts millenia before the west did was based on Intuition??

    Even if you read some of the comments given by great modern western mathematicians and physicists on ancient Indian mathematics, you will find that their opinions are completely contrary to what you have said! I still dont understand what is your definition for a formal mathematical theory? How on earth can you say that there was no formal mathematical theory in ancient India?

    Einstein said, ‘We should be thankful to Indians who taught us how to count without which no major worthwhile scientific discovery would have been possible’! – without a formal mathematical theory?

    Actually your comments have inspired me to write a series of blogs on the vedic mathematics with examples and details. I am sure 99.9% of the people who comment on the pros and cons of Vedic Mathematics havent even read it properly! Do you know that it comes as a part of Atharva Veda and Atharva Veda is all about engineering ? Engineering without a formal mathematical theory? Have you by any chance read Vymanika Shastra, Vaayu Purana, etc ?

    I sincerely request you not to spread wrong information without having proper sources to quote. Now if I had not replied to your comment, and if somebody else had read your comments and taken it to be true, they would have thought that Vedic Mathematics is based on Intuition and there was no formal mathematical theory!! Please post the same question to a western mathematician who has studied ancient Indian mathematics and you will probably get an even more accurate answer.

  14. My first line got truncated. I meant
    “”The Katapayadi sankhya was indeed a great achievement of ancient Indian mathematics.””

  15. The Katapayadi sankhya was indeed a great achievement of

    However, I find many generalizations in your article:

    “”Western world failed to understand the basics of Indian mathematics when they learnt it from us, which is why vedic mathematics is faster than western math!””

    The first part is questionable and the second part is plainly wrong. What you are referring to as “”Vedic mathematics”” is a set of rules for mental arithmetic. The theory behind these was developed, but rarely stated explicitly in Indian mathematical texts. This is because the notion of a formal mathematical theory as we know it was largely absent in ancient Indian mathematics. Vedic mathematics is instead founded primarily on insight and intuition – which is certainly an integral part of mathematics. However, crass statements like the one above are uncalled for and do an injustice to both Indian and Western mathematics.

    Vedic mathematics is more than mere fast calculation.

    “”Western world started developing generic formulae for calculations while Indian math has specific formulae depending on the type of calculations.””

    Precisely my above point.

    1) Indian math is more than a set of calculation rules. Aryabhatta and Brahmagupta discovered solutions for Diophantine equations centuries before the west did. You are actually belittling our mathematical tradition with such points.

    2) To a mathematician, the above statement reads as a negative for Indian mathematics.

    I also have a suggestion regarding your description of the Katapayadi sankhya as a “”hashing algorithm””. Yes, the method is a hashing algorithm in principle. However, you also need to consider that the intent of the scheme is not to prevent you from figuring out the first two consonants of a raga given its Melakarta number (nor is it very effective in doing so). The idea of the scheme is to provide a “”lookup table”” for ragas. Hence, a better description of the Melakarta scheme would be that it is a “”dictionary”” (in the computer science sense of the term).


  16. an excellent entry. although i knew the KaTaPaYaDi sutra, and the way of finding the number of which melakartha raga it is, i didnt know the further use of it. good.


Please enter your comment!
Please enter your name here

RSS FeedSubscribe
Sound CloudFollow

Latest Articles

The difference between Itihasa and Puranas

Documentation of ancient Indian history and the historical events of Indian civilization in the form of Itihasa and Puranas - Ramayana and Mahabharata.

Online Education should be interactive and innovative – Fun to Learn

For online education to succeed for smaller classses - it should be as interesting as cartoons. Online education cant succeed unless it is more interesting, interactive and innovative than offline schooling.

The Complete List of Dhatus – Sanskrit Root Words and their English meaning

A complete list of all dhatus (root words or verb roots) in Sanskrit dictionary and their meanings with corresponding IPA transliteration.

Sanskrit Lesson 4 – Word Creation Magic using Dhatus

Learn how easy it is to create new words in Sanskrit using root words called Dhatus. This simple process of Sanskrit grammar powers the entire language.

Latest Music Notations

Kempadavo Ella Kempadavo – Ellindalo Bandavaru – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Kempadavo Ella Kempadavo from the 1980 Kannada movie Ellindalo Bandavaru in Western and Indian Notations.

Bella Ciao – Money Heist (La casa de papel) – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Bella Ciao from the 2018 Spanish Web Series Money Heist (La casa de papel) in Western and Indian Notations.

Haule Haule – Rab Ne Banadi Jodi – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Haule Haule from the 2008 Hindi movie Rab Ne Banadi Jodi in Western and Indian Notations.

Gori Tera Gaon Bada Pyara – Chitchor – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Gori Tera Gaon Bada Pyara from the 1976 Hindi movie Chitchor in Western and Indian Notations.
Content Protection by DMCA.com