Friday, August 29, 2008

Age Old Hashing Algorithm

In our last post of this series, we learnt how 72 scales formed the Melakartha Scheme. Few other points to note related to Melakartha Raga are:

1. They are also called "Sampoorna Raga" as all the 7 swaras are present in the scale.

2. The aarohanam and avarohanam will contain exactly the same swaras though in reverse order. (Aarohanam is the pattern of ascending notes – frequencies and Avarohanam is the pattern of descending notes)

Well the 72 raaga in Melakartha scheme needed a unique name. It wasn’t as easy as how the roads and districts are named today. VenkaTamakhi of 18th century applied a hashing algorithm called KaTaPaYaaDi to name the raga.

Like how all the encoding is done in today’s world, KaTaPaYaaDi is a simple mechanism to encode a string literal to a number:

Each alphabet in Devanagari script is assigned a number:

1   2   3   4   5   6   7   8   9   0
ka kha ga gha nga ca cha ja jha nya
ṭa ṭha ḍa ḍha ṇa ta tha da dha na
pa pha ba bha ma
ya ra la va śha sha sa ha

So, let us take any Melakartha Raaga in random – (say) ShaNmukhapriya. Take the first 2 consonant – Sha and Mu. Their equivalent values according to the KaTaPaYaadi sankya is: Sha = 6 and Mu = 5. Hence, applying the hashing gives 65. However, we have to reverse the number as we were following little endianness as opposed to big endianness scheme.

So, the equivalent value becomes 56. Hence, ShanmukhaPriya is 56th raga in Melakartha Scheme. Big Deal? How does it help to know just the position of the raga?

Once you know the Mela # of a raga, you can derive its scale by a simple algorithm.

a) Sa and Pa are fixed.

b) If Mela # > 36, Use Ma2, Else Use Ma1

c) If Mela # is > 36, subtract 36 from it

d) Then, Divide the Mela # by 6

  • Ri1 and Ga1 if the quotient is 0
  • Ri1 and Ga2 if the quotient is 1
  • Ri1 and Ga3 if the quotient is 2
  • Ri2 and Ga2 if the quotient is 3
  • Ri2 and Ga3 if the quotient is 4
  • Ri3 and Ga3 if the quotient is 5
  • Da1 and Ni1 if remainder is 0
  • Da1 and Ni2 if remainder is 1
  • Da1 and Ni3 if remainder is 2
  • Da2 and Ni2 if remainder is 3
  • Da2 and Ni3 if remainder is 4
  • Da3 and Ni3 if remainder is 5

    For eg: MechaKalyani (Originally known as Kalyani and was renamed to suit KaTaPaYaadi Sankya) has the Mela # as 65.

    Since 65 > 36, we will use Ma2.
    Also, as Mela # is > 36, we will subtract 36 from it to get 28.
    When we divide by 6, Quotient is 4 and Remainder is 4.

    So, Scale for Kalyani is Sa Ri2 Ga3 Ma2 Pa Da2 Ni3.
    (Remember Sa and Pa are fixed for all Mela Ragas)

    Alternatively, you can also find the Scale using Mukund Chart.

    Bottomline: All the encoding, hashing and mathematical algorithms we use now were used centuries earlier for organizing music for our pleasure! It is even believed that value of Pi could be traced back up to 17 digit precision when you apply KaTaPaYaaDi algorithm to a treatise in “Sadratnamala”. More details found at:


    TKB said...

    Thank you so much for visitng Sathya's videos. Also your blog is well done and very informative. Congrats. Krishnababu f/o Sathya - keyboard Artiste

    முருகேஷ் said...

    Our ancestors are great!!

    I read this post 4 times and now I think I'm getting the logic. You have explained it very well, it's just my brain not taking new things very easily.