Thursday, November 19, 2009

Sutra based Programming

Haven't software engineers had enough of programming languages? C and C++ were there for a while unchallenged. Then Java took over C/C++ pretty quickly. Even though you could create complex applications using Java and run on any platform, there is no dearth of new languages. Scala, Groovy, Ruby and very recently Go from Google.

All high-level programming languages do 4 basic things:

  1. Assignment
  2. Condition
  3. Loop
  4. Function/Procedure.
Loop and Function/Procedure/Subroutine are essentially glorified Goto.

Everything else is syntactic sugar.

Galileo has influenced us heavily to think math in terms of symbols. A mathematical symbol expresses an idea very concisely and effectively. Much more than a language could do.


x = 1
is more concise than saying "let x equal to 1".

Let me rephrase the above bereft of assumptions --

The mathematical expression "x = 1" is more concise than saying it in English "let x equal to 1".

But what if we could express "x = 1" much more concise in a natural language?

For e.g., let me just say

x 1
I just dropped the symbol "=". One symbol less! Whohoo! I also established a convention that whatever on left side is receiver and on the right side is provider. In a language like Sanskrit, for e.g., the "is/happens" is implicit (asti/bhavati). So no other verb is required. (There are other languages that exhibit this property too).

People think that just because ancient Sanskrit mathematicians did not use symbols, the works are not scientific. Symbol is just a convenience; if language could be more powerful than symbols, who needs them? As a side note, Sanskrita almost does not use punctuations (except for end of sentence - the pipeline character |). In contrast, English just can't be "communicated" without appropriate punctuations' usage.

To demonstrate the power of the language, let us look at a simple program using a pseudo-language.

//Pseudo-code to produce a random number and determine if its odd or even
s = 100;
r = (int) rand(s);
if (r % 2 == 0)
return "even";
return "odd";
The question is, can this program be expressed using natural language? Of course, we can write the whole program in plain English, but it wont be concise. (COBOL anyone, hello?)

Now lets apply the Sanskrit grammarian Paninian rules. I am going to keep the function names as is (in bold), but conjugate the variable names per Sanskrit rules (taking them to be consonant ending variables).

1: aSeSha: SUnyam  // No remainder 0 (No remainder equals 0)
2: s Satam         // s Satam asti (s is 100)
3: sa: rand r      // of s random is r (r is random of s)
4: int ca          // int also (r is also int of random of s)
5: even ra: aSeshe dvibhAjane  // "even" is of r during division of 2 when no reminder happens (on division by 2 of r has no reminder, it is even)
6: odd SeShe       // "odd" when there is a reminder

Here are the sutras in proper Sanskrit:

अशेष: शून्यम् |
स् शतम् |
स: वृथा र् |
अभिन्न: च |
समं र: अशेषे द्विभाजने |
विषमं शेषे ||

As you can see there are absolutely no mathematical symbols! A program is written purely by the expressive power of language. So what happened? How are they equal?

Using nominative case and the implicit "is", Panini eliminated the need for equals sign. Functions are defined via genetive case. Using the locative case, Panini provides the if-else condition. In effect, mathematical expressions are substituted by simply conjugating the variables.

That is the genius contribution of Panini to Sanskrita! Now a skilled poet could come and rearrange the above 6 sutras into a sloka format, and lo! there is sloka that tells us how to determine an even/odd number!

Let me attempt a half-baked sloka (May Sanskrita enthusiasts forgive me for such a blasphemy).

अशेषो शून्यं भूयात् सेकशतं वृथा रेफ: स: ।
अभिन्नश्च द्विभाजने विषमं समं शेषोऽशेषे ॥

Due to the occurrence of words like SeSha, SUnyam, aSeSha, dvibhAjane, abhinna the above can be mis-interpreted to refer Adisesha, SUnyavAda, Vishnu, Dvaita, Advaita etc. Now we have an example of a sloka referring to the gods and a mathematical algorithm encoded in it!

Tuesday, November 10, 2009

The Panini Certificate

Ever since Panini has written his monumental ashtadhyAyI, there have been plenty of commentaries on it and still continues to follow. Katyayana's Vartika, Patanjali's Mahabhashya, Kasika Vritti, Siddhanta kaumudi, Laghu kaumudi, Laghu siddhanta kaumudi are a few Sanskrit commentaries. When the West discovered Sanskrit, more commentaries sprang up.

For some reason, whosoever has tasted a little bit of Panini (not the Italian sandwich) feels so compelled to write a commentary on it. In modern days blogs have replaced commentaries. Whosoever even just heard about Panini, is compelled to write a blog about him. Just like me.

Kalidasa describes this feeling in a beautiful poem:

मन्द: अपि अमन्दताम् एति संसर्गेन विपश्चित: । (मालविकाग्निमित्रम् 2.7)

