HomeScripturesHindu scripturesThe Unwritten LibraryVol 5 · Ch 3
Volume 5 · Chapter 3 · 10 min read · By Aninda Nath

The Perfect Machine

Vyakarana is grammar, one of the six Vedangas, the limbs that protect the Veda. Its central monument is Panini's Ashtadhyayi, a formal, generative description of Sanskrit built from roughly 3,959 short rules. It is usually dated to about the fifth or fourth century BCE.

The river meets another river near a town the texts call Shalatula. The Indus takes in the Kabul. Somewhere on that ground, more than two thousand years ago, a man sat down and wrote a language as if it were a machine.

He left almost nothing of himself. We have his work, and a name. The name is Panini.

One question

Here is the thing that should not be possible. A grammarian in the Indian northwest, well over two thousand years ago, produced a complete, formal, almost algorithmic description of a living language. Rules that take in roots and affixes and grind out correct words. Rules ordered against each other so that when two of them clash, there is a procedure to decide which one fires. A technical vocabulary built only to talk about the rules themselves.

The West did not reach that kind of description until the twentieth century.

This is vyakarana, grammar, one of the six Vedangas, the limbs of the Veda we met in this volume’s opening chapter on the limbs themselves. The previous chapter followed the keepers of the sound, the men who held the Vedas intact by voice. Grammar is the limb that explains the words. Its monument is one text.

The question of this chapter is narrow. How did one man build this.

Eight chapters

FOUR THOUSAND THREADS, ONE LOOM14 Maheshvara Sutrasthe full sound inventory, in fourteen linespratyaharatwo letters name a whole class of soundsabout 4,000 sutraseight chapters, four quarters eachanuvritti: a condition carries forwardparibhashameta-rules: which rule wins when rules fightroots and affixes in, correct Sanskrit outSANATANA RAHASYA
Four thousand threads. One loom.

The text is the Ashtadhyayi. The name is plain: ashta, eight, and adhyaya, chapter. Eight Chapters.

Each adhyaya is divided into four pada, quarters. Eight chapters of four quarters gives thirty-two pada in all. Into those run the rules.

A rule is a sutra, literally a thread, the same word that names a thread of pearls. A grammatical sutra is brutally short. It is built to be memorised and chanted, not read for pleasure, and the tradition prized brevity to the point that a saved syllable was said to be worth as much as the birth of a son. How many sutra are there? The count is not fixed. Editions and recensions give a range, roughly 3,959 to about 4,000. The fourteen sound-rules we will come to are counted on their own, outside that total.

So: eight chapters, thirty-two quarters, on the order of four thousand threads. That is the scale. Now the harder claim. The Ashtadhyayi is a system that runs, not a list to be looked up.

Where and when

Before the machine, the man.

Tradition puts Panini’s birth at Shalatula, in ancient Gandhara, near where the Indus and the Kabul meet, close to modern Attock in northwest Pakistan. The attribution is old and widely accepted. We have no inscription, no tomb, no contemporary witness.

The date is worse. Estimates spread across the sixth to the fourth century BCE, with most scholars settling near the fifth to fourth. The cautious anchor comes from George Cardona, whose Panini: A Survey of Research (1976) weighed the evidence and argued that it supports a date not before about 400 BCE. Treat that as a floor, not a fixed point. Cardona’s reading is conservative on purpose.

What survives, then, is the work and a window of perhaps two centuries in which to place it. Everything else about the perfection is inside the text.

The drum

The system begins with sound, and with a story.

At the head of the grammar stand fourteen short aphorisms, the Maheshvara Sutras, also called the Shiva Sutras. They are not grammar in the ordinary sense. They are an inventory: the varna-samamnaya, the full set of Sanskrit phonemes, listed in a particular order that is not the order a child would learn. Tradition holds that these fourteen issued from the damaru, the small hand-drum of Shiva, sounded at the end of his dance. That is what the tradition holds. The order, whatever its origin, was chosen with a purpose, and the purpose is the trick that makes the whole grammar compress.

Each of the fourteen lines ends in a marker sound. This marker is an anubandha, also called an it, a tag with no phonetic value of its own, present only to do work for the system.

