Encoding the Language Rules.. Ode to Pāṇini

Coding and Compression techniques some 2K years back.. Intuition into Sanskrit Grammar and Panini’s Astadyayi..

Sujatha Ratnala
14 min readSep 26, 2020

I was ruminating over a long time to have a glance of Ashtadyayi.. In its very basic form at least.. Last week I happened to find a Sanskrit video explaining it.. Some notes, musings, and thoughts.. In case you are a novice and have a penchant for knowing a little about it.. How it relates to modern computing and AI in some ways..

I tried to put the grammar pieces in small bits. Read it like a story. Do not get bogged down by the details. Feel free to skip some sections and come back. In case interested in knowing more, do not miss the last section on references.

It is hard to imagine a world without words. They paint our thoughts and imagination. They are an instrument of expression and information. With the advent of computers, even machines have latched on to the idea of languages.

Modern languages are kind of simple. They have a few loose rules and a bunch of words that we memorise. Is there a recipe for generating a million new words? Is there a language with such a recipe? The recipe had to be small and optimal, it had to be foolproof for future generations, the generated words had to be a pleasing product and not a bizarre dish..

I. M. A. G. I. N. E.

You are that spellbee expert. Given any word in your language, you should be able to explain its meaning.

You are a baker and have spinned different kinds of pasteries.. You want to coin a 1000 signature meaningful names that were not heard before..

You are in a Contest. You need to write your entire essay only using a few alphabets.

You have a crypto challenge. Reading your sentence left to right you desccribe the Sun and when read right to left, it describes the moon.

I.S. . . . I.T. . . .P.O.S.S.I.B.L.E. . ??

And what if you were to write the grammar rules of this amazing language to keep it alive for generations in a simple and yet the shortest form?

Welcome to the infinite possibilities with Sanskrit and the genius of Panini who encoded these rules of grammar in just 4K instructions.. Making the need of lofty dictionaries redundant. Words crafted from sounds that carried emotions and acoustic envelopes..

The 21st Century owes to Panini

Since the discovery of his work by European scholars in the 19th century, Panini is described as the first descriptive linguist and even as father of linguistics. It is not surprising that Mandaleef was inspired by Panini for his work on periodic table. American Linguists were amazed by the structure of his grammar. This could have very much influenced the inception of programming language.

“The descriptive grammar of Sanskrit, which Pāṇini brought to its perfection, is one of the greatest monuments of human intelligence and an indispensable model for the description of languages” -Leonard Bloomfield, 1929 [American Linguist]

“Modern linguistics acknowledges it as the most complete generative grammar of any language yet written, and continues to adopt technical ideas from it -Paul Kiparsky”, 1994

पाणिनि.. Who was Panini ?

Panini was an ancient scholar, grammarian and a logician from Ancient India. He probably lived in ancient Gandhara in the northwest Indian Subcontinent in the modern day Pakistan around 600 BC. His full name was Dakṣiputra Pāṇini and he attended the Takshashila university.

It is said that Panini was not that brilliant and when defeated in a debate, he went to the woods and meditated on Lord Shiva. That is where the special alphabet order occurs to him. There are legends that he hears them as sounds of Shiva’s drums..

Importance of Sanskrit Grammar.. Vyakarana

A friend of mine who is not very conversant with Sanskrit asked me this question. Can you remind me how Sanskrit Grammar is relavant to us?

In simple words, All of this would not have been possible without having the framework of grammar.

  • Our scholars today understand the Vedas and scriptures which are more than thousand years old.
  • Chanting of Gita, Mantras, Hymns with fidelity..
  • Decoding and parsing the elements without any ambiguity.. Noun and Verb contexts.. Gender and Plurality
  • Writing Sanskrit literature.

Interestingly Vyakarana expands to ‘An instrument or tool to generate and expand’ vya karana..

A brief view of Sanskrit Grammar

Let us try to have a small feel of Sanskrit Grammar. Feel free to skip this part if you know the basics.

At the bottom of the sound machinery we have the Sanskrit alphabets made up of vowels and consonants.. It has a very structured matrix like organisation based on human vocal anatomy. Vowels are meditative sounds without any contact and Consonants are caused by the touching effect with the teeth, lips, palette, throat etc.

1. A look at Nouns & Verbs

In a crude sense, all the words including adjectives and adverbs fall into Nouns, Verbs and immutables.

Let us begin with the Noun story. Every Noun has a specific context in a sentence. Is it the doer? Does it describe a relation? Does it act as an instrument? And so on.. In the below statement..

Ram is playing cricket with a bat. Ramah batena cricketam khelathi.
Give it to Ram.. Ramaaya dadathu
Take it from Ram.. Ramaath neyathu
Son of Rama.. Ramasya putrah
Peace is in Ram.. Rame shanthi asthi