The company of the intelligent brings respect even to the dumbwitted. (Malavikagnimitram - Ch 2, verse 7)

The human mind tends to super-impose the characteristics of an associative object with the associating subject. So whoever reads Homer is a literat. Whoever likes Homer Simpson is dumb. Whoever loves Bambi is cute, whoever appreciates legumes are nuts. During a Panini study, a student undergoes one or more, usually all, emotions of bewilderment, amazement, overwhelmingness, stunning and finally dumbfounded, in any order. By this time he/she figured out that he/she got smarter just knowing Panini.

Ignorance shadows smartness.
Ankle deep into ashtadhyAyI, the student now questions Panini's sutras and methodology. 'This sutra does not make sense', 'This sutra could have been avoided and put elsewhere', 'This is an unfortunate sequence of sutras' etc - so the student passes judgement like my wife's hand distributes neighbor's ghee to everybody.

When does this feeling stop? When does the student hear the inner-voice 'Oh, shut up'? The post-Panini period was a cauldron of grammatical activities. It has been told that several grammarians attempted modifications, additions of sutras to ashtadhyAyI. In midst of all this, one great intellectual, one that the human mind has since not surpassed, stood up and proclaims "ashtadhyAyI is perfect beyond your pea-brained comprehension faculties".

And that brings this quote from that Great Rishi Patanjali himself, who drank ashtadhyAyI as easily as soda from a can and gives an 'Outstanding' certificate to Panini.

tatra aSakyam varNena api anarthakena bhavitum, kim punariyatA sUtreNa |

तत्र अशक्यम् वर्णेन अपि अनर्थकेन भवितुम्, किम् पुनरियता सूत्रेण ।

Even by a single letter (varNena api) is not possible (tatra aSakyam) to exist (bhavitum) meaningless (anarthakena), what to say about a whole sutra!

Saturday, November 7, 2009

Myths and Facts about Sanskrit

Myth 1: Sanskrit is a dead language.Myth-buster: Define dead

Both the 'elite' historians of India and pseudo-Sanskritists of the West have delighted themselves in the propaganda of calling it a dead language. So much so that its a fashion to call it so, even by the educated. Is Latin dead because nobody speaks it? Sumerian and Egyptian languages are dead. Is Sanskrit dead the same way?

A 'dead' language has a few advantages:

  1. It remains in exclusivity of a few (of those believing the dead language theory).
  2. It creates a certain aura around it, of being something special, thereby making the people who know it also 'special'
  3. Ordinary folks will not attempt to learn it.
Lets travel back in time any period between 500 BC - 1600 AD and see the facts.
  1. Sanskrit remained in exclusivity of a few (Brahmins)
  2. Sanskrit was treated special, so were the Brahmins special
  3. Nobody else except Brahmins attempted to learn

So all the above were true even before this dead-language theory (except now Brahmins are replaced by historians and pseudo-Sanskritists). So was Sanskrit dead all the time? If it was dead, why there are several thousand Sanskrit works available?

Myth 2: Sanskrit is a difficult language to learn.

Define difficult

Which language is not? German has several conjugations. Mandarin and Japanese have too many lines. French has the 'r'. Fact is every language is difficult until your perspective is adjusted.

In fact, the toughest of all these languages is English. The alphabet is not phonetical; each letter is represented by different shapes (capital and small); each word should be learnt phonetically independently; the grammar does not have a analytical approach that can be universally applied and not the last -
if you do not punctuate the sentence, you practically puncture the meaning.

None of these anomalies apply to Sanskrit. There is a deep science (SikshA) behind phonetics. There are no capitals and small letters. The science of Sandhi is perfected just to facilitate natural flow of speech. It adheres to philosophy of WYLIWIR - What you listen is what you read. Once the alphabets are learnt, the words can be read without any additional references, ie there is absolutely no guess work when reading or listening. Imagine how the complexity of text-to-speech systems will be reduced. You feed the meta-data of letters + pronounciation of each letter/compound to the system. And the system can read any word without additional effort. Any word! And all those spelling-bee contests, where students cram and rote completely arbitrary spellings can be replaced by something more analytical. The grammar is very analytical and algorithmic. Every technical term in grammar is very meaningful. In fact the word grammar itself is vyAkaraNa - which is split into vi + aa + karaNa = (vi) separate + aa (analyze) + doing (karaNa), ie "separation and analysis".

We learnt English as kids, when we never questioned logic, so it seems easy. I know some of my friends who came from non-English medium (ie learnt all subjects through regional language and exposed to English only around 5th grade), who have dreaded the English exams.

Myth 3: There is no benefit from Sanskrit.

Define benefit.
Myth-annhilator: There is no action without an effect.

