# Pingala’s Algorithm Part IV – Algorithm to find the value of a Binary Sequence In my earlier article “Pingala’s Algorithm for Binary Conversion“, I had described how given a row number of an n-syllable prastaar you can find the sequence of Gurus and Laghus in that row using the Nashtam pratyay of Pingala. Now, what if given a sequence of n Gurus and Laghus we want to know its row number? This is essentially a converse procedure of Nashtam.

To understand how this was achieved, first let us closely observe the Nashtam pratyay. Let me present the sutras for the Nashtam pratyay:

लर्धे | सैके ग् | (छन्दः शास्त्रम् 8.24-25)

• To find the pattern in a row of the prastaar, start with the row number.
• Halve it (if possible) and write an L.
• If it cannot be halved, add one and halve and write a G.
• Proceed till all the syllables of the metre are found.

Let us use these to find the sequence of Gs and Ls in the 28th row of a prastaar of 8 syllables.

We have, n = 28.
Step 1) n = 28. It is divisible by 2. Therefore the first letter in the row is a Laghu (L).
Now, halve the number:
n = n/2 = 28/2 = 14

Step 2) n = 14. It is divisible by 2. Therefore the second letter in the row is a Laghu (L).
Now, halve the number:
n = n/2 = 14/2 = 7

Step 3) n = 7. It is not divisible by 2. Therefore the third letter in the row is a Guru (G).
Now, add a 1 to the number and then halve it.
n = n + 1 = 7 + 1 = 8
n = n/2 = 8/2 = 4

Step 4) n = 4. It is divisible by 2. Therefore the fourth letter in the row is a Laghu (L).
Now, halve the number:
n = n/2 = 4/2 = 2

Step 5) n = 2. It is divisible by 2. Therefore the fifth letter in the row is a Laghu (L).
Now, halve the number:
n = n/2 = 2/2 = 1

Step 6) n = 1. It is not divisible by 2. Therefore the sixth letter in the row is a Guru (G).
Now, add a 1 to the number and then halve it.

n = n + 1 = 1 + 1 = 2
n = n/2 = 2/2 = 1

Step 7) n = 1. It is not divisible by 2. Therefore the seventh letter in the row is a Guru (G).
Now, add a 1 to the number and then halve it.
n = n + 1 = 1 + 1 = 2
n = n/2 = 2/2 = 1

Step 8) n = 1. It is not divisible by 2. Therefore the eighth letter in the row is a Guru (G).
Now, add a 1 to the number and then halve it.
n = n + 1 = 1 + 1 = 2
n = n/2 = 2/2 = 1

Since we have got the required 8 syllables, we stop the procedure.
Hence, the pattern for the 28th row is LLGLLGGG.

If we observe steps 6, 7, and 8 closely we realize that once the quotient becomes 1 all the trailing syllables are Gurus. Pingala has made good use of this to reduce the number of steps in his converse pratyay, Uddishta.

Now, given a sequence of n Gurus and Laghus can we find the correct row number in the n-syllables prastaar. Pingala had developed an algorithm (pratyay / प्रत्याय) called Uddishta (उद्दिष्ट) to achieve this.

Pingala’s sutras for Uddishta :

प्रतिलोमगणं द्विर्लाद्यम् |  ततोग्येकं जह्यात् | (छन्दः शास्त्रम् 8.26-27)

Meaning:
• Scan the sequence in reverse order (that is from the right) and reach the first laghu. Now double the number.
• Double the number when an L is encountered.
• Double and reduce by 1 when a G is encountered.

Let me illustrate this by getting the row number for the sequence LLGLLGGG.

• Start with number 1. Notice that in Nashtam we ended the process with a 1.
• Start scanning the sequence from the right. Skip the Gs and reach the first L. (Recollect our earlier observation in the Nashtam procedure when we encountered trailing Gs towards the right of the sequence.) Now, double the number. We get, 1 x 2 = 2.
• Moving to the next syllable in the left we encounter an L. Hence, double the number.
We get, 2 x 2 = 4.
• Moving to the next syllable in the left we encounter a G. Hence, double the number and deduct 1. We get, (4 x 2) – 1 = 8 – 1 = 7. Recollect that in Nashtam, when we encounter a G, we add a 1 and then halve it.
• Moving to the next syllable in the left we encounter an L. Hence, double the number.
We get, 7 x 2 = 14.

• Moving to the next syllable in the left we encounter an L. Hence, double the number.
We get, 14 x 2 = 28.

Hence the row number in an 8-syllables prastaar for the sequence LLGLLGGG is 28.

We also know that the row number in a prastaar is value of the binary sequence plus one.

Replacing G and L in LLGLLGGG with 0 and 1 we get 11011000, this is mirror image of the binary number. Hence, the binary number is 00011011. The value of this binary number as calculated by the modern method is:
(00011011)2 = (1 x 2^4) + (1 x 2^3) + (0 x 2^2) + (1 x 2^1) + (1 x 2^0) = 16 + 8 + 2 + 1 = 27
Therefore the row number = 27 + 1 = 28.

Kedar Bhatt was the first to give such an algorithm in his work Vruttaratnakar. Kedar Bhatt’s sutras for Uddishta are:

उद्दिष्टं द्विगुणानाद्यादुपर्यङ्कान् समालिखेत् |
लघुस्था ये तु तत्राङ्कास्तैः सैकैर्मिश्रितैर्भवेत् ||        (वृत्तरत्नाकरः  6.5)

Meaning:
• Place 1 on top of the left-most syllable of the given sequence.
• Double it at each position while moving to the right.
• Sum the numbers above L and add 1 to get the row-number.

Let us apply this algorithm to get the row number for the above sequence, i.e. LLGLLGGG. Refer to Table 1. Row number = 1 + 2 + 8 + 16 + 1 = 28

Essentially Kedar Bhatt is calculating the powers of 2. Refer to Table 2. Even after 1000 years, we are using the same method as that of Kedar Bhatt to get the value of binary sequences.

When we compare the Uddishta pratyay’s of Pingala and Kedar Bhatt we find that Pingala’s method is more efficient.

Explore Pingala’s Binary Number System Part I, II, and III