Friday, December 16, 2011

The relativity theory of superiority

Everybody knows that Hanuman is very humble and always considered him only a daasa of Rama. But how humble was he? Can his humbleness be mistaken for weakness or lack of confidence?

Valmiki establishes the character of Hanuman in such a way that whatever action he took, that was possibly indeed the only best course of action. Throughout the course of sundara kanda, Hanuman makes numerous instant decisions that lead the story from one thrilling frame to another. The whole sundara kanda, frame-to-frame, is about how to take right decisions at the right time.

One such scene is when Hanuman takes departure from Sita. A simplistic retell of the story is just that Hanuman gets the cUDAmaNi from Sita and promises her that he will be back with Rama to free her. But in the details, Valmiki establishes a very deep analysis of human emotions in sorrow. Every dialog of which is something we can relate to easily in our lives.

In foreign lands, especially in remote towns, desis easily get excited by seeing one of their own. One may be from a remote village in South and another from Punjab. But in a foreign town of ten desis, language, religion and other barriers are forgotten and everyone instantly feels 'bhai-bhai'. After a long time, Sita has finally met someone who is acquainted with her husband. She naturally pleads Hanuman to stay secretly nearby for one more day, for it will console her to have someone nearby in the dreaded ashoka vana. Inspite of knowing Hanuman's exploits, she then carefully places a doubt whether Sugriva and his army of monkeys are capable of crossing the ocean and taking on the might of Ravana.

A very tricky question indeed. He has just crossed the ocean after a long journey, seen how huge, glorious yet intimidating Lanka is. He knows Rama is superior, he believes in his own strength, but he does not know the full strength of Ravana and his company yet. There is no indication he had given thought about how other monkeys can cross the ocean. Hanuman cannot say something like 'Yeah ma'm, we will try our best'. He has to completely reassure Sita of the capabilities.

The sequence of arguments he puts forth is very logical. He first mentions the leader, Sugriva is completely committed to the cause (of freeing her). Then he mentions the number of monkeys in his army (thousands of crores of monkeys). That sheer number should give confidence to Sita. Then he mentions their overall qualities - power, perseverance and loyalty to Sugriva. He finally puts forward a statement thats unbelievably astonishing, that silences any doubt of not only Sita, but even the reader.

मत् विशिष्टाः च तुल्याः च सन्ति तत्र वनौसः ।
मत्तः प्रत्यवरः कश्चिन् न अस्ति सुग्रीव संनिधौ ||

mat vishiShTaaH ca tulyaaH ca santi tatra vanausaH |
mattaH pratyavaraH kashcin na asti sugrIva saMnidhau ||

अहम् तावत् इह प्राप्तः किम् पुनः ते महाबलाः ।
न हि प्रकृष्टाः प्रेष्यन्ते प्रेष्यन्ते हि इतरे जनाः ॥

aham taavat iha praaptaH kim punaH te mahaabalaaH |
na hi prakRuShTaaH preShyante preShyante hi itare janaaH ||

All other monkeys are either equal to me or above me in valor. There is no one inferior to me in Sugriva's army. If I could come here in one leap, what to say about others? Superiors are not sent for errands, only the inferiors are, isn't it?

Hanuman was hand picked for this task by none other than the great Jambavan, further entrusted personally by Rama, purely on the basis of his most superior ablities. Yet Hanuman turns it around completely the other way, quoting that only inferior people are sent for errands, which for a moment makes perfect sense to console Sita. He does not say he is the most inferior - that would have shown lack of confidence. He says there is no one else inferior than him. He is humble, yet there is absolutely no lack of confidence.

Simply put, there is no other statement that would have quelled the doubt of Sita, than how Hanuman put it.

Thursday, December 15, 2011

The power of dsl

When I started the samskritam-dsl project, one of my goals was to develop a domain-specific language that will allow to interact with the system using a natural syntax. Not just a programmer, but a samskritam pundit with a basic computer knowledge should be able to interact with the system. While that interaction is still a long way, I feel there are some foundations in place. The sandhi-s as described in ashtaadhyayI are very arithmetic like, yielding consistent results, so a program model should be able to simulate that.

For eg

assert 'a' + 'a' == 'A' //akaH savarNe dIrghaH sandhi

instead of