Monetary Benefits:

  • Pseudo-Sanskrit academicians benefit by researching ancient Sanskrit books, habitually or purportedly misunderstanding the text, write books on it and do a Sanskrit-love-hate tango after the books are published.
  • "South-asian" pundits benefit from it with their half-baked Sanskrit knowledge (just because they were born in India) and feed the above group.
  • Vedic priests benefit from it as most rituals can be done only by them and not by anybody else
Ego-boosting benefits:

  • Elitist historians benefit by not letting any academicians challenge their pet theories, also called as history.
  • Students benefit it from learning it and showing-off to their lesser intelligent mortals
  • Bloggers benefit from it by belonging to an exclusive club and making sure no one understands what they write or turned off by lengthy blogs in these days of tweeting.
There are always benefits learning a new language. Its up to the person to figure out the weight of the benefit.
Myth 4: Sanskrit is the perfect language, mother of all languages and best suited for computers.
Myth-buster: Define perfect

This is a favorite of the overzealous right-wing enthusiasts. See this picture, where Sanskrit is one corner of the Indo-european languages. Academic opinions are pretty muddled regarding the theory of PIE, most of them peddaled by funding rather than facts. Several people have claimed that Forbes has claimed that computers have claimed that Sanskrit is best for themselves. I am not sure how much of this is misquoted. What is suitable for computers is the approach that Panini took to define a natural language such as Sanskrit, as derivable from formal rules. No other natural language is buffered by such formal rules. That method is very algorithmic, not the language itself.
Myth 5: Is it Sanskrit, Samskrit, Samskrita, Sanskrita, Samskritam?
Define is it.

The British anglicized it to cool-sounding Sanskrit, just because they never learnt anything to pronounce properly, including English. The North-Indians pronounce it as Samskrit (chopping-off the final vowel, per Hindi rules). Tamilians pronounce it as Samasgridam (adding the Dravidian grammatical touch to it). Somewhere in between these are the pronounciations Sanskrita, Samskrita etc, pretty much because of being unsure how to say it.

The correct pronounciation is sanskRitam, where n is nasalized, just like 'song'. The Ri is the most problematic and misunderstood. It should be pronounced thus: Say i (ee, as in tweet) first and then slightly roll the tongue upwards to touch little bit before the teeth.

Tuesday, November 3, 2009

The subhAshita-ratna-bhandAgara

When you think of Samskrita, one of the several things that come to mind immediately is subhAshitA. Literally it means "something well said", the english equivalent of which is 'proverb' or 'saying'. Proverbs are generally pithy sentences that reflect a truth of what happens, what should happen or sometimes a simple generalization. Many proverbs are advises, intended to correct the course of human behaviour, moral, ethical etc.

But subhAshitA-s are not just proverbs. subhAshitA-s come in very different flavors and cover a wide range of topics. There are subhAshitA-s for pretty much every occasion, every behaviour and on every natural thing that we see around. There are subhAshita-s that praise, denounce, praise and denounce at the same time (so called ninda-stuti), make fun, sarcastic, plead, humorous and exhibhit a range of other emotions. Some are philosophical, some are just down-to-earth. In fact there is a subhAshitA that makes a mockery of subhAshitA-s. Several poets have saved their heads by appeasing their kings with an appropriate subhAshita.

Throughout Samskrita literature (vAngmaya), there have been attempts at compilations of subhAshita-s too. Prime among them is the subhAshita-ratna-bhandAgara (SRB) which is a collection of almost ten thousand subhAshitAs on various topics. It consists of 7 chapters (prakarANa-s) - namely: mangalacharana, sAmAnya, rAja, chitra, anyokti, navarasa and sankIrNa. While there are so many wonderful verses there are some really stunning ones. One of them I quoted in my last post alluding to the Ocean's son-in-law selection process.

Here is another one from the navarasa (art) category. It again shows the poet's out-of-the-box thinking.

एकवस्तुम् द्विधा कर्तुम् बहव: सन्ति धन्विन: ।
धन्वी स मार एवैको द्वयो: ऐक्य: करोति य: ॥
eka vastu dvidhaa kartum bahava: santi dhanvina: |
dhanvI sa mAra evaiko dvayo: aikya: karoti ya: ||

Lets look at word by word:

eka vastum - one thing
dvidhaa - into two
kartum - to do
bahava: - many
santi - are
dhanvina: - archers
dhanvI - archer
sa mAra - (is) that manmatha (Lord of Love)
eva eka: - alone (only one)
dvayo: - of two
aikya: - into one
karoti ya: - he who does

There are many archers who can split one thing into two. But there is only one archer, Manmatha, who unites two into one.

This alludes to the fact that the Lord of Love sends an arrow to unit two people's heart. So the poet takes something that is meant for a singular purpose and uses it in the context of getting an entirely opposite result.