Ram is the actor, cricket is the object, bat is the instrument. We are able to decode the above information due to the prepositions ‘ with’ and the relative placement of the words Ram- cricket -bat. The sentence would make no sense if we rearranged the words in English. This is not the case in Sanskrit. Lets see why.

In sanskrit, there are precisely 7 noun contexts like we have seen above. And the noun could be singular, dual or plural.. Hence a given noun would have 7 * 3 making it 21 contexts. Each of these contexts can be recognised by the embedded affix (something like a suffix). The various contexts of the word Rama in singular, dual and plural would look like this.

Essentially special meta sounds were added to the roots to bring the noun context information out. Sounds like am, au, bhyām, bhiḥ, bhyaḥ, su..

This is just the beginning. The above template holds good only for Rama. Think of Noun roots having different vowel and consonant endings and different genders like राम ,हरि, गुरु, पितृ, सीता, मति , वधू, मातृ, राजन्, मरुत् , सरित् etc.

Their templates would look a little different. Imagine memorising 15 such templates to get a hang of noun contexts.

This mega expansion of noun context pattern tables is like vishwaroopa of Gita and enough to scare the wits of beginners.

Interestingly Panini codifies the noun affix sounds as a base list of 21 sounds in just one line of his code. He calls this base list as the sup pratyaya सुप्प्रत्यय‍

Switching to verbs.. In English we have verb forms like playing, played, to play, will play,are playing, having played, should play.. Partially the tense and mood is conveyed through the affix and additional words like am- is - will..

In Sanskrit, the verbs are carved by tagging specific affixes. There is a well defined matrix for conveying the verb context across tense, person and plurality.. Let’s see the factory of verb contexts..

Like the Nouns, the Verb contexts are created by adding special carveout sounds. This list of verb affixes is called as tiṅ pratyaya तिङ्प्रत्यय‍

2. The Ultimate Recipe for Word Generation

Let’s get to this. The secret sauce of word generation. To begin with there is a repository of Noun and Verb roots. Like we saw before, simple Nouns and Verbs are generated by attaching a suitable affix to the roots.

Rāma राम
rāmeṇa रामेण (by Rāma), rāmeṣu रामे‍षु ‌(in Rāma)
bhū भू
‌bhavati भवति‍, abhavan अभवन्

The flow does not end here.. More complicated nouns and verbs can be generated. A Female Noun Root can be derived from a Male Root. A Noun root can be derived from a Verb root and so on. For example, we have the following derived nouns.

female elephant gajaa from gaja, Kaushalya from kushal, kartavyam from Kara.. Kaunteya from Kunti..

In the below figure, the left side indicates Noun roots and Noun and the left side the Verb root and Stem. There are totally 7 affix lists that aid in the word formation. This flow can keep looping and generating bombastic intermediate roots. But the last leg should always be a conversion to a Noun or a Verb. If interested checkout this post or this Sanskrit video to get an idea.

quora.com Neelesh Bodas

3. Packing of Sound Blobs

Essentially sound blobs interact with other sound blobs to grow into words, compound words and then pack into a sentence.

We have so far seen the root words growing into Verbs and Nouns.

Bigger words could also be formed by compounding smaller words. Something like in aero-plane, penta-gon, row-houses, neuro-surgeon..

There is a kind of definite relation between the words.. a set of equals, a cluster, a relation between them, a prefix addition, a suffix addition. This process of compounding words is called as samaas. The contexts of individual words are dropped and they fuse to form a single word and the gender and plurality of the new formed word depends on the kind of compounding.

ramakrishna (rama and krishna)(AGGREGATION)
himalaya (house made of ice) (OBJECT)
rambhakt
(bhakt of rama) (RELATION)
yathashakthi, anusashan, nishabd (PREFIX)
buddhiheen (SUFFIX)

Sandhi literally means packing. It happens at sound boundaries.. Sometimes there are stark adjustments and sometimes no change at all. Even in English speech it can be observed.

I am eating.. Notice 'ya’ sound at the joint, ‘me’ sound in the second joint.

Sandhi is a kind of welding and marriage between the 2 bordering sound elements. When they belong to different families, a kind of adjustment is needed in the mouth for a fluid transition.

deva + alaya = devaalaya
surya + udaya = suryodaya
su + agata = swagata
duh + yodhana = duryodhana

Sandhi or packing happens at every stage.. When roots merge with suffixes to form nouns and verbs.. when compound words are formed.. when prefix filters are applied.. when words are packed into a sentence.

Information Coding and Compression Paradigm

Orthogonal Filters -Maheshwara Sutra