assert new Varna('a').add(new Varna('a').equals(new Varna('A')) == true

The former is obviously easier to understand as it follows mathematical conventions, instead of being bound by rigid programmatic syntaxes.

Static programming languages like Java just do not allow this kind of flexibility. But dynamic languages like Groovy/Ruby/Scala having special features for creating such constructs.

Let's go a step further than the above simple sandhi:

assert 'bhU' + 'sap' + 'tiG' == 'bhavati'  //bhU dhatu, kartari sap, prathama, parasmai-padam, eka vacanam, prathama purushaH

Is the above possible?

Before we answer that, does the above assert statement make sense at all? How do you know, or how do you make the computer know, that bhU is the dhaatu, sap is the vikaraNa pratyayaH, and tiG is the padam pratyayaH ? They are all straight strings and not objects. How do you tell the difference? Now lets say we rewrite the above assert slightly differently --

assert 'bhU'.dhatu + 'sap'.pratyaya + 'tiG'.pratyaya == 'bhavati'

Now, that reads better! A simple domain knowledge is now converted into a programmatic construct, yet it almost reads just like samskritam! As you read the sentence, it seems very natural. 

That, mon ami, er, mama mitrANi, is the power of dsl.

Here are the implementation details:

class Samskritam {
  def getPratyaya() { return new Pratyaya(this) }
  def getDhatu() { return new Dhatu(this) }

class Dhatu {
  def name
  Dhatu(String _name) { name = _name }
  String plus(Pratyaya p) { name + ' ' + p.toString() }
  String toString() { name }

class Pratyaya {
  String value
  String realValue
  Pratyaya(String _value) {
    value = _value
    realValue = value?.tasya_lopaH()
  String toString() { realValue }

So what sutram-s are involved here? Lets skim through the important ones -

bhU + shap -> p gets dropped due to halantyam; sh gets dropped due to lashaku ataddhite
bhU + a -> bhO + a; due to aad guNaH
bhO + a -> bhav; due to eco ayavaayaavaH
tiG -> the G gets dropped due to halantyam
bhav + a + ti -> bhavati
Here is the complete test case:

use (ch8.lang.Samskritam) {
  def a1 = 'bhU'.dhatu + 'shap'.pratyaya + 'tiG'.pratyaya
  def a2 = sandhi.apply(a1, sandhi.aad_guNaH)
  def padam = sandhi.apply(a2, sandhi.eco_ayavaayaavaH)
  assert padam == 'bhavati'
The sandhi methods aad_guNaH and eco_ayavaayaavaH also obediently follow Paninian technique of replace the varnas using respective rules. 

Once again, the full code is in

Sunday, December 11, 2011

sthAne antaratamaH

A Functional Approach

It is very interesting to observe that Panini's approach to sandhi-s is thoroughly function oriented and very algebraic in execution. Sandhi-s in Samskritam are profound sophistications. We shall see how functional programming naturally fits into Panini's approach. Once again I'm not describing theories, but real testable executable code and assertable outputs.

For the samskritam-dsl project, I was trying to come up with a simplistic representation of sandhi-s. The famous iko yan aci sandhi belongs to the purva rupa sandhi (the first word gets modified) and Panini's general technique can be functionally written as:

f = sandhi(sthana, adesha, vidhi, purva, para)

This is understood as:  "The adesha (substitute) replaces the sthana (substituted) of the purva shabda when vidhi is true on the para shabda"

Panini uses natural linguistic approach and places sthana in 6th vibhakti, adesha in 1st vibhakti and vidhi in 7th vibhakti.

So lets rewrite this in functional programming notation -

  //purva rupa sandhi sutra - closure
  def purvaRupaSandhi = {sthana, adesha, condition, words ->
    def (purva, para) = words.tokenize()
    if (condition(para)) {
      def k = sthana.substitute(adesha, purva.lastVarna())
      purva + para
    } else {

Here sthana is the list of substituted varnas (eg ik), adesha is the substitute varna (yaN). Condition is not a list but something that evaluates to true or false based on the para shabda. So its a closure again.

  def aci = { word -> word.varnas()[0].svara() }
  def jshi = { word -> word.varnas()[0] in sivaSutra.jsh }

Basically the above closure evaluates to true if the first varna of the shabda is a svara.

Remember we defined the purvaRupaSandhi as a completely generic closure. It will take any sthana, adesha and condition. How do we apply this to iko yaN aci or say, jhalaam jash jhashi?

Groovy provides the "currying" feature --

  def iko_yaN_aci = purvaRupaSandhi.curry(sivaSutra.ik, sivaSutra.yN, aci)
  def JalAm_jash_Jashi = purvaRupaSandhi.curry(sivaSutra.Jl, sivaSutra.js, jshi)

Real functional programming stuff here. aci and jshi are closures/functions which are passed to purvaRupaSandhiwhich evaluates it based on the para shabda.

Now for some more beauty. How do we substitute sthana with adesha? Panini defines a really brilliant sutra 'sthAne antaratamaH' - the closest phoneme of the adesha to the sthana, must substitute the sthana. Now how do we find the closest ? When pronouncing it is easy to realize that i is close to y or u is close to v. But how does that translate to programming terms? This is when it dawns upon us that Panini's approach is extremely methodical.

Recall the definitions of phoneme-sets?

akUhavisarjaniyanaam kanTaH | icuyashaanaam taalu | RturaShaaNaam mUrhda | Ltulasaanaam danta | upUpadhmaanIyaanaam oshta |

So if a varna from sthAna exists in one of the above sets of phonemes, then the common varna between that phoneme-set and the adesha will substitute the sthana !!!

Illustration: jhalaam_jas_jashi

example: ap + dhi

purva shabda - ap (varna is p), para shabda - dhi, satisifies condition jashi (dha). Good.

sthAna - p, adesha will be one of jash = [j, b, g, d, dh] -- now which to pick?

p exists in oshta phoneme-set; so we have to pick one from pu = [p, ph, b, bh, m] - but which one?

Remember jash adesha is [j, b, g, d, dh]. So intersect oshta with adesha, which will result in b -> that substitutes 'p' - resulting in abdhi !

Can you now appreciate the functional beauty of maheshvara sutra?

So the formula is
  def ku = [k, kh, g, gh, ~n]
  def kanta = ['a', 'A'] + ku + ['h'] + [':']
    Closure sthaneAntaratamaH = { x, adesha ->
    for (def phonemeSet : [kanta, taalu, murdha, danta, oshta, dantoshtam]) {
      if (x in phonemeSet) return phonemeSet.intersect(adesha)

That's it!! The 2 closures basically take care of any purva rupa sandhi rule! Only the additional conditional closures (aci, jashi etc.) must be provided as required.

Finally we verify

assert iko_yan_aci("iti api") == "ityapi"
assert jhalaam_jash_jashi("ap dhi") == "abdhi"

As usual the code can be found at

PS: Post this blog, I tried to verify purvaRupaSandhi closure by adding another rule "stoH shcuna shcu:" and it worked just fine. But there is a catch. The shcuna in the rule is not in 7th vibhakti, but is in instrumental case. And there is a reason why Panini uses 3rd vibhakti. The 7th vibhakti indicates the rule to be applied with respect to what follows, while the 3rd vibhakti implies just the contact of two varna-s are sufficient to produce the sandhi. The closure does not take care of that yet.

The functional programming approach of Panini makes me believe that universities should include ashTAdhyAyI as a course in Computer Science, instead of just being a research subject to elite academicians.

Tuesday, November 29, 2011

Chapter 8 DSL in GitHub

The chapter 8 dsl project is now available at github at It is just in very early stages and I will be updating whenever I get some free time.

Thursday, November 17, 2011

The Chapter 8 DSL

Domain Specific Language is fast becoming a popular way to describe a problem or a solution for a specific domain. The quality and readability of code using DSL is magnitudes above the regular "technical" code (using Java/C# for eg). Since information about DSL can be googled amply, I am not going to spend time writing on what a DSL is.

In many of the previous posts, I had used pseudo-code, demonstrating parallels in programming to Panini's techniques. Time to call the bluff now. Presented below is a seriously tested code. Here is a DSL that closely models some basic techniques of ashtaadhyaayI, specifically the maheshvara-sutra-s and those darning "it" rules. I'm using Groovy for the implementation, as I feel that it's syntax is more natural to read than that of Scala or Ruby.

Let's define some classes.

[Listing 1: SivaSutra.groovy]
package ch8

import java.util.List

 * Implementation of Maheshvara Sutra using SimpleScript transliteration scheme
 * The table itself can be moved to a groovy configuration file to allow a different scheme like HK, ITRANS or AST
 * @author vsrinivasan
class SivaSutra  {

  List table =
    ['a', 'e', 'u', 'N'],
    ['r.', 'l.', 'k'],
    ['E.', 'o', 'n'],
    ['i', 'O.', 'c'],
    ['h', 'y', 'v', 'r', 't'],
    ['l', 'N'],
    ['n.', 'm', 'n', 'N', 'N.', 'm'],
    ['J', 'B', 'n.'],
    ['G', 'D', 'D.', 's.'],
    ['j', 'b', 'g', 'd', 'd.', 's'],
    ['K', 'P', 'C', 'T', 'T.', 'c', 't', 't.', 'v'],
    ['k', 'p', 'y'],
    ['s', 's.', 'S', 'r'],
    ['h', 'l']

  List list = table.flatten()

  int indexOf(String varna) { list.indexOf(varna) }

  Iterator iterator() { list.iterator() }

  //eShaam antyaaH it
  List itMarkers = table.collect { it.last() }

   * is this iT-marker?
   * this finds only 'pratyahara iT' is defined, for other it-s see ItRules.groovy
   * @see ItRules
  boolean isIt(f) { itMarkers.contains(f) }

   * expands a given pratyahara, including all the iT-s
   * not for practical purposes, but good for testing
   * @param pratyahara
   * @return
  List expand(String pratyahara) {
    def (begin, end) = pratyahara.varnas()

   * returns the real pratyahara varna-s, excluding the intermediate it-markers
   * very procedural implementation, need to make it groovy-like
   * @param pratyahara
   * @return
  List collect(String pratyahara) {
    def (begin, end) = pratyahara.varnas()
    boolean start = false
    def result = []

    table.each { line ->
      line.each { item ->
        if (item == begin || start) {
          if (item != line.last()) {
            result << item
            start = true
          if (item == end && item == line.last()) {
            start = false
    return result

[Listing 2: ItRules.groovy]
package ch8

class ItRules {

  //#(1.3.2) upadeshe ajanunaasika iT, anunAsika-s are denoted by a "-" at the end,
  //  may be M would be a better option?
  def ajanunasika = 'aAeEuUr.R.l.E.IOO.'.varnas().collect { it + "-" }

  def cu = 'cCjJn.'.varnas()
  def tu = 'tTdDN'.varnas()

  //s.asca, denoting as "sha" for convenience
  def sha = ['s.']

  //lasaku (ataddhite)
  def ku = 'kKgGn'.varnas()
  def lasaku = 'ls'.varnas() + ku

  //some more to be defined

  //#(1.3.3) halantyam - check if the last char is hal
  SivaSutra sivaSutra = SivaSutra.instance
  boolean hasHalantyam(String pratyaya) { pratyaya.varnas().last() in sivaSutra.hl }

  //allItMarkers except hal, which is applicable only to last letter
  def allItMarkers = ajanunasika + cu + tu + lashaku

  boolean isAnunasika(String varna) { varna.endsWith('-') }

  boolean isItMarker(String varna) { varna in allItMarkers }

  String tasyaLopah(String pratyaya) { (pratyaya.halantyam().varnas() - allItMarkers).join() }

[Listing 3: Main.groovy]
package ch8.tests

import java.util.List

import ch8.ItRules
import ch8.SivaSutra
import ch8.schemes.SimpleScriptScheme
import ch8.Samjna

 * DSL: varnas() closure - tokenize the script into individual varnas (list)
String.metaClass.varnas = {
  new SimpleScriptScheme().tokenize(delegate)

 * DSL: halantyam() closure - remove the last hal iT and return the modified String
String.metaClass.halantyam = {
  ItRules itRules = ItRules.instance
  def varnas = delegate.varnas() as List
  if (itRules.hasHalantyam(delegate)) {

 * DSL: tasyaLopah() closure - remove all the it-markers from a pratyaya
String.metaClass.tasyaLopah = {
  ItRules itRules = ItRules.instance

 * DSL: Direct exposition of a pratyaya or a pratyahara!
SivaSutra sivaSutra = SivaSutra.instance
sivaSutra.metaClass.getProperty = { String pratyahara ->
  def metaProperty = SivaSutra.metaClass.getMetaProperty(pratyahara)
  def result
  if(metaProperty) {
    //if there is an existing property invoke that
    result = metaProperty.getProperty(delegate)
  } else {
      //inspect the property and convert it to varnas
    //taparastatkaalasya rule; need to formulate in a better way
        if (pratyahara.endsWith('t.')) {
      result = (pratyahara - 't.').varnas()
    } else {
        result = sivaSutra.collect(pratyahara)

void testSivaSutra() {
  SivaSutra sivaSutra = SivaSutra.instance

  sivaSutra.table.each { println it } //print the maheshvara sutrani
  println sivaSutra.list //print a flattened version of the maheshvara sutrani
  sivaSutra.each { println it } //another way to print flattened maheshvara sutrani
  println sivaSutra.itMarkers //print only the it markers

  assert sivaSutra.isIt('n.') //check if n. is an it marker

  assert sivaSutra.expand('ak') == ['a','e','u','N','r.','l.','k'] //expand pratyahara including the it
  assert ['a', 'e', 'u']== sivaSutra.collect('ak') //pratyahara excluding iT
  assert ['a', 'e', 'u']== sivaSutra.ak //another way of getting the pratyahara! Meta-programming in play!

void testItRules() {
  ItRules itRules = ItRules.instance

  println itRules.ajanunasika //prints all the ac anunasikas
  assert "lyut".varnas() == ['l', 'y', 'u', 't']}

void testHalantyamRule() {
  //print the pratyahara-s after the halantyam rule applied
  ["", "Gan.", "kt.vat.", "sap", "lyu-t", "saN", "sat.r."].each { println it + " = " + it.halantyam() }

  assert '' == ''.halantyam()
  assert ''  == 'kt.vat.'.halantyam()
  assert 'Ga' == 'Gan.'.halantyam()

void testTasyaLopahRule() {
  ["Gan.", "kt.vat.", "sap", "lyu-t", "saN", "satr."].each { println it + " = " + it.tasyaLopah() }

  assert 'a' == 'Gan.'.tasyaLopah()
  assert '' == 'kt.vat.'.tasyaLopah()

void testSamjnaSutras() {
  SivaSutra sivaSutra = SivaSutra.instance
  def vruddhi = sivaSutra.'At.' + sivaSutra.ic
  def guna = sivaSutra.'at.' + sivaSutra.'E.n'

  assert ['A', 'i', 'O.'] == vruddhi
  assert ['a', 'E.', 'o'] == guna


[Listing 4: SimpleScriptScheme.groovy]
package ch8.schemes

 * A simple script tokenizer
 * @author vsrinivasan
class SimpleScriptScheme implements ScriptScheme {

  // hyphen denotes anunasika
  static List NotationMarkers = ['.', ':', '-']

   * split/tokenize a given word into a list of varnas
   * the word could be a pada, shabda, pratyaya or pratyahara
   * needs to handle anunasika properly
   * @calledby String.metaClass.varnas()
   * @param word
   * @return list of varnas
  public List tokenize(String word) {
    def varnas = []
    word.eachWithIndex { c, i ->
      c = ((i < word.length()-1) ? ((word[i+1] in NotationMarkers) ? (c + word[i+1]) : c) : c)
      if (!(c in NotationMarkers)) varnas << c


Now some observations and analysis:

  1. To do this in a regular Java/C# would require several objects, wrapper-classes and utility methods to be created. But using meta programming techniques and defining a clean DSL makes this a very interesting implementation.
  2. Ability to work directly on strings, lists and maps makes a huge difference, as opposed to wrappers around strings and creating objects like pratyahara, it, pratyaya etc.
  3. The Main.groovy is self-explanatory in what's given and what's expected. This is not pseudo-code anymore! Note the direct method invocation like varnas(), halantyam(), tasyaLopah() on Strings. And also observe the direct reference to a pratyaya ( will expand to a list of vowels). Metaprogramming, awesome or what?
  4. Also observe the testSamjnaSutras() definitions. The only reason I have to quote the properties is due to the usage of dot in the schema. A symbol-less scheme like AST would make a very readable code.
  5. The code uses the SimpleScript for devanagari transliteration. As I had mentioned in a previous post, parsing the script is trivial, because of a strict 1:1 mapping between English and Sanskritam letters. Took less than 5 minutes to write it.
  6. However the code allows to use any transliteration scheme, if one can come up with it, by implementing the ScriptScheme interface. Harvard-Kyoto, ITRANS or AST or even Unicode - as long as the individual varna-s are correctly tokenized, the program will work fine.
  7. Any script scheme can be supplied via a groovy configuration and read by ConfigSlurper!
Obviously this is just the very beginning and some areas are still unpolished. But imagine being able to write code like

assert "bhavati" = bhU + sap + tin //1st gana
assert "kasca" == 'ka:' + sca //scutva sandhi

Imagine being able to work out sandhis just by using the plus sign! (eg ) Wouldn't that be really really cool? And that's not really impossible. It will only take a little more effort to expand the DSL to include anga, guna, operator overriding for sandhi rules etc.!

Imagine similar DSL-s can be implemented for parsing shlokas to determine chandas! The potential for a Samskritam DSL is huge.

Tuesday, November 15, 2011

Read, Restore and so forth

My first sight of a computer was in 1983 in a remote town in India, the deity of the city is a representation of "Conscious-Ethereal Grand Cosmic Nothingness". Our science teacher somehow got hold of somebody who had a Commodore 64. About 40 students from our class (India was that less populous 30 years ago) walked about 5 kilometers on a rainy day to that computer guy's house. We were allowed in a batch of 10 into a room dimly lit and were seated on the floor. A girl, sitting on the chair, was holding a joystick (or a mouse?) and a keyboard and making a noisy typing sound. On the small monitor some rectangles and squares of different colors were jumping around. She was playing some game. She said something about BASIC and thats all we learnt.

Almost 10 years forward. It was the onset of the Russian winter, I was walking with a senior towards the university. He was a smart guy, everybody respected him and was always an A-grader.  We were talking about programming language theories. C++ was just getting popular. He said "Hey, I know Pascal and C. And this year we are learning some AI using Prolog. I've also been learning C++...". He paused. Then suddenly said, "You know BASIC right? Can you teach me that?". I didn't know what to respond, but just said "Sure". I was a bit confused but elated to 'teach' a senior. That opportunity never came though.

Current times. Studying Ashtadhyayi's several techniques which are an illuminating parallel to programming - there is one that is intriguing. It is the word "aadi" given in a context. When Panini wants to mention a group of information, he would just use the first value of the group and suffix it with "aadi" or "aadya:". The reader is obviously either expected to know the list by-heart or refer to it. No big deal, when the average Sanskrit student is expected to know amarakosha by-heart anyway. So the first value of the list itself is used as the "head" to reference the list. This way Panini feeds by a pointer to an array of data using a very simple technique.

A pseudo code may clarify:

/* The list of verbs called as dhaatu paatha */
static Map DHAATU_PAATHA = [bhU:sattaayaam, ... ]

/* pointer to the list of the dhaatu paatha; trying to mimick naturalness - intentionally not referring via the static variable but via the head-value of the list */
char *list_of_verbs = ["bhu"]

Look at some of the sutra-s -

bhUvAdayo dhaatavaH (1.3.1) | By this statement Panini refers to about 2000+ verbal roots in Sanskritam, starting with bhU
sanaadyantaa dhaatavaH (3.1.32) | Refers to the list of derivational roots, the list starts with a verb that ends with suffix "-san"
praadayaH | Refers to the 22 prepositions that start with "pra"

Obviously this technique of "aadi" reference is pretty common in Sanskritam and other Indian literature. Tyagaraja in his siddharanjani kriti naadatanumanisham says "sadyojaataadi pancha-vaktra" referring to the five faces of Shiva starting from sadyoja. Obviously one who is not aware of the details will not know what the rest are, but aadi is just what it is - a pointer to a list of information. If Panini was the one who invented it (lets assume for sake of argument, because Panini had predecessor grammarians too and there were obviously other literature before him), it is a brilliant technique. The technique is not perfect though, because overtime somebody could come up with a modified list with the head-value being the same. But still its a great way to abstract information where the uniqueness of the head-value serves as an emphasised indicator to the contents following it.

Back to programming after the detour. Even after several years in programming, BASIC continues to fascinate me. Given all kinds of high level languages, there is one feature I think I sorely miss from BASIC. It is the "READ...DATA" statement. The READ...DATA statement allows for feeding data to the program in the shortest possible way without having to assign random values individually.

10 FOR I = 1 TO 10: READ X(I): NEXT I
20 DATA 1,3,5,7,11,13,17,19,23,29

20 DATA "James Bond", "555-1212", 3.14, 8
30 DATA "11/11/2011", "All the world's a Pre-Production."

The DATA statement could be anywhere in the program and the READ statement would sequentially read-off the data, like popping off a stack. The RESTORE statement acts like just like the "aadi" of ashtadhyayi - it points to just the beginning of the data. The simplicity of the bootstrap data feed is appreciated when you do not care where the DATA is set. Several high level languages have been invented after that, but not many provide such an easy way to feed bootstrap data to the program variables. Of course there is enumerators and similar stuff, but somehow the simplicity of READ statement stands out. Just like Panini's aadi technique.

Wednesday, September 28, 2011

nandI mukhI


असहाय मेघो इव आटम्
प्लवतर्योऽद्रीनाम् मध्ये
सहसा तदा अपश्यन्
सरोवरतटे तथा तरूणाम् अधो
समीरे लुटन्ति नट्यन्ति च ।

प्रसिद्ध कवे: रचना एषा । कस्य?

Friday, September 16, 2011

The Bidi Messenger

Pretty much everybody has a friend from their college days who was a smoker. A typical college guy, he would stylishly pull a Wills cigarette, fix between his teeth half-biting it, take out a "cheetah" match-stick, almost bringing it towards the cigarette, but slightly bending the neck to reach it, protect it from the winds with the other hand, light the cigarette, all the while making some unintelligible sentences with cigarette in half-open mouth and finally looking up the sky, let out a satisfactory smoke and a sigh, with thoughts lost in a philosophical world. He also would oblige his friends, by letting out "rings". Smoky Rings, especially let out in incremental diameters and one following another in perfectly equal time intervals, was considered the ultimate accomplishment in smoking.

The first time when I came across the text of Meghadhutam, The Cloud Messenger, it was bewildering, to say the least. The loooong shlokas in the mandakraantaa meter (17x4=68 syllables) seemed to have an unhurried pace of its own. The meaning had to be understood from English translations, which painted the idea, but not quite the subtlety. Later I started doing anvaya-s of the shlokas. anvaya-s are exactly like solving jigsaw puzzles. You already know what the final picture is (ie the translated meaning) but the challenge is in getting there: find the most important piece - the dhaatu, group similar vibhakti-s, figure out the kaaraka-s, fill-in the avyaya-s and suddenly a sense appears out of nowhere. The pleasure of anvaya is magnitudes above the pleasure of just reading the translation.

Even the harshest critics of Kalidasa (if any) agree that Meghadhutam is one of the finest and most original works of human mind. It has influenced several poets, both Samskritam and non-Samskritam. Poets have imagined a variety of messengers for whatever purposes. Venetia Asnell blogs that there are about 70 known-so-far messenger-poems in Samskritam alone. Literary gems like Hamsa sandesha, Kokila sandesha being aside, there are also poets who use this technique for ninda-stuti. One poet took it to a new level and composed "Donkey Messenger" (kazhudai-vidu-thoodu, கழுதை-விடு-தூது, in Tamil) to disgrace another poet.

In olden days, smoking was not known to be injurious to health. There was a poet with a pen name "seeni sakkarai pulavar" (funny name, because both seeni and sakkarai mean sugar in different Tamil dialects). It is known that he was born in the family of great poets in Ramanathapuram district. Being a great bhakta of Subrahmanya, he imagines a lady sending the cigarette smoke as a messenger to Subrahmanya in his புகையிலை விடு தூது ("pugaiyilai viDu thoodu", tobacco-smoke-messenger). Out of 59 verses, 53 praise the cigarette and the last 6 contains a message to Subrahmanya svaami of Pazhani (Balasubrahamanya).

கற்றுதெளிந்த கனபர பலவான்களும் உன் சுற்றுக்குள்ளாவதென்ன சூழ்ச்சியோ
kaRRuteLi~nda ganapara balavaangaLum un chuRRukkuLLaavadenna chUzhcchiyO
O Cigarette! Whats the trick that you make even the scholars slave to you?

வாடை பொடிக்கதம்பமனவெல்லம் உன்னுடைய சாடிப்பொடிக்கு சரியுண்டோ
vaaDai poDikkadambamanavellam unnuDaiya chaaDippoDikku chariyuNDO
Can the good smell of Kadamba powders match the smell of yours kept in a jar?

In the course of praising cigarettes, the poet also Indianizes the history of tobacco, giving it an interesting puranic twist. Once the gods gave a bilva leaf, tulasi leaf and tobacco leaf to Shiva, Vishnu and Brahma respectively and asked them to bring it the next day. The cigarette mentioned here is not the modern filtered cigarette, but the local bidi aka suruttu, which is made with tobacco leaf. The vilva leaf was taken away by Ganga (residing on Shiva's jaTa). Tulasi leaf was taken away by the milk ocean (where Vishnu resides). Smart Brahma had given the tobacco leaf to Sarasvati who resides in his tongue. The next day the gods ask the leaves back, while Shiva and Vishnu could not return, Brahma says மற்றவர்கள் பத்திரங்கள் போயின, என்னுடையது போகயிலை ("mattravargal patthirangal poyina, ennudaiyadu pogayilai, others' leaves are lost, mine is not lost), takes it from his tongue and returns. The poet plays on the word "போகயிலை" ("pOgayilai", not lost) which later morphed into புகையிலை ("pugayilai", tobacco). With the story having strong references to purana-s and also a tight etymological derivation, anyone would hardly dispute its origin!

If only this poem had been taught in schools, the smoke rings from those college friends would have served as a more meaningful messenger!

The full text in tamil can be downloaded here.

Wednesday, August 24, 2011

Lost in Transliteration

Transmogrifier is a device into which a person goes thinking of becoming of something and comes out thinking being exactly that. (Invented by Lord Calvin and Sir Hobbes).

Transliterator is a device, where a sound goes into it in one script and comes out the same in another script.

I never understood the spelling-bee contests. Young kids producing words out of infinitely bewildering phonetics. "trouvaille" (meaning: finding) goes one word, pronounced "truva" as many as 4 letters are silent. These spelling bees are only gonna get tougher, and in three years from now we may have the announcer keeping mum and the poor student will have to find the word, because, er.. all the letters are silent. Kudos to the effort and memory power of the students though.

The whole spelling bee concept is based on the platform of arbitrary and artificial phonetics. If there were a one-to-one correspondence between sound and script, the spelling-bee will become a drone-bee. If we rule that English be written phonetically from tomorrow, spelling assignments would disappear. What you say is what you hear is what your mind interprets. WYSIWYHIWYMI.

This reminds of artificially created problems and equally artifical solutions. A good analogy is some of the Java design patterns like Iterator (where you write elaborate classes) "disappear" in dynamic languages like Groovy. The Java design patterns have been elevated into language features of Groovy, so there is no "problem" to start with!

So how many times in life will you ever use that word again? That thought makes me nostalgic about those toefl and gre vocabularies where I crammed words to better the neighborhood guy whose veneer impressed my folks, while I stood exasperated. How many of those words am I using now? How many of those words are being used by native English speakers? And I'm told that I should use simple language while writing emails to clients. If I use the words appoggiatura or roscian, the client will simply take the business elsewhere, because I am hard to communicate with. The fact is, for effective communication you just need around 1000 words in any language. The rest are for poets and dictionary makers who just want to intimidate us ordinary folks and to float themselves in business :-)

Sanskritam students often wonder what is the best way to type in Sanskritam. There are a few great tools -
Baraha, Google Transliterator etc. There are also a few english transliteration schemes available for the devanagari script. Which one to choose? I feel each of them try and have their own quirks. Lets examine some of those:

The Harvard-Kyoto is mostly used in academic circles. The most jarring usage in this scheme is that of uppercases for anunasikas (G/
ङ्, J/ञ्) and z for fricative . Try however, I could not pronounce z as while reading. Just like the Tamil zh/ doesn't make any sense, but we just adapted it.

IAST is more confusing with multiple latin alphabets for the same devanagari akshara (k, K -> , kh, Kh -> ). Do you ever substitute one letter for another in English? Then why such karakter overdoz for transliterashuns?

ITRANS is even crazier. Doubled or uppercases (aa vs A), exponent symbol (R^i), doubled uppercases followed by lowercases (LLi), tilde before, power after, dot before, dot after - its hard to write in ITRANS unless you are already a mathematical genius. It could have also used integral and sum symbols - one could learn advanced calculus simultaneously while writing saMskR^itam.

The other side of the text is parsing into comprehensible data structures. Writing parse routines for such schemes involve quite a bit of effort. So the question is, can there be a simpler, consistent scheme, with fewer things to remember while typing?

Here is one such minimalistic transliteration scheme and it uses only 4 main rules and 3 corollaries:


1. lowercase 2. uppercase 3. possible dot after a letter 4. semi-colon for visarga; jihvamuliya; upadhmaaniya


1. uppercase for dIrgha
2. krama -> lowercase; lowercase+dot; uppercase; uppercase+dot
3. 1:1 mapping in the transliteration

a A e E u U r. R. l. E. I O O.

k k. g g. n
c c.j j. n.
t t. d d. N
T T. D D. N.
p p. b b. m
y r l v s s. S h
M :
a. (avasarga)

The principles behind the scheme are:
  1. A devanagari letter is either ONE char or ONE char + dot.
  2. The scheme is almost consistent (lowercase, lowercase+dot, uppercase, uppercase+dot, uppercase for dIrgha svara). This is why we get an orderly (n, n., N, N.)
Parsing or tokenizing such a scheme is also easy. There is only one if condition to determine an akshara - if a dot follows letter, they form one akshara, if not, that letter is the akshara.

In other words, converting a sentence into unicode is just one-line, assuming the unicodeMap[:] is defined already.

def toUnicode(s,i => return this.append(unicodeMap[s.charAt(i+1) == '.' ? s.substring(i,i+2) s.substring(i,i+1)]);

Q & A

Q. Why favor the 1:1 mapping? After all isn't it good to have options and easy to write in different ways?
A. It sure is, but do you really substitute one letter for another letter in English or Sanskritam? Can you say "sha" is close enough to "sa" and use it for "savam"? A 1:1 mapping allows no options and eventually it gets streamlined in a person's thought process.

Q. viDE.he -> isnt this hard to read than vaidehi ?
A. Yes it is, no doubt. But how did you learn to pronounce it as "vaidehi" with "d" as
while the most common pronunciation of d is ? It will be hard read at first, but didnt we all start with guessing what a dot, dash, tilde, apos mean on top and bottom of the letters :-). If one is already used to a scheme the mind resists a change.

Q. So whats really easy about this scheme?
A. If you are well versed with the devanagari krama, it is probably easier to apply the transliteration. Also there is only the extra character dot to remember.

Q. Whats really difficult, then?
A. Reading will be unnatural for those who are used to different scheme (eg nAraayaNa vs N.ArAyaNa). We are so much used to N being murdha nakara! But even the existing schemes were originally unnatural, so the unnaturalness just shifts to a different section.

(Note: This article is not to challenge existing schemes, but to show a minimalistic scheme ie a scheme with minimum fuss is possible from a parsing perspective. In any art form, the prevelance rules over theories). 

Friday, August 19, 2011

Bodhi learns Sanskrit

बोधि: संस्कृतं पठति

Amar Chitra Katha. The printed granny of Indian kids. That and its cousin Tinkle have been a source stories for a few decades now with a lot of nostalgia for my generation. From puranic to folktales to heroes, it has remained a valuable source of stories in compact format. I wish ACK brings out a full edition of Kathaa-sarit-saagara and similar Sanskrit works, which contains some great stories. Obviously there are already some stories published from it, but not a complete edition.

Though ACK/Tinkle has a lot of stories based on Sanskrita literature, rarely there are stories with Sanskritam itself as the theme.

The below is a translation of a funny story "Bodhi learns Sanskrit".

कस्यांश्चित् पाठशालायाम् बोधि: संस्कृतं पठति । अध्यापक: सर्वान् छात्रान् पाठयति ॥

अध्यापक: वदन्तु । ... राम: ... रामौ ... रामाः ॥
(छात्राः पुनरुच्छारयन्ति)
अध्यापक: ... रामं ... रामौ ... रामान् ॥
(छात्राः पुनरुच्छारयन्ति)


अध्यापक: अथ अङ्ग-पाठः । ... मम शिरः । (स्वशिरः स्पृशन्) ... मम शिरः ॥
छात्राः ... मम शिरः । ... मम शिरः ॥

तदनन्तरम् सर्वे स्वगृहम् गच्छन्ति । बोधि: अपि गृहम् गत्वा अभ्यासम् करोति ॥

बोधि: मम शिरः ... । मम शिरः ... । मम शिरः ... । इत्युक्ते अध्यापकस्य शिरः ॥

(बोधेः पिता तत् श्रुण्वन् तत्र आगच्छति । कोपेन तर्जयति)

पिता: अरे मूढ ! एतादृश: वा भवतः संस्कृत पठन लक्षनम् ? ’मम शिरः’ इत्युक्ते अध्यापकस्य शिरः न । (स्वशिरः स्पृशन्) मम शिरः । (पुन: स्पृशन् उच्चैः) मम शिरः

(पिता उक्त्वा निर्गच्छति)

बोधि: (किञ्चित् कालं चिन्तयित्वा) । ... आ ... आ ... आम् । इदानीम् अवगतम् । पाठशालयाम् ’मम शिरः’ इत्युक्ते अध्यापक: शिरः । गृहे ’मम शिरः’ इत्युक्ते पितु: शिरः । अवगतम् । अवगतम् ॥

Tuesday, August 9, 2011

Six degrees of Sutras

One of the memorable humour tracks of Tamil movies is from arivAli (The Intelligent) made in early 1960s. A black white film, with simple clean humour. Very likely such movies were made in other Indian languages too. The husband asks his wife to make puri. Wife does not know how to make it, so husband gives instructions to her:

Husband: Take a vessel and put some wheat flour in it
Wife: Yeah, I know that!
Husband: Pour some water and salt and mix with flour
Wife: Yeah, I know that!
Husband: Make it into small round balls
Wife: Yeah, I know that!
Husband: Flatten it and make it round like appalam
Wife: Yeah, I know that!
Husband: Then what?
Wife: Aah, I dont know that...

In an earlier post we saw how a sutram's definition can be applied to naming convention of variables in modern programming context. A natural question arises - what are the types of sutram-s? As I have mentioned before, classification is ancient Indians' forte. There are six types of sutram-s which is defined, yeah you guessed it, in a shloka:

संज्ञा च परिभाषा च विधि: नियम एव च ।
अतिदेशो अधिकारश्च षड्विधम् सूत्र-लक्षणम् ॥

A lot has been described about this classification in wiki articles and elsewhere. Here we will just look at the parallels between this classification and programming concepts.
संज्ञा - definition; परिभाषा - interpretation; विधि- rules; नियम - restriction; अतिदेश- extension; अधिकार - header/domain.

संज्ञा is a definition sutram. It gives a meaningful name for one or more symbols. Do you remember your early programming days where you are told that a good practice is to give a name for constants? (Do you still follow that?)

वृद्धिरादैच् |  [1.1.1]  {a, e, o} are called vRuddhi |

In programming terms, this is like the classic C #define statement or final static/const statements in Java/C# world. 

#define PI 3.14

#define IK_PRATYAHARA {i, u, Ru, Lu}

परिभाषा sutram is an interpretation or meta-rules sutram. Its function is to tell how to interpret other sutram-s.
तस्मात् इति उत्तरस्य | [1.1.67] When a sutra has a word in panchamI vibhakti, then the word next to it will undergo some modification. 

A very good equivalent to interpretation rules is Annotations. This example will make it clear:

public void updateUser() {

The annotation says that the method updateUser() must respond to only a http post call. It helps the runtime interpret the method in a certain way.

विधि sutram: What is the fundamental difference between a calculator and a computer? The calculator (a regular) deals with numbers only, while the computer can make logical decisions.

विधि sutram is the classic if-else-condition. In fact, the way पाणिनि has applied it - its closer to aspect-based rules than just a vanilla if-else condition. There is a slight difference between "if do this" and "when apply this". While the if-condition has to be encountered during the execution process thread, a when-rule applies anytime during the happening of a certain condition. "if" is thread-execution based, while "when" is time based, a trigger with an "if".पाणिनि defines several rules in his अष्टाध्यायी. For example there is a famous sandhi rule with just three words, that covers a matrix of sandhi-s.
इको यण् अचि | [6.1.78]
When a vowel follows, the letters i, u, Ru, Lu change to y v r l.

Obviously any if-else condition would be a vidhi sutram. If we were to follow paaNini's technique, we would not write it as a simple if condition. Instead we would define all "when rules" in a separate section of the code, and provide aspects of applying. When code executes, the aspects will monitor the code and "apply" a rule when those conditions are satisfied. For eg the (now) Oracle's Haley is one of the very popular Rules Engine products, in which Rules can be defined in simple English.

नियम sutram
If programming was based on socialistic ideologies, rules would apply uniformly to all cases (except the political class, of course). But reality is somewhat capitalistic, so there is always some case which disagrees to agree. Remember the business requirements like "should apply to all but one or two cases" and the complex if-conditions you would have to write to handle just the boundaries?

Restriction is not Exception. Exception is an alternative flow, but restriction is about applying a rule to a lesser number of or rarer cases. In general, it is achieved by if-else conditions, but doesn't always have to be so.

अतिदेश sutram-s are extensions. They qualify a pre-existing rule with another property, not originally possessed.
Using pratyaya-s vat and mat, paaNini extends the behaviour of one rule and applies to another rule.
लोट: लङ्वत् | [] would mean "लोट् vibhakti-s are to be conjugated just like लङ्"
Imagine that
लोट्, लङ् etc implement an interface called "ल". Panini's technique essentially casts लोट् as लङ्.
Class extensions are very common in OO languages. Using the Extension mechanism offered by Ruby, C# etc, one can improve the functionality of an existing class. For eg, String class does not have intrinsic methods to check if the value is null or empty . One could add a IsNullOrEmpty(this String) method and operate directly on a string instead of a new helper class.
It does not end there. Imagine two objects User and LockedUser:
User user; //normal user behaviour
LockedUser lockedUser; //a locked user behaviour, imagine a Trait (see Scala which allows partially implemented interfaces)
if (user.failedAttempts(3)) { user.setBehaviour(lockedUser)); } //user now behaves like a lockedUser

Instead of changing the state of the object (commonly via isLocked() or status = LOCKED), the behaviour of the object itself is changed. Upon certain conditions, the regular user adapts the behaviour of a locked user. We do not directly deal with properties and state changes, instead work with behaviour changes. For eg, Scala offers Traits, with partially implementable methods, which are much more than interfaces. In a way you are describing or coding to the behaviour of an object rather than the states.
अधिकार sutram: If you have done database modeling, you know Subject Areas. In programming terms, think of package, namespace etc. They all define a domain underwhich certain rules/classes/tables are grouped. Thats exactly what adhikara sutram is. More information on adhikara sutram can be found in this post.
संहितायाम् | []  "During the closeness of words"
प्रत्यय: | [3.1.1] "Affix"
namespace Com.Sun.Oracle.Java;
//ok, I was being facetious :-)

Apart from these core sutram-s there are a few more.

निषेध sutram-s are negation rules of other rules. While niyama sutram-s are positive restrictions, nishedha can be seen as negative orientation.
हलन्त्यम् | (consonant endings are it-markers)
न विभक्तौ तुस्माः | (but
letters t, th, d, dh, s, m are not it-markers if it is used for conjugations)
In programming, we can come up with a validation rules engine like this:
1. All Address Fields Required
2. Not if Address Line 2
Imagine the simplicity of a program using such a validation engine!
विभाषा sutram is an optional rule. For eg think of the sentence "I would like to goto a movie". You can also say it as "I'd like to goto a movie". The shortening of "I would" to I'd does not change the meaning, and is optional to use. पाणिनि uses this technique to provide alternative usages of words and grammar by using the shabda-s vaa, vibhaaShaa, anyatarasyaam. Optional rules are very common and are done using if conditions.

Besides these, some of the paaNini's techniques also strike a chord with modern techniques. For eg, there is an interpretation sutra विप्रतिषेधे परम् कार्यम्, which means "In case of rule-conflicts, the latter rule prevails". Virtual override feature?

Another unique technique is called स्थानी भाव where a substituting suffix can retain the characteristics of a substituted suffix. Heard of Liskov Substitution Principle? Yeah, something like that.

Panini also uses recursive techniques for some of the rule operations. We will see that in a subsequent post.

Yet another ingenious technique is seen in the last 3 pada-s of अष्टाध्यायी where every previous rule is oblivious to all the latter rule. The rules are arranged in such a way that every rule "thinks" that it is the last rule of the book.

So what is the benefit of comparing modern programming with a 2500+ old text book of grammar? Let it be पाणिनि:, Capellini or Linguini founded algorithms. As a software engineer, what do I care? I do not have an answer. After all, a programmer consultant in US writes a for-loop for $75 an hour, while the same for loop is written by some one in China for a few Yen. Can you judge which for-loop is better?

If several of modern programming concepts have indeed parallels in अष्टाध्यायी, how about some concepts in अष्टाध्यायी not yet formulated into modern programming theories? What if they could create a fundamental change in theory of programming?

What would पाणिनि: think about modern programming concepts? To find out, we shall send Donald Knuth back in time as our representative.

Knuth: Programming is about definitions, rules and algorithms.
पाणिनि: आम्, जानाम्येव !
Knuth: Using algorithms we derive and solve various equations.
पाणिनि: आम्, जानाम्येव !
Knuth: In object oriented programming, we do abstraction, polymorphism and other cool things.
पाणिनि: आम्, जानाम्येव !

Knuth: With functional programming, we define functions, recursions and closures.
पाणिनि: आम्, जानाम्येव !
Knuth: Then we create programs to play games like Grand Theft Auto all day long.
पाणिनि: अहो ! तदहम् न जानामि !!

Friday, July 29, 2011

Better than the best

श्रेष्ठेभ्यो श्रेय: |

In the superhit 1965 Tamil movie Thiruvilayaadal (Divine Sport), there is a classic scene where the poor poet Dharumi brings a poem for a prize announced by the Pandya king. Nakkeeran, the court poet, happens to doubt the authenticity of the composition. (It was indeed given to him by Shiva and was not Dharumi's original). Dharumi reacts sarcastically -

"பாட்டெழுதி பேர் வாங்கும் புலவர்கள் இருக்கிறார்கள். குற்றம் கண்டு பிடித்து பேர் வாங்கும் புலவர்களும் இருக்கிறார்கள்"
"There are poets who become famous by their own effort. And there are poets who just criticize others and become famous".

But then the world owes much to artists whose claim to fame is only critiquing/commenting somebody's work. Take Mallinaatha for example, without his significant and monumental commentary it would be impossible to understand meghadhUtam or shishupaalavadha. So much so that Mallinaatha says "माघे मेघे वयम् गत:" (Life's gone in reading maaghakaavya and meghadhUtam). There are geniuses who create phenomental stuff and then we need mediators to such geniuses to expound it for us ordinary mortals. Or take Panini vs Patanjali. Panini's pataakhi-sounding pratyaahaara-s like ढक्, डुप्, दप्, घञ्, क्ङित्, तिप्, थस् sounds could only be expounded by a genius like Patanjali. We need a Hardy and several more, just to decipher us the genius of Ramanujan. Some cant stand that - like George Polya, the Hungarian mathematician who refused to get caught in Ramanujan's theorems, for the fear that he would spend his life just proving them, and never discover anything of his own.

शिशुपालवध is no doubt one of the greatest mahakaavya-s. Among the pancha mahaakaavya-s it is considered the greatest. A famous subhaashitam says that माघ has the exceptional qualities of all three poets कालिदास, भारवि and दण्डिन्.

Think about shishupaala for a moment. Forget that he is a villain, thats a simplistic view. He consistently challenged Krishna's superiority, for whatever reasons. He showed scant respect for Krishna, repeatedly insulted him and asked others during the raajasUya-yajna "Isn't there one person who is worthy of honor than this shepherd?". People like shishupaala are not incidental, and are not coy to challenge superiority, no matter who it is. Similarly, Nakkeeran challenged the poem of Dharumi. From Dharumi's point of view, Nakkeeran criticized him. But Nakkeeran challenged the poem, the one written by Lord Shiva himself. The greatness of art is strengthened only if it can withstand any challenges. So it is only natural someone challenged the superiority of Maaghakaavya. And such a challenger was Vadiraja Tirtha.

Like several Sanskritam literature works, this one too is hardly heard of, except in a few elite circles. I had earlier mentioned that it is only our loss not savoring the Sanskritam language of scriptural literature. There appears to be a lot of noise around "secular" Sanskritam literature, whatever that means, side-lining the beauty of the language shining in other fields.

Vadiraja Tirtha is no ordinary poet. He has produced a prodigious amount of work in several fields - kavya, stotra, stuti, travelogue, commentaries, logic, cosmology and a lot more. Some of his works run into thousands of verses. And yes, living for a full 120 years (1480 to 1600 CE) helped him too! And he ensured a productive life. This event is recorded in the biography book shri vaadiraaja guruvara-caritaamRuta:

तत: पुण्यपुरीम् प्राप्तो भेरीताडनपूर्वकम् । काव्यश्रेष्ठं माघकाव्यं गजमूर्ध्नि पूज्यते ॥
इत्याघोषितमाकर्ण्य सभापतिमवोचत । अस्मत्पुरे महाकाव्यमेकम् श्रेष्ठं प्रकाशते ॥
दीयते समय: कश्चित् दर्षयिष्ये परीक्ष्यताम् । अङ्गीकुर्वति विज्ञौघे गुरु: एकोनविंशता ॥
दिवसै: एकदिवसे हि एकसर्ग क्रमेण स: । रुक्मिणीश महाकाव्यं निर्ममे सुरसाकरम् ॥
अवेक्षणाय विदुषां संसदं प्रैषयेत् सुधी: । परिषत्सा परीक्षाय विस्मित आनन्दपूरिता ॥
रुक्मिणीश महाकाव्यमुत्तमं माघतोऽपि च । इत्याघोष्य च सम्मान्य प्रार्चयत् कविसत्तमम् ॥
कवीनाम् कुलमध्ये हि तिलक: अयम् इति प्रथाम् । ख्यापयामास विदुषां परिषद्गुणमोदिनी ॥
(श्रीवादिरज गुरुवर चरितामृतम् ३.४.१०)

The verses are very simple and pretty straight-forward to understand.

"Once in पुण्यपुरी (modern Pune), the best of kaavya namely Maghakaavya was about to be honored on elephant's head. Hearing this, Vadiraja said to the scholars there "Before you honor the kaavya, listen to one kaavyaa written in our place. If some time is given, I will show you and you can verify it yourself. Vadiraja wrote one sarga per day for the next 19 days and completed the work rukmiNIsha vijaya ("The Victory of Lord of Rukmini"). The scholars read and were stunned and filled with joy. They declared रुक्मिणीश विजय to be better than माघकाव्य. They declared Vadiraja as a "tilaka" (foremost) among the poetic society."

An important contention of Vadiraja was that the title of the book is about "killing" shishupala and invokes negative thoughts, while Rukminisha vijaya is about the "victory" of Krishna, which evokes positive feelings. The name of the kavya itself is mangala. One cannot argue with that point though.

Replete with अलङ्कार, अनुप्रास, यमक, चित्रपद, a variety of छन्दस्  and lot more that a tiny mind like mine cannot comprehend, Rukminisha Vijaya is as delightful to read as shishupaalavadha.

When India loses in a close match, commentators have a cliche for consoling - "cricket is the winner". Borrowing that, we could say whatever may be the reason behind the two kaavya-s, Sanskritam is the winner :-). जयतु संस्कृतम् |

Monday, July 25, 2011

nakShatra yuddhaaH

नक्षत्र युद्धा:
Yoda is the most powerful Jedi of the Galaxy, and probably because of that, he has a different way of communicating.

Meditate on this, I will.
Powerful you have become, Dooku. The dark side in you I sense.
Much to learn, you still have (Dooku)

Who hasn't wondered about his pensive mood, superior intellect, fast reflexes, and measured delivery? Which Jedi fan hasn't admired and mimicked Yoda's speech? He sure sounds funny.

Or does he?

Let us translate his quotes into Samskritam.
अधिकम् अस्ति ज्ञातुम् भवता इतोऽपि ।
चिन्तनम् एतस्य अहम् करिष्यामि ।
बलवान् त्वम् असि Dooku | कलिम् त्वयि पश्यामि ।

Before we see whats all the fuss is about, lets look at this sentence:

"I am going to the temple and then will go to a movie"

First, translate that into an Indian language, preferably mother tongue.

Now translate that same sentence, only now preserving the syntax order as in English.

Did you sound funny? Or poetic? You will notice that the first time you naturally placed the verb automatically following the object - mein mandir jaaraahan hoon, uske baat movie jaaoonga. Second time you had to make a conscious effort to preserve the syntactic order - mein jaaraahaan hoon mandir, uske baat jaaoonga movie. (You will surely sound a shaayar if you say this twice).

Lets get back to Yoda's wisdom. The translation is purposefuly preserving the syntactic order. Even though translating as "bhavataa itopi adhikam asti jnaatum" sounds natural, saying "adhikam asti jnaatum bhavataa itopi" does not sound funny at all. So all Yoda does is use the syntactic order "Object-Subject-Verb" (OSV) instead of the regular "Subject-Verb-Object" and suddenly we find academicians writing thesis over Yoda's constructs. Samskritam in fact allows all the combinations (not always, but more often), yet none of them tickle our ribs. Such variations are found in shlokas aplenty and that does not evoke laughter!

Students who wish to learn Samskritam can be broadly camped into one or more of:
  • I studied in school (for easy marks), forgot everything, I want to learn now
  • I want to understand the meaning of shlokas
  • I am really passionate about Samskritam
  • I feel I should learn Samskritam, because my grandpa spoke so
  • I am easily impressed by people who fluently converse in Samskritam, so I want to learn too

Students with other ambitions tend to lose interest after a few attempts. Most of the time, time, or lack of it, is blamed. That reminds me of a quote by Swami Vivekananda "In the West, a man would goto any length to find gold; in the East, a man would climb any high mountain to gain knowledge". One may recall Homer Simpson climbing all the way, along with Apu, to a high mountain to ask a Rshi three questions. (Are you really the head of Kwik-E-Mart? "Yes"; Are you? "Yes"; Really? - "Yes, Thank you come again!").

A frequent folly committed by beginner Indian students is trying to think in English. The structural and syntactical differences just dont match. Thinking in mother tongue will yield richer dividends and I am not talking just about word similarities, but the syntax itself. This is a very important point to grasp but infact a hard rule to follow. But what about the people with English as their mother tongue? Easy-breezy. Start thinking like Yoda!

I cannot be sure if George Lucas intended or not, but Yoda in Samskritam means Warrior (yodha:). Lazy googling suggests he was influenced by Joseph Campbell who in turn was influenced by Oriental stories. I hope some day Star Wars will be translated into Samskritam. Only suddenly Yoda will not be funny anymore. May be he is the one who talks correctly and we all talk funny. You see, English is surely a phunny language. Only if that way not necessarily Yoda speaks.

Sunday, July 10, 2011

Paninian Blues

The brevity of Panini's अष्टाध्यायी has been widely read, wondered, appreciated, criticized, discussed, commented and treatised over the past couple of thousand years. On one end of the Sanskritam literature spectrum are such extremely, almost ridiculously, laser-like focused and concise treatment of subjects in sutram format. On other end stand the lengthy and wordy mega-serial type works from kaadambarI, kathaasaritsaagara, yogavasiShTha (32,000 verses), raamaayaNa (24,000 verses) upto the granpa and granny of all - the mahaabhaarata (100,000) and bhaagavatam. In between are the short-stories focusing as much as possible to the main theme.

Interestingly while raamaayana contains 24000 verses, it has been retold in different variations in a wide variety of formats in different languages, since vaalmIki. In fact the very first 100 slokas contain an abridged version of raamaayaNa by vaalmIki himself. There is a Swati Tirunal's kriti "bhaavayaami raghuraamam" - the story of raama in few stanzas set in different ragas. Very recently was released a visually stunning retell of the story by Sanjay Patel. There is even a eka-shlokI-raamaayaNa which tells raamaayaNa in just one shloka!

आदौ राम तपोवनादि गमनम् हत्वा मृगम् काञ्चनम् ।
वैदही हरणम् जटायु मरणम् सुग्रीव सम्भाषणम्  ।
वाली निग्रहणम् समुद्रतरणम् लङ्कापुरि दहनम् ।
पश्चात् रावण कुम्भकर्ण निधनम् तु एतत् हि रामायणम् ॥

The transformation of a few verses to a delightful and an exquisite kaavya (eg. shaakuntalaa by kaalidaasa) or crunching a big story to a few lines like the above seems to have fascinated Sanskritam poets.

One of the most fascinating पञ्चतन्त्र story is The Blue Jackal. Hunger, sympathy, cunningness, fear, imposture, divine invocation, regality, anger, violence - so much characteristics are packed in a few verses. One can quote several movies on this pose-as-somebody-else-and-take-others-for-a-ride theme and variations. While movies of every language seem to have this kind of comedic setup, the evergreen classic Golmal (Amol Palekar) comes to my mind immediately.

But what if, instead of विष्णु शर्म, पाणिनि had written the पञ्चतन्त्र ? May be he would have reduced the pancha-tantra to pancha-paragraphs.

Lets imagine the blue jackal story, Panini-style. Let paNDita-s forgive me for such a blasphemy.

अरण्ये ।
शृगाल: ।
  - वने कश्चन शृगाल: वसति स्म ।
प्रत्याहारम् भुभुक्षाया: ।
  - स्वस्य भुभुक्षा-कारणत: आहारम् प्रति स: अन्वेषणम् अकरोत् ।
तत्र । (2.1.56)
श्वपदानुसारणात् नीलभाण्डपतितोऽपिसन् ।
    - शुनकै: खेतित: धावित: श्रुगाल: नीलभाण्डे अपतत् ।
परश्च । (3.1.2)
प्रतिपथमेति । (4.4.42)
    - तत्परम् स: वनम् प्रत्यागच्छत् ।
अज्ञाते । (5.3.30)
आत्मने चण्डरव: इति ।
दूतस्य भाग-ब्रह्मणि । (4.4.120)
    - मृगा: तम् न ज्ञातवन्त: । स: शृगाल: "अहम् चण्डरव:, ब्रह्मण: दूत:" इति कथितवान् ।
राजा च । (6.2.59)
वृन्दारक नाग-सिंह-कुन्जरै: पूज्यमान: । (2.2.62)
प्रसंशावचनैश्च । (2.2.66)
    - स्वयम् राजानम् मत्वा सर्वेषु मृगेषु भीति: उत्पादितवान् । मृगा: तं शृगालं प्रशंसवचनै: पूजितवन्त: ।
वृष्टिरादैच् ।
    - एकदा वृष्टि: आकाशात् आगता ।
अन्यैश्च टंकार: ।
    - अन्यै: शृगालै: टंकार: कृत: ।
स्वं रूपम् शब्दस्य (1.1.68)
    - तं शब्दं श्रुत्वा शृगाल: स्वस्य रूपं विस्मृतवान् ।
स्वयं तेन । (2.1.25)
    - तेन शब्देन स्वयं पुर्व-रूपं स्मृत: नीलशृगालेन अपि टंकार: कृत: ।  मृगा: तस्य शब्दस्य अभिज्ञातम् कृतवन्त: ।
हनस्च वध: । (3.3.76)
     - मृगा: चण्डरवम् मरितवन्त: । 
तस्य लोप: । (1.3.9)
    - शृगालस्य लोप: स्यात् ।
तदर्हम् । (5.1.117)
    - स: तद् अर्हति एव ।
The sutram-s with indicated numbers are either a direct lift or lousy modifications of the अष्टाध्यायी sutram-s. The वृत्ति is in blue.