Here is how the work is done. A rule, Ashtadhyayi 1.3.3, halantyam, declares that a final consonant in this technical context is a marker rather than a real sound. A second rule, Ashtadhyayi 1.1.71, adir antyena sahetā, says that an initial sound taken together with a final marker denotes all the sounds lying between them. Pair a starting phoneme with a closing tag, and you have named a class.

That paired name is a pratyahara, an abbreviation. The vowel a taken with the marker C gives aC, which stands for every vowel at once. The consonant h taken with the marker L gives haL, which stands for every consonant. Dozens of such labels fall out of the same fourteen lines. This is set notation, written down in the centuries before the Common Era, a way to point at an entire category of sounds with two letters.

The drum, in the story, gave the order. The order gave the algebra.

Carrying forward

A grammar of four thousand rules would drown in repetition if every rule restated its own conditions. Panini’s answer is anuvritti, carrying forward.

A word stated in one sutra is silently inherited by the sutra that follow it, until something cancels or replaces it. State a condition once at the head of a run of rules, and it governs all of them without being spoken again. A modern programmer would recognise the idea at once. It is scope, a value set once and held until it goes out of range.

The economy is severe. To read any single rule correctly, you must already be carrying the rules above it in your head, the way the reciters of the previous chapter carried the Veda. The Ashtadhyayi assumes a reader who never forgets the line before.

That assumption is also a vulnerability, because now the rules depend on each other, and dependent rules can collide.

When rules fight

What happens when two rules both apply to the same form and demand different things?

A flat list cannot answer that. Panini’s grammar can, because above the ordinary rules sits a second tier: the paribhasha, the meta-rules. These do not describe Sanskrit. They describe how to read and apply the rules that describe Sanskrit. Which rule outranks which. How an inherited condition is to be understood. What to do when two operations compete for the same slot.

One such meta-rule sits at the centre of a debate that has run for two thousand years. Ashtadhyayi 1.4.2, vipratisedhe param karyam, governs conflict. The long-standing reading is that when two rules of equal strength clash, the later one in serial order wins. We will return to that single line at the end of this chapter, because a Cambridge thesis recently proposed reading it in a wholly different way.

For now, hold the architecture. Ordered rules. A metalanguage of abbreviations. Inheritance between rules. Meta-rules that adjudicate when rules fight. Put together, it is a formal, generative system: feed it roots and affixes, run the rules in order under the meta-rules, and correct Sanskrit comes out. This is why it is so often called the first formal grammar.

It is also why the man who built it did not have the last word.

The three sages

The Ashtadhyayi was too important to leave alone, and too tight to be perfect. What followed is the trimuni, the munitraya, the three sages of the grammatical tradition.

First, Panini himself, the sutrakara, the maker of the threads.

Second, roughly in the third century BCE, Katyayana, also known as Vararuci, the varttikakara. His Varttika are critical notes on Panini’s rules, correcting them where they overreach, supplementing them where they fall short, refining them where they are unclear. He read the machine and filed its faults.

Third, around the second century BCE, came Patanjali the grammarian, whose Mahabhashya, the Great Commentary, is the masterwork of the three. It quotes Panini, quotes Katyayana, and sits as judge between them, weighing rule against objection, deciding what stands. The tradition’s own maxim ranks them in a line: yathottaram muninam pramanyam, the authority of the sages increases in later order. The later voice settles the earlier.

One caution. This Patanjali the grammarian is traditionally identified with the Patanjali of the Yoga Sutras. That identification is not historically established and is doubted by most scholars. Keep the two apart in your mind. We have a grammarian named Patanjali, and we have a yoga teacher named Patanjali, and the bridge between them is faith, not evidence.

Three men, three or four centuries, one machine repaired in public. And then, for a very long time, the West knew none of it.

The greatest monument

When European linguists finally read Panini, they did not respond with politeness. They responded with shock.

Leonard Bloomfield, the American structuralist whose 1933 book Language shaped a generation of the field, had already met the Ashtadhyayi. In a 1929 review published in the journal Language, volume 5, he wrote that the descriptive grammar of Sanskrit which Panini brought to perfection is “one of the greatest monuments of human intelligence.” Note the two corrections that careless writers get wrong. It was Leonard Bloomfield, not his cousin the Sanskritist Maurice Bloomfield. And it was 1929, not 1933.