I was watching a short video on evolution of databases. Unstructured database access in github, twitter handles to nexflix recommendations.. And complex graph based structured access for google search.

A sharp tool or an instrument helps us get the result with ease and precision. It is like a special filter that produces the effect with ease and dexterity.

The alphabet in Sanskrit are traditionally arranged in a matrix form. Panini revolutionizes it by linearly arranging them as 14 sets according to their vocal properties. This list is known as Maheshwara or Shiva Sutra. For instance the vowels are spread across the first 4 sets. The later sets correspond to semi vowels, nasals sounds, consonants arranged by aspiration and voice property and thermal sounds.

Video Presentation from Neelesh Bodas

In order to access a range of elements from this list, he provides a simple mechanism of pratyaharaa list and anubandah markers. The last element in each of the 14 sets above is a dummy marker element that aids in the list name identification..

A list was referenced by picking the first member and the last marker member of the last list. For example, the set of vowels which spawned 4 rows was referenced by just calling it ac. Through this scheme, he provides a mechanism to seamlessly index about 40 subsets by using only 2 letters. He uses only 55 bytes instead of 1600 bytes otherwise.

This novel arrangement is like an edge filter on a word and is used widely for noun verb generation, samaas and sandhi packing. The truth tables of Sandhi combinations were greatly simplified.

Where does this novel arrangement fit in?

Just to get an intuition.. We have seen Sandhi. There can be numerous combinations of vowels and consonants in Sandhi. Instead of enumerating each combination, he breaks down the combinations into template classes. Something like Set A interacts with Set B and results Set C types.. And his novel arrangement and lists come handy in this Template and Set arrangement.

Just like in chemistry, we dont study the interaction of every element with another.. But Sodium series with Flouride series and so on.. His classification helped in breaking the myriad combinations into distinct combinations. Not a surprise that Mendaleef was inspired by Panini for his work,

Meta Language and Structure

We have already seen the Shiva Sutra as a tool and the smart listing scheme with pratyaya and anubandha.

Panini cleverly seperates the databases from the algorithm. The data bases included the Shiva sutra list, the noun roots, the verb roots, the gender rules for nouns and so on. The algorithm accessed the database and outlined the process for word and sentence generation from the root sounds.

In his algorithm he introduces meta language aliases and macro body like concepts to avoid repetetions. These were called as sangya and adhikaaras. There were 91 aliases and 73 macro bodies.

Pieces of code were written in generic and override kind of blocks known as utsarga apavaada

There was inheritance principles. The nouns were generated with sup suffix list.. the verbs were generated with the tant list. There was superposition kind of concepts where one kind of verb object type inherits from another type of verb and then overrides a few.

There was bootstrapping kind of philosophy where some global objects are defined and the contexts are to be understood and referenced later on when needed.

Seperation of Algorithm from Databases, Meta language, defines, declarations, lists, list of lists, Classes and Inheritance, Superimposition, Overrides, Global Context, Scope resolution of Methods..

Compression achieved

The total number of words in Ashtadhyayi is 7,000. The Total number of words after repeating the words with anuvrtti is 40,000. Panini needed only approximately one-sixth of the words that would have been required without anuvrtti. He achieved compression by a factor of 3 in terms of byte size, making memorisation easy.

Before & After Panini

Well, the Sanskrit grammar was existing even before Panini. Each of the Vedas had their own branch of Grammar. Perhaps he used the work of his predecessors. Panini kind of created a baseline standard version of Sanskrit Grammar. He tried to include the different flavors and usages.

Along with Ashtadhyayi, he has compiled the Maheshwara Sutra, the Guna paata on noun stems, the Dhatu paata on verb stems, Linganusashana on gender and PanineeyaSiksha on phonetics.

A 17th-century birch bark manuscript of Pāṇini’s grammar treatise from Kashmir

As Ashtaadyaayi was kind of very cryptic and concise, sage Patanjali’s MahaBhashya provides illustrations and commentary on Panini’s work. This was in 300 BC, about 300 years after Panini.

Siddhanta Kaumudi is a Sanskrit commentary by Bhattoji Dikshita in the 17th century on the Ashtadhydyi. It re-arranges the sutras and kind of simplifies the representation. His work was edited in three abridged versions by his student Varadarāja. The shortest version having only about 700 of Panini’s 4000 rules.

Open Questions

But, How did the Big Bang happen? How were sound blobs bucketed into roots, immutables, non overlapping affix suffix prefix sounds? How did they fix on the 2000 root sounds? Any correlation with Tamil roots?Could there be more? Why did vowels have 2 place holders? Why some sounds are not present in the Sanskrit alphabets though some of them seem to occur during transitions.

