Tuesday, July 22, 2025

Engineers of Bharat - Wake up and embrace Sanskrit - part III - we knew the value of Pi centuries before the European - Kaṭapayādi system...

 The Kaṭapayādi system is an ancient Indian method of encoding numbers as syllables, allowing them to be embedded within meaningful words or verses—often for mnemonic or poetic purposes. This system was used extensively in Sanskrit and other Indian languages for transmitting mathematical and astronomical knowledge.

What is the Kaṭapayādi System?

In this system, consonants are assigned numerical values from 0 to 9. Vowels do not carry value but are used to form pronounceable words.

Basic Encoding Table:

Digit Consonants (Examples)
1 ka, kha, ga, gha, ṅa
2 ca, cha, ja, jha, ña
3 ṭa, ṭha, ḍa, ḍha, ṇa
4 ta, tha, da, dha, na
5 pa, pha, ba, bha, ma
6 ya, ra, la, va
7 śa, ṣa, sa
8 ha
9 (varies by source)
0 ṁ, na (anusvāra or zero-consonants)

Note: There are multiple minor variations across regions.

Use in Encoding the Value of Pi (π)

The famous value of Pi up to 31 digits was encoded in a Sanskrit verse using the Kaṭapayādi system. The most well-known example comes from Madhava of Sangamagrama or later Kerala mathematicians.

The verse (in Malayalam tradition):

"गोपीभाग्यमधुव्रात-श्रुंगिशोदधिसंधिगः।
खलजीवितखाताव गलहाला रसंधरः॥"

Each syllable in the verse is decoded using the Kaṭapayādi system to yield digits of π.

Decoded Digits of π

Applying the Kaṭapayādi values to this verse yields:

3.1415926535897932384626433832792

This gives 31 digits of π — centuries before π was known to this precision in Europe.

Significance of the Kaṭapayādi-Pi Verse

  1. Mnemonic Tool: Easily remembered and recited by students and scholars.

  2. Intellectual Heritage: Shows the mathematical sophistication of ancient India.

  3. Kerala School of Mathematics (14th–16th century): Used this in conjunction with infinite

Here's the simplified python code to calculate the value of pi using Kaṭapayādi system....

import re
from indic_transliteration import sanscript
from indic_transliteration.sanscript import transliterate

# Kaapayādi consonant → digit map (Kaādi system for Pi verse)
# This specific mapping is used for the Pi verse mnemonic.
# Note: Vowels are ignored in this system.
katapayadi_map = {
1: ['k', '', 'p', 'y'], # , , ,
2: ['kh', 'h', 'ph', 'r'], # , , ,
3: ['g', '', 'b', 'l'], # , , ,
4: ['gh', 'h', 'bh', 'v'], # , , ,
5: ['', '', 'm', 'ś'], # , , ,
6: ['c', 't', ''], # , ,
7: ['ch', 'th', 's'], # , ,
8: ['j', 'd', 'h'], # , ,
9: ['jh', 'dh'], # ,
0: ['ñ', 'n'] # ,
}

# Reverse mapping: consonant to digit for quick lookup
consonant_to_digit = {}
for digit, consonants in katapayadi_map.items():
for consonant in consonants:
consonant_to_digit[consonant] = str(digit)

# Build regex pattern to match consonants (longest matches first to handle 'dh' before 'd')
# This ensures that 'dh' is matched as a single unit before 'd' is considered.
pattern = '|'.join(sorted(consonant_to_digit.keys(), key=len, reverse=True))

def decode_katapayadi(devanagari_text):
"""
Decodes a Devanagari text using the Kaapayādi system.
It transliterates the text to IAST and then extracts digits based on consonant mapping.
"""
# Step 1: Transliterate Devanagari to IAST (International Alphabet of Sanskrit Transliteration)
# Convert to lowercase to match the keys in our map.
iast = transliterate(devanagari_text, sanscript.DEVANAGARI, sanscript.IAST).lower()
print(f"IAST Transliteration: {iast}") # For debugging/verification

# Step 2: Extract consonant roots using the pre-built regex pattern
# re.findall finds all non-overlapping matches of the pattern in the string.
matches = re.findall(pattern, iast)
print(f"Extracted Consonant Matches: {matches}") # For debugging/verification

# Step 3: Map extracted consonants to their corresponding digits
digits = [consonant_to_digit[c] for c in matches]
return ''.join(digits)

# Your input verse (the famous Pi mnemonic)
devanagari_verse = "गोपीभाग्यमधुव्रातश्रुंगिशोदधिसंधिगःखलजीवितखातावगलहालारसंधरः"

# Decode the verse
decoded_digits = decode_katapayadi(devanagari_verse)

# Format the output as an approximation of Pi
# For the Pi verse, the digits are traditionally read in reverse order from the verse,
# and often only the first consonant of each word is considered.
# This code extracts all mapped consonants in order.
# The actual Pi value (3.141592653589793238462643383279...)
# will be obtained if the specific rules for this mnemonic are applied (e.g., word segmentation and reversal).
# Here, we present the directly decoded sequence.
pi_approx = f"{decoded_digits[0]}.{decoded_digits[1:]}" if decoded_digits else "N/A"

# 🖨️ Output
print("\nDecoded Digits (using Kaādi map and all consonant extraction):", decoded_digits)
print("Approx Pi (based on direct decoding):", pi_approx)
print("\nNote: For the exact Pi sequence from this verse, traditional methods often involve splitting the verse into words and reversing the final digit sequence. This script applies the Kaādi map to all found consonants in order.")

And here's the result...

IAST Transliteration: gopībhāgyamadhuvrātaśruṃgiśodadhisaṃdhigaḥkhalajīvitakhātāvagalahālārasaṃdharaḥ
Extracted Consonant Matches: ['g', 'p', 'bh', 'g', 'y', 'm', 'dh', 'v', 'r', 't', 'ś', 'r', 'g', 'ś', 'd', 'dh', 's', 'dh', 'g', 'kh', 'l', 'j', 'v', 't', 'kh', 't', 'v', 'g', 'l', 'h', 'l', 'r', 's', 'dh', 'r']

Decoded Digits (using Kaṭādi map and all consonant extraction): 31431594265235897932384626433832792
Approx Pi (based on direct decoding): 3.1431594265235897932384626433832792

Note: For the exact Pi sequence from this verse, traditional methods often involve splitting the verse into words and reversing the final digit sequence. This script applies the Kaṭādi map to all found consonants in order.

Wake up... O my Hindus of Bharat... You are the progenies of a great civilisation...

Read...
Read...