The Dutch scholar Frits Staal went further into the machinery. Staal argued that the Indian grammarians, Panini above all, had commanded methods of linguistic theory that the West did not rediscover until the 1950s. He documented a precise parallel: Panini’s anubandha markers behave like the auxiliary symbols in the rewrite systems of the logician Emil Post, the production systems that sit under modern formal-language theory.

That parallel is where the story turns from the ancient to the digital.

The machine and the machines

Programming languages need a way to describe their own grammar. The standard tool is Backus-Naur Form, BNF, a metalanguage for writing the syntax of a language in formal rules. It was introduced by John Backus for ALGOL 58 around 1959 and named after him and Peter Naur around 1963.

In 1967, the computer scientist P.Z. Ingerman noticed the resemblance. He proposed calling it “Panini-Backus Form,” pointing to the shared features: recursion, auxiliary markers, meta-rules above the object rules. The honour was sincere and the structural likeness is real.

It is also where the discipline of this house matters most. Ingerman’s renaming is a retrospective analogy, a tribute. It is not evidence that Backus or Naur ever read Panini, and no one should claim the Ashtadhyayi as the source of BNF. The two systems converged on similar solutions because similar problems pull toward similar shapes. “BNF is just Panini renamed” is false, and so is the louder claim that Panini invented binary or the computer. Binary numbering in this tradition belongs to Pingala, the metrician of the previous chapter, in the last part of his work, not to Panini at all. Convergence is remarkable enough without inflation.

Which brings us back to one line.

The rule that fights itself

In December 2022, a Cambridge doctoral thesis made global headlines. A young scholar named Rishi Rajpopat, the press reported, had solved a problem that had stood for two and a half thousand years.

The line at issue is the one we set aside earlier: Ashtadhyayi 1.4.2, vipratisedhe param karyam. For most of the tradition, para in that rule meant later in serial order, so that of two competing rules the one printed afterward should apply. That reading leaves a residue of cases where it produces the wrong Sanskrit, and the tradition patched those cases with further exceptions. Rajpopat proposed reading para differently, as the rule applicable to the right-hand part of the word being formed. On his reading, many of the stubborn conflict cases resolve cleanly without the patches. He set it out at length in his book, Pāṇini’s Perfect Rule (Harvard University Press, 2025).

Two cautions, in the spirit of the whole chapter. The thesis is his, and it is contested, not yet settled consensus among Sanskritists. And “solved a 2,500-year-old problem” is press framing, not a verdict the field has signed.

But notice what the news itself proves. The machine is still running. A single one of its rules can still be read, and re-read, and argued over, by people who treat it as a living system rather than a relic.

The man at the river meeting left no portrait. He left the most exacting description of a language anyone made before our own century, and a tradition still bent over it. The next chapter turns from the form of words to what they carry: meaning, and the measure of time.

Four thousand threads. One loom.

Frequently asked

What is the Ashtadhyayi?

The Ashtadhyayi ("Eight Chapters") is Panini's grammar of Sanskrit. It contains roughly 3,959 short rules called sutras, arranged in eight adhyayas of four padas each. It is a formal, rule-ordered system that generates correct Sanskrit forms from roots and affixes, and it is widely described as the first generative grammar.

When did Panini live?

We do not know exactly. Tradition places him at Shalatula in ancient Gandhara, in what is now northwest Pakistan. Scholars usually date him to roughly the sixth to fourth century BCE, with the fifth to fourth century the most cited window. George Cardona's survey of the evidence argues for a date not before about 400 BCE.

Was Panini's grammar really like a computer program?

The comparison is real but easy to overstate. Panini's grammar uses ordered rules, a technical metalanguage, abbreviation by markers, and meta-rules for resolving conflicts, which is why linguists and computer scientists have drawn parallels to formal-language theory and to Backus-Naur Form. He did not invent the computer or binary. Binary numbering in this tradition belongs to Pingala, not Panini.

Sources
  • Panini, Ashtadhyayi 1.1.71, 1.3.3, 1.4.2
  • George Cardona, Panini: A Survey of Research (1976/1980)
  • Patanjali, Mahabhashya
  • Leonard Bloomfield, review of Liebich, Language vol. 5 (1929)
  • Frits Staal, on Indian grammarians and formal method
Share this

Read next

From the journal

Referenced in

Cited across 2 treatises · 2 reference entries.