In a stream of untrained syllables, how to identify the markers for words?

How could we use Panini’s filter in modern day Acoustics, linguistics, NLP? Can it be used to study the Covid distribution as a function of linguistics?

Will blog more on these topics later.. If you have reached this point.. I hope you have a small view on this topic. I have bookmarked some resources for beginners, further viewing etc. Check them at your leisure.

Sneak Peek into his Code

Have a look at Ashtadyaayi and the auxillary texts in the 21st century HTML format.

In Chapter 1in the first 2 lines he defines the technical terms vṛ́ddhi and guṇa. Expanding them by using the indexing mechanism for Shiva Sutras, {ā, ai, au} is vṛ́ddhi and {a, e, o} is guṇa

1.1.1 वृद्धिरादैच्
1.1.2 अदेङ् गुणः

In the below rule, he defines the transformation when ik list sounds meets a. It forms a sound from yan list. For eg. नदी + अत्र → नद् य् + अत्र → नद्यत्र

6.1.77 इको यणचि

He defines the various lists through this big macro body spanning chapters -pratyaya. The noun and verb affix sup and ting list which we have seen before, he represents them through these lines in the packed form which expand to

3.1.1 प्रत्ययः4.1.2 स्वौजसमौट्छष्टाभ्याम्भिस्ङेभ्याम्भ्यस्ङसिभ्याम्भ्यस्ङसोसाम्ङ्योस्सुप् => सुँ-औ-जस्-अम्-औट्-शस्-टा-भ्याम्-भिस्-ङे-भ्याम्-भ्यस्-ङसिँ-भ्याम्-भ्यस्-ङस्-ओस्-आम्-ङि-ओस्-सुप्3.4.78 तिप्तस्झिसिप्थस्थमिब्वस्मस्तातांझथासाथांध्वमिड्वहिमहिङ् => तिप्-तस्-झि-सिप्-थस्-थ-मिप्-वस्-मस्-त-आताम्-झ-थास्-आथाम्-ध्वम्-इड्-वहि-महिङ्

Databases sets like noun and verb roots groups are referenced by the first term followed by adhi. This style is seen in Lalitha Sahasranamam and other works where a popular set is referenced by the first member followed by adhi.. And in the periodic table Lanthanides Actanide sets..

Prof Madhav Deshpande Talk

https://youtu.be/N5BcwDcb6Rs

Wonderful talk on the social dynamics and space and time history of Sanskrit and a view beyond Panini in a very story like narration.

On the 3 shades of past tenses which were earlier used, I remember Sundarakandam having a lot of jagaama and double sound kind of resonant words.

Interesting to note dual noun contexts were disappearing in Ashoka time in Prakrit and the sound changes in various regional Prakrits. Raja becoming aa-aa in East, raya in south, racha in West..

Astadyayi more as Authentication mechanism of Language and not for learning the language itself.

Proper Sanskrit according to Panini was spoken in Aryavarta region by Brahmins during ritual time.

I used to wonder if Sanskrit was the language for mantras, literary works and perhaps Prakrit spoken other time. In Sundarakandam, Hanuman says let me speak to Sita in Sanskrit, the language of humans and dwijas.

In Siberia, A German scholar translates Astadyayi. Was it the inspiration for Mendaleef?

REFERENCES

Grammar lessons by Neelesh B https://youtu.be/TgkOHrlq8qg

https://nivedita2015.wordpress.com/2016/10/12/video-overview-of-the-paninian-grammar-neelesh/

Astadhyaayi & associated works in HTML Format
https://ashtadhyayi.com/sutraani/

Quora topic on Suffixes

https://www.thehindu.com/society/history-and-culture/panini-worlds-first-informatician/

http://web.stanford.edu/~kiparsky/Papers/hyderabad.pdf

RESOURCES

1 WEEK SPOKEN COURSE

Sanskrit through Stories Madras College, Book Box

Sanskrit through Recipes

GRAMMAR RESOURCES

NOUN TABLES -https://www.sanskrit-trikashaivism.com/en/learning-sanskrit-declension-1-1/436

ORAL RECITATION of Noun Table

Sandhi https://openpathshala.com/sandhi-in-sanskrit

Samaas https://openpathshala.com/samas-in-sanskrit

Laghu Siddanta Kaumudi Video Lectures

Noun & Verb FORMATION Video by Neelesh B
https://sanskritstudy.blogspot.com/2009/10/padam.html?m=1

PRAVESHA Content

--

--

Sujatha Ratnala
Sujatha Ratnala

Written by Sujatha Ratnala

I write.. I weave.. I walk.. कवयामि.. वयामि.. यामि.. Musings on Patterns, Science, Linguistics, Sanskrit and other things..

Responses (1)